Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hist/hist/src/TProfile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions hist/hist/src/TProfile2D.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions hist/hist/src/TProfile3D.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 4 additions & 0 deletions hist/hist/src/TProfileHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ T* TProfileHelper::ExtendAxis(T* p, Double_t x, TAxis *axis)
template <typename T>
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
Expand Down
45 changes: 45 additions & 0 deletions hist/hist/test/test_TProfile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down