ATLAS Offline Software
MaxCellDecorator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // MaxCellDecorator.cxx, (c) ATLAS Detector software
8 
12 
13 #include <string>
14 #include <vector>
15 namespace {}
16 
17 // Constructor
19  const std::string& n,
20  const IInterface* p)
21  : base_class(t, n, p)
22 {
23 }
24 
25 // Destructor
27 
28 // Athena initialize and finalize
31 {
32  ATH_MSG_VERBOSE("initialize() ...");
33 
34  ATH_CHECK(m_cablingKey.initialize());
35 
36  if (!m_SGKey_electrons.key().empty()) {
37  const std::string key = m_SGKey_electrons.key();
38  ATH_MSG_INFO("Using " << key << " for electrons");
39  ATH_CHECK(m_SGKey_electrons.initialize());
40 
41  // setup vector of decorators
42  m_SGKey_electrons_decorations.emplace_back(key + ".maxEcell_time");
43  m_SGKey_electrons_decorations.emplace_back(key + ".maxEcell_energy");
44  m_SGKey_electrons_decorations.emplace_back(key + ".maxEcell_gain");
45  m_SGKey_electrons_decorations.emplace_back(key + ".maxEcell_onlId");
46  m_SGKey_electrons_decorations.emplace_back(key + ".maxEcell_x");
47  m_SGKey_electrons_decorations.emplace_back(key + ".maxEcell_y");
48  m_SGKey_electrons_decorations.emplace_back(key + ".maxEcell_z");
49 
50  if (!m_SGKey_egammaClusters.key().empty()) {
51  ATH_MSG_INFO("Using " << m_SGKey_egammaClusters.key() << " to try to match a cluster to the LRT egamma cluster");
52  ATH_CHECK(m_SGKey_egammaClusters.initialize());
53  m_SGKey_electrons_decorations.emplace_back(key + ".dR");
54  }
55 
56  ATH_CHECK(m_SGKey_electrons_decorations.initialize());
57  }
58 
59  if (!m_SGKey_photons.key().empty()) {
60  const std::string key = m_SGKey_photons.key();
61  ATH_MSG_INFO("Using " << key << " for photons");
62  ATH_CHECK(m_SGKey_photons.initialize());
63 
64  // setup vector of decorators
65  m_SGKey_photons_decorations.emplace_back(key + ".maxEcell_time");
66  m_SGKey_photons_decorations.emplace_back(key + ".maxEcell_energy");
67  m_SGKey_photons_decorations.emplace_back(key + ".maxEcell_gain");
68  m_SGKey_photons_decorations.emplace_back(key + ".maxEcell_onlId");
69  m_SGKey_photons_decorations.emplace_back(key + ".maxEcell_x");
70  m_SGKey_photons_decorations.emplace_back(key + ".maxEcell_y");
71  m_SGKey_photons_decorations.emplace_back(key + ".maxEcell_z");
72  ATH_CHECK(m_SGKey_photons_decorations.initialize());
73  }
74 
75  if (!m_SGKey_taus.key().empty()) {
76  const std::string key = m_SGKey_taus.key();
77  ATH_MSG_INFO("Using " << key << " for taus");
78  ATH_CHECK(m_SGKey_taus.initialize());
79 
80  // setup vector of decorators
81  m_SGKey_taus_decorations.emplace_back(key + ".maxEcell_time");
82  m_SGKey_taus_decorations.emplace_back(key + ".maxEcell_energy");
83  m_SGKey_taus_decorations.emplace_back(key + ".maxEcell_gain");
84  m_SGKey_taus_decorations.emplace_back(key + ".maxEcell_onlId");
85  m_SGKey_taus_decorations.emplace_back(key + ".maxEcell_x");
86  m_SGKey_taus_decorations.emplace_back(key + ".maxEcell_y");
87  m_SGKey_taus_decorations.emplace_back(key + ".maxEcell_z");
88  ATH_CHECK(m_SGKey_taus_decorations.initialize());
89  }
90 
91  if (!m_SGKey_jets.key().empty()) {
92  const std::string key = m_SGKey_jets.key();
93  ATH_MSG_INFO("Using " << key << " for jets");
94  ATH_CHECK(m_SGKey_jets.initialize());
95 
96  // setup vector of decorators
97  m_SGKey_jets_decorations.emplace_back(key + ".maxEcell_time");
98  m_SGKey_jets_decorations.emplace_back(key + ".maxEcell_energy");
99  m_SGKey_jets_decorations.emplace_back(key + ".maxEcell_gain");
100  m_SGKey_jets_decorations.emplace_back(key + ".maxEcell_onlId");
101  m_SGKey_jets_decorations.emplace_back(key + ".maxEcell_x");
102  m_SGKey_jets_decorations.emplace_back(key + ".maxEcell_y");
103  m_SGKey_jets_decorations.emplace_back(key + ".maxEcell_z");
104  ATH_CHECK(m_SGKey_jets_decorations.initialize());
105  }
106 
107  return StatusCode::SUCCESS;
108 }
109 
112 {
113  return StatusCode::SUCCESS;
114 }
115 
116 // The decoration itself
119 {
120  const EventContext& ctx = Gaudi::Hive::currentContext();
121 
122  if (!m_SGKey_photons.key().empty()) {
123  // Retrieve photon container
125  // setup vector of decorators
127  m_SGKey_photons_decorations[0], ctx);
129  m_SGKey_photons_decorations[1], ctx);
131  m_SGKey_photons_decorations[2], ctx);
133  m_SGKey_photons_decorations[3], ctx);
135  m_SGKey_photons_decorations[4], ctx);
137  m_SGKey_photons_decorations[5], ctx);
139  m_SGKey_photons_decorations[6], ctx);
140 
141  const xAOD::EgammaContainer* importedPhotons = photonContainer.ptr();
142  for (const auto* egamma : *importedPhotons) {
143  const xAOD::CaloCluster *cluster = egamma->caloCluster();
145  decorateObject(cluster, ctx);
146  decorationPh0(*egamma) = res.maxEcell_time;
147  decorationPh1(*egamma) = res.maxEcell_energy;
148  decorationPh2(*egamma) = res.maxEcell_gain;
149  decorationPh3(*egamma) = res.maxEcell_onlId;
150  decorationPh4(*egamma) = res.maxEcell_x;
151  decorationPh5(*egamma) = res.maxEcell_y;
152  decorationPh6(*egamma) = res.maxEcell_z;
153  }
154  }
155 
156  if (!m_SGKey_electrons.key().empty()) {
157  // Retrieve electron container
159  ctx);
160 
161  //
162  std::optional<SG::WriteDecorHandle<xAOD::EgammaContainer, float>> odecorationEl7;
163  const xAOD::CaloClusterContainer* egClContainer(nullptr);
164  if (!m_SGKey_egammaClusters.key().empty()) {
166  m_SGKey_egammaClusters, ctx);
167  egClContainer = egClContainerRH.ptr();
168  odecorationEl7.emplace(m_SGKey_electrons_decorations[7], ctx);
169  }
170 
171  // setup vector of decorators
173  m_SGKey_electrons_decorations[0], ctx);
175  m_SGKey_electrons_decorations[1], ctx);
177  m_SGKey_electrons_decorations[2], ctx);
179  m_SGKey_electrons_decorations[3], ctx);
181  m_SGKey_electrons_decorations[4], ctx);
183  m_SGKey_electrons_decorations[5], ctx);
185  m_SGKey_electrons_decorations[6], ctx);
186 
187  const xAOD::EgammaContainer* importedElectrons = electronContainer.ptr();
188  for (const auto* egamma : *importedElectrons) {
189  const xAOD::CaloCluster *cluster = egamma->caloCluster();
190  if (!m_SGKey_egammaClusters.key().empty()) {
191  double dRMin = 9e9;
192  const xAOD::CaloCluster *matchedCluster(nullptr);
193  for (const auto *clus : *egClContainer) {
194  double dR = clus->p4().DeltaR(cluster->p4());
195  if (dR < dRMin && dR < m_dRLRTegClusegClusMax) {
196  dRMin = dR;
197  matchedCluster = clus;
198  }
199  }
200  cluster = matchedCluster;
201  odecorationEl7.value()(*egamma) = dRMin;
202  }
204  decorateObject(cluster, ctx);
205  decorationEl0(*egamma) = res.maxEcell_time;
206  decorationEl1(*egamma) = res.maxEcell_energy;
207  decorationEl2(*egamma) = res.maxEcell_gain;
208  decorationEl3(*egamma) = res.maxEcell_onlId;
209  decorationEl4(*egamma) = res.maxEcell_x;
210  decorationEl5(*egamma) = res.maxEcell_y;
211  decorationEl6(*egamma) = res.maxEcell_z;
212  }
213  }
214 
215  if (!m_SGKey_taus.key().empty()) {
216  // Retrieve tau container
217  SG::ReadHandle<xAOD::TauJetContainer> tauJetContainer(m_SGKey_taus, ctx);
218  // setup vector of decorators
220  m_SGKey_taus_decorations[0], ctx);
222  m_SGKey_taus_decorations[1], ctx);
224  m_SGKey_taus_decorations[2], ctx);
226  m_SGKey_taus_decorations[3], ctx);
228  m_SGKey_taus_decorations[4], ctx);
230  m_SGKey_taus_decorations[5], ctx);
232  m_SGKey_taus_decorations[6], ctx);
233 
234  const xAOD::TauJetContainer* importedTaus = tauJetContainer.ptr();
235  for (const auto* tau : *importedTaus) {
237  res.maxEcell_energy = -9999.;
238  for (size_t i = 0;i<tau->nClusters();++i) {
239  // get particle
240  const xAOD::IParticle* part = tau->cluster(i);
241  if ( not part ) {
242  ATH_MSG_WARNING("Tau particle link invalid");
243  continue;
244  }
245 
246  const xAOD::CaloCluster* cluster=dynamic_cast<const xAOD::CaloCluster*> (part);
247  if ( not cluster ) {
248  ATH_MSG_WARNING("Tau cluster link invalid");
249  continue;
250  }
251 
253  decorateObject(cluster, ctx);
254  if (resCand.maxEcell_energy > res.maxEcell_energy) {
255  res = resCand;
256  }
257  }
258 
259  decorationTau0(*tau) = res.maxEcell_time;
260  decorationTau1(*tau) = res.maxEcell_energy;
261  decorationTau2(*tau) = res.maxEcell_gain;
262  decorationTau3(*tau) = res.maxEcell_onlId;
263  decorationTau4(*tau) = res.maxEcell_x;
264  decorationTau5(*tau) = res.maxEcell_y;
265  decorationTau6(*tau) = res.maxEcell_z;
266  }
267  }
268 
269  if (!m_SGKey_jets.key().empty()) {
270  // Retrieve jet container
271  SG::ReadHandle<xAOD::JetContainer> jetContainer(m_SGKey_jets, ctx);
272  // setup vector of decorators
274  m_SGKey_jets_decorations[0], ctx);
276  m_SGKey_jets_decorations[1], ctx);
278  m_SGKey_jets_decorations[2], ctx);
280  m_SGKey_jets_decorations[3], ctx);
282  m_SGKey_jets_decorations[4], ctx);
284  m_SGKey_jets_decorations[5], ctx);
286  m_SGKey_jets_decorations[6], ctx);
287 
288  const xAOD::JetContainer* importedJets = jetContainer.ptr();
289  for (const auto* jet : *importedJets) {
290  if (jet->numConstituents() == 0) continue;
291 
293  res.maxEcell_energy = -9999.;
294  std::vector<const xAOD::CaloCluster*> clusterList;
295  clusterList.clear();
296 
297  xAOD::Type::ObjectType ctype = jet->rawConstituent( 0 )->type();
298 
299  if (ctype == xAOD::Type::FlowElement) {
300  // Particle Flow jets
301  for (size_t i=0;i<jet->numConstituents();++i) {
302  if(jet->rawConstituent(i)->type() != xAOD::Type::FlowElement) {
303  ATH_MSG_WARNING("Tried to call fillEperSamplingFE with a jet constituent that is not a FlowElement!");
304  continue;
305  }
306 
307  const xAOD::FlowElement* constit = static_cast<const xAOD::FlowElement*>(jet->rawConstituent(i));
308  if (constit) {
309  const SG::AuxElement::ConstAccessor< ElementLink<xAOD::IParticleContainer> > originalObject("originalObjectLink");
310  auto originalFE = dynamic_cast<const xAOD::FlowElement*>(*originalObject(*constit));
311  if(originalFE && !originalFE->isCharged()){
312  const xAOD::CaloCluster* cluster = dynamic_cast<const xAOD::CaloCluster*>(originalFE->otherObject(0));
313  if (cluster) {
314  clusterList.push_back(cluster);
315  }
316  }
317  }
318  }
319  } else if (ctype == xAOD::Type::CaloCluster) {
320  // Topo jets
321  for (size_t i=0;i<jet->numConstituents();++i) {
322  if(jet->rawConstituent(i)->type() != xAOD::Type::CaloCluster) {
323  ATH_MSG_WARNING("Tried to call fillEperSamplingCluster with a jet constituent that is not a cluster!");
324  continue;
325  }
326 
327  const xAOD::CaloCluster* cluster = static_cast<const xAOD::CaloCluster*>(jet->rawConstituent(i));
328  if (cluster) {
329  clusterList.push_back(cluster);
330  }
331  }
332  } else {
333  // PFlow (old)
334  for (size_t i=0;i<jet->numConstituents();++i) {
335  if(jet->rawConstituent(i)->type() != xAOD::Type::ParticleFlow) {
336  continue;
337  }
338  const xAOD::PFO* iPFO = static_cast<const xAOD::PFO*>(jet->rawConstituent(i));
339  if ( iPFO ) {
340  for (unsigned int cidx=0;cidx<iPFO->nCaloCluster();++cidx) {
341  if ( iPFO->cluster(cidx) ) {
342  clusterList.push_back(iPFO->cluster(cidx));
343  }
344  }
345  }
346  }
347  }
348 
349  for (auto cluster : clusterList) {
351  decorateObject(cluster, ctx);
352  if (resCand.maxEcell_energy > res.maxEcell_energy) {
353  res = resCand;
354  }
355  }
356 
357  decorationJet0(*jet) = res.maxEcell_time;
358  decorationJet1(*jet) = res.maxEcell_energy;
359  decorationJet2(*jet) = res.maxEcell_gain;
360  decorationJet3(*jet) = res.maxEcell_onlId;
361  decorationJet4(*jet) = res.maxEcell_x;
362  decorationJet5(*jet) = res.maxEcell_y;
363  decorationJet6(*jet) = res.maxEcell_z;
364  }
365  }
366 
367  return StatusCode::SUCCESS;
368 }
369 
372  const xAOD::CaloCluster* cluster,
373  const EventContext& ctx) const
374 {
375 
377 
378  if (cluster) {
379  if (!cluster->getCellLinks()) {
380  ATH_MSG_DEBUG("CellLinks not found");
381  return result;
382  }
383 
384  SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{ m_cablingKey, ctx };
385  const LArOnOffIdMapping* cabling{ *cablingHdl };
386  if (!cabling) {
387  ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
388  return result;
389  }
390 
391  float emax = -9999.;
392 
393  const CaloCell* cell_maxE = nullptr;
394  for (const CaloCell* cell : *cluster) {
395  int sampling = cell->caloDDE()->getSampling();
396  if (sampling == CaloCell_ID::EMB2 || sampling == CaloCell_ID::EME2) {
397  if ((cell->provenance() & 0x2000)) {
398  if (cell->energy() > emax) {
399  emax = cell->energy();
400  cell_maxE = cell;
401  }
402  }
403  }
404  }
405 
406  if (cell_maxE) {
407  const CaloDetDescrElement* caloDDEl = cell_maxE->caloDDE();
408  result.maxEcell_time = cell_maxE->time();
409  result.maxEcell_energy = cell_maxE->energy();
410  result.maxEcell_gain = (int)cell_maxE->gain();
411  result.maxEcell_onlId =
412  (uint64_t)(cabling->createSignalChannelID(caloDDEl->identify()))
413  .get_compact();
414  result.maxEcell_x = caloDDEl->x();
415  result.maxEcell_y = caloDDEl->y();
416  result.maxEcell_z = caloDDEl->z();
417  }
418  }
419  return result;
420 }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
DerivationFramework::MaxCellDecorator::initialize
StatusCode initialize()
Definition: MaxCellDecorator.cxx:30
electronContainer
xAOD::ElectronContainer * electronContainer
Definition: TrigGlobEffCorrValidation.cxx:187
get_generator_info.result
result
Definition: get_generator_info.py:21
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloDetDescrElement::y
float y() const
cell y
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:365
ObjectType
ObjectType
Definition: BaseObject.h:11
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
DerivationFramework::MaxCellDecorator::calculation::maxEcell_energy
float maxEcell_energy
Definition: MaxCellDecorator.h:46
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
DerivationFramework::MaxCellDecorator::~MaxCellDecorator
~MaxCellDecorator()
CaloCell::time
float time() const
get time (data member)
Definition: CaloCell.h:362
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
CaloCell_ID.h
egamma
Definition: egamma.h:58
CaloCell::energy
double energy() const
get energy (data member)
Definition: CaloCell.h:321
DerivationFramework::MaxCellDecorator::MaxCellDecorator
MaxCellDecorator(const std::string &t, const std::string &n, const IInterface *p)
Definition: MaxCellDecorator.cxx:18
DerivationFramework::MaxCellDecorator::calculation
Definition: MaxCellDecorator.h:44
CaloDetDescrElement::identify
Identifier identify() const override final
cell identifier
Definition: CaloDetDescrElement.cxx:63
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::PFO_v1::nCaloCluster
unsigned int nCaloCluster() const
Find out how many CaloCluster are linked.
Definition: PFO_v1.cxx:659
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:729
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
DerivationFramework::MaxCellDecorator::finalize
StatusCode finalize()
Definition: MaxCellDecorator.cxx:111
xAOD::FlowElement
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition: FlowElement.h:16
CaloCell::caloDDE
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition: CaloCell.h:315
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:11
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAODType::ParticleFlow
@ ParticleFlow
The object is a particle-flow object.
Definition: ObjectType.h:41
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
DerivationFramework::MaxCellDecorator::addBranches
virtual StatusCode addBranches() const
Definition: MaxCellDecorator.cxx:118
xAOD::CaloCluster_v1::getCellLinks
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
Definition: CaloCluster_v1.cxx:859
photonContainer
xAOD::PhotonContainer * photonContainer
Definition: TrigGlobEffCorrValidation.cxx:189
xAOD::CaloCluster_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: CaloCluster_v1.cxx:465
xAOD::PFO_v1
Class describing a particle flow object.
Definition: PFO_v1.h:35
CaloCell::gain
CaloGain::CaloGain gain() const
get gain (data member )
Definition: CaloCell.h:355
CaloDetDescrElement::x
float x() const
cell x
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:363
CaloClusterStoreHelper.h
SG::ReadHandle::ptr
const_pointer_type ptr()
Dereference the pointer.
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloDetDescrElement::z
float z() const
cell z
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:367
MaxCellDecorator.h
DerivationFramework::MaxCellDecorator::decorateObject
calculation decorateObject(const xAOD::CaloCluster *cluster, const EventContext &ctx) const
Definition: MaxCellDecorator.cxx:371
xAOD::PFO_v1::cluster
const CaloCluster * cluster(unsigned int index) const
Retrieve a const pointer to a CaloCluster.
Definition: PFO_v1.cxx:669
DataVector::emplace
iterator emplace(iterator position, value_type pElem)
Add a new element to the collection.
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
xAOD::FlowElement_v1
A detector object made of other lower level object(s)
Definition: FlowElement_v1.h:25
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37