ATLAS Offline Software
Loading...
Searching...
No Matches
InDetRecStatisticsAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// file: InDetRecStatisticsAlg.cxx
6// author: Sven Vahsen (sevahsen AT lbl DOT gov), with contributions from Andrei Gaponenko and Laurent Vacavant
7//
8// to do-list:
9// o write out percentage of tracks with bad tracksummary
10// o add energy of mctracks for Michael
11// o don't save intermediate newTracking track's to ntuple
12// o statistics prints hit association purity, (holes in sct/pixels/b-layer, outliers, etc...)
13// o navigation between hits and tracks
14// X check Propagator defaults (check with Andrei regarding Tool)
15// o count tracks with without associated hits, without truth, truth without beginvertex
16// o improved navigation between truth and reconstructed tracks
17// o follow atlas naming conventions for all variable and method names
18
19#include "GaudiKernel/SmartDataPtr.h"
20#include "CLHEP/Units/SystemOfUnits.h"
22#include <cmath>
23#include <memory>
24#include <ostream>
25#include <iostream>
26#include <sstream>
27
35#include "TrkSurfaces/Surface.h"
37#include "TrkTrack/Track.h"
52
53// Other
59#include "VxVertex/RecVertex.h"
60
67#include "IdDict/IdDictMgr.h"
68
69
70
71static const char * const s_linestr = "----------------------------------------------------------------------------------------------------------------------------------------------";
72static const char * const s_linestr2 = "..............................................................................................................................................";
73
74InDet::InDetRecStatisticsAlg::InDetRecStatisticsAlg(const std::string& name, ISvcLocator* pSvcLocator) :
75 AthReentrantAlgorithm(name, pSvcLocator),
76 m_trtID (nullptr),
77 m_idDictMgr (nullptr),
78 m_truthToTrack ("Trk::TruthToTrack"),
79 m_trkSummaryTool ("Trk::TrackSummaryTool/InDetTrackSummaryTool"),
80 m_updatorHandle ("Trk::KalmanUpdator/TrkKalmanUpdator"),
81 m_updator (nullptr),
82 m_residualPullCalculator ("Trk::ResidualPullCalculator/ResidualPullCalculator"),
83 m_McTrackCollection_key ("TruthEvent"),
84 m_trackSelectorTool ("InDet::InDetDetailedTrackSelectorTool"),
85 m_UseTrackSummary (true),
86 m_printSecondary (false),
87 m_minPt (1000),
88 m_maxEta (4.2),
89 m_maxEtaBarrel (0.8),
91 m_maxEtaEndcap (2.5),
92 m_fakeTrackCut (0.9),
93 m_fakeTrackCut2 (0.7),
94 m_matchTrackCut (0.5),
95 m_maxRStartPrimary ( 25.0*CLHEP::mm),
96 m_maxRStartSecondary ( 360.0*CLHEP::mm),
97 m_maxZStartPrimary ( 200.0*CLHEP::mm),
98 m_maxZStartSecondary (2000.0*CLHEP::mm),
99 m_minREndPrimary ( 400.0*CLHEP::mm),
100 m_minREndSecondary (1000.0*CLHEP::mm),
101 m_minZEndPrimary (2300.0*CLHEP::mm),
102 //m_maxZIndet (),
103 m_minZEndSecondary (3200.0*CLHEP::mm),
104 m_useTrackSelection (false),
105 m_doTruth (true),
106 m_minEtaFORWARD (2.5),
107 m_maxEtaFORWARD (4.2),
108 m_isUnbiased (0),
110{
111 // m_RecTrackCollection_keys.push_back(std::string("Tracks"));
112 // m_TrackTruthCollection_keys.push_back(std::string("TrackTruthCollection"));
113
114 // Algorithm properties
115 declareProperty("SummaryTool", m_trkSummaryTool);
116 declareProperty("TruthToTrackTool", m_truthToTrack);
117 declareProperty("UpdatorTool", m_updatorHandle,
118 "Measurement updator to calculate unbiased track states");
119 declareProperty("ResidualPullCalculatorTool", m_residualPullCalculator,
120 "Tool to calculate residuals and pulls");
121 declareProperty("TrackCollectionKeys", m_RecTrackCollection_keys);
122 declareProperty("McTrackCollectionKey", m_McTrackCollection_key);
123 declareProperty("TrackTruthCollectionKeys", m_TrackTruthCollection_keys);
124 declareProperty("UseTrackSelection" , m_useTrackSelection);
125 declareProperty("DoTruth" , m_doTruth);
126 declareProperty("TrackSelectorTool" , m_trackSelectorTool);
127 declareProperty("UseTrackSummary", m_UseTrackSummary);
128 declareProperty("PrintSecondary", m_printSecondary);
129 declareProperty("minPt", m_minPt);
130 declareProperty("maxEta", m_maxEta);
131 declareProperty("maxEtaBarrel", m_maxEtaBarrel );
132 declareProperty("maxEtaTransition", m_maxEtaTransition);
133 declareProperty("maxEtaEndcap", m_maxEtaEndcap);
134 declareProperty("maxEtaFORWARD", m_maxEtaFORWARD);
135 declareProperty("minEtaFORWARD", m_minEtaFORWARD);
136 declareProperty("fakeTrackCut", m_fakeTrackCut);
137 declareProperty("fakeTrackCut2", m_fakeTrackCut2);
138 declareProperty("matchTrackCut", m_matchTrackCut);
139 declareProperty("maxRStartPrimary", m_maxRStartPrimary);
140 declareProperty("maxRStartSecondary", m_maxRStartSecondary);
141 declareProperty("maxZStartPrimary", m_maxZStartPrimary);
142 declareProperty("maxZStartSecondary", m_maxZStartSecondary);
143 declareProperty("minREndPrimary", m_minREndPrimary);
144 declareProperty("minREndSecondary", m_minREndSecondary);
145 declareProperty("minZEndPrimary", m_minZEndPrimary);
146 declareProperty("minZEndSecondary", m_minZEndSecondary);
147 m_idHelper = nullptr;
148 m_pixelID = nullptr;
149 m_sctID = nullptr;
150 m_UpdatorWarning = false;
151 m_pullWarning = false;
152}
153
154
155// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
157
158 // Part 1: Get the messaging service, print where you are
159 ATH_MSG_DEBUG("initialize()");
160
161 StatusCode sc1 = getServices(); // retrieve store gate service etc
162 if (sc1.isFailure()) {
163 ATH_MSG_FATAL("Error retrieving services !");
164 return StatusCode::FAILURE;
165 }
166
167 if (m_RecTrackCollection_keys.empty()) {
168 ATH_MSG_ERROR("No reco track collection specified! Aborting.");
169 return StatusCode::FAILURE;
170 }
171
173 ATH_MSG_ERROR("You have specified "
175 << " TrackCollection keys, and " << m_TrackTruthCollection_keys.size()
176 << " TrackTruthCollection keys."
177 << " You have to specify one TrackTruthCollection for each"
178 << " TrackCollection! Exiting."
179 );
180 return StatusCode::FAILURE;
181 }
182
183 // ----------------------------------
184 // use updator to get unbiased states
185 if ( ! m_updatorHandle.empty() ) {
186 if (m_updatorHandle.retrieve().isFailure()) {
187 ATH_MSG_FATAL("Could not retrieve measurement updator tool: "
188 << m_updatorHandle);
189 return StatusCode::FAILURE;
190 }
191 m_updator = &(*m_updatorHandle);
192 } else {
194 "No Updator for unbiased track states given, use normal states!");
195 m_updator = nullptr;
196 }
197
198
199 //get residual and pull calculator
200 if (m_residualPullCalculator.empty()) {
202 "No residual/pull calculator for general hit residuals configured."
203 );
205 "It is recommended to give R/P calculators to the det-specific tool"
206 << " handle lists then.");
207 } else if (m_residualPullCalculator.retrieve().isFailure()) {
208 ATH_MSG_FATAL("Could not retrieve "<< m_residualPullCalculator
209 <<" (to calculate residuals and pulls) ");
210
211 } else {
212 ATH_MSG_INFO("Generic hit residuals&pulls will be calculated in one or both "
213 << "available local coordinates");
214 }
215
216 // create one TrackStatHelper object of each trackCollection --- this is used to accumulate track and hit statistics
217
218 struct cuts ct;
219 ct.maxEtaBarrel= m_maxEtaBarrel;
220 ct.maxEtaTransition= m_maxEtaTransition;
221 ct.maxEtaEndcap= m_maxEtaEndcap;
222 ct.fakeTrackCut= m_fakeTrackCut;
223 ct.fakeTrackCut2= m_fakeTrackCut2;
224 ct.matchTrackCut = m_matchTrackCut;
225 ct.maxRStartPrimary = m_maxRStartPrimary;
226 ct.maxRStartSecondary = m_maxRStartSecondary;
227 ct.maxZStartPrimary = m_maxZStartPrimary;
228 ct.maxZStartSecondary = m_maxZStartSecondary;
229 ct.minREndPrimary = m_minREndPrimary;
230 ct.minREndSecondary = m_minREndSecondary;
231 ct.minZEndPrimary = m_minZEndPrimary;
232 ct.minZEndSecondary = m_minZEndSecondary;
233 ct.minPt = m_minPt;
234 ct.minEtaFORWARD = m_minEtaFORWARD;
235 ct.maxEtaFORWARD = m_maxEtaFORWARD;
236
237 unsigned int nCollections = 0;
238 for (SG::ReadHandleKeyArray<TrackCollection>::const_iterator
239 it = m_RecTrackCollection_keys.begin();
240 it < m_RecTrackCollection_keys.end(); ++ it) {
241 InDet::TrackStatHelper * collection =
242 new TrackStatHelper(it->key(),(m_doTruth ? m_TrackTruthCollection_keys[nCollections].key() : ""), m_doTruth);
243 nCollections ++;
244 collection->SetCuts(ct);
245 m_SignalCounters.push_back(collection);
246 }
247
248 StatusCode sc3 = resetStatistics(); // reset all statistic counters
249 if (sc3.isFailure()) {
250 ATH_MSG_FATAL("Error in resetStatistics !");
251 return StatusCode::FAILURE;
252 }
253
254 ATH_CHECK( m_RecTrackCollection_keys.initialize() );
257
258 return StatusCode :: SUCCESS;
259
260}
261
262
263// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
264
265StatusCode InDet::InDetRecStatisticsAlg::execute(const EventContext &ctx) const {
266
267 ATH_MSG_DEBUG("entering execute()");
268
269 // Get reconstructed tracks , generated tracks, and truth from storegate
270
272
273 if (m_doTruth) {
275 if (!SimTracks.isValid()) {
276 // @TODO warning ?
277 ATH_MSG_WARNING("Error retrieving collections !");
278 return StatusCode::SUCCESS;
279 }
280 }
281
282 // Doesn't take account of pileup:
283 //m_gen_tracks_processed += (*(SimTracks->begin()))->particles_size();
285 CounterLocal counter;
286
287 // select charged and stable generated tracks
288 // apply pt, eta etc cuts to generated tracks
289 // devide generated tracks into primary, truncated, secondary
290
291 std::vector <std::pair<HepMC::ConstGenParticlePtr,int> > GenSignal;
292 // GenSignalPrimary, GenSignalTruncated, GenSignalSecondary;
293 unsigned int inTimeStart = 0;
294 unsigned int inTimeEnd = 0;
295 if (m_doTruth) selectGenSignal ((SimTracks.isValid() ? &(*SimTracks) : nullptr), GenSignal, inTimeStart, inTimeEnd, counter);
296
297 // step through the various reconstructed TrackCollections and
298 // corresponding TrackTruthCollections and produce statistics for each
299
300 if (m_SignalCounters.empty()) {
301 ATH_MSG_ERROR("No reco track collection specified! Aborting.");
302 return StatusCode::FAILURE;
303 }
304
305 std::vector< SG::ReadHandle<TrackCollection> > rec_track_collections = m_RecTrackCollection_keys.makeHandles(ctx);
306 std::vector< SG::ReadHandle<TrackTruthCollection> > truth_track_collections;
307 if (m_doTruth && !m_TrackTruthCollection_keys.empty()) {
308 truth_track_collections = m_TrackTruthCollection_keys.makeHandles(ctx);
309 if (truth_track_collections.size() != rec_track_collections.size()) {
310 ATH_MSG_ERROR("Different number of reco and truth track collections (" << rec_track_collections.size() << "!=" << truth_track_collections.size() << ")" );
311 }
312 }
313 if (m_SignalCounters.size() != rec_track_collections.size()) {
314 ATH_MSG_ERROR("Number expected reco track collections does not match the actual number of such collections ("
315 << m_SignalCounters.size() << "!=" << rec_track_collections.size() << ")" );
316 }
317
318 std::vector< SG::ReadHandle<TrackCollection> >::iterator rec_track_collections_iter = rec_track_collections.begin();
319 std::vector< SG::ReadHandle<TrackTruthCollection> >::iterator truth_track_collections_iter = truth_track_collections.begin();
320 for (std::vector <class TrackStatHelper *>::const_iterator statHelper
321 = m_SignalCounters.begin();
322 statHelper != m_SignalCounters.end();
323 ++statHelper, ++rec_track_collections_iter) {
324 assert( rec_track_collections_iter != rec_track_collections.end());
325
326 ATH_MSG_DEBUG("Acessing TrackCollection " << m_RecTrackCollection_keys.at(rec_track_collections_iter - rec_track_collections.begin()).key());
327 const TrackCollection * RecCollection = &(**rec_track_collections_iter);
328 const TrackTruthCollection * TruthMap = nullptr;
329
330 if (RecCollection) ATH_MSG_DEBUG("Retrieved " << RecCollection->size() << " reconstructed tracks from storegate");
331
332 if (m_doTruth) {
333 ATH_MSG_DEBUG("Acessing TrackTruthCollection " << m_TrackTruthCollection_keys.at(truth_track_collections_iter - truth_track_collections.begin()).key());
334 assert( truth_track_collections_iter != truth_track_collections.end());
335 TruthMap = &(**truth_track_collections_iter);
336 if (TruthMap) ATH_MSG_DEBUG("Retrieved " << TruthMap->size() << " TrackTruth elements from storegate");
337 ++truth_track_collections_iter;
338 }
339
340 //start process of getting correct track summary
341
342 std::vector <const Trk::Track *> RecTracks, RecSignal;
343 selectRecSignal (RecCollection, RecTracks,RecSignal,counter);
344
346 " RecTracks.size()=" << RecTracks.size()
347 << ", GenSignal.size()=" << GenSignal.size());
348
349 ATH_MSG_DEBUG("Accumulating Statistics...");
350 (*statHelper)->addEvent (ctx,
351 RecCollection,
352 RecTracks,
353 GenSignal,
354 TruthMap,
356 m_pixelID,
357 m_sctID,
358 m_trkSummaryTool.operator->(),
360 &inTimeStart,
361 &inTimeEnd);
362
363 counter.m_counter[kN_rec_tracks_processed] += RecCollection->size();
364
365 for ( TrackCollection::const_iterator it = RecCollection->begin() ;
366 it < RecCollection->end(); ++ it){
367 std::vector<const Trk::RIO_OnTrack*> rioOnTracks;
368 Trk::RoT_Extractor::extract( rioOnTracks,
369 (*it)->measurementsOnTrack()->stdcont() );
370 counter.m_counter[kN_spacepoints_processed] += rioOnTracks.size();
371 }
372
373 }
374 m_counter += counter;
375
376 ATH_MSG_DEBUG("leaving execute()");
377 return StatusCode::SUCCESS;
378}
379
380
381// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
382
383StatusCode InDet :: InDetRecStatisticsAlg :: finalize() {
384
385 // Part 1: Get the messaging service, print where you are
386 ATH_MSG_DEBUG("finalize()");
387
389
390 for (std::vector <class TrackStatHelper *>::const_iterator collection =
391 m_SignalCounters.begin(); collection != m_SignalCounters.end();
392 ++collection) {
394 delete (*collection);
395 }
396 m_SignalCounters.clear();
397 return StatusCode::SUCCESS;
398}
399
400
401StatusCode InDet :: InDetRecStatisticsAlg :: getServices ()
402{
403 //Set up ATLAS ID helper to be able to identify the RIO's det-subsystem.
404
405 // Get the dictionary manager from the detector store
406 const IdDictManager* idDictMgr = nullptr;
407 StatusCode sc = detStore()->retrieve(idDictMgr, "IdDict");
408 if (sc.isFailure()) {
409 ATH_MSG_FATAL("Could not get IdDictManager !");
410 return StatusCode::FAILURE;
411 }
412
413 // Initialize the helper with the dictionary information.
414 sc = detStore()->retrieve(m_idHelper, "AtlasID");
415 if (sc.isFailure()) {
416 ATH_MSG_FATAL("Could not get AtlasDetectorID helper.");
417 return StatusCode::FAILURE;
418 }
419
420 //get Pixel, SCT, TRT managers and helpers
421
422 if (detStore()->retrieve(m_pixelID, "PixelID").isFailure()) {
423 msg(MSG::FATAL) << "Could not get Pixel ID helper" << endmsg;
424 return StatusCode::FAILURE;
425 }
426 if (detStore()->retrieve(m_sctID, "SCT_ID").isFailure()) {
427 msg(MSG::FATAL) << "Could not get SCT ID helper" << endmsg;
428 return StatusCode::FAILURE;
429 }
430
431 //retrieve the TRT helper only if not-SLHC layout used
432 sc = detStore()->retrieve(m_idDictMgr, "IdDict");
433 if (sc.isFailure()) {
434 ATH_MSG_FATAL("Could not get IdDictManager !");
435 return StatusCode::FAILURE;
436 }
437 const IdDictDictionary* dict = m_idDictMgr->manager()->find_dictionary("InnerDetector");
438 if(!dict) {
439 ATH_MSG_FATAL(" Cannot access InnerDetector dictionary ");
440 return StatusCode::FAILURE;
441 }
442
443 bool isSLHC = false;
444 if (dict->file_name().find("SLHC")!=std::string::npos) isSLHC=true;
445
446 if(!isSLHC){
447 if (detStore()->retrieve(m_trtID, "TRT_ID").isFailure()) {
448 msg(MSG::FATAL) << "Could not get TRT ID helper" << endmsg;
449 return StatusCode::FAILURE;
450 }
451 }
452 //
453
454 if (m_UseTrackSummary) {
455 if (m_trkSummaryTool.retrieve().isFailure() ) {
456 ATH_MSG_FATAL("Failed to retrieve tool "
458 return StatusCode::FAILURE;
459 } else {
460 ATH_MSG_INFO("Retrieved tool " << m_trkSummaryTool);
461 }
462 } else {
463 m_trkSummaryTool.disable();
464 }
465
466 // AG: init truthToTrack
467 if (m_doTruth) {
468 if (m_truthToTrack.retrieve().isFailure() ) {
469 ATH_MSG_FATAL("Failed to retrieve tool " << m_truthToTrack);
470 return StatusCode::FAILURE;
471 } else {
472 ATH_MSG_INFO("Retrieved tool " << m_truthToTrack);
473 }
474 } else {
475 m_truthToTrack.disable();
476 }
477
478 //adding track selector tool
480 if ( m_trackSelectorTool.retrieve().isFailure() ) {
481 ATH_MSG_FATAL("Failed to retrieve tool " << m_trackSelectorTool);
482 return StatusCode::FAILURE;
483 } else {
484 ATH_MSG_INFO("Retrieved tool " << m_trackSelectorTool);
485 }
486 } else {
487 m_trackSelectorTool.disable();
488 }
489 return StatusCode :: SUCCESS;
490}
491
492StatusCode InDet :: InDetRecStatisticsAlg :: resetStatistics() {
493 m_counter.reset();
495
496 for (std::vector<InDet::TrackStatHelper *>::const_iterator counter =
497 m_SignalCounters.begin();
498 counter != m_SignalCounters.end(); ++ counter) {
499 (*counter)->reset();
500 }
501 return StatusCode :: SUCCESS;
502}
503
505 std::vector <const Trk::Track *> & RecTracks ,
506 std::vector <const Trk::Track *> & RecSignal,
508
509 for ( TrackCollection::const_iterator it = RecCollection->begin() ;
510 it != RecCollection->end(); ++ it){
511 RecTracks.push_back(*it);
513 (*it)->trackParameters();
514
515 if(!trackpara->empty()){
516 const Trk::TrackParameters* para = trackpara->front();
517 if (para){
518 if (para->pT() > m_minPt && std::abs(para->eta()) < m_maxEta) {
519 RecSignal.push_back(*it);
520 }
521 }
522 }
523 else {
524 counter.m_counter[kN_rec_tracks_without_perigee] ++;
525 }
526 }
527 }
528
529// select charged, stable particles in allowed pt and eta range
530void InDet :: InDetRecStatisticsAlg ::
531selectGenSignal (const McEventCollection* SimTracks,
532 std::vector <std::pair<HepMC::ConstGenParticlePtr,int> > & GenSignal,
533 unsigned int /*inTimeStart*/, unsigned int /*inTimeEnd*/,
534 InDet::InDetRecStatisticsAlg::CounterLocal &counter) const //'unused' compiler warning
535{
536 if (! SimTracks) return;
537
538 unsigned int nb_mc_event = SimTracks->size();
539 std::unique_ptr<PileUpType> put = std::make_unique<PileUpType>(SimTracks);
540
543
544 if (put)
545 {
546 inTimeMBbegin = put->in_time_minimum_bias_event_begin();
547 inTimeMBend = put->in_time_minimum_bias_event_end();
548 }
549
550 for(unsigned int ievt=0; ievt<nb_mc_event; ++ievt)
551 {
552 const HepMC::GenEvent* genEvent = SimTracks->at(ievt);
553 counter.m_counter[kN_gen_tracks_processed] += genEvent->particles_size();
554 for (const auto& particle: *genEvent){
555 // require stable particle from generation or simulation
556 if (!MC::isStable(particle)) continue;
557 int pdgCode = particle->pdg_id();
558 if (MC::isNucleus(pdgCode)) continue; // ignore nuclei from hadronic interactions
559 float charge = MC::charge(pdgCode);
560 if (std::abs(charge)<0.5) continue;
561 if (std::abs(particle->momentum().perp()) > m_minPt &&
562 std::abs(particle->momentum().pseudoRapidity()) < m_maxEta ) {
563 std::pair<HepMC::ConstGenParticlePtr,int> thisPair(particle,ievt);
564 GenSignal.push_back(thisPair);
565 }
566 } // End of a particle iteration
567 } // End of one GenEvent iteration
568 }
569
570namespace {
571
572 template <class T_Stream>
573 class RestoreStream
574 {
575 public:
576 RestoreStream(T_Stream &out) : m_stream(&out),m_precision(out.precision()) { }
577 ~RestoreStream() { (*m_stream).precision(m_precision); }
578 private:
579 T_Stream *m_stream;
580 int m_precision;
581 };
582}
583
584void InDet :: InDetRecStatisticsAlg :: printStatistics() {
585 if (!msgLvl(MSG::INFO)) return;
586
587 ATH_MSG_INFO(" ********** Beginning InDetRecStatistics Statistics Table ***********");
588 ATH_MSG_INFO("For documentation see https://twiki.cern.ch/twiki/bin/view/Atlas/InDetRecStatistics");
589 ATH_MSG_INFO("(or for guaranteed latest version: http://atlas-sw.cern.ch/cgi-bin/viewcvs-atlas.cgi/offline/InnerDetector/InDetValidation/InDetRecStatistics/doc/mainpage.h?&view=markup )");
590 ATH_MSG_INFO(" ********************************************************************");
591
592 std::stringstream outstr;
593 int def_precision(outstr.precision());
594 outstr << "\n"
595 << MSG::INFO
596 << std::setiosflags(std::ios::fixed | std::ios::showpoint)
597 << std::setw(7) << std::setprecision(2)
598 << s_linestr << "\n"
599 << "Summary" << "\n"
600 << "\tProcessed : " << m_events_processed
601 << " events, " << m_counter.m_counter[kN_rec_tracks_processed]
602 << " reconstructed tracks with " << m_counter.m_counter[kN_spacepoints_processed]
603 << " hits, and " << m_counter.m_counter[kN_gen_tracks_processed]
604 << " truth particles" << "\n"
605 << "\tProblem objects : " << m_counter.m_counter[kN_rec_tracks_without_perigee]
606 << " tracks without perigee, "
607 << m_counter.m_counter[kN_unknown_hits] << " unknown hits" << "\n"
608 << "\t" << "Reco TrackCollections : ";
609 bool first = true;
610 for (std::vector <class TrackStatHelper *>::const_iterator collection =
611 m_SignalCounters.begin();
612 collection != m_SignalCounters.end(); ++collection)
613 {
614 if (first) {
615 first = false;
616 }
617 else {
618 outstr << ", ";
619 }
620 outstr << "\"" << (*collection)->key() << "\"";
621 }
622 ATH_MSG_INFO(outstr.str());
623 outstr.str("");
624
625 if (m_doTruth)
626 {
627 outstr.str("");
628 outstr << "\n"
629 << "\t" << "TrackTruthCollections : ";
630 first = true;
631 for (std::vector <class TrackStatHelper *>::const_iterator collection = m_SignalCounters.begin();
632 collection != m_SignalCounters.end(); ++collection)
633 {
634 if (first) {
635 first = false;
636 }
637 else {
638 outstr << ", ";
639 }
640 outstr << "\"" << (*collection)->Truthkey() << "\"";
641 }
642 ATH_MSG_INFO(outstr.str());
643 outstr.str("");
644 }
645 outstr.str("");
646 outstr << "\n"
647 << s_linestr2 << "\n"
648 << "Cuts and Settings for Statistics Table" << "\n"
649 << "\t" << "TrackSummary Statistics" << "\t"
650 << (m_UseTrackSummary ? "YES" : "NO") << "\n"
651 << "\t" << "Signal \t" << "pT > "
652 << m_minPt/1000 << " GeV/c, |eta| < " << m_maxEta << "\t\t"
653 << "\t" << "Primary track start \t" << "R < "
654 << m_maxRStartPrimary << "mm and |z| < "
655 << m_maxZStartPrimary << "mm" << "\n"
656 << "\t" << "Barrel \t" << 0.0
657 << "< |eta| < " << m_maxEtaBarrel << "\t\t\t"
658 << "\t" << "Primary track end \t" << "R > "
659 << m_minREndPrimary << "mm or |z| > " << m_minZEndPrimary
660 << "mm" << "\n"
661 << "\t" << "Transition Region \t" << m_maxEtaBarrel
662 << "< |eta| < " << m_maxEtaTransition << "\t\t\t"
663 << "\t" << "Secondary (non-Primary) start \t"
664 << " R < " << m_maxRStartSecondary << "mm and"
665 << " |z| < " << m_maxZStartSecondary << " mm" << "\n"
666 << "\t" << "Endcap \t" << m_maxEtaTransition
667 << "< |eta| < " << m_maxEtaEndcap << "\t\t\t"
668 << "\t" << "Secondary (non-primary) end \t"
669 << " R > " << m_minREndSecondary << "mm or"
670 << " |z| > " << m_minREndSecondary << "mm" << "\n"
671 << "\t" << "Forward \t"
672 << "|eta| > " << m_minEtaFORWARD << "\n"
673 << "\t" << "Low prob tracks #1 \t" << "< "
674 << m_fakeTrackCut << " of hits from single Truth Track "
675 << "\n"
676 << "\t" << "Low prob tracks #2 \t" << "< "
677 << m_fakeTrackCut2 << " of hits from single Truth Track "
678 << "\n"
679 << "\t" << "No link tracks \t Track has no link associated to an HepMC Particle" << "\n"
680 << "\t" << "Good reco tracks \t" << "> "
681 << m_matchTrackCut << " of hits from single Truth Track + a link !";
682 ATH_MSG_INFO(outstr.str());
683 outstr.str("");
684
685 MsgStream &out = msg(MSG::INFO);
686 {
687 RestoreStream<MsgStream> restore(out);
688 out << "\n" << s_linestr2 << "\n";
689 m_SignalCounters.back()->print(out);
690
691 if (m_UseTrackSummary) {
692 std::string track_stummary_type_header = TrackStatHelper::getSummaryTypeHeader();
693 out << "\n"
694 << s_linestr2 << "\n"
695 << "Detailed Statistics for Hits on Reconstructed tracks, using TrackSummary: (Preselection of tracks as described above.)" << "\n"
696 << s_linestr2 << "\n"
697 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n"
698 << " Reco Tracks .........................................hits/track....................................................... " << "\n"
699 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n"
700 << " in BARREL tracks/event " << track_stummary_type_header << "\n"
701 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n";
702 printTrackSummary (out, ETA_BARREL);
703
704 out<< "\n"
705 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n"
706 << " in TRANSITION region tracks/event " << track_stummary_type_header << "\n"
707 << "----------------------------------------------------------------------------------------------------------------------------------------------------"
708 << "\n";
709 printTrackSummary (out, ETA_TRANSITION);
710
711 out << "\n"
712 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n"
713 << " in ENDCAP tracks/event " << track_stummary_type_header << "\n"
714 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n";
715 printTrackSummary (out, ETA_ENDCAP);
716
717 out << "\n"
718 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n"
719 << " in FORWARD region tracks/event " << track_stummary_type_header << "\n"
720 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n";
721 printTrackSummary (out, ETA_FORWARD);
722 }
723
725 outstr.str("");
726 outstr << "\n" << std::setprecision(def_precision)
727 <<s_linestr<<"\n"
728 <<"Statistics for Secondaries (non-Primaries)"<<"\n"
729 << "\t" << "Secondary track start \t"
730 << " R < " << m_maxRStartSecondary << "mm and"
731 << " |z| < " << m_maxZStartSecondary << " mm" << "\n"
732 << "\t" << "Secondary track end \t"
733 << " R > " << m_minREndSecondary << "mm or"
734 << " |z| > " << m_minZEndSecondary << "mm";
735 ATH_MSG_INFO(outstr.str());
736 outstr.str("");
737 out << "\n" << s_linestr2 << "\n";
738 m_SignalCounters.back()->printSecondary(out);
739
740 }
741 }
742 out << endmsg;
743
744 ATH_MSG_INFO(" ********** Ending InDetRecStatistics Statistics Table ***********");
745 ATH_MSG_INFO( "\n"
746 << s_linestr );
747}
748
749
750void InDet :: InDetRecStatisticsAlg ::printTrackSummary (MsgStream &out, enum eta_region eta_reg)
751{
752 bool printed = m_SignalCounters.back()->printTrackSummaryRegion(out, TRACK_ALL, eta_reg);
753
754 if (printed) {
755 out << "\n"
756 << "----------------------------------------------------------------------------------------------------------------------------------------------" << "\n";
757 }
758
759 printed = m_SignalCounters.back()->printTrackSummaryRegion(out, TRACK_LOWTRUTHPROB, eta_reg);
760 if (printed) {
761 out << "\n"
762 << "----------------------------------------------------------------------------------------------------------------------------------------------" << "\n";
763 }
764
765 m_SignalCounters.back()->printTrackSummaryRegion(out, TRACK_LOWTRUTHPROB2, eta_reg);
766
767}
768
769// =================================================================================================================
770// calculatePull
771// =================================================================================================================
772float InDet :: InDetRecStatisticsAlg :: calculatePull(const float residual,
773 const float trkErr,
774 const float hitErr){
775 double ErrorSum;
776 ErrorSum = sqrt(pow(trkErr, 2) + pow(hitErr, 2));
777 if (ErrorSum != 0) { return residual/ErrorSum; }
778 else { return 0; }
779}
780
782
783
784 const Trk::TrackParameters *unbiasedTrkParameters = nullptr;
785
786 // -----------------------------------------
787 // use unbiased track states or normal ones?
788 // unbiased track parameters are tried to retrieve if the updator tool
789 // is available and if unbiased track states could be produced before
790 // for the current track (ie. if one trial to get unbiased track states
791 // fail
792
793 if (m_updator && (m_isUnbiased==1) ) {
794 if ( trkParameters->covariance() ) {
795 // Get unbiased state
796 ATH_MSG_VERBOSE(" getting unbiased params");
797 unbiasedTrkParameters =
798 m_updator->removeFromState( *trkParameters,
799 measurement->localParameters(),
800 measurement->localCovariance()).release();
801
802 if (!unbiasedTrkParameters) {
803 ATH_MSG_WARNING("Could not get unbiased track parameters, "
804 <<"use normal parameters");
805 m_isUnbiased = 0;
806 }
807 } else if(!m_UpdatorWarning) {
808 // warn only once!
809 ATH_MSG_WARNING("TrackParameters contain no covariance: "
810 <<"Unbiased track states can not be calculated "
811 <<"(ie. pulls and residuals will be too small)");
812 m_UpdatorWarning = true;
813 m_isUnbiased = 0;
814 } else {
815 m_isUnbiased = 0;
816 }
817 } // end if no measured track parameter
818 return unbiasedTrkParameters;
819}
820
821
823 Identifier id;
824 const Trk::CompetingRIOsOnTrack *comprot = nullptr;
825 // identify by ROT:
826 const Trk::RIO_OnTrack *rot =
827 dynamic_cast<const Trk::RIO_OnTrack*>(measurement);
828 if (rot) {
829 id = rot->identify();
830 } else {
831 // identify by CompetingROT:
832 comprot = dynamic_cast<const Trk::CompetingRIOsOnTrack*>(measurement);
833 if (comprot) {
834 rot = &comprot->rioOnTrack(comprot->indexOfMaxAssignProb());
835 id = rot->identify();
836 } else {
837 ATH_MSG_DEBUG("measurement is neither ROT nor competingROT:"
838 <<" can not determine detector type");
839 id.clear();
840 }
841 }
842 delete comprot;
843 return id;
844}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
double charge(const T &p)
Definition AtlasPID.h:997
ATLAS-specific HepMC functions.
Extrapolation for HepMC particles.
static const char *const s_linestr
static const char *const s_linestr2
static Double_t sc
This is an Identifier helper class for the Pixel subdetector.
This is an Identifier helper class for the SCT subdetector.
This is an Identifier helper class for the TRT subdetector.
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
An algorithm that can be simultaneously executed in multiple threads.
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.
const T * front() const
Access the first element in the collection as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
IdDictManager is the interface to identifier dictionaries.
const TRT_ID * m_trtID
get trt layer from hit ID
float m_minZEndSecondary
If track has end vertex, this is min Z of end vertex to be considered secondary.
void selectGenSignal(const McEventCollection *, std::vector< std::pair< HepMC::ConstGenParticlePtr, int > > &, unsigned int, unsigned int, CounterLocal &counter) const
Select charged,stable particles which pass pt and eta cuts for analysis.
ToolHandle< Trk::ITruthToTrack > m_truthToTrack
tool to create track parameters from a gen particle
std::atomic< long > m_events_processed
number of events processed
Trk::IUpdator * m_updator
updator for unbiased states
std::atomic< int > m_isUnbiased
if can get unbiased residuals
float m_maxEta
Maximum Eta cut for tracks used by the algorithm.
SG::ReadHandleKey< McEventCollection > m_McTrackCollection_key
StatusCode getServices()
Get various services such as StoreGate, dictionaries, detector managers etc.
float m_minREndSecondary
If track has end vertex, this is min R of end vertex to be considered secondary.
float m_maxRStartSecondary
Maximum R of start vertex to be considered secondary.
StatusCode resetStatistics()
Clear statistics counters, called before each track collection is processed.
const AtlasDetectorID * m_idHelper
Used to find out the sub-det from PRD->identify().
SG::ReadHandleKeyArray< TrackTruthCollection > m_TrackTruthCollection_keys
std::atomic< bool > m_pullWarning
warn only once, if pull cannot be calculated
float m_minZEndPrimary
If track has end vertex, this is min Z of end vertex to be considered primary.
void printStatistics()
Print tracking statistics calculated with TrackStatHelper.
float m_maxZStartPrimary
Maximum Z of start vertex to be considered primary.
bool m_printSecondary
Flag to print hit information for secondary tracks.
const PixelID * m_pixelID
get pixel layer from hit ID
float m_minREndPrimary
If track has end vertex, this is min R of end vertex to be considered primary.
InDetRecStatisticsAlg(const std::string &name, ISvcLocator *pSvcLocator)
Default Constructor.
float m_fakeTrackCut2
Second definition of maximum probability for which a track will be considered a fake.
StatusCode execute(const EventContext &ctx) const
Calculation of statistics.
float m_maxRStartPrimary
Maximum R of start vertex to be considered primary.
float m_maxEtaEndcap
define max eta of eta region
bool m_doTruth
Use truth information.
ToolHandle< Trk::IResidualPullCalculator > m_residualPullCalculator
The residual and pull calculator tool handle.
std::vector< class TrackStatHelper * > m_SignalCounters
Vector of TrackStatHelper objects, one for each track collection.
float m_maxEtaTransition
define max eta of transition region
std::atomic< bool > m_UpdatorWarning
warn only once, if unbiased track states can not be calculated
ToolHandle< Trk::IUpdator > m_updatorHandle
Tool handle of updator for unbiased states.
void selectRecSignal(const TrackCollection *, std::vector< const Trk::Track * > &, std::vector< const Trk::Track * > &, CounterLocal &counter) const
Select for analysis reconstructed tracks passing Pt and eta cuts.
const SCT_ID * m_sctID
get sct layer from hit ID
Identifier getIdentifier(const Trk::MeasurementBase *measurement)
ToolHandle< Trk::IExtendedTrackSummaryTool > m_trkSummaryTool
tool to get track summary information from track
const Trk::TrackParameters * getUnbiasedTrackParameters(const Trk::TrackParameters *, const Trk::MeasurementBase *)
Get Unbiased Track Parameters.
SG::ReadHandleKeyArray< TrackCollection > m_RecTrackCollection_keys
ToolHandle< Trk::ITrackSelectorTool > m_trackSelectorTool
float m_minPt
Minimum Pt cut for tracks used by the algorithm.
bool m_UseTrackSummary
Flag to print detailed statistics for each track collection.
float m_fakeTrackCut
Maximum probability for which a track will be considered a fake.
@ kN_gen_tracks_processed
number of generated tracks processed
@ kN_rec_tracks_processed
number of reconstructed tracks processed
@ kN_rec_tracks_without_perigee
number of tracks w/o perigee
@ kN_spacepoints_processed
number of space points processed
@ kN_unknown_hits
number of hits without track
void printTrackSummary(MsgStream &out, enum eta_region)
Print track statistics for all and low proability tracks.
float m_maxEtaBarrel
define max eta of barrel region
StatusCode initialize()
Initialization of services, track collections, creates TrackStatHelper for each Track Collection.
bool m_useTrackSelection
Use track selector tool.
float m_maxZStartSecondary
Maximum Z of start vertex to be considered secondary.
float m_matchTrackCut
Minimum number of hits from a truth track to be considered a matched reco track.
static std::string getSummaryTypeHeader()
void SetCuts(const struct cuts &)
Sets the cuts such as the eta regions (barrel, transition,endcap) and the hit fraction fake cuts and ...
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
unsigned int indexOfMaxAssignProb() const
Index of the ROT with the highest assignment probability.
virtual const RIO_OnTrack & rioOnTrack(unsigned int) const =0
returns the RIO_OnTrack (also known as ROT) objects depending on the integer.
This class is the pure abstract base class for all fittable tracking measurements.
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
const Amg::MatrixX & localCovariance() const
Interface method to get the localError.
double eta() const
Access method for pseudorapidity - from momentum.
double pT() const
Access method for transverse momentum.
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
static void extract(std::vector< const RIO_OnTrack * > &rots, const std::vector< const MeasurementBase * > &measurements)
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
double charge(const T &p)
bool isNucleus(const T &p)
PDG rule 16 Nuclear codes are given as 10-digit numbers ±10LZZZAAAI.
ParametersBase< TrackParametersDim, Charged > TrackParameters
MsgStream & msg
Definition testRead.cxx:32