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

Đang mở
#21,726 3 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@guitargeek đang làm issue này rồi.

Từ ngày 28/3/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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

Ngôn ngữ chính
C++
Star
3.3k
Fork
1.6k
Merge trung bình
2 ngày 14 giờ
Pull request đã merge (30 ngày)
222

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của root-project/root

Tất cả issue của root-project/root

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.