SdHasDataRec/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 
5 #include <sevt/SEvent.h>
6 #include <sevt/SortCriteria.h>
7 
8 #include <utl/ErrorLogger.h>
9 #include <utl/Branch.h>
10 #include <utl/AugerUnits.h>
11 
12 #include <tst/Validatrix.h>
13 
14 #include <fwk/CentralConfig.h>
15 #include <fwk/LocalCoordinateSystem.h>
16 
17 #include "Validation.h"
18 
19 using namespace std;
20 using namespace evt;
21 using namespace sevt;
22 using namespace fevt;
23 using namespace fwk;
24 using namespace utl;
25 using namespace tst::Validatrix;
26 using namespace ValidationNS;
27 
28 
31 {
32  Branch topB = CentralConfig::GetInstance()->GetTopBranch("Validation");
33  topB.GetChild("RefFilename").GetData(fRefFileName);
34 
35  fResults = new ofstream((fRefFileName + string(".new")).c_str());
36 
37  return eSuccess;
38 }
39 
40 
42 Validation::Run(evt::Event& event)
43 {
44  // SD
45  if (!event.HasSEvent()) {
46  ERROR("Event should contain an SEvent.");
47  return eFailure;
48  }
49 
50  event.GetSEvent().SortStations(ByIncreasingId());
51  const auto& sEvent = event.GetSEvent();
52 
53  const double tolerance = 0.02;
54 
55  *fResults << BeLabel("SD_rec");
56 
57  for (const auto& station : sEvent.StationsRange()) {
58  if (station.HasRecData()) {
59  ostringstream label;
60  label << "Station_" << station.GetId();
61  *fResults << BeLabel(label.str());
62  *fResults << BeCloseRel(station.GetRecData().GetTotalSignal(), tolerance);
63  }
64  }
65 
66  *fResults << BeLabel("Shower_rec");
67 
68  // Shower-level rec data
69  if (!event.HasRecShower())
70  ERROR("Event does not contain a RecShower");
71  const auto& showerRec = event.GetRecShower();
72 
73  // SD rec (shower level)
74 
75  if (!showerRec.HasSRecShower())
76  ERROR("RecShower does not have SRecShower");
77 
78  *fResults << BeLabel("Shower_S_rec");
79 
80  const auto& showerSRec = showerRec.GetSRecShower();
81 
82  const auto& corePos = showerSRec.GetCorePosition();
83  const auto& baryPos = showerSRec.GetBarycenter();
84  const auto& coreCS = LocalCoordinateSystem::Create(corePos);
85  const auto& baryCS = LocalCoordinateSystem::Create(baryPos);
86 
87 #define SCOMPARE(item, eps) \
88  *fResults << BeLabel(#item); \
89  *fResults << BeCloseRel(showerSRec.Get##item(), eps)
90 
91  SCOMPARE(ShowerSize, tolerance);
92  SCOMPARE(Curvature, tolerance);
93  SCOMPARE(ShowerSizeError, tolerance);
94  SCOMPARE(CurvatureError, tolerance);
95 
96  SCOMPARE(LDFChi2, tolerance);
97  *fResults << BeLabel("LDFNdof");
98  *fResults << BeEqual(showerSRec.GetLDFNdof());
99 
100  *fResults << BeLabel("Theta");
101  *fResults << BeCloseRel(showerSRec.GetAxis().GetTheta(coreCS), tolerance);
102  *fResults << BeLabel("Phi");
103  *fResults << BeCloseRel(showerSRec.GetAxis().GetPhi(coreCS), tolerance);
104  SCOMPARE(ThetaError, tolerance);
105  SCOMPARE(PhiError, tolerance);
106 
107  *fResults << BeLabel("CoreX");
108  *fResults << BeCloseRel(corePos.GetX(baryCS), tolerance);
109  *fResults << BeLabel("CoreY");
110  *fResults << BeCloseRel(corePos.GetY(baryCS), tolerance);
111  *fResults << BeLabel("CoreXError");
112  *fResults << BeCloseRel(showerSRec.GetCoreError().GetX(baryCS), tolerance);
113  *fResults << BeLabel("CoreYError");
114  *fResults << BeCloseRel(showerSRec.GetCoreError().GetY(baryCS), tolerance);
115 #undef SCOMPARE
116 
117  return eSuccess;
118 }
119 
120 
122 Validation::Finish()
123 {
124  delete fResults;
125  fResults = nullptr;
126 
127  ifstream newFile((fRefFileName + string(".new")).c_str());
128  ifstream oldFile(fRefFileName.c_str());
129 
130  const bool comp = Compare(oldFile, newFile, /*failOnFirst=*/true);
131 
132  return comp ? eSuccess : eFailure;
133 }
Branch GetTopBranch() const
Definition: Branch.cc:63
std::string BeCloseRel(const T &value, const double tolerance=kDefaultTolerance)
Definition: Validatrix.h:153
bool HasRecShower() const
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
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)
#define SCOMPARE(item, eps)
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
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
bool HasSEvent() const

, generated on Tue Sep 26 2023.