ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetValidation
InDetPhysValMonitoring
src
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
10
11
#include "
CachedGetAssocTruth.h
"
12
#include "
xAODTruth/TruthParticleContainer.h
"
13
#include "
AthContainers/ConstAccessor.h
"
14
15
namespace
IDPVM
{
16
void
17
CachedGetAssocTruth::clear
() {
18
m_cache
.clear();
19
}
20
21
const
std::string
CachedGetAssocTruth::s_trackParticleLinkDecorationName
(
"truthParticleLink"
);
22
23
void
CachedGetAssocTruth::neededTrackParticleDecorations
(std::vector<std::string> &decorations) {
24
if
(std::find(decorations.begin(),decorations.end(),
s_trackParticleLinkDecorationName
) == decorations.end()) {
25
decorations.push_back(
s_trackParticleLinkDecorationName
);
26
}
27
}
28
const
xAOD::TruthParticle
*
29
CachedGetAssocTruth::getTruth
(
const
xAOD::TrackParticle
* trackParticle) {
30
if
(not trackParticle) {
31
return
nullptr
;
32
}
33
auto
pCache =
m_cache
.find(trackParticle);
34
if
(pCache !=
m_cache
.end()) {
35
return
pCache->second;
36
}
37
using
ElementTruthLink_t =
ElementLink<xAOD::TruthParticleContainer>
;
38
const
xAOD::TruthParticle
* result(
nullptr
);
39
static
const
SG::ConstAccessor<ElementTruthLink_t>
truthParticleLinkAcc(
s_trackParticleLinkDecorationName
);
40
// 0. is there any truth?
41
if
(truthParticleLinkAcc.
isAvailable
(*trackParticle)) {
42
// 1. ..then get link
43
const
ElementTruthLink_t ptruthContainer = truthParticleLinkAcc(*trackParticle);
44
if
(ptruthContainer.isValid()) {
45
result = *ptruthContainer;
46
}
47
}
48
m_cache
[trackParticle] = result;
49
return
result;
50
}
51
52
const
xAOD::TruthParticle
*
53
CachedGetAssocTruth::operator ()
(
const
xAOD::TrackParticle
* trackParticle) {
54
return
getTruth
(trackParticle);
55
}
56
57
}
CachedGetAssocTruth.h
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
TruthParticleContainer.h
ElementLink
ElementLink implementation for ROOT usage.
Definition
A/AthLinks/ElementLink.h:40
IDPVM::CachedGetAssocTruth::clear
void clear()
clear the cache
Definition
CachedGetAssocTruth.cxx:17
IDPVM::CachedGetAssocTruth::operator()
const xAOD::TruthParticle * operator()(const xAOD::TrackParticle *trackParticle)
Get the associated truth particle, given a track particle.
Definition
CachedGetAssocTruth.cxx:53
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:39
IDPVM::CachedGetAssocTruth::neededTrackParticleDecorations
static void neededTrackParticleDecorations(std::vector< std::string > &decorations)
Definition
CachedGetAssocTruth.cxx:23
IDPVM::CachedGetAssocTruth::s_trackParticleLinkDecorationName
static const std::string s_trackParticleLinkDecorationName
Definition
CachedGetAssocTruth.h:40
IDPVM::CachedGetAssocTruth::getTruth
const xAOD::TruthParticle * getTruth(const xAOD::TrackParticle *const trackParticle)
Definition
CachedGetAssocTruth.cxx:29
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition
ConstAccessor.h:55
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
IDPVM
Class to retrieve associated truth from a track, implementing a cached response.
Definition
InDetPhysValMonitoringTool.h:56
xAOD::TrackParticle
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Definition
Event/xAOD/xAODTracking/xAODTracking/TrackParticle.h:13
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
Generated on
for ATLAS Offline Software by
1.17.0