ATLAS Offline Software
Loading...
Searching...
No Matches
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
25namespace InDet
26{
27
28 InDetSecVtxFinder::InDetSecVtxFinder ( const std::string &n, ISvcLocator *pSvcLoc )
29 : AthAlgorithm ( n, pSvcLoc ),
30
31 // for summary output at the end
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
60
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helper class to provide constant type-safe access to aux data.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
BooleanProperty m_useTrackParticles
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_inputTrackParticles
BooleanProperty m_doVertexMerging
ToolHandle< ISecVertexFinder > m_InclusiveVertexFinderTool
SG::ReadHandleKey< TrackCollection > m_inputTrackCollection
unsigned int m_totalNumVerticesWithoutDummy
ToolHandle< InDet::IAdaptiveMultiSecVertexFinder > m_AdaptiveMultiVertexFinderTool
SG::WriteHandleKey< xAOD::VertexContainer > m_outputSecondaryVertices
SG::ReadHandleKey< xAOD::VertexContainer > m_inputPrimaryVertices
ToolHandle< Trk::IVertexMergingTool > m_VertexMergingTool
InDetSecVtxFinder(const std::string &name, ISvcLocator *pSvcLocator)
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
VxType::VertexType vertexType() const
The type of the vertex.
const Amg::Vector3D & position() const
Returns the 3-pos.
Primary Vertex Finder.
@ PriVtx
Primary vertex.
VertexAuxContainer_v1 VertexAuxContainer
Definition of the current jet auxiliary container.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.