`RooPlot::chiSquare` returns `NaN` with `Expected` data errors due to division by zero
I maintainer di solito rispondono entro 1 giorno
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Check duplicate issues.
- Checked for duplicates
Description
Description
Calculating the chi2 via RooPlot::chiSquare on data plotted with RooFit::DataError(RooAbsData::Expected) returns NaN. Because RooPlot::chiSquare only supports Neyman-style chi2, the behavior for Expected errors is undefined and causes a silent division by zero.
Reproducer
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", "h", len(bin_edge) - 1, array("d", bin_edge))
for i, val in enumerate(bin_content):
h.SetBinContent(i + 1, val)
h.Sumw2(ROOT.kFALSE)
x = ROOT.RooRealVar("X", "x", 0.0, 1.0)
x.setBins(len(bin_edge) - 1)
data = ROOT.RooDataHist("dh", "dh", ROOT.RooArgList(x), h)
mu = ROOT.RooRealVar("mu", "mu", 0.5, 0.0, 1.0)
sig = ROOT.RooRealVar("sigma", "sigma", 0.1, 0.01, 0.5)
pdf = ROOT.RooGaussian("gauss", "gauss", x, mu, sig)
pdf.fitTo(data)
# Test both error types
for err_type, err_name in [(ROOT.RooAbsData.Poisson, "Poisson"), (ROOT.RooAbsData.Expected, "Expected")]:
frame = x.frame()
data.plotOn(frame, ROOT.RooFit.DataError(err_type), ROOT.RooFit.Name("h_data"))
pdf.plotOn(frame, ROOT.RooFit.Name("p_curve"))
chi2 = frame.chiSquare("p_curve", "h_data", 0)
print(f"chi2 with {err_name} data error = {chi2}")
Output:
chi2 with Poisson data error = 0.590340854118924
chi2 with Expected data error = nan
Root Cause
- Zero Bin Errors:
RooPlotdefaults toSumW2forRooHistiferror_type != Poisson(RooHist.cxx#L236), yielding zero errors for unweighted data. - Missing Safety Check:
RooCurve::chiSquaredivides by these errors without checking for zeros (RooCurve.cxx#L563), causing theNaN.
Proposed Solutions
- Option 1: Raise an error if
error_type = Expectedis used duringRooAbsData::plotOn. - Option 2: Fall back to
Poissonerrors and emit aRooFit::Warning.
Reproducer
See above
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 17h
- PR unite (30g)
- 188
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 4 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 13 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
-
[RDataFrame] Code that transforms `#var` alias to `R_rdf_sizeof_var` does not respect string literalsForse già presa @vepadulano l’ha presa 1 giorno fa. Apertabug in:RDataFrame
Difficoltà 3/5 1-2 giorni Idoneità per principianti 71/100
root-project/root#23790 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
TDataMember::GetOffset interfers to TDataMember::GetOffsetCintForse già presa @pcanal l’ha presa 1 giorno fa. Apertabug in:Core Libraries
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
root-project/root#23777 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
`TChain::GetEntries` internal caching ineffective?Forse già presa @pcanal l’ha presa 6 giorni fa. Apertaimprovement in:TTree
root-project/root#23738 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di root-project/root
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
telegramdesktop/tdesktop#31505 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
ll-builder shell completions omit existing lockfile commands and --lockedForse già presa @project-nju-learner l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
OpenAtom-Linyaps/linyaps#2291 ·
I maintainer di solito rispondono entro 1 giorno
-
area: ui bug P3: low value: low
Difficoltà 1/5 1-3 ore Idoneità per principianti 85/100
patrick-hudson/put.gd-desktop#494 ·
I maintainer di solito rispondono entro 1 giorno