ATLAS Offline Software
InDetSecVtxFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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
23 
24 namespace InDet
25 {
26 
27  InDetSecVtxFinder::InDetSecVtxFinder ( const std::string &n, ISvcLocator *pSvcLoc )
28  : AthAlgorithm ( n, pSvcLoc ),
29 
30  // for summary output at the end
31  m_numEventsProcessed(0),
32  m_totalNumVerticesWithoutDummy(0)
33 
34  {}
35 
36 
37 
39  {
40  /* Get the VertexFinderTool */
41 
43 
45 
46 
47  /*Get the Vertex Merging Tool*/
49  {
50  if(m_FinderTool == "AMVF"){
51  ATH_MSG_ERROR("AMVF finding and vertex merging is not possible");
52  return StatusCode::FAILURE;
53  }
54  ATH_CHECK( m_VertexMergingTool.retrieve());
55 
56  }
57 
63  ATH_CHECK(m_inputPrimaryVertices.initialize());
64 
65  ATH_MSG_DEBUG("Initialization successful");
66 
67  return StatusCode::SUCCESS;
68  }
69 
70 
72  {
74 
75  const EventContext& ctx = Gaudi::Hive::currentContext();
76 
78 
79  xAOD::VertexContainer* theXAODContainer = nullptr;
80  xAOD::VertexAuxContainer* theXAODAuxContainer = nullptr;
81  std::pair<xAOD::VertexContainer*,xAOD::VertexAuxContainer*> theXAODContainers
82  = std::make_pair( theXAODContainer, theXAODAuxContainer );
83 
84  // retrieve the PRIMARY Vertex
85 
87 
88  if(vtxCont.isValid()){
89  const xAOD::Vertex *privtx = static_cast< const xAOD::Vertex * >( *(vtxCont->begin()) );
90  if( privtx->vertexType() != xAOD::VxType::PriVtx || privtx->nTrackParticles() < 2 || !privtx->isAvailable<float> ("z")){
91  ATH_MSG_WARNING(" Illed Primary vertex, keeping privtx_z0 = 0 ");
92  }
93  else{
94  if(m_FinderTool == "ISV"){
95  m_InclusiveVertexFinderTool->setPriVtxPosition( privtx->position().x(), privtx->position().y(), privtx->position().z());
96  }
97  else if(m_FinderTool == "AMVF"){
98  m_AdaptiveMultiVertexFinderTool->setPrimaryVertexPosition( privtx->position().x(), privtx->position().y(), privtx->position().z());
99  }
100  else{
101  ATH_MSG_WARNING("Please specify a valid FinderTool");
102  }
103  }
104  }
105 
106  else{
107  ATH_MSG_WARNING("couldn't retrieve Primary vertex, keeping privtx_z0 = 0 ");
108  }
109 
110  std::unique_ptr<Trk::VxSecVertexInfo> foundVrts;
113  if(trackParticleCollection.isValid()){
114 
115  if(m_FinderTool == "ISV"){
116  theXAODContainers = m_InclusiveVertexFinderTool->findVertex ( trackParticleCollection.cptr());
117  }
118  else if(m_FinderTool == "AMVF"){
119  theXAODContainers = m_AdaptiveMultiVertexFinderTool->findVertex ( trackParticleCollection.cptr());
120  }
121  else{
122  ATH_MSG_WARNING("Please specify a Finder Tool");
123  }
124 
125  }
126  else{
127  ATH_MSG_DEBUG("No TrackParticle Collection with key "<<m_inputTrackParticles.key()<<" exists in StoreGate. No Vertexing Possible");
128  return StatusCode::SUCCESS;
129  }
130  }
131  else{
133  if(trackCollection.isValid()){
134 
135  if(m_FinderTool == "ISV"){
136  theXAODContainers = m_InclusiveVertexFinderTool->findVertex ( trackCollection.cptr() );
137  }
138  else{
139  ATH_MSG_WARNING("Please use ISV for vertex finding with trackCollection ");
140  }
141 
142 
143  }
144  else{
145  ATH_MSG_DEBUG("No Trk::Track Collection with key "<< m_inputTrackCollection.key()<<" exists in StoreGate. No Vertexing Possible");
146  return StatusCode::SUCCESS;
147  }
148 
149  }
150 
151 
152  // now re-merge and resort the vertex container and store to SG
153  xAOD::VertexContainer* myVertexContainer = nullptr;
154  xAOD::VertexAuxContainer* myVertexAuxContainer = nullptr;
155  std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*> myVxContainers = std::make_pair( myVertexContainer, myVertexAuxContainer );
156  ATH_MSG_DEBUG("Vertexing done, sorting the vertex container");
157  if (theXAODContainers.first) {
158  //sort xAOD::Vertex container
159 
160  if( m_doVertexMerging && theXAODContainers.first->size() > 1) {
161  myVxContainers = m_VertexMergingTool->mergeVertexContainer( *theXAODContainers.first );
162  delete theXAODContainers.first; //also cleans up the aux store
163  delete theXAODContainers.second;
164  theXAODContainers = myVxContainers;
165  }
166 
167  myVxContainers.first = theXAODContainers.first;
168  myVxContainers.second = theXAODContainers.second;
169 
170  if (myVxContainers.first == 0) {
171  ATH_MSG_WARNING("Vertex container has no associated store.");
172 
173  return StatusCode::SUCCESS;
174  }
175 
176  if (not myVxContainers.first->hasStore()) {
177  ATH_MSG_WARNING("Vertex container has no associated store.");
178 
179  return StatusCode::SUCCESS;
180  }
181 
182  ATH_MSG_DEBUG("Successfully reconstructed " << myVxContainers.first->size()-1 << " vertices (excluding dummy)");
183  m_totalNumVerticesWithoutDummy += (myVxContainers.first->size()-1);
184 
185  }
186 
187  ATH_CHECK(outputVertices.record(std::unique_ptr<xAOD::VertexContainer>(myVxContainers.first),std::unique_ptr<xAOD::VertexAuxContainer>(myVxContainers.second)));
188 
189 
190  ATH_MSG_DEBUG( "Recorded Vertices with key: " << m_outputSecondaryVertices.key() );
191 
192  return StatusCode::SUCCESS;
193  }
194 
196  {
197  ATH_MSG_DEBUG("Summary from Secondary Vertex Finder (InnerDetector/InDetRecAlgs/InDetSecVtxFinder)");
198  ATH_MSG_DEBUG("=== " << m_totalNumVerticesWithoutDummy << " vertices recoed in " << m_numEventsProcessed << " events (excluding dummy).");
199 
200  if (m_numEventsProcessed!=0) {
201  ATH_MSG_DEBUG( "=== " << double(m_totalNumVerticesWithoutDummy)/double(m_numEventsProcessed) << " vertices per event (excluding dummy).");
202  }
203 
204  return StatusCode::SUCCESS;
205  }
206 
207 } // 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
DUMMY Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
InDet::InDetSecVtxFinder::initialize
StatusCode initialize()
Definition: InDetSecVtxFinder.cxx:45
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::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:78
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:34
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:581
Vertex.h
AthAlgorithm
Definition: AthAlgorithm.h:47
InDetSecVtxFinder.h
SG::AuxElement::isAvailable
bool isAvailable(const std::string &name, const std::string &clsname="") const
Check if an aux variable is available for reading.
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:202
InDet::InDetSecVtxFinder::m_inputPrimaryVertices
SG::ReadHandleKey< xAOD::VertexContainer > m_inputPrimaryVertices
Definition: InDetSecVtxFinder.h:63
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