MdSdReReconstruction/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 #include <evt/ShowerMRecData.h>
5 
6 #include <sevt/SEvent.h>
7 #include <sevt/SortCriteria.h>
8 #include <sevt/PMTSimData.h>
9 #include <mevt/MEvent.h>
10 
11 #include <utl/ErrorLogger.h>
12 #include <utl/Branch.h>
13 #include <utl/Particle.h>
14 #include <utl/AugerUnits.h>
15 
16 #include <tst/Validatrix.h>
17 #include <fwk/CentralConfig.h>
18 #include <iostream>
19 #include "Validation.h"
20 
21 using namespace std;
22 using namespace evt;
23 using namespace sevt;
24 using namespace mevt;
25 using namespace fwk;
26 using namespace utl;
27 using namespace tst::Validatrix;
28 
29 namespace ValidationNS {
30 
33  INFO("Doing the validation !!!!");
34  Branch topB = CentralConfig::GetInstance() -> GetTopBranch("Validation");
35  topB.GetChild("RefFilename").GetData(fRefFileName);
36  const string mode = topB.GetChild("Mode").Get < string > ();
37 
38  cout << "Validation mode = " << mode << endl;
39 
40  fMode = (mode == "Create") ? Validation::eCreate : Validation::eCompare;
41 
42  fResults = new stringstream;
43 
44  return eSuccess;
45  }
46 
48  Validation::Run(evt::Event & event) {
49  /*********************
50  Shower-Rec Validation
51  **********************/
52  *fResults << BeLabel("Shower_rec");
53 
54  if (!event.HasRecShower())
55  ERROR("Event does not contain a RecShower");
56  const ShowerRecData & showerRec = event.GetRecShower();
57 
58  // SD rec (shower level)
59  if (!showerRec.HasSRecShower())
60  ERROR("RecShower does not have SRecShower");
61 
62  *fResults << BeLabel("Shower_S_rec");
63 
64  const ShowerSRecData & showerSRec = showerRec.GetSRecShower();
65 
66  *fResults << BeLabel("S450");
67  *fResults << BeEqual(showerSRec.GetShowerSize());
68  *fResults << BeLabel("S450e");
69  *fResults << BeCloseAbs(showerSRec.GetShowerSizeError(), /*tolerance*/ 1e-4);
70 
71  // MD rec (shower level)
72  if (!showerRec.HasMRecShower())
73  ERROR("RecShower does not have MRecShower");
74 
75  *fResults << "\n";
76  *fResults << BeLabel("Shower_M_rec");
77 
78  const ShowerMRecData & showerMRec = showerRec.GetMRecShower();
79 
80  *fResults << BeLabel("rho450");
81  *fResults << BeCloseAbs(showerMRec.GetNMuRef(), /*tolerance*/ 1e-5);
82  *fResults << BeLabel("rho450e");
83  *fResults << BeCloseAbs(showerMRec.GetNMuRef(), /*tolerance*/ 1e-4);
84  *fResults << "\n";
85 
86  /**************************
87  SD Station-Level Validation
88  ***************************/
89  if (!event.HasSEvent()) {
90  ERROR("Event should contain an SEvent.");
91  return eFailure;
92  }
93 
94  event.GetSEvent().SortStations(ByIncreasingId());
95  const SEvent & sEvent = event.GetSEvent();
96 
97  *fResults << BeLabel("SD_rec");
98 
99  for (SEvent::ConstStationIterator sIt = sEvent.StationsBegin(); sIt != sEvent.StationsEnd(); ++sIt) {
100  if (sIt -> HasRecData()) {
101  ostringstream label;
102  label << "Station_" << sIt -> GetId();
103  *fResults << BeLabel(label.str());
104  *fResults << BeEqual(sIt -> GetRecData().GetTotalSignal());
105  }
106  }
107 
108  /**************************
109  MD Counter-Level Validation
110  ***************************/
111  if (!event.HasMEvent()) {
112  ERROR("Event should contain an MEvent.");
113  return eFailure;
114  }
115 
116  const MEvent & mEvent = event.GetMEvent();
117 
118  *fResults << "\n";
119  *fResults << BeLabel("MD_rec");
120 
121  for (SEvent::ConstStationIterator sIt = sEvent.StationsBegin(); sIt != sEvent.StationsEnd(); ++sIt) {
122  if (sIt -> HasRecData()) {
123  // getting the counter
124  const mevt::Counter & counter = mEvent.GetCounter(1e5 + sIt -> GetId());
125  // if at least one of the modules is a candidate
126  if (!counter.IsRejected()) {
127 
128  string counterLabel;
129  counterLabel = "Counter_" + to_string(counter.GetId());
130 
131  //Vectors to allocate the number of muons per module
132  vector<double> muonNumber(3, 0);
133  vector<double> muonNumberMC(3, 0);
134 
135  // Iteration over module mIt of station sdId
136  for (mevt::Counter::ModuleConstIterator mIt = counter.ModulesBegin(); mIt != counter.ModulesEnd(); ++mIt) {
137 
138  int mId = mIt -> GetId();
139 
140  if (mIt -> IsRejected()) {
141  muonNumberMC.at(mId - 1) = -1;
142  muonNumber.at(mId - 1) = -1;
143  continue;
144  }
145 
146  // Iteration over scillantors of module mdId -> to get the injected muons, i.e. True Label
147  for (mevt::Module::ScintillatorConstIterator sIt = mIt -> ScintillatorsBegin(); sIt != mIt -> ScintillatorsEnd(); ++sIt) {
148  if (sIt -> HasSimData()) {
149  const mevt::ScintillatorSimData & ssd = sIt -> GetSimData();
150  muonNumberMC.at(mId - 1) += ssd.GetNumberOfInjectedMuons();
151  }
152  } // end of iteration over scillantors of module mdId
153 
154  if (mIt -> HasRecData()) {
155 
156  // Reconstructed number of muons at module level
157  const mevt::ModuleRecData & mRecData = mIt -> GetRecData();
158 
159  if (mRecData.IsSaturated())
160  muonNumber.at(mId - 1) += mRecData.GetNumberOfMuonsLowLimit();
161  else
162  muonNumber.at(mId - 1) += mRecData.GetNumberOfEstimatedMuons();
163 
164  } else
165  muonNumber.at(mId - 1) = -1;
166 
167  } // end of teration over module mIt of station sdId
168 
169  for (size_t i = 0; i < muonNumber.size(); ++i) {
170  *fResults << BeLabel(counterLabel + "_Module_" + to_string(i) + "_rec");
171  *fResults << BeCloseAbs(muonNumber.at(i), /*tolerance*/ 1e-4); // Access the corresponding element in vector 'v' using iterator difference
172  *fResults << BeLabel(counterLabel + "_Module_" + to_string(i) + "_MC");
173  *fResults << BeEqual(muonNumberMC.at(i)); // Access the corresponding element in vector 'vMC' using iterator difference
174  }
175  }
176  }
177  }
178 
179  return eSuccess;
180  }
181 
183  Validation::Finish() {
184  bool comp = true;
185 
186  if (fMode == Validation::eCreate) {
187  INFO("Writing reference file");
188  ofstream fout(fRefFileName.c_str());
189  fout << fResults -> str();
190  fout.close();
191  } else {
192  INFO("Comparing re-reconstruction results to reference file");
193  ifstream savedFile(fRefFileName.c_str());
194  comp = Compare( * fResults, savedFile, /*failOnFirst=*/ false);
195  savedFile.close();
196 
197  // store the new results in a ref file for easier comparison in case of problems
198  string newRef = fRefFileName + ".after-rereconstruction";
199  ofstream fout(newRef.c_str());
200  fout << fResults -> str();
201  fout.close();
202  }
203 
204  delete fResults;
205  fResults = nullptr;
206 
207  return comp ? eSuccess : eFailure;
208  }
209 }
Module level reconstruction data. This class contains all data required by the muon reconstruction...
Definition: ModuleRecData.h:29
StationIterator StationsEnd()
End of all stations.
Definition: SEvent.h:59
bool HasMEvent() const
Interface class to access to the SD Reconstruction of a Shower.
Interface class to access Shower Reconstructed parameters.
Definition: ShowerRecData.h:33
Counter level event data.
bool HasRecShower() const
Interface class to access to the SD part of an event.
Definition: SEvent.h:39
double GetNumberOfEstimatedMuons() const
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
double GetShowerSize() const
void Init()
Initialise the registry.
bool IsRejected() const
Check if the counter is rejected.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
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)
InternalScintillatorCollection::ComponentConstIterator ScintillatorConstIterator
std::string BeLabel(const string &tag)
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
bool HasMRecShower() const
ModuleConstIterator ModulesBegin() const
std::string BeEqual(const T &value)
Definition: Validatrix.h:131
ShowerMRecData & GetMRecShower()
Scintillator level simulation data.
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
int GetId() const
The id of the counter.
ModuleConstIterator ModulesEnd() const
StationIterator StationsBegin()
Beginning of all stations.
Definition: SEvent.h:57
double GetShowerSizeError() const
InternalModuleCollection::ComponentConstIterator ModuleConstIterator
double GetNMuRef() const
Counter & GetCounter(const int cId)
Definition: MEvent.h:34
Interface class to access to the Muon 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
bool HasSRecShower() const
Root of the Muon event hierarchy.
Definition: MEvent.h:25
bool HasSEvent() const
unsigned int GetNumberOfInjectedMuons() const
bool IsSaturated() const
Definition: ModuleRecData.h:85
double GetNumberOfMuonsLowLimit() const

, generated on Tue Sep 26 2023.