Likelihood.cc
Go to the documentation of this file.
1 #include "Likelihood.h"
2 #include <sstream>
3 
4 using std::cout;
5 using std::endl;
6 using std::vector;
7 
8 
9 namespace MdLDFFinderAG {
10 
11  Likelihood::Likelihood(const VLDFFunctor* const ldfFnc, const bool useSil, const unsigned int silLim, const bool useSat, const size_t satLim)
12  {
13  fLDFunction = ldfFnc;
14  fUseSilent = useSil;
15  fSilentLimit = silLim;
16  fUseSaturated = useSat;
17  fSaturationLimit = satLim;
18  siteCS = det::Detector::GetInstance().GetSiteCoordinateSystem();
19  }
20 
21 
22  double
23  Likelihood::operator()(const std::vector<double>& par)
24  const
25  {
26  double nLogLikelihood = 0;
27 
28  nLogLikelihood += CalculateCandidateLikelihood(par);
29 
30  if (fUseSilent)
31  nLogLikelihood += CalculateSilentLikelihood(par);
32 
33  return nLogLikelihood;
34  }
35 
36 
37  double
38  Likelihood::CalculateCandidateLikelihood(const std::vector<double>& par)
39  const
40  {
41  //DEBUGLOG( "Starting Likelihood evaluation");
42 
43  double nLogLikelihood = 0;
44  std::ostringstream os;
45  os.str("");
46 
47  os << "Nmu = " << par[0] << endl;
48  //DEBUGLOG ( os.str() );
49 
50  // core position
51  const double xcore = par[2];
52  const double ycore = par[3];
53  const utl::Point core = utl::Point(xcore, ycore, zcore, siteCS);
54 
55  const mdet::MDetector& mDetector = det::Detector::GetInstance().GetMDetector();
56 
57  for (auto ic = fCandidateCounters.begin(), icEnd = fCandidateCounters.end(); ic != icEnd; ++ic) {
58 
59  const mevt::Counter* co = *ic;
60 
61  const unsigned int counterId = co->GetId();
62  const mdet::Counter& mdetCounter = mDetector.GetCounter(counterId);
63 
64  // Loop over the modules
65  for (auto im = co->ModulesBegin(); im != co->ModulesEnd(); ++im) {
66 
67  if (!im->IsCandidate()) // skip non candidate modules
68  continue;
69 
70  const unsigned int moduleId = im->GetId();
71  const mdet::Module& mdetModule = mdetCounter.GetModule(moduleId);
72 
73  const double moduleArea = im->GetRecData().GetActiveArea();
74 
75  const utl::Point modulePosition = mdetModule.GetPosition();
76 
77  const double coreDistance = DistanceInShowerPlane(modulePosition - core);
78 
79  // muon density in the shower plane
80  const double muonDensity = (*fLDFunction)(coreDistance, &par[0]);
81  // number of muons expected in the module
82  const double predictedMuons = muonDensity * moduleArea * cosTheta;
83 
84  // check for saturation
85  bool isSaturated = im->GetRecData().SaturationFlag();
86 
87  // DEBUG
88  /*
89  os.str("");
90  os << "Processing counter " << co->GetId() << " - module " << im->GetId() << std::endl;
91  os << "Segmentation " << im->GetRecData().GetSegmentation() << std::endl;
92  os << "position = (" << modulePosition.GetX(siteCS) << ", " << modulePosition.GetY(siteCS)
93  << ", " << modulePosition.GetZ(siteCS) << ")" << std::endl
94  << "Distance to the core = " << coreDistance/utl::m << std::endl;
95  os << "Predicted muons = " << muonDensity << " * " << moduleArea << " * " << cosTheta
96  << " = " << predictedMuons << std::endl;
97  DEBUGLOG( os.str() );
98  */
99 
100  // calculate the negative of the log likelihood
101  double nLogLikelihood1; // likelihood of a counter
102  if (!isSaturated) { // if not saturared
103 
104  const double measuredMuons = im->GetRecData().GetNumberOfEstimatedMuons();
105  nLogLikelihood1 = predictedMuons - measuredMuons * std::log(predictedMuons);
106 
107  } else { // if saturated
108 
109  const unsigned int windowsOn = im->GetRecData().GetNumberOfChannelsOn();
110  nLogLikelihood1 = -utl::LogarithmOfNormalComplementCDF(windowsOn, predictedMuons, std::sqrt(predictedMuons));
111  }
112 
113  nLogLikelihood += nLogLikelihood1; // add the likelihood of this module
114 
115  }
116 
117  }
118  /*
119  os.str("");
120  os << "Total -logL = " << nLogLikelihood << std::endl;
121  os << "Finishing Likelihood evaluation" << std::endl ;
122  DEBUGLOG( os.str() );
123  */
124  return nLogLikelihood;
125  }
126 
127 }
double LogarithmOfNormalComplementCDF(const double x)
const Module & GetModule(const int mId) const
Retrieve by id a constant module.
Point object.
Definition: Point.h:32
Counter level event data.
double DistanceInShowerPlane(const utl::Vector v) const
utl::Point GetPosition() const
Detector associated to muon detector hierarchy.
Definition: MDetector.h:32
Likelihood(const VLDFFunctor *const ldfFnc, const bool useSil, const unsigned int silLim, const bool useSat, const size_t satLim)
Creates a functor.
Definition: Likelihood.cc:11
utl::CoordinateSystemPtr siteCS
Array of Scintillator.
double operator()(const std::vector< double > &par) const
Perform the actual count.
Definition: Likelihood.cc:23
ModuleConstIterator ModulesBegin() const
Common interface for functors performing the muon LDF fitting.
Definition: VLDFFunctor.h:26
double CalculateSilentLikelihood(const std::vector< double > &par) const
Likelihood of silent counters.
Root detector of the muon detector hierarchy.
int GetId() const
The id of the counter.
ModuleConstIterator ModulesEnd() const
int GetId() const
The id of this component.
const Counter & GetCounter(int id) const
Retrieve Counter by id.
Definition: MDetector.h:68
double CalculateCandidateLikelihood(const std::vector< double > &par) const
Definition: Likelihood.cc:38

, generated on Tue Sep 26 2023.