ATLAS Offline Software
Loading...
Searching...
No Matches
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
8
9#include <string>
10#include <vector>
11namespace {}
12
13// Athena initialize
14StatusCode
16{
17 ATH_MSG_VERBOSE("initialize() ...");
18
19 ATH_CHECK(m_cablingKey.initialize());
20
22 if (!m_SGKey_electrons.key().empty()) {
23 ATH_MSG_INFO("Using " << m_SGKey_electrons.key() << " for electrons");
24 }
26
28
30 if (!m_SGKey_photons.key().empty()) {
31 ATH_MSG_INFO("Using " << m_SGKey_photons.key() << " for photons");
32 }
33 ATH_CHECK(m_SGKey_photons_decorations.initialize(!m_SGKey_photons.key().empty()));
34
36 if (!m_SGKey_taus.key().empty()) {
37 ATH_MSG_INFO("Using " << m_SGKey_taus.key() << " for taus");
38 }
39 ATH_CHECK(m_SGKey_taus_decorations.initialize(!m_SGKey_taus.key().empty()));
40
42 if (!m_SGKey_jets.key().empty()) {
43 ATH_MSG_INFO("Using " << m_SGKey_jets.key() << " for jets");
44 }
45 ATH_CHECK(m_SGKey_jets_decorations.initialize(!m_SGKey_jets.key().empty()));
46
47 return StatusCode::SUCCESS;
48}
49
50
51// The decoration itself
52StatusCode
54{
55
56 if (!m_SGKey_photons.key().empty()) {
57 // Retrieve photon container
59 // setup vector of decorators
74
75 const xAOD::EgammaContainer* importedPhotons = photonContainer.ptr();
76 for (const auto* egamma : *importedPhotons) {
77 const xAOD::CaloCluster *cluster = egamma->caloCluster();
79 decorateObject(cluster, ctx);
80 decorationPh0(*egamma) = res.maxEcell_time;
81 decorationPh1(*egamma) = res.maxEcell_energy;
82 decorationPh2(*egamma) = res.maxEcell_gain;
83 decorationPh3(*egamma) = res.maxEcell_onlId;
84 decorationPh4(*egamma) = res.maxEcell_x;
85 decorationPh5(*egamma) = res.maxEcell_y;
86 decorationPh6(*egamma) = res.maxEcell_z;
87 }
88 }
89
90 if (!m_SGKey_electrons.key().empty()) {
91 // Retrieve electron container
93 ctx);
94
95 //
96 std::optional<SG::WriteDecorHandle<xAOD::EgammaContainer, float>> odecorationEl7;
97 const xAOD::CaloClusterContainer* egClContainer{};
98 if (!m_SGKey_egammaClusters.key().empty()) {
101 egClContainer = egClContainerRH.ptr();
102 odecorationEl7.emplace(m_SGKey_electrons_decorations[7], ctx);
103 }
104
105 // setup vector of decorators
120
121 const xAOD::EgammaContainer* importedElectrons = electronContainer.ptr();
122 for (const auto* egamma : *importedElectrons) {
123 const xAOD::CaloCluster *cluster = egamma->caloCluster();
124 if (!m_SGKey_egammaClusters.key().empty()) {
125 double dRMin = 9e9;
126 const xAOD::CaloCluster *matchedCluster(nullptr);
127 for (const auto *clus : *egClContainer) {
128 double dR = clus->p4().DeltaR(cluster->p4());
129 if (dR < dRMin && dR < m_dRLRTegClusegClusMax) {
130 dRMin = dR;
131 matchedCluster = clus;
132 }
133 }
134 cluster = matchedCluster;
135 odecorationEl7.value()(*egamma) = dRMin;
136 }
138 decorateObject(cluster, ctx);
139 decorationEl0(*egamma) = res.maxEcell_time;
140 decorationEl1(*egamma) = res.maxEcell_energy;
141 decorationEl2(*egamma) = res.maxEcell_gain;
142 decorationEl3(*egamma) = res.maxEcell_onlId;
143 decorationEl4(*egamma) = res.maxEcell_x;
144 decorationEl5(*egamma) = res.maxEcell_y;
145 decorationEl6(*egamma) = res.maxEcell_z;
146 }
147 }
148
149 if (!m_SGKey_taus.key().empty()) {
150 // Retrieve tau container
152 // setup vector of decorators
167
168 const xAOD::TauJetContainer* importedTaus = tauJetContainer.ptr();
169 for (const auto* tau : *importedTaus) {
171 res.maxEcell_energy = -9999.;
172 for (size_t i = 0;i<tau->nClusters();++i) {
173 // get particle
174 const xAOD::IParticle* part = tau->cluster(i);
175 if ( not part ) {
176 ATH_MSG_WARNING("Tau particle link invalid");
177 continue;
178 }
179
180 const xAOD::CaloCluster* cluster=dynamic_cast<const xAOD::CaloCluster*> (part);
181 if ( not cluster ) {
182 ATH_MSG_WARNING("Tau cluster link invalid");
183 continue;
184 }
185
187 decorateObject(cluster, ctx);
188 if (resCand.maxEcell_energy > res.maxEcell_energy) {
189 res = resCand;
190 }
191 }
192
193 decorationTau0(*tau) = res.maxEcell_time;
194 decorationTau1(*tau) = res.maxEcell_energy;
195 decorationTau2(*tau) = res.maxEcell_gain;
196 decorationTau3(*tau) = res.maxEcell_onlId;
197 decorationTau4(*tau) = res.maxEcell_x;
198 decorationTau5(*tau) = res.maxEcell_y;
199 decorationTau6(*tau) = res.maxEcell_z;
200 }
201 }
202
203 if (!m_SGKey_jets.key().empty()) {
204 // Retrieve jet container
206 // setup vector of decorators
221
222 const xAOD::JetContainer* importedJets = jetContainer.ptr();
223 for (const auto* jet : *importedJets) {
224 if (jet->numConstituents() == 0) continue;
225
227 res.maxEcell_energy = -9999.;
228 std::vector<const xAOD::CaloCluster*> clusterList;
229 clusterList.clear();
230
231 xAOD::Type::ObjectType ctype = jet->rawConstituent( 0 )->type();
232
233 if (ctype == xAOD::Type::FlowElement) {
234 // Particle Flow jets
235 for (size_t i=0;i<jet->numConstituents();++i) {
236 if(jet->rawConstituent(i)->type() != xAOD::Type::FlowElement) {
237 ATH_MSG_WARNING("Tried to call fillEperSamplingFE with a jet constituent that is not a FlowElement!");
238 continue;
239 }
240
241 const xAOD::FlowElement* constit = static_cast<const xAOD::FlowElement*>(jet->rawConstituent(i));
242 if (constit) {
243 const SG::AuxElement::ConstAccessor< ElementLink<xAOD::IParticleContainer> > originalObject("originalObjectLink");
244 auto originalFE = dynamic_cast<const xAOD::FlowElement*>(*originalObject(*constit));
245 if(originalFE && !originalFE->isCharged()){
246 const xAOD::CaloCluster* cluster = dynamic_cast<const xAOD::CaloCluster*>(originalFE->otherObject(0));
247 if (cluster) {
248 clusterList.push_back(cluster);
249 }
250 }
251 }
252 }
253 } else if (ctype == xAOD::Type::CaloCluster) {
254 // Topo jets
255 for (size_t i=0;i<jet->numConstituents();++i) {
256 if(jet->rawConstituent(i)->type() != xAOD::Type::CaloCluster) {
257 ATH_MSG_WARNING("Tried to call fillEperSamplingCluster with a jet constituent that is not a cluster!");
258 continue;
259 }
260
261 const xAOD::CaloCluster* cluster = static_cast<const xAOD::CaloCluster*>(jet->rawConstituent(i));
262 if (cluster) {
263 clusterList.push_back(cluster);
264 }
265 }
266 } else {
267 // PFlow (old)
268 for (size_t i=0;i<jet->numConstituents();++i) {
269 if(jet->rawConstituent(i)->type() != xAOD::Type::ParticleFlow) {
270 continue;
271 }
272 const xAOD::PFO* iPFO = static_cast<const xAOD::PFO*>(jet->rawConstituent(i));
273 if ( iPFO ) {
274 for (unsigned int cidx=0;cidx<iPFO->nCaloCluster();++cidx) {
275 if ( iPFO->cluster(cidx) ) {
276 clusterList.push_back(iPFO->cluster(cidx));
277 }
278 }
279 }
280 }
281 }
282
283 for (auto cluster : clusterList) {
285 decorateObject(cluster, ctx);
286 if (resCand.maxEcell_energy > res.maxEcell_energy) {
287 res = resCand;
288 }
289 }
290
291 decorationJet0(*jet) = res.maxEcell_time;
292 decorationJet1(*jet) = res.maxEcell_energy;
293 decorationJet2(*jet) = res.maxEcell_gain;
294 decorationJet3(*jet) = res.maxEcell_onlId;
295 decorationJet4(*jet) = res.maxEcell_x;
296 decorationJet5(*jet) = res.maxEcell_y;
297 decorationJet6(*jet) = res.maxEcell_z;
298 }
299 }
300
301 return StatusCode::SUCCESS;
302}
303
306 const xAOD::CaloCluster* cluster,
307 const EventContext& ctx) const
308{
309
311
312 if (cluster) {
313 if (!cluster->getCellLinks()) {
314 ATH_MSG_DEBUG("CellLinks not found");
315 return result;
316 }
317
319 const LArOnOffIdMapping* cabling{ *cablingHdl };
320 if (!cabling) {
321 ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
322 return result;
323 }
324
325 float emax = -9999.;
326
327 const CaloCell* cell_maxE = nullptr;
328 for (const CaloCell* cell : *cluster) {
329 int sampling = cell->caloDDE()->getSampling();
330 if (sampling == CaloCell_ID::EMB2 || sampling == CaloCell_ID::EME2) {
331 if ((cell->provenance() & 0x2000)) {
332 if (cell->energy() > emax) {
333 emax = cell->energy();
334 cell_maxE = cell;
335 }
336 }
337 }
338 }
339
340 if (cell_maxE) {
341 const CaloDetDescrElement* caloDDEl = cell_maxE->caloDDE();
342 result.maxEcell_time = cell_maxE->time();
343 result.maxEcell_energy = cell_maxE->energy();
344 result.maxEcell_gain = (int)cell_maxE->gain();
345 result.maxEcell_onlId =
346 (uint64_t)(cabling->createSignalChannelID(caloDDEl->identify()))
347 .get_compact();
348 result.maxEcell_x = caloDDEl->x();
349 result.maxEcell_y = caloDDEl->y();
350 result.maxEcell_z = caloDDEl->z();
351 }
352 }
353 return result;
354}
#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)
#define ATH_MSG_DEBUG(x)
std::pair< std::vector< unsigned int >, bool > res
xAOD::ElectronContainer * electronContainer
xAOD::PhotonContainer * photonContainer
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
float time() const
get time (data member)
Definition CaloCell.h:368
double energy() const
get energy (data member)
Definition CaloCell.h:327
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition CaloCell.h:321
CaloGain::CaloGain gain() const
get gain (data member )
Definition CaloCell.h:361
This class groups all DetDescr information related to a CaloCell.
Identifier identify() const override final
cell identifier
SG::WriteDecorHandleKeyArray< xAOD::JetContainer > m_SGKey_jets_decorations
SG::ReadHandleKey< xAOD::TauJetContainer > m_SGKey_taus
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_photons
SG::WriteDecorHandleKeyArray< xAOD::TauJetContainer > m_SGKey_taus_decorations
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > m_SGKey_electrons_decorations
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_SGKey_egammaClusters
This should be only for using run 2 reprocessing, which misses the cell link from LRT electron cluste...
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_electrons
calculation decorateObject(const xAOD::CaloCluster *cluster, const EventContext &ctx) const
Gaudi::Property< double > m_dRLRTegClusegClusMax
matching cone size
virtual StatusCode initialize() override final
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > m_SGKey_photons_decorations
SG::ReadHandleKey< xAOD::JetContainer > m_SGKey_jets
virtual StatusCode addBranches(const EventContext &ctx) const override final
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
const_pointer_type ptr()
Dereference the pointer.
Handle class for adding a decoration to an object.
elec/gamma data class.
Definition egamma.h:58
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Class providing the definition of the 4-vector interface.
unsigned int nCaloCluster() const
Find out how many CaloCluster are linked.
Definition PFO_v1.cxx:659
const CaloCluster * cluster(unsigned int index) const
Retrieve a const pointer to a CaloCluster.
Definition PFO_v1.cxx:669
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition ObjectType.h:32
@ ParticleFlow
The object is a particle-flow object.
Definition ObjectType.h:41
@ FlowElement
The object is a track-calo-cluster.
Definition ObjectType.h:52
@ CaloCluster
The object is a calorimeter cluster.
Definition ObjectType.h:39
PFO_v1 PFO
Definition of the current "pfo version".
Definition PFO.h:17
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition FlowElement.h:16
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
EgammaContainer_v1 EgammaContainer
Definition of the current "egamma container version".
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".