ATLAS Offline Software
CachedGetAssocTruth.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
11  #include "CachedGetAssocTruth.h"
14 
15 namespace IDPVM {
16  void
18  m_cache.clear();
19  }
20 
21  const xAOD::TruthParticle*
23  if (not trackParticle) {
24  return nullptr;
25  }
26  auto pCache = m_cache.find(trackParticle);
27  if (pCache != m_cache.end()) {
28  return pCache->second;
29  }
30  using ElementTruthLink_t = ElementLink<xAOD::TruthParticleContainer>;
31  const xAOD::TruthParticle* result(nullptr);
32  static const SG::ConstAccessor<ElementTruthLink_t> truthParticleLinkAcc("truthParticleLink");
33  // 0. is there any truth?
34  if (truthParticleLinkAcc.isAvailable(*trackParticle)) {
35  // 1. ..then get link
36  const ElementTruthLink_t ptruthContainer = truthParticleLinkAcc(*trackParticle);
37  if (ptruthContainer.isValid()) {
38  result = *ptruthContainer;
39  }
40  }
41  m_cache[trackParticle] = result;
42  return result;
43  }
44 
45  const xAOD::TruthParticle*
47  return getTruth(trackParticle);
48  }
49 
50 }
IDPVM
Class to retrieve associated truth from a track, implementing a cached response.
Definition: InDetPhysValMonitoringTool.h:55
get_generator_info.result
result
Definition: get_generator_info.py:21
IDPVM::CachedGetAssocTruth::clear
void clear()
clear the cache
Definition: CachedGetAssocTruth.cxx:17
TruthParticleContainer.h
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
CachedGetAssocTruth.h
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
IDPVM::CachedGetAssocTruth::getTruth
const xAOD::TruthParticle * getTruth(const xAOD::TrackParticle *const trackParticle)
Definition: CachedGetAssocTruth.cxx:22
IDPVM::CachedGetAssocTruth::operator()
const xAOD::TruthParticle * operator()(const xAOD::TrackParticle *trackParticle)
Get the associated truth particle, given a track particle.
Definition: CachedGetAssocTruth.cxx:46
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
IDPVM::CachedGetAssocTruth::m_cache
std::unordered_map< const xAOD::TrackParticle *, const xAOD::TruthParticle * > m_cache
private cache container; map or unordered_map could be used
Definition: CachedGetAssocTruth.h:37