ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetRecAlgs
InDetPriVxFinder
src
InDetPriVxFinder.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 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
***************************************************************************/
13
#include "
InDetPriVxFinder/InDetPriVxFinder.h
"
14
#include "
xAODTracking/Vertex.h
"
15
#include "
xAODTracking/TrackParticle.h
"
16
#include "
xAODTracking/TrackParticleAuxContainer.h
"
17
#include "
AthenaMonitoringKernel/Monitored.h
"
18
19
// normal includes
20
#include "
TrkParticleBase/TrackParticleBaseCollection.h
"
21
22
namespace
InDet
23
{
24
25
InDetPriVxFinder::InDetPriVxFinder
26
(
const
std::string& name,ISvcLocator* pSvcLocator) :
AthReentrantAlgorithm
(name, pSvcLocator)
27
{ }
28
29
30
StatusCode
InDetPriVxFinder::initialize
()
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*/
41
if
(
m_doVertexMerging
) {
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*/
53
if
(
m_doVertexSorting
) {
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
{
61
ATH_MSG_VERBOSE
(
"Retrieved tool "
<<
m_VertexCollectionSortingTool
);
62
}
63
}
else
{
64
m_VertexCollectionSortingTool
.disable();
65
}
66
if
(!
m_monTool
.empty())
CHECK
(
m_monTool
.retrieve());
67
68
ATH_CHECK
(
m_trkTracksName
.initialize(!
m_useTrackParticles
));
69
ATH_CHECK
(
m_tracksName
.initialize(
m_useTrackParticles
));
70
ATH_CHECK
(
m_vxCandidatesOutputName
.initialize());
71
return
StatusCode::SUCCESS;
72
}
73
74
75
StatusCode
InDetPriVxFinder::execute
(
const
EventContext& ctx)
const
76
{
77
78
SG::WriteHandle<xAOD::VertexContainer>
outputVertices (
m_vxCandidatesOutputName
, ctx);
79
80
xAOD::VertexContainer
* vertexContainer =
nullptr
;
81
xAOD::VertexAuxContainer
* vertexAuxContainer =
nullptr
;
82
auto
vertexContainerPair = std::make_pair(vertexContainer, vertexAuxContainer);
83
84
if
(
m_useTrackParticles
) {
85
SG::ReadHandle<xAOD::TrackParticleContainer>
trackParticleCollection(
m_tracksName
, ctx);
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
{
95
SG::ReadHandle<TrackCollection>
trackCollection(
m_trkTracksName
, ctx);
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( ctx, *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
159
StatusCode
InDetPriVxFinder::finalize
()
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
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
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
TrackParticle.h
Vertex.h
InDetPriVxFinder.h
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
TrackParticleAuxContainer.h
TrackParticleBaseCollection.h
y
#define y
x
#define x
z
#define z
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
DataVector< xAOD::Vertex_v1 >::iterator
DataModel_detail::iterator< DataVector > iterator
Definition
DataVector.h:842
InDet::InDetPriVxFinder::finalize
virtual StatusCode finalize() override
Definition
InDetPriVxFinder.cxx:159
InDet::InDetPriVxFinder::m_VertexMergingTool
ToolHandle< Trk::IVertexMergingTool > m_VertexMergingTool
Definition
InDetPriVxFinder.h:65
InDet::InDetPriVxFinder::m_trkTracksName
SG::ReadHandleKey< TrackCollection > m_trkTracksName
Definition
InDetPriVxFinder.h:60
InDet::InDetPriVxFinder::m_VertexFinderTool
ToolHandle< IVertexFinder > m_VertexFinderTool
Definition
InDetPriVxFinder.h:64
InDet::InDetPriVxFinder::m_useTrackParticles
BooleanProperty m_useTrackParticles
Definition
InDetPriVxFinder.h:71
InDet::InDetPriVxFinder::monitor_vertex
void monitor_vertex(const std::string &prefix, const xAOD::Vertex &vertex) const
Definition
InDetPriVxFinder.cxx:164
InDet::InDetPriVxFinder::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
InDetPriVxFinder.cxx:75
InDet::InDetPriVxFinder::InDetPriVxFinder
InDetPriVxFinder(const std::string &name, ISvcLocator *pSvcLocator)
Definition
InDetPriVxFinder.cxx:26
InDet::InDetPriVxFinder::m_doVertexSorting
BooleanProperty m_doVertexSorting
Definition
InDetPriVxFinder.h:70
InDet::InDetPriVxFinder::m_VertexCollectionSortingTool
ToolHandle< Trk::IVertexCollectionSortingTool > m_VertexCollectionSortingTool
Definition
InDetPriVxFinder.h:66
InDet::InDetPriVxFinder::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition
InDetPriVxFinder.h:67
InDet::InDetPriVxFinder::initialize
virtual StatusCode initialize() override
Definition
InDetPriVxFinder.cxx:30
InDet::InDetPriVxFinder::m_tracksName
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_tracksName
Definition
InDetPriVxFinder.h:61
InDet::InDetPriVxFinder::m_vxCandidatesOutputName
SG::WriteHandleKey< xAOD::VertexContainer > m_vxCandidatesOutputName
Definition
InDetPriVxFinder.h:62
InDet::InDetPriVxFinder::m_doVertexMerging
BooleanProperty m_doVertexMerging
Definition
InDetPriVxFinder.h:69
Monitored::Group
Group of local monitoring quantities and retain correlation when filling histograms
Definition
MonitoredGroup.h:53
Monitored::Scalar
Declare a monitored scalar variable.
Definition
MonitoredScalar.h:34
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition
comparitor.cxx:525
InDet
Primary Vertex Finder.
Definition
VP1ErrorUtils.h:36
xAOD::VertexAuxContainer
VertexAuxContainer_v1 VertexAuxContainer
Definition of the current jet auxiliary container.
Definition
VertexAuxContainer.h:19
xAOD::VertexContainer
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Definition
VertexContainer.h:14
xAOD::Vertex
Vertex_v1 Vertex
Define the latest version of the vertex class.
Definition
Event/xAOD/xAODTracking/xAODTracking/Vertex.h:16
Generated on
for ATLAS Offline Software by
1.17.0