The Gaudi Framework
master (1a7a3838)
Toggle main menu visibility
Loading...
Searching...
No Matches
HistogramsTests.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 2021-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
#include <
Gaudi/Accumulators/StaticHistogram.h
>
12
#include <
Gaudi/Functional/Consumer.h
>
13
#include <
GaudiKernel/AlgTool.h
>
14
#include <type_traits>
15
16
namespace
Gaudi::Tests::Histograms::CustomAxis
{
17
enum class
Category
{
Simple
,
Complex
,
Bad
,
Wrong
};
18
std::ostream&
operator<<
( std::ostream& o,
Category
v ) {
19
switch
( v ) {
20
case
Category::Simple
:
21
o <<
"Simple"
;
22
break
;
23
case
Category::Complex
:
24
o <<
"Complex"
;
25
break
;
26
case
Category::Bad
:
27
o <<
"Bad"
;
28
break
;
29
case
Category::Wrong
:
30
o <<
"Wrong"
;
31
break
;
32
}
33
return
o;
34
}
35
}
// namespace Gaudi::Tests::Histograms::CustomAxis
36
37
namespace
Gaudi::Accumulators
{
38
struct
CustomAxis
{
39
using
Category
=
Gaudi::Tests::Histograms::CustomAxis::Category
;
40
using
ArithmeticType
=
Category
;
41
42
CustomAxis
() =
default
;
44
unsigned
int
numBins
()
const
{
return
4; }
46
std::underlying_type_t<Category>
minValue
= 0,
maxValue
= 4;
48
std::string
title
{
"Category"
};
50
std::vector<std::string>
labels
{
"Simple"
,
"Complex"
,
"Bad"
,
"Wrong"
};
51
52
unsigned
int
index
(
Category
value )
const
{
return
static_cast<
unsigned
int
>
( value ) + 1; }
53
friend
std::ostream&
operator<<
( std::ostream& o,
CustomAxis
const
& axis ) {
54
return
o << axis.
numBins
() <<
" "
<< axis.
minValue
<<
" "
<< axis.
maxValue
;
55
}
56
};
57
void
to_json
( nlohmann::json& j,
const
CustomAxis
& axis ) {
58
j = nlohmann::json{ {
"nBins"
, axis.
numBins
() },
59
{
"minValue"
, axis.
minValue
},
60
{
"maxValue"
, axis.
maxValue
},
61
{
"title"
, axis.
title
} };
62
j[
"labels"
] = axis.
labels
;
63
}
64
}
// namespace Gaudi::Accumulators
65
66
namespace
Gaudi::Tests::Histograms
{
67
namespace
Directories
{
68
using
MyHist_t
=
Gaudi::Accumulators::StaticHistogram<1>
;
69
70
struct
HistoGroupsTool
:
AlgTool
{
71
using
AlgTool::AlgTool
;
72
73
mutable
MyHist_t
m_hist0
{
this
,
"Top"
,
"Top title"
, { 1, 0, 1 } };
74
mutable
MyHist_t
m_hist1
{
this
,
"Group/First"
,
"First title"
, { 1, 0, 1 } };
75
mutable
MyHist_t
m_hist2
{
this
,
"Group/Second"
,
"Second title"
, { 1, 0, 1 } };
76
mutable
MyHist_t
m_hist3
{
this
,
"Group/SubGroup/Third"
,
"Third title"
, { 1, 0, 1 } };
77
78
void
fillHistos
()
const
{
79
++
m_hist0
[0.5];
80
++
m_hist1
[0.5];
81
++
m_hist2
[0.5];
82
++
m_hist3
[0.5];
83
}
84
};
85
DECLARE_COMPONENT
( HistoGroupsTool )
86
87
struct
HistoGroupsAlg
:
Gaudi
::
Functional
::Consumer<
void
()> {
88
using
Base
=
Gaudi::Functional::Consumer
<void()>;
89
using
Base::Base;
90
91
mutable
MyHist_t
m_hist0
{
this
,
"Top"
,
"Top title"
, { 1, 0, 1 } };
92
mutable
MyHist_t
m_hist1
{
this
,
"Group/First"
,
"First title"
, { 1, 0, 1 } };
93
mutable
MyHist_t
m_hist2
{
this
,
"Group/Second"
,
"Second title"
, { 1, 0, 1 } };
94
mutable
MyHist_t
m_hist3
{
this
,
"Group/SubGroup/Third"
,
"Third title"
, { 1, 0, 1 } };
95
96
ToolHandle<HistoGroupsTool>
m_tool
{
this
,
"Tool"
,
"Gaudi::Tests::Histograms::Directories::HistoGroupsTool/Tool"
};
97
98
void
operator()
()
const override
{
99
++
m_hist0
[0.5];
100
++
m_hist1
[0.5];
101
++
m_hist2
[0.5];
102
++
m_hist3
[0.5];
103
m_tool
->fillHistos();
104
}
105
};
106
DECLARE_COMPONENT
( HistoGroupsAlg )
107
}
// namespace Directories
108
namespace
AxesLabels
{
109
struct
HistWithLabelsAlg
:
Gaudi::Functional::Consumer
<void()> {
110
using
Base
=
Gaudi::Functional::Consumer
<void()>;
111
using
MyHist_t
=
Gaudi::Accumulators::StaticHistogram<1, Gaudi::Accumulators::atomicity::full, int>
;
112
113
using
Base::Base;
114
115
mutable
MyHist_t
m_hist
{
116
this
,
"hist"
,
"Histogram title"
, { 5, 0, 5,
"axis title"
, {
"a"
,
"b"
,
"c"
,
"d"
,
"e"
} } };
117
118
void
operator()
()
const override
{
119
for
(
int
i : { 1, 2, 3, 4, 5 } )
m_hist
[i - 1] += i;
120
}
121
};
122
DECLARE_COMPONENT
( HistWithLabelsAlg )
123
}
// namespace AxesLabels
124
namespace
CustomAxis {
125
struct
EnumAxisAlg
:
Gaudi::Functional::Consumer
<void()> {
126
using
Base
=
Gaudi::Functional::Consumer
<void()>;
127
using
Base::Base;
128
129
mutable
Gaudi::Accumulators::StaticHistogram
<1,
Gaudi::Accumulators::atomicity::full
,
Category
,
130
std::tuple<Gaudi::Accumulators::CustomAxis>>
131
m_hist
{
this
,
"Categories"
,
""
,
Gaudi::Accumulators::CustomAxis
{} };
132
133
void
operator()
()
const override
{
134
++
m_hist
[
Category::Simple
];
135
m_hist
[
Category::Complex
] += 2;
136
m_hist
[
Category::Bad
] += 3;
137
m_hist
[
Category::Wrong
] += 4;
138
}
139
};
140
DECLARE_COMPONENT
( EnumAxisAlg )
141
}
// namespace CustomAxis
142
namespace
MultiDimLayout
{
143
// Simple algorithm used to check https://gitlab.cern.ch/gaudi/Gaudi/-/issues/212
144
struct
TestAlg
:
Gaudi::Functional::Consumer
<void()> {
145
using
Base
=
Gaudi::Functional::Consumer
<void()>;
146
using
Base::Base;
147
148
mutable
Gaudi::Accumulators::StaticHistogram<1>
m_h1
{
this
,
"h1"
,
""
, { 10, 0, 10 } };
149
mutable
Gaudi::Accumulators::StaticHistogram<2>
m_h2
{
this
,
"h2"
,
""
, { 10, 0, 10 }, { 10, 0, 10 } };
150
mutable
Gaudi::Accumulators::StaticHistogram<3>
m_h3
{
this
,
"h3"
,
""
,
151
{ 10, 0, 10 }, { 10, 0, 10 }, { 10, 0, 10 } };
152
153
void
operator()
()
const override
{
154
int
value = 0;
155
// fill 1, 2 and 3 dimensional histograms with different values in each bin
156
for
(
double
x = -0.5; x < 11; x += 1.0 ) {
157
m_h1
[x] += ++value;
158
for
(
double
y = -0.5; y < 11; y += 1.0 ) {
159
m_h2
[{ x, y }] += ++value;
160
for
(
double
z = -0.5; z < 11; z += 1.0 ) {
m_h3
[{ x, y, z }] += ++value; }
161
}
162
}
163
}
164
};
165
DECLARE_COMPONENT
(
TestAlg
)
166
}
// namespace MultiDimLayout
167
}
// namespace Gaudi::Tests::Histograms
AlgTool.h
Consumer.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
StaticHistogram.h
AlgTool::AlgTool
AlgTool(std::string type, std::string name, const IInterface *parent)
Standard Constructor.
Definition
AlgTool.cpp:80
ToolHandle
Handle to be used in lieu of naked pointers to tools.
Definition
ToolHandle.h:132
Gaudi::Accumulators
Efficient counter implementations for Gaudi.
Definition
Accumulators.h:18
Gaudi::Accumulators::to_json
void to_json(nlohmann::json &j, const Axis< Arithmetic > &axis)
automatic conversion of the Axis type to json
Definition
StaticHistogram.h:329
Gaudi::Accumulators::StaticHistogram
HistogramingCounterBase< ND, Atomicity, Arithmetic, naming::histogramString, HistogramingAccumulator, AxisTupleType > StaticHistogram
standard static histograming counter. See HistogramingCounterBase for details
Definition
StaticHistogram.h:744
Gaudi::Accumulators::atomicity::full
@ full
Definition
Accumulators.h:262
Gaudi::Functional
Definition
Consumer.h:15
Gaudi::Functional::Consumer
details::Consumer< Signature, Traits_, details::isLegacy< Traits_ > > Consumer
Definition
Consumer.h:47
Gaudi::Tests::Histograms::AxesLabels
Definition
HistogramsTests.cpp:108
Gaudi::Tests::Histograms::CustomAxis
Definition
HistogramsTests.cpp:16
Gaudi::Tests::Histograms::CustomAxis::Category
Category
Definition
HistogramsTests.cpp:17
Gaudi::Tests::Histograms::CustomAxis::Category::Complex
@ Complex
Definition
HistogramsTests.cpp:17
Gaudi::Tests::Histograms::CustomAxis::Category::Simple
@ Simple
Definition
HistogramsTests.cpp:17
Gaudi::Tests::Histograms::CustomAxis::Category::Bad
@ Bad
Definition
HistogramsTests.cpp:17
Gaudi::Tests::Histograms::CustomAxis::Category::Wrong
@ Wrong
Definition
HistogramsTests.cpp:17
Gaudi::Tests::Histograms::CustomAxis::operator<<
std::ostream & operator<<(std::ostream &o, Category v)
Definition
HistogramsTests.cpp:18
Gaudi::Tests::Histograms::Directories
Definition
HistogramsTests.cpp:67
Gaudi::Tests::Histograms::Directories::MyHist_t
Gaudi::Accumulators::StaticHistogram< 1 > MyHist_t
Definition
HistogramsTests.cpp:68
Gaudi::Tests::Histograms::MultiDimLayout
Definition
HistogramsTests.cpp:142
Gaudi::Tests::Histograms
Definition
HistogramsTests.cpp:16
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition
__init__.py:1
Gaudi::Accumulators::CustomAxis
Definition
HistogramsTests.cpp:38
Gaudi::Accumulators::CustomAxis::minValue
std::underlying_type_t< Category > minValue
min and max values on this axis
Definition
HistogramsTests.cpp:46
Gaudi::Accumulators::CustomAxis::maxValue
std::underlying_type_t< Category > maxValue
Definition
HistogramsTests.cpp:46
Gaudi::Accumulators::CustomAxis::ArithmeticType
Category ArithmeticType
Definition
HistogramsTests.cpp:40
Gaudi::Accumulators::CustomAxis::index
unsigned int index(Category value) const
Definition
HistogramsTests.cpp:52
Gaudi::Accumulators::CustomAxis::CustomAxis
CustomAxis()=default
Gaudi::Accumulators::CustomAxis::operator<<
friend std::ostream & operator<<(std::ostream &o, CustomAxis const &axis)
Definition
HistogramsTests.cpp:53
Gaudi::Accumulators::CustomAxis::title
std::string title
title of this axis
Definition
HistogramsTests.cpp:48
Gaudi::Accumulators::CustomAxis::labels
std::vector< std::string > labels
labels for the bins
Definition
HistogramsTests.cpp:50
Gaudi::Accumulators::CustomAxis::Category
Gaudi::Tests::Histograms::CustomAxis::Category Category
Definition
HistogramsTests.cpp:39
Gaudi::Accumulators::CustomAxis::numBins
unsigned int numBins() const
number of bins for this Axis
Definition
HistogramsTests.cpp:44
Gaudi::Tests::Histograms::AxesLabels::HistWithLabelsAlg
Definition
HistogramsTests.cpp:109
Gaudi::Tests::Histograms::AxesLabels::HistWithLabelsAlg::MyHist_t
Gaudi::Accumulators::StaticHistogram< 1, Gaudi::Accumulators::atomicity::full, int > MyHist_t
Definition
HistogramsTests.cpp:111
Gaudi::Tests::Histograms::AxesLabels::HistWithLabelsAlg::operator()
void operator()() const override
Definition
HistogramsTests.cpp:118
Gaudi::Tests::Histograms::AxesLabels::HistWithLabelsAlg::m_hist
MyHist_t m_hist
Definition
HistogramsTests.cpp:115
Gaudi::Tests::Histograms::AxesLabels::HistWithLabelsAlg::Base
Gaudi::Functional::Consumer< void()> Base
Definition
HistogramsTests.cpp:110
Gaudi::Tests::Histograms::CustomAxis::EnumAxisAlg
Definition
HistogramsTests.cpp:125
Gaudi::Tests::Histograms::CustomAxis::EnumAxisAlg::Base
Gaudi::Functional::Consumer< void()> Base
Definition
HistogramsTests.cpp:126
Gaudi::Tests::Histograms::CustomAxis::EnumAxisAlg::m_hist
Gaudi::Accumulators::StaticHistogram< 1, Gaudi::Accumulators::atomicity::full, Category, std::tuple< Gaudi::Accumulators::CustomAxis > > m_hist
Definition
HistogramsTests.cpp:131
Gaudi::Tests::Histograms::CustomAxis::EnumAxisAlg::operator()
void operator()() const override
Definition
HistogramsTests.cpp:133
Gaudi::Tests::Histograms::Directories::HistoGroupsAlg
Definition
HistogramsTests.cpp:87
Gaudi::Tests::Histograms::Directories::HistoGroupsAlg::m_tool
ToolHandle< HistoGroupsTool > m_tool
Definition
HistogramsTests.cpp:96
Gaudi::Tests::Histograms::Directories::HistoGroupsAlg::m_hist1
MyHist_t m_hist1
Definition
HistogramsTests.cpp:92
Gaudi::Tests::Histograms::Directories::HistoGroupsAlg::m_hist0
MyHist_t m_hist0
Definition
HistogramsTests.cpp:91
Gaudi::Tests::Histograms::Directories::HistoGroupsAlg::Base
Gaudi::Functional::Consumer< void()> Base
Definition
HistogramsTests.cpp:88
Gaudi::Tests::Histograms::Directories::HistoGroupsAlg::operator()
void operator()() const override
Definition
HistogramsTests.cpp:98
Gaudi::Tests::Histograms::Directories::HistoGroupsAlg::m_hist2
MyHist_t m_hist2
Definition
HistogramsTests.cpp:93
Gaudi::Tests::Histograms::Directories::HistoGroupsAlg::m_hist3
MyHist_t m_hist3
Definition
HistogramsTests.cpp:94
Gaudi::Tests::Histograms::Directories::HistoGroupsTool
Definition
HistogramsTests.cpp:70
Gaudi::Tests::Histograms::Directories::HistoGroupsTool::m_hist3
MyHist_t m_hist3
Definition
HistogramsTests.cpp:76
Gaudi::Tests::Histograms::Directories::HistoGroupsTool::AlgTool
AlgTool(std::string type, std::string name, const IInterface *parent)
Standard Constructor.
Definition
AlgTool.cpp:80
Gaudi::Tests::Histograms::Directories::HistoGroupsTool::m_hist2
MyHist_t m_hist2
Definition
HistogramsTests.cpp:75
Gaudi::Tests::Histograms::Directories::HistoGroupsTool::fillHistos
void fillHistos() const
Definition
HistogramsTests.cpp:78
Gaudi::Tests::Histograms::Directories::HistoGroupsTool::m_hist1
MyHist_t m_hist1
Definition
HistogramsTests.cpp:74
Gaudi::Tests::Histograms::Directories::HistoGroupsTool::m_hist0
MyHist_t m_hist0
Definition
HistogramsTests.cpp:73
Gaudi::Tests::Histograms::MultiDimLayout::TestAlg
Definition
HistogramsTests.cpp:144
Gaudi::Tests::Histograms::MultiDimLayout::TestAlg::m_h2
Gaudi::Accumulators::StaticHistogram< 2 > m_h2
Definition
HistogramsTests.cpp:149
Gaudi::Tests::Histograms::MultiDimLayout::TestAlg::operator()
void operator()() const override
Definition
HistogramsTests.cpp:153
Gaudi::Tests::Histograms::MultiDimLayout::TestAlg::m_h1
Gaudi::Accumulators::StaticHistogram< 1 > m_h1
Definition
HistogramsTests.cpp:148
Gaudi::Tests::Histograms::MultiDimLayout::TestAlg::Base
Gaudi::Functional::Consumer< void()> Base
Definition
HistogramsTests.cpp:145
Gaudi::Tests::Histograms::MultiDimLayout::TestAlg::m_h3
Gaudi::Accumulators::StaticHistogram< 3 > m_h3
Definition
HistogramsTests.cpp:150
TestAlg
Simple algorithm useful as base class for tests.
Definition
TestAlg.h:19
GaudiTestSuite
src
testing
HistogramsTests.cpp
Generated on
for The Gaudi Framework by
1.17.0