ATLAS Offline Software
Loading...
Searching...
No Matches
JetTrackVtxAssoAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
9
10
12 ATH_MSG_DEBUG("Initializing tool " << name() << "...");
13 ATH_MSG_DEBUG("initializing version with data handles");
14
15 ATH_CHECK(m_trackContainer_key.initialize());
16 ATH_CHECK(m_vertexContainer_key.initialize());
17 ATH_CHECK(m_tva_key.initialize());
18
19 if(! m_tvaTool.empty() ) {
20 ATH_MSG_INFO("Intialized using ITrackVertexAssociationTool");
21 return m_tvaTool.retrieve();
22 }
23
24 ATH_MSG_INFO("Intialized using custom track-vertex association");
25 return StatusCode::SUCCESS;
26}
27
28
29StatusCode JetTrackVtxAssoAlg::execute(const EventContext& ctx) const {
30
31 // Get input track collection
32
33 auto handle_tracks = SG::makeHandle(m_trackContainer_key,ctx);
34
35 if(!handle_tracks.isValid()){
36 ATH_MSG_ERROR("Error retrieving TrackParticleContainer from evtStore: "
37 << m_trackContainer_key.key());
38 return StatusCode::FAILURE;
39 }
40
41 const auto *trackContainer = handle_tracks.cptr();
42
43
44 // If this is a view container, then we assume that it contains elements from only one owning container
45 if ( trackContainer->ownPolicy() != SG::OWN_ELEMENTS ) {
46 bool oneOwningContainer(true);
47 for(const auto *const track : *trackContainer) {
48 if(track->container() != trackContainer->front()->container()) {
49 oneOwningContainer=false;
50 break;
51 }
52 }
53 if(!oneOwningContainer) {
54 ATH_MSG_ERROR("Track view container holds track from multiple owning containers.");
55 ATH_MSG_ERROR("Problem is this container: " << m_trackContainer_key.key());
56 return StatusCode::FAILURE;
57 }
58 }
59
60 // Get input vertex collection
61 auto handle_vert = SG::makeHandle(m_vertexContainer_key,ctx);
62
63 if(!handle_vert.isValid()){
64 ATH_MSG_ERROR("Error retrieving VertexContainer from evtStore: "
65 << m_vertexContainer_key.key());
66 return StatusCode::FAILURE;
67 }
68
69 const auto *vertexContainer = handle_vert.cptr();
70
71 auto useCustom = m_tvaTool.empty();
72 auto tva = makeTrackVertexAssociation(trackContainer,
73 vertexContainer,
74 useCustom);
75 // Check the result.
76 if (!tva){
77 ATH_MSG_ERROR("Could not build the TrackVertexAssociation");
78 return StatusCode::FAILURE;
79 }
80
81 // Store it
82
83 auto handle_tva = SG::makeHandle(m_tva_key,ctx);
84 if(!handle_tva.record(std::move(tva))){
85 ATH_MSG_ERROR("Unable to write new TrackVertexAssociation to evtStore: "
86 << m_tva_key.key());
87 return StatusCode::FAILURE;
88 }
89
90 // Success
91 ATH_MSG_DEBUG("Wrote new TrackVertexAssociation to evtStore: "
92 << m_tva_key.key());
93 return StatusCode::SUCCESS;
94
95}
96
97
98
99std::unique_ptr<jet::TrackVertexAssociation>
101{
102
103 ATH_MSG_DEBUG("Building track-vertex association USING InDet tool. trk size="<< trackContainer->size()
104 << " vtx size="<< vertexContainer->size());
105
106 auto tva = std::make_unique<jet::TrackVertexAssociation>(trackContainer);
107
108 std::vector<const xAOD::Vertex*> vecVert;
109 vecVert.assign(vertexContainer->begin(), vertexContainer->end());
110
111 for( const xAOD::TrackParticle* track : *trackContainer) {
112
113 const xAOD::Vertex * v = m_tvaTool->getUniqueMatchVertex(*track, vecVert) ;
114 tva->associate( track, v );
115 }
116 return tva;
117}
118
120// jet::TrackVertexAssociation*
121std::unique_ptr<jet::TrackVertexAssociation>
123{
124 ATH_MSG_DEBUG("Building track-vertex association trk size="<< trackContainer->size()
125 << " vtx size="<< vertexContainer->size());
126
127 auto tva = std::make_unique<jet::TrackVertexAssociation>(trackContainer);
128
129 for (size_t iTrack = 0; iTrack < trackContainer->size(); ++iTrack)
130 {
131 const xAOD::TrackParticle* track = trackContainer->at(iTrack);
132
133 // Apply track transverse distance cut
134 const float transverseDistance = track->d0();//perigeeParameters().parameters()[Trk::d0];
135 if (transverseDistance > m_transDistMax) continue;
136
137
138 // Get track longitudinal distance offset
139 const float longitudinalDistance = track->z0()+track->vz();
140
141 double sinTheta = std::sin(track->theta());
142
143 // For each track, find the vertex with highest sum pt^2 within z0 cut
144 size_t matchedIndex = 0;
145 bool foundMatch = false;
146 for (size_t iVertex = 0; iVertex < vertexContainer->size(); ++iVertex)
147 {
148 const xAOD::Vertex* vertex = vertexContainer->at(iVertex);
149
150 double deltaz = longitudinalDistance - vertex->z();
151
152 // Check longitudinal distance between track and vertex
153 if ( std::abs(deltaz) > m_longDistMax)
154 continue;
155
156 // Check z0*sinThetha between track and vertex
157 if (std::abs(deltaz*sinTheta) > m_maxZ0SinTheta)
158 continue;
159
160 // If it passed the cuts, then this is the vertex we want
161 // This does make the assumption that the container is sorted in sum pT^2 order
162 foundMatch = true;
163 matchedIndex = iVertex;
164 break;
165 }
166
167 // If we matched a vertex, then associate that vertex to the track
168 if (foundMatch)
169 tva->associate(trackContainer->at(iTrack),vertexContainer->at(matchedIndex));
170 }
171
172
173 // Return the TVA object
174 return tva;
175}
176
179std::unique_ptr<jet::TrackVertexAssociation>
181 PVC vertexContainer,
182 bool useCustom) const {
183 if (useCustom) {
184 return buildTrackVertexAssociation_custom(trackContainer,
185 vertexContainer);
186 } else {
187 return buildTrackVertexAssociation_withTool(trackContainer,
188 vertexContainer);
189 }
190}
#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)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
const xAOD::TrackParticleContainer * PTPC
const xAOD::VertexContainer * PVC
const T * at(size_type n) const
Access an element, as an rvalue.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainer_key
StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackContainer_key
StatusCode initialize() override
Athena algorithm's Hooks.
std::unique_ptr< jet::TrackVertexAssociation > buildTrackVertexAssociation_custom(const xAOD::TrackParticleContainer *, const xAOD::VertexContainer *) const
std::unique_ptr< jet::TrackVertexAssociation > buildTrackVertexAssociation_withTool(const xAOD::TrackParticleContainer *, const xAOD::VertexContainer *) const
Gaudi::Property< float > m_longDistMax
Gaudi::Property< float > m_transDistMax
ToolHandle< CP::ITrackVertexAssociationTool > m_tvaTool
std::unique_ptr< jet::TrackVertexAssociation > makeTrackVertexAssociation(const xAOD::TrackParticleContainer *, const xAOD::VertexContainer *, bool useCustom) const
SG::WriteHandleKey< jet::TrackVertexAssociation > m_tva_key
Gaudi::Property< float > m_maxZ0SinTheta
@ OWN_ELEMENTS
this data object owns its elements
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
TrackParticle_v1 TrackParticle
Reference the current persistent version:
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".