Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

`RooPlot::chiSquare` returns `NaN` with `Expected` data errors due to division by zero

オープン
#21,697 コメント 9 件 リアクション 1 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@guitargeek がすでに取り組んでいます。

2026年3月26日 から。

  • #21710 @AyachiMishra による — マージされずにクローズ

評価

この issue はまだ評価されていません。

説明

bug in:RooFit
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
  1. Zero Bin Errors: RooPlot defaults to SumW2 for RooHist if error_type != Poisson (RooHist.cxx#L236), yielding zero errors for unweighted data.
  2. Missing Safety Check: RooCurve::chiSquare divides by these errors without checking for zeros (RooCurve.cxx#L563), causing the NaN.
Proposed Solutions
  • Option 1: Raise an error if error_type = Expected is used during RooAbsData::plotOn.
  • Option 2: Fall back to Poisson errors and emit a RooFit::Warning.
Reproducer

See above

ROOT version

6.38.00

Installation method

conda

Operating system

Linux

Additional context

No response

主要言語
C++
スター
3.3k
フォーク
1.6k
平均マージ
2日 16時間
マージ済み PR(30日)
194

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

root-project/root のほかの issue

root-project/root の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。