MdPatternFinder.cc
Go to the documentation of this file.
1 #include "MdPatternFinder.h"
2 
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/ConfigUtils.h>
15 
16 #include <utl/ErrorLogger.h>
17 #include <utl/Verbosity.h>
18 
19 #include <sstream>
20 #include <cassert>
21 
22 using namespace fwk;
23 using std::cout;
24 using std::endl;
25 
26 
27 namespace MdPatternFinderAG {
28 
29  const char* const MdPatternFinder::kStrategyTags[] = { "Consecutive" };
30 
33  {
34  // Configuration reading.
35  utl::Branch config = fwk::CentralConfig::GetInstance()->GetTopBranch("MdPatternFinder");
36  fUnits.SetTimeDefault(utl::ns, "ns");
37  fUnits.Configure(config);
38  fLog.Configure(config);
39  std::string tag;
40  LoadConfig(config, "strategy", tag, kStrategyTags[0]);
42 
43  // Init according to selected strategy.
44  switch (fStrategy) {
45  case eConsecutive:
46  LoadConfig(config, "windowSize", fWindowSize, 18);
47  LoadConfig(config, "nOnes", fNOnes, 4);
48  fFinder.reset(new ConsecutiveInWindowStrategy(fWindowSize, fNOnes));
49  fLog("#Window size", 1)
50  (fWindowSize)("-")
51  ("Number of ones")(fNOnes)("-")
52  ("Strategy")(kStrategyTags[ fStrategy ])(".");
53  break;
54  }
55 
56  return eSuccess;
57  }
58 
59 
61  MdPatternFinder::Run(evt::Event& event)
62  {
63  if (!event.HasMEvent()) {
64  WARNING("\n+++++++++\nEvent without MEvent: nothing to be done. Skipping to next event.\n++++++++++\n");
65  return eContinueLoop;
66  }
67 
68  mevt::MEvent& me = event.GetMEvent();
69  const mdet::MDetector& theMdDetector = det::Detector::GetInstance().GetMDetector();
70 
71  std::ostringstream os;
72  for (mevt::MEvent::CounterIterator ic = me.CountersBegin(), ec = me.CountersEnd(); ic != ec; ++ic) {
73 
74  mevt::Counter& counter = *ic;
75  const int counterId = counter.GetId();
76  const mdet::Counter& mdetCounter = theMdDetector.GetCounter(counterId);
77 
78  if (counter.IsRejected()) {
79  os.str("");
80  os << "Skipping the rejected counter " << counterId;
81  INFO(os);
82  continue;
83  }
84 
85  os.str("");
86  os << "Processing counter " << counterId;
87  INFO(os);
88 
89  for (mevt::Counter::ModuleIterator im = counter.ModulesBegin(), em = counter.ModulesEnd(); im != em; ++im) {
90 
91  mevt::Module& module = *im;
92  const int moduleId = module.GetId();
93  const mdet::Module& mdetModule = mdetCounter.GetModule(moduleId);
94 
95  os.str("");
96  os << "Processing module " << moduleId;
97  INFO(os);
98 
99  // Check if module was flagged as rejected (by a selector) or, in the case of real data, if T1 from SD was not matched
100  // this should imply an empty (all "0s" ) module traces
101  if (module.IsRejected()) {
102  os.str("");
103  os << "Module " << module.GetId() << " of counter " << counterId;
104  os << " discarded because flagged as: " << module.GetRejectionReason();
105  WARNING(os);
106  continue;
107  }
108 
109  unsigned int nTotalChannelsOn = 0; // total number of channels with at least one pattern match
110 
111  for (mevt::Module::ChannelIterator ch = module.ChannelsBegin(), ech = module.ChannelsEnd(); ch != ech; ++ch) {
112  mevt::Channel& channel = *ch;
113 
114  const unsigned int nRecPatternMatches = FillChannelRecData(channel, mdetModule);
115 
116  os.str("");
117  os << "counter " << counterId << ": "
118  << "module " << module.GetId() << " "
119  << "channel " << channel.GetId() << " "
120  << nRecPatternMatches << " pattern(s) match(es) was(were) found ";
121  os << PrintPatternMatchBins(channel);
122 
123  if ( nRecPatternMatches ) {
124  fLog( os.str(), 5 );
125  nTotalChannelsOn +=1;
126  }
127  }
128 
129  if (!module.HasRecData())
130  module.MakeRecData();
131 
132  mevt::ModuleRecData& mRecData = module.GetRecData();
133 
134  const size_t segmentation = module.GetNumberOfActiveChannels();
135  mRecData.SetSegmentation(segmentation);
136  mRecData.SetWindowSize(fWindowSize);
137  assert(nTotalChannelsOn <= 64);
138  mRecData.SetTotalNumberOfChannelsOn(nTotalChannelsOn);
139 
140  } // end module loop
141 
142  } // end counter loop
143 
144  return eSuccess;
145  }
146 
147 
149  MdPatternFinder::Finish()
150  {
151  return eSuccess;
152  }
153 
154 
155  // Private methods
156 
157  unsigned int
158  MdPatternFinder::FillChannelRecData(mevt::Channel& channel, const mdet::Module& mdetModule)
159  {
160  if (!channel.HasTrace())
161  return 0;
162 
163  const utl::TraceB trace = channel.GetTrace();
164 
165  if (channel.HasRecData()) {
166  if (channel.GetRecData().GetNumberOfPatternMatchs()) {
167  fLog("Clearing", 35)
169  ("preexisting muons for channel=")(channel.GetId())(':')
170  ("in rec info.");
171  channel.GetRecData().ClearPatternMatchBins();
172  }
173  } else
174  channel.MakeRecData();
175 
176  mevt::ChannelRecData& rData = channel.GetRecData();
177  // reconstructed muons
178  const unsigned int nRecPatternMatches = (*fFinder)(trace, rData);
179 
180  /*Reconstructed trace. Values means: 0- no signal
181  * 1- identified first bin of given pattern match
182  * 2- inhibited bin
183  */
184  if (channel.HasRecData() && !channel.IsMasked()) { // use unmasked channels only
185  const unsigned int numberOfSamples = mdetModule.IsSiPM() ?
186  mdetModule.GetFrontEndSiPM().GetBufferLength() :
187  mdetModule.GetFrontEnd().GetBufferLength();
188 
189  if (!rData.HasTrace())
190  rData.MakeTrace();
191 
192  utl::TraceUI& traceRec = rData.GetTrace();
193  traceRec.Clear();
194 
195  for ( size_t bin = 0; bin < numberOfSamples; ++bin )
196  traceRec.PushBack(0);//no signal
197 
199  end = rData.PatternMatchBinsEnd(); pIt != end; ++pIt) {
200  traceRec.At(*pIt) = 1; //Starting bin of a pattern match
201  for ( size_t bin = 1; bin < fWindowSize && *pIt+bin<numberOfSamples; ++bin )
202  traceRec.At(*pIt+bin) = 2;//inhibited bins
203  }
204 
205  //Print values for debugging
206  const unsigned int debugLevel = 30;
207  if (nRecPatternMatches && fLog.GetLevel() >= debugLevel ) {
208  fLog("Channel", debugLevel, false)(channel.GetId())(":");
209  for ( size_t bin = 0; bin < numberOfSamples || fLog("|", debugLevel); ++bin )
210  if( traceRec.At(bin) ) fLog("|",debugLevel,false)(traceRec.At(bin))(":")(bin);
211  }
212 
213  }
214 
215  return nRecPatternMatches;
216  }
217 
218 
219  std::string
220  MdPatternFinder::PrintPatternMatchBins(const mevt::Channel& channel)
221  const
222  {
223  std::ostringstream os;
224  os.str("");
225  os << "at bin(s) ";
226 
227  if (channel.HasRecData() && !channel.IsMasked()) { // use unmasked channels only
229  end = channel.GetRecData().PatternMatchBinsEnd(); mut != end; ++mut) {
230  os << " " << (*mut);
231  }
232  }
233  return os.str();
234  }
235 
236 }
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.
PatternMatchBinIterator PatternMatchBinsBegin() const
Begin of the collection of times.
Counter level event data.
std::string GetRejectionReason() const
PatternMatchBinContainer::const_iterator PatternMatchBinIterator
ChannelRecData & GetRecData()
Functor implementing a constant window consecutive-rows-of-ones criteria.
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
bool IsRejected() const
Check if the counter is rejected.
int GetId() const
utl::TraceB & GetTrace()
Detector associated to muon detector hierarchy.
Definition: MDetector.h:32
Class representing a document branch.
Definition: Branch.h:107
Module level event data.
Definition: MEvent/Module.h:41
bool HasRecData() const
ChannelConstIterator ChannelsBegin() const
Array of Scintillator.
void ClearPatternMatchBins()
Clears pattern match detection times information.
void Clear()
Definition: Trace.h:158
PatternMatchBinIterator PatternMatchBinsEnd() const
End of the collection of times.
unsigned int GetNumberOfPatternMatchs() const
Retrieve the number of pattern matchs that impinged this scintillator.
bool IsMasked() const
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
int GetId() const
void SetWindowSize(const unsigned int ws)
unsigned int GetBufferLength() const
Number of bins of the buffer.
Definition: FrontEnd.h:130
const FrontEnd & GetFrontEnd() const
InternalModuleCollection::ComponentIterator ModuleIterator
void SetSegmentation(const size_t nm)
ModuleConstIterator ModulesBegin() const
Root detector of the muon detector hierarchy.
ChannelConstIterator ChannelsEnd() const
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
ModuleRecData & GetRecData()
const FrontEndSiPM & GetFrontEndSiPM() const
bool IsRejected() const
Channel level event data.
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
void SetTotalNumberOfChannelsOn(const unsigned int n)
Total number of channels with at least one pattern match (it cannot be greater than 64) ...
bool HasTrace() const
Channel level reconstruction data.
const Counter & GetCounter(int id) const
Retrieve Counter by id.
Definition: MDetector.h:68
bool HasRecData() const
void PushBack(const T &value)
Insert a single value at the end.
Definition: Trace.h:119
Root of the Muon event hierarchy.
Definition: MEvent.h:25
size_t GetNumberOfActiveChannels() const
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
void MakeRecData()
InternalChannelCollection::ComponentIterator ChannelIterator
Definition: MEvent/Module.h:68
unsigned int GetBufferLength() const
Number of bins of the buffer.
Definition: FrontEndSiPM.h:120

, generated on Tue Sep 26 2023.