AmountInWindowStrategy.cc
Go to the documentation of this file.
2 //
3 #include <mevt/ChannelRecData.h>
4 //
5 #include <utl/Trace.h>
6 //
7 #include <deque>
8 
9 namespace MdMuonCounterAG {
10 
11  AmountInWindowStrategy::AmountInWindowStrategy(unsigned int windowSize, unsigned int nOnes) :
12  fWindowSize(windowSize) ,
13  fNumOnes(nOnes)
14  {
15  }
16 
17  unsigned int
19  const
20  {
21  unsigned int nPatternMatchs = 0;
22  /*
23  * The sample has to contain at least fNumOnes samples.
24  */
25  if (samples.GetSize() >= fNumOnes) {
26  // Window to accumulate the positive samples
27  // and the zeros following them (til next positive sample).
28  typedef std::deque<std::pair<double, unsigned int> > Window;
29  //typedef Window::const_iterator WinItor;
30  Window win;
31  // Global count of zeros within the current window.
32  unsigned int nZeros = 0;
33  for (utl::TraceB::SizeType sNumber = 0; sNumber < samples.GetSize();) {
34  /*
35  * Window updating.
36  */
37  if (samples[ sNumber ]) {
38  // Register the bin and an own zero count.
39  win.push_back( std::make_pair(sNumber,0) );
40  } else if (! win.empty()){
41  // If there's an open window, increase the zero count
42  // (of the trailing element of the window),
43  win.back().second++;
44  // ... and increase the global count.
45  ++nZeros;
46  }
47  // Advance to the next (or the samples are exhausted).
48  ++sNumber;
49  /*
50  * Window checking.
51  */
52  // If not empty, then a window is being considered.
53  if (! win.empty() ) {
54  // Check if we ran out of samples, or the advanced-to sample lies outside the window.
55  // In both cases we have to analyze what's in the window.
56  if ( sNumber==samples.GetSize() || !( sNumber-win.front().first<=fWindowSize ) ) {
57  bool detected;
58  // If there are not enought ones, no way: not detected.
59  if (win.size() < fNumOnes) {
60  detected = false;
61  // Erase only the first element (reducing the quantity of ones):
62  // it has been found that a window starting at this one is not good.
63  // Before poping, substract the zeros from the to-be-eliminated one from
64  // the grand total.
65  nZeros -= win.front().second;
66  win.pop_front();
67  } else {
68  // If there are more than what's required, then it's a muon for sure.
69  detected = true;
70  }
71  /*
72  * On-detection actions.
73  */
74  if (detected) {
75  // The bin of detection is the start bin (note that with the strategy
76  // here implemented the first bin is guaranteed to be correspond
77  // to a one, but not the last).
78  nZeros = 0;
79  recData.AddPatternMatchBin(win.front().first);
80  ++nPatternMatchs;
81  // Get rid of everything because we have already counted a muon.
82  win.clear();
83  }
84  }
85  }
86  }
87  }
88  return nPatternMatchs;
89  }
90 
91 }
92 
AmountInWindowStrategy(unsigned int windowSize, unsigned int nOnes)
Creates a functor.
unsigned int operator()(const utl::TraceB &samples, mevt::ChannelRecData &recData) const
Performs the counting.
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.
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.