diff --git a/hist/hist/src/TProfile.cxx b/hist/hist/src/TProfile.cxx index 4885ed630f111..dc1c39b64fc51 100644 --- a/hist/hist/src/TProfile.cxx +++ b/hist/hist/src/TProfile.cxx @@ -1727,6 +1727,9 @@ void TProfile::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/) void TProfile::Scale(Double_t c1, Option_t * option) { TProfileHelper::Scale(this, c1, option); + // the y values are scaled, so are their sums used for the mean and standard deviation of y + fTsumwy *= c1; + fTsumwy2 *= c1 * c1; } //////////////////////////////////////////////////////////////////////////////// diff --git a/hist/hist/src/TProfile2D.cxx b/hist/hist/src/TProfile2D.cxx index fa2e5ef736c6d..0f22cfdd59335 100644 --- a/hist/hist/src/TProfile2D.cxx +++ b/hist/hist/src/TProfile2D.cxx @@ -1809,6 +1809,9 @@ void TProfile2D::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/) void TProfile2D::Scale(Double_t c1, Option_t * option) { TProfileHelper::Scale(this, c1, option); + // the z values are scaled, so are their sums used for the mean and standard deviation of z + fTsumwz *= c1; + fTsumwz2 *= c1 * c1; } //////////////////////////////////////////////////////////////////////////////// diff --git a/hist/hist/src/TProfile3D.cxx b/hist/hist/src/TProfile3D.cxx index 4756da07a4778..5e8bbca22251d 100644 --- a/hist/hist/src/TProfile3D.cxx +++ b/hist/hist/src/TProfile3D.cxx @@ -1347,6 +1347,9 @@ void TProfile3D::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/) void TProfile3D::Scale(Double_t c1, Option_t *option) { TProfileHelper::Scale(this, c1, option); + // the t values are scaled, so are their sums used for the mean and standard deviation of t + fTsumwt *= c1; + fTsumwt2 *= c1 * c1; } //////////////////////////////////////////////////////////////////////////////// diff --git a/hist/hist/src/TProfileHelper.h b/hist/hist/src/TProfileHelper.h index e2996b96f65a9..0efc9124182d1 100644 --- a/hist/hist/src/TProfileHelper.h +++ b/hist/hist/src/TProfileHelper.h @@ -513,6 +513,10 @@ T* TProfileHelper::ExtendAxis(T* p, Double_t x, TAxis *axis) template void TProfileHelper::Scale(T* p, Double_t c1, Option_t *) { + // fill the bins from the buffer and delete it, otherwise the buffered entries are not scaled + if (p->fBuffer) + p->BufferEmpty(1); + Double_t ac1 = TMath::Abs(c1); // Make the loop over the bins to calculate the Addition diff --git a/hist/hist/test/test_TProfile.cxx b/hist/hist/test/test_TProfile.cxx index c08d0d2563608..3a8266f6b275e 100644 --- a/hist/hist/test/test_TProfile.cxx +++ b/hist/hist/test/test_TProfile.cxx @@ -58,6 +58,51 @@ TEST(TProfile, Chi2TestWithWrongErrors) } } +TEST(TProfile, ScaleScalesMeanAndStdDevOfY) +{ + TProfile p("p", "p", 10, 0, 10); + p.Fill(1, 2); + p.Fill(2, 4); + p.Scale(3); + EXPECT_DOUBLE_EQ(p.GetBinContent(3), 12); + EXPECT_DOUBLE_EQ(p.GetMean(2), 9); + EXPECT_DOUBLE_EQ(p.GetStdDev(2), 3); +} + +TEST(TProfile, ScaleScalesBufferedEntries) +{ + TProfile p("p", "p", 10, 0, 10); + p.SetBuffer(100); + p.Fill(1, 2); + p.Fill(2, 4); + p.Scale(3); + EXPECT_DOUBLE_EQ(p.GetBinContent(2), 6); + EXPECT_DOUBLE_EQ(p.GetBinContent(3), 12); + EXPECT_DOUBLE_EQ(p.GetMean(2), 9); +} + +TEST(TProfile2D, ScaleScalesMeanAndStdDevOfZ) +{ + TProfile2D p("p", "p", 10, 0, 10, 10, 0, 10); + p.Fill(1, 1, 2); + p.Fill(2, 2, 4); + p.Scale(3); + EXPECT_DOUBLE_EQ(p.GetMean(3), 9); + EXPECT_DOUBLE_EQ(p.GetStdDev(3), 3); +} + +TEST(TProfile3D, ScaleScalesSumsOfT) +{ + TProfile3D p("p", "p", 10, 0, 10, 10, 0, 10, 10, 0, 10); + p.Fill(1, 1, 1, 2); + p.Fill(2, 2, 2, 4); + p.Scale(3); + Double_t stats[TH1::kNstat]; + p.GetStats(stats); + EXPECT_DOUBLE_EQ(stats[11], 18); // 3 * (2 + 4) + EXPECT_DOUBLE_EQ(stats[12], 180); // 9 * (4 + 16) +} + TEST(TProfile2D, Chi2Test) { TProfile2D reference("reference", "reference", 10, 0, 10, 10, 0, 10);