ATLAS Offline Software
Loading...
Searching...
No Matches
InDetPriVxFinder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5/***************************************************************************
6 InDetPriVxFinder.cxx - Description
7 -------------------
8 begin : 28-01-2004
9 authors : Andreas Wildauer (CERN PH-ATC), Fredrik Akesson (CERN PH-ATC)
10 email : andreas.wildauer@cern.ch, fredrik.akesson@cern.ch
11 changes :
12 ***************************************************************************/
14#include "xAODTracking/Vertex.h"
18
19// normal includes
21
22namespace InDet
23{
24
26 (const std::string& name,ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator)
27 { }
28
29
31 {
32 /* Get the VertexFinderTool */
33 if ( m_VertexFinderTool.retrieve().isFailure() )
34 {
35 ATH_MSG_FATAL("Failed to retrieve tool " << m_VertexFinderTool);
36 return StatusCode::FAILURE;
37 }
38 ATH_MSG_DEBUG("Retrieved tool " << m_VertexFinderTool);
39
40 /*Get the Vertex Merging Tool*/
42 if ( m_VertexMergingTool.retrieve().isFailure() )
43 {
44 ATH_MSG_FATAL("Failed to retrieve tool " << m_VertexMergingTool);
45 return StatusCode::FAILURE;
46 }
47 ATH_MSG_DEBUG("Retrieved tool " << m_VertexMergingTool);
48 } else {
49 m_VertexMergingTool.disable();
50 }
51
52 /*Get the Vertex Collection Sorting Tool*/
54 if ( m_VertexCollectionSortingTool.retrieve().isFailure() )
55 {
56 ATH_MSG_FATAL("Failed to retrieve tool " << m_VertexCollectionSortingTool);
57 return StatusCode::FAILURE;
58 }
59 else
60 {
62 }
63 } else {
65 }
66 if (!m_monTool.empty()) CHECK(m_monTool.retrieve());
67
71 return StatusCode::SUCCESS;
72 }
73
74
75 StatusCode InDetPriVxFinder::execute(const EventContext& ctx) const
76 {
77
79
80 xAOD::VertexContainer* vertexContainer = nullptr;
81 xAOD::VertexAuxContainer* vertexAuxContainer = nullptr;
82 auto vertexContainerPair = std::make_pair(vertexContainer, vertexAuxContainer);
83
86 if (trackParticleCollection.isValid()) {
87 vertexContainerPair = m_VertexFinderTool->findVertex(ctx, trackParticleCollection.cptr());
88 } else {
89 ATH_MSG_ERROR("No TrackParticle Collection with key "
90 << m_tracksName.key()
91 << " exists in StoreGate. No Vertexing Possible");
92 return StatusCode::FAILURE;
93 }
94 } else {
96 if (trackCollection.isValid()) {
97 vertexContainerPair = m_VertexFinderTool->findVertex(ctx, trackCollection.cptr());
98 } else {
99 ATH_MSG_ERROR("No Trk::Track Collection with key "
100 << m_trkTracksName.key()
101 << " exists in StoreGate. No Vertexing Possible");
102 return StatusCode::FAILURE;
103 }
104 }
105
106 // now re-merge and resort the vertex container and store to SG
107 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer* > myVertexContainerPair{nullptr, nullptr};
108 auto deletePair = [](std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer* > &p){
109 delete p.first; p.first = nullptr;
110 delete p.second; p.second = nullptr;
111 };
112
113 if (vertexContainerPair.first) {
114 //sort xAOD::Vertex container
115 if(m_doVertexMerging && vertexContainerPair.first->size() > 1) {
116 myVertexContainerPair = m_VertexMergingTool->mergeVertexContainer( *vertexContainerPair.first );
117 deletePair(vertexContainerPair); //also cleans up the aux store
118 vertexContainerPair = myVertexContainerPair;
119 }
120
121 if (m_doVertexSorting) {
122 myVertexContainerPair = m_VertexCollectionSortingTool->sortVertexContainer(*vertexContainerPair.first);
123 deletePair(vertexContainerPair);
124 }
125
126 if (myVertexContainerPair.first == nullptr) {
127 ATH_MSG_ERROR("Vertex container has no associated store.");
128 return StatusCode::FAILURE;
129 }
130
131 if (not myVertexContainerPair.first->hasStore()) {
132 ATH_MSG_ERROR("Vertex container has no associated store.");
133 return StatusCode::FAILURE;
134 }
135 ATH_MSG_DEBUG("Successfully reconstructed "
136 << myVertexContainerPair.first->size() - 1
137 << " vertices (excluding dummy)");
138 }
139
140 ATH_CHECK(outputVertices.record(
141 std::unique_ptr<xAOD::VertexContainer>(myVertexContainerPair.first),
142 std::unique_ptr<xAOD::VertexAuxContainer>(myVertexContainerPair.second)));
143
144 auto NVertices = Monitored::Scalar<int>( "NVertices" , 0 );
145 for ( xAOD::VertexContainer::iterator vertexIter = myVertexContainerPair.first->begin();
146 vertexIter != myVertexContainerPair.first->end(); ++vertexIter ) {
147 if((*vertexIter)->nTrackParticles() > 0 and (*vertexIter)->vertexType() != 0 ){
148 NVertices++;
149 monitor_vertex( "allVertex", **vertexIter);
150 //This expects that vertices are already sorted by SumpT(or different criteria)!!!
151 if( vertexIter == myVertexContainerPair.first->begin() ) monitor_vertex( "primVertex", **vertexIter);
152 }
153 }
154 auto mon = Monitored::Group( m_monTool, NVertices);
155
156 return StatusCode::SUCCESS;
157 }
158
160 {
161 return StatusCode::SUCCESS;
162 }
163
164 void InDetPriVxFinder::monitor_vertex( const std::string &prefix, const xAOD::Vertex& vertex ) const {
165 if (prefix == "allVertex"){
166 auto x = Monitored::Scalar<double>( "allVertexX", vertex.x() );
167 auto y = Monitored::Scalar<double>( "allVertexY", vertex.y() );
168 auto z = Monitored::Scalar<double>( "allVertexZ", vertex.z() );
169 auto chi2 = Monitored::Scalar<double>( "allVertexChi2", vertex.chiSquared() );
170 auto nDoF = Monitored::Scalar<double>( "allVertexnDoF", vertex.numberDoF() );
171 auto NTracks = Monitored::Scalar<int> ( "allVertexNTracks", vertex.nTrackParticles() );
172 auto mon = Monitored::Group(m_monTool, x, y, z, chi2, nDoF, NTracks );
173 }
174 else if (prefix == "primVertex"){
175 auto x = Monitored::Scalar<double>( "primVertexX", vertex.x() );
176 auto y = Monitored::Scalar<double>( "primVertexY", vertex.y() );
177 auto z = Monitored::Scalar<double>( "primVertexZ", vertex.z() );
178 auto chi2 = Monitored::Scalar<double>( "primVertexChi2", vertex.chiSquared() );
179 auto nDoF = Monitored::Scalar<double>( "primVertexnDoF", vertex.numberDoF() );
180 auto NTracks = Monitored::Scalar<int> ( "primVertexNTracks", vertex.nTrackParticles() );
181 auto mon = Monitored::Group(m_monTool, x, y, z, chi2, nDoF, NTracks );
182 }
183 }
184
185} // end namespace InDet
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
Header file to be included by clients of the Monitored infrastructure.
#define y
#define x
#define z
An algorithm that can be simultaneously executed in multiple threads.
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
virtual StatusCode finalize() override
ToolHandle< Trk::IVertexMergingTool > m_VertexMergingTool
SG::ReadHandleKey< TrackCollection > m_trkTracksName
ToolHandle< IVertexFinder > m_VertexFinderTool
BooleanProperty m_useTrackParticles
void monitor_vertex(const std::string &prefix, const xAOD::Vertex &vertex) const
virtual StatusCode execute(const EventContext &ctx) const override
InDetPriVxFinder(const std::string &name, ISvcLocator *pSvcLocator)
BooleanProperty m_doVertexSorting
ToolHandle< Trk::IVertexCollectionSortingTool > m_VertexCollectionSortingTool
ToolHandle< GenericMonitoringTool > m_monTool
virtual StatusCode initialize() override
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_tracksName
SG::WriteHandleKey< xAOD::VertexContainer > m_vxCandidatesOutputName
BooleanProperty m_doVertexMerging
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
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.
double chi2(TH1 *h0, TH1 *h1)
Primary Vertex Finder.
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.