3 #include <fwk/CentralConfig.h>
6 #include <evt/ShowerRecData.h>
7 #include <evt/ShowerRRecData.h>
9 #include <revt/REvent.h>
10 #include <revt/Header.h>
12 #include <utl/ErrorLogger.h>
13 #include <utl/Reader.h>
14 #include <utl/config.h>
31 CentralConfig::GetInstance()->
GetTopBranch(
"RdDirectionConvergenceChecker");
47 INFOFinal(
"eContinueLoop: No REvent, so no reconstruction");
51 REvent& rEvent =
event.GetREvent();
58 if (!showerrrec.
HasParameter(eNumberOfIterationsInDirectionFit)) {
60 info <<
"New event with ID: " << eventId;
67 showerrrec.
SetParameter(eNumberOfIterationsInDirectionFit, 0,
false);
71 unsigned int currentIteration = showerrrec.
GetParameter(eNumberOfIterationsInDirectionFit) + 1;
72 showerrrec.
SetParameter(eNumberOfIterationsInDirectionFit, currentIteration,
false);
74 if (currentIteration == 1) {
79 INFO(
"No reconstructed shower axis was found in first iteration. Breaking the loop without axis!");
85 fAllAzimuths.push_back(showerrrec.
GetAzimuth());
86 fAllZeniths.push_back(showerrrec.
GetZenith());
92 info <<
"Currently in " << currentIteration <<
" iteration for event " << eventId;
96 if (currentIteration > fMaxIterations) {
99 showerrrec.
SetParameter(eShowerAxisX, ePreFitShowerAxisX,
false);
100 showerrrec.
SetParameter(eShowerAxisY, ePreFitShowerAxisY,
false);
101 showerrrec.
SetParameter(eShowerAxisZ, ePreFitShowerAxisZ,
false);
102 showerrrec.
SetParameter(eNumberOfIterationsInDirectionFit, 1,
false);
104 fAllAzimuths.clear();
107 fAllAzimuths.push_back(showerrrec.
GetAzimuth());
108 fAllZeniths.push_back(showerrrec.
GetZenith());
110 INFOFinal(
"Iteration with mirrowed zenith did not converge. "
111 "Restart iteration with original axis of the pre-fit");
114 INFO(
"Iteration limit reached without convergence! Killing Loop!");
122 INFO(
"Previous fit failed, killing loop!");
128 const double curZen = showerrrec.
GetZenith();
129 const double curAzi = showerrrec.
GetAzimuth();
132 const double angleDiff = GetAngularDifference(curZen, curAzi, fAllZeniths.back(), fAllAzimuths.back());
134 info <<
"angular difference: " << angleDiff <<
" rad, " << angleDiff /
utl::deg <<
" deg";
137 if (fInfoLevel >= eInfoDebug) {
139 info <<
"Current iteration: " << currentIteration <<
", "
140 <<
"last azimuth: " << fAllAzimuths.back() /
deg <<
", current one: " << curAzi /
deg <<
", "
141 <<
"last zenith: " << fAllZeniths.back() /
deg <<
", curZen one: " << curZen /
deg <<
", "
142 <<
"angular difference: " << angleDiff /
deg;
147 if (
abs(angleDiff) <= fAngleEpsilon){
151 if (fCheckMirrorZenith && curZen /
deg > 90 && !showerrrec.
HasParameter(eMirroredZenith)) {
152 const auto oldZAxis = showerrrec.
GetParameter(eShowerAxisZ);
153 showerrrec.
SetParameter(eShowerAxisZ, -oldZAxis,
false);
155 showerrrec.
SetParameter(eNumberOfIterationsInDirectionFit, 1,
false);
157 INFOFinal(
"Upwarding going shower detected, restart iteration with mirrowed zenith angle");
170 if (fAllAzimuths.size() > 4 && fAllZeniths.size() > 4) {
172 vector<double> latestAzi(fAllAzimuths.end() - 4, fAllAzimuths.end());
173 vector<double> latestZen(fAllZeniths.end() - 4, fAllZeniths.end());
175 reverse(latestAzi.begin() , latestAzi.end());
176 reverse(latestZen.begin() , latestZen.end());
179 info <<
"Azimuth 0 - 1: " << (latestAzi[0] - latestAzi[1]) /
degree <<
"\n"
180 <<
"Azimuth 1 - 2: " << (latestAzi[1] - latestAzi[2]) /
degree <<
"\n"
181 <<
"Azimuth 2 - 3: " << (latestAzi[2] - latestAzi[3]) /
degree <<
"\n"
182 <<
"Zenith 0 - 1: " << (latestZen[0] - latestZen[1]) /
degree <<
"\n"
183 <<
"Zenith 1 - 2: " << (latestZen[1] - latestZen[2]) /
degree <<
"\n"
184 <<
"Zenith 2 - 3: " << (latestZen[2] - latestZen[3]) /
degree <<
"\n";
187 const double sa1 = GetAngularDifference(latestZen[0], latestAzi[0], latestZen[1], latestAzi[1]);
188 const double sa2 = GetAngularDifference(latestZen[1], latestAzi[1], latestZen[2], latestAzi[2]);
189 const double sa3 = GetAngularDifference(latestZen[2], latestAzi[2], latestZen[3], latestAzi[3]);
192 INFO(
"Alternation detected, breaking loop ...");
200 fAllAzimuths.push_back(curAzi);
201 fAllZeniths.push_back(curZen);
208 RdDirectionConvergenceChecker::Finish()
215 RdDirectionConvergenceChecker::GetAngularDifference(
const double zen1,
const double azim1,
216 const double zen2,
const double azim2)
221 curDirection = sin(zen1)*cos(azim1), sin(zen1)*sin(azim1), cos(zen1);
222 lastDirection = sin(zen2)*cos(azim2), sin(zen2)*sin(azim2), cos(zen2);
224 return Angle(curDirection, lastDirection);
Branch GetTopBranch() const
void SetParameter(Parameter i, double value, bool lock=true)
bool HasParameter(const Parameter i) const
double Angle(const double theta1, const double phi1, const double theta2, const double phi2)
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.
void reverse(double arr[], int count)
#define INFOIntermediate(y)
Class representing a document branch.
double GetZenith() const
returns the zenith angle (from the wave fit)
bool HasAxis() const
Return true if all 3 axis parameter are set.
double abs(const SVector< n, T > &v)
Header & GetHeader()
access to REvent Header
double GetAzimuth() const
returns the azimuth angle (from the wave fit)
void GetData(bool &b) const
Overloads of the GetData member template function.
ResultFlag
Flag returned by module methods to the RunController.
double GetParameter(const Parameter i) const