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 180 of file TrigInDetTrackTruth.cxx.

181{
183}

◆ bestSiMatch()

const HepMcParticleLink * TrigInDetTrackTruth::bestSiMatch ( ) const

returns best match according to the number of hits

Definition at line 186 of file TrigInDetTrackTruth.cxx.

187{
189}

◆ bestTRTMatch()

const HepMcParticleLink * TrigInDetTrackTruth::bestTRTMatch ( ) const

returns best match according to the number of hits

Definition at line 192 of file TrigInDetTrackTruth.cxx.

193{
195}

◆ 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 273 of file TrigInDetTrackTruth.cxx.

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

◆ 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 292 of file TrigInDetTrackTruth.cxx.

292 {
293 std::vector<unsigned int> v_indx = daughterIndicesInChain(mother);
294 return ( !(v_indx.empty()) );
295}
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 246 of file TrigInDetTrackTruth.cxx.

247{
248 return m_family_tree;
249}

◆ 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 267 of file TrigInDetTrackTruth.cxx.

267 {
268 return ( motherIndexInChain(daughter) >=0 );
269}
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 253 of file TrigInDetTrackTruth.cxx.

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

◆ nrCommonHits()

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

returns number of common hits from true particle i and TrigInDetTrack

Definition at line 206 of file TrigInDetTrackTruth.cxx.

207{
208 if (i < m_true_part_vec.size()) return m_nr_common_hits[i].total();
209 else return 0;
210}

◆ nrCommonHitsBestSi()

unsigned int TrigInDetTrackTruth::nrCommonHitsBestSi ( ) const

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

Definition at line 227 of file TrigInDetTrackTruth.cxx.

228{
230}

◆ nrCommonHitsBestTRT()

unsigned int TrigInDetTrackTruth::nrCommonHitsBestTRT ( ) const

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

Definition at line 233 of file TrigInDetTrackTruth.cxx.

234{
235 return m_nr_common_hits[m_best_TRT_match_hits].trthits();
236}

◆ nrCommonSiHits()

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

returns number of common hits from true particle i and TrigInDetTrack

Definition at line 213 of file TrigInDetTrackTruth.cxx.

214{
215 if (i < m_true_part_vec.size()) return (m_nr_common_hits[i].pixhits() + m_nr_common_hits[i].scthits());
216 else return 0;
217}

◆ nrCommonTRTHits()

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

returns number of common hits from true particle i and TrigInDetTrack

Definition at line 220 of file TrigInDetTrackTruth.cxx.

221{
222 if (i < m_true_part_vec.size()) return m_nr_common_hits[i].trthits();
223 else return 0;
224}

◆ nrMatches()

unsigned int TrigInDetTrackTruth::nrMatches ( ) const

returns number of matching particles

Definition at line 240 of file TrigInDetTrackTruth.cxx.

241{
242 return m_true_part_vec.size();
243}

◆ truthMatch()

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

returns matching true particle number i

Definition at line 198 of file TrigInDetTrackTruth.cxx.

199{
200 if (i < m_true_part_vec.size()) return &(m_true_part_vec[i]);
201 else return NULL;
202}

◆ 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 auto p_mum = p_child_vtx->particles_in().begin();
143 log << MSG::DEBUG<< "Mother GenParticle (" << *p_mum << ") found; PDG id="
144 << (*p_mum)->pdg_id() << "; status=" << (*p_mum)->status()
145 << "; pT=" << (*p_mum)->momentum().perp()
146 << "; does it match track?"
147 << endmsg;
148 // mother is (*p_mum); still have to see if it is a match to this track
149 std::vector<HepMcParticleLink>::iterator it2=m_true_part_vec.begin();
150
151 bool mum_found=false;
152 for (unsigned int mum=0; it2 != end; ++it2, ++mum)
153 {
154 log << MSG::DEBUG << "* Trying daughter index=" << child
155 << " and mother index=" << mum << endmsg;
156 auto p2 = *it2;
157 if ( *p_mum == p2 )
158 { // mother also matches track
159 m_family_tree.push_back( std::pair<unsigned int, unsigned int>(mum,child) );
160 mum_found=true;
161 nr_mothers_found++;
162
163 log << MSG::DEBUG << "* Mother also matches track! "
164 << nr_mothers_found
165 << " mother-daughter relations found so far" << endmsg;
166 log << MSG::DEBUG << "Daughter "<< child <<" (PDG id="
167 << p_child->pdg_id() << "; pT=" << p_child->momentum().perp()
168 << ") comes from mother " << mum << " (PDG id="
169 << (*p_mum)->status() << "; pT=" << p_child->momentum().perp()
170 << ")" << endmsg;
171 }
172 }
173 if (!mum_found) log << MSG::DEBUG << "* Mother doesn't match track"
174 << endmsg;
175 }
176 return nr_mothers_found;
177}

◆ 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: