ATLAS Offline Software
Loading...
Searching...
No Matches
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
6
8
11
12#include <cmath>
13#include <limits>
14
15namespace FlavorTagJetDecorators {
16
18 const std::string& name, ISvcLocator* loc)
19 : AthReentrantAlgorithm(name, loc) {}
20
22 ATH_MSG_DEBUG("Initializing " << name() << "...");
23
24 ATH_CHECK(m_vertexContainerKey.initialize());
25 ATH_CHECK(m_eventInfoKey.initialize());
27 ATH_CHECK(m_dec_primaryVertexZ.initialize());
28
29 return StatusCode::SUCCESS;
30 }
31
33 const EventContext& ctx) const {
34 ATH_MSG_DEBUG("Executing " << name() << "...");
35
36 constexpr float NaN = std::numeric_limits<float>::quiet_NaN();
37
40 ATH_CHECK(vertices.isValid());
41
42 auto eventInfo = SG::makeHandle(m_eventInfoKey, ctx);
43 ATH_CHECK(eventInfo.isValid());
44
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for adding a decoration to an object.
An algorithm that can be simultaneously executed in multiple threads.
SG::WriteDecorHandleKey< xAOD::EventInfo > m_dec_nPrimaryVertices
PrimaryVertexDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteDecorHandleKey< xAOD::EventInfo > m_dec_primaryVertexZ
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
@ PriVtx
Primary vertex.
Vertex_v1 Vertex
Define the latest version of the vertex class.