HdSimWriteRec/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 #include <evt/ShowerSimData.h>
5 
6 #include <sevt/SEvent.h>
7 #include <sevt/PMTSimData.h>
8 #include <sevt/SortCriteria.h>
9 
10 #include <fevt/FEvent.h>
11 #include <fevt/Eye.h>
12 #include <fevt/Telescope.h>
13 #include <fevt/EyeRecData.h>
14 #include <fevt/TelescopeRecData.h>
15 
16 #include <evt/ShowerFRecData.h>
17 
18 #include <utl/ErrorLogger.h>
19 #include <utl/Branch.h>
20 #include <utl/Particle.h>
21 #include <utl/AugerUnits.h>
22 #include <utl/Point.h>
23 #include <fwk/CoordinateSystemRegistry.h>
24 
25 #include <tst/Validatrix.h>
26 
27 #include <fwk/CentralConfig.h>
28 
29 #include <iostream>
30 
31 #include "Validation.h"
32 
33 using namespace std;
34 using namespace evt;
35 using namespace sevt;
36 using namespace fevt;
37 using namespace fwk;
38 using namespace utl;
39 using namespace tst::Validatrix;
40 using namespace ValidationNS;
41 
42 
45 {
46  INFO("Doing the validation !!!!");
47  Branch topB = CentralConfig::GetInstance()->GetTopBranch("Validation");
48  topB.GetChild("RefFilename").GetData(fRefFileName);
49  string mode;
50  topB.GetChild("Mode").GetData(mode);
51 
52  cout << "Validation mode = " << mode << endl;
53 
54  fMode = mode == "Create" ? Validation::eCreate : Validation::eCompare;
55 
56  fResults.str("");
57 
58  return eSuccess;
59 }
60 
61 
63 Validation::Run(evt::Event& event)
64 {
65  // SD
66  if (!event.HasSEvent()) {
67  ERROR("Event should contain an SEvent.");
68  return eFailure;
69  }
70 
71  SEvent& sEvent = event.GetSEvent();
72 
73  fResults << BeLabel("SD_rec");
74 
75  // NB you have to sort the stations before writing to ref
76  // file, since there is no guarantee the
77  // station list will come back in the same order after serialization
78 
79  sEvent.SortStations(ByIncreasingId());
80 
81  ostringstream label;
82  for (SEvent::ConstStationIterator sIt = sEvent.StationsBegin();
83  sIt != sEvent.StationsEnd(); ++sIt) {
84  if (sIt->HasRecData()) {
85  label.str("");
86  label << "Station_" << sIt->GetId();
87  fResults << BeLabel(label.str());
88  fResults << BeCloseRel(sIt->GetRecData().GetTotalSignal(), /*tolerance*/0.05);
89  }
90  }
91 
92  // FD
93  if (!event.HasFEvent()) {
94  ERROR("Event should contain an FEvent.");
95  return eFailure;
96  }
97 
98  const FEvent& fEvent = event.GetFEvent();
99 
100  fResults << BeLabel("FD_rec");
101 
102  for (FEvent::ConstEyeIterator eIt = fEvent.EyesBegin(ComponentSelector::eHasData);
103  eIt != fEvent.EyesEnd(ComponentSelector::eHasData); ++eIt) {
104 
105  if (eIt->HasRecData()) {
106  label.str("");
107  label << "Eye_" << eIt->GetId();
108  fResults << BeLabel(label.str());
109 
110  const ShowerFRecData& showerRec = eIt->GetRecData().GetFRecShower();
111  fResults << BeLabel("Stations_in_fit");
112  fResults << BeEqual(showerRec.GetStationIds());
113 
114  fResults << BeLabel("TotalEnergy(EeV)");
115  fResults << BeCloseRel(showerRec.GetTotalEnergy()/EeV, /*tolerance*/1e-5);
116 
117  fResults << BeLabel("TotalEnergyError(EeV)");
118  fResults << BeCloseRel(showerRec.GetTotalEnergyError()/EeV, /*tolerance*/1e-1);
119 
120  fResults << BeLabel("Xmax(g/cm2)");
121  fResults << BeCloseRel(showerRec.GetGHParameters().GetXMax()/gram*cm2, 1e-5);
122 
123  fResults << BeLabel("Xmax2Error");
124  fResults << BeCloseRel(showerRec.GetGHParameters().GetXMaxError()/gram*cm2, 1e-1);
125  }
126 
127  for (Eye::ConstTelescopeIterator tIt = eIt->TelescopesBegin(ComponentSelector::eHasData);
128  tIt != eIt->TelescopesEnd(ComponentSelector::eHasData); ++tIt) {
129 
130  if (tIt->HasRecData()) {
131  label.str("");
132  label << "Telescope_" << tIt->GetId();
133  fResults << BeLabel(label.str());
134 
135  const TelescopeRecData& tRec = tIt->GetRecData();
136  //fResults << BeLabel("zeta");
137  //fResults << BeCloseRel(tRec.GetZeta(), /*tolerance*/0.05);
138  fResults << BeLabel("photon_trace_start_sec");
139  fResults << BeEqual(tRec.GetPhotonsStartTime().GetGPSSecond());
140  fResults << BeLabel("photon_trace_start_ns");
141  fResults << BeCloseAbs(tRec.GetPhotonsStartTime().GetGPSNanoSecond(), 50*ns);
142  }
143  }
144  }
145 
146  fResults << BeLabel("Shower_rec");
147 
148  // Shower-level rec data
149  if (!event.HasRecShower())
150  ERROR("Event does not contain a RecShower");
151  const ShowerRecData& showerRec = event.GetRecShower();
152 
153  // SD rec (shower level)
154 
155  if (!showerRec.HasSRecShower())
156  ERROR("RecShower does not have SRecShower");
157 
158  fResults << BeLabel("Shower_S_rec");
159 
160  const ShowerSRecData& showerSRec = showerRec.GetSRecShower();
161 
162  fResults << BeLabel("S1000");
163  fResults << BeCloseRel(showerSRec.GetShowerSize(), 1e-5);
164 
165  // Confirm that the MC truth is stored and read back
166 
167  if (!event.HasSimShower())
168  ERROR("Event does not have ShowerSimData");
169 
170  const ShowerSimData& sSim = event.GetSimShower();
171 
172  const Point& cP = sSim.GetPosition();
173  // get reference coordinate system of detector (usually PampaAmarilla)
174  const utl::CoordinateSystemPtr referenceCS = det::Detector::GetInstance().GetReferenceCoordinateSystem();
175 
176  fResults << BeLabel("core position (pampa CS)");
177  fResults << BeCloseRel(cP.GetX(referenceCS)/km) << " "
178  << BeCloseRel(cP.GetY(referenceCS)/km) << " "
179  << BeCloseRel(cP.GetZ(referenceCS)/km);
180 
181  return eSuccess;
182 }
183 
184 
186 Validation::Finish()
187 {
188  bool comp = true;
189 
190  if (fMode == Validation::eCreate) {
191  INFO("Writing reference file");
192  ofstream fout(fRefFileName.c_str());
193  fout << fResults.str();
194  fout.close();
195  } else {
196  INFO("Comparing re-reconstruction results to reference file");
197  ifstream savedFile(fRefFileName.c_str());
198  comp = Compare(fResults, savedFile, /*failOnFirst=*/false);
199  savedFile.close();
200 
201  // store the new results in a ref file for easier comparison in case of problems
202  const string newRef = fRefFileName + ".after-rereconstruction";
203  ofstream fout(newRef.c_str());
204  fout << fResults.str();
205  fout.close();
206  }
207  fResults.str("");
208 
209  return comp ? eSuccess : eFailure;
210 }
Branch GetTopBranch() const
Definition: Branch.cc:63
StationIterator StationsEnd()
End of all stations.
Definition: SEvent.h:59
Point object.
Definition: Point.h:32
std::string BeCloseRel(const T &value, const double tolerance=kDefaultTolerance)
Definition: Validatrix.h:153
Interface class to access to the SD Reconstruction of a Shower.
boost::filter_iterator< ComponentSelector, ConstAllEyeIterator > ConstEyeIterator
Definition: FEvent.h:56
Interface class to access Shower Reconstructed parameters.
Definition: ShowerRecData.h:33
bool HasRecShower() const
bool HasFEvent() const
Interface class to access to the SD part of an event.
Definition: SEvent.h:39
bool HasSimShower() const
EyeIterator EyesEnd(const ComponentSelector::Status status)
Definition: FEvent.h:66
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
double GetShowerSize() 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
const double EeV
Definition: GalacticUnits.h:34
void SortStations(const OrderingCriterion ord) const
Sort the list of stations by the criterion specified in an OrderingCriterion object.
Definition: SEvent.h:172
ShowerSRecData & GetSRecShower()
std::string BeCloseAbs(const T &value, const double tolerance=kDefaultTolerance)
Definition: Validatrix.h:141
Interface class to access Shower Simulated parameters.
Definition: ShowerSimData.h:49
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
Definition: Branch.h:107
bool Compare(const string &oldFilename, const string &newFilename, const bool failOnFirst)
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
const double ns
std::string BeLabel(const string &tag)
const utl::Point & GetPosition() const
Get the position of the shower core.
EyeIterator EyesBegin(const ComponentSelector::Status status)
Definition: FEvent.h:58
const double km
Telescope-specific shower reconstruction data.
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
Top of Fluorescence Detector event hierarchy.
Definition: FEvent.h:33
std::string BeEqual(const T &value)
Definition: Validatrix.h:131
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
StationIterator StationsBegin()
Beginning of all stations.
Definition: SEvent.h:57
Interface class to access to Fluorescence reconstruction of a Shower.
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
boost::indirect_iterator< InternalConstStationIterator, const Station & > ConstStationIterator
Definition: SEvent.h:54
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
constexpr double gram
Definition: AugerUnits.h:195
bool HasSRecShower() const
bool HasSEvent() const
boost::filter_iterator< ComponentSelector, ConstAllTelescopeIterator > ConstTelescopeIterator
Definition: FEvent/Eye.h:73
constexpr double cm2
Definition: AugerUnits.h:118

, generated on Tue Sep 26 2023.