Skip to content

[hist] Honour a Z axis range in TProfile3D::GetStats - #23829

Draft
Elvand-Lie wants to merge 2 commits into
root-project:masterfrom
Elvand-Lie:fix/tprofile3d-getstats-zrange
Draft

Elvand-Lie wants to merge 2 commits into
root-project:masterfrom
Elvand-Lie:fix/tprofile3d-getstats-zrange

Conversation

@Elvand-Lie

@Elvand-Lie Elvand-Lie commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

This Pull request:

Changes or fixes:

A range set only on the Z axis of a TProfile3D is ignored by GetMean and GetStdDev:

TProfile3D p("p", "", 4, 0, 4, 5, 0, 10, 3, 0, 30);
p.Fill(0.5, 1., 5., 1.);
p.Fill(3.5, 9., 25., 1.);
p.GetZaxis()->SetRange(1, 1);
// master: GetMean(1) == 2, GetMean(3) == 15 (both points still counted)
// TH3D with the same fills and range: GetMean(1) == 0.5, GetMean(3) == 5

TProfile3D::GetStats recomputes the statistics from the bins in range only when the X or Y axis has a range:

if ((fTsumw == 0) || fXaxis.TestBit(TAxis::kAxisRange) || fYaxis.TestBit(TAxis::kAxisRange)) {

TH3::GetStats also checks the Z axis, so this change adds fZaxis.TestBit(TAxis::kAxisRange) to the condition.

Taking that path for a Z range exposed a second problem. The recomputation loop never includes underflow and overflow bins, even when overflow statistics are enabled (SetStatOverflows(TH1::kConsider) or TH1::StatOverflows(true)). With a Z range, an entry in the X underflow was then dropped. The loop now uses the per-axis bounds of TProfile2D::GetStats: on an axis without a range, the underflow and overflow bins are included when overflow statistics are enabled.

Two tests in hist/hist/test/test_TProfile.cxx:

  • TProfile3D.GetStatsHonoursZRange: the example above; the means are the centers of the one bin in range.

  • TProfile3D.GetStatsHonoursStatOverflowsWithZRange: with SetStatOverflows(TH1::kConsider) and a Z range, an entry in the X underflow is still counted (sum of weights 2, X mean 0, as with TH3D).

  • Both tests fail without the corresponding change and pass with it.

  • ctest -R '^gtest-hist-hist-' passes: 33 tests, 0 failures, on Linux with a minimal build.

  • Also checked against TH3D: every combination of X, Y and Z ranges with each overflow-statistics setting, all means and standard deviations.

  • Not run: the full ROOT test suite, roottest, and platforms other than Linux.

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

Antigravity (Claude Opus 5.5) and Codex (gpt-6.1-sol) implemented the fix and the tests; Claude Code (Claude Opus 5.5) found the bug and validated it.

GetStats recomputed statistics for an X or Y range but ignored a range
set only on the Z axis; TH3::GetStats checks all three axes.
Include the Z axis in the condition and test the selected bin's means.

Assisted-by: antigravity:claude-opus-5-5
Assisted-by: codex:gpt-6.1-sol
Assisted-by: claude-code:claude-opus-5-5
Include enabled overflow statistics on axes without an explicit range.
Use TProfile2D's per-axis bounds so selecting Z keeps X flow entries.
Test the selected sum of weights and X mean with per-histogram stat
overflows.

Assisted-by: codex:gpt-6.1-sol
Assisted-by: claude-code:claude-opus-5-5

This branch has not been deployed

No deployments
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.

1 participant