19 #include "GaudiKernel/SmartDataPtr.h"
20 #include "GaudiKernel/IPartPropSvc.h"
21 #include "HepPDT/ParticleData.hh"
22 #include "CLHEP/Units/SystemOfUnits.h"
71 static const char *
const s_linestr =
"----------------------------------------------------------------------------------------------------------------------------------------------";
72 static const char *
const s_linestr2 =
"..............................................................................................................................................";
76 m_particleDataTable (nullptr),
78 m_idDictMgr (nullptr),
79 m_truthToTrack (
"Trk::TruthToTrack"),
80 m_trkSummaryTool (
"Trk::TrackSummaryTool/InDetTrackSummaryTool"),
81 m_updatorHandle (
"Trk::KalmanUpdator/TrkKalmanUpdator"),
83 m_residualPullCalculator (
"Trk::ResidualPullCalculator/ResidualPullCalculator"),
84 m_McTrackCollection_key (
"TruthEvent"),
85 m_trackSelectorTool (
"InDet::InDetDetailedTrackSelectorTool"),
86 m_UseTrackSummary (true),
87 m_printSecondary (false),
91 m_maxEtaTransition (1.6),
94 m_fakeTrackCut2 (0.7),
95 m_matchTrackCut (0.5),
96 m_maxRStartPrimary ( 25.0*
CLHEP::
mm),
97 m_maxRStartSecondary ( 360.0*
CLHEP::
mm),
98 m_maxZStartPrimary ( 200.0*
CLHEP::
mm),
99 m_maxZStartSecondary (2000.0*
CLHEP::
mm),
100 m_minREndPrimary ( 400.0*
CLHEP::
mm),
101 m_minREndSecondary (1000.0*
CLHEP::
mm),
102 m_minZEndPrimary (2300.0*
CLHEP::
mm),
104 m_minZEndSecondary (3200.0*
CLHEP::
mm),
105 m_useTrackSelection (false),
107 m_minEtaFORWARD (2.5),
108 m_maxEtaFORWARD (4.2),
110 m_events_processed (0)
119 "Measurement updator to calculate unbiased track states");
121 "Tool to calculate residuals and pulls");
163 if (sc1.isFailure()) {
165 return StatusCode::FAILURE;
169 ATH_MSG_ERROR(
"No reco track collection specified! Aborting.");
170 return StatusCode::FAILURE;
177 <<
" TrackTruthCollection keys."
178 <<
" You have to specify one TrackTruthCollection for each"
179 <<
" TrackCollection! Exiting."
181 return StatusCode::FAILURE;
188 ATH_MSG_FATAL(
"Could not retrieve measurement updator tool: "
190 return StatusCode::FAILURE;
195 "No Updator for unbiased track states given, use normal states!");
203 "No residual/pull calculator for general hit residuals configured."
206 "It is recommended to give R/P calculators to the det-specific tool"
207 <<
" handle lists then.");
210 <<
" (to calculate residuals and pulls) ");
213 ATH_MSG_INFO(
"Generic hit residuals&pulls will be calculated in one or both "
214 <<
"available local coordinates");
238 unsigned int nCollections = 0;
250 if (sc3.isFailure()) {
252 return StatusCode::FAILURE;
259 return StatusCode :: SUCCESS;
279 return StatusCode::SUCCESS;
292 std::vector <std::pair<HepMC::ConstGenParticlePtr,int> > GenSignal;
294 unsigned int inTimeStart = 0;
295 unsigned int inTimeEnd = 0;
302 ATH_MSG_ERROR(
"No reco track collection specified! Aborting.");
303 return StatusCode::FAILURE;
307 std::vector< SG::ReadHandle<TrackTruthCollection> > truth_track_collections;
310 if (truth_track_collections.size() != rec_track_collections.size()) {
311 ATH_MSG_ERROR(
"Different number of reco and truth track collections (" << rec_track_collections.size() <<
"!=" << truth_track_collections.size() <<
")" );
315 ATH_MSG_ERROR(
"Number expected reco track collections does not match the actual number of such collections ("
316 <<
m_SignalCounters.size() <<
"!=" << rec_track_collections.size() <<
")" );
319 std::vector< SG::ReadHandle<TrackCollection> >
::iterator rec_track_collections_iter = rec_track_collections.begin();
320 std::vector< SG::ReadHandle<TrackTruthCollection> >
::iterator truth_track_collections_iter = truth_track_collections.begin();
321 for (std::vector <class TrackStatHelper *>::const_iterator statHelper
324 ++statHelper, ++rec_track_collections_iter) {
325 assert( rec_track_collections_iter != rec_track_collections.end());
328 const TrackCollection * RecCollection = &(**rec_track_collections_iter);
331 if (RecCollection)
ATH_MSG_DEBUG(
"Retrieved " << RecCollection->
size() <<
" reconstructed tracks from storegate");
335 assert( truth_track_collections_iter != truth_track_collections.end());
336 TruthMap = &(**truth_track_collections_iter);
337 if (TruthMap)
ATH_MSG_DEBUG(
"Retrieved " << TruthMap->size() <<
" TrackTruth elements from storegate");
338 ++truth_track_collections_iter;
343 std::vector <const Trk::Track *> RecTracks, RecSignal;
347 " RecTracks.size()=" << RecTracks.size()
348 <<
", GenSignal.size()=" << GenSignal.size());
351 (*statHelper)->addEvent (RecCollection,
366 it < RecCollection->
end(); ++
it){
367 std::vector<const Trk::RIO_OnTrack*> rioOnTracks;
369 (*it)->measurementsOnTrack()->stdcont() );
377 return StatusCode::SUCCESS;
390 for (std::vector <class TrackStatHelper *>::const_iterator collection =
391 m_SignalCounters.begin(); collection != m_SignalCounters.end();
394 delete (*collection);
396 m_SignalCounters.clear();
397 return StatusCode::SUCCESS;
404 IPartPropSvc* partPropSvc =
nullptr;
405 StatusCode sc = evtStore()->service(
"PartPropSvc", partPropSvc,
true);
407 if (
sc.isFailure()) {
408 ATH_MSG_FATAL(
" Could not initialize Particle Properties Service" );
409 return StatusCode::FAILURE;
412 m_particleDataTable = partPropSvc->PDT();
418 sc =
detStore()->retrieve(idDictMgr,
"IdDict");
419 if (
sc.isFailure()) {
421 return StatusCode::FAILURE;
425 sc =
detStore()->retrieve(m_idHelper,
"AtlasID");
426 if (
sc.isFailure()) {
428 return StatusCode::FAILURE;
435 return StatusCode::FAILURE;
439 return StatusCode::FAILURE;
443 sc =
detStore()->retrieve(m_idDictMgr,
"IdDict");
444 if (
sc.isFailure()) {
446 return StatusCode::FAILURE;
448 const IdDictDictionary* dict = m_idDictMgr->manager()->find_dictionary(
"InnerDetector");
451 return StatusCode::FAILURE;
455 if (dict->
file_name().find(
"SLHC")!=std::string::npos) isSLHC=
true;
460 return StatusCode::FAILURE;
465 if (m_UseTrackSummary) {
466 if (m_trkSummaryTool.retrieve().isFailure() ) {
468 << m_trkSummaryTool);
469 return StatusCode::FAILURE;
474 m_trkSummaryTool.disable();
479 if (m_truthToTrack.retrieve().isFailure() ) {
481 return StatusCode::FAILURE;
486 m_truthToTrack.disable();
490 if(m_useTrackSelection){
491 if ( m_trackSelectorTool.retrieve().isFailure() ) {
492 ATH_MSG_FATAL(
"Failed to retrieve tool " << m_trackSelectorTool);
493 return StatusCode::FAILURE;
498 m_trackSelectorTool.disable();
500 return StatusCode :: SUCCESS;
503 StatusCode InDet :: InDetRecStatisticsAlg :: resetStatistics() {
505 m_events_processed = 0;
507 for (std::vector<InDet::TrackStatHelper *>::const_iterator
counter =
508 m_SignalCounters.begin();
512 return StatusCode :: SUCCESS;
516 std::vector <const Trk::Track *> & RecTracks ,
517 std::vector <const Trk::Track *> & RecSignal,
521 it != RecCollection->
end(); ++
it){
522 RecTracks.push_back(*
it);
524 (*it)->trackParameters();
526 if(!trackpara->
empty()){
530 RecSignal.push_back(*
it);
541 void InDet :: InDetRecStatisticsAlg ::
543 std::vector <std::pair<HepMC::ConstGenParticlePtr,int> > & GenSignal,
544 unsigned int ,
unsigned int ,
547 if (! SimTracks)
return;
549 unsigned int nb_mc_event = SimTracks->size();
550 std::unique_ptr<PileUpType> put = std::make_unique<PileUpType>(SimTracks);
561 for(
unsigned int ievt=0; ievt<nb_mc_event; ++ievt)
563 const HepMC::GenEvent* genEvent = SimTracks->at(ievt);
564 counter.m_counter[kN_gen_tracks_processed] += genEvent->particles_size();
565 for (
const auto&
particle: *genEvent){
569 const HepPDT::ParticleData* pd = m_particleDataTable->particle(std::abs(pdgCode));
575 float charge = pd->charge();
576 if (std::abs(
charge)<0.5)
continue;
577 if (std::abs(
particle->momentum().perp()) > m_minPt &&
578 std::abs(
particle->momentum().pseudoRapidity()) < m_maxEta ) {
579 std::pair<HepMC::ConstGenParticlePtr,int> thisPair(
particle,ievt);
580 GenSignal.push_back(thisPair);
588 template <
class T_Stream>
592 RestoreStream(T_Stream &
out) : m_stream(&
out),m_precision(
out.precision()) { }
593 ~RestoreStream() { (*m_stream).precision(m_precision); }
600 void InDet :: InDetRecStatisticsAlg :: printStatistics() {
601 if (!msgLvl(MSG::INFO))
return;
603 ATH_MSG_INFO(
" ********** Beginning InDetRecStatistics Statistics Table ***********");
604 ATH_MSG_INFO(
"For documentation see https://twiki.cern.ch/twiki/bin/view/Atlas/InDetRecStatistics");
605 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 )");
606 ATH_MSG_INFO(
" ********************************************************************");
608 std::stringstream outstr;
609 int def_precision(outstr.precision());
612 << std::setiosflags(std::ios::fixed | std::ios::showpoint)
613 << std::setw(7) << std::setprecision(2)
616 <<
"\tProcessed : " << m_events_processed
617 <<
" events, " << m_counter.m_counter[kN_rec_tracks_processed]
618 <<
" reconstructed tracks with " << m_counter.m_counter[kN_spacepoints_processed]
619 <<
" hits, and " << m_counter.m_counter[kN_gen_tracks_processed]
620 <<
" truth particles" <<
"\n"
621 <<
"\tProblem objects : " << m_counter.m_counter[kN_rec_tracks_without_perigee]
622 <<
" tracks without perigee, "
623 << m_counter.m_counter[kN_unknown_hits] <<
" unknown hits" <<
"\n"
624 <<
"\t" <<
"Reco TrackCollections : ";
626 for (std::vector <class TrackStatHelper *>::const_iterator collection =
627 m_SignalCounters.begin();
628 collection != m_SignalCounters.end(); ++collection)
636 outstr <<
"\"" << (*collection)->key() <<
"\"";
645 <<
"\t" <<
"TrackTruthCollections : ";
647 for (std::vector <class TrackStatHelper *>::const_iterator collection = m_SignalCounters.begin();
648 collection != m_SignalCounters.end(); ++collection)
656 outstr <<
"\"" << (*collection)->Truthkey() <<
"\"";
663 << s_linestr2 <<
"\n"
664 <<
"Cuts and Settings for Statistics Table" <<
"\n"
665 <<
"\t" <<
"TrackSummary Statistics" <<
"\t"
666 << (m_UseTrackSummary ?
"YES" :
"NO") <<
"\n"
667 <<
"\t" <<
"Signal \t" <<
"pT > "
668 << m_minPt/1000 <<
" GeV/c, |eta| < " << m_maxEta <<
"\t\t"
669 <<
"\t" <<
"Primary track start \t" <<
"R < "
670 << m_maxRStartPrimary <<
"mm and |z| < "
671 << m_maxZStartPrimary <<
"mm" <<
"\n"
672 <<
"\t" <<
"Barrel \t" << 0.0
673 <<
"< |eta| < " << m_maxEtaBarrel <<
"\t\t\t"
674 <<
"\t" <<
"Primary track end \t" <<
"R > "
675 << m_minREndPrimary <<
"mm or |z| > " << m_minZEndPrimary
677 <<
"\t" <<
"Transition Region \t" << m_maxEtaBarrel
678 <<
"< |eta| < " << m_maxEtaTransition <<
"\t\t\t"
679 <<
"\t" <<
"Secondary (non-Primary) start \t"
680 <<
" R < " << m_maxRStartSecondary <<
"mm and"
681 <<
" |z| < " << m_maxZStartSecondary <<
" mm" <<
"\n"
682 <<
"\t" <<
"Endcap \t" << m_maxEtaTransition
683 <<
"< |eta| < " << m_maxEtaEndcap <<
"\t\t\t"
684 <<
"\t" <<
"Secondary (non-primary) end \t"
685 <<
" R > " << m_minREndSecondary <<
"mm or"
686 <<
" |z| > " << m_minREndSecondary <<
"mm" <<
"\n"
687 <<
"\t" <<
"Forward \t"
688 <<
"|eta| > " << m_minEtaFORWARD <<
"\n"
689 <<
"\t" <<
"Low prob tracks #1 \t" <<
"< "
690 << m_fakeTrackCut <<
" of hits from single Truth Track "
692 <<
"\t" <<
"Low prob tracks #2 \t" <<
"< "
693 << m_fakeTrackCut2 <<
" of hits from single Truth Track "
695 <<
"\t" <<
"No link tracks \t Track has no link associated to an HepMC Particle" <<
"\n"
696 <<
"\t" <<
"Good reco tracks \t" <<
"> "
697 << m_matchTrackCut <<
" of hits from single Truth Track + a link !";
701 MsgStream &
out =
msg(MSG::INFO);
703 RestoreStream<MsgStream> restore(
out);
704 out <<
"\n" << s_linestr2 <<
"\n";
705 m_SignalCounters.back()->print(
out);
707 if (m_UseTrackSummary) {
710 << s_linestr2 <<
"\n"
711 <<
"Detailed Statistics for Hits on Reconstructed tracks, using TrackSummary: (Preselection of tracks as described above.)" <<
"\n"
712 << s_linestr2 <<
"\n"
713 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
714 <<
" Reco Tracks .........................................hits/track....................................................... " <<
"\n"
715 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
716 <<
" in BARREL tracks/event " << track_stummary_type_header <<
"\n"
717 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
721 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
722 <<
" in TRANSITION region tracks/event " << track_stummary_type_header <<
"\n"
723 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------"
728 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
729 <<
" in ENDCAP tracks/event " << track_stummary_type_header <<
"\n"
730 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
734 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
735 <<
" in FORWARD region tracks/event " << track_stummary_type_header <<
"\n"
736 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
740 if(m_printSecondary){
742 outstr <<
"\n" << std::setprecision(def_precision)
744 <<
"Statistics for Secondaries (non-Primaries)"<<
"\n"
745 <<
"\t" <<
"Secondary track start \t"
746 <<
" R < " << m_maxRStartSecondary <<
"mm and"
747 <<
" |z| < " << m_maxZStartSecondary <<
" mm" <<
"\n"
748 <<
"\t" <<
"Secondary track end \t"
749 <<
" R > " << m_minREndSecondary <<
"mm or"
750 <<
" |z| > " << m_minZEndSecondary <<
"mm";
753 out <<
"\n" << s_linestr2 <<
"\n";
754 m_SignalCounters.back()->printSecondary(
out);
760 ATH_MSG_INFO(
" ********** Ending InDetRecStatistics Statistics Table ***********");
766 void InDet :: InDetRecStatisticsAlg ::printTrackSummary (MsgStream &
out,
enum eta_region eta_reg)
768 bool printed = m_SignalCounters.back()->printTrackSummaryRegion(
out,
TRACK_ALL, eta_reg);
772 <<
"----------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
778 <<
"----------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
788 float InDet :: InDetRecStatisticsAlg :: calculatePull(
const float residual,
792 ErrorSum = sqrt(
pow(trkErr, 2) +
pow(hitErr, 2));
793 if (ErrorSum != 0) {
return residual/ErrorSum; }
810 if ( trkParameters->covariance() ) {
813 unbiasedTrkParameters =
818 if (!unbiasedTrkParameters) {
820 <<
"use normal parameters");
826 <<
"Unbiased track states can not be calculated "
827 <<
"(ie. pulls and residuals will be too small)");
834 return unbiasedTrkParameters;
854 <<
" can not determine detector type");