MdMuonCounterAG/ConsecutiveInWindowStrategy.cc
Go to the documentation of this file.
2 //
3 #include <mevt/ChannelRecData.h>
4 //
5 #include <utl/Trace.h>
6 
7 namespace MdMuonCounterAG {
8 
9  ConsecutiveInWindowStrategy::ConsecutiveInWindowStrategy(unsigned int windowSize, unsigned int nOnes) :
10  fWindowSize(windowSize) ,
11  fNumOnes(nOnes)
12  {
13  }
14 
15  unsigned int
17  const
18  {
19  unsigned int nPatternMatchs = 0;
20  /*
21  * The sample has to contain at least fNumOnes samples.
22  */
23  if (samples.GetSize() >= fNumOnes) {
24  /*
25  * This variables hold the index and time
26  * of the first one (true) after a zero.
27  * ie all the samples starting from this
28  * index until the current one are true.
29  * The bool variable indicates whether the
30  * one was found, or not in which case theirs
31  * values are meaningless.
32  */
33  unsigned int firstOneIndex = 0; // dummy init to please compilers.
34  unsigned int firstOneBin = 0; // idem.
35  bool firstOneFound = false;
36  /*
37  * Inhibition window.
38  * Start of the sampling window & whether
39  * the time is valid (ie a window was found).
40  * Curious: these two variables will properly
41  * initialized within the loop.
42  */
43  unsigned int sampleInitBin = 0; // dummy init to please compilers.
44  bool vSampleInitBin = false;
45  for (utl::TraceB::SizeType currBin = 0; currBin < samples.GetSize(); ++currBin) {
46  bool currSample = samples[ currBin ];
47  // Counting criteria: fOnes consecutive muons & inhibtion window not enabled.
48  if ( currSample && !vSampleInitBin ) {
49  // Check the specific quantity: if only 1, don't care about previous history.
50  // If more than one used the index of the leftiest one (without 0s in between).
51  if (fNumOnes == 1 || (firstOneFound && currBin- firstOneIndex + 1 == fNumOnes) ) {
52  // Register the muon detection time: the first time of a one.
53  recData.AddPatternMatchBin(firstOneBin);
54  ++nPatternMatchs;
55  // The windows starts on the leftiest one.
56  sampleInitBin = firstOneBin;
57  vSampleInitBin = true; // enable inhibition window.
58  }
59  }
60  // Previous values for lookup update.
61  if (currSample) {
62  if (! firstOneFound) {
63  // If the current is a 1 and we weren't
64  // having consecutive ones: this is the leftiest by
65  // now.
66  firstOneFound = true;
67  firstOneIndex = currBin;
68  firstOneBin = currBin;
69  }
70  } else {
71  // The current one is not a 1, then the consecutiveness is
72  // broken.
73  firstOneFound = false;
74  }
75  // Window criteria: note the strict < for window finalization.
76  if (vSampleInitBin && fWindowSize < (currBin - sampleInitBin)){
77  // Current window ended.
78  vSampleInitBin = false;
79  }
80  }
81  }
82  return nPatternMatchs;
83  }
84 
85 }
86 
unsigned int operator()(const utl::TraceB &samples, mevt::ChannelRecData &recData) const
Performs the counting.
std::vector< T >::size_type SizeType
Definition: Trace.h:58
ConsecutiveInWindowStrategy(unsigned int windowSize, unsigned int nOnes)
Creates a functor.
SizeType GetSize() const
Definition: Trace.h:156
void AddPatternMatchBin(unsigned int bin)
Adds the time of a pattern match detection.
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
Channel level reconstruction data.

, generated on Tue Sep 26 2023.