LikeFCN.cc
Go to the documentation of this file.
1 #include "LikeFCN.h"
2 
3 #include <cmath>
4 #include <iostream>
5 #include <iomanip>
6 
7 namespace MdLDFFinderAG {
8 
9  const double LikeFCN::EPSILON = 1e-4;
10 
11 
12  LikeFCN::LikeFCN(const unsigned int n0, const SegmentsOnMulti& km0, const double mu0) :
13  fNumberSegments(n0),
14  fSegmentsOnMulti(km0),
15  fMuons(mu0)
16  { }
17 
18 
19  LikeFCN::LikeFCN(const unsigned int n0, const std::vector<unsigned int>& k0, const double mu0) :
20  fNumberSegments(n0),
21  fMuons(mu0)
22  {
23  for (std::vector<unsigned int>::const_iterator it1 = k0.begin(); it1 != k0.end(); ++it1)
24  fSegmentsOnMulti.push_back(std::make_pair(*it1, 1));
25  }
26 
27 
28  // Evaluates the negative of the logarithm of the likelihood (which is always positive!)
29  // of mu_i expected muons in each time bin with the condition that the sum of the mu_i's
30  // is a fixed mu (profile likelihood)
31  // Input: par vector are mu_i with i = 1,...,w-1 and w the number of time bins
32  // Output: negative of the log likelihood for mu
33 
34  double
35  LikeFCN::operator()(const std::vector<double>& par)
36  const
37  {
38  // Build a vector holding the mu_i's (i=1,..,w), the last element is
39  // (mu minus the sum of the mu_i's)
40 
41  std::vector<double> vmu(par);
42  double parWsum = 0; // sum vmu weighted with k multiplicy
43 
44  std::vector<double>::const_iterator it1;
45  SegmentsOnMulti::const_iterator it2;
46 
47  for (it1 = par.begin(), it2 = fSegmentsOnMulti.begin();
48  it1 != par.end(); ++it1, ++it2) {
49 
50  //std::cout << "mu_i = " << *it1 << ", m = " << (*it2).second << std::endl;
51 
52  parWsum += *it1 * (it2->second);
53 
54  }
55 
56  // calculate mulast using the multiplicity of the last window
57  double mulast = (fMuons - parWsum) / fSegmentsOnMulti.back().second;
58 
59  if (mulast < EPSILON)
60  mulast = EPSILON; // trick to avoid divergences
61 
62  // Debug
63  //std::cout << "In LikeFCN::operator(). mulast = " << mulast << std::endl;
64 
65  vmu.push_back(mulast);
66 
67  // Evaluate likelihood
68  double nlnLike = 0; // negative log of the likelihood (>0!)
69 
70  for (it1 = vmu.begin(), it2 = fSegmentsOnMulti.begin();
71  it2 != fSegmentsOnMulti.end() && it1 != vmu.end(); ++it1, ++it2) {
72 
73  const double k = it2->first;
74  const double m = it2->second;
75  const double p = 1 - exp(-(*it1) / fNumberSegments);
76 
77  nlnLike -= m*(k*log(p) + (fNumberSegments - k)*log(1 - p));
78 
79  }
80 
81  //std::cout << "In LikeFCN::operator(). nlnLike = ";
82  //std::cout << std::setprecision(9) << nlnLike << std::endl;
83 
84  return nlnLike;
85  }
86 
87 
88  double
89  LikeFCN::operator()(const double* const mup, const double* const)
90  const
91  {
92  std::vector<double> k;
93  k.push_back(mup[0]);
94  k.push_back(mup[1]);
95  return this->operator()(k);
96  }
97 
98 }
unsigned int fNumberSegments
Definition: LikeFCN.h:50
double operator()(const std::vector< double > &) const
Definition: LikeFCN.cc:35
SegmentsOnMulti fSegmentsOnMulti
Definition: LikeFCN.h:52
LikeFCN(const unsigned int, const std::vector< unsigned int > &, const double)
Definition: LikeFCN.cc:19
const double mu0
Definition: GalacticUnits.h:48
static const double EPSILON
Definition: LikeFCN.h:26
std::vector< std::pair< unsigned int, unsigned int > > SegmentsOnMulti
Definition: LikeFCN.h:21
constexpr double m
Definition: AugerUnits.h:121

, generated on Tue Sep 26 2023.