Skip to content

[RooFit] Guard against zero bin errors in RooPlot::chiSquareHandle zero bin error in chiSquare calculation (in: Roofit)#21710

Closed
AyachiMishra wants to merge 1 commit intoroot-project:masterfrom
AyachiMishra:patch-1
Closed

[RooFit] Guard against zero bin errors in RooPlot::chiSquareHandle zero bin error in chiSquare calculation (in: Roofit)#21710
AyachiMishra wants to merge 1 commit intoroot-project:masterfrom
AyachiMishra:patch-1

Conversation

@AyachiMishra
Copy link
Copy Markdown

@AyachiMishra AyachiMishra commented Mar 26, 2026

(closes #21697 )

RooPlot::chiSquare can have zero bin errors (e.g. when using Expected data errors), leading to division by zero in the pull calculation and resulting in NaN values.

I Added a warning for zero bin error and deprecated method usage as discussed in the issue: #21697 .

Until RooPlot::chiSquare gets deprecated in favor of RooAbsReal::createChi2 (as mentioned by @guitargeek ), this guard will be helpful for users who come across this error..

Added warning for zero bin error and deprecated method usage.
@AyachiMishra AyachiMishra changed the title [RooFit] Guard against zero bin errors in RooPlot::chiSquareHandle zero bin error in chiSquare calculation [RooFit] Guard against zero bin errors in RooPlot::chiSquareHandle zero bin error in chiSquare calculation (in: Roofit) Mar 27, 2026
@guitargeek
Copy link
Copy Markdown
Contributor

Thanks! However, as we discussed in the issue, a warning is not appropriate. Skipping empty bins in a chi-square test is statistically wrong: the chi-square is not defined in that case. So erroring hard by returning NaN is fine.

The better solution would be to provide an alternative goodness-of-fit tests that is also defined when bins are empty, based on the Poisson likelihood. Not sure why you opened this PR even when this was already discussed in the issue, maybe you used GitHub copilot 🙂

@guitargeek guitargeek closed this Mar 30, 2026
@AyachiMishra
Copy link
Copy Markdown
Author

I appreciate the reality check! I got too eager to patch it up instead of weighing the statistical implications and meaning that was discussed later in that issue.

I will keep an eye on the developments in this regard though. Thanks for the guidance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants