The Gaudi Framework  v36r1 (3e2fb5a8)
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{this, "hist", "Histogram title", {5, 0, 5, "axis title", {"a", "b", "c", "d", "e"}}};
88 
89  void operator()() const override {
90  for ( int i : {1, 2, 3, 4, 5} ) m_hist[i - 1] += i;
91  }
92  };
93  DECLARE_COMPONENT( HistWithLabelsAlg )
94  } // namespace AxesLabels
95  namespace CustomAxis {
98  using Base::Base;
99 
101  this, "Categories", "", {{}}};
102 
103  void operator()() const override {
106  m_hist[Category::Bad] += 3;
107  m_hist[Category::Wrong] += 4;
108  }
109  };
110  DECLARE_COMPONENT( EnumAxisAlg )
111  } // namespace CustomAxis
112 } // namespace Gaudi::Tests::Histograms
Gaudi::Accumulators::Axis::minValue
Arithmetic minValue
min and max values on this axis
Definition: Histogram.h:144
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:144
Gaudi::Accumulators::Axis::nBins
unsigned int nBins
number of bins for this Axis
Definition: Histogram.h:140
Histogram.h
std::vector< std::string >
Gaudi::Accumulators::HistogramingCounterBase
A base counter dealing with Histograms.
Definition: Histogram.h:399
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:132
ToolHandle
Definition: ToolHandle.h:135
Consumer.h
Gaudi::Tests::Histograms::AxesLabels::HistWithLabelsAlg::operator()
void operator()() const override
Definition: HistogramsTests.cpp:89
Gaudi::Tests::Histograms::CustomAxis::EnumAxisAlg::m_hist
Gaudi::Accumulators::Histogram< 1, Gaudi::Accumulators::atomicity::full, Category > m_hist
Definition: HistogramsTests.cpp:100
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:103
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:96
AlgTool
Definition: AlgTool.h:62
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
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::Axis::title
std::string title
title of this axis
Definition: Histogram.h:146
Gaudi::Accumulators::Axis::labels
std::vector< std::string > labels
labels for the bins
Definition: Histogram.h:148