ATLAS Offline Software
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
26 {
27  ATH_MSG_VERBOSE("initialize() ...");
28 
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  }
43  ATH_CHECK(m_SGKey_electrons_decorations.initialize(!m_SGKey_electrons.key().empty()));
44 
45  return StatusCode::SUCCESS;
46 
47 }
48 
51 {
52 
53  if (!m_SGKey_photons.key().empty()) {
54 
55  // Decorate photons
56  ATH_CHECK(
58  m_SGKey_photons,
59  m_SGKey_photons_decorations,
60  ctx
61  )
62  );
63 
64  }
65 
66  if (!m_SGKey_electrons.key().empty()) {
67 
68  // Decorate electrons
69  ATH_CHECK(
71  m_SGKey_electrons,
72  m_SGKey_electrons_decorations,
73  ctx
74  )
75  );
76 
77  }
78 
79  return StatusCode::SUCCESS;
80 }
81 
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 }
DerivationFramework::CaloCellDecorator::cell_decorations::cells_phi
std::vector< float > cells_phi
Definition: CaloCellDecorator.h:49
DerivationFramework::CaloCellDecorator::cell_decorations::cells_y
std::vector< float > cells_y
Definition: CaloCellDecorator.h:51
constants.EMB1
int EMB1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:53
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
DerivationFramework::CaloCellDecorator::initialize
virtual StatusCode initialize() override final
Definition: CaloCellDecorator.cxx:25
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
egammaContainer
Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Current egammaContainer
Definition: egammaEventTPCnv.cxx:93
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
DerivationFramework::CaloCellDecorator::m_SGKey_photons
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_photons
Definition: CaloCellDecorator.h:74
DerivationFramework::CaloCellDecorator::~CaloCellDecorator
~CaloCellDecorator()
DerivationFramework::CaloCellDecorator::m_SGKey_electrons
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_electrons
Definition: CaloCellDecorator.h:93
SG::HandleKeyArray
Definition: StoreGate/StoreGate/HandleKeyArray.h:45
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
DerivationFramework::CaloCellDecorator::cell_decorations::cells_eta
std::vector< float > cells_eta
Definition: CaloCellDecorator.h:48
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
DerivationFramework::CaloCellDecorator::decorateCells
StatusCode decorateCells(const SG::ReadHandleKey< xAOD::EgammaContainer > &contKey, const SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > &decorKeys, const EventContext &ctx) const
Definition: CaloCellDecorator.cxx:83
CaloCell_ID.h
egamma
Definition: egamma.h:58
DerivationFramework::CaloCellDecorator::cell_decorations::ncells
int ncells
Definition: CaloCellDecorator.h:59
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:283
DerivationFramework::CaloCellDecorator::cell_decorations::cells_E
std::vector< float > cells_E
Definition: CaloCellDecorator.h:46
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DerivationFramework::CaloCellDecorator::cell_decorations::cells_onlId
std::vector< uint64_t > cells_onlId
Definition: CaloCellDecorator.h:56
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
DerivationFramework::CaloCellDecorator::cell_decorations::cells_time
std::vector< float > cells_time
Definition: CaloCellDecorator.h:47
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:11
DerivationFramework::CaloCellDecorator::m_SGKey_photons_decorations
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > m_SGKey_photons_decorations
Definition: CaloCellDecorator.h:82
constants.EME1
int EME1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:55
egammaContainer
Definition: egammaContainer.h:41
DerivationFramework::CaloCellDecorator::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition: CaloCellDecorator.cxx:50
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
xAOD::CaloCluster_v1::getCellLinks
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
Definition: CaloCluster_v1.cxx:829
DerivationFramework::CaloCellDecorator::cell_decorations::cells_quality
std::vector< int > cells_quality
Definition: CaloCellDecorator.h:55
DerivationFramework::CaloCellDecorator::cell_decorations::cells_layer
std::vector< int > cells_layer
Definition: CaloCellDecorator.h:54
CaloCell_ID_FCS::EME3
@ EME3
Definition: FastCaloSim_CaloCell_ID.h:26
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
DerivationFramework::CaloCellDecorator::cell_decorations::cells_gain
std::vector< int > cells_gain
Definition: CaloCellDecorator.h:53
CaloClusterStoreHelper.h
CaloCellDecorator.h
DerivationFramework::CaloCellDecorator::cell_decorations
Definition: CaloCellDecorator.h:43
DerivationFramework::CaloCellDecorator::cell_decorations::cells_z
std::vector< float > cells_z
Definition: CaloCellDecorator.h:52
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloCell_ID_FCS::PreSamplerE
@ PreSamplerE
Definition: FastCaloSim_CaloCell_ID.h:23
CaloCell_ID_FCS::PreSamplerB
@ PreSamplerB
Definition: FastCaloSim_CaloCell_ID.h:19
DerivationFramework::CaloCellDecorator::cell_decorations::cells_x
std::vector< float > cells_x
Definition: CaloCellDecorator.h:50
DerivationFramework::CaloCellDecorator::m_SGKey_electrons_decorations
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > m_SGKey_electrons_decorations
Definition: CaloCellDecorator.h:101
DerivationFramework::CaloCellDecorator::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: CaloCellDecorator.h:66
DerivationFramework::CaloCellDecorator::getDecorations
cell_decorations getDecorations(const xAOD::CaloCluster *cluster, const EventContext &ctx) const
Definition: CaloCellDecorator.cxx:145
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:27
CaloCell_ID_FCS::EMB3
@ EMB3
Definition: FastCaloSim_CaloCell_ID.h:22
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20