Skip to content

Commit 18f560e

Browse files
committed
Add two tests for auto-binning of TH1 and in TTree::Draw.
Due to an feature to remove bins at the ends of a range, TTree::Draw() could create histograms that didn't show the full data. See e.g.: https://root-forum.cern.ch/t/bug-or-feature-in-ttree-draw/
1 parent d807f6c commit 18f560e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-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 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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,20 @@ TEST(TTreeRegressions, TTreeFormulaMemberIndex)
279279
ASSERT_FLOAT_EQ(mc.Get(-2)->x, h3->GetMean());
280280
delete h3;
281281
}
282+
283+
// see https://root-forum.cern.ch/t/bug-or-feature-in-ttree-draw/62862
284+
// Due to a poor binning choice in THLimitsFinder, the histogram didn't contain
285+
// all values.
286+
TEST(TTreeRegressions, DrawAutoBinning)
287+
{
288+
TTree t;
289+
Float_t x;
290+
t.Branch("x", &x);
291+
x = -999;
292+
t.Fill();
293+
x = 0;
294+
t.Fill();
295+
t.Draw("x");
296+
auto h = (TH1 *)gROOT->FindObject("htemp");
297+
ASSERT_EQ(h->GetEntries(), h->GetEffectiveEntries());
298+
}

0 commit comments

Comments
 (0)