ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
JetTagging
FlavorTagJetDecorators
src
PrimaryVertexDecoratorAlg.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
#include "
PrimaryVertexDecoratorAlg.h
"
6
7
#include "
StoreGate/WriteDecorHandle.h
"
8
9
#include "
xAODTracking/VertexContainer.h
"
10
#include "
xAODTracking/TrackingPrimitives.h
"
11
12
#include <cmath>
13
#include <limits>
14
15
namespace
FlavorTagJetDecorators
{
16
17
PrimaryVertexDecoratorAlg::PrimaryVertexDecoratorAlg
(
18
const
std::string& name, ISvcLocator* loc)
19
:
AthReentrantAlgorithm
(name, loc) {}
20
21
StatusCode
PrimaryVertexDecoratorAlg::initialize
() {
22
ATH_MSG_DEBUG
(
"Initializing "
<< name() <<
"..."
);
23
24
ATH_CHECK
(
m_vertexContainerKey
.initialize());
25
ATH_CHECK
(
m_eventInfoKey
.initialize());
26
ATH_CHECK
(
m_dec_nPrimaryVertices
.initialize());
27
ATH_CHECK
(
m_dec_primaryVertexZ
.initialize());
28
29
return
StatusCode::SUCCESS;
30
}
31
32
StatusCode
PrimaryVertexDecoratorAlg::execute
(
33
const
EventContext& ctx)
const
{
34
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"..."
);
35
36
constexpr
float
NaN = std::numeric_limits<float>::quiet_NaN();
37
38
SG::ReadHandle<xAOD::VertexContainer>
vertices(
39
m_vertexContainerKey
, ctx);
40
ATH_CHECK
(vertices.
isValid
());
41
42
auto
eventInfo =
SG::makeHandle
(
m_eventInfoKey
, ctx);
43
ATH_CHECK
(eventInfo.isValid());
44
45
SG::WriteDecorHandle<xAOD::EventInfo, int>
dec_nPV(
46
m_dec_nPrimaryVertices
, ctx);
47
SG::WriteDecorHandle<xAOD::EventInfo, float>
dec_pvZ(
48
m_dec_primaryVertexZ
, ctx);
49
50
if
(vertices->empty()) {
51
ATH_MSG_WARNING
(
"Empty PrimaryVertices container — writing defaults"
);
52
dec_nPV(*eventInfo) = 0;
53
dec_pvZ(*eventInfo) = NaN;
54
return
StatusCode::SUCCESS;
55
}
56
57
// Find the primary vertex: first with vertexType == PriVtx,
58
// fallback to front(). Matches TDD's primary() function exactly.
59
const
xAOD::Vertex
* pv =
nullptr
;
60
for
(
const
auto
* vertex : *vertices) {
61
if
(vertex->vertexType() ==
xAOD::VxType::PriVtx
) {
62
pv = vertex;
63
break
;
64
}
65
}
66
if
(!pv) {
67
pv = vertices->front();
68
}
69
70
dec_nPV(*eventInfo) =
static_cast<
int
>
(vertices->size());
71
dec_pvZ(*eventInfo) =
static_cast<
float
>
(pv->z());
72
73
ATH_MSG_DEBUG
(
"nPrimaryVertices="
<< vertices->size()
74
<<
" primaryVertexZ="
<< pv->z());
75
76
return
StatusCode::SUCCESS;
77
}
78
79
}
// namespace FlavorTagJetDecorators
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
PrimaryVertexDecoratorAlg.h
WriteDecorHandle.h
Handle class for adding a decoration to an object.
TrackingPrimitives.h
VertexContainer.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
FlavorTagJetDecorators::PrimaryVertexDecoratorAlg::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition
PrimaryVertexDecoratorAlg.h:36
FlavorTagJetDecorators::PrimaryVertexDecoratorAlg::m_dec_nPrimaryVertices
SG::WriteDecorHandleKey< xAOD::EventInfo > m_dec_nPrimaryVertices
Definition
PrimaryVertexDecoratorAlg.h:40
FlavorTagJetDecorators::PrimaryVertexDecoratorAlg::PrimaryVertexDecoratorAlg
PrimaryVertexDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
PrimaryVertexDecoratorAlg.cxx:17
FlavorTagJetDecorators::PrimaryVertexDecoratorAlg::m_dec_primaryVertexZ
SG::WriteDecorHandleKey< xAOD::EventInfo > m_dec_primaryVertexZ
Definition
PrimaryVertexDecoratorAlg.h:44
FlavorTagJetDecorators::PrimaryVertexDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition
PrimaryVertexDecoratorAlg.cxx:21
FlavorTagJetDecorators::PrimaryVertexDecoratorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
PrimaryVertexDecoratorAlg.cxx:32
FlavorTagJetDecorators::PrimaryVertexDecoratorAlg::m_vertexContainerKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
Definition
PrimaryVertexDecoratorAlg.h:32
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
FlavorTagJetDecorators
Definition
JetOverlapLeptonDecoratorAlg.cxx:25
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition
ReadCondHandle.h:269
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition
TrackingPrimitives.h:590
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