NBinCenteredStrategy.cc
Go to the documentation of this file.
1 #include "NBinCenteredStrategy.h"
2 #include <TH1I.h>
3 
4 namespace MdMuonEstimatorAG {
5 
6  NBinCenteredStrategy::NBinCenteredStrategy(unsigned int nBinWindowSize, unsigned int nTraceLength) :
7  fNBinWindowSize(nBinWindowSize),
8  fTraceSize(nTraceLength)
9  {
10  }
11 
12  double
13  NBinCenteredStrategy::operator()(std::vector<std::pair<unsigned int, unsigned int>>& vModulePatternMatches, mevt::ModuleRecData& mRecData)
14  const
15  {
16  //std::cout << "In N bin centered strategy" << std::endl;
17  //std::cout << "Size " << vModulePatternMatches.size() << std::endl;
18 
19  double mu = 0;
20  double nmu = 0;
21  bool isSat = 0;
22 
23  if (vModulePatternMatches.size()>0) {
24  //std::cout << "Channels with signal ";
25  //for (std::vector<std::pair<unsigned int, unsigned int>>::const_iterator it = vModulePatternMatches.begin(); it != vModulePatternMatches.end(); ++it) {
26  //std::cout << it->first << " ";
27  //}
28  //std::cout << std::endl;
29 
30  // Create a vector that contains the sum of pattern matches (any of the bins of the pattern contributes) in each time bin of the trace
31  unsigned int vSummedPatternMatches[fTraceSize] = {0};
32  for (std::vector<std::pair<unsigned int, unsigned int>>::const_iterator it = vModulePatternMatches.begin(); it != vModulePatternMatches.end(); ++it) {
33  for (unsigned int i = 0 ; i < mRecData.GetWindowSize() ; ++i) { //mRecData.GetWindowSize() = size of the pattern match
34  if ((int) it->second - (int) i >= 0) {
35  ++vSummedPatternMatches[(int) it->second - (int) i];
36  }
37  }
38  }
39  //std::cout << "SUMMED VECTOR" << std::endl;
40  //for (unsigned int i = 0; i < nTraceSamples; ++i) {
41  // std::cout << vSummedPatternMatches[i] << " ";
42  //}
43  //std::cout << std::endl;
44 
45  //Find the (first) bin where the sum is maximum
46  unsigned int imax = 0; // imax is the bin with maximum counts
47  unsigned int maxcounts = 0; // maxcounts is the number of pattern matches (any of the bins of the pattern contributes) in the bin imax
48  for (unsigned int i = 0; i < fTraceSize; ++i) {
49  if (vSummedPatternMatches[i] > maxcounts) {
50  maxcounts = vSummedPatternMatches[i];
51  imax = i;
52  }
53  }
54 
55  // Define the start time and size of the histogram such that there is a window of size fNBinWindowSize opening at time-bin imax
56  unsigned int histogramStartTime = imax % fNBinWindowSize + 1; // beware shift between vector and TH1 indexes
57  unsigned int histogramSize = fTraceSize - histogramStartTime + 1;
58  //std::cout << " histogramStartTime " << histogramStartTime << " histogramSize " << histogramSize << endl;
59 
60  // Build a histogram of pattern matches
61  TH1I hChannelsOn("h", "Pattern matches", histogramSize, histogramStartTime, histogramSize); //XXX Check!!!!
62  for (std::vector<std::pair<unsigned int, unsigned int>>::const_iterator it = vModulePatternMatches.begin(); it != vModulePatternMatches.end(); ++it) {
63  const unsigned int bin = it->second + 1; // beware shift between vector and TH1 indexes
64  hChannelsOn.Fill(bin); // load the histogram
65  }
66 
67  // Rebin the histogram in windows of size fNBinWindowSize
68  if (fNBinWindowSize <= fTraceSize) {
69  hChannelsOn.Rebin(fNBinWindowSize); // group bins according to the window size
70  } else {
71  hChannelsOn.Rebin(fTraceSize);
72  }
73 
74  // Count
75  unsigned int nActiveCh = mRecData.GetSegmentation(); // = number of active channels
76  for (int i = 0; i <= hChannelsOn.GetNbinsX(); ++i) {
77  unsigned int ki = hChannelsOn.GetBinContent(i);
78  if (ki > 0) {
79  mu -= (double) nActiveCh * log(1. - (double) ki/(double) nActiveCh);
80  nmu += log(1. - (double) ki/(double) nActiveCh) / log(1.-1./(double) nActiveCh);
81  }
82  if (ki >= nActiveCh){
83  isSat = 1;
84  //std::cout << "Module is saturated" << std::endl;
85  }
86  }
87  }
88  //std::cout << "Mu " << mu << std::endl;
89  //std::cout << "Nmu " << nmu << std::endl;
90  //std::cout << "IsSat " << isSat << std::endl;
91 
92  mRecData.SetMeanMuons(mu);
93  mRecData.SetNumberOfEstimatedMuons(nmu);
94  mRecData.SetSaturated(isSat);
95 
96  return nmu;
97  }
98 }
99 
100 
Module level reconstruction data. This class contains all data required by the muon reconstruction...
Definition: ModuleRecData.h:29
void SetSaturated(const bool sat)
Definition: ModuleRecData.h:84
void SetMeanMuons(const double m)
void SetNumberOfEstimatedMuons(const double m)
Number of estimated muons in a module.
unsigned int GetWindowSize() const
size_t GetSegmentation() const
NBinCenteredStrategy(unsigned int nBinWindowSize, unsigned int fTraceSize)
Creates a functor.
double operator()(std::vector< std::pair< unsigned int, unsigned int >> &vModulePatternMatches, mevt::ModuleRecData &mRecData) const
Performs the counting.

, generated on Tue Sep 26 2023.