Skip to content

Conversation

@ahmedbilal9
Copy link
Contributor

Description

Fixes #20761

This PR fixes a bug in TH1::Chi2TestX where residuals were only correctly stored for 1D histograms. For 2D and 3D histograms, the residual array indexing only used the i loop index and ignored j and k, causing incorrect storage.

Changes

  • Added resIndex counter for each of the three comparison modes (UU, UW, WW)
  • Replaced res[i - i_start] with res[resIndex] in all three sections
  • Added resIndex++ increment after each residual is stored
  • Each comparison mode now properly handles multi-dimensional histogram bins

Testing

The fix ensures that residuals are stored sequentially for all bins in 2D/3D histograms, matching the order returned by GetBin(i, j, k).

Impact

Users can now retrieve residuals from Chi2Test for 2D and 3D histograms as originally intended by passing a residuals array.

Fixed bug where Chi2Test only stored residuals for 1D histograms.
For 2D/3D histograms, the residual array indexing ignored j and k
loop indices, causing incorrect storage.

Added resIndex counter for each comparison mode (UU, UW, WW) to
properly index the residuals array for multi-dimensional histograms.

Fixes root-project#20761
Copy link
Member

@hageboeck hageboeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, thanks for the contribution!

I think we could remove two unnecessary if (res). Please have a look if you agree.

ahmedbilal9 and others added 2 commits January 7, 2026 15:21
Co-authored-by: Stephan Hageboeck <stephan.hageboeck@cern.ch>
Removed redundant if(res) checks

Co-authored-by: Stephan Hageboeck <stephan.hageboeck@cern.ch>
@github-actions
Copy link

github-actions bot commented Jan 7, 2026

Test Results

    21 files      21 suites   3d 14h 17m 32s ⏱️
 3 792 tests  3 792 ✅ 0 💤 0 ❌
76 582 runs  76 582 ✅ 0 💤 0 ❌

Results for commit f6053e7.

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.

Chi2Test: Report residuals also for higher dimensions

2 participants