19 if ( data == 0 )
return mc;
24 else if ( data >= mc )
return 0.;
29 return ( mc - data + data * std::log( data / mc ) );
53 else if ( data >= mc )
return 0.;
57 const double fractional = std::sqrt( w2 ) / newmc;
59 const double fractional2 = fractional * fractional;
61 const double temp = newmc * fractional2 - 1;
63 const double temp2 = temp * temp + 4 * data * fractional2;
65 MACH3LOG_ERROR(
"Negative square root in Barlow Beeston coefficient calculation!");
69 const double beta = ( -1 * temp + sqrt( temp2 ) ) / 2.;
72 double stat = mc * beta;
76 stat = newmc - data + data * std::log( data / newmc );
82 if ( fractional > 0 ) penalty = ( beta - 1 ) * ( beta - 1 ) / ( 2 * fractional2 );
103 else if ( data >= mc )
return 0.;
107 const double k = newmc * newmc / w2;
109 const double beta = ( data + k ) / ( newmc + k );
114 const double penalty = k * beta - k + k * std::log( k / ( k * beta ) );
120 if ( data > 0 ) stat = newmc - data + data * std::log( data / newmc );
142 const long double b = mc / w2;
143 const long double a = mc * b + 1;
146 const double stat = double( -1 * ( a * logl( b ) + lgammal( data + a ) - lgammal( data + 1 ) - ( ( data + a ) * log1pl( b ) ) - lgammal( a ) ) );
153 if ( stat > poisson )
return poisson;
165 if ( data == 0 )
return mc/2.;
170 else if ( data >= mc )
return 0.;
174 return ( data - mc ) * ( data - mc ) / ( 2 * mc );
200 buf = std::cout.rdbuf();
201 errbuf = std::cerr.rdbuf();
202 std::cout.rdbuf(
nullptr );
203 std::cerr.rdbuf(
nullptr );
214 std::cout.rdbuf(
buf);
@ kNTestStatistics
Number of test statistics.
@ kPearson
Standard Pearson likelihood .
@ kBarlowBeeston
Barlow-Beeston () following Conway approximation ()
@ kDembinskiAbdelmotteleb
Based on .
@ kPoisson
Standard Poisson likelihood .
Custom exception class used throughout MaCh3.
TestStatistic fTestStatistic
Test statistic tells what kind of likelihood sample is using.
std::streambuf * errbuf
Keep the cerr buffer.
std::streambuf * buf
Keep the cout buffer.
double GetPoissonLLH(const double data, const double mc) const
Calculate test statistic for a single bin using Poisson.
double GetTestStatLLH(const double data, const double mc, const double w2) const
Calculate test statistic for a single bin. Calculation depends on setting of fTestStatistic....
M3::int_t nSamples
Contains how many samples we've got.
virtual ~SampleHandlerInterface()
destructor
void NowTalk()
CW: Redirect std::cout to silence some experiment specific libraries.
SampleHandlerInterface()
The main constructor.
void QuietPlease()
CW: Redirect std::cout to silence some experiment specific libraries.
constexpr static const double _LOW_MC_BOUND_
MC prediction lower bound in bin to identify problematic binning definitions and handle LogL calculat...