Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Inconsistent Neyman chi2 definition for Poisson data between TH1::Chisquare and RooAbsReal::createChi2

Abierto
#21,726 3 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@guitargeek ya está trabajando en esto.

Desde el 28/3/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

improvement in:Math Libraries in:RooFit
Explain what you would like to see improved and how.

To evaluate the goodness of fit between a model and binned data, we can either use TH1::Chisquare with a TH1 histogram and a TF1 function, or use RooAbsReal::createChi2 with a RooAbsPdf pdf and a RooDataHist dataset. However, in the case of Neyman chi2 with Poisson data, the two uses different strategies when computing the variance of the data, TH1::Chisquare uses Wald approximation $\sqrt{n_{obs}}$ (FitUtil.cxx#352) whereas RooAbsReal::createChi2 uses the exact Poisson (Garwood) interval at 68.3% (RooChi2Var.cxx#157 and RooDataHist.cxx#1589).

Reproducer

import ROOT
import numpy as np

MU = 0.5
SIGMA = 0.1
SIZE = 100

ROOT.RooRandom.randomGenerator().SetSeed(2026)

x = ROOT.RooRealVar("x", "x", 0, 1)
x.setBins(20)
mu = ROOT.RooRealVar("mu", "mean", MU)
sigma = ROOT.RooRealVar("sigma", "width", SIGMA)
gauss = ROOT.RooGaussian("gauss", "gaussian PDF", x, mu, sigma)

data = gauss.generate(ROOT.RooArgSet(x), SIZE)

data_hist = data.binnedClone()

th1 = data_hist.createHistogram("h1", x)

f1 = ROOT.TF1("f1", "gaus", 0, 1)
f1.SetParameters(1, MU, SIGMA)
integral = f1.Integral(x.getMin(), x.getMax()) / th1.GetBinWidth(1)
f1.SetParameters(SIZE / integral, MU, SIGMA)

# Pearson chi2
pearson_chi2 = gauss.createChi2(
    data_hist, 
    ROOT.RooFit.DataError(ROOT.RooAbsData.Expected),
    ROOT.RooFit.Extended(False)
)

print(f"Pearson chi2 with RooAbsReal::createChi2 = {pearson_chi2.getVal()}")
print(f"Pearson chi2 with TH1::Chisquare = {th1.Chisquare(f1, 'p')}")

# Neyman chi2
neyman_chi2 = gauss.createChi2(
    data_hist, 
    ROOT.RooFit.DataError(ROOT.RooAbsData.Poisson),
    ROOT.RooFit.Extended(False)
)

print(f"Neyman chi2 with RooAbsReal::createChi2 = {neyman_chi2.getVal()}")
print(f"Neyman chi2 with TH1::Chisquare = {th1.Chisquare(f1, '')}")

Output

Pearson chi2 with RooAbsReal::createChi2 = 7.391492169139706
Pearson chi2 with TH1::Chisquare = 7.391492169139708
Neyman chi2 with RooAbsReal::createChi2 = 5.055198120851967
Neyman chi2 with TH1::Chisquare = 6.590759652852072
ROOT version

6.38.00

Installation method

conda

Operating system

Linux

Additional context

No response

Lenguaje dominante
C++
Estrellas
3.3k
Forks
1.6k
Merge medio
2 d 17 h
PR fusionados (30 d)
188

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de root-project/root

Todos los issues de root-project/root

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.