ATLAS Offline Software
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 
19 namespace Analysis {
20 
22 
23  CHECK( m_trackToVertexIPEstimator.retrieve() );
24 
25  ATH_MSG_DEBUG("Initialize successful");
26 
27  return StatusCode::SUCCESS;
28 
29 }
30 
31 PrimaryVertexRefitter::PrimaryVertexRefitter(const std::string& t, const std::string& n, const IInterface* p) :
32 AthAlgTool(t,n,p)
33 {
34  declareInterface<PrimaryVertexRefitter>(this);
35 }
36 
38 
39 // -------------------------------------------------------------------------------------------------
40 xAOD::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 // -------------------------------------------------------------------------------------------------
76 xAOD::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 }
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition: Vertex_v1.cxx:270
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
xAOD::Vertex
Vertex_v1 Vertex
Define the latest version of the vertex class.
Definition: Event/xAOD/xAODTracking/xAODTracking/Vertex.h:16
keylayer_zslicemap.pb
pb
Definition: keylayer_zslicemap.py:188
ParticleTest.tp
tp
Definition: ParticleTest.py:25
athena.exitcode
int exitcode
Definition: athena.py:159
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
PrimaryVertexRefitter.h
Analysis::PrimaryVertexRefitter::PrimaryVertexRefitter
PrimaryVertexRefitter(const std::string &t, const std::string &n, const IInterface *p)
Definition: PrimaryVertexRefitter.cxx:31
LArG4AODNtuplePlotter.pe
pe
Definition: LArG4AODNtuplePlotter.py:116
Analysis::PrimaryVertexRefitter::refitVertex
xAOD::Vertex * refitVertex(const xAOD::Vertex *vertex, const xAOD::Vertex *excludeVertex, bool ReturnCopy=true, int *exitcode=nullptr) const
Definition: PrimaryVertexRefitter.cxx:40
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
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
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
xAOD::Vertex_v1::trackParticle
const TrackParticle * trackParticle(size_t i) const
Get the pointer to a given track that was used in vertex reco.
Definition: Vertex_v1.cxx:249
Vertex.h
Analysis
The namespace of all packages in PhysicsAnalysis/JetTagging.
Definition: BTaggingCnvAlg.h:20
TrackParticle.h
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
Analysis::PrimaryVertexRefitter::m_trackToVertexIPEstimator
ToolHandle< Trk::ITrackToVertexIPEstimator > m_trackToVertexIPEstimator
Definition: PrimaryVertexRefitter.h:42
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
AthAlgTool
Definition: AthAlgTool.h:26
Analysis::PrimaryVertexRefitter::initialize
StatusCode initialize()
Definition: PrimaryVertexRefitter.cxx:21
Analysis::PrimaryVertexRefitter::~PrimaryVertexRefitter
~PrimaryVertexRefitter()
Definition: PrimaryVertexRefitter.cxx:37
Analysis::PrimaryVertexRefitter::m_ntrk_min
Gaudi::Property< unsigned int > m_ntrk_min
Definition: PrimaryVertexRefitter.h:41