23 const std::string& anaTag ) :
44 m_trkAnaDefSvc = Gaudi::svcLocator()->service(
"TrkAnaDefSvc"+m_anaTag );
50 if( m_trkAnaDefSvc->isTestTruth() ) {
51 m_matches = std::make_unique< TrackMatchingLookup_truthTrk >( m_anaTag );
54 else if( m_trkAnaDefSvc->isReferenceTruth() ) {
55 m_matches = std::make_unique< TrackMatchingLookup_trkTruth >( m_anaTag );
59 m_matches = std::make_unique< TrackMatchingLookup_trk >( m_anaTag );
62 return StatusCode::SUCCESS;
73 m_eventInfo =
nullptr;
74 m_truthEventContainer =
nullptr;
75 m_truthPUEventContainer =
nullptr;
81 }
else m_eventInfo = pie.
ptr();
83 if( not m_trkAnaDefSvc->useTruth() )
return StatusCode::SUCCESS;
87 if( not pTruthEventCont.
isValid() ) {
90 else m_truthEventContainer = pTruthEventCont.
ptr();
93 if( m_trkAnaDefSvc->hasFullPileupTruth() ) {
95 if( not pTruthPUEventCont.
isValid() ) {
96 ATH_MSG_WARNING(
"Non valid truth pile up event collection: " << truthPUEventHandleKey.
key() );
98 else m_truthPUEventContainer = pTruthPUEventCont.
ptr();
101 return StatusCode::SUCCESS;
111 if( m_trkAnaDefSvc->useTruth() ) {
114 if( not pTruthColl.
isValid() ) {
115 ATH_MSG_ERROR(
"Non valid truth particles collection: " << truthPartHandleKey.
key() );
116 return StatusCode::FAILURE;
120 m_truthPartContainer = pTruthColl.
ptr();
126 if( m_trkAnaDefSvc->pileupSwitch() ==
"All" ) {
127 m_truthPartVec[
FULL ].insert(
131 }
else if( m_trkAnaDefSvc->pileupSwitch() ==
"HardScatter" ) {
132 if( m_truthEventContainer ) {
134 const auto&
links =
event->truthParticleLinks();
135 for(
const auto& link :
links ) {
136 if( link.isValid() ) m_truthPartVec[
FULL ].push_back( *link );
141 }
else if( m_trkAnaDefSvc->pileupSwitch() ==
"PileUp" ) {
142 if( m_truthPUEventContainer ) {
144 for(
size_t ipu=0; ipu < m_truthPUEventContainer->size(); ipu++ ) {
147 for(
const auto& link :
links ) {
148 if( link.isValid() ) m_truthPartVec[
FULL ].push_back( *link );
154 ATH_MSG_ERROR(
"Invalid pileupSwitch: " << m_trkAnaDefSvc->pileupSwitch() );
155 return StatusCode::FAILURE;
158 m_truthPartContainer =
nullptr;
159 m_truthPartVec[
FULL ].clear();
162 return StatusCode::SUCCESS;
169 if( m_trkAnaDefSvc->useOffline() ) {
175 ATH_MSG_ERROR(
"Non valid offline tracks collection: " << handleKey.
key() );
176 return StatusCode::FAILURE;
180 m_offlTrackContainer = pColl.
ptr();
184 m_offlTrackVec[
FULL ].insert(
188 m_offlTrackContainer =
nullptr;
189 m_offlTrackVec[
FULL ].clear();
192 return StatusCode::SUCCESS;
199 if( m_trkAnaDefSvc->useTrigger()) {
205 ATH_MSG_ERROR(
"Non valid trigger tracks collection: " << handleKey.
key() );
206 return StatusCode::FAILURE;
210 m_trigTrackContainer = pColl.
ptr();
214 m_trigTrackVec[
FULL ].insert(
218 m_trigTrackContainer =
nullptr;
219 m_trigTrackVec[
FULL ].clear();
222 return StatusCode::SUCCESS;
230 const std::vector< const xAOD::TruthParticle* >&
vec,
233 if( m_trkAnaDefSvc->isTestTruth() ) {
234 m_truthPartVec[
stage ].clear();
235 m_truthPartVec[
stage ].insert(
238 return StatusCode::SUCCESS;
242 return StatusCode::SUCCESS;
247 const std::vector< const xAOD::TrackParticle* >&
vec,
250 if( m_trkAnaDefSvc->isTestOffline() ) {
251 m_offlTrackVec[
stage ].clear();
252 m_offlTrackVec[
stage ].insert(
255 return StatusCode::SUCCESS;
258 if( m_trkAnaDefSvc->isTestTrigger() ) {
259 m_trigTrackVec[
stage ].clear();
260 m_trigTrackVec[
stage ].insert(
263 return StatusCode::SUCCESS;
267 return StatusCode::SUCCESS;
275 const std::vector< const xAOD::TruthParticle* >&
vec,
278 if( m_trkAnaDefSvc->isReferenceTruth() ) {
279 m_truthPartVec[
stage ].clear();
280 m_truthPartVec[
stage ].insert(
283 return StatusCode::SUCCESS;
287 return StatusCode::SUCCESS;
292 const std::vector< const xAOD::TrackParticle* >&
vec,
295 if( m_trkAnaDefSvc->isReferenceOffline() ) {
296 m_offlTrackVec[
stage ].clear();
297 m_offlTrackVec[
stage ].insert(
300 return StatusCode::SUCCESS;
303 if( m_trkAnaDefSvc->isReferenceTrigger() ) {
304 m_trigTrackVec[
stage ].clear();
305 m_trigTrackVec[
stage ].insert(
308 return StatusCode::SUCCESS;
312 return StatusCode::SUCCESS;
320 const std::vector< const xAOD::TruthParticle* >&
vec,
323 if( m_trkAnaDefSvc->useTruth() ) {
324 m_truthPartVec[
stage ].clear();
325 m_truthPartVec[
stage ].insert(
328 return StatusCode::SUCCESS;
332 return StatusCode::SUCCESS;
337 const std::vector< const xAOD::TrackParticle* >&
vec,
340 if( m_trkAnaDefSvc->useOffline() ) {
341 m_offlTrackVec[
stage ].clear();
342 m_offlTrackVec[
stage ].insert(
345 return StatusCode::SUCCESS;
349 return StatusCode::SUCCESS;
354 const std::vector< const xAOD::TrackParticle* >&
vec,
357 if( m_trkAnaDefSvc->useTrigger() or m_trkAnaDefSvc->useEFTrigger() ) {
358 m_trigTrackVec[
stage ].clear();
359 m_trigTrackVec[
stage ].insert(
362 return StatusCode::SUCCESS;
366 return StatusCode::SUCCESS;
376 m_truthVertexContainer =
nullptr;
377 m_truthVertexVec[
FULL ].clear();
380 if( not m_trkAnaDefSvc->useTruth() or
381 truthVertexHandleKey.
key().empty() )
return StatusCode::SUCCESS;
385 if( not pTruthVertColl.
isValid() ) {
386 ATH_MSG_ERROR(
"Non valid truth vertex collection: " << truthVertexHandleKey.
key() );
387 return StatusCode::FAILURE;
391 m_truthVertexContainer = pTruthVertColl.
ptr();
396 pTruthVertColl->
begin(), pTruthVertColl->
end() );
400 return StatusCode::SUCCESS;
407 m_offlVertexContainer =
nullptr;
408 m_offlVertexVec[
FULL ].clear();
411 if( not m_trkAnaDefSvc->useOffline() or
412 handleKey.
key().empty() )
return StatusCode::SUCCESS;
417 ATH_MSG_ERROR(
"Non valid offline vertex collection: " << handleKey.
key() );
418 return StatusCode::FAILURE;
422 m_offlVertexContainer = pColl.
ptr();
429 return StatusCode::SUCCESS;
436 m_trigVertexContainer =
nullptr;
437 m_trigVertexVec[
FULL ].clear();
440 if( not m_trkAnaDefSvc->useTrigger() or
441 handleKey.
key().empty() )
return StatusCode::SUCCESS;
446 ATH_MSG_ERROR(
"Non valid trigger vertex collection: " << handleKey.
key() );
447 return StatusCode::FAILURE;
451 m_trigVertexContainer = pColl.
ptr();
458 return StatusCode::SUCCESS;
466 const std::vector< const xAOD::TruthVertex* >&
vec,
469 if( m_trkAnaDefSvc->isTestTruth() ) {
470 m_truthVertexVec[
stage ].clear();
471 m_truthVertexVec[
stage ].insert(
474 return StatusCode::SUCCESS;
478 return StatusCode::SUCCESS;
483 const std::vector< const xAOD::Vertex* >&
vec,
486 if( m_trkAnaDefSvc->isTestOffline() ) {
487 m_offlVertexVec[
stage ].clear();
488 m_offlVertexVec[
stage ].insert(
491 return StatusCode::SUCCESS;
493 }
else if( m_trkAnaDefSvc->isTestTrigger() ) {
494 m_trigVertexVec[
stage ].clear();
495 m_trigVertexVec[
stage ].insert(
498 return StatusCode::SUCCESS;
502 return StatusCode::SUCCESS;
510 const std::vector< const xAOD::TruthVertex* >&
vec,
513 if( m_trkAnaDefSvc->isReferenceTruth() ) {
514 m_truthVertexVec[
stage ].clear();
515 m_truthVertexVec[
stage ].insert(
518 return StatusCode::SUCCESS;
522 return StatusCode::SUCCESS;
527 const std::vector< const xAOD::Vertex* >&
vec,
530 if( m_trkAnaDefSvc->isReferenceOffline() ) {
531 m_offlVertexVec[
stage ].clear();
532 m_offlVertexVec[
stage ].insert(
535 return StatusCode::SUCCESS;
537 }
else if( m_trkAnaDefSvc->isReferenceTrigger() ) {
538 m_trigVertexVec[
stage ].clear();
539 m_trigVertexVec[
stage ].insert(
542 return StatusCode::SUCCESS;
546 return StatusCode::SUCCESS;
554 const std::vector< const xAOD::TruthVertex* >&
vec,
557 if( m_trkAnaDefSvc->useTruth() ) {
558 m_truthVertexVec[
stage ].clear();
559 m_truthVertexVec[
stage ].insert(
562 return StatusCode::SUCCESS;
566 return StatusCode::SUCCESS;
571 const std::vector< const xAOD::Vertex* >&
vec,
574 if( m_trkAnaDefSvc->useOffline() ) {
575 m_offlVertexVec[
stage ].clear();
576 m_offlVertexVec[
stage ].insert(
579 return StatusCode::SUCCESS;
583 return StatusCode::SUCCESS;
588 const std::vector< const xAOD::Vertex* >&
vec,
591 if( m_trkAnaDefSvc->useTrigger() or m_trkAnaDefSvc->useEFTrigger() ) {
592 m_trigVertexVec[
stage ].clear();
593 m_trigVertexVec[
stage ].insert(
596 return StatusCode::SUCCESS;
600 return StatusCode::SUCCESS;
612 bool isTrigEmpty = m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() and
614 m_trigTrackVec[
stage ].empty() :
false;
615 bool isEFTrigEmpty = m_trkAnaDefSvc->useEFTrigger() ?
616 m_trigTrackVec[
stage ].empty() :
false;
617 bool isOfflEmpty = m_trkAnaDefSvc->useOffline() ?
618 m_offlTrackVec[
stage ].empty() :
false;
619 bool isTruthEmpty = m_trkAnaDefSvc->useTruth() ?
620 m_truthPartVec[
stage ].empty() :
false;
622 if( isTrigEmpty or isEFTrigEmpty or isOfflEmpty or isTruthEmpty )
return true;
633 m_truthPartVec[
FULL ].clear();
634 m_offlTrackVec[
FULL ].clear();
635 m_trigTrackVec[
FULL ].clear();
637 m_truthVertexVec[
FULL ].clear();
638 m_offlVertexVec[
FULL ].clear();
639 m_trigVertexVec[
FULL ].clear();
643 m_truthPartVec[ FS ].clear();
644 m_offlTrackVec[ FS ].clear();
645 m_trigTrackVec[ FS ].clear();
647 m_truthVertexVec[ FS ].clear();
648 m_offlVertexVec[ FS ].clear();
649 m_trigVertexVec[ FS ].clear();
653 m_truthPartVec[ InRoI ].clear();
654 m_offlTrackVec[ InRoI ].clear();
655 m_trigTrackVec[ InRoI ].clear();
657 m_truthVertexVec[ InRoI ].clear();
658 m_offlVertexVec[ InRoI ].clear();
659 m_trigVertexVec[ InRoI ].clear();
670 m_offlTrackVec[ InRoI ].clear();
671 m_offlTrackVec[ InRoI ].insert(
672 m_offlTrackVec[ InRoI ].
begin(),
673 m_offlTrackVec[ FS ].
begin(),
674 m_offlTrackVec[ FS ].
end() );
676 m_offlVertexVec[ InRoI ].clear();
677 m_offlVertexVec[ InRoI ].insert(
678 m_offlVertexVec[ InRoI ].
begin(),
679 m_offlVertexVec[ FS ].
begin(),
680 m_offlVertexVec[ FS ].
end() );
684 m_truthPartVec[ InRoI ].clear();
685 m_truthPartVec[ InRoI ].insert(
686 m_truthPartVec[ InRoI ].
begin(),
687 m_truthPartVec[ FS ].
begin(),
688 m_truthPartVec[ FS ].
end() );
690 m_truthVertexVec[ InRoI ].clear();
691 m_truthVertexVec[ InRoI ].insert(
692 m_truthVertexVec[ InRoI ].
begin(),
693 m_truthVertexVec[ FS ].
begin(),
694 m_truthVertexVec[ FS ].
end() );
697 if( m_trkAnaDefSvc->useEFTrigger() ) {
699 m_trigTrackVec[ InRoI ].clear();
700 m_trigTrackVec[ InRoI ].insert(
701 m_trigTrackVec[ InRoI ].
begin(),
702 m_trigTrackVec[ FS ].
begin(),
703 m_trigTrackVec[ FS ].
end() );
705 m_trigVertexVec[ InRoI ].clear();
706 m_trigVertexVec[ InRoI ].insert(
707 m_trigVertexVec[ InRoI ].
begin(),
708 m_trigVertexVec[ FS ].
begin(),
709 m_trigVertexVec[ FS ].
end() );
713 ATH_MSG_DEBUG(
"Tracks and vertices after in RoI copy: " << printInfo( InRoI ) );
723 if( m_trkAnaDefSvc->isTestTruth() ) {
724 return m_truthPartContainer;
734 if( m_trkAnaDefSvc->isTestOffline() ) {
735 return m_offlTrackContainer;
738 if( m_trkAnaDefSvc->isTestTrigger() ) {
739 return m_trigTrackContainer;
749 if( m_trkAnaDefSvc->isReferenceTruth() ) {
750 return m_truthPartContainer;
760 if( m_trkAnaDefSvc->isReferenceOffline() ) {
761 return m_offlTrackContainer;
764 if( m_trkAnaDefSvc->isReferenceTrigger() ) {
765 return m_trigTrackContainer;
775 const std::vector< const xAOD::TruthParticle* >&
779 if( m_trkAnaDefSvc->isTestTruth() ) {
780 return m_truthPartVec[
stage ];
784 return m_nullTruthVec;
788 const std::vector< const xAOD::TrackParticle* >&
792 if( m_trkAnaDefSvc->isTestOffline() ) {
793 return m_offlTrackVec[
stage ];
796 if( m_trkAnaDefSvc->isTestTrigger() ) {
797 return m_trigTrackVec[
stage ];
801 return m_nullTrackVec;
805 const std::vector< const xAOD::TruthParticle* >&
809 if( m_trkAnaDefSvc->isReferenceTruth() ) {
810 return m_truthPartVec[
stage ];
814 return m_nullTruthVec;
818 const std::vector< const xAOD::TrackParticle* >&
822 if( m_trkAnaDefSvc->isReferenceOffline() ) {
823 return m_offlTrackVec[
stage ];
826 if( m_trkAnaDefSvc->isReferenceTrigger() ) {
827 return m_trigTrackVec[
stage ];
831 return m_nullTrackVec;
838 std::vector< size_t >
841 std::vector< size_t > counts( NCOUNTERS, 0 );
842 counts[ ALL ] = m_trkAnaDefSvc->isTestTruth() ?
843 testTruthVec(
FULL ).size() :
844 testTrackVec(
FULL ).size();
845 counts[ SELECTED ] = m_trkAnaDefSvc->isTestTruth() ?
846 testTruthVec( FS ).size() :
847 testTrackVec( FS ).size();
848 counts[ INROI ] = m_trkAnaDefSvc->isTestTruth() ?
849 testTruthVec( InRoI ).size() :
850 testTrackVec( InRoI ).size();
851 counts[
MATCHED ] = matches().getNmatches();
856 std::vector< size_t >
859 std::vector< size_t > counts( NCOUNTERS, 0 );
860 counts[ ALL ] = m_trkAnaDefSvc->isReferenceTruth() ?
861 refTruthVec(
FULL ).size() :
862 refTrackVec(
FULL ).size();
863 counts[ SELECTED ] = m_trkAnaDefSvc->isReferenceTruth() ?
864 refTruthVec( FS ).size() :
865 refTrackVec( FS ).size();
866 counts[ INROI ] = m_trkAnaDefSvc->isReferenceTruth() ?
867 refTruthVec( InRoI ).size() :
868 refTrackVec( InRoI ).size();
869 counts[
MATCHED ] = matches().getNmatches(
true );
880 if( m_trkAnaDefSvc->isTestTruth() ) {
881 return m_truthVertexContainer;
891 if( m_trkAnaDefSvc->isTestOffline() ) {
892 return m_offlVertexContainer;
895 if( m_trkAnaDefSvc->isTestTrigger() ) {
896 return m_trigVertexContainer;
906 if( m_trkAnaDefSvc->isReferenceTruth() ) {
907 return m_truthVertexContainer;
917 if( m_trkAnaDefSvc->isReferenceOffline() ) {
918 return m_offlVertexContainer;
921 if( m_trkAnaDefSvc->isReferenceTrigger() ) {
922 return m_trigVertexContainer;
932 const std::vector< const xAOD::TruthVertex* >&
936 if( m_trkAnaDefSvc->isTestTruth() ) {
937 return m_truthVertexVec[
stage ];
941 return m_nullTruthVertVec;
945 const std::vector< const xAOD::Vertex* >&
949 if( m_trkAnaDefSvc->isTestOffline() ) {
950 return m_offlVertexVec[
stage ];
953 if( m_trkAnaDefSvc->isTestTrigger() ) {
954 return m_trigVertexVec[
stage ];
958 return m_nullRecoVertVec;
962 const std::vector< const xAOD::TruthVertex* >&
966 if( m_trkAnaDefSvc->isReferenceTruth() ) {
967 return m_truthVertexVec[
stage ];
971 return m_nullTruthVertVec;
975 const std::vector< const xAOD::Vertex* >&
979 if( m_trkAnaDefSvc->isReferenceOffline() ) {
980 return m_offlVertexVec[
stage ];
983 if( m_trkAnaDefSvc->isReferenceTrigger() ) {
984 return m_trigVertexVec[
stage ];
988 return m_nullRecoVertVec;
995 std::vector< size_t >
998 std::vector< size_t > counts( NCOUNTERS, 0 );
999 counts[ ALL ] = m_trkAnaDefSvc->isTestTruth() ?
1000 testTruthVertexVec(
FULL ).size() :
1001 testRecoVertexVec(
FULL ).size();
1002 counts[ SELECTED ] = m_trkAnaDefSvc->isTestTruth() ?
1003 testTruthVertexVec( FS ).size() :
1004 testRecoVertexVec( FS ).size();
1005 counts[ INROI ] = m_trkAnaDefSvc->isTestTruth() ?
1006 testTruthVertexVec( InRoI ).size() :
1007 testRecoVertexVec( InRoI ).size();
1013 std::vector< size_t >
1016 std::vector< size_t > counts( NCOUNTERS, 0 );
1017 counts[ ALL ] = m_trkAnaDefSvc->isReferenceTruth() ?
1018 refTruthVertexVec(
FULL ).size() :
1019 refRecoVertexVec(
FULL ).size();
1020 counts[ SELECTED ] = m_trkAnaDefSvc->isReferenceTruth() ?
1021 refTruthVertexVec( FS ).size() :
1022 refRecoVertexVec( FS ).size();
1023 counts[ INROI ] = m_trkAnaDefSvc->isReferenceTruth() ?
1024 refTruthVertexVec( InRoI ).size() :
1025 refRecoVertexVec( InRoI ).size();
1037 std::stringstream
ss;
1038 ss <<
"\n==========================================" << std::endl;
1042 ss <<
"Offline track"
1043 <<
" : pt = " <<
pT( *thisOfflineTrack )
1044 <<
" : eta = " <<
eta( *thisOfflineTrack )
1045 <<
" : phi = " <<
phi( *thisOfflineTrack )
1047 if(
it > 20 ) {
ss <<
"et al...." << std::endl;
break; }
1052 ss <<
"==========================================" << std::endl;
1056 ss <<
"Truth particle"
1057 <<
" : pt = " <<
pT( *thisTruthParticle )
1058 <<
" : eta = " <<
eta( *thisTruthParticle )
1059 <<
" : phi = " <<
phi( *thisTruthParticle )
1061 if(
it > 20 ) {
ss <<
"et al...." << std::endl;
break; }
1066 ss <<
"==========================================" << std::endl;
1070 ss <<
"Trigger track"
1071 <<
" : pt = " <<
pT( *thisTriggerTrack )
1072 <<
" : eta = " <<
eta( *thisTriggerTrack )
1073 <<
" : phi = " <<
phi( *thisTriggerTrack )
1075 if(
it > 20 ) {
ss <<
"et al...." << std::endl;
break; }
1080 ss <<
"==========================================" << std::endl;
1083 if( printVertex )
ss <<
"Vertices: " << printVertexInfo(
stage );
1092 std::stringstream
ss;
1093 ss <<
"\n==========================================" << std::endl;
1097 ss <<
"Offline vertex"
1098 <<
" : z = " <<
posZ( *thisOfflineVertex )
1100 if(
it > 20 ) {
ss <<
"et al...." << std::endl;
break; }
1105 ss <<
"==========================================" << std::endl;
1109 ss <<
"Truth vertex"
1110 <<
" : z = " <<
posZ( *thisTruthVertex )
1112 if(
it > 20 ) {
ss <<
"et al...." << std::endl;
break; }
1117 ss <<
"==========================================" << std::endl;
1121 ss <<
"Trigger vertex"
1122 <<
" : z = " <<
posZ( *thisTriggerVertex )
1124 if(
it > 20 ) {
ss <<
"et al...." << std::endl;
break; }
1129 ss <<
"==========================================" << std::endl;
1140 if( m_trkAnaDefSvc->isTestTruth() ) {
1141 return m_matches->printInfo( testTruthVec( InRoI ), refTrackVec( InRoI ) );
1144 if( m_trkAnaDefSvc->isReferenceTruth() ) {
1145 return m_matches->printInfo( testTrackVec( InRoI ), refTruthVec( InRoI ) );
1148 return m_matches->printInfo( testTrackVec( InRoI ), refTrackVec( InRoI ) );
1156 const std::string& chainRoi,
const std::string& roiStr )
1158 ATH_MSG_DEBUG(
"Updating TrackAnalysisCollection with ChainRoiName: " << chainRoi );
1160 std::pair< mapChainRoi_t::iterator, bool >
result =
1161 m_chainRois.insert( mapChainRoi_t::value_type( chainRoi, roiStr ) );
1163 if( not
result.second ) {
1164 ATH_MSG_WARNING(
"ChainRoiName has already been cached. No update." );
1170 m_matches->chainRoiName( chainRoi );