1 #ifndef PhysicsTools_Utilities_Likelihood_h 2 #define PhysicsTools_Utilities_Likelihood_h 9 template<
typename PDF,
typename Tuple>
11 static double evaluate(
const PDF & pdf,
const Tuple & tuple) {
17 template<
typename PDF>
26 template<
typename Sample,
typename PDF,
typename Yield = NoExtendedLikelihood>
31 pdf_(& pdf), yield_(&yield), sample_(sample) {
35 double l = - (*yield_)();
36 for(
typename Sample::const_iterator
i = sample_.begin();
i != sample_.end(); ++
i) {
37 double p = Evaluator::evaluate(*pdf_, *
i);
40 sampleSize_ = sample_.size();
44 return std::log(TMath::Factorial(sampleSize_));
47 return log() - logNFactorial();
49 PDF &
pdf() {
return * pdf_; }
50 const PDF &
pdf()
const {
return * pdf_; }
51 Yield &
yield() {
return * yield_; }
52 const Yield &
yield()
const {
return * yield_; }
59 mutable unsigned int sampleSize_ = 0u;
62 template<
typename Sample,
typename PDF>
67 pdf_(& pdf), sample_(sample) {
72 for(
typename Sample::const_iterator
i = sample_.begin();
i != sample_.end(); ++
i) {
73 l +=
std::log(Evaluator::evaluate(*pdf_, *
i));
77 PDF &
pdf() {
return * pdf_; }
78 const PDF &
pdf()
const {
return * pdf_; }
85 template<
typename Sample,
typename PDF,
typename Yield>
88 std::cout <<
"-2 log(maximum-likelihood) = " << amin <<
", free parameters = " << numberOfFreeParameters
93 template<
typename Sample,
typename PDF,
typename Yield>
LikelihoodEvaluator< PDF, typename Sample::value_type > Evaluator
static double evaluate(const Likelihood< Sample, PDF, Yield > &f)
double logNFactorial() const
Likelihood(const Sample &sample, PDF &pdf, Yield &yield)
static double evaluate(const PDF &pdf, const Tuple &tuple)
static void print(double amin, unsigned int numberOfFreeParameters, const Likelihood< Sample, PDF, Yield > &f)
LikelihoodEvaluator< PDF, typename Sample::value_type > Evaluator
static double evaluate(const PDF &pdf, const double val)
double operator()() const
double absoluteLog() const
const Yield & yield() const
double operator()() const
unsigned int sampleSize() const
Likelihood(const Sample &sample, PDF &pdf)