5 #include <fwk/CentralConfig.h>
8 #include <utl/ErrorLogger.h>
9 #include <utl/Vector.h>
10 #include <utl/Point.h>
11 #include <utl/RadioGeometryUtilities.h>
12 #include <utl/CoordinateSystemPtr.h>
13 #include <utl/Minou.h>
14 #include <utl/AnalyticCoordinateTransformator.h>
17 #include <evt/Event.h>
18 #include <evt/ShowerRecData.h>
19 #include <evt/ShowerSRecData.h>
20 #include <evt/ShowerRRecData.h>
21 #include <evt/ShowerSimData.h>
24 #include <revt/REvent.h>
25 #include <revt/Header.h>
26 #include <revt/Station.h>
27 #include <revt/StationRecData.h>
28 #include <revt/StationRRecDataQuantities.h>
31 #include <det/Detector.h>
32 #include <rdet/RDetector.h>
35 #include <atm/AerosolDB.h>
36 #include <atm/AerosolZone.h>
37 #include <atm/ProfileResult.h>
38 #include <atm/MonthlyAvgDBProfileModel.h>
39 #include <atm/InclinedAtmosphericProfile.h>
40 #include <atm/SimShowerProfileModel.h>
60 const Vector& showerAxis,
const double tau0)
62 vector<double> expectedTimes;
63 vector<double> timeResiduals;
65 for (
const auto& d : vStationFitData) {
66 const double expTime = (d.antennaPos - showerAxis).GetMag() /
kSpeedOfLight;
67 expectedTimes.push_back(expTime);
70 const double t0 =
TMath::Mean(expectedTimes.begin(), expectedTimes.end());
72 for (
unsigned int i = 0, n = vStationFitData.size(); i < n; ++i) {
73 const double residual = (vStationFitData[i].signalTime - tau0) - (expectedTimes[i] - t0);
74 timeResiduals.push_back(residual);
86 topBranch.
GetChild(
"minNumberOfStations").
GetData(fMinNumberOfStations);
93 const string yesnostr = topBranch.
GetChild(
"allowMultipleCalls").
Get<
string>();
94 fLockParameterStorage = (yesnostr ==
"no");
105 INFOFinal(
"eContinueLoop: No REvent, so no reconstruction");
106 return eContinueLoop;
109 REvent& rEvent =
event.GetREvent();
110 ShowerRRecData& showerrrec =
event.GetRecShower().GetRRecShower();
113 const det::Detector& detector = det::Detector::GetInstance();
118 if (fNumberOfStations < fMinNumberOfStations) {
120 info <<
"Event contains only " << fNumberOfStations
121 <<
" station(s), not enough for spherical fit. Event is skipped";
123 return eContinueLoop;
127 det::Detector::GetInstance().GetReferenceCoordinateSystem();
133 if (fUseInitialGeometry ==
"SD") {
135 WARNING(
"Event has no SRecShower. Event is skipped");
136 return eContinueLoop;
138 initialShowerAxis =
event.GetRecShower().GetSRecShower().GetAxis();
139 initialCore =
event.GetRecShower().GetSRecShower().GetCorePosition();
140 }
else if (fUseInitialGeometry ==
"MC") {
142 WARNING(
"Event has no simulated shower. Event is skipped");
143 return eContinueLoop;
145 initialShowerAxis = -
event.GetSimShower().GetDirection();
146 initialCore =
event.GetSimShower().GetPosition();
147 }
else if (fUseInitialGeometry ==
"RD") {
149 WARNING(
"Event has no HasRRecShower. Event is skipped");
150 return eContinueLoop;
152 initialShowerAxis = showerrrec.
GetAxis();
154 }
else if (fUseInitialGeometry ==
"Reference") {
156 WARNING(
"Event has no HasRRecShower. Event is skipped");
157 return eContinueLoop;
159 initialShowerAxis =
event.GetRecShower().GetRRecShower().GetReferenceAxis(event);
160 initialCore =
event.GetRecShower().GetRRecShower().GetReferenceCorePosition(event);
164 const double initialZenith = initialShowerAxis.
GetTheta(localCS);
165 const double initialAzimuth = initialShowerAxis.
GetPhi(localCS);
168 const double avgShowerXmax = 750*
g/
cm2;
173 const double initialRadius =
abs(distanceFromDepth.
Y(avgShowerXmax));
176 info <<
"Event has " << fNumberOfStations <<
" antennas, "
177 <<
"initial geometry is " << fUseInitialGeometry <<
"\n"
178 <<
"Zenith = " << initialZenith /
deg <<
", azimuth = "
179 << initialAzimuth /
deg <<
", radius = " << initialRadius /
km;
185 vector<StationFitData> vStationFitData;
187 for (
const auto& station : rEvent.SignalStationsRange()) {
197 vStationFitData.push_back(stationFitData);
201 tau0 /= vStationFitData.size();
206 vector<Minou::ParameterDef> parameters;
207 parameters.emplace_back(
"radius", initialRadius, 100, 0, fRadiusMax,
false);
208 parameters.emplace_back(
"zenith", initialZenith, 0.1, fThetaMin, fThetaMax,
false);
209 parameters.emplace_back(
"azimuth", initialAzimuth, 0.01, 0, 0,
false);
210 parameters.emplace_back(
"gamma", 1, 1e-3, 0, 0,
true);
215 if (fInfoLevel >= eInfoIntermediate)
220 showerrrec.
SetParameter(eFitSuccess, 0, fLockParameterStorage);
221 return eContinueLoop;
234 const auto tmpFitResult = min.GetParameters();
235 const auto bestParameterError = min.GetParametersAndErrors();
236 const TMatrixD pcov = min.GetCovarianceMatrix();
238 const double radius = bestParameterError.at(0).first;
239 const double theta = bestParameterError.at(1).first;
240 const double phi = bestParameterError.at(2).first;
241 const double gamma = bestParameterError.at(3).first;
243 const double radiusErr = bestParameterError.at(0).second;
244 const double thetaErr = bestParameterError.at(1).second;
245 const double phiErr = bestParameterError.at(2).second;
246 const double gammaErr = bestParameterError.at(3).second;
250 const int ndf =
max(fitFunction.
GetNDF(), 1);
251 const double chi2 = fitFunction.
GetChi2(tmpFitResult);
254 info <<
"Spherical wavefront fit succesfull \n"
255 "\ttheta = " << theta /
deg <<
" +/- " << thetaErr <<
"\n"
256 "\tphi = " << phi /
deg <<
" +/- " << phiErr /
deg <<
"\n"
257 "\tR = " << radius /
km <<
" +/- " << radiusErr /
km <<
"\n"
258 "\tchi2 / ndf = " << chi2 <<
" / " << ndf <<
" = " << chi2/ndf;
262 const Vector axis(radius, theta, phi, localCS, Vector::kSpherical);
263 showerrrec.
SetParameter(eShowerAxisX, axis.
GetX(localCS), fLockParameterStorage);
264 showerrrec.
SetParameter(eShowerAxisY, axis.
GetY(localCS), fLockParameterStorage);
265 showerrrec.
SetParameter(eShowerAxisZ, axis.
GetZ(localCS), fLockParameterStorage);
270 showerrrec.
SetParameter(eFitSuccess, 1, fLockParameterStorage);
271 showerrrec.
SetParameter(eWaveFitChi2, chi2, fLockParameterStorage);
272 showerrrec.
SetParameter(eWaveFitNDF, ndf, fLockParameterStorage);
275 AnalyticCoordinateTransformator::GetCartesianCovarianceFromSpherical(0, 0, radius, theta, phi,
276 pcov(0,0), pcov(1,1), pcov(2,2), pcov(0,1), pcov(0,2), pcov(1,2));
279 AnalyticCoordinateTransformator::GetCartesianCovarianceFromSpherical(1, 1, radius, theta, phi,
280 pcov(0,0), pcov(1,1), pcov(2,2), pcov(0,1), pcov(0,2), pcov(1,2));
283 AnalyticCoordinateTransformator::GetCartesianCovarianceFromSpherical(2, 2, radius, theta, phi,
284 pcov(0,0), pcov(1,1), pcov(2,2), pcov(0,1), pcov(0,2), pcov(1,2));
287 AnalyticCoordinateTransformator::GetCartesianCovarianceFromSpherical(0, 1, radius, theta, phi,
288 pcov(0,0), pcov(1,1), pcov(2,2), pcov(0,1), pcov(0,2), pcov(1,2));
291 AnalyticCoordinateTransformator::GetCartesianCovarianceFromSpherical(0, 2, radius, theta, phi,
292 pcov(0,0), pcov(1,1), pcov(2,2), pcov(0,1), pcov(0,2), pcov(1,2));
295 AnalyticCoordinateTransformator::GetCartesianCovarianceFromSpherical(1, 2, radius, theta, phi,
296 pcov(0,0), pcov(1,1), pcov(2,2), pcov(0,1), pcov(0,2), pcov(1,2));
300 const vector<double> timeResiduals =
GetTimeResiduals(vStationFitData, axis, tau0);
303 for (
auto& station : rEvent.SignalStationsRange()) {
306 sRec.
SetParameter(eTimeResidual, timeResiduals[iStation], fLockParameterStorage);
312 sRec.
SetParameter(eSignalArrivalDirectionX, axis.
GetX(stationCS), fLockParameterStorage);
313 sRec.
SetParameter(eSignalArrivalDirectionY, axis.
GetY(stationCS), fLockParameterStorage);
314 sRec.
SetParameter(eSignalArrivalDirectionZ, axis.
GetZ(stationCS), fLockParameterStorage);
324 RdSphericalFit::Finish()
void SetVerbose(const bool verbose)
Branch GetTopBranch() const
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Get the Auger reference system centered on the station.
Class to access station level reconstructed data.
Top of the interface to Atmosphere information.
void SetParameter(Parameter i, double value, bool lock=true)
utl::Vector GetAxis() const
Returns vector of the shower axis.
void SetParameterError(Parameter i, double value, bool lock=true)
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
void InitSlantProfileModel(const utl::Point &core, const utl::Vector &dir, const double deltaX) const
Interface class to access to the Radio part of an event.
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
ShowerRecData & GetRecShower()
Interface class to access to the RD Reconstruction of a Shower.
bool HasSimShower() const
double GetParameterError(const Parameter i) const
const atm::ProfileResult & EvaluateDistanceVsSlantDepth() const
Table of distance as a function of slant depth.
vector< double > GetTimeResiduals(const vector< StationFitData > &vStationFitData, const Vector &showerAxis, const double tau0)
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
double GetChi2(const std::vector< double > &pars)
double Y(const double x) const
Get the Y value (coordinate) for given X (ordinate)
Detector description interface for RDetector-related data.
const atm::Atmosphere & GetAtmosphere() const
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
#define INFOIntermediate(y)
Class representing a document branch.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Class describing the Atmospheric profile.
double abs(const SVector< n, T > &v)
bool HasRRecShower() const
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.
int GetNumberOfSignalStations() const
Get number of signal stations in the event.
double GetParameter(const Parameter i) const
double GetY(const CoordinateSystemPtr &coordinateSystem) const
constexpr double kSpeedOfLight
ResultFlag
Flag returned by module methods to the RunController.
int Minimize(const int n=500)
void SetParameterError(Parameter i, double value, bool lock=true)
void SetParameter(Parameter i, double value, bool lock=true)
utl::Point GetCorePosition() const
returns pointer of the position vector of the core in the reference coor system
const rdet::RDetector & GetRDetector() const
double Mean(const std::vector< double > &v)
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
utl::Point GetPosition() const
Tank position in Site Cartesian Coordinates.
const Station & GetStation(const int stationId) const
Get station by Station Id.
bool HasSRecShower() const
void SetParameterCovariance(Parameter i1, Parameter i2, double value, bool lock=true)