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
23
31#include "TrkSurfaces/Surface.h"
33#include "TrkTrack/Track.h"
48
49// Other
55#include "VxVertex/RecVertex.h"
56
63#include "IdDict/IdDictMgr.h"
64
65#include <cmath>
66#include <memory>
67#include <ostream>
68#include <iostream>
69#include <sstream>
70
71
72
73static const char * const s_linestr = "----------------------------------------------------------------------------------------------------------------------------------------------";
74static const char * const s_linestr2 = "..............................................................................................................................................";
75
76InDet::InDetRecStatisticsAlg::InDetRecStatisticsAlg(const std::string& name, ISvcLocator* pSvcLocator) :
77 AthReentrantAlgorithm(name, pSvcLocator),
78 m_trtID (nullptr),
79 m_idDictMgr (nullptr),
80 m_truthToTrack ("Trk::TruthToTrack"),
81 m_trkSummaryTool ("Trk::TrackSummaryTool/InDetTrackSummaryTool"),
82 m_updatorHandle ("Trk::KalmanUpdator/TrkKalmanUpdator"),
83 m_updator (nullptr),
84 m_residualPullCalculator ("Trk::ResidualPullCalculator/ResidualPullCalculator"),
85 m_McTrackCollection_key ("TruthEvent"),
86 m_trackSelectorTool ("InDet::InDetDetailedTrackSelectorTool"),
87 m_UseTrackSummary (true),
88 m_printSecondary (false),
89 m_minPt (1000),
90 m_maxEta (4.2),
91 m_maxEtaBarrel (0.8),
93 m_maxEtaEndcap (2.5),
94 m_fakeTrackCut (0.9),
95 m_fakeTrackCut2 (0.7),
96 m_matchTrackCut (0.5),
97 m_maxRStartPrimary ( 25.0*CLHEP::mm),
98 m_maxRStartSecondary ( 360.0*CLHEP::mm),
99 m_maxZStartPrimary ( 200.0*CLHEP::mm),
100 m_maxZStartSecondary (2000.0*CLHEP::mm),
101 m_minREndPrimary ( 400.0*CLHEP::mm),
102 m_minREndSecondary (1000.0*CLHEP::mm),
103 m_minZEndPrimary (2300.0*CLHEP::mm),
104 //m_maxZIndet (),
105 m_minZEndSecondary (3200.0*CLHEP::mm),
106 m_useTrackSelection (false),
107 m_doTruth (true),
108 m_minEtaFORWARD (2.5),
109 m_maxEtaFORWARD (4.2),
110 m_isUnbiased (0),
112{
113 // m_RecTrackCollection_keys.push_back(std::string("Tracks"));
114 // m_TrackTruthCollection_keys.push_back(std::string("TrackTruthCollection"));
115
116 // Algorithm properties
117 declareProperty("SummaryTool", m_trkSummaryTool);
118 declareProperty("TruthToTrackTool", m_truthToTrack);
119 declareProperty("UpdatorTool", m_updatorHandle,
120 "Measurement updator to calculate unbiased track states");
121 declareProperty("ResidualPullCalculatorTool", m_residualPullCalculator,
122 "Tool to calculate residuals and pulls");
123 declareProperty("TrackCollectionKeys", m_RecTrackCollection_keys);
124 declareProperty("McTrackCollectionKey", m_McTrackCollection_key);
125 declareProperty("TrackTruthCollectionKeys", m_TrackTruthCollection_keys);
126 declareProperty("UseTrackSelection" , m_useTrackSelection);
127 declareProperty("DoTruth" , m_doTruth);
128 declareProperty("TrackSelectorTool" , m_trackSelectorTool);
129 declareProperty("UseTrackSummary", m_UseTrackSummary);
130 declareProperty("PrintSecondary", m_printSecondary);
131 declareProperty("minPt", m_minPt);
132 declareProperty("maxEta", m_maxEta);
133 declareProperty("maxEtaBarrel", m_maxEtaBarrel );
134 declareProperty("maxEtaTransition", m_maxEtaTransition);
135 declareProperty("maxEtaEndcap", m_maxEtaEndcap);
136 declareProperty("maxEtaFORWARD", m_maxEtaFORWARD);
137 declareProperty("minEtaFORWARD", m_minEtaFORWARD);
138 declareProperty("fakeTrackCut", m_fakeTrackCut);
139 declareProperty("fakeTrackCut2", m_fakeTrackCut2);
140 declareProperty("matchTrackCut", m_matchTrackCut);
141 declareProperty("maxRStartPrimary", m_maxRStartPrimary);
142 declareProperty("maxRStartSecondary", m_maxRStartSecondary);
143 declareProperty("maxZStartPrimary", m_maxZStartPrimary);
144 declareProperty("maxZStartSecondary", m_maxZStartSecondary);
145 declareProperty("minREndPrimary", m_minREndPrimary);
146 declareProperty("minREndSecondary", m_minREndSecondary);
147 declareProperty("minZEndPrimary", m_minZEndPrimary);
148 declareProperty("minZEndSecondary", m_minZEndSecondary);
149 m_idHelper = nullptr;
150 m_pixelID = nullptr;
151 m_sctID = nullptr;
152 m_UpdatorWarning = false;
153 m_pullWarning = false;
154}
155
156
157// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
159
160 // Part 1: Get the messaging service, print where you are
161 ATH_MSG_DEBUG("initialize()");
162
163 StatusCode sc1 = getServices(); // retrieve store gate service etc
164 if (sc1.isFailure()) {
165 ATH_MSG_FATAL("Error retrieving services !");
166 return StatusCode::FAILURE;
167 }
168
169 if (m_RecTrackCollection_keys.empty()) {
170 ATH_MSG_ERROR("No reco track collection specified! Aborting.");
171 return StatusCode::FAILURE;
172 }
173
175 ATH_MSG_ERROR("You have specified "
177 << " TrackCollection keys, and " << m_TrackTruthCollection_keys.size()
178 << " TrackTruthCollection keys."
179 << " You have to specify one TrackTruthCollection for each"
180 << " TrackCollection! Exiting."
181 );
182 return StatusCode::FAILURE;
183 }
184
185 // ----------------------------------
186 // use updator to get unbiased states
187 if ( ! m_updatorHandle.empty() ) {
188 if (m_updatorHandle.retrieve().isFailure()) {
189 ATH_MSG_FATAL("Could not retrieve measurement updator tool: "
190 << m_updatorHandle);
191 return StatusCode::FAILURE;
192 }
193 m_updator = &(*m_updatorHandle);
194 } else {
196 "No Updator for unbiased track states given, use normal states!");
197 m_updator = nullptr;
198 }
199
200
201 //get residual and pull calculator
202 if (m_residualPullCalculator.empty()) {
204 "No residual/pull calculator for general hit residuals configured."
205 );
207 "It is recommended to give R/P calculators to the det-specific tool"
208 << " handle lists then.");
209 } else if (m_residualPullCalculator.retrieve().isFailure()) {
210 ATH_MSG_FATAL("Could not retrieve "<< m_residualPullCalculator
211 <<" (to calculate residuals and pulls) ");
212
213 } else {
214 ATH_MSG_INFO("Generic hit residuals&pulls will be calculated in one or both "
215 << "available local coordinates");
216 }
217
218 // create one TrackStatHelper object of each trackCollection --- this is used to accumulate track and hit statistics
219
220 struct cuts ct;
221 ct.maxEtaBarrel= m_maxEtaBarrel;
222 ct.maxEtaTransition= m_maxEtaTransition;
223 ct.maxEtaEndcap= m_maxEtaEndcap;
224 ct.fakeTrackCut= m_fakeTrackCut;
225 ct.fakeTrackCut2= m_fakeTrackCut2;
226 ct.matchTrackCut = m_matchTrackCut;
227 ct.maxRStartPrimary = m_maxRStartPrimary;
228 ct.maxRStartSecondary = m_maxRStartSecondary;
229 ct.maxZStartPrimary = m_maxZStartPrimary;
230 ct.maxZStartSecondary = m_maxZStartSecondary;
231 ct.minREndPrimary = m_minREndPrimary;
232 ct.minREndSecondary = m_minREndSecondary;
233 ct.minZEndPrimary = m_minZEndPrimary;
234 ct.minZEndSecondary = m_minZEndSecondary;
235 ct.minPt = m_minPt;
236 ct.minEtaFORWARD = m_minEtaFORWARD;
237 ct.maxEtaFORWARD = m_maxEtaFORWARD;
238
239 unsigned int nCollections = 0;
240 for (SG::ReadHandleKeyArray<TrackCollection>::const_iterator
241 it = m_RecTrackCollection_keys.begin();
242 it < m_RecTrackCollection_keys.end(); ++ it) {
243 InDet::TrackStatHelper * collection =
244 new TrackStatHelper(it->key(),(m_doTruth ? m_TrackTruthCollection_keys[nCollections].key() : ""), m_doTruth);
245 nCollections ++;
246 collection->SetCuts(ct);
247 m_SignalCounters.push_back(collection);
248 }
249
250 StatusCode sc3 = resetStatistics(); // reset all statistic counters
251 if (sc3.isFailure()) {
252 ATH_MSG_FATAL("Error in resetStatistics !");
253 return StatusCode::FAILURE;
254 }
255
256 ATH_CHECK( m_RecTrackCollection_keys.initialize() );
259
260 return StatusCode :: SUCCESS;
261
262}
263
264
265// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
266
267StatusCode InDet::InDetRecStatisticsAlg::execute(const EventContext &ctx) const {
268
269 ATH_MSG_DEBUG("entering execute()");
270
271 // Get reconstructed tracks , generated tracks, and truth from storegate
272
274
275 if (m_doTruth) {
277 if (!SimTracks.isValid()) {
278 // @TODO warning ?
279 ATH_MSG_WARNING("Error retrieving collections !");
280 return StatusCode::SUCCESS;
281 }
282 }
283
284 // Doesn't take account of pileup:
285 //m_gen_tracks_processed += (*(SimTracks->begin()))->particles_size();
287 CounterLocal counter;
288
289 // select charged and stable generated tracks
290 // apply pt, eta etc cuts to generated tracks
291 // devide generated tracks into primary, truncated, secondary
292
293 std::vector <std::pair<HepMC::ConstGenParticlePtr,int> > GenSignal;
294 // GenSignalPrimary, GenSignalTruncated, GenSignalSecondary;
295 unsigned int inTimeStart = 0;
296 unsigned int inTimeEnd = 0;
297 if (m_doTruth) selectGenSignal ((SimTracks.isValid() ? &(*SimTracks) : nullptr), GenSignal, inTimeStart, inTimeEnd, counter);
298
299 // step through the various reconstructed TrackCollections and
300 // corresponding TrackTruthCollections and produce statistics for each
301
302 if (m_SignalCounters.empty()) {
303 ATH_MSG_ERROR("No reco track collection specified! Aborting.");
304 return StatusCode::FAILURE;
305 }
306
307 std::vector< SG::ReadHandle<TrackCollection> > rec_track_collections = m_RecTrackCollection_keys.makeHandles(ctx);
308 std::vector< SG::ReadHandle<TrackTruthCollection> > truth_track_collections;
309 if (m_doTruth && !m_TrackTruthCollection_keys.empty()) {
310 truth_track_collections = m_TrackTruthCollection_keys.makeHandles(ctx);
311 if (truth_track_collections.size() != rec_track_collections.size()) {
312 ATH_MSG_ERROR("Different number of reco and truth track collections (" << rec_track_collections.size() << "!=" << truth_track_collections.size() << ")" );
313 }
314 }
315 if (m_SignalCounters.size() != rec_track_collections.size()) {
316 ATH_MSG_ERROR("Number expected reco track collections does not match the actual number of such collections ("
317 << m_SignalCounters.size() << "!=" << rec_track_collections.size() << ")" );
318 }
319
320 std::vector< SG::ReadHandle<TrackCollection> >::iterator rec_track_collections_iter = rec_track_collections.begin();
321 std::vector< SG::ReadHandle<TrackTruthCollection> >::iterator truth_track_collections_iter = truth_track_collections.begin();
322 for (std::vector <class TrackStatHelper *>::const_iterator statHelper
323 = m_SignalCounters.begin();
324 statHelper != m_SignalCounters.end();
325 ++statHelper, ++rec_track_collections_iter) {
326 assert( rec_track_collections_iter != rec_track_collections.end());
327
328 ATH_MSG_DEBUG("Acessing TrackCollection " << m_RecTrackCollection_keys.at(rec_track_collections_iter - rec_track_collections.begin()).key());
329 const TrackCollection * RecCollection = &(**rec_track_collections_iter);
330 const TrackTruthCollection * TruthMap = nullptr;
331
332 if (RecCollection) ATH_MSG_DEBUG("Retrieved " << RecCollection->size() << " reconstructed tracks from storegate");
333
334 if (m_doTruth) {
335 ATH_MSG_DEBUG("Acessing TrackTruthCollection " << m_TrackTruthCollection_keys.at(truth_track_collections_iter - truth_track_collections.begin()).key());
336 assert( truth_track_collections_iter != truth_track_collections.end());
337 TruthMap = &(**truth_track_collections_iter);
338 if (TruthMap) ATH_MSG_DEBUG("Retrieved " << TruthMap->size() << " TrackTruth elements from storegate");
339 ++truth_track_collections_iter;
340 }
341
342 //start process of getting correct track summary
343
344 std::vector <const Trk::Track *> RecTracks, RecSignal;
345 selectRecSignal (RecCollection, RecTracks,RecSignal,counter);
346
348 " RecTracks.size()=" << RecTracks.size()
349 << ", GenSignal.size()=" << GenSignal.size());
350
351 ATH_MSG_DEBUG("Accumulating Statistics...");
352 (*statHelper)->addEvent (ctx,
353 RecCollection,
354 RecTracks,
355 GenSignal,
356 TruthMap,
358 m_pixelID,
359 m_sctID,
360 m_trkSummaryTool.operator->(),
362 &inTimeStart,
363 &inTimeEnd);
364
365 counter.m_counter[kN_rec_tracks_processed] += RecCollection->size();
366
367 for ( TrackCollection::const_iterator it = RecCollection->begin() ;
368 it < RecCollection->end(); ++ it){
369 std::vector<const Trk::RIO_OnTrack*> rioOnTracks;
370 Trk::RoT_Extractor::extract( rioOnTracks,
371 (*it)->measurementsOnTrack()->stdcont() );
372 counter.m_counter[kN_spacepoints_processed] += rioOnTracks.size();
373 }
374
375 }
376 m_counter += counter;
377
378 ATH_MSG_DEBUG("leaving execute()");
379 return StatusCode::SUCCESS;
380}
381
382
383// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
384
385StatusCode InDet :: InDetRecStatisticsAlg :: finalize() {
386
387 // Part 1: Get the messaging service, print where you are
388 ATH_MSG_DEBUG("finalize()");
389
391
392 for (std::vector <class TrackStatHelper *>::const_iterator collection =
393 m_SignalCounters.begin(); collection != m_SignalCounters.end();
394 ++collection) {
396 delete (*collection);
397 }
398 m_SignalCounters.clear();
399 return StatusCode::SUCCESS;
400}
401
402
403StatusCode InDet :: InDetRecStatisticsAlg :: getServices ()
404{
405 //Set up ATLAS ID helper to be able to identify the RIO's det-subsystem.
406
407 // Get the dictionary manager from the detector store
408 const IdDictManager* idDictMgr = nullptr;
409 StatusCode sc = detStore()->retrieve(idDictMgr, "IdDict");
410 if (sc.isFailure()) {
411 ATH_MSG_FATAL("Could not get IdDictManager !");
412 return StatusCode::FAILURE;
413 }
414
415 // Initialize the helper with the dictionary information.
416 sc = detStore()->retrieve(m_idHelper, "AtlasID");
417 if (sc.isFailure()) {
418 ATH_MSG_FATAL("Could not get AtlasDetectorID helper.");
419 return StatusCode::FAILURE;
420 }
421
422 //get Pixel, SCT, TRT managers and helpers
423
424 if (detStore()->retrieve(m_pixelID, "PixelID").isFailure()) {
425 msg(MSG::FATAL) << "Could not get Pixel ID helper" << endmsg;
426 return StatusCode::FAILURE;
427 }
428 if (detStore()->retrieve(m_sctID, "SCT_ID").isFailure()) {
429 msg(MSG::FATAL) << "Could not get SCT ID helper" << endmsg;
430 return StatusCode::FAILURE;
431 }
432
433 //retrieve the TRT helper only if not-SLHC layout used
434 sc = detStore()->retrieve(m_idDictMgr, "IdDict");
435 if (sc.isFailure()) {
436 ATH_MSG_FATAL("Could not get IdDictManager !");
437 return StatusCode::FAILURE;
438 }
439 const IdDictDictionary* dict = m_idDictMgr->manager()->find_dictionary("InnerDetector");
440 if(!dict) {
441 ATH_MSG_FATAL(" Cannot access InnerDetector dictionary ");
442 return StatusCode::FAILURE;
443 }
444
445 bool isSLHC = false;
446 if (dict->file_name().find("SLHC")!=std::string::npos) isSLHC=true;
447
448 if(!isSLHC){
449 if (detStore()->retrieve(m_trtID, "TRT_ID").isFailure()) {
450 msg(MSG::FATAL) << "Could not get TRT ID helper" << endmsg;
451 return StatusCode::FAILURE;
452 }
453 }
454 //
455
456 if (m_UseTrackSummary) {
457 if (m_trkSummaryTool.retrieve().isFailure() ) {
458 ATH_MSG_FATAL("Failed to retrieve tool "
460 return StatusCode::FAILURE;
461 } else {
462 ATH_MSG_INFO("Retrieved tool " << m_trkSummaryTool);
463 }
464 } else {
465 m_trkSummaryTool.disable();
466 }
467
468 // AG: init truthToTrack
469 if (m_doTruth) {
470 if (m_truthToTrack.retrieve().isFailure() ) {
471 ATH_MSG_FATAL("Failed to retrieve tool " << m_truthToTrack);
472 return StatusCode::FAILURE;
473 } else {
474 ATH_MSG_INFO("Retrieved tool " << m_truthToTrack);
475 }
476 } else {
477 m_truthToTrack.disable();
478 }
479
480 //adding track selector tool
482 if ( m_trackSelectorTool.retrieve().isFailure() ) {
483 ATH_MSG_FATAL("Failed to retrieve tool " << m_trackSelectorTool);
484 return StatusCode::FAILURE;
485 } else {
486 ATH_MSG_INFO("Retrieved tool " << m_trackSelectorTool);
487 }
488 } else {
489 m_trackSelectorTool.disable();
490 }
491 return StatusCode :: SUCCESS;
492}
493
494StatusCode InDet :: InDetRecStatisticsAlg :: resetStatistics() {
495 m_counter.reset();
497
498 for (std::vector<InDet::TrackStatHelper *>::const_iterator counter =
499 m_SignalCounters.begin();
500 counter != m_SignalCounters.end(); ++ counter) {
501 (*counter)->reset();
502 }
503 return StatusCode :: SUCCESS;
504}
505
507 std::vector <const Trk::Track *> & RecTracks ,
508 std::vector <const Trk::Track *> & RecSignal,
510
511 for ( TrackCollection::const_iterator it = RecCollection->begin() ;
512 it != RecCollection->end(); ++ it){
513 RecTracks.push_back(*it);
515 (*it)->trackParameters();
516
517 if(!trackpara->empty()){
518 const Trk::TrackParameters* para = trackpara->front();
519 if (para){
520 if (para->pT() > m_minPt && std::abs(para->eta()) < m_maxEta) {
521 RecSignal.push_back(*it);
522 }
523 }
524 }
525 else {
526 counter.m_counter[kN_rec_tracks_without_perigee] ++;
527 }
528 }
529 }
530
531// select charged, stable particles in allowed pt and eta range
532void InDet :: InDetRecStatisticsAlg ::
533selectGenSignal (const McEventCollection* SimTracks,
534 std::vector <std::pair<HepMC::ConstGenParticlePtr,int> > & GenSignal,
535 unsigned int /*inTimeStart*/, unsigned int /*inTimeEnd*/,
536 InDet::InDetRecStatisticsAlg::CounterLocal &counter) const //'unused' compiler warning
537{
538 if (! SimTracks) return;
539
540 unsigned int nb_mc_event = SimTracks->size();
541 std::unique_ptr<PileUpType> put = std::make_unique<PileUpType>(SimTracks);
542
545
546 if (put)
547 {
548 inTimeMBbegin = put->in_time_minimum_bias_event_begin();
549 inTimeMBend = put->in_time_minimum_bias_event_end();
550 }
551
552 for(unsigned int ievt=0; ievt<nb_mc_event; ++ievt)
553 {
554 const HepMC::GenEvent* genEvent = SimTracks->at(ievt);
555 counter.m_counter[kN_gen_tracks_processed] += genEvent->particles_size();
556 for (const auto& particle: *genEvent){
557 // require stable particle from generation or simulation
558 if (!MC::isStable(particle)) continue;
559 int pdgCode = particle->pdg_id();
560 if (MC::isNucleus(pdgCode)) continue; // ignore nuclei from hadronic interactions
561 float charge = MC::charge(pdgCode);
562 if (std::abs(charge)<0.5) continue;
563 if (std::abs(particle->momentum().perp()) > m_minPt &&
564 std::abs(particle->momentum().pseudoRapidity()) < m_maxEta ) {
565 GenSignal.emplace_back(particle,ievt);
566 }
567 } // End of a particle iteration
568 } // End of one GenEvent iteration
569 }
570
571namespace {
572
573 template <class T_Stream>
574 class RestoreStream
575 {
576 public:
577 RestoreStream(T_Stream &out) : m_stream(&out),m_precision(out.precision()) { }
578 ~RestoreStream() { (*m_stream).precision(m_precision); }
579 private:
580 T_Stream *m_stream;
581 int m_precision;
582 };
583}
584
585void InDet :: InDetRecStatisticsAlg :: printStatistics() {
586 if (!msgLvl(MSG::INFO)) return;
587
588 ATH_MSG_INFO(" ********** Beginning InDetRecStatistics Statistics Table ***********");
589 ATH_MSG_INFO("For documentation see https://twiki.cern.ch/twiki/bin/view/Atlas/InDetRecStatistics");
590 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 )");
591 ATH_MSG_INFO(" ********************************************************************");
592
593 std::stringstream outstr;
594 int def_precision(outstr.precision());
595 outstr << "\n"
596 << MSG::INFO
597 << std::setiosflags(std::ios::fixed | std::ios::showpoint)
598 << std::setw(7) << std::setprecision(2)
599 << s_linestr << "\n"
600 << "Summary" << "\n"
601 << "\tProcessed : " << m_events_processed
602 << " events, " << m_counter.m_counter[kN_rec_tracks_processed]
603 << " reconstructed tracks with " << m_counter.m_counter[kN_spacepoints_processed]
604 << " hits, and " << m_counter.m_counter[kN_gen_tracks_processed]
605 << " truth particles" << "\n"
606 << "\tProblem objects : " << m_counter.m_counter[kN_rec_tracks_without_perigee]
607 << " tracks without perigee, "
608 << m_counter.m_counter[kN_unknown_hits] << " unknown hits" << "\n"
609 << "\t" << "Reco TrackCollections : ";
610 bool first = true;
611 for (std::vector <class TrackStatHelper *>::const_iterator collection =
612 m_SignalCounters.begin();
613 collection != m_SignalCounters.end(); ++collection)
614 {
615 if (first) {
616 first = false;
617 }
618 else {
619 outstr << ", ";
620 }
621 outstr << "\"" << (*collection)->key() << "\"";
622 }
623 ATH_MSG_INFO(outstr.str());
624 outstr.str("");
625
626 if (m_doTruth)
627 {
628 outstr.str("");
629 outstr << "\n"
630 << "\t" << "TrackTruthCollections : ";
631 first = true;
632 for (std::vector <class TrackStatHelper *>::const_iterator collection = m_SignalCounters.begin();
633 collection != m_SignalCounters.end(); ++collection)
634 {
635 if (first) {
636 first = false;
637 }
638 else {
639 outstr << ", ";
640 }
641 outstr << "\"" << (*collection)->Truthkey() << "\"";
642 }
643 ATH_MSG_INFO(outstr.str());
644 outstr.str("");
645 }
646 outstr.str("");
647 outstr << "\n"
648 << s_linestr2 << "\n"
649 << "Cuts and Settings for Statistics Table" << "\n"
650 << "\t" << "TrackSummary Statistics" << "\t"
651 << (m_UseTrackSummary ? "YES" : "NO") << "\n"
652 << "\t" << "Signal \t" << "pT > "
653 << m_minPt/1000 << " GeV/c, |eta| < " << m_maxEta << "\t\t"
654 << "\t" << "Primary track start \t" << "R < "
655 << m_maxRStartPrimary << "mm and |z| < "
656 << m_maxZStartPrimary << "mm" << "\n"
657 << "\t" << "Barrel \t" << 0.0
658 << "< |eta| < " << m_maxEtaBarrel << "\t\t\t"
659 << "\t" << "Primary track end \t" << "R > "
660 << m_minREndPrimary << "mm or |z| > " << m_minZEndPrimary
661 << "mm" << "\n"
662 << "\t" << "Transition Region \t" << m_maxEtaBarrel
663 << "< |eta| < " << m_maxEtaTransition << "\t\t\t"
664 << "\t" << "Secondary (non-Primary) start \t"
665 << " R < " << m_maxRStartSecondary << "mm and"
666 << " |z| < " << m_maxZStartSecondary << " mm" << "\n"
667 << "\t" << "Endcap \t" << m_maxEtaTransition
668 << "< |eta| < " << m_maxEtaEndcap << "\t\t\t"
669 << "\t" << "Secondary (non-primary) end \t"
670 << " R > " << m_minREndSecondary << "mm or"
671 << " |z| > " << m_minREndSecondary << "mm" << "\n"
672 << "\t" << "Forward \t"
673 << "|eta| > " << m_minEtaFORWARD << "\n"
674 << "\t" << "Low prob tracks #1 \t" << "< "
675 << m_fakeTrackCut << " of hits from single Truth Track "
676 << "\n"
677 << "\t" << "Low prob tracks #2 \t" << "< "
678 << m_fakeTrackCut2 << " of hits from single Truth Track "
679 << "\n"
680 << "\t" << "No link tracks \t Track has no link associated to an HepMC Particle" << "\n"
681 << "\t" << "Good reco tracks \t" << "> "
682 << m_matchTrackCut << " of hits from single Truth Track + a link !";
683 ATH_MSG_INFO(outstr.str());
684 outstr.str("");
685
686 MsgStream &out = msg(MSG::INFO);
687 {
688 RestoreStream<MsgStream> restore(out);
689 out << "\n" << s_linestr2 << "\n";
690 m_SignalCounters.back()->print(out);
691
692 if (m_UseTrackSummary) {
693 std::string track_stummary_type_header = TrackStatHelper::getSummaryTypeHeader();
694 out << "\n"
695 << s_linestr2 << "\n"
696 << "Detailed Statistics for Hits on Reconstructed tracks, using TrackSummary: (Preselection of tracks as described above.)" << "\n"
697 << s_linestr2 << "\n"
698 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n"
699 << " Reco Tracks .........................................hits/track....................................................... " << "\n"
700 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n"
701 << " in BARREL tracks/event " << track_stummary_type_header << "\n"
702 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n";
703 printTrackSummary (out, ETA_BARREL);
704
705 out<< "\n"
706 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n"
707 << " in TRANSITION region tracks/event " << track_stummary_type_header << "\n"
708 << "----------------------------------------------------------------------------------------------------------------------------------------------------"
709 << "\n";
710 printTrackSummary (out, ETA_TRANSITION);
711
712 out << "\n"
713 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n"
714 << " in ENDCAP tracks/event " << track_stummary_type_header << "\n"
715 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n";
716 printTrackSummary (out, ETA_ENDCAP);
717
718 out << "\n"
719 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n"
720 << " in FORWARD region tracks/event " << track_stummary_type_header << "\n"
721 << "----------------------------------------------------------------------------------------------------------------------------------------------------" << "\n";
722 printTrackSummary (out, ETA_FORWARD);
723 }
724
726 outstr.str("");
727 outstr << "\n" << std::setprecision(def_precision)
728 <<s_linestr<<"\n"
729 <<"Statistics for Secondaries (non-Primaries)"<<"\n"
730 << "\t" << "Secondary track start \t"
731 << " R < " << m_maxRStartSecondary << "mm and"
732 << " |z| < " << m_maxZStartSecondary << " mm" << "\n"
733 << "\t" << "Secondary track end \t"
734 << " R > " << m_minREndSecondary << "mm or"
735 << " |z| > " << m_minZEndSecondary << "mm";
736 ATH_MSG_INFO(outstr.str());
737 outstr.str("");
738 out << "\n" << s_linestr2 << "\n";
739 m_SignalCounters.back()->printSecondary(out);
740
741 }
742 }
743 out << endmsg;
744
745 ATH_MSG_INFO(" ********** Ending InDetRecStatistics Statistics Table ***********");
746 ATH_MSG_INFO( "\n"
747 << s_linestr );
748}
749
750
751void InDet :: InDetRecStatisticsAlg ::printTrackSummary (MsgStream &out, enum eta_region eta_reg)
752{
753 bool printed = m_SignalCounters.back()->printTrackSummaryRegion(out, TRACK_ALL, eta_reg);
754
755 if (printed) {
756 out << "\n"
757 << "----------------------------------------------------------------------------------------------------------------------------------------------" << "\n";
758 }
759
760 printed = m_SignalCounters.back()->printTrackSummaryRegion(out, TRACK_LOWTRUTHPROB, eta_reg);
761 if (printed) {
762 out << "\n"
763 << "----------------------------------------------------------------------------------------------------------------------------------------------" << "\n";
764 }
765
766 m_SignalCounters.back()->printTrackSummaryRegion(out, TRACK_LOWTRUTHPROB2, eta_reg);
767
768}
769
770// =================================================================================================================
771// calculatePull
772// =================================================================================================================
773float InDet :: InDetRecStatisticsAlg :: calculatePull(const float residual,
774 const float trkErr,
775 const float hitErr){
776 double ErrorSum;
777 ErrorSum = sqrt(pow(trkErr, 2) + pow(hitErr, 2));
778 if (ErrorSum != 0) { return residual/ErrorSum; }
779 else { return 0; }
780}
781
783
784
785 const Trk::TrackParameters *unbiasedTrkParameters = nullptr;
786
787 // -----------------------------------------
788 // use unbiased track states or normal ones?
789 // unbiased track parameters are tried to retrieve if the updator tool
790 // is available and if unbiased track states could be produced before
791 // for the current track (ie. if one trial to get unbiased track states
792 // fail
793
794 if (m_updator && (m_isUnbiased==1) ) {
795 if ( trkParameters->covariance() ) {
796 // Get unbiased state
797 ATH_MSG_VERBOSE(" getting unbiased params");
798 unbiasedTrkParameters =
799 m_updator->removeFromState( *trkParameters,
800 measurement->localParameters(),
801 measurement->localCovariance()).release();
802
803 if (!unbiasedTrkParameters) {
804 ATH_MSG_WARNING("Could not get unbiased track parameters, "
805 <<"use normal parameters");
806 m_isUnbiased = 0;
807 }
808 } else if(!m_UpdatorWarning) {
809 // warn only once!
810 ATH_MSG_WARNING("TrackParameters contain no covariance: "
811 <<"Unbiased track states can not be calculated "
812 <<"(ie. pulls and residuals will be too small)");
813 m_UpdatorWarning = true;
814 m_isUnbiased = 0;
815 } else {
816 m_isUnbiased = 0;
817 }
818 } // end if no measured track parameter
819 return unbiasedTrkParameters;
820}
821
822
824 Identifier id;
825 const Trk::CompetingRIOsOnTrack *comprot = nullptr;
826 // identify by ROT:
827 const Trk::RIO_OnTrack *rot =
828 dynamic_cast<const Trk::RIO_OnTrack*>(measurement);
829 if (rot) {
830 id = rot->identify();
831 } else {
832 // identify by CompetingROT:
833 comprot = dynamic_cast<const Trk::CompetingRIOsOnTrack*>(measurement);
834 if (comprot) {
835 rot = &comprot->rioOnTrack(comprot->indexOfMaxAssignProb());
836 id = rot->identify();
837 } else {
838 ATH_MSG_DEBUG("measurement is neither ROT nor competingROT:"
839 <<" can not determine detector type");
840 id.clear();
841 }
842 }
843 delete comprot;
844 return id;
845}
#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)
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
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