ATLAS Offline Software
Loading...
Searching...
No Matches
PrimaryVertexRefitter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
5// ****************************************************************************
6// ----------------------------------------------------------------------------
7// PrimaryVertexRefitter
8// James Catmore <James.Catmore@cern.ch>
9// Evelina Bouhova-Thacker <e.bouhova@cern.ch>
10// Returns a refitted primary vertex having removed requested tracks
11// ----------------------------------------------------------------------------
12// ****************************************************************************
13
15
16#include "xAODTracking/Vertex.h"
18
19namespace Analysis {
20
22
24
25 ATH_MSG_DEBUG("Initialize successful");
26
27 return StatusCode::SUCCESS;
28
29}
30
31PrimaryVertexRefitter::PrimaryVertexRefitter(const std::string& t, const std::string& n, const IInterface* p) :
32AthAlgTool(t,n,p)
33{
34 declareInterface<PrimaryVertexRefitter>(this);
35}
36
38
39// -------------------------------------------------------------------------------------------------
40xAOD::Vertex* PrimaryVertexRefitter::refitVertex(const xAOD::Vertex* vertex, const xAOD::Vertex* excludeVertex, bool returnCopy, int* exitcode) const
41{
42
43 if (vertex == 0) {
44 ATH_MSG_DEBUG("Empty original xAOD::Vertex pointer passed: returning 0");
45 if(exitcode) *exitcode = -1;
46 return 0;
47 }
48 unsigned int ntrk_pv = vertex->nTrackParticles();
49 if (ntrk_pv == 0) {
50 ATH_MSG_DEBUG("Input vertex has no associated tracks: returning 0");
51 if(exitcode) *exitcode =-2;
52 return 0;
53 }
54 if (excludeVertex == 0) {
55 ATH_MSG_DEBUG("Empty exclude xAOD::Vertex pointer passed: returning original vertex");
56 if(exitcode) *exitcode = 10;
57 return returnCopy ? new xAOD::Vertex(*vertex) : nullptr;
58 }
59 std::vector<const xAOD::TrackParticle*> tps; tps.clear();
60 unsigned int ntrk = excludeVertex->nTrackParticles();
61 if (ntrk == 0) {
62 ATH_MSG_DEBUG("Exclude vertex has no associated tracks: returning original vertex");
63 if(exitcode) *exitcode = 11;
64 return returnCopy ? new xAOD::Vertex(*vertex) : nullptr;
65 }
66
67 for (unsigned int i = 0; i < ntrk ; ++i) {
68 const xAOD::TrackParticle* tp = excludeVertex->trackParticle(i);
69 if (tp==0) continue;
70 tps.push_back(tp);
71 }
72 return refitVertex(vertex,tps, returnCopy, exitcode);
73}
74
75// -------------------------------------------------------------------------------------------------
76xAOD::Vertex* PrimaryVertexRefitter::refitVertex(const xAOD::Vertex* vertex, const std::vector<const xAOD::TrackParticle*> &tps, bool returnCopy, int* exitcode) const
77{
78
79 if (vertex == 0) {
80 ATH_MSG_DEBUG("Empty original xAOD::Vertex pointer passed: returning 0");
81 if(exitcode) *exitcode =-1;
82 return 0;
83 }
84 unsigned int ntrk_pv = vertex->nTrackParticles();
85 if (ntrk_pv == 0) {
86 ATH_MSG_DEBUG("Input vertex has no associated tracks: returning 0");
87 if(exitcode) *exitcode = -2;
88 return 0;
89 }
90 if (ntrk_pv <= m_ntrk_min) {
91 ATH_MSG_DEBUG("The number of tracks " << ntrk_pv << " in the original vertex is already <= the allowed minimum number of tracks " << m_ntrk_min << ", returning original vertex");
92 if(exitcode) *exitcode = 2;
93 return returnCopy ? new xAOD::Vertex(*vertex) : nullptr;
94 }
95 unsigned int ntrk = tps.size();
96 if (ntrk == 0) {
97 ATH_MSG_DEBUG("No tracks requested to be removed: returning original vertex");
98 if(exitcode) *exitcode = 3;
99 return returnCopy ? new xAOD::Vertex(*vertex) : nullptr;
100 }
101
102 xAOD::Vertex* reducedVertex(0);
103 const xAOD::Vertex* tmpVert = vertex;
104 std::vector <const xAOD::TrackParticle*>::const_iterator pb = tps.begin();
105 std::vector <const xAOD::TrackParticle*>::const_iterator pe = tps.end();
106 for (;pb!=pe;++pb) {
107 const xAOD::TrackParticle* tp = (*pb);
108 reducedVertex = m_trackToVertexIPEstimator->getUnbiasedVertex(tp,tmpVert);
109 if (tmpVert != vertex) delete tmpVert;
110 if (reducedVertex == 0) {
111 ATH_MSG_DEBUG("Refit failed: returning original vertex");
112 if(exitcode) *exitcode = -4;
113 return returnCopy ? new xAOD::Vertex(*vertex) : nullptr;
114 }
115 tmpVert = reducedVertex;
116 if (tmpVert->nTrackParticles() <= m_ntrk_min-1) {
117 ATH_MSG_DEBUG("The number of tracks in the refitted vertex would be less than the allowed minimum number of tracks: " << m_ntrk_min << ", returning original vertex");
118 delete reducedVertex;
119 if(exitcode) *exitcode = 5;
120 return returnCopy ? new xAOD::Vertex(*vertex) : nullptr;
121 }
122 }
123 if(exitcode) *exitcode = 1;
124 return reducedVertex;
125}
126
127}
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
PrimaryVertexRefitter(const std::string &t, const std::string &n, const IInterface *p)
Gaudi::Property< unsigned int > m_ntrk_min
xAOD::Vertex * refitVertex(const xAOD::Vertex *vertex, const xAOD::Vertex *excludeVertex, bool ReturnCopy=true, int *exitcode=nullptr) const
ToolHandle< Trk::ITrackToVertexIPEstimator > m_trackToVertexIPEstimator
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
const TrackParticle * trackParticle(size_t i) const
Get the pointer to a given track that was used in vertex reco.
The namespace of all packages in PhysicsAnalysis/JetTagging.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.