ATLAS Offline Software
Loading...
Searching...
No Matches
TrackVertexAssoTestAlg.cxx
Go to the documentation of this file.
1
2
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
14
15// STL includes
16
17// FrameWork includes
18#include "Gaudi/Property.h"
19
21#include "xAODTracking/Vertex.h"
24
25using 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
49 ATH_CHECK( m_trkContname.initialize() );
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContname
virtual StatusCode initialize()
TrackVertexAssoTestAlg()
Default constructor:
ToolHandle< CP::ITrackVertexAssociationTool > m_TVATool
virtual ~TrackVertexAssoTestAlg()
Destructor:
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trkContname
Containers.
float z() const
Returns the z position.
float y() const
Returns the y position.
float x() const
Returns the x position.
STL namespace.
std::map< const xAOD::Vertex *, xAOD::TrackVertexAssociationList > TrackVertexAssociationMap
Vertex_v1 Vertex
Define the latest version of the vertex class.