MdPileUpCorrecter.cc
Go to the documentation of this file.
1 #include "MdPileUpCorrecter.h"
2 
3 #include "InhibitionStrategy.h"
4 
5 #include <fwk/CentralConfig.h>
6 #include <det/VManager.h>
7 #include <mdet/MDetector.h>
8 #include <mevt/Counter.h>
9 
10 #include <utl/ConsecutiveEnumFactory.h>
11 #include <utl/Trace.h>
12 #include <utl/AugerUnits.h>
13 #include <utl/Branch.h>
14 #include <utl/RandomEngine.h>
15 #include <utl/ConfigUtils.h>
16 #include <utl/TimeInterval.h>
17 #include <utl/TabularStream.h>
18 
19 #include <utl/ErrorLogger.h>
20 #include <utl/Verbosity.h>
21 
22 #include <sstream>
23 //#include <cassert>
24 
25 using namespace fwk;
26 using std::cout;
27 using std::endl;
28 
29 
30 namespace MdPileUpCorrecterAG {
31 
32  const char* const MdPileUpCorrecter::kStrategyTags[] = { "Inhibit" };
33 
36  {
37  // Configuration reading.
38  utl::Branch config = fwk::CentralConfig::GetInstance()->GetTopBranch("MdPileUpCorrecter");
39  fUnits.SetTimeDefault(utl::ns, "ns");
40  fUnits.Configure(config);
41  fLog.Configure(config);
42  std::string tag;
43  LoadConfig(config, "strategy", tag, kStrategyTags[0]);
45 
46  // Init according to selected strategy.
47  switch (fStrategy) {
48  case eInhibit:
49  fCorrecter.reset(new InhibitionStrategy());
50  fLog("Strategy",1)(kStrategyTags[ fStrategy ])(".");
51  break;
52  }
53 
54  return eSuccess;
55  }
56 
57 
59  MdPileUpCorrecter::Run(evt::Event& event)
60  {
61  if (!event.HasMEvent()) {
62  WARNING("\n+++++++++\nEvent without MEvent: nothing to be done. Skipping to next event.\n++++++++++\n");
63  return eContinueLoop;
64  }
65 
66  mevt::MEvent& me = event.GetMEvent();
67  const mdet::MDetector& theMdDetector = det::Detector::GetInstance().GetMDetector();
68 
69  std::ostringstream os;
70  for (mevt::MEvent::CounterIterator ic = me.CountersBegin(), ec = me.CountersEnd(); ic != ec; ++ic) {
71 
72  mevt::Counter& counter = *ic;
73  const int counterId = counter.GetId();
74  const mdet::Counter& mdetCounter = theMdDetector.GetCounter(counterId);
75 
76  if (counter.IsRejected()) {
77  os.str("");
78  os << "Skipping the rejected counter " << counterId;
79  INFO(os);
80  continue;
81  }
82 
83  os.str("");
84  os << "Processing counter " << counterId;
85  INFO(os);
86 
87  for (mevt::Counter::ModuleIterator im = counter.ModulesBegin(), em = counter.ModulesEnd(); im != em; ++im) {
88 
89  mevt::Module& module = *im;
90  const int moduleId = module.GetId();
91  const mdet::Module& mdetModule = mdetCounter.GetModule(moduleId);
92 
93  os.str("");
94  os << "Processing module " << moduleId;
95 
96  // Check if module was flagged as rejected (by a selector) or, in the case of real data, if T1 from SD was not matched
97  // this should imply an empty (all "0s" ) module traces
98  if (module.IsRejected()) {
99  os.str("");
100  os << "Module " << module.GetId() << " of counter " << counterId;
101  os << " discarded because flagged as: " << module.GetRejectionReason();
102  WARNING(os);
103  continue;
104  }
105 
106  double nSingleRealizationMuons = 0;
107  double nAverageMuons = 0;
108  // Reconstructed muons
109  boost::tie(nAverageMuons, nSingleRealizationMuons) = (*fCorrecter)(module,mdetModule);
110 
111  mevt::ModuleRecData& mRecData = module.GetRecData();
112 
113  mRecData.SetNumberOfEstimatedMuons(nSingleRealizationMuons);
114  mRecData.SetMeanMuons(nAverageMuons);
115  // Calculate errors with the likelihood at a later step in the reconstruction, using the profile likelihood
116  mRecData.SetNumberOfMuonsErrorHigh(0);
117  mRecData.SetNumberOfMuonsErrorLow(0);
118  // Set the lower limit to the number of muons for both saturated and unsaturated modules
119  mRecData.SetNumberOfMuonsLowLimit(0);
120  //Set ActiveArea
121  const mdet::Scintillator& s = *(mdetModule.ScintillatorsBegin());
122  const double moduleArea = s.GetArea() * im->GetRecData().GetSegmentation();
123  mRecData.SetActiveArea( moduleArea );
124 
125 
126  const utl::TraceUI& channelsOnTrace = mRecData.GetChannelsOn();
127  const utl::TraceUI& channelsInhiTrace = mRecData.GetChannelsInhibited();
128 
129  const unsigned int numberOfSamples = mdetModule.IsSiPM() ?
130  mdetModule.GetFrontEndSiPM().GetBufferLength() :
131  mdetModule.GetFrontEnd().GetBufferLength();
132 
133  std::unique_ptr<utl::TabularStream> spanTable;
134  const unsigned int LogLevel = 15;
135  if (fLog.GetLevel() >= LogLevel) {
136  InitTable(spanTable, 5);
137  *spanTable << utl::hline
138  << "Ctr" << utl::endc //1
139  << "Mod" << utl::endc //2
140  << "#Bin" << utl::endc //3
141  << "On" << utl::endc //4
142  << "Inhi" << utl::endr;//5
143 
144  for ( size_t bin = 0; bin < numberOfSamples; ++bin ) {
145  if (channelsOnTrace.At(bin)||channelsInhiTrace.At(bin))
146  *spanTable << utl::hline
147  << counterId << utl::endc
148  << moduleId << utl::endc
149  << bin << utl::endc
150  << fLog << channelsOnTrace.At(bin) << utl::endc
151  << fLog << channelsInhiTrace.At(bin) << utl::endr
152  << utl::hline;
153  }
154  fLog("Channels On & Inhibited span:");
155  fLog(spanTable->Str());
156  }
157 
158  fLog("Estimated muons in")(mRecData.IsSaturated()?"SATURATED":"")("Cter")(counterId)
159  ("Mod")(moduleId)(": Single realization")(nSingleRealizationMuons)("- Average")(nAverageMuons);
160 
161  } // end module loop
162 
163  } // end counter loop
164 
165  return eSuccess;
166  }
167 
168 
170  MdPileUpCorrecter::Finish()
171  {
172  return eSuccess;
173  }
174 
175  void
176  MdPileUpCorrecter::InitTable(std::unique_ptr<utl::TabularStream>& pt, unsigned int nCol)
177  const
178  {
179  std::stringstream fmt;
180  for(unsigned int i = 0; i < nCol; ++i)
181  fmt << "|r";
182  fmt << "|";
183  pt.reset(new utl::TabularStream(fmt.str()));
184  fLog.ApplyConfigurationOn(*pt);
185  }
186 
187 }
Module level reconstruction data. This class contains all data required by the muon reconstruction...
Definition: ModuleRecData.h:29
T & At(const SizeType i)
trace entry with checked address
Definition: Trace.h:205
const Module & GetModule(const int mId) const
Retrieve by id a constant module.
CounterConstIterator CountersBegin() const
Definition: MEvent.h:49
bool HasMEvent() const
static EnumType Create(const int k)
int version of the overloaded creation method.
Counter level event data.
std::string GetRejectionReason() const
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
ScintillatorConstIterator ScintillatorsBegin() const
Begin iterator over the contained scitillators.
void Init()
Initialise the registry.
bool IsRejected() const
Check if the counter is rejected.
int GetId() const
Detector associated to muon detector hierarchy.
Definition: MDetector.h:32
Actual muon-sensitive objects.
Class representing a document branch.
Definition: Branch.h:107
constexpr double s
Definition: AugerUnits.h:163
Module level event data.
Definition: MEvent/Module.h:41
const EndRow endr
Array of Scintillator.
class to format data in tabular form
void SetNumberOfEstimatedMuons(const double m)
Number of estimated muons in a module.
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
double GetArea() const
Compute Scintillator&#39;s total area in square metres.
unsigned int GetBufferLength() const
Number of bins of the buffer.
Definition: FrontEnd.h:130
const FrontEnd & GetFrontEnd() const
InternalModuleCollection::ComponentIterator ModuleIterator
ModuleConstIterator ModulesBegin() const
Root detector of the muon detector hierarchy.
Functor implementing pile-up correction proposed in GAP 2022-001.
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
int GetId() const
The id of the counter.
ModuleConstIterator ModulesEnd() const
InternalCounterCollection::ComponentIterator CounterIterator
Definition: MEvent.h:31
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
Template class for a FADC data or calibrated data container. Use the typedefs (TraceD, TraceI, etc.) defined in Trace-fwd.h.
Definition: Trace-fwd.h:19
const FrontEndSiPM & GetFrontEndSiPM() const
bool IsRejected() const
void LoadConfig(const utl::Branch &b, const std::string &tag, T1 &var, const T2 &defaultValue)
Helper method to load a particular configuration parameter.
Definition: ConfigUtils.h:35
CounterConstIterator CountersEnd() const
Definition: MEvent.h:52
constexpr double ns
Definition: AugerUnits.h:162
bool IsSiPM() const
const Counter & GetCounter(int id) const
Retrieve Counter by id.
Definition: MDetector.h:68
const HLine hline('-')
const EndColumn endc
Root of the Muon event hierarchy.
Definition: MEvent.h:25
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
unsigned int GetBufferLength() const
Number of bins of the buffer.
Definition: FrontEndSiPM.h:120

, generated on Tue Sep 26 2023.