3 #include <fwk/CentralConfig.h>
5 #include <det/Detector.h>
6 #include <rdet/RDetector.h>
8 #include <utl/Branch.h>
9 #include <utl/RadioGeometryUtilities.h>
10 #include <utl/PhysicalConstants.h>
11 #include <utl/Vector.h>
12 #include <utl/Point.h>
14 #include <evt/Event.h>
15 #include <evt/Header.h>
16 #include <evt/ShowerRecData.h>
17 #include <evt/ShowerRRecData.h>
19 #include <revt/REvent.h>
20 #include <revt/Header.h>
21 #include <revt/StationConstants.h>
22 #include <revt/StationRecData.h>
39 topB.
GetChild(
"minNumberOfStations").
GetData(fInitialNumberOfSignalStations);
41 topB.
GetChild(
"chiSquareProbabilityCutValue").
GetData(fChiSquareProbabilityCutValue);
43 topB.
GetChild(
"maxIncomingDirectionDifference").
GetData(fMaxIncomingDirectionDifference);
44 topB.
GetChild(
"additionalSystematicError").
GetData(fAdditionalSystematicError);
51 ComparePair(
const std::pair<int, double>&
a,
const std::pair<int, double>&
b)
53 return a.second < b.second;
66 info <<
"RUN in iteration " << fIteration;
80 const string headerId =
event.GetHeader().GetId();
83 if ((fCurrentRunId != runId) || (fCurrentEventId != eventId) || (fCurrentHeaderId != headerId)) {
85 fCurrentRunId = runId;
86 fCurrentEventId = eventId;
87 fCurrentHeaderId = headerId;
89 fCurrentNumberOfStations = fInitialNumberOfSignalStations;
95 if (fCurrentNumberOfStations >= 4) {
97 WARNING(
"Event has no eFitSuccess parameter. Since this is not the first iteration"
98 " (at least I think so) it should! This can happen if events with identical IDs are"
99 " reconstructed, e.g. using the Offline file format and <loop numTimes='>1'...");
105 info <<
"Wave fit was not successful with station " << fLastAddedStationId
106 <<
". Station will be rejected permanently.";
109 if (fStopAtFirstStation) {
116 INFODebug(
"calculating chi2 manually: ");
117 for (
const auto& station : rEvent.SignalStationsRange()) {
118 const double timeResidual = station.GetRecData().GetParameter(revt::eTimeResidual);
119 const double timeResidualError = station.GetRecData().GetParameterError(revt::eTimeResidual);
120 const double sigma_t2 =
utl::Sqr(fAdditionalSystematicError) +
utl::Sqr(timeResidualError);
121 chi2 +=
utl::Sqr(timeResidual) / sigma_t2;
123 info <<
"tres = " << timeResidual /
utl::ns <<
"ns, error = "
128 const double chi2ndf = chi2 / ndf;
129 info <<
"chi2 = " << chi2 <<
"/" << ndf <<
" = " << chi2ndf << std::endl;
133 if ((chi2ndf > 2 * fChiSquaredNDF) && (chi2ndf > 1)) {
135 info <<
"This condition is not used, but for your information: Adding Station "
136 << fLastAddedStationId <<
" to the fit results in a chi2/ndf = " << chi2ndf
137 <<
". Previously it was " << fChiSquaredNDF
138 <<
". Station will be rejected permanently.";
142 bool rejectChi2Prob =
false;
143 const double chi2prob = TMath::Prob(chi2, ndf);
145 if (chi2prob < fChiSquareProbabilityCutValue) {
146 rejectChi2Prob =
true;
148 info <<
"Adding Station " << fLastAddedStationId
149 <<
" to the fit results in a chi2probability = " << chi2prob
150 <<
". This is smaller than the allowed probability of "
151 << fChiSquareProbabilityCutValue <<
". Station will be rejected permanently.";
156 if (rejectChi2Prob) {
158 if (fStopAtFirstStation) {
162 fCurrentNumberOfStations++;
163 fChiSquaredNDF = chi2ndf;
165 info <<
"Adding Station " << fLastAddedStationId
166 <<
" does not increase chi2ndf significantly (chi2probability = " << chi2prob
167 <<
"). Station will be kept. In the next step " << fCurrentNumberOfStations
168 <<
" stations will be considered.";
172 }
else if (fInitialSDCheck && (fCurrentNumberOfStations == 3)) {
175 if (fCurrentNumberOfStations == 3) {
177 bool faultyStationPresent =
false;
179 faultyStationPresent =
true;
181 info <<
"Fit was not successful, suggesting that there is something wrong with one of the 3 stations"
182 " closest to the axis. Need to investigate further...";
186 const double dotProduct = showerAxis * referenceAxis;
187 const double angularDifference = acos(dotProduct / showerAxis.
GetMag() / referenceAxis.GetMag());
189 if (angularDifference > fMaxIncomingDirectionDifference) {
190 faultyStationPresent =
true;
192 info <<
"SD and RD reconstruction differ by "
194 <<
" degrees. Need to investigate further...";
199 if (faultyStationPresent) {
205 std::vector<double> expectedSignalTime;
206 std::vector<double> measuredSignalTime;
207 std::vector<int> stationIds;
209 for (
auto& station : rEvent.SignalStationsRange()) {
210 measuredSignalTime.push_back(station.GetRecData().GetParameter(revt::eSignalTime));
211 const int stationId = station.GetId();
214 expectedSignalTime.push_back(-(referenceAxis * stationPosition /
utl::kSpeedOfLight));
215 stationIds.push_back(stationId);
218 const double avgExpectedSignalTime =
TMath::Mean(expectedSignalTime.begin(),
219 expectedSignalTime.end());
220 const double avgMeasuredSignalTime =
TMath::Mean(measuredSignalTime.begin(),
221 measuredSignalTime.end());
222 int faultyStation = 0;
223 double maxTimeResidual = 0;
224 for (
unsigned int i = 0; i < measuredSignalTime.size(); i++) {
225 const double timeResidual =
abs(measuredSignalTime[i] - avgMeasuredSignalTime -
226 expectedSignalTime[i] + avgExpectedSignalTime);
227 if (timeResidual > maxTimeResidual) {
228 maxTimeResidual = timeResidual;
229 faultyStation = stationIds[i];
234 ++fCurrentNumberOfStations;
241 if (fMaxNumberOfStations < fCurrentNumberOfStations) {
243 info <<
"Maximum number of signal stations reached, breaking loop... ("
244 <<
"current number of signal stations is " << fCurrentNumberOfStations
245 <<
" and maximum number of stations is " << fMaxNumberOfStations <<
")";
255 std::vector<std::pair<int, double> > vIdDistance;
258 info <<
"List of suitable stations:";
259 for (
auto& station : rEvent.StationsRange()) {
263 info <<
" " << station.GetId() << endl;
268 station.ClearRejectedReason();
273 vIdDistance.emplace_back(station.GetId(), distance);
277 sort(vIdDistance.begin(), vIdDistance.end(),
ComparePair);
280 if (fCurrentNumberOfStations > vIdDistance.size()) {
282 info <<
"Number of available signal stations is " << vIdDistance.size()
283 <<
" and current number of used stations is " << fCurrentNumberOfStations;
285 INFO(
"All available stations are considered, breaking loop.");
292 for (
unsigned int i = fCurrentNumberOfStations; i < vIdDistance.size(); ++i) {
293 const int stationId = vIdDistance[i].first;
296 info <<
"station " << stationId <<
" is temporarily rejected (distance to shower axis = "
297 << vIdDistance[i].second /
utl::m <<
"m)";
300 fLastAddedStationId = vIdDistance[fCurrentNumberOfStations - 1].first;
308 RdTopDownStationSelector::Finish()
Branch GetTopBranch() const
bool HasParameter(const Parameter i) const
utl::Point GetReferenceCorePosition(const Event &event) const
Returning the reference core position depending on the corresponding flag.
constexpr T Sqr(const T &x)
static double GetDistanceToAxis(const utl::Vector &ShowerAxis, const utl::Point &CorePosition, const utl::Point &AntennaPosition)
computes the distance from the antenna position to the shower "line" defined by the core position and...
Interface class to access to the Radio part of an event.
Interface class to access to the RD Reconstruction of a Shower.
#define INFO(message)
Macro for logging informational messages.
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Station & GetStation(const int stationId)
retrieve station by id throw utl::NonExistentComponentException if n.a.
Detector description interface for RDetector-related data.
#define INFOIntermediate(y)
Class representing a document branch.
double abs(const SVector< n, T > &v)
Header & GetHeader()
access to REvent Header
Top of the hierarchy of the detector description interface.
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
void SetRejectedReason(const unsigned long long int reason)
constexpr double kSpeedOfLight
ResultFlag
Flag returned by module methods to the RunController.
utl::Vector GetReferenceAxis(const Event &event) const
Returning the referencedirection depending on the corresponding flag.
const rdet::RDetector & GetRDetector() const
double GetParameter(const Parameter i) const
double Mean(const std::vector< double > &v)
utl::Point GetPosition() const
Tank position in Site Cartesian Coordinates.
const Station & GetStation(const int stationId) const
Get station by Station Id.
bool ComparePair(const std::pair< int, double > &a, const std::pair< int, double > &b)