ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetRecTools
TrackVertexAssociationTool
src
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
13
#include "
TrackVertexAssoTestAlg.h
"
14
15
// STL includes
16
17
// FrameWork includes
18
#include "Gaudi/Property.h"
19
20
#include "
xAODTracking/TrackParticle.h
"
21
#include "
xAODTracking/Vertex.h
"
22
#include "
xAODTracking/TrackParticleContainer.h
"
23
#include "
xAODTracking/VertexContainer.h
"
24
25
using namespace
std
;
26
28
// Public methods:
30
31
// Constructors
33
TrackVertexAssoTestAlg::TrackVertexAssoTestAlg
(
const
std::string& name,
34
ISvcLocator* pSvcLocator ) :
35
::
AthAlgorithm
( name, pSvcLocator )
36
{}
37
38
// Destructor
40
TrackVertexAssoTestAlg::~TrackVertexAssoTestAlg
()
41
=
default
;
42
43
// Athena Algorithm's Hooks
45
StatusCode
TrackVertexAssoTestAlg::initialize
()
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
57
StatusCode
TrackVertexAssoTestAlg::finalize
()
58
{
59
ATH_MSG_INFO
(
"Finalizing "
<< name() <<
"..."
);
60
61
return
StatusCode::SUCCESS;
62
}
63
64
StatusCode
TrackVertexAssoTestAlg::execute
(
const
EventContext& ctx)
65
{
66
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"..."
);
67
68
// retrieve containers
69
SG::ReadHandle<xAOD::TrackParticleContainer>
trkCont(
m_trkContname
, ctx);
70
71
SG::ReadHandle<xAOD::VertexContainer>
vxCont(
m_vertexContname
, ctx);
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
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:422
TrackParticleContainer.h
TrackParticle.h
Vertex.h
TrackVertexAssoTestAlg.h
VertexContainer.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
ElementLink
ElementLink implementation for ROOT usage.
Definition
A/AthLinks/ElementLink.h:40
ElementLink::isValid
bool isValid() const
Check if the element can be found.
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrackVertexAssoTestAlg::m_vertexContname
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContname
Definition
TrackVertexAssoTestAlg.h:67
TrackVertexAssoTestAlg::initialize
virtual StatusCode initialize()
Definition
TrackVertexAssoTestAlg.cxx:45
TrackVertexAssoTestAlg::TrackVertexAssoTestAlg
TrackVertexAssoTestAlg()
Default constructor:
TrackVertexAssoTestAlg::m_TVATool
ToolHandle< CP::ITrackVertexAssociationTool > m_TVATool
Definition
TrackVertexAssoTestAlg.h:61
TrackVertexAssoTestAlg::finalize
virtual StatusCode finalize()
Definition
TrackVertexAssoTestAlg.cxx:57
TrackVertexAssoTestAlg::~TrackVertexAssoTestAlg
virtual ~TrackVertexAssoTestAlg()
Destructor:
TrackVertexAssoTestAlg::execute
virtual StatusCode execute(const EventContext &ctx)
Execute method.
Definition
TrackVertexAssoTestAlg.cxx:64
TrackVertexAssoTestAlg::m_trkContname
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trkContname
Containers.
Definition
TrackVertexAssoTestAlg.h:66
xAOD::Vertex_v1::z
float z() const
Returns the z position.
xAOD::Vertex_v1::y
float y() const
Returns the y position.
xAOD::Vertex_v1::x
float x() const
Returns the x position.
std
STL namespace.
xAOD::TrackVertexAssociationMap
std::map< const xAOD::Vertex *, xAOD::TrackVertexAssociationList > TrackVertexAssociationMap
Definition
TrackVertexAssociationMap.h:19
xAOD::Vertex
Vertex_v1 Vertex
Define the latest version of the vertex class.
Definition
Event/xAOD/xAODTracking/xAODTracking/Vertex.h:16
Generated on
for ATLAS Offline Software by
1.17.0