ATLAS Offline Software
Loading...
Searching...
No Matches
SharedHitMapper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include "TrkTrack/Track.h"
9#include <string>
14#include <vector>
15#include <utility>
16#include <iostream>
17
18typedef std::pair<const xAOD::TrackParticle*, const Trk::RIO_OnTrack*> pairTrkRio;
19typedef std::vector<pairTrkRio> vecpairTrkRio;
20
21
26void SharedHitTrackAssoc::add(const xAOD::TrackParticle* const trk, int shPattern) {
27 m_assocs.insert(std::make_pair(trk,shPattern));
28}
29void SharedHitTrackAssoc::add(const xAOD::TrackParticle* const trk, int shB, int shP, int shS) {
30 int shPattern = 100000*shB + 1000*shS + 100*shP;
31 m_assocs.insert(std::make_pair(trk,shPattern));
32}
34 int tempSharedPattern(0);
35 AssocIter aE = m_assocs.end();
36 AssocIter aI = m_assocs.find(trk);
37 if(aI!=aE) tempSharedPattern = aI->second;
38 return tempSharedPattern/100000;
39}
41 int tempSharedPattern(0);
42 AssocIter aE = m_assocs.end();
43 AssocIter aI = m_assocs.find(trk);
44 if(aI!=aE) tempSharedPattern = aI->second;
45 return ((tempSharedPattern%100000)%1000)/100;
46}
48 int tempSharedPattern(0);
49 AssocIter aE = m_assocs.end();
50 AssocIter aI = m_assocs.find(trk);
51 if(aI!=aE) tempSharedPattern = aI->second;
52 return (tempSharedPattern%100000)/1000;
53}
54
56 std::cout<<"SharedHitTrackAssoc has "<<this->size()<<" elements:"<<std::endl;
57 AssocIter aI = m_assocs.begin();
58 AssocIter aE = m_assocs.end();
59 for(; aI!=aE; ++aI) {
60 std::cout << "--> track: "
61 << " Eta= " << aI->first->eta()
62 << " Phi= " << aI->first->phi()
63 << " pT= " << aI->first->pt()
64 << " Shared pattern= " << aI->second
65 // what follows is not nice...
66 << " shB= " << this->numberSharedBLayer(aI->first)
67 << " shP= " << this->numberSharedPix(aI->first)
68 << " shS= " << this->numberSharedSct(aI->first)
69 << std::endl;
70 }
71}
72
73
74SharedHitMapper::SharedHitMapper(const std::string& name, ISvcLocator* pSvcLocator)
75 : AthAlgorithm(name, pSvcLocator) {
76 declareProperty("inputTrackCollection", m_inputTrackCollection = "TrackParticleCandidate");
77 declareProperty("sharedHitMapLocation", m_sharedHitMapLocation = "SharedHitMap");
78 declareProperty("deltaRCut", m_deltaRCut = 1.0);
79 declareProperty("QualityOrdering", m_qualOrder = false);
80 declareProperty("useTrackSummaryShared", m_useTrackSummaryShared = true);
81}
82
85
88 StatusCode sc = detStore()->retrieve(m_pixelId, "PixelID");
89 if (sc.isFailure()) {
90 ATH_MSG_ERROR("Could not get PixelID helper !");
91 }
92 sc = detStore()->retrieve(m_sctId, "SCT_ID");
93 if (sc.isFailure()) {
94 ATH_MSG_ERROR("Could not get SCT_ID helper !");
95 }
96 }
97 std::cout<<name()<<" with input tracks "<<m_inputTrackCollection<<std::endl;
98 std::cout<<name()<<" initialized"<<std::endl;
99 return StatusCode::SUCCESS;
100}
101
103
104 MsgStream mlog(msgSvc(), name());
105
107 const xAOD::TrackParticleContainer* inputTracks(0);
108 StatusCode sc = evtStore()->retrieve(inputTracks, m_inputTrackCollection);
109 if (sc.isFailure()) {
110 ATH_MSG_ERROR("TrackParticles " << m_inputTrackCollection << " not found in StoreGate.");
111 return StatusCode::SUCCESS;
112 }
113 ATH_MSG_VERBOSE("TrackParticleContainer " << m_inputTrackCollection << " found.");
114
116 ATH_MSG_INFO("Number of initial TrackParticles: " << inputTracks->size());
117
119 // --- Use shared hit information from TrackSummary:
120 // loop on first track:
123 for (; trk1I!=trkE; ++trk1I) {
124 int nbs, nps, nss;
125 (*trk1I)->summaryValue(nbs, xAOD::numberOfInnermostPixelLayerSharedHits);
126 (*trk1I)->summaryValue(nps, xAOD::numberOfPixelSharedHits);
127 (*trk1I)->summaryValue(nss, xAOD::numberOfSCTSharedHits);
128 if (nbs < 0) nbs = 0;
129 if (nps < 0) nps = 0;
130 if (nss < 0) nss = 0;
131 if(nbs+nps+nss>0) assoc->add( (*trk1I), nbs, nps, nss);
132 }
133 } else {
134 // --- Recompute shared hit information from TrkTracks:
135
136 vecpairTrkRio myvecTrkRio(0);
137
138 // loop on first track:
141 for (; trk1I!=trkE; ++trk1I) {
142 const xAOD::TrackParticle* trk1 = (*trk1I);//->track();
143 if(trk1==0) {
144 ATH_MSG_ERROR("Can't get the original track ! Please run on ESD");
145 return StatusCode::SUCCESS;
146 }
147 //
148 // For the quality computation
149 int q1 = 0 ,q2 = 0;
150 int np1 = 0, np2 = 0, ns1 = 0, ns2 = 0;
151 int nhp1 = 0, nhp2 = 0, nhs1 = 0, nhs2 = 0, nh1 = 0, nh2 = 0;
152 int nprec1 = 0, nprec2 = 0;
153 double chi21 = 0., chi22 = 0.;
154 if (m_qualOrder) {
155 chi21 = (*trk1I)->chiSquared();
156 (*trk1I)->summaryValue(np1, xAOD::numberOfPixelHits); if (np1<0)np1=0;
157 (*trk1I)->summaryValue(ns1, xAOD::numberOfSCTHits); if (ns1<0)ns1=0;
158 nprec1 = np1 + ns1;
159 (*trk1I)->summaryValue(nhp1, xAOD::numberOfPixelHoles); if (nhp1<0)nhp1=0;
160 (*trk1I)->summaryValue(nhs1, xAOD::numberOfSCTHoles); if (nhs1<0)nhs1=0;
161 nh1 = nhp1 + nhs1;
162 q1 = 10000*(2*nprec1-nh1) - int(20.*chi21/float(nprec1));
163
164 }
165 //
166 xAOD::IParticle::FourMom_t t1p4 = (*trk1I)->p4();
167 const DataVector<const Trk::MeasurementBase>* mb = (*trk1->track())->measurementsOnTrack();
170 ATH_MSG_VERBOSE("First track (pT="<<t1p4.Pt()<<", eta="<<t1p4.Eta ()<<") has " << mb->size() << " RIOs on track");
171 // init arrays for pixels:
172 bool pl[m_nbpl]; // layers
173 for(int i=0;i<m_nbpl;i++) m_npl[i] = 0;
174 bool pd[m_nbpd]; // disks
175 for(int i=0;i<m_nbpd;i++) m_npd[i] = 0;
176 // init arrays for sct:
177 bool sl[m_nbsl];
178 for(int i=0;i<m_nbsl;i++) m_nsl[i] = 0;
179 bool sd[m_nbsd];
180 for(int i=0;i<m_nbsd;i++) m_nsd[i] = 0;
181 // loop on second track:
183 for (; trk2I!=trkE; ++trk2I) {
184 if(trk2I==trk1I) continue;
185 const xAOD::TrackParticle* trk2 = (*trk2I);
186 if(trk2==0) {
187 ATH_MSG_ERROR("Can't get the original track ! Please run on ESD");
188 return StatusCode::SUCCESS;
189 }
190 xAOD::IParticle::FourMom_t t2p4 = (*trk2I)->p4();
191 double deltaR = t1p4.DeltaR(t2p4);
192 if(deltaR<m_deltaRCut) {
193 // Assign the shared hit to the worst quality track
194 // If a hit is shared by more than 2 tracks, this will not be perfect...
195 // From IG : Quality = 10000*(2*Nhit-Nhole) - int(20.*Xi2/float(Nhit))
196 if (m_qualOrder) {
197 chi22 = (*trk2I)->chiSquared();
198 (*trk2I)->summaryValue(np2, xAOD::numberOfPixelHits); if (np2<0)np2=0;
199 (*trk2I)->summaryValue(ns2, xAOD::numberOfSCTHits); if (ns2<0)ns2=0;
200 nprec1 = np1 + ns1;
201 (*trk2I)->summaryValue(nhp2, xAOD::numberOfPixelHoles); if (nhp2<0)nhp2=0;
202 (*trk2I)->summaryValue(nhs2, xAOD::numberOfSCTHoles); if (nhs2<0)nhs2=0;
203 nh2 = nhp2 + nhs2;
204 q2 = 10000*(2*nprec2-nh2) - int(20.*chi22/float(nprec2));
205 if (q1 > q2) continue;
206 }
207 // loop on 1st track clusters:
208 nextMb = mb->begin();
209 for(; nextMb != lastMb; ++nextMb) {
210 const Trk::RIO_OnTrack* nextRio = dynamic_cast<const Trk::RIO_OnTrack*>(*nextMb);
211 bool pixl = m_pixelId->is_pixel(nextRio->identify());
212 bool ssct = m_sctId->is_sct(nextRio->identify());
213 if( (!pixl) && (!ssct) ) continue;
214 // pixels:
215 for(int i=0;i<m_nbpl;i++) pl[i] = false;
216 for(int i=0;i<m_nbpd;i++) pd[i] = false;
217 if(pixl) {
218 pl[0] = m_pixelId->is_blayer(nextRio->identify());
219 if(m_pixelId->is_barrel(nextRio->identify())) {
220 int player = m_pixelId->layer_disk(nextRio->identify());
221 for(int i=1;i<m_nbpl;i++) pl[i] = ( player == i );
222 } else {
223 int pdisk = m_pixelId->layer_disk(nextRio->identify());
224 for(int i=0;i<m_nbpd;i++) pd[i] = ( pdisk == i );
225 }
226 }
227 // sct:
228 for(int i=0;i<m_nbsl;i++) sl[i] = false;
229 for(int i=0;i<m_nbsd;i++) sd[i] = false;
230 if(ssct) {
231 if(m_sctId->is_barrel(nextRio->identify())) {
232 int slayer = m_sctId->layer_disk(nextRio->identify());
233 for(int i=0;i<m_nbsl;i++) sl[i] = ( slayer == i );
234 } else {
235 int sdisk = m_sctId->layer_disk(nextRio->identify());
236 for(int i=0;i<m_nbsd;i++) sd[i] = ( sdisk == i );
237 }
238 }
239 // loop on 2nd track clusters:
240 const DataVector<const Trk::MeasurementBase>* mb2 = (*trk2->track())->measurementsOnTrack();
243 if (nextMb == mb->begin()) ATH_MSG_VERBOSE("Second track (pT="<<t2p4.Pt()<<") has " << mb2->size() << " RIOs on track");
244 int nriosi = 0;
245 for(; nextMb2 != lastMb2; ++nextMb2) {
246 const Trk::RIO_OnTrack* nextRio2 = dynamic_cast<const Trk::RIO_OnTrack*>(*nextMb2);
247 bool pixl2 = m_pixelId->is_pixel(nextRio2->identify());
248 bool ssct2 = m_sctId->is_sct(nextRio2->identify());
249 if( (!pixl2) && (!ssct2) ) continue;
250 nriosi++;
251 if( nextRio2->identify() == nextRio->identify() ) {
252 ATH_MSG_DEBUG("Shared hit ! Track1 Pt = " << t1p4.Pt() <<" Track2 Pt = " << t2p4.Pt());
253 if (m_qualOrder) {
254 ATH_MSG_VERBOSE("Track1 chi2 = " << chi21 << " nprec = " << nprec1 << " (np,ns) = (" << np1 << " , " << ns1 << ") " << " nhole = " << nh1 << " (nhp,nhs) = (" << nhp1 << " , " << nhs1 << ") " << " quality = " << q1);
255 ATH_MSG_VERBOSE("Track2 chi2 = " << chi22 << " nprec = " << nprec2 << " (np,ns) = (" << np2 << " , " << ns2 << ") " << " nhole = " << nh2 << " (nhp,nhs) = (" << nhp2 << " , " << nhs2 << ") " << " quality = " << q2);
256 }
257 ATH_MSG_DEBUG(pl[0] << " "<< pl[1] << " " << pl[2]);
258 ATH_MSG_DEBUG(pd[0] << " "<< pd[1] << " " << pd[2]);
259 ATH_MSG_DEBUG(sl[0] << " "<< sl[1] << " " << sl[2] << " " << sl[3]);
260 ATH_MSG_DEBUG(sd[0] << " "<< sd[1] << " " << sd[2] << " " << sd[3] << " " << sd[4] << " "<< sd[5] << " " << sd[6] << " " << sd[7] << " " << sd[8]);
261 pairTrkRio p = std::make_pair(*trk1I,nextRio);
262 for(int i=0;i<m_nbpl;i++) {
263 if (pl[i] && std::find(myvecTrkRio.begin(), myvecTrkRio.end(), p) == myvecTrkRio.end()) {m_npl[i]++;myvecTrkRio.push_back(p);}
264 }
265 for(int i=0;i<m_nbpd;i++) {
266 if (pd[i] && std::find(myvecTrkRio.begin(), myvecTrkRio.end(), p) == myvecTrkRio.end()) {m_npd[i]++;myvecTrkRio.push_back(p);}
267 }
268 for(int i=0;i<m_nbsl;i++) {
269 if (sl[i] && std::find(myvecTrkRio.begin(), myvecTrkRio.end(), p) == myvecTrkRio.end()) {m_nsl[i]++;myvecTrkRio.push_back(p);}
270 }
271 for(int i=0;i<m_nbsd;i++) {
272 if (sd[i] && std::find(myvecTrkRio.begin(), myvecTrkRio.end(), p) == myvecTrkRio.end()) {m_nsd[i]++;myvecTrkRio.push_back(p);}
273 }
274 }
275 } // end loop on rio2
276 } // end loop on rio1
277 }
278 } // end loop on trk2
279 // now store the result:
280 if(this->numberSharedBLayer()+this->numberSharedPix()+this->numberSharedSct()>0) {
281 assoc->add( (*trk1I), this->numberSharedBLayer(),
282 this->numberSharedPix(),
283 this->numberSharedSct() );
284 }
285 } // end loop on trk1
286 }
287
288 ATH_MSG_INFO("Size of SharedHitMap: " << assoc->size());
289
290 if (mlog.level() <= MSG::DEBUG) assoc->dump();
291
292 if(evtStore()->record(assoc,m_sharedHitMapLocation,false).isFailure()) {
293 ATH_MSG_ERROR("recording of SharedHitAssoc " << m_sharedHitMapLocation << " failed.");
294 } else {
295 ATH_MSG_VERBOSE("Recording of SharedHitAssoc " << m_sharedHitMapLocation << " succeeded, coll is now const." );
296 }
297
298
299 return StatusCode::SUCCESS;
300}
301
303 return StatusCode::SUCCESS;
304}
305
307 return m_npl[0];
308}
309
311 int nbs = 0;
312 for(int i=0;i<m_nbpl;i++) nbs += m_npl[i];
313 for(int i=0;i<m_nbpd;i++) nbs += m_npd[i];
314 return nbs;
315}
316
318 int nbs = 0;
319 for(int i=0;i<m_nbsl;i++) nbs += m_nsl[i];
320 for(int i=0;i<m_nbsd;i++) nbs += m_nsd[i];
321 return nbs;
322}
323
324
Scalar deltaR(const MatrixBase< Derived > &vec) const
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
This is an Identifier helper class for the Pixel subdetector.
This is an Identifier helper class for the SCT subdetector.
std::vector< pairTrkRio > vecpairTrkRio
std::pair< const xAOD::TrackParticle *, const Trk::RIO_OnTrack * > pairTrkRio
Assoc::const_iterator AssocIter
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Derived DataVector<T>.
Definition DataVector.h:795
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool m_qualOrder
pairs of tracks with dR>dRCut not considered
int m_nsl[m_nbsl]
static const int m_nbsl
const PixelID * m_pixelId
if true use shared info from track summary instead of recomputing them
std::string m_inputTrackCollection
virtual StatusCode execute()
int numberSharedPix() const
int numberSharedSct() const
int m_npl[m_nbpl]
static const int m_nbpl
const SCT_ID * m_sctId
virtual StatusCode initialize()
int m_nsd[m_nbsd]
int m_npd[m_nbpd]
std::string m_sharedHitMapLocation
location of inputTracks in StoreGate
static const int m_nbsd
static const int m_nbpd
double m_deltaRCut
location of sharedHitMap in StoreGate
virtual ~SharedHitMapper()
SharedHitMapper(const std::string &name, ISvcLocator *pSvcLocator)
int numberSharedBLayer() const
virtual StatusCode finalize()
int numberSharedSct(const xAOD::TrackParticle *const trk) const
int numberSharedBLayer(const xAOD::TrackParticle *const trk) const
void add(const xAOD::TrackParticle *const trk, int shPattern)
int numberSharedPix(const xAOD::TrackParticle *const trk) const
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
Identifier identify() const
return the identifier -extends MeasurementBase
TLorentzVector FourMom_t
Definition of the 4-momentum type.
const Trk::Track * track() const
Returns a pointer (which can be NULL) to the Trk::Track which was used to make this TrackParticle.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
@ numberOfPixelHoles
number of pixel layers on track with absence of hits [unit8_t].
@ numberOfInnermostPixelLayerSharedHits
number of Pixel 0th layer barrel hits shared by several tracks.
@ numberOfSCTHits
number of hits in SCT [unit8_t].
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].
@ numberOfPixelSharedHits
number of Pixel all-layer hits shared by several tracks [unit8_t].
@ numberOfSCTSharedHits
number of SCT hits shared by several tracks [unit8_t].
@ numberOfSCTHoles
number of SCT holes [unit8_t].