It could be true from a statistics stand point that you don't really need the integral because the fitted function value is suppose to reflect the correct count in that bin? But it would nevertheless be good to have that option available in both ways.
from array import array
import ROOT
bin_edge = [
0., 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5,
0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.,
]
bin_content = [
0, 0, 0, 0, 0, 1, 3, 16, 17, 14, 18, 18, 7, 5, 1, 0, 0, 0, 0, 0
]
h = ROOT.TH1D(
"h_gauss", "",
len(bin_edge) - 1,
array("d", bin_edge),
)
for i, val in enumerate(bin_content):
h.SetBinContent(i + 1, val)
h.Sumw2(ROOT.kFALSE)
f = ROOT.TF1("f_gauss", "gaus", 0.0, 1.0)
h.Fit(f, f"Q")
print(f"Neyman chi2 (useIntegral = False) from TF1::GetChisquare = {f.GetChisquare()}")
print(f"Neyman chi2 (useIntegral = False) from TH1::Chisquare = {h.Chisquare(f, '')}")
# option I for integral over bins instead of bin center
h.Fit(f, f"QI")
print(f"Neyman chi2 (useIntegral = True) from TF1::GetChisquare = {f.GetChisquare()}")
# not supported
print(f"Neyman chi2 (useIntegral = True) from TH1::Chisquare = {h.Chisquare(f, 'I')}")
Explain what you would like to see improved and how.
It is possible to compute the chi2 between a fitted function
TF1and a histogramTH1using two different methods:You usually perform a fit with
TH1::Fitfirst, which automatically computes the chi2 in TF1. You can then get the chi2 with eitherTF1::GetChisquare, orTH1.Chisquare(which triggers a manual computation). The behavior of the two approaches are basically the same except that the chi2 computed fromTH1::Fitalso accepts the optionIwhich uses the integral of function in the bin instead of the default bin center value. This option is not available inTH1.Chisquare.It could be true from a statistics stand point that you don't really need the integral because the fitted function value is suppose to reflect the correct count in that bin? But it would nevertheless be good to have that option available in both ways.
For the fix we probably just need some way to propagate the "I" option in
ROOT::Fit::Chisquareto set the proper value ofROOT::Fit::DataOptions.fIntegralReproducer:
ROOT version
6.38.00
Installation method
conda
Operating system
Linux
Additional context
No response