ATLAS Offline Software
Loading...
Searching...
No Matches
SegmentDriftCircleAssValidation.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#include "GaudiKernel/MsgStream.h"
6#include "GaudiKernel/DataSvc.h"
7#include "GaudiKernel/SmartDataPtr.h"
8
9#include "TrkTrack/Track.h"
11
13
16
19
20// ReadHandle
22
24
25using HepGeom::Point3D;
26
28// Constructor
30
31InDet::SegmentDriftCircleAssValidation::SegmentDriftCircleAssValidation (const std::string& name,ISvcLocator* pSvcLocator) :
32 AthAlgorithm(name,pSvcLocator),
33 m_nprint (0),
34 m_tcut (0.),
35 m_events (0),
36 m_ncircles (0),
37 m_nqsegments (0)
38{
39
40 // SegmentDriftCircleAssValidation steering parameters
41 //
42 m_pTmin = 500. ;
43 m_rapcut = 2.1 ;
44 m_dccut = 10 ;
45 m_rmin = 0. ;
46 m_rmax = 20. ;
47
48 declareProperty("pTmin", m_pTmin );
49 declareProperty("Pseudorapidity", m_rapcut );
50 declareProperty("MinNumberDCs" , m_dccut );
51 declareProperty("RadiusMin", m_rmin );
52 declareProperty("RadiusMax", m_rmax );
53}
54
56// Initialisation
58
60{
61
62 StatusCode sc;
63
64 m_tcut = 1./tan(2.*atan(exp(-m_rapcut)));
65
66 // Get output print level
67 //
68 if(msgLvl(MSG::DEBUG)){m_nprint=0; msg(MSG::DEBUG) << (*this) << endmsg;}
69
70 // Erase statistics information
71 //
72 m_events = 0 ;
73
74 for(int i=0; i!=5; ++i) m_efficiency[i] = 0;
75
76 // Initialize ReadHandleKey
77 ATH_CHECK( m_origtrackKey.initialize() );
78 ATH_CHECK( m_PRDTruthTRTKey.initialize() );
79 ATH_CHECK( m_circlesTRTKey.initialize() );
80
81 return sc;
82}
83
85// Execute
87
89{
90 msg(MSG::DEBUG) << " InDetSegmentDriftCircleAssValidation execute()" << endmsg;
91
93
94 if( !origColTracks.isValid() ){
95 msg(MSG::FATAL) << "No TRT tracks with name " << m_origtrackKey.key() << " found in StoreGate!" << endmsg;
96 return StatusCode::FAILURE;
97 }else{
98 msg(MSG::DEBUG) << "Found TRT trak collection " << m_origtrackKey.key() << " in StoreGate!" << endmsg;
99 }
100
102
103 if ( !prdCollection.isValid() ){
104 msg(MSG::FATAL) << "TRT PRD_MultiTruthCollection " << m_PRDTruthTRTKey.key() << " NOT found!" << endmsg;
105 return StatusCode::FAILURE;
106 } else {
107 msg(MSG::DEBUG) << "Got TRT PRD_MultiTruthCollection " << m_PRDTruthTRTKey.key() << endmsg;
108 }
109
110 newCirclesEvent( prdCollection.cptr() );
112
113 tracksComparison( origColTracks.cptr(), prdCollection.cptr() );
114
115 if(m_particles.size() > 0) {
116
118
119 }
120
121 if(msgLvl(MSG::DEBUG)){m_nprint=1; msg(MSG::DEBUG) << (*this) << endmsg;}
122
123 return StatusCode::SUCCESS;
124}
125
127// Finalize
129
131
132 if(m_events<=0) return StatusCode::SUCCESS;
133
134 std::cout<<"|-----------------------------------------------------------------------------------|"
135 <<std::endl;
136 std::cout<<"| TrackSegmentValidation statistics"<<std::endl;
137
138 double ne = double(m_events);
139 double ef[5]; for(int i=0; i!=5; ++i) ef[i] = double(m_efficiency[i])/ne;
140
141 std::cout<<"|-----------------------------------------------------------------------------------|"
142 <<std::endl;
143 std::cout<<"| TRT Particles >0.9 >0.75 >0.50 >0.25 <=0.25 |"
144 <<std::endl;
145 std::cout<<"|-----------------------------------------------------------------------------------|"
146 <<std::endl;
147
148 std::cout<<"| "
149 <<std::setw(6)<<m_events<<" "
150 <<std::setw(13)<<std::setprecision(5)<<ef[0]
151 <<std::setw(13)<<std::setprecision(5)<<ef[1]
152 <<std::setw(13)<<std::setprecision(5)<<ef[2]
153 <<std::setw(13)<<std::setprecision(5)<<ef[3]
154 <<std::setw(13)<<std::setprecision(5)<<ef[4]<<" |"
155 <<std::endl;
156 std::cout<<"|-----------------------------------------------------------------------------------|"
157 <<std::endl;
158
159 return StatusCode::SUCCESS;
160}
161
163// Overload of << operator MsgStream
165
166MsgStream& InDet::operator <<
167 (MsgStream& sl,const InDet::SegmentDriftCircleAssValidation& se)
168{
169 return se.dump(sl);
170}
171
173// Overload of << operator std::ostream
175
176std::ostream& InDet::operator <<
177 (std::ostream& sl,const InDet::SegmentDriftCircleAssValidation& se)
178{
179 return se.dump(sl);
180}
181
183// Dumps relevant information into the MsgStream
185
186MsgStream& InDet::SegmentDriftCircleAssValidation::dump( MsgStream& out ) const
187{
188 out<<std::endl;
189 if(m_nprint) return dumpevent(out);
190 return dumptools(out);
191}
192
194// Dumps conditions information into the MsgStream
196
198{
199 int n;
200
201 out<<"|----------------------------------------------------------------"
202 <<"----------------------------------------------------|"
203 <<std::endl;
204 n = 65-m_origtrackKey.key().size();
205 std::string s1; for(int i=0; i<n; ++i) s1.append(" "); s1.append("|");
206 n = 65-m_circlesTRTKey.key().size();
207 std::string s2; for(int i=0; i<n; ++i) s2.append(" "); s2.append("|");
208 n = 65-m_PRDTruthTRTKey.key().size();
209 std::string s3; for(int i=0; i<n; ++i) s3.append(" "); s3.append("|");
210
211 out<<"| Location of input segmentss | "<<m_origtrackKey.key() <<s1
212 <<std::endl;
213 out<<"| TRT clusters | "<<m_circlesTRTKey.key() <<s2
214 <<std::endl;
215 out<<"| Truth location for trt | "<<m_PRDTruthTRTKey.key() <<s3
216 <<std::endl;
217 out<<"| pT cut | "
218 <<std::setw(14)<<std::setprecision(5)<<m_pTmin
219 <<" |"
220 <<std::endl;
221 out<<"| rapidity cut | "
222 <<std::setw(14)<<std::setprecision(5)<<m_rapcut
223 <<" |"
224 <<std::endl;
225 out<<"| min Radius | "
226 <<std::setw(14)<<std::setprecision(5)<<m_rmin
227 <<" |"
228 <<std::endl;
229 out<<"| max Radius | "
230 <<std::setw(14)<<std::setprecision(5)<<m_rmax
231 <<" |"
232 <<std::endl;
233 out<<"| Min. number drift circles for generated segment | "
234 <<std::setw(14)<<std::setprecision(5)<<m_dccut
235 <<" |"
236 <<std::endl;
237 out<<"|----------------------------------------------------------------"
238 <<"----------------------------------------------------|"
239 <<std::endl;
240
241 return out;
242}
243
245// Dumps event information into the ostream
247
249{
250 out<<"|---------------------------------------------------------------------|"
251 <<std::endl;
252 out<<"| TRT Drift Circles | "
253 <<std::setw(12)<<m_ncircles
254 <<" |"<<std::endl;
255 out<<"| Good TRT particles size | "
256 <<std::setw(12)<<m_particles.size()
257 <<" |"<<std::endl;
258 out<<"| Number good kine segments | "
259 <<std::setw(12)<<m_nqsegments
260 <<" |"<<std::endl;
261 out<<"|---------------------------------------------------------------------|"
262 <<std::endl;
263
264 return out;
265}
266
268// Dumps relevant information into the ostream
270
271std::ostream& InDet::SegmentDriftCircleAssValidation::dump( std::ostream& out ) const
272{
273 return out;
274}
275
277// New event for drift circles information
279
281{
282 m_ncircles = 0;
283 m_kinecircle.clear();
284 m_allBarcodes.clear();
285
286 // Get Drift Circles container
287 //
289
290 // Loop through all pixel clusters
291 //
292 if( trtcontainer.isValid() ) {
293
294 InDet::TRT_DriftCircleContainer::const_iterator w = trtcontainer->begin();
295 InDet::TRT_DriftCircleContainer::const_iterator we = trtcontainer->end ();
296
297 for(; w!=we; ++w) {
298
299 InDet::TRT_DriftCircleCollection::const_iterator c = (*w)->begin();
300 InDet::TRT_DriftCircleCollection::const_iterator ce = (*w)->end ();
301
302 for(; c!=ce; ++c) {
303
304 ++m_ncircles;
305
306 std::list<int> lk = kine((*c), prdCollection );
307 if(int(lk.size())==0) continue;
308 std::list<int>::iterator ik,ike=lk.end();
309 for(ik=lk.begin();ik!=ike;++ik){
310 if(!isTheSameStrawElement((*ik),(*c))) {
311 m_kinecircle.insert(std::make_pair((*ik),(*c)));
312 bool isThere = false;
313 std::list<int>::iterator ii, iie=m_allBarcodes.end();
314 for(ii=m_allBarcodes.begin();ii!=iie;++ii) {
315 if((*ik)==(*ii)) isThere = true;
316 }
317 if(!isThere) m_allBarcodes.push_back((*ik));
318 }
319 }
320 }
321 }
322 }
323}
324
326// Good kine segments selection
328
330{
331 m_particles.clear();
332 m_allParticles.clear();
333
334 if (m_kinecircle.empty()) return 0;
335
336 std::list<int>::iterator ii,iie=m_allBarcodes.end();
337 for(ii=m_allBarcodes.begin();ii!=iie;++ii) {
338 int ndc = 0;
339 std::multimap<int,const Trk::PrepRawData*>::iterator dc = m_kinecircle .begin();
340 for(; dc!=m_kinecircle.end(); ++dc) {
341 if((*ii)==(*dc).first) ndc++;
342 }
343 m_allParticles.insert(std::make_pair((*ii),ndc));
344 }
345
346 int t = 0;
347 std::multimap<int,int>::iterator im, ime=m_allParticles.end();
348 for(im=m_allParticles.begin(); im!=ime; ++im) {
349 if((*im).second>=m_dccut){
350 m_particles.push_back((*im).first);
351 ++t;
352 }else{
353 m_kinecircle.erase((*im).first);
354 }
355 }
356
357 return t;
358}
359
361// Recontructed segment comparison with kine information
363
365{
366 if(!m_nqsegments) return;
367
368 m_tracks.clear();
369
370 int KINE[200],NKINE[200];
371 for(int i=0;i<200;++i){
372 KINE[i] =0; NKINE[i] = 0;
373 }
374
375 Trk::SegmentCollection::const_iterator iseg = origColTracks->begin();
376 Trk::SegmentCollection::const_iterator isegEnd = origColTracks->end();
377 for(; iseg != isegEnd; ++ iseg) {
378
380 const Trk::TrackSegment *tS = dynamic_cast<const Trk::TrackSegment*>(*iseg);
381 if(!tS) continue;
382
383 int NK = 0;
384
385 for(int it=0; it<int(tS->numberOfMeasurementBases()); ++it){
386 //test if it is a pseudo measurement
387 if ( dynamic_cast<const Trk::PseudoMeasurementOnTrack*>(tS->measurement(it)) ) continue;
388
389 const InDet::TRT_DriftCircleOnTrack* trtcircle = dynamic_cast<const InDet::TRT_DriftCircleOnTrack*>(tS->measurement(it));
390 if(!trtcircle) continue;
391
392 const InDet::TRT_DriftCircle* RawDataClus=dynamic_cast<const InDet::TRT_DriftCircle*>(trtcircle->prepRawData());
393 if(!RawDataClus) continue;
394
395 std::list<PRD_MultiTruthCollection::const_iterator> lk = kinpart(RawDataClus, prdCollection );
396 if (int(lk.size())==0) continue;
397 std::list<PRD_MultiTruthCollection::const_iterator>::iterator ik, ike=lk.end();
398
399 //* looping over the returned list of genParticles
400 for(ik=lk.begin(); ik!=ike; ++ik){
401 const int uniqueID = HepMC::uniqueID((*ik)->second);
402 if (uniqueID<=0) continue;
403 int m = -1;
404
405 for(int n=0; n!=NK; ++n) {
406 if(uniqueID==KINE[n]) {
407 ++NKINE[n];
408 m=n;
409 break;
410 }
411 }
412
413 if(m<0) {
414 KINE[NK] = uniqueID;
415 NKINE[NK] = 1;
416 if(NK < 200) ++NK;
417 }
418 }
419 }
420 int nm = 0, m = 0;
421 for(int n=0; n!=NK; ++n) {
422 if(NKINE[n] > m) {
423 nm = n;
424 m=NKINE[n];
425 }
426 }
427 m_tracks.insert(std::make_pair(KINE[nm],m) ); //* if m=0, the KINE[nm] will be set to the previous one
428 }
429}
430
432// Particles and reconstructed segments comparision
434
436{
437 if(m_particles.empty()) return;
438 std::multimap<int,int>::iterator t, te = m_tracks.end();
439
440 for (auto k: m_particles) {
441
442 std::multimap<int,int>::iterator im = m_allParticles.find(k);
443 int n = (*im).second;
444
445 int m = 0;
446 t = m_tracks.find(k);
447 for(; t!=te; ++t) { //* check if reaching the end of the multimap instead
448 if((*t).first!=k) break;
449 if((*t).second > m) m = (*t).second;
450 }
451 int d = 0;
452 double rd = (double)m/n; if(rd>0.9) d = 0;
453 else if(rd > 0.75) d=1;
454 else if(rd > 0.50) d=2;
455 else if(rd > 0.25) d=3;
456 else if(rd <= 0.25) d=4;
457 ++m_efficiency[d]; ++m_events;
458 }
459
460}
461
463// Pointer to particle production for drift circle
465
467(const InDet::TRT_DriftCircle* d, const PRD_MultiTruthCollection* prdCollection )
468{
469 std::list<int> lk;
470 bool find;
471 std::list<PRD_MultiTruthCollection::const_iterator> mc = findTruth(d,find, prdCollection );
472 if(!find) return lk;
473 std::list<PRD_MultiTruthCollection::const_iterator>::iterator imc, imce=mc.end();
474 for(imc=mc.begin();imc!=imce;++imc){
475 const int uniqueID = HepMC::uniqueID((*imc)->second); if(uniqueID<=0) continue;
476
477 HepMC::ConstGenParticlePtr pa = (*imc)->second.cptr();
478 if(!pa || !pa->production_vertex()) continue;
479
480 // Charge != 0 test
481 //
482 int pdg = pa->pdg_id();
483 if (MC::isNucleus(pdg)) continue; // ignore nuclei from hadronic interactions
484 if(std::abs(MC::charge(pdg)) < .5) continue;
485
486 // pT cut
487 //
488 double pt = pa->momentum().perp();
489 if( pt < m_pTmin ) continue;
490
491 // Rapidity cut
492 //
493 double t = std::abs(pa->momentum().pz())/pt;
494 if( t > m_tcut ) continue;
495
496 // Radius cut
497 //
498 Point3D<double> v(pa->production_vertex()->position().x(),
499 pa->production_vertex()->position().y(),
500 pa->production_vertex()->position().z());
501 double r = sqrt(v.x()*v.x()+v.y()*v.y());
502 if( r < m_rmin || r > m_rmax) continue;
503
504 lk.push_back(uniqueID);
505 }
506
507 return lk;
508}
509
511// Pointer to particle production for drift circle
513
514std::list<PRD_MultiTruthCollection::const_iterator> InDet::SegmentDriftCircleAssValidation::kinpart
515(const InDet::TRT_DriftCircle* d, const PRD_MultiTruthCollection* prdCollection )
516{
517
518 std::list<PRD_MultiTruthCollection::const_iterator> lk;
519 bool find;
520 std::list<PRD_MultiTruthCollection::const_iterator> mc = findTruth(d,find, prdCollection );
521 if(!find) return lk;
522
523 std::list<PRD_MultiTruthCollection::const_iterator>::iterator imc, imce=mc.end();
524 for(imc=mc.begin();imc!=imce;++imc){
525
526 const int uniqueID = HepMC::uniqueID((*imc)->second); if(uniqueID<=0) continue;
527
528 HepMC::ConstGenParticlePtr pa = (*imc)->second.cptr();
529 if(!pa || !pa->production_vertex()) continue;
530
531 // Charge != 0 test
532 //
533 int pdg = pa->pdg_id();
534 if (MC::isNucleus(pdg)) continue; // ignore nuclei from hadronic interactions
535 if (std::abs(MC::charge(pdg)) < .5) continue;
536
537 // pT cut
538 //
539 double pt = pa->momentum().perp();
540 if( pt < m_pTmin ) continue;
541
542
543 // Rapidity cut
544 //
545 double t = std::abs(pa->momentum().pz())/pt;
546 if( t > m_tcut ) continue;
547
548 // Radius cut
549 //
550 Point3D<double> v(pa->production_vertex()->position().x(),
551 pa->production_vertex()->position().y(),
552 pa->production_vertex()->position().z());
553 double r = sqrt(v.x()*v.x()+v.y()*v.y());
554 if( r < m_rmin || r > m_rmax) continue;
555
556 lk.push_back((*imc));
557 }
558
559 return lk;
560}
561
563// Test detector element
565
567(int K,const Trk::PrepRawData* d)
568{
569 std::multimap<int,const Trk::PrepRawData*>::iterator k = m_kinecircle.find(K);
570 for(; k!=m_kinecircle.end(); ++k) {
571
572 if((*k).first!= K) return false;
573 if(d->detectorElement()==(*k).second->detectorElement()) return true;
574 }
575 return false;
576}
577
579// Drift Circle truth information
581std::list<PRD_MultiTruthCollection::const_iterator>
583{
584 Q = true;
585 std::list<PRD_MultiTruthCollection::const_iterator> mc;
586 if (d) {
587 auto r = prdCollection->equal_range(d->identify());
588 for( auto i = r.first; i != r.second && i != prdCollection->end(); ++i){
589 mc.push_back(i);
590 }
591 }
592 if (mc.empty()) Q = false;
593
594 return mc;
595}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
ATLAS-specific HepMC functions.
static Double_t sc
Handle class for reading from StoreGate.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
bool msgLvl(const MSG::Level lvl) const
MsgStream & msg() const
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.
SG::ReadHandleKey< TRT_DriftCircleContainer > m_circlesTRTKey
SG::ReadHandleKey< Trk::SegmentCollection > m_origtrackKey
std::list< int > kine(const InDet::TRT_DriftCircle *, const PRD_MultiTruthCollection *prdCollection)
std::list< PRD_MultiTruthCollection::const_iterator > kinpart(const InDet::TRT_DriftCircle *, const PRD_MultiTruthCollection *)
std::multimap< int, const Trk::PrepRawData * > m_kinecircle
bool isTheSameStrawElement(int, const Trk::PrepRawData *)
SegmentDriftCircleAssValidation(const std::string &name, ISvcLocator *pSvcLocator)
void tracksComparison(const Trk::SegmentCollection *, const PRD_MultiTruthCollection *)
std::list< PRD_MultiTruthCollection::const_iterator > findTruth(const InDet::TRT_DriftCircle *, bool &, const PRD_MultiTruthCollection *)
SG::ReadHandleKey< PRD_MultiTruthCollection > m_PRDTruthTRTKey
void newCirclesEvent(const PRD_MultiTruthCollection *)
Represents 'corrected' measurements from the TRT (for example, corrected for wire sag).
virtual const TRT_DriftCircle * prepRawData() const override final
returns the PrepRawData - is a TRT_DriftCircle in this scope
A PRD is mapped onto all contributing particles.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Class to handle pseudo-measurements in fitters and on track objects.
const MeasurementBase * measurement(unsigned int) const
returns the Trk::MeasurementBase objects depending on the integer
unsigned int numberOfMeasurementBases() const
Return the number of contained Trk::MeasurementBase (s)
Class for a generic track segment that holdes polymorphic Trk::MeasurementBase objects,...
int r
Definition globals.cxx:22
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
int uniqueID(const T &p)
const GenParticle * ConstGenParticlePtr
Definition GenParticle.h:38
double charge(const T &p)
bool isNucleus(const T &p)
PDG rule 16 Nuclear codes are given as 10-digit numbers ±10LZZZAAAI.
DataVector< Trk::Segment > SegmentCollection