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