ATLAS Offline Software
Loading...
Searching...
No Matches
HitBeamSpotDataDecoratorAlg.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
13
14
15namespace FlavorTagDiscriminants {
16
17HitBeamSpotDataDecoratorAlg::HitBeamSpotDataDecoratorAlg(const std::string& name, ISvcLocator* loc)
18 : AthReentrantAlgorithm(name, loc) {}
19
20
22 ATH_MSG_INFO("Initializing " << name());
23
24 // BS conditions key
25 ATH_CHECK(m_beamSpotKey.initialize());
26
27 // Initialize hit keys
28 ATH_CHECK(m_HitContainerKey.initialize());
29 ATH_CHECK(m_OutputHitXKey.initialize());
30 ATH_CHECK(m_OutputHitYKey.initialize());
31 ATH_CHECK(m_OutputHitZKey.initialize());
32
33 return StatusCode::SUCCESS;
34}
35
36
37StatusCode HitBeamSpotDataDecoratorAlg::execute(const EventContext& ctx) const {
38 ATH_MSG_DEBUG("Executing " << name());
39
40 // Get event vertex
41 ROOT::Math::XYZVector vtx;
42 ATH_CHECK(getEventVertex(ctx, vtx));
43
44 // Read out hits
46 if(!hits.isValid()) {
47 ATH_MSG_ERROR("Failed to retrieve hit container with key " << m_HitContainerKey.key());
48 return StatusCode::FAILURE;
49 }
50
51 // Set up hit decorators
55
56 // Calculate relative hit position to the vertex and decorate it to hits container
57 for(const xAOD::TrackMeasurementValidation* hit : *hits) {
58 correctedHitX(*hit) = hit->globalX() - vtx.X();
59 correctedHitY(*hit) = hit->globalY() - vtx.Y();
60 correctedHitZ(*hit) = hit->globalZ() - vtx.Z();
61 }
62
63 return StatusCode::SUCCESS;
64}
65
66
67StatusCode HitBeamSpotDataDecoratorAlg::getEventVertex(const EventContext& ctx, ROOT::Math::XYZVector& vtx) const {
68 // Read out beamspot from conditions
70 if(!beamSpotHandle.isValid()) {
71 ATH_MSG_ERROR("Failed to retrieve BeamSpot conditions data with key " << m_beamSpotKey.key());
72 return StatusCode::FAILURE;
73 }
74 const InDet::BeamSpotData* beamSpot = *beamSpotHandle;
75
76 vtx.SetXYZ(
77 beamSpot->beamPos()[Amg::x],
78 beamSpot->beamPos()[Amg::y],
79 beamSpot->beamPos()[Amg::z]
80 );
81
82 return StatusCode::SUCCESS;
83}
84
85}
#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.
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_OutputHitZKey
HitBeamSpotDataDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_OutputHitYKey
SG::ReadHandleKey< xAOD::TrackMeasurementValidationContainer > m_HitContainerKey
StatusCode getEventVertex(const EventContext &ctx, ROOT::Math::XYZVector &vtx) const
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_OutputHitXKey
Handle class for adding a decoration to an object.
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version: