Likelihood3.cc
Go to the documentation of this file.
1 #include "Likelihood3.h"
2 #include <sstream>
3 
4 using std::cout;
5 using std::endl;
6 using std::vector;
7 
8 
9 namespace MdLDFFinderAG {
10 
11  Likelihood3::Likelihood3(const VLDFFunctor* const ldfFnc, const bool useSil, const unsigned int silLim, const bool useSat)
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  Likelihood3::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  Likelihood3::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  const unsigned int chOn = im->GetRecData().GetTotalNumberOfChannelsOn();
85 
86  const unsigned int segmentation = im->GetRecData().GetSegmentation();
87 
88  // check for saturation // TODO use this to check if the user wants to use saturated modules or not
89  //bool isSaturated = im->GetRecData().SaturationFlag();
90 
91  // DEBUG
92  /*
93  os.str("");
94  os << "Processing counter " << co->GetId() << " - module " << im->GetId() << std::endl;
95  os << "Segmentation " << im->GetRecData().GetSegmentation() << std::endl;
96  os << "position = (" << modulePosition.GetX(siteCS) << ", " << modulePosition.GetY(siteCS)
97  << ", " << modulePosition.GetZ(siteCS) << ")" << std::endl
98  << "Distance to the core = " << coreDistance/utl::m << std::endl;
99  os << "Predicted muons = " << muonDensity << " * " << moduleArea << " * " << cosTheta
100  << " = " << predictedMuons << std::endl;
101  DEBUGLOG( os.str() );
102  */
103 
104  // calculate the negative of the log likelihood
105  double nLogLikelihood1; // likelihood of a counter
106 
107  //const double measuredMuons = CornerClippLike::GetNumberOfEstimatedMuonsCorrected(*im, mDetModule, rAxis, siteCS)
108 
109  const double ratio = double(chOn) / double(segmentation);
110 
111  const double pcc = im->GetRecData().GetCornerClippingProbability();
112 
113  nLogLikelihood1 = predictedMuons*(1+pcc)*(1. - ratio) - chOn * std::log(1 - std::exp(-predictedMuons*(1+pcc) / segmentation));
114  //nLogLikelihood1 = predictedMuons - chOn * std::log(std::exp(predictedMuons / segmentation) -1);
115  nLogLikelihood += nLogLikelihood1; // add the likelihood of this module
116 
117  }
118 
119  }
120  /*
121  os.str("");
122  os << "Total -logL = " << nLogLikelihood << std::endl;
123  os << "Finishing Likelihood evaluation" << std::endl ;
124  DEBUGLOG( os.str() );
125  */
126  return nLogLikelihood;
127  }
128 
129 }
Likelihood3(const VLDFFunctor *const ldfFnc, const bool useSil, const unsigned int silLim, const bool useSat)
Creates a functor.
Definition: Likelihood3.cc:11
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
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
double operator()(const std::vector< double > &par) const
Perform the actual count.
Definition: Likelihood3.cc:23
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: Likelihood3.cc:38

, generated on Tue Sep 26 2023.