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