ATLAS Offline Software
|
Class for providing fast lookup of linked tracks and truth particles. More...
#include <TrackTruthLookup.h>
Public Member Functions | |
TrackTruthLookup () | |
Constructor(s). More... | |
TrackTruthLookup (const xAOD::TrackParticleContainer *trackParticles, const xAOD::TruthParticleContainer *truthParticles) | |
TrackTruthLookup (const xAOD::TrackParticleContainer *trackParticles, const std::vector< const xAOD::TruthParticle * > *truthParticlesVec) | |
~TrackTruthLookup () | |
Destructor. More... | |
CacheMethods | |
Methods for initial cache generation of links between associated tracks and truth particles in the provided containers. | |
std::unordered_map< const xAOD::TrackParticle *, const xAOD::TruthParticle * > | m_mapTrack |
Data member(s). More... | |
std::unordered_map< const xAOD::TruthParticle *, std::vector< const xAOD::TrackParticle * > > | m_mapTruth |
void | cache (const xAOD::TrackParticleContainer *trackParticles, const std::vector< const xAOD::TruthParticle * > *truthParticlesVec) |
Cache using a vector of TruthParticles, for compatibility with datatype returned from the xAOD::TruthEvent::truthParticleLinks() More... | |
void | cache (const xAOD::TrackParticleContainer *trackParticles, const xAOD::TruthParticleContainer *truthParticles) |
Generate cache from usual evtStore() retrieved container pointers. More... | |
std::vector< const xAOD::TrackParticle * > | getTracks (const xAOD::TruthParticle *truth) const |
Accessor to get the vector of xAOD::TrackParticles associated with 'truth', possibly empty if none is associated. More... | |
const xAOD::TruthParticle * | getTruth (const xAOD::TrackParticle *track) const |
Accessor to get the unique xAOD::TruthParticle associated with 'track', or a nullptr is none is associated. More... | |
bool | contains (const xAOD::TruthParticle *truth) const |
Returns true if the Lookup contains the pointer 'truth'. More... | |
bool | contains (const xAOD::TrackParticle *track) const |
Returns true if the Lookup contains the pointer 'track'. More... | |
void | clear () |
Clears the contents of the unordered map data members. More... | |
void | cacheTracks (const xAOD::TrackParticleContainer *trackParticles) |
void | cacheTruth (const xAOD::TruthParticleContainer *truthParticles) |
void | cacheTruth (const std::vector< const xAOD::TruthParticle * > *truthParticlesVec) |
Class for providing fast lookup of linked tracks and truth particles.
Intended to be used to avoid nested loops when matching tracks and truth particles, e.g. when computing efficiencies.
The links are stored in two unordered maps (single caching call per event, with O(N) complexity), emulating a bidirectional[1] map with O(1) look-up complexity. Tracks in the provided container are guaranteed to exist in the corresponding map, but may map to a nullptr if no link to a truth particle exists. Conversely, every truth particle is guaranteed to exist in the corresponding map, but may map to an empty vector if no link to a track exists.
Use, e.g. in the InDetPhysValLargeD0Tool, like:
[InDetPhysValMonitoring/InDetPhysValLargeD0Tool.h] #include "src/TrackTruthLookup.h" ... private: std::unique_ptr<IDPVM::TrackTruthLookup> m_lookup; ... [src/InDetPhysValLargeD0Tool.cxx] InDetPhysValLargeD0Tool::initialize() { ... m_lookup = std::move(std::unique_ptr<IDPVM::TrackTruthLookup>(new IDPVM::TrackTruthLookup())); ... } ... InDetPhysValLargeD0Tool::fillHistograms() { ... m_lookup->cache(ptracks, truthParticles); ... for (const auto &thisTruth : *truthParticles) { for (const auto& track : m_lookup->getTracks(thisTruth)) { // Only looping explicitly associated tracks, hence // O(N) complexity rather than O(N^2). } } ... }
[1] It is not exactly bidirectional, since the mapping track <-> truth is not exactly bijective: tracks are injective (one-to-one) on the set of truth particles but one truth particle may (although rarely) be associated to more than one track.
Definition at line 74 of file TrackTruthLookup.h.
|
inline |
|
inline |
Definition at line 80 of file TrackTruthLookup.h.
|
inline |
Definition at line 85 of file TrackTruthLookup.h.
|
inline |
void IDPVM::TrackTruthLookup::cache | ( | const xAOD::TrackParticleContainer * | trackParticles, |
const std::vector< const xAOD::TruthParticle * > * | truthParticlesVec | ||
) |
Cache using a vector of TruthParticles, for compatibility with datatype returned from the xAOD::TruthEvent::truthParticleLinks()
Definition at line 107 of file TrackTruthLookup.cxx.
void IDPVM::TrackTruthLookup::cache | ( | const xAOD::TrackParticleContainer * | trackParticles, |
const xAOD::TruthParticleContainer * | truthParticles | ||
) |
Generate cache from usual evtStore() retrieved container pointers.
Definition at line 98 of file TrackTruthLookup.cxx.
|
private |
Definition at line 54 of file TrackTruthLookup.cxx.
|
private |
Definition at line 88 of file TrackTruthLookup.cxx.
|
private |
Definition at line 78 of file TrackTruthLookup.cxx.
|
inline |
Clears the contents of the unordered map data members.
Definition at line 136 of file TrackTruthLookup.h.
|
inline |
Returns true if the Lookup contains the pointer 'track'.
Definition at line 130 of file TrackTruthLookup.h.
|
inline |
Returns true if the Lookup contains the pointer 'truth'.
Definition at line 124 of file TrackTruthLookup.h.
std::vector< const xAOD::TrackParticle * > IDPVM::TrackTruthLookup::getTracks | ( | const xAOD::TruthParticle * | truth | ) | const |
Accessor to get the vector of xAOD::TrackParticles associated with 'truth', possibly empty if none is associated.
Throws out_of_range exception if truth particle does not exist in cache.
Definition at line 30 of file TrackTruthLookup.cxx.
const xAOD::TruthParticle * IDPVM::TrackTruthLookup::getTruth | ( | const xAOD::TrackParticle * | track | ) | const |
Accessor to get the unique xAOD::TruthParticle associated with 'track', or a nullptr is none is associated.
Throws out_of_range exception if track does not exist in cache.
Definition at line 42 of file TrackTruthLookup.cxx.
|
private |
Data member(s).
Definition at line 150 of file TrackTruthLookup.h.
|
private |
Definition at line 155 of file TrackTruthLookup.h.