ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
HighGranularityTimingDetector
HGTD_Analysis
src
HGTD_AnalysisAlgBase.h
Go to the documentation of this file.
1
14
15
#ifndef HGTD_ANALYSIS_ANALYSISALGBASE_H
16
#define HGTD_ANALYSIS_ANALYSISALGBASE_H
17
18
#include "
AthenaBaseComps/AthAlgorithm.h
"
19
20
// Athena includes
21
#include "GaudiKernel/ITHistSvc.h"
22
#include "GaudiKernel/ServiceHandle.h"
23
24
// ROOT includes
25
#include "TEfficiency.h"
26
#include "TH1.h"
27
28
// stl includes
29
#include <map>
30
#include <string>
31
32
class
HGTD_AnalysisAlgBase
:
public
AthAlgorithm
{
33
34
public
:
35
HGTD_AnalysisAlgBase
(
const
std::string& name, ISvcLocator* svc_locator);
36
virtual
~HGTD_AnalysisAlgBase
();
37
38
virtual
StatusCode
initialize
();
39
40
Gaudi::Property<std::string>
m_directory_name
{
41
this
,
"DirectoryName"
,
"/HGTD_ANA/"
,
"The output directory name"
};
42
51
template
<
typename
T = TH1F,
typename
... Ts>
52
void
bookSubdir
(
const
std::string& trk_sel_name,
const
std::string& time_wp,
53
const
std::string& hist_name,
const
std::string& title,
54
Ts... args) {
55
// check if hist exists already and warn for duplication
56
// doesn't do anything then...
57
std::string name = trk_sel_name +
"/"
+ time_wp +
"/"
+ hist_name;
58
if
(
m_histos
.find(name) !=
m_histos
.end()) {
59
ATH_MSG_WARNING
(
"You are duplicating histogram: "
60
<< name <<
", this is not a good idea\n"
);
61
return
;
62
}
63
m_histos
[name] =
new
T(hist_name.c_str(), title.c_str(), args...);
64
dynamic_cast<
T*
>
(
m_histos
[name])->Sumw2();
65
if
(not
m_hist_svc
66
->regHist(
m_directory_name
+ name,
67
dynamic_cast<
T*
>
(
m_histos
[name]))
68
.isSuccess()) {
69
ATH_MSG_WARNING
(
"Failed to book "
<< name);
70
}
71
}
72
73
template
<
typename
T,
typename
... Ts>
74
void
book
(
const
std::string& name,
const
std::string& title, Ts... args) {
75
// check if hist exists already and warn for duplication
76
// doesn't do anything then...
77
if
(
m_histos
.find(name) !=
m_histos
.end()) {
78
ATH_MSG_WARNING
(
"You are duplicating histogram: "
79
<< name <<
", this is not a good idea\n"
);
80
return
;
81
}
82
m_histos
[name] =
new
T(name.c_str(), title.c_str(), args...);
83
dynamic_cast<
T*
>
(
m_histos
[name])->Sumw2();
84
if
(not
m_hist_svc
85
->regHist(
m_directory_name
+ name,
86
dynamic_cast<
T*
>
(
m_histos
[name]))
87
.isSuccess()) {
88
ATH_MSG_WARNING
(
"Failed to book "
<< name);
89
}
90
}
91
92
template
<
typename
... Ts>
93
void
bookEffSubdir
(
const
std::string& trk_sel_name,
94
const
std::string& time_wp,
const
std::string& hist_name,
95
const
std::string& title, Ts... args) {
96
// check if hist exists already and warn for duplication
97
// doesn't do anything then...
98
std::string name = trk_sel_name +
"/"
+ time_wp +
"/"
+ hist_name;
99
if
(
m_histos
.find(name) !=
m_histos
.end()) {
100
ATH_MSG_WARNING
(
"You are duplicating histogram: "
101
<< name <<
", this is not a good idea\n"
);
102
return
;
103
}
104
m_histos
[name] =
new
TEfficiency(hist_name.c_str(), title.c_str(), args...);
105
if
(not
m_hist_svc
106
->regGraph(
m_directory_name
+ name,
107
reinterpret_cast<
TGraph*
>
(
m_histos
[name]))
108
.isSuccess()) {
109
ATH_MSG_WARNING
(
"Failed to book "
<< name);
110
}
111
}
112
113
template
<
typename
... Ts>
114
void
bookEff
(
const
std::string& name,
const
std::string& title, Ts... args) {
115
// check if hist exists already and warn for duplication
116
// doesn't do anything then...
117
if
(
m_histos
.find(name) !=
m_histos
.end()) {
118
ATH_MSG_WARNING
(
"You are duplicating histogram: "
119
<< name <<
", this is not a good idea\n"
);
120
return
;
121
}
122
m_histos
[name] =
new
TEfficiency(name.c_str(), title.c_str(), args...);
123
if
(not
m_hist_svc
124
->regGraph(
m_directory_name
+ name,
125
reinterpret_cast<
TGraph*
>
(
m_histos
[name]))
126
.isSuccess()) {
127
ATH_MSG_WARNING
(
"Failed to book "
<< name);
128
}
129
}
130
135
template
<
typename
T,
typename
... Ts>
136
void
fill
(
const
std::string& name, Ts... args) {
137
if
(
m_histos
[name] ==
nullptr
or
m_histos
.find(name) ==
m_histos
.end()) {
138
ATH_MSG_WARNING
(
139
"[HistogramHandler::fill] ERROR: you are attempting to fill "
140
"a histogram with name "
141
<< name <<
" which doesn't exist!\n"
);
142
return
;
143
}
144
dynamic_cast<
T*
>
(
m_histos
[name])->Fill(args...);
145
}
146
147
template
<
typename
T,
typename
... Ts>
148
void
fillSubdir
(
const
std::string& trk_sel_name,
const
std::string& time_wp,
149
const
std::string& hist_name, Ts... args) {
150
std::string name = trk_sel_name +
"/"
+ time_wp +
"/"
+ hist_name;
151
if
(
m_histos
[name] ==
nullptr
or
m_histos
.find(name) ==
m_histos
.end()) {
152
ATH_MSG_WARNING
(
153
"[HistogramHandler::fill] ERROR: you are attempting to fill "
154
"a histogram with name "
155
<< name <<
" which doesn't exist!\n"
);
156
return
;
157
}
158
dynamic_cast<
T*
>
(
m_histos
[name])->Fill(args...);
159
}
160
161
template
<
typename
... Ts>
void
fillEff
(
const
std::string& name, Ts... args) {
162
if
(
m_histos
[name] ==
nullptr
or
m_histos
.find(name) ==
m_histos
.end()) {
163
ATH_MSG_WARNING
(
164
"[HistogramHandler::fill] ERROR: you are attempting to fill "
165
"a histogram with name "
166
<< name <<
" which doesn't exist!\n"
);
167
return
;
168
}
169
dynamic_cast<
TEfficiency*
>
(
m_histos
[name])->Fill(args...);
170
}
171
172
template
<
typename
... Ts>
173
void
fillEffSubDir
(
const
std::string& trk_sel_name,
174
const
std::string& wp_name,
const
std::string& hist_name,
175
Ts... args) {
176
std::string name = trk_sel_name +
"/"
+ wp_name +
"/"
+ hist_name;
177
if
(
m_histos
[name] ==
nullptr
or
m_histos
.find(name) ==
m_histos
.end()) {
178
ATH_MSG_WARNING
(
179
"[HistogramHandler::fill] ERROR: you are attempting to fill "
180
"a histogram with name "
181
<< name <<
" which doesn't exist!\n"
);
182
return
;
183
}
184
dynamic_cast<
TEfficiency*
>
(
m_histos
[name])->Fill(args...);
185
}
186
187
protected
:
188
ServiceHandle<ITHistSvc>
m_hist_svc
{
this
,
"THistSvc"
,
"THistSvc"
};
189
190
private
:
191
std::map<std::string, TObject*>
m_histos
;
192
};
193
194
#endif
// HGTD_ANALYSIS_ANALYSISALGBASE_H
AthAlgorithm.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x,...)
Definition
AthMsgStreamMacros.h:46
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
HGTD_AnalysisAlgBase::m_directory_name
Gaudi::Property< std::string > m_directory_name
Definition
HGTD_AnalysisAlgBase.h:40
HGTD_AnalysisAlgBase::bookSubdir
void bookSubdir(const std::string &trk_sel_name, const std::string &time_wp, const std::string &hist_name, const std::string &title, Ts... args)
Templated function for booking histograms The type of the histogram is passed as a template parameter...
Definition
HGTD_AnalysisAlgBase.h:52
HGTD_AnalysisAlgBase::fillEff
void fillEff(const std::string &name, Ts... args)
Definition
HGTD_AnalysisAlgBase.h:161
HGTD_AnalysisAlgBase::bookEff
void bookEff(const std::string &name, const std::string &title, Ts... args)
Definition
HGTD_AnalysisAlgBase.h:114
HGTD_AnalysisAlgBase::m_histos
std::map< std::string, TObject * > m_histos
Definition
HGTD_AnalysisAlgBase.h:191
HGTD_AnalysisAlgBase::~HGTD_AnalysisAlgBase
virtual ~HGTD_AnalysisAlgBase()
Definition
HGTD_AnalysisAlgBase.cxx:15
HGTD_AnalysisAlgBase::fill
void fill(const std::string &name, Ts... args)
Templated function for filling histograms The type of the histogram is passed as a template parameter...
Definition
HGTD_AnalysisAlgBase.h:136
HGTD_AnalysisAlgBase::initialize
virtual StatusCode initialize()
Definition
HGTD_AnalysisAlgBase.cxx:17
HGTD_AnalysisAlgBase::HGTD_AnalysisAlgBase
HGTD_AnalysisAlgBase(const std::string &name, ISvcLocator *svc_locator)
Definition
HGTD_AnalysisAlgBase.cxx:11
HGTD_AnalysisAlgBase::fillEffSubDir
void fillEffSubDir(const std::string &trk_sel_name, const std::string &wp_name, const std::string &hist_name, Ts... args)
Definition
HGTD_AnalysisAlgBase.h:173
HGTD_AnalysisAlgBase::bookEffSubdir
void bookEffSubdir(const std::string &trk_sel_name, const std::string &time_wp, const std::string &hist_name, const std::string &title, Ts... args)
Definition
HGTD_AnalysisAlgBase.h:93
HGTD_AnalysisAlgBase::m_hist_svc
ServiceHandle< ITHistSvc > m_hist_svc
Definition
HGTD_AnalysisAlgBase.h:188
HGTD_AnalysisAlgBase::fillSubdir
void fillSubdir(const std::string &trk_sel_name, const std::string &time_wp, const std::string &hist_name, Ts... args)
Definition
HGTD_AnalysisAlgBase.h:148
HGTD_AnalysisAlgBase::book
void book(const std::string &name, const std::string &title, Ts... args)
Definition
HGTD_AnalysisAlgBase.h:74
ServiceHandle
Definition
ClusterMakerTool.h:36
Generated on
for ATLAS Offline Software by
1.17.0