ATLAS Offline Software
Loading...
Searching...
No Matches
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$
12
21#include "xAODTracking/Vertex.h"
22
23namespace 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
121const 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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE(LVL)
Report a message.
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t sc
Associate from a TrackParticle to its reconstructed vertex.
virtual StatusCode addVariable(const std::string &name, const std::type_info &ti, void *&ptr, const std::string &docstring="", const void *defval=0)
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexKey
xAOD vertex container handle key
TrackParticleVertexAssociationTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
float * m_weight
weight of the track at the associated vertex
std::string m_targetSGKey
SG key for target collection.
bool m_fast
flag to just return whatever is returned by TrackParticle::reconstructedVertex()
virtual const Trk::VxCandidate * get(const Rec::TrackParticle &p) override
Return the target object.
SingleAssociationTool< Types< Rec::TrackParticle, xAOD::TrackParticle >, Types< Trk::VxCandidate, xAOD::Vertex > > Base
virtual StatusCode initialize() override
Standard Gaudi initialize method.
virtual StatusCode book() final
book ntuple variables
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::vector< Trk::VxTrackAtVertex * > * vxTrackAtVertex(void)
Unconst pointer to the vector of tracks Required by some of the vertex fitters.
The VxTrackAtVertex is a common class for all present TrkVertexFitters The VxTrackAtVertex is designe...
Block filler tool for noisy FEB information.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.