ATLAS Offline Software
Loading...
Searching...
No Matches
TrigInDetTrackTruth.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6/**************************************************************************
7 **
8 ** File: TrigInDetTrackTruth.cxx
9 **
10 ** Description: - Stores a vector of pointers to GenParticles which match
11 ** a TrigInDetTrack and associated matching quality
12 ** quantities (nr of common hits only for now)
13 **
14 ** Author: R.Goncalo
15 **
16 ** Created: Sat Jan 18 19:55:56 GMT 2006
17 ** Modified: RG 1/9/06 - added method for object to update own family tree
18 ** RG 2/9/06 - was going to change set of two vectors acting
19 ** as a map<HepMcPart.Link,TrigIDHitStats> into a GaudiUtils::VectorMap to
20 ** improve readout speed but decided against this since it complicates
21 ** matters and creates dependencies, and because only a few (~1-5) GenParticles
22 ** can be expected to match any TrigInDetTrack, so the overhead is small.
23 ** Changed m_family_tree from map<unsigned int,unsigned int> into
24 ** vector< pair<unsigned int,unsigned int>> to avoid persistency problems and
25 ** also to make it easier to use either mother or daughter indices as keys
26 **************************************************************************/
27
30#include "GaudiKernel/IMessageSvc.h"
32
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}
70
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}
88
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}
178
184
190
196
199{
200 if (i < m_true_part_vec.size()) return &(m_true_part_vec[i]);
201 else return NULL;
202}
203
204
206unsigned int TrigInDetTrackTruth::nrCommonHits(unsigned int i) const
207{
208 if (i < m_true_part_vec.size()) return m_nr_common_hits[i].total();
209 else return 0;
210}
211
213unsigned int TrigInDetTrackTruth::nrCommonSiHits(unsigned int i) const
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}
218
220unsigned int TrigInDetTrackTruth::nrCommonTRTHits(unsigned int i) const
221{
222 if (i < m_true_part_vec.size()) return m_nr_common_hits[i].trthits();
223 else return 0;
224}
225
231
234{
235 return m_nr_common_hits[m_best_TRT_match_hits].trthits();
236}
237
238
241{
242 return m_true_part_vec.size();
243}
244
246const std::vector< std::pair<unsigned int, unsigned int> >& TrigInDetTrackTruth::getFamilyTree() const
247{
248 return m_family_tree;
249}
250
253int TrigInDetTrackTruth::motherIndexInChain(unsigned int daughter) const {
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}
264
267bool TrigInDetTrackTruth::motherInChain(unsigned int daughter) const {
268 return ( motherIndexInChain(daughter) >=0 );
269}
270
273std::vector<unsigned int> TrigInDetTrackTruth::daughterIndicesInChain(unsigned int mother) const {
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}
289
292bool TrigInDetTrackTruth::daughtersInChain(unsigned int mother) const {
293 std::vector<unsigned int> v_indx = daughterIndicesInChain(mother);
294 return ( !(v_indx.empty()) );
295}
#define endmsg
const HepMcParticleLink * bestSiMatch() const
returns best match according to the number of hits
unsigned int nrCommonSiHits(unsigned int i) const
returns number of common hits from true particle i and TrigInDetTrack
std::vector< std::pair< unsigned int, unsigned int > > m_family_tree
bool daughtersInChain(unsigned int) const
given index of a GenParticle which matches the track returns true if it has stable a daughter which a...
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
int motherIndexInChain(unsigned int) const
given index of a GenParticle which matches the track returns index of its mother,...
unsigned int nrCommonHits(unsigned int i) const
returns number of common hits from true particle i and TrigInDetTrack
int updateFamilyTree()
accessor to fill family tree: for each HepMcParticleLink in the internal vector of HepMC::GenParticle...
unsigned int nrCommonHitsBestSi() const
returns total number of common hits from best match true particle and TrigInDetTrack
const HepMcParticleLink * bestTRTMatch() const
returns best match according to the number of hits
unsigned int nrCommonHitsBestTRT() const
returns total number of common hits from best match true particle and TrigInDetTrack
const std::vector< std::pair< unsigned int, unsigned int > > & getFamilyTree() const
returns copy of family tree "map"
unsigned int nrMatches() const
returns number of matching particles
bool motherInChain(unsigned int) const
given index of a GenParticle which matches the track returns true if its mother also matches the trac...
std::vector< TrigIDHitStats > m_nr_common_hits
std::vector< unsigned int > daughterIndicesInChain(unsigned int) const
given index of a GenParticle which matches the track returns vector with indices of its daughters,...
int addMatch(HepMcParticleLink p_tru_part, TrigIDHitStats hits)
accessor to fill object: returns index of new entry in vectors
const HepMcParticleLink * truthMatch(unsigned int i) const
returns matching true particle number i
const HepMcParticleLink * bestMatch() const
returns best match according to the number of hits
std::vector< HepMcParticleLink > m_true_part_vec
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
Definition index.py:1