ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
JetTagging
FlavorTagDiscriminants
src
HitDecoratorAlg.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
// Header file
6
#include "
FlavorTagDiscriminants/HitDecoratorAlg.h
"
7
8
// Read and write handles
9
#include "
StoreGate/WriteDecorHandle.h
"
10
#include "
StoreGate/ReadDecorHandle.h
"
11
12
13
namespace
FlavorTagDiscriminants
{
14
15
HitDecoratorAlg::HitDecoratorAlg
(
16
const
std::string& name, ISvcLocator* loc )
17
:
AthReentrantAlgorithm
(name, loc) {}
18
19
20
StatusCode
HitDecoratorAlg::initialize
() {
21
ATH_MSG_INFO
(
"Initializing "
<< name());
22
23
// Initialize EventInfo/vertex/beamspot keys
24
if
(!
m_eventInfoKey
.empty() && !
m_verticesKey
.empty()) {
25
ATH_MSG_ERROR
(
"Cannot use multiple Vertex position sources for the local coordinates calculation"
);
26
return
StatusCode::FAILURE;
27
}
else
if
(!
m_eventInfoKey
.empty()) {
28
ATH_MSG_DEBUG
(
"Calculating local coordinates w.r.t. EventInfo Beamspot"
);
29
}
else
if
(!
m_verticesKey
.empty()) {
30
ATH_MSG_DEBUG
(
"Calculating local coordinates w.r.t. Primary Vertex"
);
31
}
else
{
32
ATH_MSG_DEBUG
(
"Calculating local coordinates w.r.t. detector origin (same coordinates)"
);
33
}
34
35
ATH_CHECK
(
m_eventInfoKey
.initialize(
SG::AllowEmpty
));
36
ATH_CHECK
(
m_verticesKey
.initialize(
SG::AllowEmpty
));
37
38
39
// Initialize hit keys
40
ATH_CHECK
(
m_HitContainerKey
.initialize());
41
ATH_CHECK
(
m_OutputHitXKey
.initialize());
42
ATH_CHECK
(
m_OutputHitYKey
.initialize());
43
ATH_CHECK
(
m_OutputHitZKey
.initialize());
44
45
return
StatusCode::SUCCESS;
46
}
47
48
49
StatusCode
HitDecoratorAlg::execute
(
const
EventContext& ctx)
const
{
50
ATH_MSG_DEBUG
(
"Executing "
<< name());
51
52
// Get event vertex
53
ROOT::Math::XYZVector vtx;
54
ATH_CHECK
(
getEventVertex
(ctx, vtx));
55
56
// Read out hits
57
SG::ReadHandle<xAOD::TrackMeasurementValidationContainer>
hits (
m_HitContainerKey
, ctx);
58
if
(!hits.isValid()) {
59
ATH_MSG_ERROR
(
"Failed to retrieve hit container with key "
<<
m_HitContainerKey
.key());
60
return
StatusCode::FAILURE;
61
}
62
63
// Set up hit decorators
64
SG::WriteDecorHandle<xAOD::TrackMeasurementValidationContainer, float>
correctedHitX (
m_OutputHitXKey
, ctx);
65
SG::WriteDecorHandle<xAOD::TrackMeasurementValidationContainer, float>
correctedHitY (
m_OutputHitYKey
, ctx);
66
SG::WriteDecorHandle<xAOD::TrackMeasurementValidationContainer, float>
correctedHitZ (
m_OutputHitZKey
, ctx);
67
68
// Calculate relative hit position to the vertex and decorate it to hits container
69
for
(
const
xAOD::TrackMeasurementValidation
*
hit
: *hits) {
70
correctedHitX(*
hit
) =
hit
->globalX() - vtx.X();
71
correctedHitY(*
hit
) =
hit
->globalY() - vtx.Y();
72
correctedHitZ(*
hit
) =
hit
->globalZ() - vtx.Z();
73
}
74
75
return
StatusCode::SUCCESS;
76
}
77
78
79
StatusCode
HitDecoratorAlg::getEventVertex
(
const
EventContext& ctx, ROOT::Math::XYZVector& vtx)
const
{
80
vtx.SetXYZ(0, 0, 0);
81
82
if
(!
m_eventInfoKey
.empty()) {
83
// Read out event info
84
SG::ReadHandle<xAOD::EventInfo>
eventInfoHandle(
m_eventInfoKey
, ctx);
85
if
(!eventInfoHandle.
isValid
()) {
86
ATH_MSG_ERROR
(
"Failed to retrieve event info container with key "
<<
m_eventInfoKey
.key());
87
return
StatusCode::FAILURE;
88
}
89
90
vtx.SetXYZ(
91
eventInfoHandle->beamPosX(),
92
eventInfoHandle->beamPosY(),
93
eventInfoHandle->beamPosZ()
94
);
95
96
}
else
if
(!
m_verticesKey
.empty()) {
97
// Read out vertices collection
98
SG::ReadHandle<xAOD::VertexContainer>
verticesHandle(
m_verticesKey
, ctx);
99
if
(!verticesHandle.
isValid
()) {
100
ATH_MSG_ERROR
(
"Failed to retrieve vertices container with key "
<<
m_verticesKey
.key());
101
return
StatusCode::FAILURE;
102
}
103
104
if
(verticesHandle->empty()) {
105
ATH_MSG_ERROR
(
"Empty primary vertices container"
);
106
return
StatusCode::FAILURE;
107
}
108
109
const
xAOD::Vertex
* pv =
nullptr
;
110
for
(
const
xAOD::Vertex
*vertex : *verticesHandle) {
111
if
(vertex->vertexType() ==
xAOD::VxType::PriVtx
) {
112
pv = vertex;
113
break
;
114
}
115
}
116
// If no PV was found, fallback to the beamspot (should be the first vertex in the collection)
117
if
(!pv) pv = verticesHandle->front();
118
119
vtx.SetXYZ(
120
pv->x(),
121
pv->y(),
122
pv->z()
123
);
124
}
125
126
return
StatusCode::SUCCESS;
127
}
128
}
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_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
HitDecoratorAlg.h
hit
bool hit(const Container &ids, int pdgId)
Definition
JetIRCSafeLabelTool.cxx:64
ReadDecorHandle.h
Handle class for reading a decoration on an object.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
FlavorTagDiscriminants::HitDecoratorAlg::HitDecoratorAlg
HitDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
HitDecoratorAlg.cxx:15
FlavorTagDiscriminants::HitDecoratorAlg::m_verticesKey
SG::ReadHandleKey< xAOD::VertexContainer > m_verticesKey
Definition
HitDecoratorAlg.h:56
FlavorTagDiscriminants::HitDecoratorAlg::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition
HitDecoratorAlg.h:59
FlavorTagDiscriminants::HitDecoratorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
HitDecoratorAlg.cxx:49
FlavorTagDiscriminants::HitDecoratorAlg::m_OutputHitXKey
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_OutputHitXKey
Definition
HitDecoratorAlg.h:47
FlavorTagDiscriminants::HitDecoratorAlg::m_OutputHitZKey
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_OutputHitZKey
Definition
HitDecoratorAlg.h:53
FlavorTagDiscriminants::HitDecoratorAlg::getEventVertex
StatusCode getEventVertex(const EventContext &ctx, ROOT::Math::XYZVector &vtx) const
Definition
HitDecoratorAlg.cxx:79
FlavorTagDiscriminants::HitDecoratorAlg::m_HitContainerKey
SG::ReadHandleKey< xAOD::TrackMeasurementValidationContainer > m_HitContainerKey
Definition
HitDecoratorAlg.h:43
FlavorTagDiscriminants::HitDecoratorAlg::m_OutputHitYKey
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_OutputHitYKey
Definition
HitDecoratorAlg.h:50
FlavorTagDiscriminants::HitDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition
HitDecoratorAlg.cxx:20
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
FlavorTagDiscriminants
Definition
CaloChargedFlowDecoratorAlg.h:15
SG::AllowEmpty
@ AllowEmpty
Definition
StoreGate/StoreGate/VarHandleKey.h:27
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition
TrackingPrimitives.h:590
xAOD::TrackMeasurementValidation
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version:
Definition
TrackMeasurementValidation.h:13
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