Skip to content
Draft
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
4 changes: 2 additions & 2 deletions hist/hist/src/TProfile2D.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ Bool_t TProfile2D::Divide(const TH1 *h1)
}

// Reset statistics
fEntries = fTsumw = fTsumw2 = fTsumwx = fTsumwx2 = 0;
fEntries = fTsumw = fTsumw2 = fTsumwx = fTsumwx2 = fTsumwy = fTsumwy2 = fTsumwxy = fTsumwz = fTsumwz2 = 0;

// Loop on bins (including underflows/overflows)
Int_t bin,binx,biny;
Expand Down Expand Up @@ -580,7 +580,7 @@ Bool_t TProfile2D::Divide(const TH1 *h1, const TH1 *h2, Double_t c1, Double_t c2
}

// Reset statistics
fEntries = fTsumw = fTsumw2 = fTsumwx = fTsumwx2 = 0;
fEntries = fTsumw = fTsumw2 = fTsumwx = fTsumwx2 = fTsumwy = fTsumwy2 = fTsumwxy = fTsumwz = fTsumwz2 = 0;

// Loop on bins (including underflows/overflows)
Int_t bin,binx,biny;
Expand Down
16 changes: 9 additions & 7 deletions hist/hist/src/TProfile3D.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,10 @@ Bool_t TProfile3D::Divide(const TH1 *h1)
}

// Reset statistics
fEntries = fTsumw = fTsumw2 = fTsumwx = fTsumwx2 = 0;
fEntries = fTsumw = fTsumw2 = fTsumwx = fTsumwx2 = fTsumwy = fTsumwy2 = fTsumwxy = fTsumwz = fTsumwz2 = fTsumwxz =
fTsumwyz = fTsumwt = fTsumwt2 = 0;

// Loop on bins (including underflows/overflows)
// Loop on bins (including underflows/overflows)
Int_t bin,binx,biny,binz;
Double_t *cu1 = p1->GetW();
Double_t *er1 = p1->GetW2();
Expand All @@ -478,8 +479,8 @@ Bool_t TProfile3D::Divide(const TH1 *h1)
fTsumwy += u*y;
fTsumwy2 += u*y*y;
fTsumwxy += u*x*y;
fTsumwz += u;
fTsumwz2 += u*z;
fTsumwz += u * z;
fTsumwz2 += u * z * z;
fTsumwxz += u*x*z;
fTsumwyz += u*y*z;
fTsumwt += u;
Expand Down Expand Up @@ -553,9 +554,10 @@ Bool_t TProfile3D::Divide(const TH1 *h1, const TH1 *h2, Double_t c1, Double_t c2
}

// Reset statistics
fEntries = fTsumw = fTsumw2 = fTsumwx = fTsumwx2 = 0;
fEntries = fTsumw = fTsumw2 = fTsumwx = fTsumwx2 = fTsumwy = fTsumwy2 = fTsumwxy = fTsumwz = fTsumwz2 = fTsumwxz =
fTsumwyz = fTsumwt = fTsumwt2 = 0;

// Loop on bins (including underflows/overflows)
// Loop on bins (including underflows/overflows)
Int_t bin,binx,biny,binz;
Double_t *cu1 = p1->GetW();
Double_t *cu2 = p2->GetW();
Expand All @@ -578,7 +580,7 @@ Bool_t TProfile3D::Divide(const TH1 *h1, const TH1 *h2, Double_t c1, Double_t c2
u = TMath::Abs(w);
x = fXaxis.GetBinCenter(binx);
y = fYaxis.GetBinCenter(biny);
z = fZaxis.GetBinCenter(biny);
z = fZaxis.GetBinCenter(binz);
fEntries++;
fTsumw += u;
fTsumw2 += u*u;
Expand Down
65 changes: 64 additions & 1 deletion hist/hist/test/test_TProfile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,67 @@ TEST(TProfile3D, Chi2Test)
}

runTest(reference, sameDistr, differentDistr);
}
}

TEST(TProfile2D, DivideStatistics)
{
TProfile2D target("target", "", 4, 0, 4, 5, 0, 10);
TProfile2D denominator("denominator", "", 4, 0, 4, 5, 0, 10);
target.Fill(0.5, 1., 2.);
target.Fill(3.5, 9., 1.);
denominator.Fill(0.5, 1., 1.);

ASSERT_TRUE(target.Divide(&denominator));
EXPECT_DOUBLE_EQ(0.5, target.GetMean(1));
EXPECT_DOUBLE_EQ(1., target.GetMean(2));
}

TEST(TProfile2D, DivideTwoProfilesStatistics)
{
TProfile2D numerator("numerator", "", 4, 0, 4, 5, 0, 10);
TProfile2D denominator("denominator", "", 4, 0, 4, 5, 0, 10);
TProfile2D target("target", "", 4, 0, 4, 5, 0, 10);
numerator.Fill(0.5, 1., 2.);
denominator.Fill(0.5, 1., 1.);
target.Fill(3.5, 9., 1.);

ASSERT_TRUE(target.Divide(&numerator, &denominator));
EXPECT_DOUBLE_EQ(0.5, target.GetMean(1));
EXPECT_DOUBLE_EQ(1., target.GetMean(2));
}

TEST(TProfile3D, DivideStatistics)
{
TProfile3D target("target", "", 4, 0, 4, 5, 0, 10, 3, 0, 30);
TProfile3D denominator("denominator", "", 4, 0, 4, 5, 0, 10, 3, 0, 30);
target.Fill(0.5, 1., 25., 2.);
target.Fill(0.5, 1., 5., 2.);
target.Fill(3.5, 9., 5., 1.);
denominator.Fill(0.5, 1., 25., 1.);
denominator.Fill(0.5, 1., 5., 1.);

ASSERT_TRUE(target.Divide(&denominator));
EXPECT_DOUBLE_EQ(0.5, target.GetMean(1));
EXPECT_DOUBLE_EQ(1., target.GetMean(2));
EXPECT_DOUBLE_EQ(15., target.GetMean(3));
EXPECT_DOUBLE_EQ(10., target.GetStdDev(3));
}

TEST(TProfile3D, DivideTwoProfilesStatistics)
{
for (bool prefill : {false, true}) {
SCOPED_TRACE(prefill);
TProfile3D numerator("numerator", "", 4, 0, 4, 5, 0, 10, 3, 0, 30);
TProfile3D denominator("denominator", "", 4, 0, 4, 5, 0, 10, 3, 0, 30);
TProfile3D target("target", "", 4, 0, 4, 5, 0, 10, 3, 0, 30);
numerator.Fill(0.5, 1., 25., 2.);
denominator.Fill(0.5, 1., 25., 1.);
if (prefill)
target.Fill(3.5, 9., 5., 1.);

ASSERT_TRUE(target.Divide(&numerator, &denominator));
EXPECT_DOUBLE_EQ(0.5, target.GetMean(1));
EXPECT_DOUBLE_EQ(1., target.GetMean(2));
EXPECT_DOUBLE_EQ(25., target.GetMean(3));
}
}