Skip to content

Commit 7c7ad25

Browse files
hageboeckferdymercuryguitargeek
committed
Add two tests for auto-binning of TH1 and in TTree::Draw.
THLimitFinder tries to trim empty bins close to the end of an axis range, but sometimes, the min/max was trimmed as well, so not all data would be visible in the histogram. Here, the case from the following post is tested: https://root-forum.cern.ch/t/bug-or-feature-in-ttree-draw/ Co-authored-by: ferdymercury <[email protected]> Co-authored-by: Jonas Rembser <[email protected]>
1 parent 439bc5b commit 7c7ad25

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

hist/hist/test/test_TH1.cxx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ TEST(THLimitsFinder, Degenerate)
5454
EXPECT_GE(xmax, centralValue + 5.);
5555
}
5656

57+
// see https://root-forum.cern.ch/t/bug-or-feature-in-ttree-draw/62862
58+
// Due to a poor binning choice in THLimitsFinder, the histograms in
59+
// TTree::Draw might not contain all values.
60+
TEST(THLimitsFinder, TTreeDraw_AutoBinning)
61+
{
62+
TH1F histo("limitsFinder", "", 100, 0, 0);
63+
histo.Fill(-999);
64+
histo.Fill(0);
65+
histo.BufferEmpty(1);
66+
67+
EXPECT_EQ(histo.GetEntries(), histo.GetEffectiveEntries());
68+
}
69+
5770
// Simple cross-check that TH1::SmoothArray() is not doing anything if input
5871
// array is already smooth.
5972
TEST(TH1, SmoothArrayCrossCheck)

tree/tree/test/TTreeRegressions.cxx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,23 @@ TEST(TTreeRegressions, FindBranchBrackets)
289289
EXPECT_NE(t.FindBranch("branch[3]"), nullptr);
290290
EXPECT_EQ(t.FindBranch("branch[3]"), t.GetBranch("branch[3]"));
291291
}
292+
293+
// see https://root-forum.cern.ch/t/bug-or-feature-in-ttree-draw/62862
294+
// Due to a poor binning choice in THLimitsFinder, the histogram didn't contain
295+
// all values.
296+
TEST(TTreeRegressions, DrawAutoBinning)
297+
{
298+
TTree t;
299+
Float_t x;
300+
t.Branch("x", &x);
301+
x = -999;
302+
t.Fill();
303+
x = 0;
304+
t.Fill();
305+
t.Draw("x");
306+
auto h = (TH1 *)gROOT->FindObject("htemp");
307+
ASSERT_NE(h, nullptr);
308+
EXPECT_EQ(h->GetEntries(), h->GetEffectiveEntries());
309+
delete h;
310+
delete gROOT->FindObject("c1");
311+
}

0 commit comments

Comments
 (0)