Likelihood2.cc
Go to the documentation of this file.
1 #include "Likelihood2.h"
2 
3 #include <utl/ErrorLogger.h>
4 #include <utl/Math.h>
5 #include <utl/Trace.h>
6 //
7 #include <vector>
8 #include <iostream>
9 #include <limits>
10 
11 
12 using std::cout;
13 using std::endl;
14 using std::vector;
15 
16 namespace MdLDFFinderAG
17 {
18 
19 Likelihood2::Likelihood2(const VLDFFunctor* ldfFnc, bool useSil, unsigned int silLim)
20 {
21  fLDFunction = ldfFnc;
22  fUseSilent = useSil;
23  fSilentLimit = silLim;
24  siteCS = det::Detector::GetInstance().GetSiteCoordinateSystem();
25 }
26 
27 double
28  Likelihood2::operator()(const std::vector<double>& par)
29 const
30 {
31  double nLogLikelihood = 0;
32 
33  nLogLikelihood += CalculateCandidateLikelihood(par);
34 
35  if (fUseSilent==true) {
36  nLogLikelihood += CalculateSilentLikelihood(par);
37  }
38 
39  return nLogLikelihood;
40 
41 }
42 
43 double
44  Likelihood2::CalculateCandidateLikelihood(const std::vector<double>& par)
45 const
46 {
47 // INFO("Starting");
48 
49  std::ostringstream info("");
50 
51 // cout << "Starting Likelihood2 evaluation" << endl ;
52 
53  double nLogLikelihood = 0;
54 
55  // Debug
56 /* INFO("Parameters");
57  cout << "Nmu = " << par[0] << endl;
58  cout << "Beta = " << par[1] << endl;
59  cout << "xcore = " << par[2] << endl;
60  cout << "ycore = " << par[3] << endl;
61 */
62 
63  // core position
64  const double xcore = par[2];
65  const double ycore = par[3];
66  const utl::Point core = utl::Point(xcore, ycore, zcore, siteCS);
67 
68 // info.str("");
69 // info << "Core = (" << core.GetX(siteCS) << ", " << core.GetY(siteCS) << ", " << core.GetZ(siteCS) << ")" << endl;
70 // INFO(info.str());
71 
72  const mdet::MDetector& mDetector = det::Detector::GetInstance().GetMDetector();
73 
74  for (CounterList::const_iterator ic = fCandidateCounters.begin();
75  ic != fCandidateCounters.end(); ++ic) {
76 
77  const mevt::Counter* co = *ic;
78 
79  unsigned int counterId = co->GetId();
80  const mdet::Counter& mdetCounter = mDetector.GetCounter(counterId);
81 
82  // Loop over the modules
83  for (auto im = co->ModulesBegin(); im != co->ModulesEnd(); ++im) {
84 
85  if(!im->IsCandidate()) { // skip non candidate modules
86  continue;
87  }
88 
89  unsigned int moduleId = im->GetId();
90  const mdet::Module& mdetModule = mdetCounter.GetModule(moduleId);
91 
92  const double moduleArea = im->GetRecData().GetActiveArea();
93 
94  const utl::Point modulePosition = mdetModule.GetPosition();
95 
96  const double coreDistance = DistanceInShowerPlane(modulePosition-core);
97  size_t activeChannels = im->GetNumberOfActiveChannels();
98  const utl::TraceUI& channelsOn = im->GetRecData().GetChannelsOn();
99 
100  // Calculate likelihood
101  const double muonDensity = (*fLDFunction)( coreDistance, &par[0] ); // muon density in the shower plane
102  const double predictedMuons = muonDensity * moduleArea * cosTheta; // number of muons expected in the module
103 
104  // DEBUG
105 /* INFO("");
106  cout << "Processing counter " << co->GetId() << " - module " << im->GetId() << endl
107  << "position = (" << modulePosition.GetX(siteCS) << ", " << modulePosition.GetY(siteCS)
108  << ", " << modulePosition.GetZ(siteCS) << ")" << endl
109  << "Distance to the core = " << coreDistance << endl;
110  cout << "LDF(r) = " << muonDensity << endl;
111  cout << "Predicted muons = " << predictedMuons << endl;
112  cout << "channelsOn = ";
113  for(std::vector<size_t>::iterator it=channelsOn.begin(); it!=channelsOn.end(); ++it) {
114  cout << *it << " ";
115  }
116  cout << endl;
117 */
118 
119  ProfLike nLogLike1(activeChannels,channelsOn);
120 // INFO("After creating the likelihood");
121 
122  const double nLogLikelihood1 = nLogLike1(predictedMuons); // calculate the negative of the log likelihood
123 // INFO("After evaluating the likelihood");
124 
125  nLogLikelihood += nLogLikelihood1; // add the likelihood of this module
126 
127  // DEBUG
128 /* INFO("");
129  cout << "nLogLikelihood1 = " << nLogLikelihood1;
130  cout << ", nLogLikelihood = " << nLogLikelihood << endl;
131 */
132  }
133 
134  } // end counter loop
135 
136 // cout << "Total -logL = " << nLogLikelihood << endl;
137 // cout << "Finishing Likelihood2 evaluation" << endl ;
138 
139 // INFO("Finishing");
140 
141  return nLogLikelihood;
142 }
143 
144 }
145 
const Module & GetModule(const int mId) const
Retrieve by id a constant module.
Point object.
Definition: Point.h:32
double CalculateCandidateLikelihood(const std::vector< double > &par) const
Definition: Likelihood2.cc:44
Counter level event data.
double operator()(const std::vector< double > &par) const
Perform the actual count.
Definition: Likelihood2.cc:28
double DistanceInShowerPlane(const utl::Vector v) const
utl::Point GetPosition() const
Detector associated to muon detector hierarchy.
Definition: MDetector.h:32
utl::CoordinateSystemPtr siteCS
Array of Scintillator.
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
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
int GetId() const
The id of this component.
const Counter & GetCounter(int id) const
Retrieve Counter by id.
Definition: MDetector.h:68
Likelihood2(const VLDFFunctor *ldfFnc, bool useSil, unsigned int silLim)
Creates the likelihood.
Definition: Likelihood2.cc:19

, generated on Tue Sep 26 2023.