ReReconstruction/Validation.cc
Go to the documentation of this file.
1 #include <evt/Event.h>
2 #include <evt/ShowerRecData.h>
3 #include <evt/ShowerSRecData.h>
4 
5 #include <sevt/SEvent.h>
6 #include <sevt/SortCriteria.h>
7 #include <sevt/PMTSimData.h>
8 
9 #include <fevt/FEvent.h>
10 #include <fevt/Eye.h>
11 #include <fevt/Telescope.h>
12 #include <fevt/EyeRecData.h>
13 #include <fevt/TelescopeRecData.h>
14 
15 #include <evt/ShowerFRecData.h>
16 
17 #include <utl/ErrorLogger.h>
18 #include <utl/Branch.h>
19 #include <utl/Particle.h>
20 #include <utl/AugerUnits.h>
21 
22 #include <tst/Validatrix.h>
23 
24 #include <fwk/CentralConfig.h>
25 
26 #include <iostream>
27 
28 #include "Validation.h"
29 
30 using namespace std;
31 using namespace evt;
32 using namespace sevt;
33 using namespace fevt;
34 using namespace fwk;
35 using namespace utl;
36 using namespace tst::Validatrix;
37 
38 
39 namespace ValidationNS {
40 
43  {
44  INFO("Doing the validation !!!!");
45  Branch topB = CentralConfig::GetInstance()->GetTopBranch("Validation");
46  topB.GetChild("RefFilename").GetData(fRefFileName);
47  const string mode = topB.GetChild("Mode").Get<string>();
48 
49  cout << "Validation mode = " << mode << endl;
50 
51  fMode = (mode == "Create") ? Validation::eCreate : Validation::eCompare;
52 
53  fResults = new stringstream;
54 
55  return eSuccess;
56  }
57 
58 
60  Validation::Run(evt::Event& event)
61  {
62  // SD
63  if (!event.HasSEvent()) {
64  ERROR("Event should contain an SEvent.");
65  return eFailure;
66  }
67 
68  event.GetSEvent().SortStations(ByIncreasingId());
69  const SEvent& sEvent = event.GetSEvent();
70 
71  *fResults << BeLabel("SD_rec");
72 
73  for (SEvent::ConstStationIterator sIt = sEvent.StationsBegin();
74  sIt != sEvent.StationsEnd(); ++sIt) {
75  if (sIt->HasRecData()) {
76  ostringstream label;
77  label << "Station_" << sIt->GetId();
78  *fResults << BeLabel(label.str());
79  *fResults << BeCloseRel(sIt->GetRecData().GetTotalSignal(), /*tolerance*/0.05);
80  }
81  }
82 
83  // FD
84  if (!event.HasFEvent()) {
85  ERROR("Event should contain an FEvent.");
86  return eFailure;
87  }
88 
89  const FEvent& fEvent = event.GetFEvent();
90 
91  *fResults << BeLabel("FD_rec");
92 
93  for (FEvent::ConstEyeIterator eIt = fEvent.EyesBegin(ComponentSelector::eHasData);
94  eIt != fEvent.EyesEnd(ComponentSelector::eHasData); ++eIt) {
95 
96  if (eIt->HasRecData()) {
97  ostringstream eLabel;
98  eLabel << "Eye_" << eIt->GetId();
99  *fResults << BeLabel(eLabel.str());
100 
101  if (eIt->GetRecData().HasFRecShower()) {
102  const ShowerFRecData& showerRec = eIt->GetRecData().GetFRecShower();
103  *fResults << BeLabel("Stations_in_fit");
104  *fResults << BeEqual(showerRec.GetStationIds());
105 
106  *fResults << BeLabel("TotalEnergy(EeV)");
107  *fResults << BeCloseRel(showerRec.GetTotalEnergy()/EeV, /*tolerance*/1e-5);
108 
109  *fResults << BeLabel("TotalEnergyError(EeV)");
110  *fResults << BeCloseRel(showerRec.GetTotalEnergyError()/EeV, /*tolerance*/5e-2);
111 
112  *fResults << BeLabel("Xmax(g/cm2)");
113  *fResults << BeCloseRel(showerRec.HasGHParameters()?
114  showerRec.GetGHParameters().GetXMax()/gram*cm2:
115  0., 1e-5);
116 
117  *fResults << BeLabel("Xmax2Error");
118  *fResults << BeCloseRel(showerRec.HasGHParameters()?
119  showerRec.GetGHParameters().GetXMaxError()/gram*cm2 : 0., 5e-2);
120  }
121  }
122 
123  for (Eye::ConstTelescopeIterator tIt = eIt->TelescopesBegin(ComponentSelector::eHasData);
124  tIt != eIt->TelescopesEnd(ComponentSelector::eHasData); ++tIt) {
125  if (tIt->HasRecData()) {
126  ostringstream tLabel;
127  tLabel << "Telescope_" << tIt->GetId();
128  *fResults << BeLabel(tLabel.str());
129 
130  const TelescopeRecData& tRec = tIt->GetRecData();
131  //*fResults << BeLabel("zeta");
132  //*fResults << BeCloseRel(tRec.GetZeta(), /*tolerance*/0.05);
133  *fResults << BeLabel("photon_trace_start_sec");
134  *fResults << BeEqual(tRec.GetPhotonsStartTime().GetGPSSecond());
135  *fResults << BeLabel("photon_trace_start_ns");
136  *fResults << BeCloseAbs(tRec.GetPhotonsStartTime().GetGPSNanoSecond(), 50*ns);
137  }
138  }
139 
140  }
141 
142  *fResults << BeLabel("Shower_rec");
143 
144  // Shower-level rec data
145  if (!event.HasRecShower())
146  ERROR("Event does not contain a RecShower");
147  const ShowerRecData& showerRec = event.GetRecShower();
148 
149  // SD rec (shower level)
150 
151  if (!showerRec.HasSRecShower())
152  ERROR("RecShower does not have SRecShower");
153 
154  *fResults << BeLabel("Shower_S_rec");
155 
156  const ShowerSRecData& showerSRec = showerRec.GetSRecShower();
157 
158  *fResults << BeLabel("S1000");
159  *fResults << BeCloseRel(showerSRec.GetShowerSize(), 1e-5);
160 
161  return eSuccess;
162  }
163 
164 
166  Validation::Finish()
167  {
168  bool comp = true;
169 
170  if (fMode == Validation::eCreate) {
171  INFO("Writing reference file");
172  ofstream fout(fRefFileName.c_str());
173  fout << fResults->str();
174  fout.close();
175  } else {
176  INFO("Comparing re-reconstruction results to reference file");
177  ifstream savedFile(fRefFileName.c_str());
178  comp = Compare(*fResults, savedFile, /*failOnFirst=*/false);
179  savedFile.close();
180 
181  // store the new results in a ref file for easier comparison in case of problems
182  string newRef = fRefFileName + ".after-rereconstruction";
183  ofstream fout(newRef.c_str());
184  fout << fResults->str();
185  fout.close();
186  }
187 
188  delete fResults;
189  fResults = nullptr;
190 
191  return comp ? eSuccess : eFailure;
192  }
193 
194 }
Branch GetTopBranch() const
Definition: Branch.cc:63
StationIterator StationsEnd()
End of all stations.
Definition: SEvent.h:59
std::string BeCloseRel(const T &value, const double tolerance=kDefaultTolerance)
Definition: Validatrix.h:153
Interface class to access to the SD Reconstruction of a Shower.
boost::filter_iterator< ComponentSelector, ConstAllEyeIterator > ConstEyeIterator
Definition: FEvent.h:56
Interface class to access Shower Reconstructed parameters.
Definition: ShowerRecData.h:33
bool HasRecShower() const
double GetTotalEnergy() const
retrieve total energy and its uncertainty
bool HasFEvent() const
Interface class to access to the SD part of an event.
Definition: SEvent.h:39
std::vector< unsigned short int > & GetStationIds()
retrieve vector of station IDs used in hybrid fit
EyeIterator EyesEnd(const ComponentSelector::Status status)
Definition: FEvent.h:66
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
double GetShowerSize() const
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
const double EeV
Definition: GalacticUnits.h:34
ShowerSRecData & GetSRecShower()
std::string BeCloseAbs(const T &value, const double tolerance=kDefaultTolerance)
Definition: Validatrix.h:141
T Get() const
Definition: Branch.h:271
Class representing a document branch.
Definition: Branch.h:107
bool Compare(const string &oldFilename, const string &newFilename, const bool failOnFirst)
const double ns
std::string BeLabel(const string &tag)
EyeIterator EyesBegin(const ComponentSelector::Status status)
Definition: FEvent.h:58
Telescope-specific shower reconstruction data.
double GetTotalEnergyError(const EUncertaintyType type=eTotal) const
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
Top of Fluorescence Detector event hierarchy.
Definition: FEvent.h:33
std::string BeEqual(const T &value)
Definition: Validatrix.h:131
bool HasGHParameters() const
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
StationIterator StationsBegin()
Beginning of all stations.
Definition: SEvent.h:57
Interface class to access to Fluorescence reconstruction of a Shower.
boost::indirect_iterator< InternalConstStationIterator, const Station & > ConstStationIterator
Definition: SEvent.h:54
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
constexpr double gram
Definition: AugerUnits.h:195
bool HasSRecShower() const
bool HasSEvent() const
boost::filter_iterator< ComponentSelector, ConstAllTelescopeIterator > ConstTelescopeIterator
Definition: FEvent/Eye.h:73
constexpr double cm2
Definition: AugerUnits.h:118

, generated on Tue Sep 26 2023.