ATLAS Offline Software
EFTrackMatchingTool.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 "EFTrackMatchingTool.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_INFO( trkAnaColls.printMatchInfo() );
66 
67 
68  return StatusCode::SUCCESS;
69 }
70 
75  const std::vector< const xAOD::TrackParticle* >& vTest,
76  const std::vector< const xAOD::TrackParticle* >& vRef,
77  ITrackMatchingLookup& matches ) const
78 {
79  ATH_MSG_DEBUG( "Doing EFtrack matching through truthParticleLink" );
80 
81  for( const xAOD::TrackParticle* track_particle_test : vTest ) {
82 
83  bool firstMatch = true;
84  const xAOD::TruthParticle* truth_particle_test = nullptr;
85 
87  truth_particle_test = getLinkedTruth(
88  *track_particle_test, m_truthProbCut.value() );
89 
91  if( not truth_particle_test ) {
92  ATH_MSG_WARNING( "Test track not linked to truth. Skipping." );
93  continue;
94  }
95 
96  float prob_test = getTruthMatchProb( *track_particle_test );
97 
98  ATH_MSG_DEBUG( "Test track with pT = " << pT( *track_particle_test ) <<
99  " is linked to truth with pT = " << pT( *truth_particle_test ) << " and prob = " << prob_test );
100 
102  const xAOD::TrackParticle* track_particle_ref = nullptr;
103  float prob_ref = -99.;
104 
105  for( const xAOD::TrackParticle* track_particle_tmp : vRef ) {
106 
108  const xAOD::TruthParticle* truth_particle_tmp =
109  getLinkedTruth( *track_particle_tmp, m_truthProbCut.value() );
110 
114  if( not truth_particle_tmp ) {
115  ATH_MSG_WARNING( "Reference track not linked to truth. Skipping." );
116  continue;
117  }
118 
119  float prob_tmp = getTruthMatchProb( *track_particle_tmp );
120 
121  ATH_MSG_DEBUG( "Reference track with pT = " << pT( *track_particle_tmp ) <<
122  " is linked to truth with pT = " << pT( *truth_particle_tmp ) << " and prob = " << prob_tmp );
123 
124  if( truth_particle_tmp != truth_particle_test ) continue;
125 
126  ATH_MSG_DEBUG( "Test track with pT = " << pT( *track_particle_test ) <<
127  " matches with reference track with pT = " << pT( *track_particle_tmp ) );
128 
131  if( prob_tmp > prob_ref ) {
132  if( not firstMatch ) ATH_MSG_DEBUG( "Found better match. Updating." );
133  firstMatch = false;
134  track_particle_ref = track_particle_tmp;
135  prob_ref = prob_tmp;
136  }
137 
138  } // loop over vRef
139 
140  if( not track_particle_ref ) {
141  ATH_MSG_DEBUG( "No match found for test track with pT = " << pT( *track_particle_test ) );
142  } else {
143  ATH_MSG_DEBUG( "Found best match: test track with pT = " << pT( *track_particle_test ) <<
144  " matches with reference track with pT = " << pT( *track_particle_ref ) );
145 
147  float dist = 1 - prob_test * prob_ref;
148  ATH_CHECK( matches.update( *track_particle_test, *track_particle_ref, dist ) );
149  }
150 
151  } // loop over vTest
152 
153 
154 
155  return StatusCode::SUCCESS;
156 }
IDTPM::getTruthMatchProb
float getTruthMatchProb(const xAOD::TrackParticle &track)
getTruthMatchProb
Definition: OfflineObjectDecorHelper.cxx:53
IDTPM::EFTrackMatchingTool::match
virtual StatusCode match(TrackAnalysisCollections &trkAnaColls, const std::string &chainRoIName, const std::string &roiStr) const override
General matching method, via TrackAnalysisCollections.
Definition: EFTrackMatchingTool.cxx:44
IDTPM::TrackAnalysisCollections
Definition: TrackAnalysisCollections.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
IDTPM::TrackAnalysisCollections::updateChainRois
bool updateChainRois(const std::string &chainRoi, const std::string &roiStr)
update chainRois map
Definition: TrackAnalysisCollections.cxx:619
IDTPM::getLinkedTruth
const xAOD::TruthParticle * getLinkedTruth(const xAOD::TrackParticle &track, const float truthProbCut)
getLinkedTruth
Definition: OfflineObjectDecorHelper.cxx:59
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 matching information
Definition: TrackAnalysisCollections.cxx:601
IDTPM::TrackAnalysisCollections::testTrackVec
const std::vector< const xAOD::TrackParticle * > & testTrackVec(Stage stage=FULL)
TEST = Track.
Definition: TrackAnalysisCollections.cxx:497
TrackParametersHelper.h
Utility methods to access track/truth particles parmeters in a consitent way in this package.
IDTPM::EFTrackMatchingTool::EFTrackMatchingTool
EFTrackMatchingTool(const std::string &name)
Constructor.
Definition: EFTrackMatchingTool.cxx:23
TrackMatchingLookup.h
Look-up table (templated) class to store (internally to IDTPM) all the matches between test and refer...
IDTPM::EFTrackMatchingTool::initialize
virtual StatusCode initialize() override
Initialize.
Definition: EFTrackMatchingTool.cxx:31
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
EFTrackMatchingTool.h
Tool to perform matching of EF tracks and Offline tracks matched to the same truth via truthParticleL...
IDTPM::TrackAnalysisCollections::matches
ITrackMatchingLookup & matches()
return matching information
Definition: TrackAnalysisCollections.h:170
IDTPM::pT
float pT(const U &p)
Accessor utility function for getting the value of pT.
Definition: TrackParametersHelper.h:31
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
IDTPM::TrackAnalysisCollections::refTrackVec
const std::vector< const xAOD::TrackParticle * > & refTrackVec(Stage stage=FULL)
TEST = Track.
Definition: TrackAnalysisCollections.cxx:527
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
IDTPM::TrackAnalysisCollections::InRoI
@ InRoI
Definition: TrackAnalysisCollections.h:52
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