ATLAS Offline Software
Loading...
Searching...
No Matches
TIDAHistogram.h
Go to the documentation of this file.
1
10
11
12#ifndef TIDA_HISTOGRAM_H
13#define TIDA_HISTOGRAM_H
14
15#include "GaudiKernel/ToolHandle.h"
17
19
20#include <string>
21#include <stdexcept>
22
23namespace TIDA {
24
26
27public:
28
29 HistogramBase() : m_monTool(0), m_name("UNINITIALISED"), m_varname(), m_initialised(false) { }
30
31 HistogramBase( ToolHandle<GenericMonitoringTool>* m, const std::string& name, const std::string& domain="" ) :
33 if ( !m_name.empty() && m_monTool ) m_initialised = true;
34 }
35
36 const std::string& name() const { return m_name; }
37 const std::string& varname() const { return m_varname; }
38
39 bool initialised() const { return m_initialised; }
40
41 const ToolHandle<GenericMonitoringTool>* monTool() const { return m_monTool; };
42
43private:
44
45 ToolHandle<GenericMonitoringTool>* m_monTool;
46
47 std::string m_name;
48 std::string m_varname;
49
51
52};
53
54
55template<typename T>
56class Histogram : public HistogramBase {
57
58public:
59
61
62 void Fill( T d ) const {
63 if ( !initialised() ) throw std::runtime_error("TIDA::Histogram not initialised: "+name());
64 auto s = Monitored::Scalar<T>( varname(), d );
66 }
67
68 void Fill( T d, T w ) const {
69 if ( !initialised() ) throw std::runtime_error("TIDA::Histogram not initialised: "+name());
70 auto s = Monitored::Scalar<T>( varname(), d );
71 auto sw = Monitored::Scalar<T>( varname()+"_weight", w );
72 Monitored::Group( *monTool(), s, sw );
73 }
74
75 const Histogram* operator->() const { return this; }
76
77};
78
79
80template<typename T,typename U=T>
81class Histogram2D : public HistogramBase {
82
83public:
84
86
87 void Fill( T x, U y ) const {
88 if ( !initialised() ) throw std::runtime_error("TIDA::Histogram not initialised: "+name());
89 auto sx = Monitored::Scalar<T>( varname()+"__x", x );
90 auto sy = Monitored::Scalar<T>( varname()+"__y", y );
91 Monitored::Group( *monTool(), sx, sy );
92 }
93
94 void Fill( T x, U y, T w) const {
95 if ( !initialised() ) throw std::runtime_error("TIDA::Histogram not initialised: "+name());
96 auto sx = Monitored::Scalar<T>( varname()+"__x", x );
97 auto sy = Monitored::Scalar<T>( varname()+"__y", y );
98 auto sw = Monitored::Scalar<T>( varname()+"_weight", w );
99 Monitored::Group( *monTool(), sx, sy, sw );
100 }
101
102 const Histogram2D* operator->() const { return this; }
103
104};
105
106
107}
108
109
110#endif /* TIDA_HISTOGRAM_H */
111
112
113
114
115
116
117
118
119
120
int domain(int argc, char *argv[])
Header file to be included by clients of the Monitored infrastructure.
#define y
#define x
static const Attributes_t empty
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
void Fill(T x, U y, T w) const
void Fill(T x, U y) const
const Histogram2D * operator->() const
std::string m_varname
HistogramBase(ToolHandle< GenericMonitoringTool > *m, const std::string &name, const std::string &domain="")
ToolHandle< GenericMonitoringTool > * m_monTool
const std::string & varname() const
const std::string & name() const
const ToolHandle< GenericMonitoringTool > * monTool() const
bool initialised() const
const Histogram * operator->() const
void Fill(T d) const
void Fill(T d, T w) const
Test for xAOD.