Chi2 between pdf and RooDataHist with empty bins
I maintainer di solito rispondono entro 1 giorno
@guitargeek ci sta già lavorando.
Dal 26/3/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Explain what you would like to see improved and how.
To calculate chi2 between a pdf and a RooDataHist, we can use RooAbsReal::createChi2(). However, it fails if the RooDataHist has bins with zero error (i.e. empty bins). The expected behavior should be that empty bins are skipped, just like when computing the chi2 between a TF1 and a TH1.
Reproducer:
from array import array
import numpy as np
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_w", "h_gauss_w",
len(bin_edge) - 1,
array("d", bin_edge),
)
h.Sumw2()
rng = np.random.default_rng(1)
for i, count in enumerate(bin_content):
center = 0.5 * (bin_edge[i] + bin_edge[i + 1])
for _ in range(int(count)):
wt = float(rng.uniform(0.5, 2.0))
h.Fill(center, wt)
f = ROOT.TF1("f_gauss", "gaus", 0.0, 1.0)
h.Fit(f, 'QS')
# prints 6.73
print(f"Chi2 from TH1::Chisquare = {h.Chisquare(f)}")
data = ROOT.RooDataHist("dh", "dh", ROOT.RooArgList(x), h)
params = f.GetParameters()
fitted_mu, fitted_sigma = params[1], params[2]
x = ROOT.RooRealVar("X", "x", 0.0, 1.0)
x.setBins(len(bin_edge) - 1)
mu = ROOT.RooRealVar("mu", "mu", fitted_mu, 0.0, 1.0)
sig = ROOT.RooRealVar("sigma", "sigma", fitted_sigma, 0.01, 0.5)
pdf = ROOT.RooGaussian("gauss", "gauss", x, mu, sig)
bin_width = 0.05
# make sure the normalization matches between the function and the pdf
norm_val = f.Integral(bin_edge[0], bin_edge[-1]) / bin_width
norm_var = ROOT.RooRealVar('norm', 'norm', norm_val)
extended_pdf = ROOT.RooAddPdf('pdf_ext', 'pdf_ext', ROOT.RooArgList(pdf), ROOT.RooArgList(norm_var))
chi2_obj = extended_pdf.createChi2(
data,
ROOT.RooFit.DataError(ROOT.RooAbsData.SumW2),
ROOT.RooFit.Extended(True)
)
chi2_obj.getVal()
# prints 0
# and [#0] ERROR:Eval -- RooChi2Var::RooChi2Var(pdf_ext) INFINITY ERROR: bin 0 has zero error
print(f"Chi2 from RooAbsReal::createChi2 = {chi2_obj.getVal()}")
ROOT version
6.38.00
Installation method
conda
Operating system
Linux
Additional context
No response
- Lingua principale
- C++
- Stelle
- 3.3k
- Fork
- 1.6k
- Merge medio
- 2g 16h
- PR unite (30g)
- 194
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di root-project/root
-
thisroot.sh: wrong ROOTSYS in zsh when the shell's command line has a newlineForse già presa @dpiparo l’ha presa 3 giorni fa. Apertabug in:Build System
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
root-project/root#23746 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[tmva][sofie] Inputs of unsupported type (e.g. float16) give code that does not compile instead of an errorForse già presa @lmoneta l’ha presa 12 giorni fa. ApertaAI-Assisted bug in:SOFIE
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
root-project/root#23655 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 71/100
root-project/root#23790 ·
I maintainer di solito rispondono entro 1 giorno
-
bug in:Core Libraries
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
root-project/root#23777 ·
I maintainer di solito rispondono entro 1 giorno
-
`TChain::GetEntries` internal caching ineffective?Forse già presa @pcanal l’ha presa 5 giorni fa. Apertaimprovement in:TTree
root-project/root#23738 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di root-project/root
Issue simili
-
Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Niko1221/Strata#3673 · 2 commenti ·
I maintainer di solito rispondono entro 3 giorni
-
bug P4
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
open-astro/AlpacaBridge#1520 ·
I maintainer di solito rispondono entro 1 giorno
-
[Docs] CONTRIBUTING still says FreeType 2.14.3 and TabLabel.h says ImGui 1.92.9b after the bumpsForse già presa @mgradwohl l’ha presa oggi. Apertaagent:WSL documentation LOW
Difficoltà 1/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 1 giorno