ATLAS Offline Software
Loading...
Searching...
No Matches
TrigInDetTrackTruthMap.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6/**************************************************************************
7 **
8 ** File: TrigInDetTrackTruthMap.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:
18 **
19 **
20 **
21 **************************************************************************/
22
25#include "GaudiKernel/IMessageSvc.h"
26
27#include <iomanip>
28#include <iostream>
29#include <cassert>
30
33 unsigned int trk_indx,
34 TrigInDetTrackTruth& p_trk_tru)
35{
36 std::string thisName("TrigInDetTrackTruthMap::addMatch");
37 MsgStream log(Athena::getMessageSvc(), thisName);
38
39 log << MSG::DEBUG << "Adding TrigInDetTrack to map" << endmsg;
40
41 // check entry for this track doesn't exist (otherwise we have a multimap)
42 const TrigInDetTrack* p_trig_trk((*trkColl)[trk_indx]);
43
44 if ( !hasTruth( p_trig_trk ) ) {
45 ElementLink< TrigInDetTrackCollection > p_trk_lnk(*trkColl,trk_indx);
46 m_elink_vec.push_back(p_trk_lnk);
47 bool status = m_elink_vec.back().toPersistent();
48 if (!status)
49 log << MSG::DEBUG << "ERROR: could not set ElementLink persistent" << endmsg;
50 m_truth_vec.push_back(p_trk_tru);
51 } else {
52 log << MSG::DEBUG << "TrigInDetTrack already in map!" << endmsg;
53 }
54}
55
57// returns true if truth association exists for track
59{
60 // must loop over map because ElementLink is a unidirectional link
61 bool found=false;
62 for (unsigned int i=0; i < m_elink_vec.size(); ++i) {
63 // if ( p_trig_trk == *(m_elink_vec[i]) ) {
64 if(!m_elink_vec[i].isValid())
65 continue;
66 if ((*(m_elink_vec[i]))->param()) {
67 if ((*(m_elink_vec[i]))->algorithmId() == p_trig_trk->algorithmId() &&
68 (*(m_elink_vec[i]))->param()->pT() == p_trig_trk->param()->pT() &&
69 (*(m_elink_vec[i]))->param()->eta() == p_trig_trk->param()->eta() &&
70 (*(m_elink_vec[i]))->param()->phi0() == p_trig_trk->param()->phi0()) {
71 found=true;
72 break;
73 }
74 }
75 }
76 // true if this track pointer exists at least once in the vector
77 return (found);
78}
79
80
81// returns the track truth association object
83{
84 std::string thisName("TrigInDetTrackTruthMap::truth");
85 MsgStream log(Athena::getMessageSvc(), thisName);
86
87 log << MSG::DEBUG<<"Searching truth for track at ptr="<<p_trig_trk<<endmsg;
88
89 // must loop over map because ElementLink is a unidirectional link
90 for (unsigned int i=0; i < m_elink_vec.size(); ++i) {
91 // if ( p_trig_trk == *(m_elink_vec[i]) ) {
92 if(!m_elink_vec[i].isValid())
93 continue;
94 if ((*(m_elink_vec[i]))->param()) {
95 if ((*(m_elink_vec[i]))->algorithmId() == p_trig_trk->algorithmId() &&
96 (*(m_elink_vec[i]))->param()->pT() == p_trig_trk->param()->pT() &&
97 (*(m_elink_vec[i]))->param()->eta() == p_trig_trk->param()->eta() &&
98 (*(m_elink_vec[i]))->param()->phi0() == p_trig_trk->param()->phi0()) {
99 // found position in vector corresponding to this track pointer
100 log << MSG::DEBUG << "Truth match for track at ptr=" << p_trig_trk
101 << " found in map at index " << i <<endmsg;
102 return &m_truth_vec[i];
103 }
104 }
105 }
106 // didn't find it: return null pointer
107 log << MSG::DEBUG <<"Truth match for track at ptr="<<p_trig_trk <<" not in map"<<endmsg;
108 return NULL;
109}
110
111
112// to make the map more useful: return the link to GenParticle which better
113// matches this track according to number of common hits
115{
116 if ( hasTruth(p_trig_trk) ) {
117 return ( truth(p_trig_trk)->bestSiMatch() );
118 } else {
119 return NULL;
120 }
121}
122
124{
125 if ( hasTruth(p_trig_trk) ) {
126 return ( truth(p_trig_trk)->nrCommonHitsBestSi() );
127 } else {
128 return 0;
129 }
130}
131
132// to make the map more useful: return the link to GenParticle which better
133// matches this track according to number of common hits
135{
136 if ( hasTruth(p_trig_trk) ) {
137 return ( truth(p_trig_trk)->bestTRTMatch() );
138 } else {
139 return NULL;
140 }
141}
142
144{
145 if ( hasTruth(p_trig_trk) ) {
146 return ( truth(p_trig_trk)->nrCommonHitsBestTRT() );
147 } else {
148 return 0;
149 }
150}
151
152
154{
155 std::string thisName("TrigInDetTrackTruthMap::print");
156 MsgStream log(Athena::getMessageSvc(), thisName);
157
158 std::ostringstream oss;
159 oss << "TrigInDetTruthMap: " << m_elink_vec.size()
160 << " track-truth associations" << std::endl;
161
162 oss << "---------------------------------------------------------------------------------------------------------------------------------" << std::endl;
163 oss << "#track|algo| pointer | pT | eta | phi |#match|mother|Sihits|TRThits|ev.index| barcode | pdg id | pT | eta | phi |"<< std::endl;
164 for (unsigned int i=0; i < m_elink_vec.size(); ++i) {
165 oss << std::setiosflags(std::ios::dec) << std::setw(6) << i << "|"
166 << std::setiosflags(std::ios::dec) << std::setw(4) << (*(m_elink_vec[i]))->algorithmId() << "|"
167 << std::setw(11) << *(m_elink_vec[i]) << "|";
168
169 if(!m_elink_vec[i].isValid()) {
170 oss << std::setiosflags(std::ios::dec) << "Invalid TrigInDetTrack link !"
171 << std::setiosflags(std::ios::dec) << std::setw(8) << "|";
172 }
173 else {
174 // print reconstructed track parameters
175 if ((*(m_elink_vec[i]))->param()) {
176 oss << std::setiosflags(std::ios::dec) << std::setw(14) << (*(m_elink_vec[i]))->param()->pT() << "|"
177 << std::setiosflags(std::ios::dec) << std::setw(10) << (*(m_elink_vec[i]))->param()->eta() << "|"
178 << std::setiosflags(std::ios::dec) << std::setw(10) << (*(m_elink_vec[i]))->param()->phi0()<< "|";
179 } else {
180 oss << std::setiosflags(std::ios::dec) << std::setw(15) << "|"
181 << std::setiosflags(std::ios::dec) << std::setw(11) << "|"
182 << std::setiosflags(std::ios::dec) << std::setw(11) << "|";
183 }
184 }
185
186 if (m_truth_vec[i].nrMatches() == 0) oss << std::endl;
187 // print parameters of truth particles which have hits in common with track
188 for (unsigned int j=0; j < m_truth_vec[i].nrMatches(); ++j) {
189
190 // find if this matching true particle has a mother which also matches the track
191 HepMcParticleLink p_link( *((m_truth_vec[i]).truthMatch(j)) );
192 int child_indx = (m_truth_vec[i]).index(p_link);
193 int mother_indx = -1;
194 if (child_indx >= 0) mother_indx = (m_truth_vec[i]).motherIndexInChain(child_indx);
195
196 if (j>0) {
197
198 oss << std::setiosflags(std::ios::dec) << std::setw(7) << "|"
199 << std::setiosflags(std::ios::dec) << std::setw(5) << "|";
200 oss << std::setiosflags(std::ios::dec) << std::setw(15) << "|"
201 << std::setiosflags(std::ios::dec) << std::setw(11) << "|"
202 << std::setiosflags(std::ios::dec) << std::setw(11) << "|";
203 }
204
205 oss << std::setiosflags(std::ios::dec) << std::setw(6) << j+1 << "|";
206
207 if (mother_indx >= 0) {
208 oss << std::setiosflags(std::ios::dec) << std::setw(6) << mother_indx << "|";
209 } else {
210 oss << " -- |";
211 }
212 oss << std::setiosflags(std::ios::dec) << std::setw(6) << (m_truth_vec[i]).nrCommonSiHits(j) << "|"
213 << std::setiosflags(std::ios::dec) << std::setw(7) << (m_truth_vec[i]).nrCommonTRTHits(j) << "|"
214 << std::setiosflags(std::ios::dec) << std::setw(8) << (m_truth_vec[i]).truthMatch(j)->eventIndex() << "|"
215 << std::setiosflags(std::ios::dec) << std::setw(9) << (m_truth_vec[i]).truthMatch(j)->barcode() << "|";
216
217 if ((m_truth_vec[i]).truthMatch(j)->cptr()) {
218
219 oss << std::setiosflags(std::ios::dec) << std::setw(10) << (m_truth_vec[i]).truthMatch(j)->cptr()->pdg_id() << "|"
220 << std::setiosflags(std::ios::dec) << std::setw(14) << (m_truth_vec[i]).truthMatch(j)->cptr()->momentum().perp()<< "|"
221 << std::setiosflags(std::ios::dec) << std::setw(10) << (m_truth_vec[i]).truthMatch(j)->cptr()->momentum().eta() << "|"
222 << std::setiosflags(std::ios::dec) << std::setw(10) << (m_truth_vec[i]).truthMatch(j)->cptr()->momentum().phi() << "|";
223 } else {
224 oss << std::setiosflags(std::ios::dec) << std::setw(11) << "|"
225 << std::setiosflags(std::ios::dec) << std::setw(15) << "|"
226 << std::setiosflags(std::ios::dec) << std::setw(11) << "|"
227 << std::setiosflags(std::ios::dec) << std::setw(11) << "|";
228 }
229 oss << std::endl;
230 }
231 }
232 oss << "---------------------------------------------------------------------------------------------------------------------------------" << std::endl;
233
234 log << MSG::DEBUG << oss.str() << endmsg;
235}
236
238{
239 assert (m_elink_vec.size() == m_truth_vec.size());
240 return m_elink_vec.size();
241}
242
245{
246 assert (i < m_truth_vec.size());
247 return &m_truth_vec[i];
248}
249
250const TrigInDetTrack*
252{
253 assert (i < m_elink_vec.size());
254 return *m_elink_vec[i];
255}
256
259{
260 assert (i < m_elink_vec.size());
261 return m_elink_vec[i];
262}
#define endmsg
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
const HepMcParticleLink * bestMatchSi(const TrigInDetTrack *p_trig_trk) const
int bestMatchSiHits(const TrigInDetTrack *p_trig_trk) const
bool hasTruth(const TrigInDetTrack *p_trig_trk) const
methods to get truth-match objects
int bestMatchTRTHits(const TrigInDetTrack *p_trig_trk) const
const ElementLink< TrigInDetTrackCollection > trackiLink(size_t i) const
const TrigInDetTrack * tracki(size_t i) const
ElementLinkVector< TrigInDetTrackCollection > m_elink_vec
const HepMcParticleLink * bestMatchTRT(const TrigInDetTrack *p_trig_trk) const
const TrigInDetTrackTruth * truth(const TrigInDetTrack *p_trig_trk) const
const TrigInDetTrackTruth * truthi(size_t i) const
void addMatch(const TrigInDetTrackCollection *trkColl, unsigned int trk_indx, TrigInDetTrackTruth &p_trk_tru)
accessors to fill map
std::vector< TrigInDetTrackTruth > m_truth_vec
represents a LVL2 ID track
void algorithmId(const AlgoId id)
void param(const TrigInDetTrackFitPar *param)
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
Definition index.py:1