Skip to content

Commit 66c0acc

Browse files
JasMehta08guitargeek
authored andcommitted
[hist] Add option I to TH1::Chisquare for bin integral chi2
1 parent 8c396b1 commit 66c0acc

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

hist/hist/inc/HFitInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ namespace ROOT {
169169
/**
170170
compute the chi2 value for an histogram given a function (see TH1::Chisquare for the documentation)
171171
*/
172-
double Chisquare(const TH1 & h1, TF1 & f1, bool useRange, EChisquareType type);
172+
double Chisquare(const TH1 & h1, TF1 & f1, bool useRange, EChisquareType type, bool useIntegral = false);
173173

174174
/**
175175
compute the chi2 value for a graph given a function (see TGraph::Chisquare)

hist/hist/src/HFitImpl.cxx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace HFit {
7777
void StoreAndDrawFitFunction(FitObject * h1, TF1 * f1, const ROOT::Fit::DataRange & range, bool, bool, const char *goption);
7878

7979
template <class FitObject>
80-
double ComputeChi2(const FitObject & h1, TF1 &f1, bool useRange, ROOT::Fit::EChisquareType type );
80+
double ComputeChi2(const FitObject & h1, TF1 &f1, bool useRange, ROOT::Fit::EChisquareType type, bool useIntegral = false);
8181

8282

8383

@@ -1029,22 +1029,23 @@ TFitResultPtr ROOT::Fit::FitObject(THnBase * s1, TF1 *f1 , Foption_t & foption ,
10291029
// function to compute the simple chi2 for graphs and histograms
10301030

10311031

1032-
double ROOT::Fit::Chisquare(const TH1 & h1, TF1 & f1, bool useRange, ROOT::Fit::EChisquareType type) {
1033-
return HFit::ComputeChi2(h1,f1,useRange, type);
1032+
double ROOT::Fit::Chisquare(const TH1 & h1, TF1 & f1, bool useRange, ROOT::Fit::EChisquareType type, bool useIntegral) {
1033+
return HFit::ComputeChi2(h1,f1,useRange, type, useIntegral);
10341034
}
10351035

10361036
double ROOT::Fit::Chisquare(const TGraph & g, TF1 & f1, bool useRange) {
10371037
return HFit::ComputeChi2(g,f1, useRange, ROOT::Fit::EChisquareType::kNeyman);
10381038
}
10391039

10401040
template<class FitObject>
1041-
double HFit::ComputeChi2(const FitObject & obj, TF1 & f1, bool useRange, ROOT::Fit::EChisquareType type ) {
1041+
double HFit::ComputeChi2(const FitObject & obj, TF1 & f1, bool useRange, ROOT::Fit::EChisquareType type, bool useIntegral ) {
10421042

10431043
// implement using the fitting classes
10441044
ROOT::Fit::DataOptions opt;
10451045
opt.fUseEmpty = (type != ROOT::Fit::EChisquareType::kNeyman); // use empty bin when not using Neyman chisquare (observed error)
10461046
opt.fExpErrors = (type == ROOT::Fit::EChisquareType::kPearson);
10471047
opt.fErrors1 = (type == ROOT::Fit::EChisquareType::kPearson); // not using observed errors in Pearson chi2
1048+
opt.fIntegral = useIntegral; // use bin integral instead of value at bin center
10481049

10491050
ROOT::Fit::DataRange range;
10501051
// get range of function

hist/hist/src/TH1.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2515,6 +2515,7 @@ Double_t TH1::Chi2TestX(const TH1* h2, Double_t &chi2, Int_t &ndf, Int_t &igood
25152515
/// Use option "R" for restricting the chisquare calculation to the given range of the function
25162516
/// Use option "L" for using the chisquare based on the poisson likelihood (Baker-Cousins Chisquare)
25172517
/// Use option "P" for using the Pearson chisquare based on the expected bin errors
2518+
/// Use option "I" for using the integral of the function in each bin instead of the value at the bin center
25182519

25192520
Double_t TH1::Chisquare(TF1 * func, Option_t *option) const
25202521
{
@@ -2525,11 +2526,12 @@ Double_t TH1::Chisquare(TF1 * func, Option_t *option) const
25252526

25262527
TString opt(option); opt.ToUpper();
25272528
bool useRange = opt.Contains("R");
2529+
bool useIntegral = opt.Contains("I");
25282530
ROOT::Fit::EChisquareType type = ROOT::Fit::EChisquareType::kNeyman; // default chi2 with observed error
25292531
if (opt.Contains("L")) type = ROOT::Fit::EChisquareType::kPLikeRatio;
25302532
else if (opt.Contains("P")) type = ROOT::Fit::EChisquareType::kPearson;
25312533

2532-
return ROOT::Fit::Chisquare(*this, *func, useRange, type);
2534+
return ROOT::Fit::Chisquare(*this, *func, useRange, type, useIntegral);
25332535
}
25342536

25352537
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)