Project
Loading...
Searching...
No Matches
test_HistogramRegistry.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13#include <catch_amalgamated.hpp>
14
15using namespace o2;
16using namespace o2::framework;
17
18namespace test
19{
20DECLARE_SOA_COLUMN_FULL(X, x, float, "x");
21DECLARE_SOA_COLUMN_FULL(Y, y, float, "y");
22} // namespace test
23
25{
26 return {"r", {{"histo", "histo", {HistType::kTH1F, {{100, 0, 1}}}}}};
27}
28
29TEST_CASE("HistogramRegistryLookup")
30{
32 HistogramRegistry registry{
33 "registry", {
34 {"eta", "#Eta", {HistType::kTH1F, {{100, -2.0, 2.0}}}}, //
35 {"phi", "#Phi", {HistType::kTH1D, {{102, 0, 2 * M_PI}}}}, //
36 {"pt", "p_{T}", {HistType::kTH1D, {{1002, -0.01, 50.1}}}}, //
37 {"ptToPt", "#ptToPt", {HistType::kTH2F, {{100, -0.01, 10.01}, {100, -0.01, 10.01}}}} //
38 } //
39 };
40
42 REQUIRE(registry.get<TH1>(HIST("eta"))->GetNbinsX() == 100);
43 REQUIRE(registry.get<TH1>(HIST("phi"))->GetNbinsX() == 102);
44 REQUIRE(registry.get<TH1>(HIST("pt"))->GetNbinsX() == 1002);
45 REQUIRE(registry.get<TH2>(HIST("ptToPt"))->GetNbinsX() == 100);
46 REQUIRE(registry.get<TH2>(HIST("ptToPt"))->GetNbinsY() == 100);
47
49 auto histo = registry.get<TH1>(HIST("pt")).get();
50 REQUIRE(histo->GetNbinsX() == 1002);
51
53 auto r = foo();
54 auto histo2 = r.get<TH1>(HIST("histo")).get();
55 REQUIRE(histo2->GetNbinsX() == 100);
56
57 registry.print();
58
59 // check that registry behaves correctly when two different names have equal hash:
60 /*
61 auto str1 = "Maria has nine red beds.";
62 auto str2 = "Steven has fifteen white tables.";
63 REQUIRE(compile_time_hash(str1) == compile_time_hash(str2));;
64 try {
65 registry.add(str1, "", kTH1F, {{20, 0.0f, 10.01f}});
66 registry.add(str2, "", kTH1F, {{20, 0.0f, 10.01f}});
67 } catch (...) {
68 INFO("Hash collision was detected correctly!");
69 }
70 */
71}
72
73TEST_CASE("HistogramRegistryExpressionFill")
74{
75 TableBuilder builderA;
76 auto rowWriterA = builderA.persist<float, float>({"x", "y"});
77 rowWriterA(0, 0.0f, -2.0f);
78 rowWriterA(0, 1.0f, -4.0f);
79 rowWriterA(0, 2.0f, -1.0f);
80 rowWriterA(0, 3.0f, -5.0f);
81 rowWriterA(0, 4.0f, 0.0f);
82 rowWriterA(0, 5.0f, -9.0f);
83 rowWriterA(0, 6.0f, -7.0f);
84 rowWriterA(0, 7.0f, -4.0f);
85 auto tableA = builderA.finalize();
86 REQUIRE(tableA->num_rows() == 8);
87 using TestA = o2::soa::InPlaceTable<"A/1"_h, o2::soa::Index<>, test::X, test::Y>;
88 TestA tests{tableA};
89 REQUIRE(8 == tests.size());
90
92 HistogramRegistry registry{
93 "registry", {
94 {"x", "test x", {HistType::kTH1F, {{100, 0.0f, 10.0f}}}}, //
95 {"xy", "test xy", {HistType::kTH2F, {{100, -10.0f, 10.01f}, {100, -10.0f, 10.01f}}}} //
96 } //
97 };
98
100 registry.fill<test::X>(HIST("x"), tests, test::x > 3.0f);
101 REQUIRE(registry.get<TH1>(HIST("x"))->GetEntries() == 4);
102
104 registry.fill<test::X, test::Y>(HIST("xy"), tests, test::x > 3.0f && test::y > -5.0f);
105 REQUIRE(registry.get<TH2>(HIST("xy"))->GetEntries() == 2);
106}
107
108TEST_CASE("HistogramRegistryStepTHn")
109{
110 HistogramRegistry registry{"registry"};
111
112 registry.add("stepTHnF", "a", {kStepTHnF, {{100, -10.0f, 10.01f}, {100, -10.0f, 10.01f}}, 2});
113 registry.add("stepTHnD", "b", {kStepTHnD, {{100, -10.0f, 10.01f}, {100, -10.0f, 10.01f}}, 3});
114 registry.addClone("stepTHnD", "stepTHnD2");
115
116 auto histo = registry.get<StepTHn>(HIST("stepTHnD"));
117 REQUIRE(histo->getNSteps() == 3);
118
119 // fill first step at position (0,3)
120 registry.fill(HIST("stepTHnF"), 0, 0., 3.);
121 // fill second step (0,4)
122 registry.fill(HIST("stepTHnF"), 1, 0., 4.);
123
124 registry.fill(HIST("stepTHnD2"), 1, 0., 4.);
125
126 registry.print();
127}
#define DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_)
Definition ASoA.h:2285
#define HIST(name)
void fill(const HistName &histName, Ts... positionAndWeight)
HistPtr add(const HistogramSpec &histSpec)
auto persist(std::array< char const *, sizeof...(ARGS)+1 > const &columnNames)
std::shared_ptr< arrow::Table > finalize()
GLint GLenum GLint x
Definition glcorearb.h:403
GLboolean r
Definition glcorearb.h:1233
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("test_prepareArguments")
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
FIXME: do not use data model tables.
HistogramRegistry foo()