ATLAS Offline Software
TrackTruthMatchingTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "TrackTruthMatchingTool.h"
13 #include "TrackMatchingLookup.h"
15 #include "TrackParametersHelper.h"
16 
18 #include <algorithm> // for std::find
19 
24  const std::string& name ) :
25  asg::AsgTool( name ) { }
26 
27 
32 {
34 
35  ATH_MSG_DEBUG( "Initializing " << name() << "..." );
36 
37  return StatusCode::SUCCESS;
38 }
39 
40 
45  TrackAnalysisCollections& trkAnaColls,
46  const std::string& chainRoIName,
47  const std::string& roiStr ) const
48 {
50  bool doMatch = trkAnaColls.updateChainRois( chainRoIName, roiStr );
51 
53  if( not doMatch ) {
54  ATH_MSG_WARNING( "Matching for " << chainRoIName <<
55  " was already done. Skipping" );
56  return StatusCode::SUCCESS;
57  }
58 
63  trkAnaColls.matches() ) );
64 
65  ATH_MSG_DEBUG( trkAnaColls.printMatchInfo() );
66 
67  return StatusCode::SUCCESS;
68 }
69 
70 
75  const std::vector< const xAOD::TrackParticle* >& vTest,
76  const std::vector< const xAOD::TruthParticle* >& vRef,
77  ITrackMatchingLookup& matches ) const
78 {
79  ATH_MSG_DEBUG( "Doing Track->Truth matching via truthParticleLink" );
80 
81  for( const xAOD::TrackParticle* track_particle : vTest ) {
82 
84  const xAOD::TruthParticle* truth_particle = getLinkedTruth(
85  *track_particle, m_truthProbCut.value() );
86 
88  if( not truth_particle ) continue;
89 
90  ATH_MSG_DEBUG( "Found matched truth particle with pT = " <<
91  pT( *truth_particle ) << " and prob = " <<
92  getTruthMatchProb( *track_particle ) );
93 
96  if( std::find( vRef.begin(), vRef.end(),
97  truth_particle ) == vRef.end() ) {
98  ATH_MSG_DEBUG( "Truth particle is not in selected reference. Skipping." );
99  continue;
100  }
101 
103  float dist = 1 - getTruthMatchProb( *track_particle );
104 
106  ATH_CHECK( matches.update( *track_particle, *truth_particle, dist ) );
107  } // loop over vTest
108 
109  return StatusCode::SUCCESS;
110 }
IDTPM::getTruthMatchProb
float getTruthMatchProb(const xAOD::TrackParticle &track)
getTruthMatchProb
Definition: OfflineObjectDecorHelper.cxx:53
IDTPM::TrackTruthMatchingTool::match
virtual StatusCode match(TrackAnalysisCollections &trkAnaColls, const std::string &chainRoIName, const std::string &roiStr) const override
General matching method, via TrackAnalysisCollections.
Definition: TrackTruthMatchingTool.cxx:44
IDTPM::TrackAnalysisCollections
Definition: TrackAnalysisCollections.h:46
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
IDTPM::TrackAnalysisCollections::updateChainRois
bool updateChainRois(const std::string &chainRoi, const std::string &roiStr)
update chainRois map
Definition: TrackAnalysisCollections.cxx:1155
IDTPM::getLinkedTruth
const xAOD::TruthParticle * getLinkedTruth(const xAOD::TrackParticle &track, const float truthProbCut)
getLinkedTruth
Definition: OfflineObjectDecorHelper.cxx:61
asg
Definition: DataHandleTestTool.h:28
TrackAnalysisCollections.h
Class to hold for each event collections needed in the TrkAnalsis.
IDTPM::TrackAnalysisCollections::printMatchInfo
std::string printMatchInfo()
print track matching information
Definition: TrackAnalysisCollections.cxx:1137
IDTPM::TrackAnalysisCollections::testTrackVec
const std::vector< const xAOD::TrackParticle * > & testTrackVec(Stage stage=FULL)
TEST = Track.
Definition: TrackAnalysisCollections.cxx:789
TrackParametersHelper.h
Utility methods to access track/truth particles parmeters in a consitent way in this package.
TrackMatchingLookup.h
Look-up table (templated) class to store (internally to IDTPM) all the matches between test and refer...
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
IDTPM::TrackAnalysisCollections::matches
ITrackMatchingLookup & matches()
get track matching information
Definition: TrackAnalysisCollections.h:261
IDTPM::pT
float pT(const U &p)
Accessor utility function for getting the value of pT.
Definition: TrackParametersHelper.h:33
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrackTruthMatchingTool.h
Tool to perform matching of tracks and truth particles via truthParticleLink decorations.
IDTPM::TrackTruthMatchingTool::TrackTruthMatchingTool
TrackTruthMatchingTool(const std::string &name)
Constructor.
Definition: TrackTruthMatchingTool.cxx:23
IDTPM::TrackTruthMatchingTool::initialize
virtual StatusCode initialize() override
Initialize.
Definition: TrackTruthMatchingTool.cxx:31
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
IDTPM::TrackAnalysisCollections::InRoI
@ InRoI
Definition: TrackAnalysisCollections.h:54
IDTPM::ITrackMatchingLookup::update
virtual StatusCode update(const xAOD::TrackParticle &t, const xAOD::TrackParticle &r, float dist=0.)=0
update lookup tables with a new entry Track -> Track
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
OfflineObjectDecorHelper.h
Utility methods to access offline object decorations.
IDTPM::ITrackMatchingLookup
Definition: ITrackMatchingLookup.h:30
asg::AsgTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: AsgTool.h:133
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356
IDTPM::TrackAnalysisCollections::refTruthVec
const std::vector< const xAOD::TruthParticle * > & refTruthVec(Stage stage=FULL)
get REFERENCE track vectors
Definition: TrackAnalysisCollections.cxx:806