ATLAS Offline Software
TrackTruthLookup.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef INDETPHYSVALMONITORING_TRACKTRUTHLOOKUP_H
6 #define INDETPHYSVALMONITORING_TRACKTRUTHLOOKUP_H 1
7 
14 // STL include(s)
15 #include <unordered_map> /* std::unordered_map */
16 #include <vector> /* std::vector */
17 #include <stdexcept> /* std::out_of_range */
18 
19 // xAOD include(s)
24 
25 namespace IDPVM {
75  public:
78  }
79 
81  const xAOD::TruthParticleContainer* truthParticles) {
82  cache(trackParticles, truthParticles);
83  }
84 
86  const std::vector<const xAOD::TruthParticle*>* truthParticlesVec) {
87  cache(trackParticles, truthParticlesVec);
88  }
89 
92  }
93 
98  // @{
102  void cache(const xAOD::TrackParticleContainer* trackParticles,
103  const std::vector<const xAOD::TruthParticle*>* truthParticlesVec);
104 
106  void cache(const xAOD::TrackParticleContainer* trackParticles,
107  const xAOD::TruthParticleContainer* truthParticles);
108  // @}
109 
114  std::vector<const xAOD::TrackParticle*> getTracks(const xAOD::TruthParticle* truth) const;
115 
121 
123  inline bool
124  contains(const xAOD::TruthParticle* truth) const {
125  return m_mapTruth.find(truth) != m_mapTruth.end();
126  }
127 
129  inline bool
131  return m_mapTrack.find(track) != m_mapTrack.end();
132  }
133 
135  inline void
136  clear() {
137  m_mapTrack.clear();
138  m_mapTruth.clear();
139  return;
140  }
141 
142  private:
143  void cacheTracks(const xAOD::TrackParticleContainer* trackParticles);
144  void cacheTruth(const xAOD::TruthParticleContainer* truthParticles);
145  void cacheTruth(const std::vector<const xAOD::TruthParticle*>* truthParticlesVec);
147  // Mapping of xAOD::TrackParticle to their unique associated
148  // xAOD::TruthParticle. nullptr if none exist.
149  std::unordered_map<const xAOD::TrackParticle*,
151 
152  // Mapping of xAOD::TruthParticle to vector of their (possibly multiple
153  // associated xAOD::TrackParticles. Empty if none exist.
154  std::unordered_map<const xAOD::TruthParticle*,
155  std::vector<const xAOD::TrackParticle*> > m_mapTruth;
156  };
157 } // namespace
158 
159 #endif // > !INDETPHYSVALMONITORING_TRACKTRUTHLOOKUP_H
IDPVM::TrackTruthLookup::m_mapTruth
std::unordered_map< const xAOD::TruthParticle *, std::vector< const xAOD::TrackParticle * > > m_mapTruth
Definition: TrackTruthLookup.h:155
IDPVM
Class to retrieve associated truth from a track, implementing a cached response.
Definition: InDetPhysValMonitoringTool.h:55
IDPVM::TrackTruthLookup::getTruth
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 assoc...
Definition: TrackTruthLookup.cxx:42
IDPVM::TrackTruthLookup::contains
bool contains(const xAOD::TrackParticle *track) const
Returns true if the Lookup contains the pointer 'track'.
Definition: TrackTruthLookup.h:130
TruthParticleContainer.h
IDPVM::TrackTruthLookup
Class for providing fast lookup of linked tracks and truth particles.
Definition: TrackTruthLookup.h:74
IDPVM::TrackTruthLookup::clear
void clear()
Clears the contents of the unordered map data members.
Definition: TrackTruthLookup.h:136
IDPVM::TrackTruthLookup::TrackTruthLookup
TrackTruthLookup()
Constructor(s).
Definition: TrackTruthLookup.h:77
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
DataVector< xAOD::TrackParticle_v1 >
IDPVM::TrackTruthLookup::getTracks
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...
Definition: TrackTruthLookup.cxx:30
IDPVM::TrackTruthLookup::cache
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::Truth...
Definition: TrackTruthLookup.cxx:107
TrackParticle.h
IDPVM::TrackTruthLookup::TrackTruthLookup
TrackTruthLookup(const xAOD::TrackParticleContainer *trackParticles, const xAOD::TruthParticleContainer *truthParticles)
Definition: TrackTruthLookup.h:80
IDPVM::TrackTruthLookup::TrackTruthLookup
TrackTruthLookup(const xAOD::TrackParticleContainer *trackParticles, const std::vector< const xAOD::TruthParticle * > *truthParticlesVec)
Definition: TrackTruthLookup.h:85
IDPVM::TrackTruthLookup::~TrackTruthLookup
~TrackTruthLookup()
Destructor.
Definition: TrackTruthLookup.h:91
IDPVM::TrackTruthLookup::m_mapTrack
std::unordered_map< const xAOD::TrackParticle *, const xAOD::TruthParticle * > m_mapTrack
Data member(s).
Definition: TrackTruthLookup.h:150
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
TruthParticle.h
IDPVM::TrackTruthLookup::cacheTruth
void cacheTruth(const xAOD::TruthParticleContainer *truthParticles)
Definition: TrackTruthLookup.cxx:78
TrackParticleContainer.h
IDPVM::TrackTruthLookup::cacheTracks
void cacheTracks(const xAOD::TrackParticleContainer *trackParticles)
Definition: TrackTruthLookup.cxx:54
IDPVM::TrackTruthLookup::contains
bool contains(const xAOD::TruthParticle *truth) const
Returns true if the Lookup contains the pointer 'truth'.
Definition: TrackTruthLookup.h:124