ATLAS Offline Software
Loading...
Searching...
No Matches
TrigInDetTrackTruth Class Reference

#include <TrigInDetTrackTruth.h>

Collaboration diagram for TrigInDetTrackTruth:

Public Member Functions

 TrigInDetTrackTruth ()
 Constructors: POOL needs default constructor.
 TrigInDetTrackTruth (const HepMcParticleLink &p_tru_part, TrigIDHitStats hits)
 initialized constructor: easier way to construct an instance if there is just one true particle associated with a track
virtual ~TrigInDetTrackTruth ()
int addMatch (HepMcParticleLink p_tru_part, TrigIDHitStats hits)
 accessor to fill object: returns index of new entry in vectors
int index (HepMcParticleLink &) const
 method to find if a given HepMcParticleLink already exists in "map" and, if so, what is its index; if not found returns -1; relies on HepMcParticleLink overloaded == method (i.e.
const HepMcParticleLinkbestMatch () const
 returns best match according to the number of hits
const HepMcParticleLinkbestSiMatch () const
 returns best match according to the number of hits
const HepMcParticleLinkbestTRTMatch () const
 returns best match according to the number of hits
const HepMcParticleLinktruthMatch (unsigned int i) const
 returns matching true particle number i
unsigned int nrMatches () const
 returns number of matching particles
unsigned int nrCommonHits (unsigned int i) const
 returns number of common hits from true particle i and TrigInDetTrack
unsigned int nrCommonSiHits (unsigned int i) const
 returns number of common hits from true particle i and TrigInDetTrack
unsigned int nrCommonTRTHits (unsigned int i) const
 returns number of common hits from true particle i and TrigInDetTrack
unsigned int nrCommonHitsBestSi () const
 returns total number of common hits from best match true particle and TrigInDetTrack
unsigned int nrCommonHitsBestTRT () const
 returns total number of common hits from best match true particle and TrigInDetTrack
int updateFamilyTree ()
 accessor to fill family tree: for each HepMcParticleLink in the internal vector of HepMC::GenParticles, this method searches for its mother in the same vector.
const std::vector< std::pair< unsigned int, unsigned int > > & getFamilyTree () const
 returns copy of family tree "map"
bool motherInChain (unsigned int) const
 given index of a GenParticle which matches the track returns true if its mother also matches the track and false if not
int motherIndexInChain (unsigned int) const
 given index of a GenParticle which matches the track returns index of
its mother, if it also matches the track, or -1 if not
bool daughtersInChain (unsigned int) const
 given index of a GenParticle which matches the track returns true if it has stable a daughter which also matches the track and false if not
std::vector< unsigned int > daughterIndicesInChain (unsigned int) const
 given index of a GenParticle which matches the track returns vector with indices of its daughters, if they also matches the track, or an empty vector if not

Private Attributes

int m_best_match_hits
int m_best_Si_match_hits
int m_best_TRT_match_hits
std::vector< HepMcParticleLinkm_true_part_vec
std::vector< TrigIDHitStatsm_nr_common_hits
std::vector< std::pair< unsigned int, unsigned int > > m_family_tree

Friends

class TrigInDetTrackTruthCnv_p1
class TrigInDetTrackTruthCnv_p1_test

Detailed Description

Definition at line 36 of file TrigInDetTrackTruth.h.

Constructor & Destructor Documentation

◆ TrigInDetTrackTruth() [1/2]

TrigInDetTrackTruth::TrigInDetTrackTruth ( )
inline

Constructors: POOL needs default constructor.

Definition at line 41 of file TrigInDetTrackTruth.h.

41 :
43 { };
std::vector< std::pair< unsigned int, unsigned int > > m_family_tree
std::vector< TrigIDHitStats > m_nr_common_hits
std::vector< HepMcParticleLink > m_true_part_vec

◆ TrigInDetTrackTruth() [2/2]

TrigInDetTrackTruth::TrigInDetTrackTruth ( const HepMcParticleLink & p_tru_part,
TrigIDHitStats hits )
inline

initialized constructor: easier way to construct an instance if there is just one true particle associated with a track

Definition at line 47 of file TrigInDetTrackTruth.h.

48 {
49 // add this particle to the vector
50 m_true_part_vec.push_back(p_tru_part);
51
52 // add number of hits
53 m_nr_common_hits.push_back( hits );
54
55 // set the best match index (only 1 match so far)
59 };

◆ ~TrigInDetTrackTruth()

virtual TrigInDetTrackTruth::~TrigInDetTrackTruth ( )
inlinevirtual

Definition at line 62 of file TrigInDetTrackTruth.h.

62{ };

Member Function Documentation

◆ addMatch()

int TrigInDetTrackTruth::addMatch ( HepMcParticleLink p_tru_part,
TrigIDHitStats hits )

accessor to fill object: returns index of new entry in vectors

Definition at line 34 of file TrigInDetTrackTruth.cxx.

35{
36 std::string thisName("TrigInDetTrackTruth::addMatch");
37 MsgStream log(Athena::getMessageSvc(), thisName);
38
39 log << MSG::DEBUG<< "Inserting HepMcParticleLink and TrigIDHitStats to TrigInDetTrackTruth map" << endmsg;
40
41 int indx = index(p_tru_part);
42 if ( indx >= 0 ) {
43 // HepMcParticleLink already exists: replace in vectors
44 log << MSG::DEBUG<< "HepMcParticleLink already in map: replacing"
45 << endmsg;
46 m_true_part_vec[indx] = p_tru_part;
47 m_nr_common_hits[indx] = hits;
48 } else {
49 // push back into vectors to use HepMcParticleLink as key
50 m_true_part_vec.push_back(p_tru_part);
51 m_nr_common_hits.push_back( hits );
52 indx = m_true_part_vec.size() - 1;
53 }
54
55 // to know the best match in total nr.hits
56 if ( m_best_match_hits == -1 ||
57 (unsigned int)hits.total() > nrCommonHits(m_best_match_hits) )
59
60 if ( m_best_Si_match_hits == -1 ||
61 (unsigned int)(hits.pixhits() + hits.scthits())> nrCommonSiHits(m_best_Si_match_hits) )
63
64 if ( m_best_TRT_match_hits == -1 ||
65 (unsigned int)hits.trthits() > nrCommonTRTHits(m_best_TRT_match_hits) )
67
68 return indx;
69}
#define endmsg
unsigned int nrCommonSiHits(unsigned int i) const
returns number of common hits from true particle i and TrigInDetTrack
int index(HepMcParticleLink &) const
method to find if a given HepMcParticleLink already exists in "map" and, if so, what is its index; if...
unsigned int nrCommonTRTHits(unsigned int i) const
returns number of common hits from true particle i and TrigInDetTrack
unsigned int nrCommonHits(unsigned int i) const
returns number of common hits from true particle i and TrigInDetTrack
IMessageSvc * getMessageSvc(bool quiet=false)

◆ bestMatch()

const HepMcParticleLink * TrigInDetTrackTruth::bestMatch ( ) const

returns best match according to the number of hits

Definition at line 184 of file TrigInDetTrackTruth.cxx.

185{
187}

◆ bestSiMatch()

const HepMcParticleLink * TrigInDetTrackTruth::bestSiMatch ( ) const

returns best match according to the number of hits

Definition at line 190 of file TrigInDetTrackTruth.cxx.

191{
193}

◆ bestTRTMatch()

const HepMcParticleLink * TrigInDetTrackTruth::bestTRTMatch ( ) const

returns best match according to the number of hits

Definition at line 196 of file TrigInDetTrackTruth.cxx.

197{
199}

◆ daughterIndicesInChain()

std::vector< unsigned int > TrigInDetTrackTruth::daughterIndicesInChain ( unsigned int mother) const

given index of a GenParticle which matches the track returns vector with indices of its daughters, if they also matches the track, or an empty vector if not

Definition at line 277 of file TrigInDetTrackTruth.cxx.

277 {
278
279 std::vector<unsigned int> v_indx;
280 v_indx.clear();
281 if ( m_family_tree.empty() ) return v_indx;
282
283 std::vector< std::pair<unsigned int, unsigned int> >::const_iterator it,it_end = m_family_tree.end();
284 unsigned int i=0;
285 for (it = m_family_tree.begin(); it != it_end; ++it) {
286 if (mother == (*it).first) {
287 v_indx.push_back(i);
288 }
289 ++i;
290 }
291 return v_indx;
292}

◆ daughtersInChain()

bool TrigInDetTrackTruth::daughtersInChain ( unsigned int mother) const

given index of a GenParticle which matches the track returns true if it has stable a daughter which also matches the track and false if not

Definition at line 296 of file TrigInDetTrackTruth.cxx.

296 {
297 std::vector<unsigned int> v_indx = daughterIndicesInChain(mother);
298 return ( !(v_indx.empty()) );
299}
std::vector< unsigned int > daughterIndicesInChain(unsigned int) const
given index of a GenParticle which matches the track returns vector with indices of its daughters,...

◆ getFamilyTree()

const std::vector< std::pair< unsigned int, unsigned int > > & TrigInDetTrackTruth::getFamilyTree ( ) const

returns copy of family tree "map"

Definition at line 250 of file TrigInDetTrackTruth.cxx.

251{
252 return m_family_tree;
253}

◆ index()

int TrigInDetTrackTruth::index ( HepMcParticleLink & hep_link) const

method to find if a given HepMcParticleLink already exists in "map" and, if so, what is its index; if not found returns -1; relies on HepMcParticleLink overloaded == method (i.e.

compares only barcode)

Definition at line 74 of file TrigInDetTrackTruth.cxx.

74 {
75
76 std::vector<HepMcParticleLink>::const_iterator it1, end=m_true_part_vec.end();
77 int indx = 0;
78 for (it1=m_true_part_vec.begin(); it1 != end; ++it1) {
79 if (hep_link == (*it1)) {
80 // HepMcParticleLink found in vector: return index
81 return indx;
82 }
83 ++indx;
84 }
85 // HepMcParticleLink not found: return default -1
86 return -1;
87}

◆ motherInChain()

bool TrigInDetTrackTruth::motherInChain ( unsigned int daughter) const

given index of a GenParticle which matches the track returns true if its mother also matches the track and false if not

Definition at line 271 of file TrigInDetTrackTruth.cxx.

271 {
272 return ( motherIndexInChain(daughter) >=0 );
273}
int motherIndexInChain(unsigned int) const
given index of a GenParticle which matches the track returns index of its mother,...

◆ motherIndexInChain()

int TrigInDetTrackTruth::motherIndexInChain ( unsigned int daughter) const

given index of a GenParticle which matches the track returns index of
its mother, if it also matches the track, or -1 if not

Definition at line 257 of file TrigInDetTrackTruth.cxx.

257 {
258
259 if ( m_family_tree.empty() ) return -1;
260
261 std::vector< std::pair<unsigned int, unsigned int> >::const_iterator it,it_end = m_family_tree.end();
262
263 for (it = m_family_tree.begin(); it != it_end; ++it) {
264 if (daughter == (*it).second) return (int)(*it).first;
265 }
266 return -1;
267}

◆ nrCommonHits()

unsigned int TrigInDetTrackTruth::nrCommonHits ( unsigned int i) const

returns number of common hits from true particle i and TrigInDetTrack

Definition at line 210 of file TrigInDetTrackTruth.cxx.

211{
212 if (i < m_true_part_vec.size()) return m_nr_common_hits[i].total();
213 else return 0;
214}

◆ nrCommonHitsBestSi()

unsigned int TrigInDetTrackTruth::nrCommonHitsBestSi ( ) const

returns total number of common hits from best match true particle and TrigInDetTrack

Definition at line 231 of file TrigInDetTrackTruth.cxx.

232{
234}

◆ nrCommonHitsBestTRT()

unsigned int TrigInDetTrackTruth::nrCommonHitsBestTRT ( ) const

returns total number of common hits from best match true particle and TrigInDetTrack

Definition at line 237 of file TrigInDetTrackTruth.cxx.

238{
239 return m_nr_common_hits[m_best_TRT_match_hits].trthits();
240}

◆ nrCommonSiHits()

unsigned int TrigInDetTrackTruth::nrCommonSiHits ( unsigned int i) const

returns number of common hits from true particle i and TrigInDetTrack

Definition at line 217 of file TrigInDetTrackTruth.cxx.

218{
219 if (i < m_true_part_vec.size()) return (m_nr_common_hits[i].pixhits() + m_nr_common_hits[i].scthits());
220 else return 0;
221}

◆ nrCommonTRTHits()

unsigned int TrigInDetTrackTruth::nrCommonTRTHits ( unsigned int i) const

returns number of common hits from true particle i and TrigInDetTrack

Definition at line 224 of file TrigInDetTrackTruth.cxx.

225{
226 if (i < m_true_part_vec.size()) return m_nr_common_hits[i].trthits();
227 else return 0;
228}

◆ nrMatches()

unsigned int TrigInDetTrackTruth::nrMatches ( ) const

returns number of matching particles

Definition at line 244 of file TrigInDetTrackTruth.cxx.

245{
246 return m_true_part_vec.size();
247}

◆ truthMatch()

const HepMcParticleLink * TrigInDetTrackTruth::truthMatch ( unsigned int i) const

returns matching true particle number i

Definition at line 202 of file TrigInDetTrackTruth.cxx.

203{
204 if (i < m_true_part_vec.size()) return &(m_true_part_vec[i]);
205 else return NULL;
206}

◆ updateFamilyTree()

int TrigInDetTrackTruth::updateFamilyTree ( )

accessor to fill family tree: for each HepMcParticleLink in the internal vector of HepMC::GenParticles, this method searches for its mother in the same vector.

If the mother is in the vector, the method adds the relation as a a mother-daughter pair to the family tree vector note: this method can be used as many times as necessary as long as the association object is not constant

Definition at line 95 of file TrigInDetTrackTruth.cxx.

96{
97
98 std::string thisName("TrigInDetTrackTruth::updateFamilyTree");
99 MsgStream log(Athena::getMessageSvc(), thisName);
100
101 log << MSG::DEBUG<< "In TrigInDetTrackTruth::updateFamilyTree()" << endmsg;
102
103 int nr_mothers_found=0;
104 int child=-1;
105 std::vector<HepMcParticleLink>::iterator it1, end=m_true_part_vec.end();
106
107 for (it1=m_true_part_vec.begin(); it1 != end; ++it1)
108 {
109 child++;
110 /* get production vertex GenParticle pointed to by this link */
111 log << MSG::DEBUG<< "Looking for mother of matching particle nr "<<child<<endmsg;
112
113 // first get GenParticle pointer
114 if ( !it1->isValid() ) continue;
115
116 auto p_child = (*it1).cptr();
117 log << MSG::DEBUG << "GenParticle " << child << " (" << p_child << "); PDG id="
118 << p_child->pdg_id() << "; status=" << p_child->status()
119 << "; pT=" << p_child->momentum().perp()
120 << "; searches mother..."
121 << endmsg;
122
123 // then get production vertex (check against null)
124 auto p_child_vtx = p_child->production_vertex();
125 if ( !p_child_vtx)
126 {
127 log << MSG::DEBUG<<"GenVertex pointer null: jump to next particle"<<endmsg;
128 continue;
129 }
130 log << MSG::DEBUG<< "GenParticle "<< child << " comes from vertex with pointer "
131 << p_child_vtx << endmsg;
132
133 /* find mother: there should be only one for final state particles
134 (particles which can leave energy deposits in detectors) */
135
136 // check a mother was found
137 if ( p_child_vtx->particles_in_size()==0)
138 {
139 log << MSG::DEBUG<< "Mother not found: go to next particle" <<endmsg;
140 continue;
141 }
142#ifdef HEPMC3
143 auto p_mum = p_child_vtx->particles_in().begin();
144#else
145 HepMC::GenVertex::particles_in_const_iterator p_mum = p_child_vtx->particles_in_const_begin();
146#endif
147 log << MSG::DEBUG<< "Mother GenParticle (" << *p_mum << ") found; PDG id="
148 << (*p_mum)->pdg_id() << "; status=" << (*p_mum)->status()
149 << "; pT=" << (*p_mum)->momentum().perp()
150 << "; does it match track?"
151 << endmsg;
152 // mother is (*p_mum); still have to see if it is a match to this track
153 std::vector<HepMcParticleLink>::iterator it2=m_true_part_vec.begin();
154
155 bool mum_found=false;
156 for (unsigned int mum=0; it2 != end; ++it2, ++mum)
157 {
158 log << MSG::DEBUG << "* Trying daughter index=" << child
159 << " and mother index=" << mum << endmsg;
160 auto p2 = *it2;
161 if ( *p_mum == p2 )
162 { // mother also matches track
163 m_family_tree.push_back( std::pair<unsigned int, unsigned int>(mum,child) );
164 mum_found=true;
165 nr_mothers_found++;
166
167 log << MSG::DEBUG << "* Mother also matches track! "
168 << nr_mothers_found
169 << " mother-daughter relations found so far" << endmsg;
170 log << MSG::DEBUG << "Daughter "<< child <<" (PDG id="
171 << p_child->pdg_id() << "; pT=" << p_child->momentum().perp()
172 << ") comes from mother " << mum << " (PDG id="
173 << (*p_mum)->status() << "; pT=" << p_child->momentum().perp()
174 << ")" << endmsg;
175 }
176 }
177 if (!mum_found) log << MSG::DEBUG << "* Mother doesn't match track"
178 << endmsg;
179 }
180 return nr_mothers_found;
181}

◆ TrigInDetTrackTruthCnv_p1

friend class TrigInDetTrackTruthCnv_p1
friend

Definition at line 90 of file TrigInDetTrackTruth.h.

◆ TrigInDetTrackTruthCnv_p1_test

friend class TrigInDetTrackTruthCnv_p1_test
friend

Definition at line 91 of file TrigInDetTrackTruth.h.

Member Data Documentation

◆ m_best_match_hits

int TrigInDetTrackTruth::m_best_match_hits
private

Definition at line 94 of file TrigInDetTrackTruth.h.

◆ m_best_Si_match_hits

int TrigInDetTrackTruth::m_best_Si_match_hits
private

Definition at line 95 of file TrigInDetTrackTruth.h.

◆ m_best_TRT_match_hits

int TrigInDetTrackTruth::m_best_TRT_match_hits
private

Definition at line 96 of file TrigInDetTrackTruth.h.

◆ m_family_tree

std::vector< std::pair<unsigned int, unsigned int> > TrigInDetTrackTruth::m_family_tree
private

Definition at line 103 of file TrigInDetTrackTruth.h.

◆ m_nr_common_hits

std::vector<TrigIDHitStats> TrigInDetTrackTruth::m_nr_common_hits
private

Definition at line 100 of file TrigInDetTrackTruth.h.

◆ m_true_part_vec

std::vector<HepMcParticleLink> TrigInDetTrackTruth::m_true_part_vec
private

Definition at line 99 of file TrigInDetTrackTruth.h.


The documentation for this class was generated from the following files: