MdPatternFinder/ConsecutiveInWindowStrategy.cc
Go to the documentation of this file.
2 //
3 #include <mevt/ChannelRecData.h>
4 //
5 #include <utl/Trace.h>
6 
7 namespace MdPatternFinderAG {
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 
48  // counting criteria: fOnes consecutive patterns & inhibtion window not enabled.
49  if ( currSample && !vSampleInitBin ) {
50  // Check the specific quantity: if only 1, don't care about previous history.
51  // If more than one used the index of the leftiest one (without 0s in between).
52  if (fNumOnes == 1 || (firstOneFound && currBin-firstOneIndex + 1 == fNumOnes) ) {
53  // Register the pattern detection time: the first time of a one.
54  recData.AddPatternMatchBin(firstOneBin);
55  ++nPatternMatchs;
56  // The windows starts on the leftiest one.
57  sampleInitBin = firstOneBin;
58  vSampleInitBin = true; // enable inhibition window.
59  }
60  }
61  // Previous values for lookup update.
62  if (currSample) {
63  //std::cout << " currBin " << currBin << " firstOneIndex " << firstOneIndex << " sampleInitBin " << sampleInitBin
64  // << " currBin-sampleInitBin+1=" << currBin-sampleInitBin+1
65  // << " vSampleInitBin " << vSampleInitBin << " firstOneFound " << firstOneFound << std::endl;
66  if (!firstOneFound) {
67  // If the current is a 1 and we weren't
68  // having consecutive ones: this is the leftiest by
69  // now.
70  firstOneFound = true;
71  firstOneIndex = currBin;
72  firstOneBin = currBin;
73  }
74  } else {
75  // The current one is not a 1, then the consecutiveness is
76  // broken.
77  firstOneFound = false;
78  }
79 
80  // Window criteria
81  if (vSampleInitBin && fWindowSize <= (currBin-sampleInitBin)+1 ){
82  // Current window ended.
83  vSampleInitBin = false;
84  firstOneFound = false;
85  }
86 
87  }
88  }
89  return nPatternMatchs;
90  }
91 
92 }
93 
std::vector< T >::size_type SizeType
Definition: Trace.h:58
SizeType GetSize() const
Definition: Trace.h:156
void AddPatternMatchBin(unsigned int bin)
Adds the time of a pattern match detection.
ConsecutiveInWindowStrategy(unsigned int windowSize, unsigned int nOnes)
Creates a functor.
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.
unsigned int operator()(const utl::TraceB &samples, mevt::ChannelRecData &recData) const
Performs the counting.

, generated on Tue Sep 26 2023.