RdIndependentSimCheck/Verification.cc
Go to the documentation of this file.
1 #include <evt/Event.h>
2 #include <evt/ShowerRecData.h>
3 
4 #include <utl/ErrorLogger.h>
5 #include <utl/Branch.h>
6 #include <utl/Particle.h>
7 #include <utl/AugerUnits.h>
8 
9 #include <fwk/CentralConfig.h>
10 
11 #include <revt/REvent.h>
12 #include <revt/Header.h>
13 #include <revt/Station.h>
14 #include <revt/StationRecData.h>
15 #include <revt/StationRRecDataQuantities.h>
16 #include <evt/ShowerRecData.h>
17 #include <evt/ShowerRRecData.h>
18 
19 #include <utl/Trace.h>
20 #include <utl/TraceAlgorithm.h>
21 #include <utl/ErrorLogger.h>
22 #include <utl/Reader.h>
23 #include <utl/config.h>
24 #include <utl/AugerUnits.h>
25 #include <utl/CoordinateSystemPtr.h>
26 #include <utl/CoordinateSystem.h>
27 #include <fwk/LocalCoordinateSystem.h>
28 #include <fwk/CoordinateSystemRegistry.h>
29 
30 #include "Verification.h"
31 #include <tst/Validatrix.h>
32 
33 #include <iostream>
34 #include <string>
35 
36 using namespace std;
37 using namespace evt;
38 using namespace fwk;
39 using namespace utl;
40 using namespace VerificationRadio;
41 using namespace revt;
42 using namespace tst::Validatrix;
43 
44 
47 {
48  Branch topB = CentralConfig::GetInstance()->GetTopBranch("Verification");
49 
50  // get the coordinate system information
51  const string csString = topB.GetChild("coordinateSystemId").Get<string>();
52  fReferenceCS = fwk::CoordinateSystemRegistry::Get(csString);
53 
54  // loop through all the children and fill the list of tests to be performed
55  for (Branch b = topB.GetFirstChild(); b; b = b.GetNextSibling()) {
56  // instantiate and initialize variables to hold values
57  unsigned long parameterId = 0;
58  string parameterName;
59  bool useAbsoluteTolerance = false;
60  double tolerance = 0;
61  // see if current branch is relevant
62  if (b.GetName() == "StationQuantity") {
63  b.GetChild("ParameterId").GetData(parameterId);
64  b.GetChild("ParameterName").GetData(parameterName);
65  b.GetChild("UseAbsoluteTolerance").GetData(useAbsoluteTolerance);
66  b.GetChild("Tolerance").GetData(tolerance);
67  fStationTests.push_back(TestInformation(parameterId, parameterName, useAbsoluteTolerance, tolerance));
68  } else if (b.GetName() == "ShowerQuantity") {
69  b.GetChild("ParameterId").GetData(parameterId);
70  b.GetChild("ParameterName").GetData(parameterName);
71  b.GetChild("UseAbsoluteTolerance").GetData(useAbsoluteTolerance);
72  b.GetChild("Tolerance").GetData(tolerance);
73  fShowerTests.push_back(TestInformation(parameterId, parameterName, useAbsoluteTolerance, tolerance));
74  }
75  }
76 
77  // get the name of the file hosting the reference values
78  topB.GetChild("RefFileName").GetData(fRefFileName);
79 
80  // find out if we should compare or create the reference values
81  const string mode = topB.GetChild("Mode").Get<string>();
82  stringstream infoString;
83  infoString <<"Validation mode = " << mode;
84  INFO(infoString.str());
85  if (mode == "Create")
86  fMode = Verification::eCreate;
87  else
88  fMode = Verification::eCompare;
89 
90  // set up the stringstream for writing results
91  fTestResults = new stringstream;
92 
93  return eSuccess;
94 }
95 
96 
98 Verification::Run(evt::Event& event)
99 {
100  ostringstream info;
101  info << "Run validation for radio event E" << event.GetREvent().GetHeader().GetId();
102  INFO(info);
103 
104  *fTestResults << BeLabel("Verification for Radio:");
105 
106  if (!event.HasREvent()) {
107  *fTestResults << BeLabel("No radio event found! Test failed");
108  ERROR("No radio event found! Test failed");
109  return eFailure;
110  }
111  REvent& rEvent = event.GetREvent();
112 
113  if (!event.HasRecShower()) {
114  *fTestResults << BeLabel("No reconstructed shower found! Test failed");
115  ERROR("No reconstructed shower found! Test failed");
116  return eFailure;
117  }
118 
119  if (!event.GetRecShower().HasRRecShower()) {
120  *fTestResults << BeLabel("No reconstructed radio shower found! Test failed");
121  ERROR("No reconstructed radio shower found! Test failed");
122  return eFailure;
123  }
124  ShowerRRecData& rRecShower=event.GetRecShower().GetRRecShower();
125 
126  // check the event id
127  *fTestResults << BeLabel("Run number:")
128  << BeEqual(rEvent.GetHeader().GetRunNumber())
129  << BeLabel("Eventid:")
130  << BeEqual(rEvent.GetHeader().GetId());
131 
132  // do all the tests on shower level
133  *fTestResults << BeLabel("Tests on radio shower level:");
134  stringstream label;
135  for (const auto& info : fShowerTests) {
136  label.str("");
137  label << "R" << rEvent.GetHeader().GetRunNumber() << "-E" << rEvent.GetHeader().GetId() << "-"
138  << info.fParameterId << "->" << info.fParameterName;
139  *fTestResults << BeLabel(label.str());
140  if (rRecShower.HasParameter(ShowerRRecDataQuantities(info.fParameterId))) {
141  if (info.fUseAbsoluteTolerance)
142  *fTestResults << BeCloseAbs(rRecShower.GetParameter(ShowerRRecDataQuantities(info.fParameterId)),
143  info.fTolerance);
144  else
145  *fTestResults << BeCloseRel(rRecShower.GetParameter(ShowerRRecDataQuantities(info.fParameterId)),
146  info.fTolerance);
147  } else {
148  *fTestResults << BeEqual(-1);
149  }
150  label << "Error";
151  *fTestResults << BeLabel(label.str());
152  if (rRecShower.HasParameterError(ShowerRRecDataQuantities(info.fParameterId))) {
153  if (info.fUseAbsoluteTolerance)
154  *fTestResults << BeCloseAbs(rRecShower.GetParameterError(ShowerRRecDataQuantities(info.fParameterId)),
155  info.fTolerance);
156  else
157  *fTestResults << BeCloseRel(rRecShower.GetParameterError(ShowerRRecDataQuantities(info.fParameterId)),
158  info.fTolerance);
159  } else {
160  *fTestResults << BeEqual(-1);
161  }
162  }
163 
164  // now do all the tests on station level
165  *fTestResults << BeLabel("Tests on radio station level:");
166  for (const auto& station : rEvent.StationsRange()) {
167 
168  if (!station.HasRecData()) {
169  *fTestResults << BeLabel("No radio reconstructed data on station level found! Test failed");
170  ERROR("No radio reconstructed data on station level found! Test failed");
171  return eFailure;
172  }
173 
174  for (const auto& info : fStationTests) {
175  label.str("");
176  label << "R" << rEvent.GetHeader().GetRunNumber() << "-E" << rEvent.GetHeader().GetId() << "-S"
177  << station.GetId() << "-" << info.fParameterId << "->" << info.fParameterName;
178  *fTestResults << BeLabel(label.str());
179  if (station.GetRecData().HasParameter(StationRRecDataQuantities(info.fParameterId))) {
180  if (info.fUseAbsoluteTolerance)
181  *fTestResults << BeCloseAbs(station.GetRecData().GetParameter(StationRRecDataQuantities(info.fParameterId)),
182  info.fTolerance);
183  else
184  *fTestResults << BeCloseRel(station.GetRecData().GetParameter(StationRRecDataQuantities(info.fParameterId)),
185  info.fTolerance);
186  } else {
187  *fTestResults << BeEqual(-1);
188  }
189  label << "Error";
190  *fTestResults << BeLabel(label.str());
191  if (station.GetRecData().HasParameterError(StationRRecDataQuantities(info.fParameterId))) {
192  if (info.fUseAbsoluteTolerance)
193  *fTestResults << BeCloseAbs(station.GetRecData().GetParameterError(StationRRecDataQuantities(info.fParameterId)),
194  info.fTolerance);
195  else
196  *fTestResults << BeCloseRel(station.GetRecData().GetParameterError(StationRRecDataQuantities(info.fParameterId)),
197  info.fTolerance);
198  } else {
199  *fTestResults << BeEqual(-1);
200  }
201  }
202  }
203 
204  return eSuccess;
205 }
206 
207 
209 Verification::Finish()
210 {
211  bool comp = true;
212 
213  if (fMode == Verification::eCreate) {
214  INFO("Writing reference file");
215  ofstream fout(fRefFileName);
216  fout << fTestResults->str();
217  fout.close();
218  } else {
219  INFO("Comparing radio reconstruction results to reference file");
220  ifstream savedFile(fRefFileName);
221  comp = Compare(*fTestResults, savedFile, /*failOnFirst=*/false);
222  savedFile.close();
223 
224  if (comp) {
225  INFO("");
226  INFO("#--------------------------------#");
227  INFO(":all radio tests were successful:");
228  INFO("#--------------------------------#");
229  INFO("");
230  } else {
231  INFO("");
232  INFO("#------------------------------#");
233  INFO(":one or more radio tests failed:");
234  INFO("#------------------------------#");
235  INFO("");
236  }
237 
238  // store the new results in a ref file for easier comparison in case of problems
239  const string newRef = fRefFileName + ".new";
240  ofstream fout(newRef);
241  fout << fTestResults->str();
242  fout.close();
243  }
244 
245  // delete the stringstream
246  delete fTestResults;
247  fTestResults = nullptr;
248 
249  return (comp) ? eSuccess : eFailure;
250 }
Branch GetTopBranch() const
Definition: Branch.cc:63
bool HasParameter(const Parameter i) const
std::string BeCloseRel(const T &value, const double tolerance=kDefaultTolerance)
Definition: Validatrix.h:153
bool HasParameterError(const Parameter i) const
bool HasRecShower() const
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
ShowerRecData & GetRecShower()
Interface class to access to the RD Reconstruction of a Shower.
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
bool HasREvent() const
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)
std::string BeLabel(const string &tag)
bool HasRRecShower() const
Header & GetHeader()
access to REvent Header
Definition: REvent.h:239
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
std::string BeEqual(const T &value)
Definition: Validatrix.h:131
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
int GetRunNumber() const
Event id in the run (Start at zero at the beginning of each run) /provided by the daq...
Definition: REvent/Header.h:22
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
double GetParameter(const Parameter i) const
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
double GetParameterError(const Parameter i) const
int GetId() const
Definition: REvent/Header.h:21

, generated on Tue Sep 26 2023.