ATLAS Offline Software
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 
18  ATH_CHECK(m_vertexContainer_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 
31 StatusCode 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: "
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 
101 std::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*
123 std::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 
180 using PVC = const xAOD::VertexContainer*;
181 std::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 }
WriteHandle.h
Handle class for recording to StoreGate.
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
JetTrackVtxAssoAlg::m_tvaTool
ToolHandle< CP::ITrackVertexAssociationTool > m_tvaTool
Definition: JetTrackVtxAssoAlg.h:72
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
JetTrackVtxAssoAlg::m_vertexContainer_key
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainer_key
Definition: JetTrackVtxAssoAlg.h:81
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:269
JetTrackVtxAssoAlg::m_trackContainer_key
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackContainer_key
Definition: JetTrackVtxAssoAlg.h:80
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::OWN_ELEMENTS
@ OWN_ELEMENTS
this data object owns its elements
Definition: OwnershipPolicy.h:17
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
JetTrackVtxAssoAlg::buildTrackVertexAssociation_withTool
std::unique_ptr< jet::TrackVertexAssociation > buildTrackVertexAssociation_withTool(const xAOD::TrackParticleContainer *, const xAOD::VertexContainer *) const
Definition: JetTrackVtxAssoAlg.cxx:102
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
DataVector< xAOD::TrackParticle_v1 >
JetTrackVtxAssoAlg.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ReadHandle.h
Handle class for reading from StoreGate.
JetTrackVtxAssoAlg::buildTrackVertexAssociation_custom
std::unique_ptr< jet::TrackVertexAssociation > buildTrackVertexAssociation_custom(const xAOD::TrackParticleContainer *, const xAOD::VertexContainer *) const
Definition: JetTrackVtxAssoAlg.cxx:124
JetTrackVtxAssoAlg::m_transDistMax
Gaudi::Property< float > m_transDistMax
Definition: JetTrackVtxAssoAlg.h:76
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
python.PyAthena.v
v
Definition: PyAthena.py:157
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
JetTrackVtxAssoAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: JetTrackVtxAssoAlg.cxx:31
JetTrackVtxAssoAlg::m_tva_key
SG::WriteHandleKey< jet::TrackVertexAssociation > m_tva_key
Definition: JetTrackVtxAssoAlg.h:82
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
JetTrackVtxAssoAlg::initialize
StatusCode initialize() override
Athena algorithm's Hooks.
Definition: JetTrackVtxAssoAlg.cxx:11
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
JetTrackVtxAssoAlg::m_maxZ0SinTheta
Gaudi::Property< float > m_maxZ0SinTheta
Definition: JetTrackVtxAssoAlg.h:78
JetTrackVtxAssoAlg::makeTrackVertexAssociation
std::unique_ptr< jet::TrackVertexAssociation > makeTrackVertexAssociation(const xAOD::TrackParticleContainer *, const xAOD::VertexContainer *, bool useCustom) const
Definition: JetTrackVtxAssoAlg.cxx:182
JetTrackVtxAssoAlg::m_longDistMax
Gaudi::Property< float > m_longDistMax
Definition: JetTrackVtxAssoAlg.h:77
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.