MCShowerChecker.cc
Go to the documentation of this file.
1 
9 #include "MCShowerChecker.h"
10 
11 #include <fwk/CentralConfig.h>
12 
13 #include <det/Detector.h>
14 
15 #include <evt/Header.h>
16 #include <evt/Event.h>
17 #include <evt/ShowerSimData.h>
18 
19 #include <utl/ErrorLogger.h>
20 #include <utl/Reader.h>
21 #include <utl/TimeStamp.h>
22 #include <utl/TabularStream.h>
23 #include <utl/TabulatedFunction.h>
24 #include <utl/AugerException.h>
25 
26 #include <cstddef>
27 #include <cstdio>
28 #include <sstream>
29 
30 using namespace MCShowerCheckerOG;
31 using namespace fwk;
32 using namespace evt;
33 using namespace utl;
34 using namespace std;
35 
36 
39 {
40  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch ("MCShowerChecker");
41 
42  topBranch.GetChild("verbose").GetData(fVerbose);
43 
44  const string input = topBranch.GetChild("ElectronNumberProfile").Get<string>();
45  fElectronNumberProfile = ToEnum(input);
46 
47  ostringstream info;
48  info << " Version: "
49  << GetVersionInfo(VModule::eRevisionNumber) << "\n"
50  " Parameters:\n"
51  " electron number profile: " << ToText(fElectronNumberProfile)
52  << endl;
53 
54  return eSuccess;
55 }
56 
57 
58 std::string
60  const
61 {
62  switch (flag) {
63  case eReject:
64  return "reject";
65  break;
66  case eAssert:
67  return "assert";
68  break;
69  case eCorrect:
70  return "correct";
71  break;
72  }
73  return "unknown";
74 }
75 
76 
78 MCShowerChecker::ToEnum(const string& text)
79  const
80 {
81  if (text == "reject")
82  return eReject;
83  if (text == "correct")
84  return eCorrect;
85  if (text == "assert")
86  return eAssert;
87  throw InvalidConfigurationException("MCShowerChecker:: encountered unknown configuration string: '" + text + "'");
88 }
89 
90 
93 {
94  ++fNEventsProcessed;
95 
96  if (!event.HasSimShower())
97  return eContinueLoop;
98  evt::ShowerSimData& simShower = event.GetSimShower();
99 
100  if (!simShower.HasLongitudinalProfile())
101  return eSuccess;
102 
103  TabulatedFunction& chargeProfile = simShower.GetLongitudinalProfile();
104  bool foundNeProblem = false;
105  for (unsigned int iPoint = 0; iPoint < chargeProfile.GetNPoints(); ++iPoint) {
106 
107  if (chargeProfile.GetY(iPoint) < 0) {
108 
109  foundNeProblem = true;
110 
111  switch (fElectronNumberProfile) {
112  case eAssert:
113  ERROR("Found Monte Carlo shower information with negative entries in electron number profile!");
114  return eFailure;
115  case eReject:
116  ++fNEventsWithElectronProfileProblem;
117  WARNING("Rejecting Monte Carlo shower: negative entries in electron number profile!");
118  return eContinueLoop;
119  case eCorrect:
120  {
121  ostringstream info;
122  info << "Correcting negative entries in electron profile of Monte Carlo shower: bin="
123  << iPoint
124  << " X=" << chargeProfile.GetX(iPoint) / (g/cm2)
125  << " Ne=" << chargeProfile.GetY(iPoint);
126  WARNING(info);
127  chargeProfile.GetY(iPoint) = 0;
128  }
129  break;
130  }
131  }
132  }
133  if (foundNeProblem)
134  ++fNEventsWithElectronProfileProblem;
135 
136  ++fNEventsAccepted;
137 
138  return eSuccess;
139 }
140 
141 
144 {
145  if (fVerbose > 0) {
146 
147  if (fNEventsProcessed) {
148 
149  const int nDiscarded = fNEventsProcessed - fNEventsAccepted;
150 
151  TabularStream tab("r r .");
152 
153  tab << endc << 'N' << endc << '%' << endr
154  << "Events processed:" << endc << fNEventsProcessed << endc << 100 << endr
155  << "Events skipped:" << endc << nDiscarded << endc << int(nDiscarded*1000./fNEventsProcessed)/10. << endr
156  << "Ne-profile:" << endc << fNEventsWithElectronProfileProblem << endc
157  << int(fNEventsWithElectronProfileProblem*1000./fNEventsProcessed)/10.;
158  ostringstream info;
159  info << "\n\n" << tab;
160  INFO(info);
161 
162  } else
163  INFO("No events processed.");
164 
165  }
166  return eSuccess;
167 }
std::string ToText(const EHandle flag) const
Branch GetTopBranch() const
Definition: Branch.cc:63
unsigned int GetNPoints() const
EHandle ToEnum(const std::string &text) const
Base class for exceptions arising because configuration data are not valid.
Class to hold collection (x,y) points and provide interpolation between them.
bool HasSimShower() const
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
fwk::VModule::ResultFlag Run(evt::Event &theEvent)
Run: invoked once per event.
Interface class to access Shower Simulated parameters.
Definition: ShowerSimData.h:49
T Get() const
Definition: Branch.h:271
Class representing a document branch.
Definition: Branch.h:107
const EndRow endr
const int tab
Definition: SdInspector.cc:35
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
constexpr double g
Definition: AugerUnits.h:200
class to format data in tabular form
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
const double & GetY(const unsigned int idx) const
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
fwk::VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
const double & GetX(const unsigned int idx) const
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
const EndColumn endc
bool HasLongitudinalProfile(const ProfileType type=eCharged) const
Check initialization of the longitudinal profile.
const utl::TabulatedFunction & GetLongitudinalProfile(const ProfileType type=eCharged) const
Get the longitudinal charge profile of the shower.
constexpr double cm2
Definition: AugerUnits.h:118

, generated on Tue Sep 26 2023.