ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCellDecorator.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/*
6 * @file DerivationFrameworkCalo/src/CaloCellDecorator.cxx
7 * @author Gabriel P. Matos <gpinheir@cern.ch>, adapted from MaxCellDecorator by Nikiforos K. Nikiforou and others.
8 * @date Aug, 2025
9 * @brief Adds cell-level features as decorations to e/gamma objects.
10 */
11
15
16#include <string>
17#include <vector>
18
19
20// Destructor
22
23// Athena initialize
24StatusCode
26{
27 ATH_MSG_VERBOSE("initialize() ...");
28
29 ATH_CHECK(m_cablingKey.initialize());
30
31 // Setup for photons
33 if (!m_SGKey_photons.key().empty()) {
34 ATH_MSG_INFO("Using " << m_SGKey_photons.key() << " for photons");
35 }
36 ATH_CHECK(m_SGKey_photons_decorations.initialize(!m_SGKey_photons.key().empty()));
37
38 // Setup for electrons
40 if (!m_SGKey_electrons.key().empty()) {
41 ATH_MSG_INFO("Using " << m_SGKey_electrons.key() << " for electrons");
42 }
44
45 return StatusCode::SUCCESS;
46
47}
48
49StatusCode
51{
52
53 if (!m_SGKey_photons.key().empty()) {
54
55 // Decorate photons
60 ctx
61 )
62 );
63
64 }
65
66 if (!m_SGKey_electrons.key().empty()) {
67
68 // Decorate electrons
73 ctx
74 )
75 );
76
77 }
78
79 return StatusCode::SUCCESS;
80}
81
82StatusCode
86 const EventContext& ctx) const
87{
88
89 // Retrieve container
91
92 // Setup decorators
94 decoration0(decorKeys[0], ctx);
96 decoration1(decorKeys[1], ctx);
98 decoration2(decorKeys[2], ctx);
100 decoration3(decorKeys[3], ctx);
102 decoration4(decorKeys[4], ctx);
104 decoration5(decorKeys[5], ctx);
106 decoration6(decorKeys[6], ctx);
108 decoration7(decorKeys[7], ctx);
110 decoration8(decorKeys[8], ctx);
112 decoration9(decorKeys[9], ctx);
114 decoration10(decorKeys[10], ctx);
116 decoration11(decorKeys[11], ctx);
117
118 // Loop through egamma objects and decorate
119 const xAOD::EgammaContainer* importedEgamma = egammaContainer.ptr();
120 for (const auto* egamma : *importedEgamma) {
121 const xAOD::CaloCluster *cluster = egamma->caloCluster();
123 getDecorations(cluster, ctx);
124
125 // Decorate
126 decoration0(*egamma) = res.cells_E;
127 decoration1(*egamma) = res.cells_time;
128 decoration2(*egamma) = res.cells_eta;
129 decoration3(*egamma) = res.cells_phi;
130 decoration4(*egamma) = res.cells_x;
131 decoration5(*egamma) = res.cells_y;
132 decoration6(*egamma) = res.cells_z;
133 decoration7(*egamma) = res.cells_gain;
134 decoration8(*egamma) = res.cells_layer;
135 decoration9(*egamma) = res.cells_quality;
136 decoration10(*egamma) = res.cells_onlId;
137 decoration11(*egamma) = res.ncells;
138 }
139
140 return StatusCode::SUCCESS;
141
142};
143
146 const xAOD::CaloCluster* cluster,
147 const EventContext& ctx) const
148{
149
151
152 if (cluster) {
153 if (!cluster->getCellLinks()) {
154 ATH_MSG_WARNING("CellLinks not found");
155 return decorations;
156 }
157
158 const LArOnOffIdMapping* cabling{nullptr};
159 if (!SG::get(cabling, m_cablingKey, ctx).isSuccess()){
160 ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
161 throw std::runtime_error("Cabling retrieval failed");
162 }
163
164 for (const CaloCell* cell : *cluster) {
165
166 int sampling = cell->caloDDE()->getSampling();
167
168 // Keep track of total number of cells
169 decorations.ncells++;
170
171 // Fill with layer information
172 if (sampling == CaloCell_ID::PreSamplerB || sampling == CaloCell_ID::PreSamplerE){
173 decorations.cells_layer.push_back(0);
174 }
175
176 else if (sampling == CaloCell_ID::EMB1 || sampling == CaloCell_ID::EME1){
177 decorations.cells_layer.push_back(1);
178 }
179
180 else if (sampling == CaloCell_ID::EMB2 || sampling == CaloCell_ID::EME2){
181 decorations.cells_layer.push_back(2);
182 }
183
184 else if (sampling == CaloCell_ID::EMB3 || sampling == CaloCell_ID::EME3){
185 decorations.cells_layer.push_back(3);
186 }
187
188 else {
189 // Don't do anything with Tile cells aside from tabulating
190 continue;
191 }
192
193 // Fill vectors with cell features
194 decorations.cells_E.push_back(cell->e());
195 decorations.cells_time.push_back(cell->time());
196 decorations.cells_eta.push_back(cell->eta());
197 decorations.cells_phi.push_back(cell->phi());
198 decorations.cells_x.push_back(cell->x());
199 decorations.cells_y.push_back(cell->y());
200 decorations.cells_z.push_back(cell->z());
201 decorations.cells_gain.push_back((int)cell->gain());
202 decorations.cells_quality.push_back(cell->quality());
203
204 // Keep online ID to debug
205 decorations.cells_onlId.push_back(
206 (uint64_t)(cabling->createSignalChannelID(cell->caloDDE()->identify()))
207 .get_compact()
208 );
209 }
210 }
211
212 return decorations;
213}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::pair< std::vector< unsigned int >, bool > res
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_photons
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > m_SGKey_photons_decorations
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > m_SGKey_electrons_decorations
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_electrons
StatusCode decorateCells(const SG::ReadHandleKey< xAOD::EgammaContainer > &contKey, const SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > &decorKeys, const EventContext &ctx) const
virtual StatusCode addBranches(const EventContext &ctx) const override final
virtual StatusCode initialize() override final
cell_decorations getDecorations(const xAOD::CaloCluster *cluster, const EventContext &ctx) const
Property holding a SG store/key/clid from which a ReadHandle is made.
Handle class for adding a decoration to an object.
This is a data object, containing a collection of egamma Objects.
elec/gamma data class.
Definition egamma.h:58
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Current egammaContainer
DecorHandleKeyArray< WriteDecorHandle< T, S >, WriteDecorHandleKey< T >, Gaudi::DataHandle::Writer > WriteDecorHandleKeyArray
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
EgammaContainer_v1 EgammaContainer
Definition of the current "egamma container version".