OneBinStrategy.cc
Go to the documentation of this file.
1 #include "OneBinStrategy.h"
2 #include <TH1I.h>
3 #include <utl/Trace.h>
4 
5 namespace MdMuonEstimatorAG {
6 
7  OneBinStrategy::OneBinStrategy(unsigned int nTraceLength, double sampTime) :
8  fTraceSize(nTraceLength),
9  fSamplingTime(sampTime)
10  {
11  }
12 
13  double
14  OneBinStrategy::operator()(std::vector<std::pair<unsigned int, unsigned int>>& vModulePatternMatches, mevt::ModuleRecData& mRecData)
15  const
16  {
17  //std::cout << "In one bin strategy" << std::endl;
18  //std::cout << "Size " << vModulePatternMatches.size() << std::endl;
19 
20  double mu = 0;
21  double nmu = 0;
22  bool isSat = 0;
23  std::vector<double> vMu(fTraceSize, 0); //vector of length fTraceSize initialized to 0
24  std::vector<double> vNmu(fTraceSize, 0); //vector of length fTraceSize initialized to 0
25 
26 
27  if (vModulePatternMatches.size()>0) {
28  //std::cout << "Channels with signal ";
29  //for (std::vector<std::pair<unsigned int, unsigned int>>::const_iterator it = vModulePatternMatches.begin(); it != vModulePatternMatches.end(); ++it) {
30  //std::cout << it->first << " ";
31  //}
32  //std::cout << std::endl;
33 
34  // Build a histogram of pattern matches
35  TH1I hChannelsOn("h1", "Pattern matches", fTraceSize, 1, fTraceSize);
36  for (std::vector<std::pair<unsigned int, unsigned int>>::const_iterator it = vModulePatternMatches.begin(); it != vModulePatternMatches.end(); ++it) {
37  const unsigned int tbin = it->second + 1; // beware shift between vector and TH1 indexes
38  hChannelsOn.AddBinContent(tbin,1); // load the histogram
39  }
40 
41  //std::cout << "PatternMatch histogram" << std::endl;
42  //for (int i = 0; i <= hChannelsOn.GetNbinsX(); ++i) {
43  //if (hChannelsOn.GetBinContent(i)>0)
44  //std::cout << i << " ";
45  //}
46  //std::cout << std::endl;
47  //for (int i = 0; i <= hChannelsOn.GetNbinsX(); ++i) {
48  //if (hChannelsOn.GetBinContent(i)>0)
49  //std::cout << hChannelsOn.GetBinContent(i) << " ";
50  //}
51  //std::cout << std::endl;
52 
53 
54  // Count
55  unsigned int nActiveCh = mRecData.GetSegmentation(); // = number of active channels
56 
57  for (int i = 0; i <= hChannelsOn.GetNbinsX(); ++i) {
58  unsigned int ki = hChannelsOn.GetBinContent(i);
59  if (ki > 0) {
60  // Count inhibited channels for this time bin
61  // These are the number of pattern matches beginning at most mRecData.GetWindowSize()-1 (size of the pattern match) bins before i
62  unsigned int numInhibitedCh = 0;
63  for (int deltai = 1; ((deltai <= i) & (deltai < (int) mRecData.GetWindowSize())); ++deltai) {
64  numInhibitedCh += hChannelsOn.GetBinContent(i-deltai);
65  //std::cout << deltai << " ";
66  }
67  //std::cout << " , inhibChannels: " << numInhibitedCh << endl;
68  if (numInhibitedCh < nActiveCh) { // if not all channels are inhibited = if the module is not saturated
69  double mui = - (double) nActiveCh * log(1 - (double) ki/((double) nActiveCh- (double) numInhibitedCh));
70  double nmui = ((double) nActiveCh/((double) nActiveCh- (double) numInhibitedCh))* log(1 - (double) ki/((double) nActiveCh- (double) numInhibitedCh))/log(1.-1./((double) nActiveCh- (double) numInhibitedCh));
71  mu += mui;
72  nmu += nmui;
73  // Fill the reconstructed muon/number of muons trace
74  vMu[i] = mui;
75  vNmu[i] = nmui;
76  }
77  if (ki + numInhibitedCh >= nActiveCh) {
78  isSat = 1;
79  //std::cout << "Module is saturated" << std::endl;
80  }
81  }
82  }
83  }
84 
85  // Fill the reconstructed mu and nmu traces
86 
87  if (!mRecData.HasMeanMuonsVsTime())
88  mRecData.MakeMeanMuonsVsTime();
89 
90  if (!mRecData.HasNumberOfMuonsVsTime())
91  mRecData.MakeNumberOfMuonsVsTime();
92 
93  utl::Trace<double>& muTrace = mRecData.GetMeanMuonsVsTime();
94  utl::Trace<double>& nmuTrace = mRecData.GetNumberOfMuonsVsTime();
95  muTrace.Clear();
96  nmuTrace.Clear();
97 
98  for (unsigned int i = 0; i < fTraceSize; ++i) {
99  const double vMui = vMu[i];
100  muTrace.PushBack(vMui);
101  const double vNmui = vNmu[i];
102  nmuTrace.PushBack(vNmui);
103  }
104  // Set the binning
105  muTrace.SetBinning(fSamplingTime);
106  nmuTrace.SetBinning(fSamplingTime);
107 
108  // Print out the traces
109  //for (utl::TraceD::ConstIterator it = muTrace.Begin(); it != muTrace.End(); ++it) {
110  //if (*it != 0)
111  //std::cout << *it << " ";
112  //}
113  //std::cout << std::endl;
114 
115  //for (utl::TraceD::ConstIterator it = nmuTrace.Begin(); it != nmuTrace.End(); ++it) {
116  //if (*it != 0)
117  //std::cout << *it << " ";
118  //}
119  //std::cout << std::endl;
120 
121 
122  // Fill the reconstructed mu, nmu, and isSat
123  //std::cout << "Mu " << mu << std::endl;
124  //std::cout << "Nmu " << nmu << std::endl;
125  //std::cout << "IsSat " << isSat << std::endl;
126 
127  mRecData.SetMeanMuons(mu);
128  mRecData.SetNumberOfEstimatedMuons(nmu);
129  mRecData.SetSaturated(isSat);
130 
131  return nmu;
132  }
133 }
134 
135 
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
utl::TraceD & GetNumberOfMuonsVsTime()
void SetMeanMuons(const double m)
bool HasMeanMuonsVsTime() const
void Clear()
Definition: Trace.h:158
void SetNumberOfEstimatedMuons(const double m)
Number of estimated muons in a module.
void SetBinning(const double binning)
Definition: Trace.h:139
unsigned int GetWindowSize() const
bool HasNumberOfMuonsVsTime() const
OneBinStrategy(unsigned int fTraceSize, double fSamplingTime)
Creates a functor.
double operator()(std::vector< std::pair< unsigned int, unsigned int >> &vModulePatternMatches, mevt::ModuleRecData &mRecData) const
Performs the counting.
size_t GetSegmentation() const
void PushBack(const T &value)
Insert a single value at the end.
Definition: Trace.h:119
utl::TraceD & GetMeanMuonsVsTime()

, generated on Tue Sep 26 2023.