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 
13 // CaloCellDecorator.cxx, (c) ATLAS Detector software
15 
19 
20 #include <string>
21 #include <vector>
22 
23 
24 // Destructor
26 
27 // Athena initialize
30 {
31  ATH_MSG_VERBOSE("initialize() ...");
32 
34 
35  // Setup for photons
36  if (!m_SGKey_photons.key().empty()) {
37  const std::string key = m_SGKey_photons.key();
38  ATH_MSG_INFO("Using " << key << " for photons");
39  ATH_CHECK(m_SGKey_photons.initialize());
40 
41  m_SGKey_photons_decorations.emplace_back(key + ".cells_E");
42  m_SGKey_photons_decorations.emplace_back(key + ".cells_time");
43  m_SGKey_photons_decorations.emplace_back(key + ".cells_eta");
44  m_SGKey_photons_decorations.emplace_back(key + ".cells_phi");
45  m_SGKey_photons_decorations.emplace_back(key + ".cells_x");
46  m_SGKey_photons_decorations.emplace_back(key + ".cells_y");
47  m_SGKey_photons_decorations.emplace_back(key + ".cells_z");
48  m_SGKey_photons_decorations.emplace_back(key + ".cells_gain");
49  m_SGKey_photons_decorations.emplace_back(key + ".cells_layer");
50  m_SGKey_photons_decorations.emplace_back(key + ".cells_quality");
51  m_SGKey_photons_decorations.emplace_back(key + ".cells_onlId");
52  m_SGKey_photons_decorations.emplace_back(key + ".ncells");
53 
55  }
56 
57  // Setup for electrons
58  if (!m_SGKey_electrons.key().empty()) {
59  const std::string key = m_SGKey_electrons.key();
60  ATH_MSG_INFO("Using " << key << " for electrons");
61  ATH_CHECK(m_SGKey_electrons.initialize());
62 
63  m_SGKey_electrons_decorations.emplace_back(key + ".cells_E");
64  m_SGKey_electrons_decorations.emplace_back(key + ".cells_time");
65  m_SGKey_electrons_decorations.emplace_back(key + ".cells_eta");
66  m_SGKey_electrons_decorations.emplace_back(key + ".cells_phi");
67  m_SGKey_electrons_decorations.emplace_back(key + ".cells_x");
68  m_SGKey_electrons_decorations.emplace_back(key + ".cells_y");
69  m_SGKey_electrons_decorations.emplace_back(key + ".cells_z");
70  m_SGKey_electrons_decorations.emplace_back(key + ".cells_gain");
71  m_SGKey_electrons_decorations.emplace_back(key + ".cells_layer");
72  m_SGKey_electrons_decorations.emplace_back(key + ".cells_quality");
73  m_SGKey_electrons_decorations.emplace_back(key + ".cells_onlId");
74  m_SGKey_electrons_decorations.emplace_back(key + ".ncells");
75 
77 
78  }
79 
80  return StatusCode::SUCCESS;
81 
82 }
83 
86 {
87  const EventContext& ctx = Gaudi::Hive::currentContext();
88 
89  if (!m_SGKey_photons.key().empty()) {
90 
91  // Decorate photons
92  ATH_CHECK(
94  m_SGKey_photons,
95  m_SGKey_photons_decorations,
96  ctx
97  )
98  );
99 
100  }
101 
102  if (!m_SGKey_electrons.key().empty()) {
103 
104  // Decorate electrons
105  ATH_CHECK(
107  m_SGKey_electrons,
108  m_SGKey_electrons_decorations,
109  ctx
110  )
111  );
112 
113  }
114 
115  return StatusCode::SUCCESS;
116 }
117 
118 StatusCode
122  const EventContext& ctx) const
123 {
124 
125  // Retrieve container
127 
128  // Setup decorators
130  decoration0(decorKeys[0], ctx);
132  decoration1(decorKeys[1], ctx);
134  decoration2(decorKeys[2], ctx);
136  decoration3(decorKeys[3], ctx);
138  decoration4(decorKeys[4], ctx);
140  decoration5(decorKeys[5], ctx);
142  decoration6(decorKeys[6], ctx);
144  decoration7(decorKeys[7], ctx);
146  decoration8(decorKeys[8], ctx);
148  decoration9(decorKeys[9], ctx);
150  decoration10(decorKeys[10], ctx);
152  decoration11(decorKeys[11], ctx);
153 
154  // Loop through egamma objects and decorate
155  const xAOD::EgammaContainer* importedEgamma = egammaContainer.ptr();
156  for (const auto* egamma : *importedEgamma) {
157  const xAOD::CaloCluster *cluster = egamma->caloCluster();
159  getDecorations(cluster, ctx);
160 
161  // Decorate
162  decoration0(*egamma) = res.cells_E;
163  decoration1(*egamma) = res.cells_time;
164  decoration2(*egamma) = res.cells_eta;
165  decoration3(*egamma) = res.cells_phi;
166  decoration4(*egamma) = res.cells_x;
167  decoration5(*egamma) = res.cells_y;
168  decoration6(*egamma) = res.cells_z;
169  decoration7(*egamma) = res.cells_gain;
170  decoration8(*egamma) = res.cells_layer;
171  decoration9(*egamma) = res.cells_quality;
172  decoration10(*egamma) = res.cells_onlId;
173  decoration11(*egamma) = res.ncells;
174  }
175 
176  return StatusCode::SUCCESS;
177 
178 };
179 
182  const xAOD::CaloCluster* cluster,
183  const EventContext& ctx) const
184 {
185 
187 
188  if (cluster) {
189  if (!cluster->getCellLinks()) {
190  ATH_MSG_WARNING("CellLinks not found");
191  return decorations;
192  }
193 
194  const LArOnOffIdMapping* cabling{nullptr};
195  if (!SG::get(cabling, m_cablingKey, ctx).isSuccess()){
196  ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
197  throw std::runtime_error("Cabling retrieval failed");
198  }
199 
200  for (const CaloCell* cell : *cluster) {
201 
202  int sampling = cell->caloDDE()->getSampling();
203 
204  // Keep track of total number of cells
205  decorations.ncells++;
206 
207  // Fill with layer information
208  if (sampling == CaloCell_ID::PreSamplerB || sampling == CaloCell_ID::PreSamplerE){
209  decorations.cells_layer.push_back(0);
210  }
211 
212  else if (sampling == CaloCell_ID::EMB1 || sampling == CaloCell_ID::EME1){
213  decorations.cells_layer.push_back(1);
214  }
215 
216  else if (sampling == CaloCell_ID::EMB2 || sampling == CaloCell_ID::EME2){
217  decorations.cells_layer.push_back(2);
218  }
219 
220  else if (sampling == CaloCell_ID::EMB3 || sampling == CaloCell_ID::EME3){
221  decorations.cells_layer.push_back(3);
222  }
223 
224  else {
225  // Don't do anything with Tile cells aside from tabulating
226  continue;
227  }
228 
229  // Fill vectors with cell features
230  decorations.cells_E.push_back(cell->e());
231  decorations.cells_time.push_back(cell->time());
232  decorations.cells_eta.push_back(cell->eta());
233  decorations.cells_phi.push_back(cell->phi());
234  decorations.cells_x.push_back(cell->x());
235  decorations.cells_y.push_back(cell->y());
236  decorations.cells_z.push_back(cell->z());
237  decorations.cells_gain.push_back((int)cell->gain());
238  decorations.cells_quality.push_back(cell->quality());
239 
240  // Keep online ID to debug
241  decorations.cells_onlId.push_back(
242  (uint64_t)(cabling->createSignalChannelID(cell->caloDDE()->identify()))
243  .get_compact()
244  );
245  }
246  }
247 
248  return decorations;
249 }
DerivationFramework::CaloCellDecorator::cell_decorations::cells_phi
std::vector< float > cells_phi
Definition: CaloCellDecorator.h:53
DerivationFramework::CaloCellDecorator::cell_decorations::cells_y
std::vector< float > cells_y
Definition: CaloCellDecorator.h:55
constants.EMB1
int EMB1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:53
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
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:78
DerivationFramework::CaloCellDecorator::~CaloCellDecorator
~CaloCellDecorator()
DerivationFramework::CaloCellDecorator::m_SGKey_electrons
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_electrons
Definition: CaloCellDecorator.h:94
SG::HandleKeyArray
Definition: StoreGate/StoreGate/HandleKeyArray.h:38
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:52
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:119
CaloCell_ID.h
egamma
Definition: egamma.h:58
DerivationFramework::CaloCellDecorator::cell_decorations::ncells
int ncells
Definition: CaloCellDecorator.h:63
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
DerivationFramework::CaloCellDecorator::addBranches
virtual StatusCode addBranches() const
Definition: CaloCellDecorator.cxx:85
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:287
DerivationFramework::CaloCellDecorator::initialize
StatusCode initialize()
Definition: CaloCellDecorator.cxx:29
DerivationFramework::CaloCellDecorator::cell_decorations::cells_E
std::vector< float > cells_E
Definition: CaloCellDecorator.h:50
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:60
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:51
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:86
constants.EME1
int EME1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:55
egammaContainer
Definition: egammaContainer.h:41
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:794
xAOD::CaloCluster_v1::getCellLinks
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
Definition: CaloCluster_v1.cxx:859
DerivationFramework::CaloCellDecorator::cell_decorations::cells_quality
std::vector< int > cells_quality
Definition: CaloCellDecorator.h:59
DerivationFramework::CaloCellDecorator::cell_decorations::cells_layer
std::vector< int > cells_layer
Definition: CaloCellDecorator.h:58
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:57
CaloClusterStoreHelper.h
CaloCellDecorator.h
DerivationFramework::CaloCellDecorator::cell_decorations
Definition: CaloCellDecorator.h:47
DerivationFramework::CaloCellDecorator::cell_decorations::cells_z
std::vector< float > cells_z
Definition: CaloCellDecorator.h:56
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:54
DerivationFramework::CaloCellDecorator::m_SGKey_electrons_decorations
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > m_SGKey_electrons_decorations
Definition: CaloCellDecorator.h:102
DerivationFramework::CaloCellDecorator::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: CaloCellDecorator.h:70
DerivationFramework::CaloCellDecorator::getDecorations
cell_decorations getDecorations(const xAOD::CaloCluster *cluster, const EventContext &ctx) const
Definition: CaloCellDecorator.cxx:181
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
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37