Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
HistogramsTests.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 2021 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 \***********************************************************************************/
12 #include <GaudiAlg/Consumer.h>
13 #include <type_traits>
14 
16  enum class Category { Simple, Complex, Bad, Wrong };
17 }
18 
20  template <>
23 
24  Axis() = default;
26  unsigned int nBins = 4;
28  std::underlying_type_t<Category> minValue = 0, maxValue = 4;
30  std::string title{ "Category" };
32  std::vector<std::string> labels{ "Simple", "Complex", "Bad", "Wrong" };
33 
34  unsigned int index( Category value ) const { return static_cast<unsigned int>( value ) + 1; }
35  };
36 } // namespace Gaudi::Accumulators
37 
38 namespace Gaudi::Tests::Histograms {
39  namespace Directories {
41 
43  using AlgTool::AlgTool;
44 
45  mutable MyHist_t m_hist0{ this, "Top", "Top title", { 1, 0, 1 } };
46  mutable MyHist_t m_hist1{ this, "Group/First", "First title", { 1, 0, 1 } };
47  mutable MyHist_t m_hist2{ this, "Group/Second", "Second title", { 1, 0, 1 } };
48  mutable MyHist_t m_hist3{ this, "Group/SubGroup/Third", "Third title", { 1, 0, 1 } };
49 
50  void fillHistos() const {
51  ++m_hist0[0.5];
52  ++m_hist1[0.5];
53  ++m_hist2[0.5];
54  ++m_hist3[0.5];
55  }
56  };
57  DECLARE_COMPONENT( HistoGroupsTool )
58 
59  struct HistoGroupsAlg : Gaudi::Functional::Consumer<void()> {
61  using Base::Base;
62 
63  mutable MyHist_t m_hist0{ this, "Top", "Top title", { 1, 0, 1 } };
64  mutable MyHist_t m_hist1{ this, "Group/First", "First title", { 1, 0, 1 } };
65  mutable MyHist_t m_hist2{ this, "Group/Second", "Second title", { 1, 0, 1 } };
66  mutable MyHist_t m_hist3{ this, "Group/SubGroup/Third", "Third title", { 1, 0, 1 } };
67 
68  ToolHandle<HistoGroupsTool> m_tool{ this, "Tool", "Gaudi::Tests::Histograms::Directories::HistoGroupsTool/Tool" };
69 
70  void operator()() const override {
71  ++m_hist0[0.5];
72  ++m_hist1[0.5];
73  ++m_hist2[0.5];
74  ++m_hist3[0.5];
75  m_tool->fillHistos();
76  }
77  };
78  DECLARE_COMPONENT( HistoGroupsAlg )
79  } // namespace Directories
80  namespace AxesLabels {
84 
85  using Base::Base;
86 
87  mutable MyHist_t m_hist{
88  this, "hist", "Histogram title", { 5, 0, 5, "axis title", { "a", "b", "c", "d", "e" } } };
89 
90  void operator()() const override {
91  for ( int i : { 1, 2, 3, 4, 5 } ) m_hist[i - 1] += i;
92  }
93  };
94  DECLARE_COMPONENT( HistWithLabelsAlg )
95  } // namespace AxesLabels
96  namespace CustomAxis {
99  using Base::Base;
100 
102  this, "Categories", "", Gaudi::Accumulators::Axis<Category>{} };
103 
104  void operator()() const override {
107  m_hist[Category::Bad] += 3;
108  m_hist[Category::Wrong] += 4;
109  }
110  };
111  DECLARE_COMPONENT( EnumAxisAlg )
112  } // namespace CustomAxis
113  namespace MultiDimLayout {
114  // Simple algorithm used to check https://gitlab.cern.ch/gaudi/Gaudi/-/issues/212
117  using Base::Base;
118 
119  mutable Gaudi::Accumulators::Histogram<1> m_h1{ this, "h1", "", { 10, 0, 10 } };
120  mutable Gaudi::Accumulators::Histogram<2> m_h2{ this, "h2", "", { 10, 0, 10 }, { 10, 0, 10 } };
121  mutable Gaudi::Accumulators::Histogram<3> m_h3{ this, "h3", "", { 10, 0, 10 }, { 10, 0, 10 }, { 10, 0, 10 } };
122 
123  void operator()() const override {
124  int value = 0;
125  // fill 1, 2 and 3 dimensional histograms with different values in each bin
126  for ( double x = -0.5; x < 11; x += 1.0 ) {
127  m_h1[x] += ++value;
128  for ( double y = -0.5; y < 11; y += 1.0 ) {
129  m_h2[{ x, y }] += ++value;
130  for ( double z = -0.5; z < 11; z += 1.0 ) { m_h3[{ x, y, z }] += ++value; }
131  }
132  }
133  }
134  };
135  DECLARE_COMPONENT( TestAlg )
136  } // namespace MultiDimLayout
137 } // namespace Gaudi::Tests::Histograms
Gaudi::Accumulators::Axis::minValue
Arithmetic minValue
min and max values on this axis
Definition: Histogram.h:171
Gaudi::Tests::Histograms::Directories::HistoGroupsTool
Definition: HistogramsTests.cpp:42
Gaudi::Accumulators::Axis< Gaudi::Tests::Histograms::CustomAxis::Category >::Axis
Axis()=default
Gaudi::Functional::Consumer
details::Consumer< Signature, Traits_, details::isLegacy< Traits_ > > Consumer
Definition: Consumer.h:69
std::string
STL class.
Gaudi::Tests::Histograms::AxesLabels::HistWithLabelsAlg::m_hist
MyHist_t m_hist
Definition: HistogramsTests.cpp:87
Gaudi::Tests::Histograms::Directories::HistoGroupsTool::fillHistos
void fillHistos() const
Definition: HistogramsTests.cpp:50
Gaudi::Accumulators::Axis::maxValue
Arithmetic maxValue
Definition: Histogram.h:171
Gaudi::Accumulators::Axis::nBins
unsigned int nBins
number of bins for this Axis
Definition: Histogram.h:167
Histogram.h
std::vector< std::string >
Gaudi::Tests::Histograms::AxesLabels::HistWithLabelsAlg
Definition: HistogramsTests.cpp:81
AlgTool::AlgTool
AlgTool(std::string type, std::string name, const IInterface *parent)
Standard Constructor.
Definition: AlgTool.cpp:116
Gaudi::Accumulators::Axis< Gaudi::Tests::Histograms::CustomAxis::Category >::index
unsigned int index(Category value) const
Definition: HistogramsTests.cpp:34
Gaudi::Tests::Histograms
Definition: HistogramsTests.cpp:15
Gaudi::Tests::Histograms::CustomAxis::Category::Bad
@ Bad
Gaudi::Tests::Histograms::Directories::HistoGroupsAlg
Definition: HistogramsTests.cpp:59
Gaudi::Tests::Histograms::Directories::HistoGroupsTool::m_hist1
MyHist_t m_hist1
Definition: HistogramsTests.cpp:46
Gaudi::Functional::details::Consumer
Definition: Consumer.h:24
Gaudi::Accumulators::Axis
Definition of an Histogram Axis.
Definition: Histogram.h:154
ToolHandle
Definition: ToolHandle.h:132
Gaudi::Tests::Histograms::MultiDimLayout::TestAlg::operator()
void operator()() const override
Definition: HistogramsTests.cpp:123
Consumer.h
Gaudi::Tests::Histograms::AxesLabels::HistWithLabelsAlg::operator()
void operator()() const override
Definition: HistogramsTests.cpp:90
Gaudi::Tests::Histograms::CustomAxis::EnumAxisAlg::m_hist
Gaudi::Accumulators::Histogram< 1, Gaudi::Accumulators::atomicity::full, Category > m_hist
Definition: HistogramsTests.cpp:101
Gaudi::Tests::Histograms::CustomAxis::Category
Category
Definition: HistogramsTests.cpp:16
Gaudi::Tests::Histograms::Directories::HistoGroupsAlg::operator()
void operator()() const override
Definition: HistogramsTests.cpp:70
Gaudi::Tests::Histograms::Directories::HistoGroupsTool::m_hist0
MyHist_t m_hist0
Definition: HistogramsTests.cpp:45
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
Gaudi::Tests::Histograms::Directories::HistoGroupsTool::m_hist3
MyHist_t m_hist3
Definition: HistogramsTests.cpp:48
Gaudi::Tests::Histograms::CustomAxis::EnumAxisAlg::operator()
void operator()() const override
Definition: HistogramsTests.cpp:104
Gaudi::Tests::Histograms::MultiDimLayout::TestAlg::m_h2
Gaudi::Accumulators::Histogram< 2 > m_h2
Definition: HistogramsTests.cpp:120
Gaudi::Tests::Histograms::CustomAxis::Category::Wrong
@ Wrong
Gaudi::Tests::Histograms::CustomAxis::Category::Complex
@ Complex
Gaudi::Accumulators
Definition: HistogramsTests.cpp:19
Gaudi::Tests::Histograms::CustomAxis::EnumAxisAlg
Definition: HistogramsTests.cpp:97
AlgTool
Definition: AlgTool.h:62
Gaudi::Tests::Histograms::MultiDimLayout::TestAlg::m_h3
Gaudi::Accumulators::Histogram< 3 > m_h3
Definition: HistogramsTests.cpp:121
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Tests::Histograms::MultiDimLayout::TestAlg::m_h1
Gaudi::Accumulators::Histogram< 1 > m_h1
Definition: HistogramsTests.cpp:119
Gaudi::Tests::Histograms::MultiDimLayout::TestAlg
Definition: HistogramsTests.cpp:115
Gaudi::Tests::Histograms::CustomAxis
Definition: HistogramsTests.cpp:15
Gaudi::Tests::Histograms::Directories::HistoGroupsTool::m_hist2
MyHist_t m_hist2
Definition: HistogramsTests.cpp:47
Gaudi::Tests::Histograms::CustomAxis::Category::Simple
@ Simple
Gaudi::Accumulators::HistogramingCounterBaseInternal
A base counter dealing with Histograms.
Definition: Histogram.h:450
Gaudi::Accumulators::Axis::title
std::string title
title of this axis
Definition: Histogram.h:173
Gaudi::Accumulators::Axis::labels
std::vector< std::string > labels
labels for the bins
Definition: Histogram.h:175