ATLAS Offline Software
InDetSecVtxFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 /***************************************************************************
5  InDetSecVtxFinder.cxx - Description
6  -------------------
7  begin : Nov 10, 2016
8  authors : Lianyou SHAN ( IHEP-Beijing ) Neža Ribarič (Lancaster university, UK)
9  email : shanly@mail.ihep.ac.cn, neza.ribaric@cern.ch
10  changes : Changed name from InDetInclusiveSecVtx, added the option to chose the vertexing tool (ISV,AMVF)
11  ***************************************************************************/
13 
14 
15 // forward declares
16 
17 #include "xAODTracking/Vertex.h"
21 // normal includes
24 
25 namespace InDet
26 {
27 
28  InDetSecVtxFinder::InDetSecVtxFinder ( const std::string &n, ISvcLocator *pSvcLoc )
29  : AthAlgorithm ( n, pSvcLoc ),
30 
31  // for summary output at the end
32  m_numEventsProcessed(0),
33  m_totalNumVerticesWithoutDummy(0)
34 
35  {}
36 
37 
38 
40  {
41  /* Get the VertexFinderTool */
42 
44 
46 
47 
48  /*Get the Vertex Merging Tool*/
50  {
51  if(m_FinderTool == "AMVF"){
52  ATH_MSG_ERROR("AMVF finding and vertex merging is not possible");
53  return StatusCode::FAILURE;
54  }
55  ATH_CHECK( m_VertexMergingTool.retrieve());
56 
57  }
58 
64  ATH_CHECK(m_inputPrimaryVertices.initialize());
65 
66  ATH_MSG_DEBUG("Initialization successful");
67 
68  return StatusCode::SUCCESS;
69  }
70 
71 
73  {
75 
76  const EventContext& ctx = Gaudi::Hive::currentContext();
77 
79 
80  xAOD::VertexContainer* theXAODContainer = nullptr;
81  xAOD::VertexAuxContainer* theXAODAuxContainer = nullptr;
82  std::pair<xAOD::VertexContainer*,xAOD::VertexAuxContainer*> theXAODContainers
83  = std::make_pair( theXAODContainer, theXAODAuxContainer );
84 
85  // retrieve the PRIMARY Vertex
86 
88 
89  if(vtxCont.isValid()){
90  const xAOD::Vertex *privtx = static_cast< const xAOD::Vertex * >( *(vtxCont->begin()) );
91  static const SG::ConstAccessor<float> zAcc ("z");
92  if( privtx->vertexType() != xAOD::VxType::PriVtx || privtx->nTrackParticles() < 2 || !zAcc.isAvailable(*privtx)){
93  ATH_MSG_WARNING(" Illed Primary vertex, keeping privtx_z0 = 0 ");
94  }
95  else{
96  if(m_FinderTool == "ISV"){
97  m_InclusiveVertexFinderTool->setPriVtxPosition( privtx->position().x(), privtx->position().y(), privtx->position().z());
98  }
99  else if(m_FinderTool == "AMVF"){
100  m_AdaptiveMultiVertexFinderTool->setPrimaryVertexPosition( privtx->position().x(), privtx->position().y(), privtx->position().z());
101  }
102  else{
103  ATH_MSG_WARNING("Please specify a valid FinderTool");
104  }
105  }
106  }
107 
108  else{
109  ATH_MSG_WARNING("couldn't retrieve Primary vertex, keeping privtx_z0 = 0 ");
110  }
111 
112  std::unique_ptr<Trk::VxSecVertexInfo> foundVrts;
115  if(trackParticleCollection.isValid()){
116 
117  if(m_FinderTool == "ISV"){
118  theXAODContainers = m_InclusiveVertexFinderTool->findVertex ( trackParticleCollection.cptr());
119  }
120  else if(m_FinderTool == "AMVF"){
121  theXAODContainers = m_AdaptiveMultiVertexFinderTool->findVertex ( trackParticleCollection.cptr());
122  }
123  else{
124  ATH_MSG_WARNING("Please specify a Finder Tool");
125  }
126 
127  }
128  else{
129  ATH_MSG_DEBUG("No TrackParticle Collection with key "<<m_inputTrackParticles.key()<<" exists in StoreGate. No Vertexing Possible");
130  return StatusCode::SUCCESS;
131  }
132  }
133  else{
135  if(trackCollection.isValid()){
136 
137  if(m_FinderTool == "ISV"){
138  theXAODContainers = m_InclusiveVertexFinderTool->findVertex ( trackCollection.cptr() );
139  }
140  else{
141  ATH_MSG_WARNING("Please use ISV for vertex finding with trackCollection ");
142  }
143 
144 
145  }
146  else{
147  ATH_MSG_DEBUG("No Trk::Track Collection with key "<< m_inputTrackCollection.key()<<" exists in StoreGate. No Vertexing Possible");
148  return StatusCode::SUCCESS;
149  }
150 
151  }
152 
153 
154  // now re-merge and resort the vertex container and store to SG
155  xAOD::VertexContainer* myVertexContainer = nullptr;
156  xAOD::VertexAuxContainer* myVertexAuxContainer = nullptr;
157  std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*> myVxContainers = std::make_pair( myVertexContainer, myVertexAuxContainer );
158  ATH_MSG_DEBUG("Vertexing done, sorting the vertex container");
159  if (theXAODContainers.first) {
160  //sort xAOD::Vertex container
161 
162  if( m_doVertexMerging && theXAODContainers.first->size() > 1) {
163  myVxContainers = m_VertexMergingTool->mergeVertexContainer( *theXAODContainers.first );
164  delete theXAODContainers.first; //also cleans up the aux store
165  delete theXAODContainers.second;
166  theXAODContainers = myVxContainers;
167  }
168 
169  myVxContainers.first = theXAODContainers.first;
170  myVxContainers.second = theXAODContainers.second;
171 
172  if (myVxContainers.first == 0) {
173  ATH_MSG_WARNING("Vertex container has no associated store.");
174 
175  return StatusCode::SUCCESS;
176  }
177 
178  if (not myVxContainers.first->hasStore()) {
179  ATH_MSG_WARNING("Vertex container has no associated store.");
180 
181  return StatusCode::SUCCESS;
182  }
183 
184  ATH_MSG_DEBUG("Successfully reconstructed " << myVxContainers.first->size()-1 << " vertices (excluding dummy)");
185  m_totalNumVerticesWithoutDummy += (myVxContainers.first->size()-1);
186 
187  }
188 
189  ATH_CHECK(outputVertices.record(std::unique_ptr<xAOD::VertexContainer>(myVxContainers.first),std::unique_ptr<xAOD::VertexAuxContainer>(myVxContainers.second)));
190 
191 
192  ATH_MSG_DEBUG( "Recorded Vertices with key: " << m_outputSecondaryVertices.key() );
193 
194  return StatusCode::SUCCESS;
195  }
196 
198  {
199  ATH_MSG_DEBUG("Summary from Secondary Vertex Finder (InnerDetector/InDetRecAlgs/InDetSecVtxFinder)");
200  ATH_MSG_DEBUG("=== " << m_totalNumVerticesWithoutDummy << " vertices recoed in " << m_numEventsProcessed << " events (excluding dummy).");
201 
202  if (m_numEventsProcessed!=0) {
203  ATH_MSG_DEBUG( "=== " << double(m_totalNumVerticesWithoutDummy)/double(m_numEventsProcessed) << " vertices per event (excluding dummy).");
204  }
205 
206  return StatusCode::SUCCESS;
207  }
208 
209 } // end namespace InDet
TrackParticleBaseCollection.h
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition: Vertex_v1.cxx:270
xAOD::VertexAuxContainer_v1
Temporary container used until we have I/O for AuxStoreInternal.
Definition: VertexAuxContainer_v1.h:32
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
InDet::InDetSecVtxFinder::initialize
StatusCode initialize()
Definition: InDetSecVtxFinder.cxx:46
InDet::InDetSecVtxFinder::m_totalNumVerticesWithoutDummy
unsigned int m_totalNumVerticesWithoutDummy
Definition: InDetSecVtxFinder.h:76
InDet::InDetSecVtxFinder::m_doVertexMerging
BooleanProperty m_doVertexMerging
Definition: InDetSecVtxFinder.h:69
xAOD::Vertex_v1::position
const Amg::Vector3D & position() const
Returns the 3-pos.
SG::ConstAccessor< float >
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
InDet::InDetSecVtxFinder::m_useTrackParticles
BooleanProperty m_useTrackParticles
Definition: InDetSecVtxFinder.h:70
InDet::InDetSecVtxFinder::m_AdaptiveMultiVertexFinderTool
ToolHandle< InDet::IAdaptiveMultiSecVertexFinder > m_AdaptiveMultiVertexFinderTool
Definition: InDetSecVtxFinder.h:66
xAOD::Vertex_v1::vertexType
VxType::VertexType vertexType() const
The type of the vertex.
InDet::InDetSecVtxFinder::m_inputTrackParticles
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_inputTrackParticles
Definition: InDetSecVtxFinder.h:61
InDet::InDetSecVtxFinder::m_inputTrackCollection
SG::ReadHandleKey< TrackCollection > m_inputTrackCollection
Definition: InDetSecVtxFinder.h:60
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrackParticleAuxContainer.h
beamspotman.n
n
Definition: beamspotman.py:731
InDet::InDetSecVtxFinder::execute
StatusCode execute()
Definition: InDetSecVtxFinder.cxx:79
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
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
InDet::InDetSecVtxFinder::InDetSecVtxFinder
InDetSecVtxFinder(const std::string &name, ISvcLocator *pSvcLocator)
Definition: InDetSecVtxFinder.cxx:35
VxSecVertexInfo.h
InDet::InDetSecVtxFinder::m_numEventsProcessed
unsigned int m_numEventsProcessed
Definition: InDetSecVtxFinder.h:75
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
InDet::InDetSecVtxFinder::m_FinderTool
StringProperty m_FinderTool
Definition: InDetSecVtxFinder.h:71
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
Derived DataVector<T>.
Definition: DataVector.h:794
Vertex.h
AthAlgorithm
Definition: AthAlgorithm.h:47
InDetSecVtxFinder.h
TrackParticle.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
InDet::InDetSecVtxFinder::finalize
StatusCode finalize()
Definition: InDetSecVtxFinder.cxx:204
InDet::InDetSecVtxFinder::m_inputPrimaryVertices
SG::ReadHandleKey< xAOD::VertexContainer > m_inputPrimaryVertices
Definition: InDetSecVtxFinder.h:63
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
InDet::InDetSecVtxFinder::m_outputSecondaryVertices
SG::WriteHandleKey< xAOD::VertexContainer > m_outputSecondaryVertices
Definition: InDetSecVtxFinder.h:62
InDet::InDetSecVtxFinder::m_VertexMergingTool
ToolHandle< Trk::IVertexMergingTool > m_VertexMergingTool
Definition: InDetSecVtxFinder.h:67
InDet::InDetSecVtxFinder::m_InclusiveVertexFinderTool
ToolHandle< ISecVertexFinder > m_InclusiveVertexFinderTool
Definition: InDetSecVtxFinder.h:65