ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigCost
TrigCostAnalysis
src
Variable.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
6
7
#include "
Variable.h
"
8
#include "TH1F.h"
9
#include "TH2F.h"
10
#include "TProfile.h"
11
#include <cmath>
12
13
Variable::Variable
(
const
std::string& name, TH1* cacheHistoPtr,
VariableType
type
) :
14
m_name
(name),
15
m_variableType
(
type
),
16
m_cacheHistoPtr
(cacheHistoPtr),
17
m_calls
(0),
18
m_xaccumulator
(0.),
19
m_yaccumulator
(0.),
20
m_weight
(0.),
21
m_oneOverDenominator
(1.) {
22
}
23
24
25
const
std::string&
Variable::getName
()
const
{
26
return
m_name
;
27
}
28
29
30
size_t
Variable::getCalls
()
const
{
31
return
m_calls
;
32
}
33
34
35
float
Variable::getAccumulator
()
const
{
36
return
m_xaccumulator
;
37
}
38
39
40
void
Variable::setDenominator
(
float
value) {
41
// Stored as reciprocal so as to be able to check for /0 here
42
if
(std::abs(value) < 1e-10) {
43
m_oneOverDenominator
= 0.0;
44
}
else
{
45
m_oneOverDenominator
= 1. / value;
46
}
47
}
48
49
50
StatusCode
Variable::fill
(
float
value,
float
weight) {
51
switch
(
m_variableType
) {
52
case
kPerCall
:
53
ATH_CHECK
(
m_cacheHistoPtr
!=
nullptr
);
54
m_cacheHistoPtr
->Fill(value *
m_oneOverDenominator
, weight);
55
break
;
56
case
kPerEvent
:
57
++
m_calls
;
58
m_xaccumulator
+= value;
59
m_weight
= weight;
60
break
;
61
default
:
62
return
StatusCode::FAILURE;
63
break
;
64
}
65
return
StatusCode::SUCCESS;
66
}
67
68
69
StatusCode
Variable::fill
(
float
xvalue,
float
yvalue,
float
weight) {
70
switch
(
m_variableType
) {
71
case
kPerCall
:
72
{
73
ATH_CHECK
(
m_cacheHistoPtr
!=
nullptr
);
74
TH2F* th2f =
dynamic_cast<
TH2F*
>
(
m_cacheHistoPtr
);
75
if
(th2f ==
nullptr
){
76
// Cast failed - should be TProfile
77
auto
p =
dynamic_cast<
TProfile*
>
(
m_cacheHistoPtr
);
78
if
(p){
79
p->Fill(xvalue *
m_oneOverDenominator
, yvalue *
m_oneOverDenominator
, weight);
80
}
else
{
81
return
StatusCode::FAILURE;
82
}
83
}
else
{
84
th2f->Fill(xvalue *
m_oneOverDenominator
, yvalue *
m_oneOverDenominator
, weight);
85
}
86
break
;
87
}
88
case
kPerEvent
:
89
++
m_calls
;
90
m_xaccumulator
+= xvalue;
91
m_yaccumulator
+= yvalue;
92
m_weight
= weight;
93
break
;
94
default
:
95
return
StatusCode::FAILURE;
96
break
;
97
}
98
return
StatusCode::SUCCESS;
99
}
100
101
102
StatusCode
Variable::fill
(
const
std::string&
label
,
float
weight) {
103
m_cacheHistoPtr
->Fill(
label
.c_str(), weight);
104
return
StatusCode::SUCCESS;
105
}
106
107
108
StatusCode
Variable::increment
(
float
weight) {
109
ATH_CHECK
(
fill
(1.0, weight));
110
return
StatusCode::SUCCESS;
111
}
112
113
114
StatusCode
Variable::setBinLabel
(
int
bin
,
const
std::string&
label
) {
115
m_cacheHistoPtr
->GetXaxis()->SetBinLabel(
bin
,
label
.c_str());
116
return
StatusCode::SUCCESS;
117
}
118
119
120
StatusCode
Variable::setYBinLabel
(
int
bin
,
const
std::string&
label
) {
121
m_cacheHistoPtr
->GetYaxis()->SetBinLabel(
bin
,
label
.c_str());
122
return
StatusCode::SUCCESS;
123
}
124
125
126
StatusCode
Variable::endEvent
() {
127
if
(
m_variableType
==
kPerEvent
&&
m_calls
> 0) {
128
ATH_CHECK
(
m_cacheHistoPtr
!=
nullptr
);
129
// 2D histogram
130
if
(
m_yaccumulator
> 0){
131
TH2F* th2f =
dynamic_cast<
TH2F*
>
(
m_cacheHistoPtr
);
132
if
(th2f ==
nullptr
){
133
// Cast failed - should be TProfile
134
auto
p =
dynamic_cast<
TProfile*
>
(
m_cacheHistoPtr
);
135
if
(p){
136
p->Fill(
m_xaccumulator
*
m_oneOverDenominator
,
m_yaccumulator
,
m_weight
);
137
}
else
{
138
return
StatusCode::FAILURE;
139
}
140
}
else
{
141
th2f->Fill(
m_xaccumulator
*
m_oneOverDenominator
,
m_yaccumulator
,
m_weight
);
142
}
143
}
else
{
144
m_cacheHistoPtr
->Fill(
m_xaccumulator
*
m_oneOverDenominator
,
m_weight
);
145
}
146
147
}
148
m_calls
= 0;
149
m_xaccumulator
= 0.0;
150
m_yaccumulator
= 0.0;
151
m_weight
= 0.0;
152
m_oneOverDenominator
= 1.0;
153
return
StatusCode::SUCCESS;
154
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
Variable.h
VariableType
VariableType
Behaviour of Variable.
Definition
Variable.h:19
kPerEvent
@ kPerEvent
Variable should buffer fill calls in an accumulator and fill the underlying histogram once at the end...
Definition
Variable.h:21
kPerCall
@ kPerCall
Variable should fill underlying histogram on each fill.
Definition
Variable.h:20
Variable::m_xaccumulator
float m_xaccumulator
Definition
Variable.h:148
Variable::m_weight
float m_weight
Cache of the event weight.
Definition
Variable.h:150
Variable::endEvent
StatusCode endEvent()
Called by the framework.
Definition
Variable.cxx:126
Variable::Variable
Variable()=delete
Forbid default constructor.
Variable::increment
StatusCode increment(float weight=1.0)
Convenience function.
Definition
Variable.cxx:108
Variable::fill
StatusCode fill(float value, float weight=1.0)
Fill histogram (per-Call Variable), or add value to internal accumulator (per-Event Variable) to be f...
Definition
Variable.cxx:50
Variable::setDenominator
void setDenominator(float value)
Sets, until the end of the event, a denominator which will be used to normalise every Fill.
Definition
Variable.cxx:40
Variable::setYBinLabel
StatusCode setYBinLabel(int bin, const std::string &label)
Set label on given bin in cached histogram on y axis.
Definition
Variable.cxx:120
Variable::getName
const std::string & getName() const
Getter for Variable's name.
Definition
Variable.cxx:25
Variable::getCalls
size_t getCalls() const
Getter for how many times fill() has already been called on this Variable in this event.
Definition
Variable.cxx:30
Variable::m_variableType
const VariableType m_variableType
Definition
Variable.h:145
Variable::m_yaccumulator
float m_yaccumulator
Definition
Variable.h:149
Variable::getAccumulator
float getAccumulator() const
Getter for accumulated value of a kPerEvent Variable.
Definition
Variable.cxx:35
Variable::setBinLabel
StatusCode setBinLabel(int bin, const std::string &label)
Set label on given bin in cached histogram.
Definition
Variable.cxx:114
Variable::m_calls
size_t m_calls
Definition
Variable.h:147
Variable::m_name
const std::string m_name
Definition
Variable.h:144
Variable::m_cacheHistoPtr
TH1 * m_cacheHistoPtr
Definition
Variable.h:146
Variable::m_oneOverDenominator
float m_oneOverDenominator
Cache of the reciprocal of the denominator used to normalise when filling the histogram.
Definition
Variable.h:151
bin
Definition
BinsDiffFromStripMedian.h:43
label
std::string label(const std::string &format, int i)
Definition
label.h:19
type
Generated on
for ATLAS Offline Software by
1.17.0