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