[hist] Fix computation of number of entries in ResetStats#21254
[hist] Fix computation of number of entries in ResetStats#21254lmoneta wants to merge 1 commit intoroot-project:masterfrom
Conversation
Test Results 20 files 20 suites 3d 3h 52m 54s ⏱️ For more details on these failures, see this check. Results for commit 34b8c9a. ♻️ This comment has been updated with latest results. |
|
Thanks @lmoneta, could tests be added for the two issues fixed? |
a862423 to
08e000f
Compare
When computing the number of entries in TH1::ResetStats always include underflow/overflow. Also in number of FetEffectiveEntries() Fix a bug in the computation of GetAllSumOfWeights() and improve the function to return (as an optional parameter) the total sum of weight square (including underflow/overflows). The bug was happening for dimensions < 2. (see ROOT-21253) Remove in UHI indexing test the check that number of effective entries is equal to number of entries. With the current changes the number of entries will contain underflows/overflows while number of effective entries not, because it follows the convention used for the statistics (mean,std, etc..) including what is in the current histogram range
08e000f to
34b8c9a
Compare
ferdymercury
left a comment
There was a problem hiding this comment.
@lmoneta thanks for the fix! For the test, could you go to
https://github.com/lmoneta/root/blob/hist_fix_entries_after_reset/hist/hist/test/test_TH1.cxx#L115
and below all lines starting with
EXPECT_FLOAT_EQ(h*.GetSumOfWeights(), *);
add two additional lines:
EXPECT_FLOAT_EQ(h*.GetSumOfAllWeights(true), *);
EXPECT_FLOAT_EQ(h*.GetSumOfAllWeights(false), *);
ferdymercury
left a comment
There was a problem hiding this comment.
You can also copy-paste a similar example into https://github.com/lmoneta/root/blob/hist_fix_entries_after_reset/hist/hist/test/test_TH2.cxx and https://github.com/lmoneta/root/blob/hist_fix_entries_after_reset/hist/hist/test/test_TH3.cxx
TEST(TH2, GetSumOfAllWeights)
{
TH2F h2("h2", "h2", 10, 0, 1, 10, 0, 1);
h2.SetBinContent(1, 2, 1.);
h2.SetBinContent(3, 4, 5.);
h2.SetBinContent(5, 1, 10.);
h2.SetBinContent(7, 5, -1.);
h2.SetBinContent(10, 2, 3.);
h2.SetBinContent(150, 2, 3.);
EXPECT_FLOAT_EQ(h2.GetEntries(), 6.);
EXPECT_FLOAT_EQ(h2.GetSumOfWeights(), 18.);
EXPECT_FLOAT_EQ(h2.GetSumOfAllWeights(true), 21.);
EXPECT_FLOAT_EQ(h2.GetSumOfAllWeights(false), 18.);
double sumsq;
EXPECT_FLOAT_EQ(h2.GetSumOfAllWeights(true,&sumsq), 21.);
EXPECT_FLOAT_EQ(sumsq, 145);
}
TEST(TH3, GetSumOfAllWeights)
{
TH3F h3("h3", "h3", 10, 0, 1, 10, 0, 1, 3, 0, 1);
h3.SetBinContent(1, 2, 1, 1.);
h3.SetBinContent(3, 4, 2, 5.);
h3.SetBinContent(5, 1, 3, 10.);
h3.SetBinContent(7, 5, 1, -1.);
h3.SetBinContent(10, 2, 2, 3.);
h3.SetBinContent(150, 2, 3, 3.);
EXPECT_FLOAT_EQ(h3.GetEntries(), 6.);
EXPECT_FLOAT_EQ(h3.GetSumOfWeights(), 18.);
EXPECT_FLOAT_EQ(h3.GetSumOfAllWeights(true), 21.);
EXPECT_FLOAT_EQ(h3.GetSumOfAllWeights(false), 18.);
double sumsq;
EXPECT_FLOAT_EQ(h3.GetSumOfAllWeights(true,&sumsq), 21.);
EXPECT_FLOAT_EQ(sumsq, 145);
}
For the JIRA issue, sth like this:
TEST(TH1, Add)
{
TH1F h1("h1", "h1", 10, 0, 1);
h1.SetBinContent(1, 1.);
h1.SetBinContent(3, 5.);
h1.SetBinContent(5, 10.);
h1.SetBinContent(7, -1.);
h1.SetBinContent(10, 3.);
TH1F h2("h2", "h2", 10, 0, 1);
h2.SetBinContent(1, 2.);
h2.SetBinContent(3, 10.);
h2.SetBinContent(5, 20.);
h2.SetBinContent(7, -2.);
h2.SetBinContent(10, 6.);
h2.Add(&h1, 1.);
EXPECT_FLOAT_EQ(h2.GetEntries(), 10.);
EXPECT_FLOAT_EQ(h2.GetSumOfWeights(), ...);
}
|
|
||
| // Create Sumw2 if h1 has Sumw2 set | ||
| if (fSumw2.fN == 0 && h1->GetSumw2N() != 0) Sumw2(); | ||
| // Also Create Sumw2 if is not a simple addition , otherwise errors will not be correctly computed |
There was a problem hiding this comment.
| // Also Create Sumw2 if is not a simple addition , otherwise errors will not be correctly computed | |
| // Also Create Sumw2 if is not a simple addition, otherwise errors will not be correctly computed |
When computing the number of entries in TH1::ResetStats always include underflow/overflow. Also in number of FetEffectiveEntries()
Fix a bug in the computation of GetAllSumOfWeights() and improve the function to return (as an optional parameter) the total sum of weight square (including underflow/overflows).
Improve the handling of statistics in TH1::Add methods.
When performing additions of histograms with coefficient > 0 but not equal to 1 automatically compute the sum of weight squares, otherwise the bin errors computations (and the error on the statistics, mean, std) will not be correct.
The bug was happening for dimensions < 2. (see ROOT-21253)
This PR fixes #21253 and the old JIRA item https://its.cern.ch/jira/browse/ROOT-10567?filter=-1
For the JIRA item, in case of Addition/Subtraction of histogram, the nuber of entries is now computed using underflow/overflows. But in case of Additions/Subtraciton with coefficient not equal to 1, the histogram will be weighted and the number of effective entries will be used.