ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
BeamEffects
src
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
5
#include "
MatchingBkgVertexPositioner.h
"
6
7
#include "CLHEP/Vector/LorentzVector.h"
8
#include "
StoreGate/ReadHandle.h
"
9
10
namespace
Simulation
{
11
12
MatchingBkgVertexPositioner::MatchingBkgVertexPositioner
(
const
std::string &t,
13
const
std::string &n,
14
const
IInterface *p)
15
: base_class(t, n, p) {}
16
17
StatusCode
MatchingBkgVertexPositioner::initialize
() {
18
ATH_MSG_VERBOSE
(
"Initializing ..."
);
19
20
ATH_CHECK
(
m_vertexContainerKey
.initialize(
SG::AllowEmpty
));
21
ATH_CHECK
(
m_mcEventKey
.initialize(
SG::AllowEmpty
));
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
35
CLHEP::HepLorentzVector *
MatchingBkgVertexPositioner::generate
(
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()) {
41
SG::ReadHandle<xAOD::VertexContainer>
vertices(
m_vertexContainerKey
, ctx);
42
if
(!vertices.
isValid
()) {
43
ATH_MSG_ERROR
(
"Couldn't retrieve xAOD::VertexContainer with key: "
44
<<
m_vertexContainerKey
);
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: "
61
<<
m_vertexContainerKey
);
62
return
nullptr
;
63
}
else
if
(!
m_mcEventKey
.key().empty()) {
64
SG::ReadHandle<McEventCollection>
mcEvent(
m_mcEventKey
, ctx);
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
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x,...)
Definition
AthMsgStreamMacros.h:43
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x,...)
Definition
AthMsgStreamMacros.h:42
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
MatchingBkgVertexPositioner.h
ReadHandle.h
Handle class for reading from StoreGate.
y
#define y
x
#define x
z
#define z
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.
Simulation::MatchingBkgVertexPositioner::m_mcEventKey
SG::ReadHandleKey< McEventCollection > m_mcEventKey
Definition
MatchingBkgVertexPositioner.h:41
Simulation::MatchingBkgVertexPositioner::MatchingBkgVertexPositioner
MatchingBkgVertexPositioner(const std::string &t, const std::string &n, const IInterface *p)
Definition
MatchingBkgVertexPositioner.cxx:12
Simulation::MatchingBkgVertexPositioner::m_vertexContainerKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
Definition
MatchingBkgVertexPositioner.h:39
Simulation::MatchingBkgVertexPositioner::initialize
StatusCode initialize() override final
Definition
MatchingBkgVertexPositioner.cxx:17
Simulation::MatchingBkgVertexPositioner::generate
CLHEP::HepLorentzVector * generate(const EventContext &ctx) const override final
Definition
MatchingBkgVertexPositioner.cxx:35
SG::AllowEmpty
@ AllowEmpty
Definition
StoreGate/StoreGate/VarHandleKey.h:27
Simulation
Definition
BeamEffectsAlg.cxx:21
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