ATLAS Offline Software
TrackParticleVertexAssociationTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id$
15 #include "Particle/TrackParticle.h"
16 #include "VxVertex/VxCandidate.h"
17 #include "VxVertex/VxContainer.h"
21 #include "xAODTracking/Vertex.h"
22 
23 namespace D3PD {
24 
32  (const std::string& type,
33  const std::string& name,
34  const IInterface* parent)
35  : Base (type, name, parent)
36 {
37  declareProperty ("VxSGKey", m_targetSGKey="VxPrimaryCandidate");
38  declareProperty ("Fast", m_fast = false);
39 
40  book().ignore(); // Avoid coverity warnings.
41 }
42 
47 {
48  ATH_CHECK( m_vertexKey.initialize() );
49  return Base::initialize();
50 }
51 
56 
57  if(!m_fast) CHECK( addVariable("weight", m_weight) );
58 
59  return Base::book();
60 }
61 
69 
70  if(m_fast){
71  return p.reconstructedVertex();
72  }
73 
74  *m_weight = 0;
75 
76  const VxContainer* vxContainer = 0;
77  StatusCode sc = evtStore()->retrieve(vxContainer, m_targetSGKey);
78  if (sc.isFailure() || !vxContainer) {
79  REPORT_MESSAGE (MSG::WARNING) << "Could not retrieve primary vertex container: " << m_targetSGKey;
80  return 0;
81  }
82 
83  int nVx = vxContainer->size();
84  if(nVx < 1){
85  return 0;
86  }
87 
88  for(int v=0; v<nVx-1; v++){
89  const Trk::VxCandidate* vx = vxContainer->at(v);
90  const std::vector<Trk::VxTrackAtVertex*>* tracks = vx->vxTrackAtVertex();
91  int nTracks = 0;
92  if(tracks) nTracks = tracks->size();
93  for(int t=0; t<nTracks; t++) {
94  Trk::VxTrackAtVertex* track = tracks->at(t);
95  if(track){
96  Trk::ITrackLink* link = track->trackOrParticleLink();
97  if (link) {
98  Trk::LinkToTrackParticleBase* linkToTrackParticle = dynamic_cast<Trk::LinkToTrackParticleBase*>(link);
99  if(linkToTrackParticle){
100  const Trk::TrackParticleBase *particle_base = **linkToTrackParticle;
101  if(particle_base == &p){
102  *m_weight = track->weight();
103  return vx;
104  }
105  }
106  }
107  }
108  }
109  }
110 
111  return vxContainer->at(nVx-1);
112 }
113 
114 
121 const xAOD::Vertex*
123 {
124  const xAOD::Vertex* foundVertex { nullptr };
126  if (!vertices.isValid())
127  {
128  ATH_MSG_WARNING("No VertexContainer with key = " << m_vertexKey.key() );
129  return foundVertex;
130  }
131  for ( const auto vx : *vertices )
132  {
133  for ( const auto& tpLink : vx->trackParticleLinks() )
134  {
135  if ( *tpLink == &p )
136  {
137  foundVertex = vx;
138  break;
139  }
140  }
141  if (foundVertex) break;
142  }
143  return foundVertex;
144 }
145 
146 
147 } // namespace D3PD
Trk::VxTrackAtVertex
The VxTrackAtVertex is a common class for all present TrkVertexFitters The VxTrackAtVertex is designe...
Definition: VxTrackAtVertex.h:77
TrackParticle.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
initialize
void initialize()
Definition: run_EoverP.cxx:894
D3PD::TrackParticleVertexAssociationTool::TrackParticleVertexAssociationTool
TrackParticleVertexAssociationTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Definition: TrackParticleVertexAssociationTool.cxx:32
D3PD::SingleAssociationTool< Types< Rec::TrackParticle, xAOD::TrackParticle >, Types< Trk::VxCandidate, xAOD::Vertex > >
D3PD::AddVariable::addVariable
virtual StatusCode addVariable(const std::string &name, const std::type_info &ti, void *&ptr, const std::string &docstring="", const void *defval=0)
Add a variable to the tuple.
Definition: AddVariable.cxx:85
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
D3PD::TrackParticleVertexAssociationTool::book
virtual StatusCode book() final
book ntuple variables
Definition: TrackParticleVertexAssociationTool.cxx:55
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
D3PD::TrackParticleVertexAssociationTool::get
virtual const Trk::VxCandidate * get(const Rec::TrackParticle &p) override
Return the target object.
Definition: TrackParticleVertexAssociationTool.cxx:68
Trk::TrackParticleBase
Definition: TrackParticleBase.h:41
D3PD
Block filler tool for noisy FEB information.
Definition: CaloCellDetailsFillerTool.cxx:29
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
Trk::VxCandidate::vxTrackAtVertex
std::vector< Trk::VxTrackAtVertex * > * vxTrackAtVertex(void)
Unconst pointer to the vector of tracks Required by some of the vertex fitters.
Definition: VxCandidate.h:144
TrackParticleVertexAssociationTool.h
Associate from a TrackParticle to its reconstructed vertex.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
D3PD::TrackParticleVertexAssociationTool::m_targetSGKey
std::string m_targetSGKey
SG key for target collection.
Definition: TrackParticleVertexAssociationTool.h:78
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VxTrackAtVertex.h
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
VxContainer.h
VxContainer
Definition: VxContainer.h:28
Vertex.h
LinkToTrackParticleBase.h
Trk::LinkToTrackParticleBase
Definition: LinkToTrackParticleBase.h:17
VxCandidate.h
D3PD::TrackParticleVertexAssociationTool::m_fast
bool m_fast
flag to just return whatever is returned by TrackParticle::reconstructedVertex()
Definition: TrackParticleVertexAssociationTool.h:81
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
errorcheck.h
Helpers for checking error return status codes and reporting errors.
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
Rec::TrackParticle
Definition: Reconstruction/Particle/Particle/TrackParticle.h:47
python.PyAthena.v
v
Definition: PyAthena.py:154
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
D3PD::TrackParticleVertexAssociationTool::initialize
virtual StatusCode initialize() override
Standard Gaudi initialize method.
Definition: TrackParticleVertexAssociationTool.cxx:46
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::VxCandidate
Definition: VxCandidate.h:27
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
D3PD::SingleAssociationToolImpl::book
virtual StatusCode book()
Create any needed tuple variables.
Definition: SingleAssociationToolImpl.cxx:92
D3PD::TrackParticleVertexAssociationTool::m_vertexKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexKey
xAOD vertex container handle key
Definition: TrackParticleVertexAssociationTool.h:87
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.
D3PD::TrackParticleVertexAssociationTool::m_weight
float * m_weight
weight of the track at the associated vertex
Definition: TrackParticleVertexAssociationTool.h:84
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrackParticleContainer.h