Skip to content

[hist] Fix GetRandom with negative bins - #22980

Open
shuv-amp wants to merge 1 commit into
root-project:masterfrom
shuv-amp:fix-getrandom-negative-bins
Open

[hist] Fix GetRandom with negative bins#22980
shuv-amp wants to merge 1 commit into
root-project:masterfrom
shuv-amp:fix-getrandom-negative-bins

Conversation

@shuv-amp

@shuv-amp shuv-amp commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

ComputeIntegral(true) used break after finding a negative bin, which only exited the innermost loop. In two and three dimensions, later rows or planes could overwrite the NaN marker. GetRandom, GetRandom2, and GetRandom3 also compared the result directly to NaN, so they did not detect the failure.

Return immediately without caching the partial integral, check the result with std::isnan, and make the TH2 and TH3 FillRandom overloads validate the source before caching its integral. This also prevents TH2Poly::GetRandom2 from calling BinarySearch with a null integral.

The regression tests cover one-, two-, and three-dimensional histograms, the TH2 and TH3 FillRandom paths, and TH2Poly. Tested locally with testTH1 and the Hist GoogleTest suite.

AI disclosure: I used AI while implementing this fix. I reviewed and tested the changes and take responsibility for them.

The negative-bin check in ComputeIntegral(true) used break, which only
left the inner loop. In 2D and 3D, later rows could overwrite the NaN
marker. GetRandom, GetRandom2 and GetRandom3 also compared the result
directly to NaN, so their error paths were never taken.

Return immediately without caching a partial integral, use std::isnan
in the GetRandom methods, and make the TH2 and TH3 FillRandom overloads
validate the source before its integral is cached. This also keeps
TH2Poly::GetRandom2 from calling BinarySearch with a null integral.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants