25 #include <Math/ProbFuncMathCore.h>
34 , fHistogramExpected(0)
52 , fHistogramExpected(0)
70 , fHistogramExpected(0)
90 , fHistogramExpected(0)
110 BCLog::OutError(
"BCHistogramFitter::SetHistogram : TH1D not created.");
126 for (
int i = 0; i < nbins; ++i) {
137 double xmin = hist->GetBinLowEdge(1);
138 double xmax = hist->GetBinLowEdge(nbins + 1);
141 double histymin = hist->GetMinimum();
142 double histymax = hist->GetMaximum();
146 double ymin = TMath::Max(0., histymin - 5. * sqrt(histymin));
147 double ymax = histymax + 5. * sqrt(histymax);
184 for (
int ibin = 1; ibin <= nBins; ++ibin) {
199 yexp = fedgelow * dx + (fedgehi - fedgelow) * dx / 2.;
224 BCLog::OutError(
"BCHistogramFitter::SetFitFunction : TF1 not created.");
239 int n = func->GetNpar();
242 for (
int i = 0; i < n; ++i) {
246 func->GetParLimits(i, xmin, xmax);
270 double loglikelihood = 0;
285 for (
int ibin = 1; ibin <= nbins; ++ibin) {
287 double xedgehi =
fHistogram->GetBinLowEdge(ibin) + dx;
303 yexp = fedgelow * dx + (fedgehi - fedgelow) * dx / 2.;
313 return loglikelihood;
378 "BCHistogramFitter::Fit : Could not use the fast p-value evaluation.");
392 BCLog::OutError(
"BCHistogramFitter::DrawFit : Histogram not defined.");
397 BCLog::OutError(
"BCHistogramFitter::DrawFit : Fit function not defined.");
402 BCLog::OutError(
"BCHistogramFitter::DrawFit : Fit not performed yet.");
407 TString opt = options;
411 if (!opt.Contains(
"same"))
419 fHistogram->Draw(TString::Format(
"%ssame", opt.Data()));
429 TLegend * legend =
new TLegend(0.25, 0.75, 0.55, 0.95);
430 legend->SetBorderSize(0);
431 legend->SetFillColor(kWhite);
434 legend->AddEntry(
fErrorBand,
"Error band",
"F");
447 "BCHistogramFitter::CalculatePValueFast : Number of parameters is inconsistent.");
454 "BCHistogramFitter::CalculatePValueFast : Histogram not defined.");
462 std::vector<unsigned> observed(
fHistogram->GetNbinsX());
465 for (
int ibin = 0 ; ibin <
fHistogram->GetNbinsX(); ++ibin){
466 observed[ibin] = (
unsigned int)
fHistogram->GetBinContent(ibin + 1);
484 double logLambda = 0.0;
489 for (
int ibin = 1; ibin <=
fHistogram->GetNbinsX(); ++ibin) {
501 logLambda += yexp - y + y * log(y / yexp);
525 for (
int ibin = 1; ibin <=
fHistogram->GetNbinsX(); ++ibin) {
536 weight = (yexp > 0) ? yexp : 1.0;
538 weight = (y > 0) ? y : 1.0;
541 chi2 += (y - yexp) * (y - yexp) / weight;
558 "Please define the reference distribution by calling \n"
559 "BCHistogramFitter::SetHistogramExpected() first!");
579 if (parameters.empty())
585 double yObs =
fHistogram->GetBinContent(index);
588 double edgeLow =
fHistogram->GetBinLowEdge(index);
589 double edgeHigh = edgeLow +
fHistogram->GetBinWidth(index);
596 yExp =
fFitFunction->Integral(edgeLow, edgeHigh, ¶meters[0]);
603 yExp = fEdgeLow * dx + (fEdgeHigh - fEdgeLow) * dx / 2.;
611 return ROOT::Math::poisson_cdf((
unsigned int) (yObs - 1), yExp);
616 if ((
double) (
unsigned int) yObs != yObs) {
618 "BCHistogramFitter::CDF: Histogram values should be integer!\n"
619 " Bin %d = %f", index, yObs));
626 double yObsLower = (
unsigned int) yObs;
627 if (U > (yObs - yObsLower))
630 yObs = yObsLower + 1;
633 return ROOT::Math::poisson_cdf((
unsigned int) yObs, yExp);