ATLAS Offline Software
TruthTrackMatchingTool.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 "TruthTrackMatchingTool.h"
13 #include "TrackMatchingLookup.h"
15 #include "TrackParametersHelper.h"
16 
21  const std::string& name ) :
22  asg::AsgTool( name ) { }
23 
24 
29 {
31 
32  ATH_MSG_DEBUG( "Initializing " << name() << "..." );
33 
34  return StatusCode::SUCCESS;
35 }
36 
37 
42  TrackAnalysisCollections& trkAnaColls,
43  const std::string& chainRoIName,
44  const std::string& roiStr ) const
45 {
47  bool doMatch = trkAnaColls.updateChainRois( chainRoIName, roiStr );
48 
50  if( not doMatch ) {
51  ATH_MSG_WARNING( "Matching for " << chainRoIName <<
52  " was already done. Skipping" );
53  return StatusCode::SUCCESS;
54  }
55 
60  trkAnaColls.matches() ) );
61 
62  ATH_MSG_DEBUG( trkAnaColls.printMatchInfo() );
63 
64  return StatusCode::SUCCESS;
65 }
66 
67 
72  const std::vector< const xAOD::TruthParticle* >& vTest,
73  const std::vector< const xAOD::TrackParticle* >& vRef,
74  ITrackMatchingLookup& matches ) const
75 {
76  ATH_MSG_DEBUG( "Doing Truth->Track matching via truthParticleLink" );
77 
78  for( const xAOD::TruthParticle* truth_particle : vTest ) {
79 
80  const xAOD::TrackParticle* matched_track_particle = nullptr;
81  float prob = -99.;
82 
83  for( const xAOD::TrackParticle* track_particle : vRef ) {
84 
86  const xAOD::TruthParticle* truth_particle_tmp =
87  getLinkedTruth( *track_particle, m_truthProbCut.value() );
88 
92  if( ( not truth_particle_tmp ) or
93  ( truth_particle_tmp != truth_particle ) ) continue;
94 
95  float prob_tmp = getTruthMatchProb( *track_particle );
96 
98  if( prob_tmp > prob ) {
99  matched_track_particle = track_particle;
100  prob = prob_tmp;
104  }
105 
106  } // loop over vRef
107 
109  if( not matched_track_particle ) continue;
110 
111  ATH_MSG_DEBUG( "Found matched track particle with pT = " <<
112  pT( *matched_track_particle ) <<
113  " and prob = " << prob );
114 
116  float dist = 1 - prob;
117 
119  ATH_CHECK( matches.update( *truth_particle, *matched_track_particle, dist ) );
120 
121  } // loop over vTest
122 
123  return StatusCode::SUCCESS;
124 }
IDTPM::getTruthMatchProb
float getTruthMatchProb(const xAOD::TrackParticle &track)
getTruthMatchProb
Definition: OfflineObjectDecorHelper.cxx:51
IDTPM::TrackAnalysisCollections
Definition: TrackAnalysisCollections.h:41
IDTPM::TrackAnalysisCollections::updateChainRois
bool updateChainRois(const std::string &chainRoi, const std::string &roiStr)
update chainRois map
Definition: TrackAnalysisCollections.cxx:561
IDTPM::getLinkedTruth
const xAOD::TruthParticle * getLinkedTruth(const xAOD::TrackParticle &track, const float truthProbCut)
getLinkedTruth
Definition: OfflineObjectDecorHelper.cxx:58
TruthTrackMatchingTool.h
Tool to perform matching of truth particles and tracks via their truthParticleLink decorations....
asg
Definition: DataHandleTestTool.h:28
TrackAnalysisCollections.h
Class to hold for each event collections needed in the TrkAnalsis.
covarianceTool.prob
prob
Definition: covarianceTool.py:678
IDTPM::TrackAnalysisCollections::printMatchInfo
std::string printMatchInfo()
print matching information
Definition: TrackAnalysisCollections.cxx:543
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:41
IDTPM::TruthTrackMatchingTool::initialize
virtual StatusCode initialize() override
Initialize.
Definition: TruthTrackMatchingTool.cxx:28
IDTPM::TrackAnalysisCollections::matches
ITrackMatchingLookup & matches()
return matching information
Definition: TrackAnalysisCollections.h:158
IDTPM::pT
float pT(const U &p)
Accessor utility function for getting the value of pT.
Definition: TrackParametersHelper.h:30
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IDTPM::TruthTrackMatchingTool::TruthTrackMatchingTool
TruthTrackMatchingTool(const std::string &name)
Constructor.
Definition: TruthTrackMatchingTool.cxx:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
IDTPM::TrackAnalysisCollections::refTrackVec
const std::vector< const xAOD::TrackParticle * > & refTrackVec(Stage stage=FULL)
TEST = Track.
Definition: TrackAnalysisCollections.cxx:469
IDTPM::TruthTrackMatchingTool::match
virtual StatusCode match(TrackAnalysisCollections &trkAnaColls, const std::string &chainRoIName, const std::string &roiStr) const override
General matching method, via TrackAnalysisCollections.
Definition: TruthTrackMatchingTool.cxx:41
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
IDTPM::TrackAnalysisCollections::InRoI
@ InRoI
Definition: TrackAnalysisCollections.h:49
IDTPM::TrackAnalysisCollections::testTruthVec
const std::vector< const xAOD::TruthParticle * > & testTruthVec(Stage stage=FULL)
get TEST track vectors
Definition: TrackAnalysisCollections.cxx:426
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