33TEST_CASE(
"HistogramPool Functions",
"[Framework][functionality]") {
34 const char* test_file =
"/tmp/test_histogram_pool.root";
36 SECTION(
"exception on request") {
39 REQUIRE_THROWS_WITH(test_pool.create(
"dne",
"foo", 10, 0.0, 1.0),
43 SECTION(
"creation on request") {
44 TFile* histogram_file{
nullptr};
45 auto open_on_request = [&histogram_file, &test_file]() -> TDirectory* {
46 if (histogram_file ==
nullptr) {
47 histogram_file = TFile::Open(test_file,
"recreate");
49 return histogram_file->mkdir(
"histo_directory");
53 REQUIRE(histogram_file ==
nullptr);
54 test_pool.create(
"h",
"bla", 10, 0, 1);
56 REQUIRE(histogram_file !=
nullptr);
57 CHECK(histogram_file->Get(
"histo_directory") !=
nullptr);
58 histogram_file->Write();
60 CHECK(histogram_file->Get(
"histo_directory/h") !=
nullptr);
63 SECTION(
"separate pools") {
64 TFile histogram_file{test_file,
"recreate"};
66 static TDirectory* d{histogram_file.mkdir(
"p1")};
70 static TDirectory* d{histogram_file.mkdir(
"p2")};
73 CHECK(histogram_file.Get(
"p1") ==
nullptr);
74 CHECK(histogram_file.Get(
"p2") ==
nullptr);
75 test_pool_1.create(
"h",
"bar", 10, 0, 1);
76 CHECK(histogram_file.Get(
"p1") !=
nullptr);
77 CHECK(histogram_file.Get(
"p2") ==
nullptr);
78 test_pool_2.create(
"h",
"buz", 10, 0, 10);
79 CHECK(histogram_file.Get(
"p1") !=
nullptr);
80 CHECK(histogram_file.Get(
"p2") !=
nullptr);
81 histogram_file.Write();
85 auto h1 =
dynamic_cast<TH1F*
>(histogram_file.Get(
"p1/h"));
86 auto h2 =
dynamic_cast<TH1F*
>(histogram_file.Get(
"p2/h"));
87 REQUIRE(h1 !=
nullptr);
88 REQUIRE(h2 !=
nullptr);
89 CHECK(h1->GetNbinsX() == 10);
90 CHECK(h2->GetNbinsX() == 10);
91 CHECK(h1->GetBinLowEdge(10) == 0.9);
92 CHECK(h2->GetBinLowEdge(10) == 9);
96 SECTION(
"different types of histograms") {
97 TFile histogram_file{test_file,
"recreate"};
99 static TDirectory* d{histogram_file.mkdir(
"p")};
102 std::vector<std::string> cats{
"one",
"two",
"three"};
104 test_pool.
create(
"h1_1",
"foo", 10, 0, 1);
105 test_pool.create(
"h1_2",
"bar", {0.0, 0.5, 0.8, 1.0},
true);
106 test_pool.create(
"h1_3",
"", cats);
108 test_pool.create(
"h2_1",
"baz", 5, -5, 5,
"foo", 10, -5, 5);
109 test_pool.create(
"h2_2",
"baz", {-5.0, -1.0, 0.0, 1.0, 5.0},
"foo",
111 test_pool.create(
"h2_3",
"", cats,
"", cats);
113 test_pool.setWeight(0.75);
114 test_pool.fill(
"h1_2", 0.75);
115 test_pool.fillw(
"h1_2", 0.1, 0.5);
116 test_pool.fill(
"h1_2", 0.75);
117 test_pool.setWeight(1);
119 test_pool.fill(
"h1_3",
"one");
121 test_pool.fill(
"h1_3", 0);
123 test_pool.fill(
"h1_3", 1);
125 test_pool.fill(
"h1_3",
"three");
130 test_pool.fill(
"h2_3",
"one",
"two");
132 histogram_file.Write();
134 auto h1_1 =
dynamic_cast<TH1F*
>(histogram_file.Get(
"p/h1_1"));
135 REQUIRE(h1_1 !=
nullptr);
136 CHECK(h1_1->GetNbinsX() == 10);
137 CHECK(h1_1->GetBinLowEdge(1) == 0.0);
138 CHECK(h1_1->GetBinLowEdge(11) == 1.0);
139 REQUIRE(h1_1->GetSumw2() !=
nullptr);
140 CHECK(h1_1->GetSumw2()->fN == 0);
142 auto h1_2 =
dynamic_cast<TH1F*
>(histogram_file.Get(
"p/h1_2"));
143 REQUIRE(h1_2 !=
nullptr);
144 CHECK(h1_2->GetNbinsX() == 3);
145 CHECK(h1_2->GetBinLowEdge(1) == 0.0);
146 CHECK(h1_2->GetBinLowEdge(2) == 0.5);
147 CHECK(h1_2->GetBinLowEdge(3) == 0.8);
148 CHECK(h1_2->GetBinLowEdge(4) == 1.0);
149 CHECK(h1_2->GetBinContent(1) == 0.5);
150 CHECK(h1_2->GetBinContent(2) == 2 * 0.75);
151 REQUIRE(h1_2->GetSumw2() !=
nullptr);
152 CHECK(h1_2->GetSumw2()->fN == 5);
153 CHECK(h1_2->GetSumw2()->At(1) == 0.25);
154 CHECK(h1_2->GetSumw2()->At(2) == 0.75 * 0.75 * 2);
156 auto h1_3 =
dynamic_cast<TH1F*
>(histogram_file.Get(
"p/h1_3"));
157 REQUIRE(h1_3 !=
nullptr);
158 CHECK(h1_3->GetNbinsX() == 3);
160 CHECK(h1_3->GetBinContent(0) == 0);
161 CHECK(h1_3->GetBinContent(1) == 2);
162 CHECK(h1_3->GetBinContent(2) == 1);
163 CHECK(h1_3->GetBinContent(3) == 1);
164 CHECK(h1_3->GetBinContent(4) == 0);
166 auto h2_1 =
dynamic_cast<TH2F*
>(histogram_file.Get(
"p/h2_1"));
167 REQUIRE(h2_1 !=
nullptr);
168 CHECK(h2_1->GetNbinsX() == 5);
169 CHECK(h2_1->GetNbinsY() == 10);
171 auto h2_2 =
dynamic_cast<TH2F*
>(histogram_file.Get(
"p/h2_2"));
172 REQUIRE(h2_2 !=
nullptr);
173 CHECK(h2_2->GetNbinsX() == 4);
174 CHECK(h2_2->GetNbinsY() == 2);
176 auto h2_3 =
dynamic_cast<TH2F*
>(histogram_file.Get(
"p/h2_3"));
177 REQUIRE(h2_3 !=
nullptr);
178 CHECK(h2_3->GetBinContent(1, 2) == 1);