ATLAS Offline Software
BeamSpotFixerAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 #include <StoreGate/ReadHandle.h>
11 
12 #include "BeamSpotFixerAlg.h"
13 
14 namespace Simulation
15 {
16 
17  BeamSpotFixerAlg::BeamSpotFixerAlg( const std::string& name, ISvcLocator* pSvcLocator )
18  : AthReentrantAlgorithm( name, pSvcLocator )
19  {
20  }
21 
24  {
26 
28  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_inputKey);
30  ATH_MSG_VERBOSE("Initialized WriteHandleKey: " << m_outputKey);
31 
32  return StatusCode::SUCCESS;
33  }
34 
35  StatusCode BeamSpotFixerAlg::execute(const EventContext& ctx) const
36  {
38  if (!beamSpotHandle.isValid()) {
39  ATH_MSG_ERROR("Beam spot information not valid");
40  return StatusCode::FAILURE;
41  }
42 
43  SG::ReadHandle<xAOD::EventInfo> inputEventInfo(m_inputKey, ctx);
44  if (!inputEventInfo.isValid()) {
45  ATH_MSG_ERROR("Could not get input xAOD::EventInfo " << inputEventInfo.name() << " from store " << inputEventInfo.store());
46  return StatusCode::FAILURE;
47  }
48  ATH_MSG_DEBUG("Found input xAOD::EventInfo " << inputEventInfo.name() << " in store " << inputEventInfo.store());
49 
51  ATH_CHECK(eventInfo.record(std::make_unique<xAOD::EventInfo>(), std::make_unique<xAOD::EventAuxInfo>()));
52  if (!eventInfo.isValid()) {
53  ATH_MSG_ERROR("Could not record output xAOD::EventInfo " << eventInfo.name() << " to store " << eventInfo.store());
54  return StatusCode::FAILURE;
55  }
56  ATH_MSG_DEBUG("Recorded output xAOD::EventInfo " << eventInfo.name() << " in store " << eventInfo.store());
57 
58  // Copy the eventInfo data
59  *eventInfo = *inputEventInfo;
60 
61  // Copy the beamspot info
62  eventInfo->setBeamPos( beamSpotHandle->beamPos()[ Amg::x ],
63  beamSpotHandle->beamPos()[ Amg::y ],
64  beamSpotHandle->beamPos()[ Amg::z ] );
65  eventInfo->setBeamPosSigma( beamSpotHandle->beamSigma( 0 ),
66  beamSpotHandle->beamSigma( 1 ),
67  beamSpotHandle->beamSigma( 2 ) );
68  eventInfo->setBeamPosSigmaXY( beamSpotHandle->beamSigmaXY() );
69  eventInfo->setBeamTiltXZ( beamSpotHandle->beamTilt( 0 ) );
70  eventInfo->setBeamTiltYZ( beamSpotHandle->beamTilt( 1 ) );
71  eventInfo->setBeamStatus( beamSpotHandle->beamStatus() );
72 
73  return StatusCode::SUCCESS;
74  }
75 
76 } // namespace Simulation
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
xAOD::EventInfo_v1::setBeamPos
void setBeamPos(float x, float y, float z)
Set the beam spot position.
Definition: EventInfo_v1.cxx:916
Amg::y
@ y
Definition: GeoPrimitives.h:35
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::EventInfo_v1::setBeamPosSigma
void setBeamPosSigma(float x, float y, float z)
Set the size of the beam spot.
Definition: EventInfo_v1.cxx:935
ReadCondHandle.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
xAOD::EventInfo_v1::setBeamTiltYZ
void setBeamTiltYZ(float value)
Set the beam's tilt in radians in YZ.
xAOD::EventInfo_v1::setBeamStatus
void setBeamStatus(uint32_t value)
Set the beam spot's status word.
WriteHandle.h
Handle class for recording to StoreGate.
Amg::z
@ z
Definition: GeoPrimitives.h:36
Simulation::BeamSpotFixerAlg::m_inputKey
SG::ReadHandleKey< xAOD::EventInfo > m_inputKey
Definition: BeamSpotFixerAlg.h:44
BeamSpotFixerAlg.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Amg::x
@ x
Definition: GeoPrimitives.h:34
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition: StoreGate/src/VarHandleBase.cxx:379
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
Simulation::BeamSpotFixerAlg::BeamSpotFixerAlg
BeamSpotFixerAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: BeamSpotFixerAlg.cxx:17
xAOD::EventInfo_v1::setBeamPosSigmaXY
void setBeamPosSigmaXY(float value)
Set the beam spot shape's X-Y correlation.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Simulation::BeamSpotFixerAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Athena algorithm's interface method execute()
Definition: BeamSpotFixerAlg.cxx:35
Simulation::BeamSpotFixerAlg::initialize
virtual StatusCode initialize() override final
Athena algorithm's interface method initialize()
Definition: BeamSpotFixerAlg.cxx:23
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
EventAuxInfo.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
Simulation::BeamSpotFixerAlg::m_outputKey
SG::WriteHandleKey< xAOD::EventInfo > m_outputKey
Definition: BeamSpotFixerAlg.h:45
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
xAOD::EventInfo_v1::setBeamTiltXZ
void setBeamTiltXZ(float value)
Set the beam's tilt in radians in XZ.
Simulation
Definition: BeamEffectsAlg.cxx:21
ReadHandle.h
Handle class for reading from StoreGate.
Simulation::BeamSpotFixerAlg::m_beamSpotKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Definition: BeamSpotFixerAlg.h:42