ATLAS Offline Software
Loading...
Searching...
No Matches
TrigTrackSelector.cxx
Go to the documentation of this file.
1
9
10
13
15
16#include <stdexcept>
17
22
23
24TrigTrackSelector::TrigTrackSelector( TrackFilter* selector, double radius, int selectPdgId, int selectParentPdgId ) :
25 TrackSelector(selector), m_id(0), m_xBeam(0), m_yBeam(0), m_zBeam(0),
26 m_correctTrkTracks(false),
27 m_radius(radius), m_selectPdgId(selectPdgId), m_selectParentPdgId(selectParentPdgId) {
28}
29
30
31
38
40 if ( p==nullptr ) return nullptr;
41 if ( MC::isElectron(p) || MC::isMuon(p) ) return nullptr; //don't want light leptons from eg tau decays - they are found directly
42 if ( p->absPdgId()==pdg_id ) {
43 return p; // recursive stopping conditions
44 }
45 auto vertex = p->prodVtx();
46 if ( vertex == nullptr ) {
47 return nullptr; // has no production vertex !!!
48 }
49 if ( vertex->nIncomingParticles() < 1 ) {
50 return nullptr; // recursive stopping conditions
51 }
52 for( unsigned ip = 0; ip < vertex->nIncomingParticles(); ip++ ) {
53 auto* in = vertex->incomingParticle(ip);
54 auto parent = fromAncestor( pdg_id, in);
55 if ( parent!=nullptr ) {
56 if (parent->absPdgId()==pdg_id) return parent;
57 }
58 }
59
60 return nullptr;
61}
62
63
72
73const xAOD::TruthParticle* TrigTrackSelector::fromAncestor( const std::vector<int>& ids, const xAOD::TruthParticle *p ) const {
74 if ( p==nullptr ) return nullptr;
75 if (MC::isElectron(p) || MC::isMuon(p)) return nullptr; //don't want light leptons from eg tau decays - they are found directly
76 for ( size_t i=ids.size() ; i-- ; ) {
77 if ( p->absPdgId()==ids[i] ) return p; // recursive stopping conditions
78 }
79
80 auto vertex = p->prodVtx();
81 if ( vertex == nullptr ) return nullptr; // has no production vertex !!!
82
83 if ( vertex->nIncomingParticles()<1 ) return nullptr; // recursive stopping conditions
84
85 for( unsigned ip = 0; ip < vertex->nIncomingParticles(); ip++ ) {
86 auto* in = vertex->incomingParticle(ip);
87 auto parent = fromAncestor( ids, in);
88 if ( parent!=nullptr ) {
89 for ( size_t i=ids.size() ; i-- ; ) {
90 if ( parent->absPdgId()==ids[i] ) return parent;
91 }
92 }
93 }
94
95 return nullptr;
96}
97
98
99
106
107// const xAOD::TruthParticle* TrigTrackSelector::fromAncestor(const int pdg_id, const xAOD::TruthParticle *p) const {
108// return fromAncestor( std::vector<int>(1,pdg_id), p );
109// }
110
111
112// extract all the tracks from a TruthParticle collection and add them
114 // std::cout << "\t\t\tSUTT \tTrackParticleContainer->size() = " << trigtracks->size() << std::endl;
115
116 TruthParticleContainer::const_iterator trackitr = truthtracks->begin();
117 TruthParticleContainer::const_iterator trackend = truthtracks->end();
118
119 while ( trackitr!=trackend ) {
120
121 selectTrack( *trackitr );
122
123 ++trackitr;
124
125 } // loop over tracks
126
127}
128
129
133
134void TrigTrackSelector::truthBeamline( const xAOD::TruthParticleContainer* truthtracks, double& x0, double& y0 ) {
135
136 x0 = 0;
137 y0 = 0;
138
140
141 int Nx = 300;
142 int Ny = 300;
143
145 std::vector<double> xpos(Nx,0);
146 std::vector<double> ypos(Ny,0);
147
149 std::vector<int> xn(Nx,0);
150 std::vector<int> yn(Ny,0);
151
152 int xoffset = Nx/2;;
153 int yoffset = Ny/2;
154
155 double deltax = 3.0/Nx;
156 double deltay = 3.0/Ny;
157
159
160 xAOD::TruthParticleContainer::const_iterator trackitr = truthtracks->begin();
161 xAOD::TruthParticleContainer::const_iterator trackend = truthtracks->end();
162
163 for ( ; trackitr!=trackend ; ++trackitr ) {
164
165 const xAOD::TruthParticle* track = (*trackitr);
166
167 if ( !MC::isStable(track) || !track->hasProdVtx() ) continue;
168
170
171 double xp[3] = { track->prodVtx()->x(), track->prodVtx()->y(), track->prodVtx()->z() };
172
174
175 int ix = xp[0]/deltax + xoffset;
176 int iy = xp[1]/deltay + yoffset;
177
178 if ( ix<0 || ix>=Nx || iy<0 || iy>=Nx ) continue;
179
180 xpos[ix] += xp[0];
181 ypos[iy] += xp[1];
182
183 xn[ix]++;
184 yn[iy]++;
185
186 } // loop over tracks
187
189
190 int imx = 0;
191 int imy = 0;
192
193 for ( size_t i=0 ; i<xpos.size() ; i++ ) {
194 if ( xn[i]>xn[imx] ) imx = i;
195 if ( yn[i]>yn[imy] ) imy = i;
196 }
197
201 if ( xn[imx]>1 ) x0 = xpos[imx]/xn[imx];
202 if ( yn[imy]>1 ) y0 = ypos[imy]/yn[imy];
203
204}
205
206
207// extract all the tracks from a xAOD::TruthParticle collection and add them
209
210 xAOD::TruthParticleContainer::const_iterator trackitr = truthtracks->begin();
211 xAOD::TruthParticleContainer::const_iterator trackend = truthtracks->end();
212
214 double x0 = 0;
215 double y0 = 0;
216
217 truthBeamline( truthtracks, x0, y0 );
218
219
220 for ( ; trackitr!=trackend; ++trackitr) {
221
222
223 // Only select charged final state particles
224 double q = (*trackitr)->charge();
225
227 static const particleType ptype;
228 if ( q==-999 ) q = ptype.charge( (*trackitr)->pdgId() );
229
230 if (q == 0 || !MC::isStable(*trackitr) ) continue;
231
232 // If looking for tau parents, don't select mu or e children
233
234 // select based on the pdg of final state particle
235 bool gotPdgId = true;
236 if (m_selectPdgId!=0) gotPdgId = (*trackitr)->absPdgId()==m_selectPdgId;
237
238 // select based on the pdg of the parent or ancestor
239 bool gotParentPdgId = true;
240 if ( gotPdgId && m_selectParentPdgId!=0 ) gotParentPdgId = fromAncestor(m_selectParentPdgId, (*trackitr))!=nullptr;
243
244 if ( gotParentPdgId && gotPdgId ) selectTrack( *trackitr, x0, y0);
245
246 } // loop over tracks
247
248}
249
250
251
252// add a TruthParticle from a GenParticle - easy, bet it doesn't work
254
256 if ( !MC::isStable(track) ) return false;
257
259//AV Using memory to get some value is not a good idea. This is not a repruducible/portable way, but I leave it as is.
260 m_id = (unsigned long)(track.get());
261 bool sel;
262 sel = selectTrack( TruthParticle(track) );
263 m_id = 0;
264
265 return sel;
266
267}
268
269
270// add a TruthParticle
272
273 return selectTrack( &track );
274
275}
276
277
278// add a TruthParticle
280 TIDA::Track* t = makeTrack( track, m_id );
281 if ( t == 0 ) return false;
282 if ( !addTrack(t) ) {
283 delete t;
284 return false;
285 }
286 return true;
287}
288
289
290
291
292// add an xAOD::TruthParticle
293bool TrigTrackSelector::selectTrack( const xAOD::TruthParticle* track, double x0, double y0) {
294 if ( track ) {
295
296 if (!MC::isStable(track) ) return false;
297
299 const xAOD::TruthParticle* measPer = track;
300
301 double pT = measPer->pt();
302 double eta = measPer->eta();
303 double phi = measPer->phi();
304
305 // AAARCH!!!!! the TrackParticle pT is NOT SIGNED!!!! ( I ask you! )
306 if ( measPer->charge()<0 && pT>0 ) pT *= -1;
307 double q = track->charge();
308
309 static const particleType ptype;
310
312 if ( q==-999 ) q = ptype.charge( track->pdgId() );
313
315 if ( q==0 ) return 0;
316
320 // double xbeam = getBeamX(); // track->vx();
321 // double ybeam = getBeamY(); // track->vy();
322 // double zbeam = getBeamZ(); // track->vz();
323
324 if ( !track->hasProdVtx() ) return false;
325
327
328 double xp[3] = { measPer->prodVtx()->x(), measPer->prodVtx()->y(), measPer->prodVtx()->z() };
329 double xb[3] = { xp[0]-x0, xp[1]-y0, measPer->prodVtx()->z() };
330 double xd[3] = { 0, 0, 0 };
331
332 if ( track->hasDecayVtx() ) {
333 xd[0] = track->decayVtx()->x();
334 xd[1] = track->decayVtx()->y();
335 xd[2] = track->decayVtx()->z();
336 }
337
338 double rp = std::sqrt( xp[0]*xp[0] + xp[1]*xp[1] );
339 double rd = std::sqrt( xd[0]*xd[0] + xd[1]*xd[1] );
340
343 double theta = 2*std::atan( std::exp( -eta ) );
344 double z0 = xb[2] - (xb[0]*std::cos(phi) + xb[1]*std::sin(phi))/std::tan(theta);
345 double d0 = xb[1]*std::cos(phi) - xb[0]*std::sin(phi);
346
347 bool final_state = false;
348
360 const double inner_radius = m_radius;
361 const double outer_radius = m_radius;
362
363 if ( ( track->hasProdVtx() && rp<=inner_radius ) &&
364 ( !track->hasDecayVtx() || rd>outer_radius ) ) final_state = true;
365
366 if ( !final_state ) return false;
367
368 double deta = 0;
369 double dphi = 0;
370 double dz0 = 0;
371 double dd0 = 0;
372
373 double dpT = 0;
374
375 int nBlayerHits = 0;
376 int nPixelHits = 0;
377 int nSctHits = 0;
378 int nStrawHits = 0;
379 int nTrtHits = 0;
380
381 double chi2 = 0;
382 double dof = 0;
383
384 bool expectBL = false;
385
386 nSctHits += 0;
387 nPixelHits += 0;
388
390 int nSiHits = 0;
391
392 unsigned long id = (unsigned long)track;
393
394 unsigned bitmap = 0;
395
396 int trackAuthor = track->pdgId();
397 int uniqueID = HepMC::uniqueID(track);
398
399#if 0
400 std::cout << "\t\t\tSUTT TP track"
401 << "\teta=" << eta
402 << "\tphi=" << phi
403 << "\tz0=" << z0
404 << "\tpT=" << pT
405 << "\td0=" << d0
406 << "\tauthor=" << trackAuthor
407 << "\tVTX x " << xp[0]<< "\ty " << xp[1] << "\tz " << xp[2]
408 << std::endl;
409#endif
410
411 // Create and save Track
412
413 TIDA::Track* t = new TIDA::Track( eta, phi, z0, d0, pT, chi2, dof,
414 deta, dphi, dz0, dd0, dpT,
415 nBlayerHits, nPixelHits, nSctHits, nSiHits,
416 nStrawHits, nTrtHits, bitmap, 0,
417 trackAuthor, false, uniqueID, -1,
418 expectBL, id) ;
419
421 // std::cout << "SUTT TP track " << *t << "\t0x" << std::hex << bitmap << std::dec << std::endl;
422
423 // addTrack applies additional cuts using the Filter
424 if ( !addTrack( t ) ){
425 delete t;
426 return false;
427 }
428 }
429 return false;
430
431}
432
433
434
435
436// make a TIDA::Track from a GenParticle
438//AV Using memory to get some value is not a good idea. This is not a repruducible/portable way, but I leave it as is.
439 unsigned long id = (unsigned long)(track.get());
440 TruthParticle t = TruthParticle(track);
441 return makeTrack( &t, id );
442}
443
444// make a TIDA::Track from a TruthParticle
445TIDA::Track* TrigTrackSelector::makeTrack( const TruthParticle* track, unsigned long tid ) {
446
447 if ( track==0 ) return 0;
448 if ( !MC::isStable(track)) return 0;
449
450
451 double phi = track->phi();
452 double eta = track->eta();
453
457 double xp[3] = { 0, 0, 0 };
458
459 if ( track->genParticle()->production_vertex() ) {
460 xp[0] = track->genParticle()->production_vertex()->position().x();
461 xp[1] = track->genParticle()->production_vertex()->position().y();
462 xp[2] = track->genParticle()->production_vertex()->position().z();
463 }
464
465 // CHANGED BY JK - z0 with respect to (0,0)
466 // double z0 = xp[2];
467 double theta = 2*std::atan( exp( (-1)*eta ) );
468 double z0 = xp[2] - (xp[0]*std::cos(phi) + xp[1]*std::sin(phi))/std::tan(theta);
469
470 double xd[3] = { 0, 0, 0 };
471
472 if ( track->genParticle()->end_vertex() ) {
473 xd[0] = track->genParticle()->end_vertex()->position().x();
474 xd[1] = track->genParticle()->end_vertex()->position().y();
475 xd[2] = track->genParticle()->end_vertex()->position().z();
476 }
477
478 double rp = std::sqrt( xp[0]*xp[0] + xp[1]*xp[1] );
479 double rd = std::sqrt( xd[0]*xd[0] + xd[1]*xd[1] );
480
481
482 bool final_state = false;
483
495 const double inner_radius = m_radius;
496 const double outer_radius = m_radius;
497 if ( ( track->genParticle()->production_vertex() && rp<=inner_radius ) &&
498 ( track->genParticle()->end_vertex()==0 || rd>outer_radius ) ) final_state = true;
499
500
501 if ( !final_state ) return 0;
502
513
514 double q = track->charge();
515
516 static const particleType ptype;
517
519 if ( q==-999 ) q = ptype.charge( track->pdgId() );
520
522 if ( q==0 ) return 0;
523
524 double pT = q*track->pt();
525
526
527 double d0 = 0;
528
533
535
536
537 // CHANGED BY JK - d0 with respect to (0,0)
538 // d0 = q*rp*std::sin(phi);
539 d0 = xp[1]*std::cos(phi) - xp[0]*std::sin(phi);
540
541
543
544 double dz0 = 0;
545 double dd0 = 0;
546
547 correctToBeamline( z0, dz0, d0, dd0, theta, phi );
548
549
550
552
554 int author = track->pdgId();
555 int uniqueID = HepMC::uniqueID(track);
556
557
558 unsigned long id = (unsigned long)track;
559 if ( tid!=0 ) id = tid;
560
564
565
567
568 // std::cout << "\t\t\tSUTT Truth track"
569 // << "\teta=" << eta // << " +- " << (*trackitr)->params()->deta()
570 // << "\tphi=" << phi // << " +- " << (*trackitr)->params()->dphi()
571 // << "\tz0=" << z0
572 // << "\tpT=" << pT // << "\t( " << 1/qoverp << ")"
573 // << "\td0=" << d0
574 // << "\tauthor=" << author
575 // << std::endl;
576
577
578
579 TIDA::Track* t = new TIDA::Track(eta, phi, z0, d0, pT, 0, 0,
580 0, 0, 0, 0, 0,
581 0, 0, 0, 0,
582 0, 0, 0, 0,
583 author, false, uniqueID, -1,
584 false,
585 id ) ;
586
587 return t;
588
589}
590
591
592
593// add a Trk::Track
595
596 // do the track extraction stuff here....
597
598 static const int hpmap[20] = { 0, 1, 2, 7, 8, 9, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
599 // std::cout << __FILE__<< " " <<__LINE__<<std::endl;
600
601 if ( track ) {
602
603 // const Trk::Perigee* startPerigee = track->perigeeParameters();
604
605#ifdef TRKPARAMETERS_MEASUREDPERIGEE_H
606 const Trk::MeasuredPerigee* startPerigee = dynamic_cast<const Trk::MeasuredPerigee*>(track->perigeeParameters());
607 // const Trk::MeasuredPerigee* measPer = startPerigee; // just out of laziness
608#else
609 const Trk::Perigee* startPerigee = track->perigeeParameters();
610 const Trk::Perigee* measPer = startPerigee; // just out of laziness
611#endif
612
613
614 // CLHEP::HepVector perigeeParams = measPer->parameters();
615 // double pT = measPer->pT();
616 // double eta = measPer->eta();
617 // double phi = perigeeParams[Trk::phi0];
618 // double z0 = perigeeParams[Trk::z0];
619 // double d0 = perigeeParams[Trk::d0];
620 // // AAARCH!!!!! the TrackParticle pT is NOT SIGNED!!!! ( I ask you! )
621 // if ( perigeeParams[Trk::qOverP]<0 ) pT *= -1;
622 // std::cout <<pT1<<" pt1vspT "<<pT<<std::endl;
623
624 if (startPerigee){
625
626 double theta = startPerigee->parameters()[Trk::theta];
627 double p = 1/startPerigee->parameters()[Trk::qOverP];
628 double qOverPt = startPerigee->parameters()[Trk::qOverP]/std::sin(theta);
629 double charge = startPerigee->charge();
630 double eta = startPerigee->eta();
631 double phi = startPerigee->parameters()[Trk::phi0];
632 double z0 = startPerigee->parameters()[Trk::z0];
633 double d0 = startPerigee->parameters()[Trk::d0];
634 // double pT = (1./qOverPt)*(charge);
635 double pT = (1./qOverPt); // always use signed PT
636
637 if ( charge<0 && pT>0 ) pT *= -1;
638 if ( charge<0 && p>0 ) p *= -1;
639
640
641
642#ifdef TRKPARAMETERS_MEASUREDPERIGEE_H
643 const Trk::ErrorMatrix err = startPerigee->localErrorMatrix();
644 double dtheta = err.error(Trk::theta);
645 double dqovp = err.error(Trk::qOverP);
646 double covthetaOvP = err.covValue(Trk::qOverP,Trk::theta);
647
648 double dphi = err.error(Trk::phi0);
649 double dz0 = err.error(Trk::z0);
650 double dd0 = err.error(Trk::d0);
651#else
652 double dtheta = std::sqrt((*measPer->covariance())(Trk::theta,Trk::theta));
653 double dqovp = std::sqrt((*measPer->covariance())(Trk::qOverP,Trk::qOverP));
654 double covthetaOvP = (*measPer->covariance())(Trk::qOverP,Trk::theta);
655
656 double dphi = std::sqrt((*measPer->covariance())(Trk::phi0,Trk::phi0));
657 double dz0 = std::sqrt((*measPer->covariance())(Trk::z0,Trk::z0));
658 double dd0 = std::sqrt((*measPer->covariance())(Trk::d0,Trk::d0));
659#endif
660
661 double deta = 0.5*dtheta/(std::cos(0.5*theta)*std::cos(0.5*theta)*std::tan(0.5*theta));
662
663
664 if ( m_correctTrkTracks ) correctToBeamline( z0, dz0, d0, dd0, theta, phi );
665
666 double dpT = 0;
667
668
669 double sintheta = std::sin(theta);
670 double costheta = std::cos(theta);
671 double dpT2 = (p*p*sintheta)*(p*p*sintheta)*dqovp*dqovp + (p*costheta)*(p*costheta)*dtheta*dtheta - 2*(p*p*sintheta)*(p*costheta)*covthetaOvP;
672
673 if ( dpT2>0 ) dpT = std::sqrt( dpT2 );
674
675 // Check number of hits
676 // NB: a spacepoint is two offline "hits", so a pixel spacepoint is really
677 // 2 "hits" and an offline SCT "hit" is really a 1D cluster, so two intersetcting
678 // stereo clusters making a spacepoint are two "hits"
679 // const Trk::TrackSummary *summary = dynamic_cast<const Trk::TrackSummary*>(track->trackSummary());
680 //ToolHandle< Trk::ITrackSummaryTool > m_trackSumTool;
681 //m_trackSumTool = ToolHandle<Trk::ITrackSummaryTool>("Trk::TrackSummaryTool/InDetTrackSummaryTool");
682 //const Trk::TrackSummary* summary = NULL;
683 //summary = m_trackSumTool->createSummary(*track);
684
685 const Trk::TrackSummary * summary = track->trackSummary();
686 int nBlayerHits = 0;
687 int nPixelHits = 0;
688 int nSctHits = 0;
689 int nStrawHits = 0;
690 int nTrHits = 0;
691 int nSiHits = 0;
692 bool expectBL = false; // Not stored for Trk::Track
693 unsigned bitmap = 0;
694
695 if(summary==0){
696 std::cerr << "Could not create TrackSummary - Track will likely fail hits requirements" << std::endl;
697 }
698 else{
699 nBlayerHits = 2*summary->get(Trk::numberOfBLayerHits);
700 nPixelHits = 2*summary->get(Trk::numberOfPixelHits);
701 nSctHits = summary->get(Trk::numberOfSCTHits);
702 nStrawHits = summary->get(Trk::numberOfTRTHits);
703 nTrHits = summary->get(Trk::numberOfTRTHighThresholdHits);
704 nSiHits = nPixelHits + nSctHits;
705
706 for ( int ih=0 ; ih<20 ; ih++ ) {
707 if ( summary->isHit(Trk::DetectorType(ih)) ) bitmap |= ( 1<<hpmap[ih] );
708 }
709 }
710
711 unsigned long id = (unsigned long)track;
712 double chi2 = 0;
713 double dof = 0;
714 //const Trk::FitQuality *quality = dynamic_cast<const Trk::FitQuality*>(track->fitQuality());
715 const Trk::FitQuality *quality = (track->fitQuality());
716 if(quality==0) std::cerr << "Could not create FitQuality - Track will likely fail hits requirements" << std::endl;
717 else{
718 chi2 = quality->chiSquared();
719 dof = quality->numberDoF();
720 }
721
722 int trackAuthor = -1;
723
726
727 // std::cout << "fetching author info :" << track->info().trackFitter() << ":"
728 // << track->info().dumpInfo() << ": bm 0x" << std::hex << bitmap << std::dec << std::endl;
729
730 int fitter = track->info().trackFitter();
731 // std::string dumpinfo = track->info().dumpInfo();
732
733 if ( fitter>0 && fitter<Trk::TrackInfo::NumberOfTrackFitters ) {
734 if ((track->info().dumpInfo()).find("TRTStandalone") != std::string::npos) trackAuthor = 2;
735 else if ((track->info().dumpInfo()).find("TRTSeededTrackFinder") != std::string::npos) trackAuthor = 1;
736 else trackAuthor = 0;
737 }
738
739 #if 0
740 std::cout << "\t\t\tSUTT TP track"
741 << "\teta=" << eta // << " +- " << (*trackitr)->params()->deta()
742 << "\tphi=" << phi // << " +- " << (*trackitr)->params()->dphi()
743 << "\tz0=" << z0
744 << "\tpT=" << pT // << "\t( " << 1/qoverp << ")"
745 << "\td0=" << d0
746 << "\tNsi=" << nSiHits
747 << "\tNtrt=" << nTrHits
748 << "\tNstr=" << nStrawHits
749 << "\tauthor=" << trackAuthor
750 << std::endl;
751 #endif
752 // Create and save Track
753 TIDA::Track* t = new TIDA::Track(eta, phi, z0, d0, pT, chi2, dof,
754 deta, dphi, dz0, dd0, dpT,
755 nBlayerHits, nPixelHits, nSctHits, nSiHits,
756 nStrawHits, nTrHits, bitmap, 0,
757 trackAuthor, false, -1, -1,
758 expectBL, id) ;
759
760 if ( !addTrack( t ) ){
761 delete t;
762 return false;
763 }
764 return true;
765
766 //std::cout << "SUTT TP track " << *t << "\t0x" << std::hex << bitmap << std::dec << std::endl;
767 }
768 }
769
770 return false;
771}
772
773// extract all the tracks from a TrackCollection and add them
775
776 // std::cout << "\t\t\tSUTT \tTrackContainer->size() = " << trigtracks->size() << std::endl;
777
778 TrackCollection::const_iterator trackitr = trigtracks->begin();
779 TrackCollection::const_iterator trackend = trigtracks->end();
780
781 while ( trackitr!=trackend ) {
782 selectTrack( *trackitr );
783 ++trackitr;
784 } // loop over tracks
785
786}
787
788
789
791 // do the track extraction stuff here....
792
793 // static int hpmap[20] = { 0, 1, 2, 7, 8, 9, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
794
795 if ( track ) {
796
798 const xAOD::TrackParticle* measPer = track;
799
800 // CLHEP::HepVector perigeeParams = measPer->parameters();
801
802 double pT = measPer->pt();
803 double eta = measPer->eta();
804 double phi = measPer->phi0();
805 double z0 = measPer->z0() + measPer->vz();
806 double d0 = measPer->d0();
807
808 double theta = measPer->theta();
809
814 // if ( measPer->qOverP()==0 ) return false;
815 if ( measPer->qOverP()==0 ) throw std::runtime_error( "probable corrupted track - this should never happen" );
816 double p = 1/measPer->qOverP();
817
818 // AAARCH!!!!! the TrackParticle pT is NOT SIGNED!!!! ( I ask you! )
819 if ( measPer->qOverP()<0 && pT>0 ) pT *= -1;
820
821 double dtheta = std::sqrt(measPer->definingParametersCovMatrix()(Trk::theta,Trk::theta));
822 double dqovp = std::sqrt(measPer->definingParametersCovMatrix()(Trk::qOverP,Trk::qOverP));
823 double covthetaOvP = measPer->definingParametersCovMatrix()(Trk::qOverP,Trk::theta);
824
825 double deta = 0.5*dtheta/(std::cos(0.5*theta)*std::cos(0.5*theta)*std::tan(0.5*theta)); // ???? CHECK THIS <<--
826
827 double dphi = std::sqrt(measPer->definingParametersCovMatrix()(Trk::phi0,Trk::phi0));
828 double dz0 = std::sqrt(measPer->definingParametersCovMatrix()(Trk::z0,Trk::z0));
829 double dd0 = std::sqrt(measPer->definingParametersCovMatrix()(Trk::d0,Trk::d0));
830
831 double dpT = 0;
832
833
835 // if ( m_xBeam!=0 || m_yBeam!=0 ) correctToBeamline( z0, dz0, d0, dd0, theta, phi );
836
837
838 double sintheta = std::sin(theta);
839 double costheta = std::cos(theta);
840 double dpt2 = (p*p*sintheta)*(p*p*sintheta)*dqovp*dqovp + (p*costheta)*(p*costheta)*dtheta*dtheta - 2*(p*p*sintheta)*(p*costheta)*covthetaOvP;
841
842 if ( dpt2>0 ) dpT = std::sqrt( dpt2 );
843
844 // Check number of hits
845 // NB: a spacepoint is two offline "hits", so a pixel spacepoint is really
846 // 2 "hits" and an offline SCT "hit" is really a 1D cluster, so two intersetcting
847 // stereo clusters making a spacepoint are two "hits"
848
849 uint8_t sum_nBlayerHits = 0;
850 track->summaryValue( sum_nBlayerHits, xAOD::numberOfInnermostPixelLayerHits);
851 int nBlayerHits = 2*sum_nBlayerHits;
852
853 uint8_t sum_nPixelHits = 0;
854 track->summaryValue( sum_nPixelHits, xAOD::numberOfPixelHits);
855 int nPixelHits = 2*sum_nPixelHits;
856
857 uint8_t sum_nSctHits = 0;
858 track->summaryValue( sum_nSctHits, xAOD::numberOfSCTHits);
859 int nSctHits = sum_nSctHits;
860
861 uint8_t sum_nStrawHits = 0;
862 track->summaryValue( sum_nStrawHits, xAOD::numberOfTRTHits);
863 int nStrawHits = sum_nStrawHits;
864
865 uint8_t sum_nTrtHits = 0;
866 track->summaryValue( sum_nTrtHits, xAOD::numberOfTRTHighThresholdHits);
867 int nTrtHits = sum_nTrtHits;
868
869
870 uint8_t sum_expectBL = 0;
871 track->summaryValue( sum_expectBL, xAOD::expectInnermostPixelLayerHit);
872 bool expectBL = ( sum_expectBL ? true : false );
873
875
876 uint8_t sum_sctholes = 0;
877 track->summaryValue( sum_sctholes, xAOD::numberOfSCTHoles);
878
879 uint8_t sum_pixholes = 0;
880 track->summaryValue( sum_pixholes, xAOD::numberOfPixelHoles);
881
885
886 nSctHits += 1000*sum_sctholes;
887 nPixelHits += 1000*sum_pixholes;
888
890 int nSiHits = nPixelHits + nSctHits;
891
893
894 double chi2 = track->chiSquared();
895 double dof = track->numberDoF();
896
897 unsigned long id = (unsigned long)track;
898
899 unsigned bitmap = track->hitPattern();
900
901
902
903 double xbeam = track->vx();
904 double ybeam = track->vy();
905 double zbeam = track->vz();
906
907 if ( xbeam!=getBeamX() || ybeam!=getBeamY() || zbeam!=getBeamZ() ) setBeamline( xbeam, ybeam, zbeam );
908
909 int trackAuthor = 0;
910
911 int fitter = track->trackFitter();
912 std::bitset<xAOD::NumberOfTrackRecoInfo> patternrec = track->patternRecoInfo();
913
914 //int icount = 0;<- never used if section below is commented
915 for ( unsigned ipr=patternrec.size() ; ipr-- ; ) {
916 if ( patternrec[ipr] ) {
917 //icount++; <- never used if section below is commented
918 trackAuthor |= (ipr >> 16);
919 // static bool first = true;
920 // if ( first && icount>1 ) {
921 // std::cerr << "more than one pattern rec strategy " << ipr << "\t(suppressing further output)" << std::endl;
922 // first = false;
923 // }
924 }
925 }
926
927 trackAuthor |= fitter;
928
929 // if ( fitter>0 && fitter<Trk::TrackInfo::NumberOfTrackFitters ) {
930 // if ( dumpinfo.find("TRTStandalone")!=std::string::npos) trackAuthor = 2;
931 // else if ( dumpinfo.find("TRTSeededTrackFinder")!=std::string::npos) trackAuthor = 1;
932 // else trackAuthor = 0;
933 // }
934
935#if 0
936 std::cout << "\t\t\tSUTT TP track"
937 << "\teta=" << eta // << " +- " << (*trackitr)->params()->deta()
938 << "\tphi=" << phi // << " +- " << (*trackitr)->params()->dphi()
939 << "\tz0=" << z0
940 << "\tpT=" << pT // << "\t( " << 1/qoverp << ")"
941 << "\td0=" << d0
942 << "\tNsi=" << nSiHits
943 // << "\tNtrt=" << nTrtHits
944 // << "\tNstr=" << nStrawHits
945 << "\tfitter=" << fitter
946 << "\tauthor=" << trackAuthor
947 << "\tVTX x " << track->vx() << "\ty " << track->vy() << "\tz " << track->vz()
948 << std::endl;
949#endif
950
951 // Create and save Track
952
953 TIDA::Track* t = new TIDA::Track( eta, phi, z0, d0, pT, chi2, dof,
954 deta, dphi, dz0, dd0, dpT,
955 nBlayerHits, nPixelHits, nSctHits, nSiHits,
956 nStrawHits, nTrtHits, bitmap, 0,
957 trackAuthor, false, -1, -1,
958 expectBL, id) ;
959
960 // std::cout << "SUTT TP track " << *t << "\t0x" << std::hex << bitmap << std::dec << std::endl;
961
962 if ( !addTrack( t ) ){
963 delete t;
964 return false;
965 }
966 return true;
967
968 }
969 return false;
970
971
972}
973
974
976 // std::cout << "\t\t\tSUTT \tTrackContainer->size() = " << trigtracks->size() << std::endl;
979 while ( trackitr!=trackend ) {
980 selectTrack( *trackitr );
981 ++trackitr;
982 } // loop over tracks
983}
984
985
986
991 // std::cout << "\t\t\tSUTT \tTrackContainer->size() = " << trigtracks->size() << std::endl;
992 while ( trackitr!=trackend ) {
993 selectTrack( *trackitr );
994 ++trackitr;
995 } // loop over tracks
996}
997
998
1000 for( const auto& track : tracks ) selectTrack( *track );
1001}
1002
1003
1004
1005
1006
1007void TrigTrackSelector::correctToBeamline( double& z0, double& dz0,
1008 double& d0, double& dd0,
1009 double theta, double phi ) {
1010
1012
1013 // if ( m_first ) {
1014 // if ( m_xBeam==0 && m_yBeam==0 ) {
1015 // std::cerr << "TrigTrackSelector::correctToBeamline() WARNING -- Beamline set to (0,0) -- WARNING" << std::endl;
1016 // }
1017 // else {
1018 // std::cout << "TrigTrackSelector::correctToBeamline() Beamline set to " << m_xBeam << " " << m_yBeam << std::endl;
1019 // }
1020 // m_first = false;
1021 // }
1022
1023
1024 // double theta = 2*std::atan( exp( (-1)*eta ) );
1025 double z0t = z0 + ((std::cos(phi)*m_xBeam + std::sin(phi)*m_yBeam)/std::tan(theta));
1026 double a0t = d0 + std::sin(phi)*m_xBeam - std::cos(phi)*m_yBeam;
1027
1029 double dz0t = dz0 + ((std::cos(phi)*m_xBeam + std::sin(phi)*m_yBeam)/std::tan(theta));
1030 double da0t = dd0 + std::sin(phi)*m_xBeam - std::cos(phi)*m_yBeam;
1031
1032 z0 = z0t;
1033 d0 = a0t;
1034
1035 dz0 = dz0t;
1036 dd0 = da0t;
1037}
1038
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Scalar theta() const
theta method
double charge(const T &p)
Definition AtlasPID.h:999
ATLAS-specific HepMC functions.
ReadCards * rp
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:861
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.
virtual bool addTrack(TIDA::Track *t, bool(*f)(const TIDA::Track *)=0)
const std::vector< TIDA::Track * > & tracks() const
void setBeamline(double x, double y, double z=0)
const xAOD::TruthParticle * fromAncestor(const int pdg_id, const xAOD::TruthParticle *p) const
recursive functions to identify whether a particle comes from some particle of a specific PDG ID,...
bool selectTrack(HepMC::ConstGenParticlePtr track)
double getBeamY() const
void truthBeamline(const xAOD::TruthParticleContainer *truthtracks, double &x0, double &y0)
extract all the tracks from a xAOD::TruthParticle collection and histogram the x and y production coo...
double getBeamX() const
TrigTrackSelector(TrackFilter *selector)
use a radius of 47 mm corresponding to the Run 1 pixel inner radius For the IBL it should be 32 mm,...
TIDA::Track * makeTrack(HepMC::ConstGenParticlePtr track)
double getBeamZ() const
void correctToBeamline(double &z0, double &dz0, double &d0, double &dd0, double theta, double phi)
void selectTracks(const TruthParticleContainer *truthtracks)
neater code to make use of vector function also for a single ancestor pdgid, instead of the full code...
static const double s_default_radius
NB: This was 47 for Run 2, but with the addition of the IBL it should be 32 It was kept at 47 for all...
std::vector< ElementLink< xAOD::TrackParticleContainer > > TrackParticleLinks_t
Class to represent and store fit qualities from track reconstruction in terms of and number of degre...
Definition FitQuality.h:97
int numberDoF() const
returns the number of degrees of freedom of the overall track or vertex fit as integer
Definition FitQuality.h:60
double chiSquared() const
returns the of the overall track fit
Definition FitQuality.h:56
double eta() const
Access method for pseudorapidity - from momentum.
double charge() const
Returns the charge.
A summary of the information contained by a track.
double charge(int id) const
float z0() const
Returns the parameter.
float theta() const
Returns the parameter, which has range 0 to .
const ParametersCovMatrix_t definingParametersCovMatrix() const
Returns the 5x5 symmetric matrix containing the defining parameters covariance matrix.
float vz() const
The z origin for the parameters.
float d0() const
Returns the parameter.
float qOverP() const
Returns the parameter.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
float phi0() const
Returns the parameter, which has range to .
virtual double pt() const override final
The transverse momentum ( ) of the particle.
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
double charge() const
Physical charge.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
virtual double phi() const override final
The azimuthal angle ( ) of the particle.
float z() const
Vertex longitudinal distance along the beam line form the origin.
float y() const
Vertex y displacement.
float x() const
Vertex x displacement.
Definition zbeam.h:24
double chi2(TH1 *h0, TH1 *h1)
int uniqueID(const T &p)
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
bool isElectron(const T &p)
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isMuon(const T &p)
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
Perigee MeasuredPerigee
@ phi0
Definition ParamDefs.h:65
@ theta
Definition ParamDefs.h:66
@ qOverP
perigee
Definition ParamDefs.h:67
@ d0
Definition ParamDefs.h:63
@ z0
Definition ParamDefs.h:64
DetectorType
enumerates the various detector types currently accessible from the isHit() method.
@ numberOfPixelHits
number of pixel layers on track with absence of hits
@ numberOfBLayerHits
these are the hits in the 0th pixel layer?
@ numberOfTRTHighThresholdHits
total number of TRT hits which pass the high threshold
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
@ expectInnermostPixelLayerHit
Do we expect a 0th-layer barrel hit for this track?
@ numberOfPixelHoles
number of pixel layers on track with absence of hits [unit8_t].
@ numberOfTRTHits
number of TRT hits [unit8_t].
@ numberOfSCTHits
number of hits in SCT [unit8_t].
@ numberOfInnermostPixelLayerHits
these are the hits in the 0th pixel barrel layer
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].
@ numberOfTRTHighThresholdHits
number of TRT hits which pass the high threshold (only xenon counted) [unit8_t].
@ numberOfSCTHoles
number of SCT holes [unit8_t].
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.