ATLAS Offline Software
Loading...
Searching...
No Matches
Reconstruction/Jet/JetRecTools/Root/TrackVertexAssociationTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include <cmath>
9
11 : AsgTool(t)
12 , m_tvaTool("",this) // default as empty
13 , m_transDistMax(10e6)
14 , m_longDistMax(10e6)
15 , m_maxZ0SinTheta(10e6)
16{
17 declareProperty("TrackVertexAssoTool", m_tvaTool); // Tool handle
18
19 declareProperty("MaxTransverseDistance",m_transDistMax);
20 declareProperty("MaxLongitudinalDistance",m_longDistMax);
21 declareProperty("MaxZ0SinTheta", m_maxZ0SinTheta);
22
23 declareProperty("TrackParticleContainer",m_trackContainer_key);
24 declareProperty("VertexContainer",m_vertexContainer_key);
25 declareProperty("TrackVertexAssociation",m_tva_key);
26
27}
28
30 ATH_MSG_INFO("Initializing tool " << name() << "...");
31 ATH_MSG_DEBUG("initializing version with data handles");
32
33 ATH_CHECK(m_trackContainer_key.initialize());
34 ATH_CHECK(m_vertexContainer_key.initialize());
35 ATH_CHECK(m_tva_key.initialize());
36
37 if(! m_tvaTool.empty() ) {
38 ATH_MSG_INFO("Intialized using ITrackVertexAssociationTool");
39 return m_tvaTool.retrieve();
40 }
41
42 ATH_MSG_INFO("Intialized using custom track-vertex association");
43 return StatusCode::SUCCESS;
44}
45
47 // Get input track collection
48
49 auto handle_tracks = SG::makeHandle(m_trackContainer_key);
50
51 if(!handle_tracks.isValid()){
52 ATH_MSG_ERROR("Error retrieving TrackParticleContainer from evtStore: "
53 << m_trackContainer_key.key());
54 return 1;
55 }
56
57 const auto *trackContainer = handle_tracks.cptr();
58
59
60 // If this is a view container, then we assume that it contains elements from only one owning container
61 if ( trackContainer->ownPolicy() != SG::OWN_ELEMENTS ) {
62 bool oneOwningContainer(true);
63 for(const xAOD::TrackParticle* track : *trackContainer) {
64 if(track->container() != trackContainer->front()->container()) {
65 oneOwningContainer=false;
66 break;
67 }
68 }
69 if(!oneOwningContainer) {
70 ATH_MSG_ERROR("Track view container holds track from multiple owning containers.");
71 ATH_MSG_ERROR("Problem is this container: " << m_trackContainer_key.key());
72 return 11;
73 }
74 }
75
76 // Get input vertex collection
77 auto handle_vert = SG::makeHandle(m_vertexContainer_key);
78
79 if(!handle_vert.isValid()){
80 ATH_MSG_ERROR("Error retrieving VertexContainer from evtStore: "
81 << m_vertexContainer_key.key());
82 return 2;
83 }
84
85 const auto *vertexContainer = handle_vert.cptr();
86
87 auto useCustom = m_tvaTool.empty();
88 auto tva = makeTrackVertexAssociation(trackContainer,
89 vertexContainer,
90 useCustom);
91 // Check the result.
92 // if ( tva == nullptr ) {
93 if (!tva){
94 ATH_MSG_ERROR("Could not build the TrackVertexAssociation");
95 return 3;
96 }
97
98 // Store it
99
100 auto handle_tva = SG::makeHandle(m_tva_key);
101 if(!handle_tva.record(std::move(tva))){
102 ATH_MSG_ERROR("Unable to write new TrackVertexAssociation to evtStore: "
103 << m_tva_key.key());
104 return 4;
105 }
106
107 // Success
108 ATH_MSG_DEBUG("Wrote new TrackVertexAssociation to evtStore: "
109 << m_tva_key.key());
110 return 0;
111}
112
113
114
115
117// jet::TrackVertexAssociation*
118std::unique_ptr<jet::TrackVertexAssociation>
120{
121
122 ATH_MSG_DEBUG("Building track-vertex association USING InDet tool. trk size="<< trackContainer->size()
123 << " vtx size="<< vertexContainer->size());
124
125 auto tva = std::make_unique<jet::TrackVertexAssociation>(trackContainer);
126
127 std::vector<const xAOD::Vertex*> vecVert;
128 vecVert.assign(vertexContainer->begin(), vertexContainer->end());
129
130 for( const xAOD::TrackParticle* track : *trackContainer) {
131
132 const xAOD::Vertex * v = m_tvaTool->getUniqueMatchVertex(*track, vecVert) ;
133 tva->associate( track, v );
134 }
135 return tva;
136}
137
139// jet::TrackVertexAssociation*
140std::unique_ptr<jet::TrackVertexAssociation>
142{
143 ATH_MSG_DEBUG("Building track-vertex association trk size="<< trackContainer->size()
144 << " vtx size="<< vertexContainer->size());
145
146 auto tva = std::make_unique<jet::TrackVertexAssociation>(trackContainer);
147
148 for (size_t iTrack = 0; iTrack < trackContainer->size(); ++iTrack)
149 {
150 const xAOD::TrackParticle* track = trackContainer->at(iTrack);
151
152 // Apply track transverse distance cut
153 const float transverseDistance = track->d0();//perigeeParameters().parameters()[Trk::d0];
154 if (transverseDistance > m_transDistMax) continue;
155
156
157 // Get track longitudinal distance offset
158 const float longitudinalDistance = track->z0()+track->vz();
159
160 double sinTheta = std::sin(track->theta());
161
162 // For each track, find the vertex with highest sum pt^2 within z0 cut
163 size_t matchedIndex = 0;
164 bool foundMatch = false;
165 for (size_t iVertex = 0; iVertex < vertexContainer->size(); ++iVertex)
166 {
167 const xAOD::Vertex* vertex = vertexContainer->at(iVertex);
168
169 double deltaz = longitudinalDistance - vertex->z();
170
171 // Check longitudinal distance between track and vertex
172 if ( fabs(deltaz) > m_longDistMax)
173 continue;
174
175 // Check z0*sinThetha between track and vertex
176 if (fabs(deltaz*sinTheta) > m_maxZ0SinTheta)
177 continue;
178
179 // If it passed the cuts, then this is the vertex we want
180 // This does make the assumption that the container is sorted in sum pT^2 order
181 foundMatch = true;
182 matchedIndex = iVertex;
183 break;
184 }
185
186 // If we matched a vertex, then associate that vertex to the track
187 if (foundMatch)
188 tva->associate(trackContainer->at(iTrack),vertexContainer->at(matchedIndex));
189 }
190
191
192 // Return the TVA object
193 return tva;
194}
195
198std::unique_ptr<jet::TrackVertexAssociation>
200 PVC vertexContainer,
201 bool useCustom) const {
202 if (useCustom) {
203 return buildTrackVertexAssociation_custom(trackContainer,
204 vertexContainer);
205 } else {
206 return buildTrackVertexAssociation_withTool(trackContainer,
207 vertexContainer);
208 }
209}
#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
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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.
std::unique_ptr< jet::TrackVertexAssociation > makeTrackVertexAssociation(const xAOD::TrackParticleContainer *, const xAOD::VertexContainer *, bool useCustom) const
StatusCode initialize()
Dummy implementation of the initialisation function.
std::unique_ptr< jet::TrackVertexAssociation > buildTrackVertexAssociation_withTool(const xAOD::TrackParticleContainer *, const xAOD::VertexContainer *) const
std::unique_ptr< jet::TrackVertexAssociation > buildTrackVertexAssociation_custom(const xAOD::TrackParticleContainer *, const xAOD::VertexContainer *) const
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
@ 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".