Skip to content

Commit 6babed6

Browse files
author
Petr Jacka
committed
[hist] Adding test of constructors for THn and THnSparse histograms
1 parent d8a9b0b commit 6babed6

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

hist/hist/test/THn.cxx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,48 @@
55
#include "TH1.h"
66
#include "TH2.h"
77

8+
// Constructors for THn and THnSparse
9+
TEST(THn, Constructors) {
10+
11+
std::vector<int> nbins = {4, 5, 6};
12+
std::vector<double> xmin = {0., 0., 0.};
13+
std::vector<double> xmax = {4., 5., 6.};
14+
15+
std::vector<std::vector<double>> edges = {
16+
{0, 1, 2, 3, 4},
17+
{0, 1, 2, 3, 4, 5},
18+
{0, 1, 2, 3, 4, 5, 6}
19+
};
20+
21+
std::vector<TAxis> axes = {
22+
TAxis(nbins[0], xmin[0], xmax[0]),
23+
TAxis(nbins[1], xmin[1], xmax[1]),
24+
TAxis(nbins[2], xmin[2], xmax[2])
25+
};
26+
27+
28+
THnD hn_v1("hn_v1", "hn_v1", 3, nbins.data(), xmin.data(), xmax.data());
29+
THnD hn_v2("hn_v2", "hn_v2", 3, nbins.data(), edges);
30+
THnD hn_v3("hn_v3", "hn_v3", axes);
31+
THnI hn_v4("hn_v4", "hn_v4", axes);
32+
33+
THnSparseD hs_v1("hs_v1", "hs_v1", 3, nbins.data(), xmin.data(), xmax.data());
34+
THnSparseD hs_v2("hs_v2", "hs_v2", 3, nbins.data(), edges);
35+
THnSparseD hs_v3("hs_v3", "hs_v3", axes);
36+
THnSparseI hs_v4("hs_v4", "hs_v4", axes);
37+
38+
std::vector<THnBase*> hns = {&hn_v1, &hn_v2, &hn_v3, &hn_v4, &hs_v1, &hs_v2, &hs_v3, &hs_v4};
39+
for (THnBase* hn : hns) {
40+
EXPECT_EQ(hn->GetNdimensions(), 3);
41+
for (int dim = 0; dim < 3; ++dim) {
42+
EXPECT_EQ(hn->GetAxis(dim)->GetNbins(), nbins[dim]);
43+
for (int bin = 1; bin <= (int)edges[dim].size(); ++bin) {
44+
EXPECT_DOUBLE_EQ(hn->GetAxis(dim)->GetBinLowEdge(bin), edges[dim][bin-1]);
45+
}
46+
}
47+
}
48+
}
49+
850
// Filling THn
951
TEST(THn, Fill) {
1052
Int_t bins[2] = {2, 3};

0 commit comments

Comments
 (0)