ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkCalo
src
GainDecorator.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
// Author: Simone Mazza (simone.mazza@mi.infn.it),
6
// Bruno Lenzi,
7
// Giovanni Marchiori (giovanni.marchiori@cern.ch)
8
// Decorate egamma objects with the energy and number of cells per layer per
9
// gain
10
11
#include "
DerivationFrameworkCalo/GainDecorator.h
"
12
#include "
CaloEvent/CaloCell.h
"
13
14
15
16
// Athena initialize and finalize
17
StatusCode
18
DerivationFramework::GainDecorator::initialize
()
19
{
20
ATH_MSG_VERBOSE
(
"initialize() ..."
);
21
22
if
(
m_SGKey_photons
.key().empty() &&
m_SGKey_electrons
.key().empty()) {
23
ATH_MSG_FATAL
(
"No e-gamma collection provided for thinning. At least one "
24
"egamma collection (photons/electrons) must be provided!"
);
25
return
StatusCode::FAILURE;
26
}
27
28
for
(
const
auto
& kv :
m_gainNames
) {
29
for
(
const
auto
layer :
m_layers
) {
30
m_names_E
.emplace_back(kv.first, layer);
31
}
32
}
33
34
ATH_CHECK
(
m_SGKey_electrons
.initialize(
SG::AllowEmpty
));
35
if
(!
m_SGKey_electrons
.key().empty()) {
36
ATH_MSG_DEBUG
(
"Using "
<<
m_SGKey_electrons
<<
" for electrons"
);
37
}
38
ATH_CHECK
(
m_SGKey_electrons_decorations
.initialize(!
m_SGKey_electrons
.key().empty()));
39
40
ATH_CHECK
(
m_SGKey_photons
.initialize(
SG::AllowEmpty
));
41
if
(!
m_SGKey_photons
.key().empty()) {
42
ATH_MSG_DEBUG
(
"Using "
<<
m_SGKey_photons
<<
" for photons"
);
43
}
44
ATH_CHECK
(
m_SGKey_photons_decorations
.initialize(!
m_SGKey_photons
.key().empty()));
45
46
return
StatusCode::SUCCESS;
47
}
48
49
// The decoration itself
50
StatusCode
51
DerivationFramework::GainDecorator::addBranches
(
const
EventContext& ctx)
const
52
{
53
ATH_MSG_DEBUG
(
"m_gainNames.size() = "
<<
m_gainNames
.size() <<
", m_layers.size() = "
<<
m_layers
.size() );
54
const
size_t
limit{
m_gainNames
.size()*
m_layers
.size()};
55
if
(limit == 0) {
return
StatusCode::FAILURE; }
// FIXME Add ERROR message here
56
// Photon decorations
57
58
if
(!
m_SGKey_photons
.key().empty()) {
59
60
// Retrieve photon container
61
SG::ReadHandle<xAOD::EgammaContainer>
photonContainer
(
m_SGKey_photons
, ctx);
62
const
xAOD::EgammaContainer
* importedPhotons =
photonContainer
.ptr();
63
64
// Setup vectors of photon decorations
65
std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>>
66
decorations_E;
67
std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>>
68
decorations_rnoW;
69
std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, char>>
70
decorations_nCells;
71
for
(
unsigned
int
i = 0; i < limit; ++i) {
72
decorations_E.emplace_back(
73
m_SGKey_photons_decorations
[i * 3], ctx);
74
decorations_rnoW.emplace_back(
75
m_SGKey_photons_decorations
[i * 3 + 1], ctx);
76
decorations_nCells.emplace_back(
77
m_SGKey_photons_decorations
[i * 3 + 2], ctx);
78
}
79
// Decorate photons
80
int
i(0);
81
for
(
const
auto
* photon : *importedPhotons) {
82
DerivationFramework::GainDecorator::calculation
res
=
83
decorateObject
(photon);
84
i = 0;
85
for
(
const
auto
& kv :
m_gainNames
) {
86
for
(
const
auto
layer :
m_layers
) {
87
std::pair<int, int> key(kv.first, layer);
88
decorations_E[i](*photon) =
res
.E[key];
89
decorations_rnoW[i](*photon) =
90
res
.EnoW[key] != 0 ?
res
.E[key]/
res
.EnoW[key] : 1;
91
decorations_nCells[i](*photon) =
res
.nCells[key];
92
i++;
93
}
94
}
95
}
96
}
97
98
// Electron decorations
99
100
if
(!
m_SGKey_electrons
.key().empty()) {
101
102
// Retrieve electron container
103
SG::ReadHandle<xAOD::EgammaContainer>
electronContainer
(
m_SGKey_electrons
,
104
ctx);
105
const
xAOD::EgammaContainer
* importedElectrons =
electronContainer
.ptr();
106
107
// Setup vectors of electron decorations
108
std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>>
109
decorations_E;
110
std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>>
111
decorations_rnoW;
112
std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, char>>
113
decorations_nCells;
114
for
(
unsigned
int
i = 0; i < limit; ++i) {
115
decorations_E.emplace_back(
116
m_SGKey_electrons_decorations
[i * 3], ctx);
117
decorations_rnoW.emplace_back(
118
m_SGKey_electrons_decorations
[i * 3 + 1], ctx);
119
decorations_nCells.emplace_back(
120
m_SGKey_electrons_decorations
[i * 3 + 2], ctx);
121
}
122
// Decorate electrons
123
int
i(0);
124
for
(
const
auto
* electron : *importedElectrons) {
125
DerivationFramework::GainDecorator::calculation
res
=
126
decorateObject
(electron);
127
i = 0;
128
for
(
const
auto
& kv :
m_gainNames
) {
129
for
(
const
auto
layer :
m_layers
) {
130
std::pair<int, int> key(kv.first, layer);
131
decorations_E[i](*electron) =
res
.E[key];
132
decorations_rnoW[i](*electron) =
133
res
.EnoW[key] != 0 ?
res
.E[key]/
res
.EnoW[key] : 1;
134
decorations_nCells[i](*electron) =
res
.nCells[key];
135
i++;
136
}
137
}
138
}
139
}
140
141
return
StatusCode::SUCCESS;
142
}
143
144
DerivationFramework::GainDecorator::calculation
145
DerivationFramework::GainDecorator::decorateObject
(
146
const
xAOD::Egamma
*&
egamma
)
const
147
{
148
149
// Compute energy and number of cells per gain per layer
150
// Set the initial values to 0 (needed?)
151
DerivationFramework::GainDecorator::calculation
result;
152
for
(
const
auto
& kv :
m_names_E
) {
153
result.E[kv] = 0.;
154
result.EnoW[kv] = 0.;
155
result.nCells[kv] = 0;
156
}
157
158
// Skip the computation for missing cell links (like topo-seeded photons)
159
// but decorate anyway
160
const
CaloClusterCellLink
* cellLinks =
161
egamma
->caloCluster() ?
egamma
->caloCluster()->getCellLinks() :
nullptr
;
162
if
(cellLinks) {
163
CaloClusterCellLink::const_iterator
it = cellLinks->
begin
(),
164
itE = cellLinks->
end
();
165
for
(; it != itE; ++it) {
166
const
CaloCell
*cell = *it;
167
if
(!cell)
168
continue
;
169
std::pair<int, int> key(
static_cast<
int
>
(cell->gain()),
getLayer
(cell));
170
// Increment the corresponding entry (not important if it is not
171
// initialised)
172
double
weight = it.weight();
173
result.E[key] += cell->energy()*weight;
174
result.EnoW[key] += cell->energy();
175
result.nCells[key]++;
176
}
177
}
178
179
return
result;
180
}
181
182
int
183
DerivationFramework::GainDecorator::getLayer
(
const
CaloCell
* cell)
184
{
185
int
sampling =
186
(cell && cell->caloDDE() ? cell->caloDDE()->getSampling() : -1);
187
if
(sampling == CaloSampling::PreSamplerB ||
188
sampling == CaloSampling::PreSamplerE)
189
return
0;
190
if
(sampling == CaloSampling::EMB1 || sampling == CaloSampling::EME1)
191
return
1;
192
if
(sampling == CaloSampling::EMB2 || sampling == CaloSampling::EME2)
193
return
2;
194
if
(sampling == CaloSampling::EMB3 || sampling == CaloSampling::EME3)
195
return
3;
196
return
-1;
197
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x,...)
Definition
AthMsgStreamMacros.h:43
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x,...)
Definition
AthMsgStreamMacros.h:42
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x,...)
Definition
AthMsgStreamMacros.h:48
CaloCell.h
GainDecorator.h
res
std::pair< std::vector< unsigned int >, bool > res
Definition
JetGroupProductTest.cxx:11
electronContainer
xAOD::ElectronContainer * electronContainer
Definition
TrigGlobEffCorrValidation.cxx:187
photonContainer
xAOD::PhotonContainer * photonContainer
Definition
TrigGlobEffCorrValidation.cxx:189
CaloCell
Data object for each calorimeter readout cell.
Definition
CaloCell.h:57
CaloClusterCellLink::const_iterator
const_iterator to loop over cells belonging to a cluster
Definition
CaloClusterCellLink.h:57
CaloClusterCellLink
Bookkeeping of cells that make up a cluster Simplified replacement for CaloCellLink,...
Definition
CaloClusterCellLink.h:24
CaloClusterCellLink::end
const_iterator end() const
const end method
Definition
CaloClusterCellLink.h:112
CaloClusterCellLink::begin
const_iterator begin() const
const begin method
Definition
CaloClusterCellLink.h:107
DerivationFramework::GainDecorator::m_SGKey_photons_decorations
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > m_SGKey_photons_decorations
Definition
GainDecorator.h:60
DerivationFramework::GainDecorator::m_SGKey_electrons
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_electrons
Definition
GainDecorator.h:47
DerivationFramework::GainDecorator::m_names_E
std::vector< std::pair< int, int > > m_names_E
Definition
GainDecorator.h:57
DerivationFramework::GainDecorator::getLayer
static int getLayer(const CaloCell *cell)
Definition
GainDecorator.cxx:183
DerivationFramework::GainDecorator::m_SGKey_photons
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_photons
Definition
GainDecorator.h:44
DerivationFramework::GainDecorator::initialize
virtual StatusCode initialize() override final
Definition
GainDecorator.cxx:18
DerivationFramework::GainDecorator::m_gainNames
Gaudi::Property< std::map< int, std::string > > m_gainNames
Definition
GainDecorator.h:50
DerivationFramework::GainDecorator::m_SGKey_electrons_decorations
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > m_SGKey_electrons_decorations
Definition
GainDecorator.h:68
DerivationFramework::GainDecorator::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition
GainDecorator.cxx:51
DerivationFramework::GainDecorator::m_layers
Gaudi::Property< std::vector< unsigned int > > m_layers
Definition
GainDecorator.h:54
DerivationFramework::GainDecorator::decorateObject
calculation decorateObject(const xAOD::Egamma *&egamma) const
Definition
GainDecorator.cxx:145
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
egamma
elec/gamma data class.
Definition
egamma.h:59
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition
PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::AllowEmpty
@ AllowEmpty
Definition
StoreGate/StoreGate/VarHandleKey.h:27
xAOD::Egamma
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition
Egamma.h:17
xAOD::EgammaContainer
EgammaContainer_v1 EgammaContainer
Definition of the current "egamma container version".
Definition
EgammaContainer.h:17
DerivationFramework::GainDecorator::calculation
Definition
GainDecorator.h:37
Generated on
for ATLAS Offline Software by
1.17.0