From 05f4881a5ce400b0070fa073803ff373f316955e Mon Sep 17 00:00:00 2001 From: Elvand Lie Nababan Date: Sun, 25 Oct 2026 02:04:18 +0700 Subject: [PATCH 1/2] [hist] Honour a Z axis range in TProfile3D::GetStats 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 --- hist/hist/src/TProfile3D.cxx | 3 ++- hist/hist/test/test_TProfile.cxx | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/hist/hist/src/TProfile3D.cxx b/hist/hist/src/TProfile3D.cxx index 4756da07a4778..15e99613bd490 100644 --- a/hist/hist/src/TProfile3D.cxx +++ b/hist/hist/src/TProfile3D.cxx @@ -814,7 +814,8 @@ void TProfile3D::GetStats(Double_t *stats) const if (fBuffer) ((TProfile3D*)this)->BufferEmpty(); // Loop on bins - if ( (fTsumw == 0 /* && fEntries > 0 */) || fXaxis.TestBit(TAxis::kAxisRange) || fYaxis.TestBit(TAxis::kAxisRange)) { + if ((fTsumw == 0 /* && fEntries > 0 */) || fXaxis.TestBit(TAxis::kAxisRange) || fYaxis.TestBit(TAxis::kAxisRange) || + fZaxis.TestBit(TAxis::kAxisRange)) { // check for labels axis . In that case corresponding statistics do not make sense and it is set to zero Bool_t labelXaxis = ((const_cast(fXaxis)).GetLabels() && fXaxis.CanExtend()); diff --git a/hist/hist/test/test_TProfile.cxx b/hist/hist/test/test_TProfile.cxx index c08d0d2563608..a3e20ad69976d 100644 --- a/hist/hist/test/test_TProfile.cxx +++ b/hist/hist/test/test_TProfile.cxx @@ -75,6 +75,18 @@ TEST(TProfile2D, Chi2Test) runTest(reference, sameDistr, differentDistr); } +TEST(TProfile3D, GetStatsHonoursZRange) +{ + TProfile3D profile("profile", "", 4, 0, 4, 5, 0, 10, 3, 0, 30); + profile.Fill(0.5, 1., 5., 1.); + profile.Fill(3.5, 9., 25., 1.); + profile.GetZaxis()->SetRange(1, 1); + + EXPECT_DOUBLE_EQ(0.5, profile.GetMean(1)); + EXPECT_DOUBLE_EQ(1., profile.GetMean(2)); + EXPECT_DOUBLE_EQ(5., profile.GetMean(3)); +} + TEST(TProfile3D, Chi2Test) { TProfile3D reference("reference", "reference", 10, 0, 10, 11, 0, 11, 12, 0, 12); From cc5240b7d511b9d3db25dd2d42219f8f1f7834ee Mon Sep 17 00:00:00 2001 From: Elvand Lie Nababan Date: Sun, 25 Oct 2026 02:32:07 +0700 Subject: [PATCH 2/2] [hist] Count stat overflows in TProfile3D::GetStats 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 --- hist/hist/src/TProfile3D.cxx | 33 +++++++++++++++++++++++++++++--- hist/hist/test/test_TProfile.cxx | 14 ++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/hist/hist/src/TProfile3D.cxx b/hist/hist/src/TProfile3D.cxx index 15e99613bd490..261d2f96a9b30 100644 --- a/hist/hist/src/TProfile3D.cxx +++ b/hist/hist/src/TProfile3D.cxx @@ -827,11 +827,38 @@ void TProfile3D::GetStats(Double_t *stats) const Double_t x,y,z; for (bin=0;binSetRange(1, 1); + + double stats[13] = {}; + profile.GetStats(stats); + EXPECT_DOUBLE_EQ(2., stats[0]); + EXPECT_DOUBLE_EQ(0., profile.GetMean(1)); +} + TEST(TProfile3D, Chi2Test) { TProfile3D reference("reference", "reference", 10, 0, 10, 11, 0, 11, 12, 0, 12);