ATLAS Offline Software
Loading...
Searching...
No Matches
MatchingBkgVertexPositioner.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
7#include "CLHEP/Vector/LorentzVector.h"
9
10namespace Simulation {
11
13 const std::string &n,
14 const IInterface *p)
15 : base_class(t, n, p) {}
16
18 ATH_MSG_VERBOSE("Initializing ...");
19
22
23 if ( m_vertexContainerKey.key().empty() && m_mcEventKey.key().empty()) {
24 ATH_MSG_ERROR("Both, vertex and McEventCollection keys are empty, no source of vertex position");
25 return StatusCode::FAILURE;
26 }
27 if ( !m_vertexContainerKey.key().empty() && !m_mcEventKey.key().empty()) {
28 ATH_MSG_ERROR("Both, vertex and McEventCollection keys are not empty, ambiguous source of vertex position");
29 return StatusCode::FAILURE;
30 }
31
32 return StatusCode::SUCCESS;
33}
34
36 const EventContext &ctx) const {
37 // we can currently not reliably determine if the timing information is
38 // available
39 constexpr bool enableTime{false};
40 if(!m_vertexContainerKey.key().empty()) {
42 if (!vertices.isValid()) {
43 ATH_MSG_ERROR("Couldn't retrieve xAOD::VertexContainer with key: "
45 return nullptr;
46 }
47
48 for (const xAOD::Vertex *vx : *(vertices.cptr())) {
49 if (vx->vertexType() == xAOD::VxType::PriVtx) {
50 ATH_MSG_INFO("Using primary vertex with position and time: "
51 << vx->position().x() << " " << vx->position().y() << " "
52 << vx->position().z() << " "
53 << (enableTime && vx->hasValidTime() ? vx->time() : 0));
54 return new CLHEP::HepLorentzVector(
55 vx->position().x(), vx->position().y(), vx->position().z(),
56 enableTime && vx->hasValidTime() ? vx->time() : 0);
57 }
58 }
59
60 ATH_MSG_ERROR("No primary vertex found in xAOD::VertexContainer with key: "
62 return nullptr;
63 } else if (!m_mcEventKey.key().empty()) {
65 for ( auto event: *mcEvent) {
66 for ( auto vertex: event->vertices()) {
67 const float x = vertex->position().x();
68 const float y = vertex->position().y();
69 const float z = vertex->position().z();
70
71 ATH_MSG_DEBUG("bkg gen vertex position " << vertex->position() << " " << vertex->particles_in_size());
72 return new CLHEP::HepLorentzVector(x, y, z, 0);
73 }
74 }
75 }
76 return nullptr;
77}
78
79} // namespace Simulation
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
Handle class for reading from StoreGate.
#define y
#define x
#define z
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandleKey< McEventCollection > m_mcEventKey
MatchingBkgVertexPositioner(const std::string &t, const std::string &n, const IInterface *p)
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
CLHEP::HepLorentzVector * generate(const EventContext &ctx) const override final
@ PriVtx
Primary vertex.
Vertex_v1 Vertex
Define the latest version of the vertex class.