ATLAS Offline Software
TrackVertexAssoTestAlg.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // TrackVertexAssoTestAlg.cxx
8 // Implementation file for class TrackVertexAssoTestAlg
9 // Author: Rachid Mazini, Bo Liu
11 
12 // TrackVertexAssociationTool includes
13 #include "TrackVertexAssoTestAlg.h"
14 
15 // STL includes
16 
17 // FrameWork includes
18 #include "Gaudi/Property.h"
19 
21 #include "xAODTracking/Vertex.h"
24 
25 using namespace std;
26 
28 // Public methods:
30 
31 // Constructors
34  ISvcLocator* pSvcLocator ) :
35  ::AthAlgorithm( name, pSvcLocator )
36 {}
37 
38 // Destructor
41 = default;
42 
43 // Athena Algorithm's Hooks
46 {
47  ATH_MSG_INFO ("Initializing " << name() << "...");
48 
50  ATH_CHECK( m_vertexContname.initialize() );
51  //retrieve tool from ToolHandle
52  CHECK(m_TVATool.retrieve());
53 
54  return StatusCode::SUCCESS;
55 }
56 
58 {
59  ATH_MSG_INFO ("Finalizing " << name() << "...");
60 
61  return StatusCode::SUCCESS;
62 }
63 
65 {
66  ATH_MSG_DEBUG ("Executing " << name() << "...");
67 
68  // retrieve containers
70 
72 
73  if (!trkCont.isValid() || !vxCont.isValid()) {
74  if (!trkCont.isValid()) ATH_MSG_ERROR("TrackParticle container not found");
75  if (!vxCont.isValid()) ATH_MSG_ERROR("Vertex container not found");
76  return StatusCode::FAILURE;
77  }
78 
79  // Test isCompitable
80  ATH_MSG_INFO("Testing TrackVertexAssociationTool::isCompatible...");
81  if(!trkCont->empty() && !vxCont->empty())
82  {
83  bool isMatched = m_TVATool->isCompatible(*(trkCont->at(0)), *(vxCont->at(0)));
84  ATH_MSG_INFO("Is the first track compatible with the first vertex (the PriVx)? "<< isMatched);
85  }
86 
87  // Test getMatchMap
88  ATH_MSG_INFO("Testing TrackVertexAssociationTool::getMatchMap...");
89  xAOD::TrackVertexAssociationMap trkvxassoMap = m_TVATool->getMatchMap(*trkCont, *vxCont);
90  ATH_MSG_INFO("Number of vertices for track-vertex association: " << trkvxassoMap.size());
91  for (const auto& assoc: trkvxassoMap) {
92  const xAOD::Vertex *vx = assoc.first;
93  ATH_MSG_INFO("vertex at x, y, z " <<
94  setprecision(4) << setfill(' ') <<
95  setw(10) << vx->x() << ", " << setw(10) << vx->y() << ", " << setw(10) << vx->z() <<
96  " has " << assoc.second.size() << " associated tracks");
97  }
98 
99  // Test getUniqueMatchVertex
100  ATH_MSG_INFO("Testing TrackVertexAssociationTool::getUniqueMatchVertex...");
101  std::vector<const xAOD::Vertex* > v_vx;
102  v_vx.clear();
103  for(const auto *vertex : *vxCont) {
104  v_vx.push_back(vertex);
105  }
106  if(!trkCont->empty())
107  {
108  const xAOD::Vertex *vx=m_TVATool->getUniqueMatchVertex(*(trkCont->at(0)), v_vx);
109  ATH_MSG_INFO("Unique match vertex for first track: " << vx);
110  }
111 
112  // Test getUniqueMatchVertexLink
113  ATH_MSG_INFO("Testing TrackVertexAssociationTool::getUniqueMatchVertexLink...");
114  if(trkCont->size() > 2)
115  {
116  ElementLink<xAOD::VertexContainer> match_vx = m_TVATool->getUniqueMatchVertexLink(*(trkCont->at(2)), *vxCont );
117 
118  if(match_vx.isValid())
119  {
120  ATH_MSG_INFO( "Uniquely matched vertex for third track - ");
121  ATH_MSG_INFO( "Vertex ElementLink address: " << match_vx );
122  ATH_MSG_INFO( "Vertex address: " << *match_vx );
123  ATH_MSG_INFO( "Vertex z pos: " << (*match_vx)->z());
124  }
125  }
126 
127  // Test getUniqueMatchMap
128  ATH_MSG_INFO("Testing TrackVertexAssociationTool::getUniqueMatchMap...");
129  xAOD::TrackVertexAssociationMap trkvxassoUniqueMap = m_TVATool->getUniqueMatchMap(*trkCont, *vxCont);
130  ATH_MSG_INFO("Number of vertices for track-vertex association: " << trkvxassoUniqueMap.size());
131  for (const auto& assoc: trkvxassoUniqueMap) {
132  const xAOD::Vertex *vx = assoc.first;
133  ATH_MSG_INFO("vertex at x, y, z " <<
134  setprecision(4) << setfill(' ') <<
135  setw(10) << vx->x() << ", " << setw(10) << vx->y() << ", " << setw(10) << vx->z() <<
136  " has " << assoc.second.size() << " uniquely associated tracks");
137  }
138 
139  // Example of accessing tracks matched to each vertex. Tracks are stored in a std::vector<xAOD::TrackParticle* >, for more details see TrackVertexAssociationMap.h
140 
141  // const xAOD::Vertex *pv=vxCont->at(0);
142  // xAOD::TrackVertexAssociationList trkvxassoList = trkvxassoMap[pv];
143  // ATH_MSG_INFO("Number of tracks associated to the PriVx: " << trkvxassoList.size());
144 
145 
146 
147  return StatusCode::SUCCESS;
148 }
xAOD::Vertex_v1::x
float x() const
Returns the x position.
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TrackVertexAssoTestAlg::execute
virtual StatusCode execute()
Definition: TrackVertexAssoTestAlg.cxx:64
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TrackVertexAssoTestAlg::m_trkContname
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trkContname
Containers.
Definition: TrackVertexAssoTestAlg.h:66
TrackVertexAssoTestAlg::finalize
virtual StatusCode finalize()
Definition: TrackVertexAssoTestAlg.cxx:57
InDetSecVtxTruthMatchUtils::isMatched
bool isMatched(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:48
TrackVertexAssoTestAlg::m_TVATool
ToolHandle< CP::ITrackVertexAssociationTool > m_TVATool
Definition: TrackVertexAssoTestAlg.h:61
xAOD::TrackVertexAssociationMap
std::map< const xAOD::Vertex *, xAOD::TrackVertexAssociationList > TrackVertexAssociationMap
Definition: TrackVertexAssociationMap.h:19
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
TrackVertexAssoTestAlg::TrackVertexAssoTestAlg
TrackVertexAssoTestAlg()
Default constructor:
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
xAOD::Vertex_v1::z
float z() const
Returns the z position.
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
Vertex.h
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrackVertexAssoTestAlg::~TrackVertexAssoTestAlg
virtual ~TrackVertexAssoTestAlg()
Destructor:
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TrackParticle.h
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
VertexContainer.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
TrackVertexAssoTestAlg.h
xAOD::Vertex_v1::y
float y() const
Returns the y position.
TrackVertexAssoTestAlg::m_vertexContname
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContname
Definition: TrackVertexAssoTestAlg.h:67
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
TrackVertexAssoTestAlg::initialize
virtual StatusCode initialize()
Definition: TrackVertexAssoTestAlg.cxx:45
TrackParticleContainer.h