ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaMonitoring
src
ExampleMonitorAlgorithm.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
ExampleMonitorAlgorithm.h
"
6
7
8
StatusCode
ExampleMonitorAlgorithm::initialize
() {
9
using namespace
Monitored
;
10
// initialize superclass
11
ATH_CHECK
(
AthMonitorAlgorithm::initialize
() );
12
13
m_abGroups1
=
buildToolMap<int>
(
m_tools
,
"ExampleMonitor"
,2);
14
m_abGroups2
=
buildToolMap<std::vector<int>
>(
m_tools
,
"ExampleMonitor"
,4,2);
15
16
std::vector<std::string> layers = {
"layer1"
,
"layer2"
};
17
std::vector<std::string> clusters = {
"clusterX"
,
"clusterB"
};
18
m_cGroups1
=
buildToolMap<int>
(
m_tools
,
"ExampleMonitor"
,layers);
19
m_cGroups2
=
buildToolMap<std::map<std::string,int>
>(
m_tools
,
"ExampleMonitor"
,layers,std::move(clusters));
20
return
StatusCode::SUCCESS;
21
}
22
23
24
StatusCode
ExampleMonitorAlgorithm::fillHistograms
(
const
EventContext& ctx )
const
{
25
using namespace
Monitored
;
26
27
// Declare the quantities which should be monitored
28
auto
lumiPerBCID =
Monitored::Scalar<float>
(
"lumiPerBCID"
,0.0);
29
auto
lb
=
Monitored::Scalar<int>
(
"lb"
,0);
30
auto
run
=
Monitored::Scalar<int>
(
"run"
,0);
31
auto
random =
Monitored::Scalar<float>
(
"random"
,0.0);
32
auto
testweight =
Monitored::Scalar<float>
(
"testweight"
,1.0);
33
34
// Two variables (value and passed) needed for TEfficiency
35
auto
pT =
Monitored::Scalar<float>
(
"pT"
,0.0);
36
auto
pT_passed =
Monitored::Scalar<bool>
(
"pT_passed"
,
false
);
37
38
// a string vector variable
39
std::vector<std::string> strvec{
"alpha"
,
"beta"
};
40
auto
mon_strvec =
Monitored::Collection
(
"strvec"
, strvec);
41
// a plain string
42
std::string mystring =
"gamma"
;
43
auto
mon_str =
Monitored::Scalar<std::string>
(
"str"
, mystring);
44
45
// Set the values of the monitored variables for the event
46
lumiPerBCID =
lbAverageInteractionsPerCrossing
(ctx);
47
lb
=
GetEventInfo
(ctx)->lumiBlock();
48
run
=
GetEventInfo
(ctx)->runNumber();
49
testweight = 2.0;
50
51
// Event number as string
52
auto
mon_evtstr =
Monitored::Scalar<std::string>
(
"evtstr"
, std::to_string(ctx.eventID().event_number()));
53
54
TRandom3
r
(ctx.eventID().event_number());
55
// Example of using flags
56
if
(
m_doRandom
) {
57
random =
r
.Rndm();
58
}
59
60
// Fake efficiency calculator
61
pT =
r
.Landau(15);
62
pT_passed = pT>
r
.Poisson(15);
63
64
// Example of passing a collection
65
std::vector<double> pT_vec{pT};
66
while
(pT_vec.back() > 5) {
67
pT_vec.push_back(pT_vec.back() - 5);
68
}
69
auto
mon_pT_vec =
Monitored::Collection
(
"pT_vec"
, pT_vec);
70
71
// Fill. First argument is the tool name, all others are the variables to be saved.
72
fill
(
"ExampleMonitor"
,lumiPerBCID,
lb
,random,pT,pT_passed,mon_pT_vec,testweight,mon_str,mon_strvec,mon_evtstr);
73
74
// Alternative fill method. Get the group yourself, and pass it to the fill function.
75
const
auto
& tool =
getGroup
(
"ExampleMonitor"
);
76
fill
(tool,
run
);
77
78
// Fill with a vector; useful in some circumstances.
79
std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> varVec = {lumiPerBCID,pT};
80
fill
(
"ExampleMonitor"
,varVec);
81
fill
(tool,varVec);
82
83
// Filling using a pre-defined array of groups.
84
auto
a
=
Scalar<float>
(
"a"
,0.0);
85
auto
b =
Scalar<float>
(
"b"
,1.0);
86
auto
c =
Scalar<float>
(
"c"
,2.0);
87
for
(
auto
iEta : {0,1} ) {
88
// 1) Valid but inefficient fill
89
fill
(
"ExampleMonitor_"
+std::to_string(iEta),
a
,b,c);
90
// 2) Faster way to fill a vector of histograms
91
fill
(
m_tools
[
m_abGroups1
[iEta]],
a
,b,c);
92
for
(
auto
iPhi : {0,1} ) {
93
// Same efficient method for 2D array
94
fill
(
m_tools
[
m_abGroups2
[iEta][iPhi]],
a
,b);
95
}
96
}
97
98
// Filling using a pre-defined map of groups.
99
for
(
auto
& layer : std::vector<std::string>({
"layer1"
,
"layer2"
}) ) {
100
fill
(
m_tools
[
m_cGroups1
.at(layer)],c);
101
for
(
auto
& cluster : std::vector<std::string>({
"clusterX"
,
"clusterB"
}) ) {
102
// Same efficient method for 2D map
103
fill
(
m_tools
[
m_cGroups2
.at(layer).at(cluster)],c);
104
}
105
}
106
107
return
StatusCode::SUCCESS;
108
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ExampleMonitorAlgorithm.h
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition
AthMonitorAlgorithm.cxx:22
AthMonitorAlgorithm::getGroup
const ToolHandle< GenericMonitoringTool > & getGroup(std::string_view name) const
Get a specific monitoring tool from the tool handle array.
Definition
AthMonitorAlgorithm.cxx:168
AthMonitorAlgorithm::GetEventInfo
SG::ReadHandle< xAOD::EventInfo > GetEventInfo(const EventContext &) const
Return a ReadHandle for an EventInfo object (get run/event numbers, etc.).
Definition
AthMonitorAlgorithm.cxx:111
AthMonitorAlgorithm::m_tools
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
Definition
AthMonitorAlgorithm.h:344
ExampleMonitorAlgorithm::m_abGroups1
std::vector< int > m_abGroups1
Definition
ExampleMonitorAlgorithm.h:20
ExampleMonitorAlgorithm::m_cGroups2
std::map< std::string, std::map< std::string, int > > m_cGroups2
Definition
ExampleMonitorAlgorithm.h:23
ExampleMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition
ExampleMonitorAlgorithm.cxx:8
ExampleMonitorAlgorithm::m_abGroups2
std::vector< std::vector< int > > m_abGroups2
Definition
ExampleMonitorAlgorithm.h:21
ExampleMonitorAlgorithm::m_doRandom
Gaudi::Property< bool > m_doRandom
Definition
ExampleMonitorAlgorithm.h:19
ExampleMonitorAlgorithm::m_cGroups1
std::map< std::string, int > m_cGroups1
Definition
ExampleMonitorAlgorithm.h:22
ExampleMonitorAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition
ExampleMonitorAlgorithm.cxx:24
Monitored::Scalar
Declare a monitored scalar variable.
Definition
MonitoredScalar.h:34
lb
int lb
Definition
globals.cxx:23
r
int r
Definition
globals.cxx:22
AthMonitorAlgorithm::fill
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable > > &&variables) const
Fills a vector of variables to a group by reference.
Definition
AthMonitorAlgorithm.cxx:99
AthMonitorAlgorithm::lbAverageInteractionsPerCrossing
virtual float lbAverageInteractionsPerCrossing(const EventContext &ctx) const
Calculate the average mu, i.e.
Definition
AthMonitorAlgorithm.cxx:236
Monitored
Generic monitoring tool for athena components.
Definition
GenericMonitoringTool.h:28
Monitored::buildToolMap
std::vector< V > buildToolMap(const ToolHandleArray< GenericMonitoringTool > &tools, const std::string &baseName, int nHist)
Builds an array of indices (base case).
Definition
MonitoredGroup.h:148
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition
MonitoredCollection.h:38
run
int run(int argc, char *argv[])
Definition
ttree2hdf5.cxx:28
Generated on
for ATLAS Offline Software by
1.17.0