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 "Framework/ASoA.h"
15#include <catch_amalgamated.hpp>
16
17using namespace o2;
18using namespace o2::framework;
19
20namespace test
21{
22DECLARE_SOA_COLUMN_FULL(X, x, float, "x");
23DECLARE_SOA_COLUMN_FULL(Y, y, float, "y");
24} // namespace test
25
27{
28 return {"r", {{"histo", "histo", {HistType::kTH1F, {{100, 0, 1}}}}}};
29}
30
31TEST_CASE("HistogramRegistryLookup")
32{
34 HistogramRegistry registry{
35 "registry", {
36 {"eta", "#Eta", {HistType::kTH1F, {{100, -2.0, 2.0}}}}, //
37 {"phi", "#Phi", {HistType::kTH1D, {{102, 0, 2 * M_PI}}}}, //
38 {"pt", "p_{T}", {HistType::kTH1D, {{1002, -0.01, 50.1}}}}, //
39 {"ptToPt", "#ptToPt", {HistType::kTH2F, {{100, -0.01, 10.01}, {100, -0.01, 10.01}}}} //
40 } //
41 };
42
44 REQUIRE(registry.get<TH1>(HIST("eta"))->GetNbinsX() == 100);
45 REQUIRE(registry.get<TH1>(HIST("phi"))->GetNbinsX() == 102);
46 REQUIRE(registry.get<TH1>(HIST("pt"))->GetNbinsX() == 1002);
47 REQUIRE(registry.get<TH2>(HIST("ptToPt"))->GetNbinsX() == 100);
48 REQUIRE(registry.get<TH2>(HIST("ptToPt"))->GetNbinsY() == 100);
49
51 auto histo = registry.get<TH1>(HIST("pt")).get();
52 REQUIRE(histo->GetNbinsX() == 1002);
53
55 auto r = foo();
56 auto histo2 = r.get<TH1>(HIST("histo")).get();
57 REQUIRE(histo2->GetNbinsX() == 100);
58
59 registry.print();
60
61 // check that registry behaves correctly when two different names have equal hash:
62 /*
63 auto str1 = "Maria has nine red beds.";
64 auto str2 = "Steven has fifteen white tables.";
65 REQUIRE(compile_time_hash(str1) == compile_time_hash(str2));;
66 try {
67 registry.add(str1, "", kTH1F, {{20, 0.0f, 10.01f}});
68 registry.add(str2, "", kTH1F, {{20, 0.0f, 10.01f}});
69 } catch (...) {
70 INFO("Hash collision was detected correctly!");
71 }
72 */
73}
74
75// FIXME: feature not used in its current state, requires rework
76// TEST_CASE("HistogramRegistryExpressionFill")
77// {
78// TableBuilder builderA;
79// auto rowWriterA = builderA.persist<float, float>({"x", "y"});
80// rowWriterA(0, 0.0f, -2.0f);
81// rowWriterA(0, 1.0f, -4.0f);
82// rowWriterA(0, 2.0f, -1.0f);
83// rowWriterA(0, 3.0f, -5.0f);
84// rowWriterA(0, 4.0f, 0.0f);
85// rowWriterA(0, 5.0f, -9.0f);
86// rowWriterA(0, 6.0f, -7.0f);
87// rowWriterA(0, 7.0f, -4.0f);
88// auto tableA = builderA.finalize();
89// REQUIRE(tableA->num_rows() == 8);
90// using TestA = o2::soa::InPlaceTable<"A/1"_h, o2::soa::Index<>, test::X, test::Y>;
91// TestA tests{tableA};
92// REQUIRE(8 == tests.size());
93
94// /// Construct a registry object with direct declaration
95// HistogramRegistry registry{
96// "registry", {
97// {"x", "test x", {HistType::kTH1F, {{100, 0.0f, 10.0f}}}}, //
98// {"xy", "test xy", {HistType::kTH2F, {{100, -10.0f, 10.01f}, {100, -10.0f, 10.01f}}}} //
99// } //
100// };
101
102// /// Fill histogram with expression and table
103// registry.fill<test::X>(HIST("x"), tests, test::x > 3.0f);
104// REQUIRE(registry.get<TH1>(HIST("x"))->GetEntries() == 4);
105
106// /// Fill histogram with expression and table
107// registry.fill<test::X, test::Y>(HIST("xy"), tests, test::x > 3.0f && test::y > -5.0f);
108// REQUIRE(registry.get<TH2>(HIST("xy"))->GetEntries() == 2);
109// }
110
111TEST_CASE("HistogramRegistryStepTHn")
112{
113 HistogramRegistry registry{"registry"};
114
115 registry.add("stepTHnF", "a", {kStepTHnF, {{100, -10.0f, 10.01f}, {100, -10.0f, 10.01f}}, 2});
116 registry.add("stepTHnD", "b", {kStepTHnD, {{100, -10.0f, 10.01f}, {100, -10.0f, 10.01f}}, 3});
117 registry.addClone("stepTHnD", "stepTHnD2");
118
119 auto histo = registry.get<StepTHn>(HIST("stepTHnD"));
120 REQUIRE(histo->getNSteps() == 3);
121
122 // fill first step at position (0,3)
123 registry.fill(HIST("stepTHnF"), 0, 0., 3.);
124 // fill second step (0,4)
125 registry.fill(HIST("stepTHnF"), 1, 0., 4.);
126
127 registry.fill(HIST("stepTHnD2"), 1, 0., 4.);
128
129 registry.print();
130}
#define DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_)
Definition ASoA.h:2442
#define HIST(name)
HistPtr add(const HistogramSpec &histSpec)
GLint GLenum GLint x
Definition glcorearb.h:403
GLboolean r
Definition glcorearb.h:1233
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
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()