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  // Property declaration
39  //
40  //declareProperty( "Property", m_nProperty );
41  declareProperty( "TVATool", m_TVATool );
42 }
43 
44 // Destructor
47 = default;
48 
49 // Athena Algorithm's Hooks
52 {
53  ATH_MSG_INFO ("Initializing " << name() << "...");
54 
56  ATH_CHECK( m_vertexContname.initialize() );
57  //retrieve tool from ToolHandle
58  CHECK(m_TVATool.retrieve());
59 
60  return StatusCode::SUCCESS;
61 }
62 
64 {
65  ATH_MSG_INFO ("Finalizing " << name() << "...");
66 
67  return StatusCode::SUCCESS;
68 }
69 
71 {
72  ATH_MSG_DEBUG ("Executing " << name() << "...");
73 
74  // retrieve containers
76 
78 
79  if (!trkCont.isValid() || !vxCont.isValid()) {
80  if (!trkCont.isValid()) ATH_MSG_ERROR("TrackParticle container not found");
81  if (!vxCont.isValid()) ATH_MSG_ERROR("Vertex container not found");
82  return StatusCode::FAILURE;
83  }
84 
85  // Test isCompitable
86  ATH_MSG_INFO("Testing TrackVertexAssociationTool::isCompatible...");
87  if(!trkCont->empty() && !vxCont->empty())
88  {
89  bool isMatched = m_TVATool->isCompatible(*(trkCont->at(0)), *(vxCont->at(0)));
90  ATH_MSG_INFO("Is the first track compatible with the first vertex (the PriVx)? "<< isMatched);
91  }
92 
93  // Test getMatchMap
94  ATH_MSG_INFO("Testing TrackVertexAssociationTool::getMatchMap...");
95  xAOD::TrackVertexAssociationMap trkvxassoMap = m_TVATool->getMatchMap(*trkCont, *vxCont);
96  ATH_MSG_INFO("Number of vertices for track-vertex association: " << trkvxassoMap.size());
97  for (const auto& assoc: trkvxassoMap) {
98  const xAOD::Vertex *vx = assoc.first;
99  ATH_MSG_INFO("vertex at x, y, z " <<
100  setprecision(4) << setfill(' ') <<
101  setw(10) << vx->x() << ", " << setw(10) << vx->y() << ", " << setw(10) << vx->z() <<
102  " has " << assoc.second.size() << " associated tracks");
103  }
104 
105  // Test getUniqueMatchVertex
106  ATH_MSG_INFO("Testing TrackVertexAssociationTool::getUniqueMatchVertex...");
107  std::vector<const xAOD::Vertex* > v_vx;
108  v_vx.clear();
109  for(const auto *vertex : *vxCont) {
110  v_vx.push_back(vertex);
111  }
112  if(!trkCont->empty())
113  {
114  const xAOD::Vertex *vx=m_TVATool->getUniqueMatchVertex(*(trkCont->at(0)), v_vx);
115  ATH_MSG_INFO("Unique match vertex for first track: " << vx);
116  }
117 
118  // Test getUniqueMatchVertexLink
119  ATH_MSG_INFO("Testing TrackVertexAssociationTool::getUniqueMatchVertexLink...");
120  if(trkCont->size() > 2)
121  {
122  ElementLink<xAOD::VertexContainer> match_vx = m_TVATool->getUniqueMatchVertexLink(*(trkCont->at(2)), *vxCont );
123 
124  if(match_vx.isValid())
125  {
126  ATH_MSG_INFO( "Uniquely matched vertex for third track - ");
127  ATH_MSG_INFO( "Vertex ElementLink address: " << match_vx );
128  ATH_MSG_INFO( "Vertex address: " << *match_vx );
129  ATH_MSG_INFO( "Vertex z pos: " << (*match_vx)->z());
130  }
131  }
132 
133  // Test getUniqueMatchMap
134  ATH_MSG_INFO("Testing TrackVertexAssociationTool::getUniqueMatchMap...");
135  xAOD::TrackVertexAssociationMap trkvxassoUniqueMap = m_TVATool->getUniqueMatchMap(*trkCont, *vxCont);
136  ATH_MSG_INFO("Number of vertices for track-vertex association: " << trkvxassoUniqueMap.size());
137  for (const auto& assoc: trkvxassoUniqueMap) {
138  const xAOD::Vertex *vx = assoc.first;
139  ATH_MSG_INFO("vertex at x, y, z " <<
140  setprecision(4) << setfill(' ') <<
141  setw(10) << vx->x() << ", " << setw(10) << vx->y() << ", " << setw(10) << vx->z() <<
142  " has " << assoc.second.size() << " uniquely associated tracks");
143  }
144 
145  // Example of accessing tracks matched to each vertex. Tracks are stored in a std::vector<xAOD::TrackParticle* >, for more details see TrackVertexAssociationMap.h
146 
147  // const xAOD::Vertex *pv=vxCont->at(0);
148  // xAOD::TrackVertexAssociationList trkvxassoList = trkvxassoMap[pv];
149  // ATH_MSG_INFO("Number of tracks associated to the PriVx: " << trkvxassoList.size());
150 
151 
152 
153  return StatusCode::SUCCESS;
154 }
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:70
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TrackVertexAssoTestAlg::m_trkContname
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trkContname
Containers.
Definition: TrackVertexAssoTestAlg.h:66
TrackVertexAssoTestAlg::finalize
virtual StatusCode finalize()
Definition: TrackVertexAssoTestAlg.cxx:63
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:195
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:51
TrackParticleContainer.h