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 
88  if (!m_SGKey_photons.key().empty()) {
89 
90  // Decorate photons
91  ATH_CHECK(
93  m_SGKey_photons,
94  m_SGKey_photons_decorations,
95  ctx
96  )
97  );
98 
99  }
100 
101  if (!m_SGKey_electrons.key().empty()) {
102 
103  // Decorate electrons
104  ATH_CHECK(
106  m_SGKey_electrons,
107  m_SGKey_electrons_decorations,
108  ctx
109  )
110  );
111 
112  }
113 
114  return StatusCode::SUCCESS;
115 }
116 
117 StatusCode
121  const EventContext& ctx) const
122 {
123 
124  // Retrieve container
126 
127  // Setup decorators
129  decoration0(decorKeys[0], ctx);
131  decoration1(decorKeys[1], ctx);
133  decoration2(decorKeys[2], ctx);
135  decoration3(decorKeys[3], ctx);
137  decoration4(decorKeys[4], ctx);
139  decoration5(decorKeys[5], ctx);
141  decoration6(decorKeys[6], ctx);
143  decoration7(decorKeys[7], ctx);
145  decoration8(decorKeys[8], ctx);
147  decoration9(decorKeys[9], ctx);
149  decoration10(decorKeys[10], ctx);
151  decoration11(decorKeys[11], ctx);
152 
153  // Loop through egamma objects and decorate
154  const xAOD::EgammaContainer* importedEgamma = egammaContainer.ptr();
155  for (const auto* egamma : *importedEgamma) {
156  const xAOD::CaloCluster *cluster = egamma->caloCluster();
158  getDecorations(cluster, ctx);
159 
160  // Decorate
161  decoration0(*egamma) = res.cells_E;
162  decoration1(*egamma) = res.cells_time;
163  decoration2(*egamma) = res.cells_eta;
164  decoration3(*egamma) = res.cells_phi;
165  decoration4(*egamma) = res.cells_x;
166  decoration5(*egamma) = res.cells_y;
167  decoration6(*egamma) = res.cells_z;
168  decoration7(*egamma) = res.cells_gain;
169  decoration8(*egamma) = res.cells_layer;
170  decoration9(*egamma) = res.cells_quality;
171  decoration10(*egamma) = res.cells_onlId;
172  decoration11(*egamma) = res.ncells;
173  }
174 
175  return StatusCode::SUCCESS;
176 
177 };
178 
181  const xAOD::CaloCluster* cluster,
182  const EventContext& ctx) const
183 {
184 
186 
187  if (cluster) {
188  if (!cluster->getCellLinks()) {
189  ATH_MSG_WARNING("CellLinks not found");
190  return decorations;
191  }
192 
193  const LArOnOffIdMapping* cabling{nullptr};
194  if (!SG::get(cabling, m_cablingKey, ctx).isSuccess()){
195  ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
196  throw std::runtime_error("Cabling retrieval failed");
197  }
198 
199  for (const CaloCell* cell : *cluster) {
200 
201  int sampling = cell->caloDDE()->getSampling();
202 
203  // Keep track of total number of cells
204  decorations.ncells++;
205 
206  // Fill with layer information
207  if (sampling == CaloCell_ID::PreSamplerB || sampling == CaloCell_ID::PreSamplerE){
208  decorations.cells_layer.push_back(0);
209  }
210 
211  else if (sampling == CaloCell_ID::EMB1 || sampling == CaloCell_ID::EME1){
212  decorations.cells_layer.push_back(1);
213  }
214 
215  else if (sampling == CaloCell_ID::EMB2 || sampling == CaloCell_ID::EME2){
216  decorations.cells_layer.push_back(2);
217  }
218 
219  else if (sampling == CaloCell_ID::EMB3 || sampling == CaloCell_ID::EME3){
220  decorations.cells_layer.push_back(3);
221  }
222 
223  else {
224  // Don't do anything with Tile cells aside from tabulating
225  continue;
226  }
227 
228  // Fill vectors with cell features
229  decorations.cells_E.push_back(cell->e());
230  decorations.cells_time.push_back(cell->time());
231  decorations.cells_eta.push_back(cell->eta());
232  decorations.cells_phi.push_back(cell->phi());
233  decorations.cells_x.push_back(cell->x());
234  decorations.cells_y.push_back(cell->y());
235  decorations.cells_z.push_back(cell->z());
236  decorations.cells_gain.push_back((int)cell->gain());
237  decorations.cells_quality.push_back(cell->quality());
238 
239  // Keep online ID to debug
240  decorations.cells_onlId.push_back(
241  (uint64_t)(cabling->createSignalChannelID(cell->caloDDE()->identify()))
242  .get_compact()
243  );
244  }
245  }
246 
247  return decorations;
248 }
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
DerivationFramework::CaloCellDecorator::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const
Definition: CaloCellDecorator.cxx:85
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: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: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:118
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
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: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: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:180
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