ATLAS Offline Software
Loading...
Searching...
No Matches
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
7
8// Read and write handles
11
12
13namespace FlavorTagDiscriminants {
14
16 const std::string& name, ISvcLocator* loc )
17 : AthReentrantAlgorithm(name, loc) {}
18
19
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
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
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
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
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
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
Handle class for adding a decoration to an object.
An algorithm that can be simultaneously executed in multiple threads.
HitDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< xAOD::VertexContainer > m_verticesKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_OutputHitXKey
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_OutputHitZKey
StatusCode getEventVertex(const EventContext &ctx, ROOT::Math::XYZVector &vtx) const
SG::ReadHandleKey< xAOD::TrackMeasurementValidationContainer > m_HitContainerKey
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_OutputHitYKey
virtual StatusCode initialize() override
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
@ PriVtx
Primary vertex.
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.