ATLAS Offline Software
InnerDetector/InDetRecTools/InDetTrackSelectionTool/src/ToolTester.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Local includes:
6 #include "ToolTester.h"
8 
12 #include "PATCore/AcceptInfo.h"
13 #include "PATCore/AcceptData.h"
14 #ifndef XAOD_ANALYSIS
15 #include "TrkTrack/Track.h"
17 #endif
18 
19 InDet::ToolTester::ToolTester( const std::string& name, ISvcLocator* svcLoc )
20  : AthReentrantAlgorithm( name, svcLoc ),
21  m_sgKey("InDetTrackParticles"),
22  m_selTool( "InDet::InDetTrackSelectionTool/TrackSelectionTool", this )
23 {
24 
25  declareProperty( "SGKey", m_sgKey);
26 
27  declareProperty( "TrackSelectionTool", m_selTool );
28 }
29 
31 
32  // Greet the user:
33  ATH_MSG_INFO( "Initialising" );
34  ATH_MSG_DEBUG( "SGKey = " << m_sgKey );
35  ATH_MSG_DEBUG( "TrackSelectionTool = " << m_selTool );
36 
37  // Retrieve the tools:
38  ATH_CHECK( m_selTool.retrieve() );
39 
41 
42  ATH_CHECK( m_vertexKey.initialize() );
43  // Return gracefully:
44  return StatusCode::SUCCESS;
45 }
46 
47 StatusCode InDet::ToolTester::execute(const EventContext &ctx) const {
48 
49  // Retrieve the tracks:
51  if (!tracks.isValid()) {
52  ATH_MSG_ERROR("Invalid xAOD::TrackParticleContainer " << m_sgKey.key());
53  return StatusCode::FAILURE;
54  }
55  Int_t numberOfTracks = tracks->size();
56  ATH_MSG_INFO( "Number of tracks: " << numberOfTracks );
57 
58 
59  // retrieve vertex container to look for tracks
61  if (!vertices.isValid()) {
62  ATH_MSG_ERROR("Invalid xAOD::VertexContainer " << m_vertexKey.key() );
63  return StatusCode::FAILURE;
64  }
65 
66 
67  // Loop over them:
68  for ( const xAOD::TrackParticle* track : *tracks ) {
69  const xAOD::Vertex* foundVertex = nullptr;
70  for (const auto *const vertex : *vertices)
71  {
72  for (const auto& tpLink : vertex->trackParticleLinks())
73  {
74  if (*tpLink == track)
75  {
76  foundVertex = vertex;
77  break;
78  }
79  }
80  if (foundVertex) break;
81  }
82  // Select "good" tracks:
83  if( ! m_selTool->accept( *track , foundVertex ) ) continue;
84  asg::AcceptData acceptxAOD = m_selTool->accept( *track, foundVertex );
85  ATH_MSG_VERBOSE( " TrackParticle AcceptData to bool " << static_cast<bool>(acceptxAOD));
86 
87 #ifndef XAOD_ANALYSIS // if we are in full athena we have access to Trk::Tracks
88  if (track->track()) {
89  Trk::Track trkTrack = *(track->track());
90  asg::AcceptData acceptTrk = m_selTool->accept( trkTrack, nullptr );
91  ATH_MSG_VERBOSE( " Trk::Track AcceptData to bool " << static_cast<bool>(acceptTrk));
92  assert( static_cast<bool>(acceptxAOD) == static_cast<bool>(acceptTrk) );
93  }
94 #endif // XAOD_ANALYSIS
95 
96  // Print some info about the selected track:
97  ATH_MSG_VERBOSE( " Selected track: eta = " << track->eta()
98  << ", phi = " << track->phi()
99  << ", pt = " << track->pt() );
100 
101  }
102 
103 
104  // Return gracefully:
105  return StatusCode::SUCCESS;
106 }
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
InDet::ToolTester::m_vertexKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexKey
Definition: InnerDetector/InDetRecTools/InDetTrackSelectionTool/src/ToolTester.h:43
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
Track.h
InDet::ToolTester::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: InnerDetector/InDetRecTools/InDetTrackSelectionTool/src/ToolTester.cxx:30
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrackParticleAuxContainer.h
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrackSummary.h
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
IInDetTrackSelectionTool.h
AcceptData.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
InDet::ToolTester::execute
virtual StatusCode execute(const EventContext &ctx) const
Function executing the algorithm.
Definition: InnerDetector/InDetRecTools/InDetTrackSelectionTool/src/ToolTester.cxx:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ToolTester.h
TrackParticle.h
AcceptInfo.h
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
InDet::ToolTester::m_selTool
ToolHandle< IInDetTrackSelectionTool > m_selTool
Connection to the selection tool.
Definition: InnerDetector/InDetRecTools/InDetTrackSelectionTool/src/ToolTester.h:47
InDet::ToolTester::m_sgKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_sgKey
StoreGate key for the track container to investigate.
Definition: InnerDetector/InDetRecTools/InDetTrackSelectionTool/src/ToolTester.h:41
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
asg::AcceptData
Definition: AcceptData.h:30
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDet::ToolTester::ToolTester
ToolTester(const std::string &name, ISvcLocator *svcLoc)
Regular Algorithm constructor.
Definition: InnerDetector/InDetRecTools/InDetTrackSelectionTool/src/ToolTester.cxx:19
TrackParticleContainer.h