RdSdCheck/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  ostringstream info;
83  info << "Validation mode = " << mode;
84  INFO(info);
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  ostringstream label;
135  for (const auto& info : fShowerTests) {
136  label.str("");
137  label << "R" << rEvent.GetHeader().GetRunNumber() << "-E" << rEvent.GetHeader().GetId() << "-" << info.fParameterId << "->" << info.fParameterName;
138  *fTestResults << BeLabel(label.str());
139  if (rRecShower.HasParameter(ShowerRRecDataQuantities(info.fParameterId))) {
140  if (info.fUseAbsoluteTolerance)
141  *fTestResults << BeCloseAbs(rRecShower.GetParameter(ShowerRRecDataQuantities(info.fParameterId)), info.fTolerance);
142  else
143  *fTestResults << BeCloseRel(rRecShower.GetParameter(ShowerRRecDataQuantities(info.fParameterId)), info.fTolerance);
144  } else {
145  *fTestResults << BeEqual(-1);
146  }
147  label << "Error";
148  *fTestResults << BeLabel(label.str());
149  if (rRecShower.HasParameterError(ShowerRRecDataQuantities(info.fParameterId))) {
150  if (info.fUseAbsoluteTolerance)
151  *fTestResults << BeCloseAbs(rRecShower.GetParameterError(ShowerRRecDataQuantities(info.fParameterId)), info.fTolerance);
152  else
153  *fTestResults << BeCloseRel(rRecShower.GetParameterError(ShowerRRecDataQuantities(info.fParameterId)), info.fTolerance);
154  } else {
155  *fTestResults << BeEqual(-1);
156  }
157  }
158 
159  // now do all the tests on station level
160  *fTestResults << BeLabel("Tests on radio station level:");
161  for (REvent::StationIterator sIt = rEvent.StationsBegin(); sIt != rEvent.StationsEnd(); ++sIt) {
162  Station& station = *sIt;
163 
164  if (!station.HasRecData()) {
165  *fTestResults << BeLabel("No radio reconstructed data on station level found! Test failed");
166  ERROR("No radio reconstructed data on station level found! Test failed");
167  return eFailure;
168  }
169 
170  for (const auto& info : fStationTests) {
171  label.str("");
172  label << "R" << rEvent.GetHeader().GetRunNumber() << "-E" << rEvent.GetHeader().GetId() << "-S" << station.GetId() << "-" << info.fParameterId << "->" << info.fParameterName;
173  *fTestResults << BeLabel(label.str());
174  if (station.GetRecData().HasParameter(StationRRecDataQuantities(info.fParameterId))) {
175  if (info.fUseAbsoluteTolerance)
176  *fTestResults << BeCloseAbs(station.GetRecData().GetParameter(StationRRecDataQuantities(info.fParameterId)), info.fTolerance);
177  else
178  *fTestResults << BeCloseRel(station.GetRecData().GetParameter(StationRRecDataQuantities(info.fParameterId)), info.fTolerance);
179  } else {
180  *fTestResults << BeEqual(-1);
181  }
182  label << "Error";
183  *fTestResults << BeLabel(label.str());
184  if (station.GetRecData().HasParameterError(StationRRecDataQuantities(info.fParameterId))) {
185  if (info.fUseAbsoluteTolerance)
186  *fTestResults << BeCloseAbs(station.GetRecData().GetParameterError(StationRRecDataQuantities(info.fParameterId)), info.fTolerance);
187  else
188  *fTestResults << BeCloseRel(station.GetRecData().GetParameterError(StationRRecDataQuantities(info.fParameterId)), info.fTolerance);
189  } else {
190  *fTestResults << BeEqual(-1);
191  }
192  }
193  }
194 
195  return eSuccess;
196 }
197 
198 
200 Verification::Finish()
201 {
202  bool comp = true;
203 
204  if (fMode == Verification::eCreate) {
205  INFO("Writing reference file");
206  ofstream fout(fRefFileName);
207  fout << fTestResults->str();
208  fout.close();
209  } else {
210  INFO("Comparing radio reconstruction results to reference file");
211  ifstream savedFile(fRefFileName);
212  comp = Compare(*fTestResults, savedFile, /*failOnFirst=*/false);
213  savedFile.close();
214 
215  if (comp)
216  INFO("radio verification was successful");
217  else
218  ERROR("radio verification failed");
219 
220  // store the new results in a ref file for easier comparison in case of problems
221  const string newRef = fRefFileName + ".new";
222  ofstream fout(newRef);
223  fout << fTestResults->str();
224  fout.close();
225  }
226 
227  // delete the stringstream
228  delete fTestResults;
229  fTestResults = nullptr;
230 
231  return (comp) ? eSuccess : eFailure;
232 }
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
StationRecData & GetRecData()
Get station level reconstructed data.
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.
double GetParameterError(const Parameter i) const
bool HasParameterError(const Parameter i1) const
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
StationIterator StationsEnd()
Definition: REvent.h:130
StationIterator StationsBegin()
Definition: REvent.h:128
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
boost::filter_iterator< StationFilter, AllStationIterator > StationIterator
Iterator over all (non-exculded) stations.
Definition: REvent.h:125
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)
class to hold data at the radio Station level.
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
int GetId() const
Get the station Id.
std::string BeEqual(const T &value)
Definition: Validatrix.h:131
double GetParameter(const Parameter i) const
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
bool HasParameter(const Parameter i) const
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
bool HasRecData() const
Check whether station reconstructed data exists.
#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.