diff --git a/hist/hist/inc/HFitInterface.h b/hist/hist/inc/HFitInterface.h index 5fa54075239ee..e92d50881570d 100644 --- a/hist/hist/inc/HFitInterface.h +++ b/hist/hist/inc/HFitInterface.h @@ -169,7 +169,7 @@ namespace ROOT { /** compute the chi2 value for an histogram given a function (see TH1::Chisquare for the documentation) */ - double Chisquare(const TH1 & h1, TF1 & f1, bool useRange, EChisquareType type); + double Chisquare(const TH1 & h1, TF1 & f1, bool useRange, EChisquareType type, bool useIntegral = false); /** compute the chi2 value for a graph given a function (see TGraph::Chisquare) diff --git a/hist/hist/src/HFitImpl.cxx b/hist/hist/src/HFitImpl.cxx index 69fb666595418..a92d958de985d 100644 --- a/hist/hist/src/HFitImpl.cxx +++ b/hist/hist/src/HFitImpl.cxx @@ -77,7 +77,7 @@ namespace HFit { void StoreAndDrawFitFunction(FitObject * h1, TF1 * f1, const ROOT::Fit::DataRange & range, bool, bool, const char *goption); template - double ComputeChi2(const FitObject & h1, TF1 &f1, bool useRange, ROOT::Fit::EChisquareType type ); + double ComputeChi2(const FitObject & h1, TF1 &f1, bool useRange, ROOT::Fit::EChisquareType type, bool useIntegral = false); @@ -1029,8 +1029,8 @@ TFitResultPtr ROOT::Fit::FitObject(THnBase * s1, TF1 *f1 , Foption_t & foption , // function to compute the simple chi2 for graphs and histograms -double ROOT::Fit::Chisquare(const TH1 & h1, TF1 & f1, bool useRange, ROOT::Fit::EChisquareType type) { - return HFit::ComputeChi2(h1,f1,useRange, type); +double ROOT::Fit::Chisquare(const TH1 & h1, TF1 & f1, bool useRange, ROOT::Fit::EChisquareType type, bool useIntegral) { + return HFit::ComputeChi2(h1,f1,useRange, type, useIntegral); } double ROOT::Fit::Chisquare(const TGraph & g, TF1 & f1, bool useRange) { @@ -1038,13 +1038,14 @@ double ROOT::Fit::Chisquare(const TGraph & g, TF1 & f1, bool useRange) { } template -double HFit::ComputeChi2(const FitObject & obj, TF1 & f1, bool useRange, ROOT::Fit::EChisquareType type ) { +double HFit::ComputeChi2(const FitObject & obj, TF1 & f1, bool useRange, ROOT::Fit::EChisquareType type, bool useIntegral ) { // implement using the fitting classes ROOT::Fit::DataOptions opt; opt.fUseEmpty = (type != ROOT::Fit::EChisquareType::kNeyman); // use empty bin when not using Neyman chisquare (observed error) opt.fExpErrors = (type == ROOT::Fit::EChisquareType::kPearson); opt.fErrors1 = (type == ROOT::Fit::EChisquareType::kPearson); // not using observed errors in Pearson chi2 + opt.fIntegral = useIntegral; // use bin integral instead of value at bin center ROOT::Fit::DataRange range; // get range of function diff --git a/hist/hist/src/TH1.cxx b/hist/hist/src/TH1.cxx index 83720aeffe471..8b0101ed182a4 100644 --- a/hist/hist/src/TH1.cxx +++ b/hist/hist/src/TH1.cxx @@ -2495,6 +2495,7 @@ Double_t TH1::Chi2TestX(const TH1* h2, Double_t &chi2, Int_t &ndf, Int_t &igood /// Use option "R" for restricting the chisquare calculation to the given range of the function /// Use option "L" for using the chisquare based on the poisson likelihood (Baker-Cousins Chisquare) /// Use option "P" for using the Pearson chisquare based on the expected bin errors +/// Use option "I" for using the integral of the function in each bin instead of the value at the bin center Double_t TH1::Chisquare(TF1 * func, Option_t *option) const { @@ -2505,11 +2506,12 @@ Double_t TH1::Chisquare(TF1 * func, Option_t *option) const TString opt(option); opt.ToUpper(); bool useRange = opt.Contains("R"); + bool useIntegral = opt.Contains("I"); ROOT::Fit::EChisquareType type = ROOT::Fit::EChisquareType::kNeyman; // default chi2 with observed error if (opt.Contains("L")) type = ROOT::Fit::EChisquareType::kPLikeRatio; else if (opt.Contains("P")) type = ROOT::Fit::EChisquareType::kPearson; - return ROOT::Fit::Chisquare(*this, *func, useRange, type); + return ROOT::Fit::Chisquare(*this, *func, useRange, type, useIntegral); } ////////////////////////////////////////////////////////////////////////////////