NBinStrategy.cc
Go to the documentation of this file.
1 #include "NBinStrategy.h"
2 #include <TH1I.h>
3 
4 namespace MdMuonEstimatorAG {
5 
6  NBinStrategy::NBinStrategy(unsigned int nBinWindowSize, unsigned int nTraceLength) :
7  fNBinWindowSize(nBinWindowSize),
8  fTraceSize(nTraceLength)
9  {
10  }
11 
12  double
13  NBinStrategy::operator()(std::vector<std::pair<unsigned int, unsigned int>>& vModulePatternMatches, mevt::ModuleRecData& mRecData)
14  const
15  {
16  //std::cout << "In N bin 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  // Build a histogram of pattern matches
31  TH1I hChannelsOn("h1", "Pattern matches", fTraceSize, 1, fTraceSize);
32  for (std::vector<std::pair<unsigned int, unsigned int>>::const_iterator it = vModulePatternMatches.begin(); it != vModulePatternMatches.end(); ++it) {
33  const unsigned int tbin = it->second + 1; // beware shift between vector and TH1 indexes
34  hChannelsOn.AddBinContent(tbin,1); // load the histogram
35  }
36  // Rebin the histogram in windows of size fNBinWindowSize
37  if (fNBinWindowSize <= fTraceSize) {
38  hChannelsOn.Rebin(fNBinWindowSize); // group bins according to the window size
39  } else {
40  hChannelsOn.Rebin(fTraceSize);
41  }
42 
43  // Count
44  unsigned int nActiveCh = mRecData.GetSegmentation(); // = number of active channels
45  for (int i = 0; i <= hChannelsOn.GetNbinsX(); ++i) {
46  unsigned int ki = hChannelsOn.GetBinContent(i);
47  if (ki > 0) {
48  mu -= (double) nActiveCh * log(1. - (double) ki/(double) nActiveCh);
49  nmu += log(1. - (double) ki/(double) nActiveCh) / log(1.-1./(double) nActiveCh);
50  }
51  if (ki >= nActiveCh){
52  isSat = 1;
53  //std::cout << "Module is saturated" << std::endl;
54  }
55  }
56  }
57  //std::cout << "Mu " << mu << std::endl;
58  //std::cout << "Nmu " << nmu << std::endl;
59  //std::cout << "IsSat " << isSat << std::endl;
60 
61  mRecData.SetMeanMuons(mu);
62  mRecData.SetNumberOfEstimatedMuons(nmu);
63  mRecData.SetSaturated(isSat);
64 
65  return nmu;
66  }
67 }
68 
69 
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
double operator()(std::vector< std::pair< unsigned int, unsigned int >> &vModulePatternMatches, mevt::ModuleRecData &mRecData) const
Performs the counting.
Definition: NBinStrategy.cc:13
void SetMeanMuons(const double m)
NBinStrategy(unsigned int nBinWindowSize, unsigned int fTraceSize)
Creates a functor.
Definition: NBinStrategy.cc:6
void SetNumberOfEstimatedMuons(const double m)
Number of estimated muons in a module.
size_t GetSegmentation() const

, generated on Tue Sep 26 2023.