ATLAS Offline Software
TrackObjectSelectionTool.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 "GaudiKernel/ISvcLocator.h"
12 #include "GaudiKernel/Service.h"
13 
18 #include "TrackParametersHelper.h"
19 
20 
25  const std::string& name ) :
26  asg::AsgTool( name ) { }
27 
28 
33 
35 
36  ATH_MSG_INFO( "Initializing " << name() << "..." );
37 
38  return StatusCode::SUCCESS;
39 }
40 
41 
46  TrackAnalysisCollections& trkAnaColls ) {
47 
48  ATH_MSG_DEBUG( "Selecting offline tracks matched to an offline " << m_objectType.value() );
49 
50  ISvcLocator* svcLoc = Gaudi::svcLocator();
51  SmartIF<ITrackAnalysisDefinitionSvc> trkAnaDefSvc( svcLoc->service( "TrkAnaDefSvc" + trkAnaColls.anaTag() ) );
52  ATH_CHECK( trkAnaDefSvc.isValid() );
53 
54  if( not trkAnaDefSvc->useOffline() ) {
55  ATH_MSG_DEBUG( "Tool not enabled if offline tracks are not used." );
56  return StatusCode::SUCCESS;
57  }
58 
60  std::vector< const xAOD::TrackParticle* > newVec;
61  for( const xAOD::TrackParticle* thisTrack :
63  if( accept( *thisTrack,
64  trkAnaColls.truthPartVec( TrackAnalysisCollections::FS ) ) ) newVec.push_back( thisTrack );
65  }
66 
68  ATH_CHECK( trkAnaColls.fillOfflTrackVec( newVec,
70 
72  if( trkAnaDefSvc->useEFTrigger() and
73  m_objectType.value().find("Truth") != std::string::npos ) {
74 
75  ATH_MSG_DEBUG( "Now doing EFTrack-truth selection" );
76 
78  newVec.clear();
79  for( const xAOD::TrackParticle* thisTrack :
81  if( accept( *thisTrack,
82  trkAnaColls.truthPartVec( TrackAnalysisCollections::FS ) ) ) newVec.push_back( thisTrack );
83  }
84 
86  ATH_CHECK( trkAnaColls.fillTrigTrackVec( newVec,
88  } // end if
89 
90  return StatusCode::SUCCESS;
91 }
92 
93 
98  const xAOD::TrackParticle& offTrack,
99  const std::vector< const xAOD::TruthParticle* >& truthVec ) const {
100 
102  if( m_objectType.value().find("Electron") != std::string::npos ) {
103 
104  const xAOD::Electron* ele = getLinkedElectron(
105  offTrack, m_objectQuality.value() );
106 
107  if( not ele ) return false;
108 
109  ATH_MSG_DEBUG( "Offline Track with pt = " << pT( offTrack ) <<
110  " matches with " << m_objectQuality.value() <<
111  " Electron with transverse energy = " << eT( *ele ) );
112 
113  return true;
114  }
115 
117  if( m_objectType.value().find("Muon") != std::string::npos ) {
118  const xAOD::Muon* mu = getLinkedMuon(
119  offTrack, m_objectQuality.value() );
120 
121  if( not mu ) return false;
122 
123  ATH_MSG_DEBUG( "Offline Track with pt = " << pT( offTrack ) <<
124  " matches with " << m_objectQuality.value() <<
125  " Muon with transverse energy = " << eT( *mu ) );
126 
127  return true;
128  }
129 
131  if( m_objectType.value().find("Tau") != std::string::npos ) {
132 
133  const xAOD::TauJet* tau = getLinkedTau(
134  offTrack, m_tauNprongs.value(),
135  m_tauType.value(), m_objectQuality.value() );
136 
137  if( not tau ) return false;
138 
139  ATH_MSG_DEBUG( "Offline Track with pt = " << pT( offTrack ) <<
140  " matches with " << m_objectQuality.value() <<
141  " hadronic " << m_tauNprongs.value() << "prong " <<
142  m_tauType.value() << " Tau with transverse energy = " <<
143  eT( *tau ) );
144 
145  return true;
146  }
147 
149  if( m_objectType.value().find("Truth") != std::string::npos ) {
150 
151  const xAOD::TruthParticle* truth = getLinkedTruth(
152  offTrack, m_truthProbCut.value() );
153 
154  if( not truth ) return false;
155 
156  if( truthVec.empty() ) {
157  ATH_MSG_DEBUG( "Truth vector is empty" );
158  return false;
159  }
160 
161  ATH_MSG_DEBUG( "Offline Track with pt = " << pT( offTrack ) <<
162  " matches with truth particle with pt = " << pT( *truth ) );
163 
165  if( std::find( truthVec.begin(), truthVec.end(),
166  truth ) == truthVec.end() ) return false;
167 
168  return true;
169  }
170 
171  ATH_MSG_WARNING( "Type " << m_objectType.value() <<
172  " is not supported for track-object selection" );
173  return false;
174 }
IDTPM::TrackObjectSelectionTool::initialize
virtual StatusCode initialize() override
Initialize.
Definition: TrackObjectSelectionTool.cxx:32
IDTPM::TrackAnalysisCollections::fillTrigTrackVec
StatusCode fillTrigTrackVec(const std::vector< const xAOD::TrackParticle * > &vec, Stage stage=FULL)
Trigger tracks.
Definition: TrackAnalysisCollections.cxx:353
IDTPM::TrackObjectSelectionTool::selectTracks
virtual StatusCode selectTracks(TrackAnalysisCollections &trkAnaColls) override
Main Track selection method.
Definition: TrackObjectSelectionTool.cxx:45
IDTPM::TrackObjectSelectionTool::TrackObjectSelectionTool
TrackObjectSelectionTool(const std::string &name)
Constructor.
Definition: TrackObjectSelectionTool.cxx:24
IDTPM::TrackAnalysisCollections
Definition: TrackAnalysisCollections.h:46
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
IDTPM::getLinkedTau
const xAOD::TauJet * getLinkedTau(const xAOD::TrackParticle &track, const int requiredNtracks, const std::string &type, const std::string &quality)
getLinkedTau
Definition: OfflineObjectDecorHelper.cxx:34
IDTPM::getLinkedTruth
const xAOD::TruthParticle * getLinkedTruth(const xAOD::TrackParticle &track, const float truthProbCut)
getLinkedTruth
Definition: OfflineObjectDecorHelper.cxx:61
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
asg
Definition: DataHandleTestTool.h:28
IDTPM::getLinkedElectron
const xAOD::Electron * getLinkedElectron(const xAOD::TrackParticle &track, const std::string &quality)
getLinkedElectron
Definition: OfflineObjectDecorHelper.cxx:18
IDTPM::TrackAnalysisCollections::trigTrackVec
const std::vector< const xAOD::TrackParticle * > & trigTrackVec(Stage stage=FULL)
Definition: TrackAnalysisCollections.h:217
TrackAnalysisCollections.h
Class to hold for each event collections needed in the TrkAnalsis.
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
IDTPM::TrackAnalysisCollections::fillOfflTrackVec
StatusCode fillOfflTrackVec(const std::vector< const xAOD::TrackParticle * > &vec, Stage stage=FULL)
Offline tracks.
Definition: TrackAnalysisCollections.cxx:336
TrackParametersHelper.h
Utility methods to access track/truth particles parmeters in a consitent way in this package.
IDTPM::eT
float eT(const U &p)
Accessor utility function for getting the value of Tranverse energy.
Definition: TrackParametersHelper.h:122
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
IDTPM::TrackAnalysisCollections::FS
@ FS
Definition: TrackAnalysisCollections.h:54
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
IDTPM::getLinkedMuon
const xAOD::Muon * getLinkedMuon(const xAOD::TrackParticle &track, const std::string &quality)
getLinkedMuon
Definition: OfflineObjectDecorHelper.cxx:26
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
IDTPM::TrackAnalysisCollections::offlTrackVec
const std::vector< const xAOD::TrackParticle * > & offlTrackVec(Stage stage=FULL)
Definition: TrackAnalysisCollections.h:215
TrackObjectSelectionTool.h
Tool to select offline ID tracks which asociated with fully-reconstructed object with specific qualit...
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
xAOD::Electron_v1
Definition: Electron_v1.h:34
IDTPM::TrackObjectSelectionTool::accept
bool accept(const xAOD::TrackParticle &offTrack, const std::vector< const xAOD::TruthParticle * > &truthVec) const
Definition: TrackObjectSelectionTool.cxx:97
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
IDTPM::TrackAnalysisCollections::truthPartVec
const std::vector< const xAOD::TruthParticle * > & truthPartVec(Stage stage=FULL)
get truth/offline/trigger track vector (TEST or REFERENCE)
Definition: TrackAnalysisCollections.h:213
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
OfflineObjectDecorHelper.h
Utility methods to access offline object decorations.
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
IDTPM::TrackAnalysisCollections::anaTag
const std::string & anaTag()
— Getter methods —
Definition: TrackAnalysisCollections.h:181
asg::AsgTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: AsgTool.h:133