RdSdSimCheckHAS/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 revt;
41 using namespace tst::Validatrix;
42 
43 
44 namespace VerificationRadio {
45 
48  {
49  auto topB = CentralConfig::GetInstance()->GetTopBranch("Verification");
50 
51  // get the coordinate system information
52  const auto 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 (auto 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 
83  // set up the stringstream for writing results
84  fTestResults = new ofstream(fRefFileName + ".new");
85 
86  return fTestResults->is_open() ? eSuccess : eFailure;
87  }
88 
89 
91  Verification::Run(evt::Event& event)
92  {
93  ostringstream info;
94  info << "Run validation for radio event E" << event.GetREvent().GetHeader().GetId();
95  INFO(info);
96 
97  *fTestResults << BeLabel("Verification for Radio:");
98 
99  if (!event.HasREvent()) {
100  *fTestResults << BeLabel("No radio event found! Test failed");
101  ERROR("No radio event found! Test failed");
102  return eFailure;
103  }
104  auto& rEvent = event.GetREvent();
105 
106  if (!event.HasRecShower()) {
107  *fTestResults << BeLabel("No reconstructed shower found! Test failed");
108  ERROR("No reconstructed shower found! Test failed");
109  return eFailure;
110  }
111 
112  if (!event.GetRecShower().HasRRecShower()) {
113  *fTestResults << BeLabel("No reconstructed radio shower found! Test failed");
114  ERROR("No reconstructed radio shower found! Test failed");
115  return eFailure;
116  }
117  auto& rRecShower = event.GetRecShower().GetRRecShower();
118 
119  // check the event id
120  *fTestResults << BeLabel("Run number:")
121  << BeEqual(rEvent.GetHeader().GetRunNumber())
122  << BeLabel("Eventid:")
123  << BeEqual(rEvent.GetHeader().GetId());
124 
125  // do all the tests on shower level
126  *fTestResults << BeLabel("Tests on radio shower level:");
127  stringstream label;
128  for (const auto& info : fShowerTests) {
129  label.str("");
130  label << "R" << rEvent.GetHeader().GetRunNumber() << "-E" << rEvent.GetHeader().GetId() << "-" << info.fParameterId << "->" << info.fParameterName;
131  *fTestResults << BeLabel(label.str());
132  if (rRecShower.HasParameter(ShowerRRecDataQuantities(info.fParameterId))) {
133  if (info.fUseAbsoluteTolerance)
134  *fTestResults << BeCloseAbs(rRecShower.GetParameter(ShowerRRecDataQuantities(info.fParameterId)), info.fTolerance);
135  else
136  *fTestResults << BeCloseRel(rRecShower.GetParameter(ShowerRRecDataQuantities(info.fParameterId)), info.fTolerance);
137  } else {
138  *fTestResults << BeEqual(-1);
139  }
140  label << "Error";
141  *fTestResults << BeLabel(label.str());
142  if (rRecShower.HasParameterError(ShowerRRecDataQuantities(info.fParameterId))) {
143  if (info.fUseAbsoluteTolerance)
144  *fTestResults << BeCloseAbs(rRecShower.GetParameterError(ShowerRRecDataQuantities(info.fParameterId)), info.fTolerance);
145  else
146  *fTestResults << BeCloseRel(rRecShower.GetParameterError(ShowerRRecDataQuantities(info.fParameterId)), info.fTolerance);
147  } else {
148  *fTestResults << BeEqual(-1);
149  }
150  }
151 
152  // now do all the tests on station level
153  *fTestResults << BeLabel("Tests on radio station level:");
154  for (auto sIt = rEvent.StationsBegin(); sIt != rEvent.StationsEnd(); ++sIt) {
155  auto& station = *sIt;
156 
157  if (!station.HasRecData()) {
158  *fTestResults << BeLabel("No radio reconstructed data on station level found! Test failed");
159  ERROR("No radio reconstructed data on station level found! Test failed");
160  return eFailure;
161  }
162 
163  for (const auto& info : fStationTests) {
164  label.str("");
165  label << "R" << rEvent.GetHeader().GetRunNumber() << "-E" << rEvent.GetHeader().GetId() << "-S" << station.GetId() << "-" << info.fParameterId << "->" << info.fParameterName;
166  *fTestResults << BeLabel(label.str());
167  if (station.GetRecData().HasParameter(StationRRecDataQuantities(info.fParameterId))) {
168  if (info.fUseAbsoluteTolerance)
169  *fTestResults << BeCloseAbs(station.GetRecData().GetParameter(StationRRecDataQuantities(info.fParameterId)), info.fTolerance);
170  else
171  *fTestResults << BeCloseRel(station.GetRecData().GetParameter(StationRRecDataQuantities(info.fParameterId)), info.fTolerance);
172  } else {
173  *fTestResults << BeEqual(-1);
174  }
175  label << "Error";
176  *fTestResults << BeLabel(label.str());
177  if (station.GetRecData().HasParameterError(StationRRecDataQuantities(info.fParameterId))) {
178  if (info.fUseAbsoluteTolerance)
179  *fTestResults << BeCloseAbs(station.GetRecData().GetParameterError(StationRRecDataQuantities(info.fParameterId)), info.fTolerance);
180  else
181  *fTestResults << BeCloseRel(station.GetRecData().GetParameterError(StationRRecDataQuantities(info.fParameterId)), info.fTolerance);
182  } else {
183  *fTestResults << BeEqual(-1);
184  }
185  }
186  }
187 
188  return eSuccess;
189  }
190 
191 
193  Verification::Finish()
194  {
195  delete fTestResults;
196  fTestResults = nullptr;
197 
198  INFO("Comparing radio reconstruction results to reference file");
199 
200  const auto comp = Compare(fRefFileName, fRefFileName + ".new", /*failOnFirst=*/false);
201 
202  return comp ? eSuccess : eFailure;
203  }
204 
205 }
std::string BeCloseRel(const T &value, const double tolerance=kDefaultTolerance)
Definition: Validatrix.h:153
bool HasRecShower() const
ShowerRecData & GetRecShower()
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
bool HasREvent() const
std::string BeCloseAbs(const T &value, const double tolerance=kDefaultTolerance)
Definition: Validatrix.h:141
bool Compare(const string &oldFilename, const string &newFilename, const bool failOnFirst)
std::string BeLabel(const string &tag)
bool HasRRecShower() const
std::string BeEqual(const T &value)
Definition: Validatrix.h:131
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.