ATLAS Offline Software
EventInfoUpdateFromContextAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 
10 
11 
12 namespace xAODMaker
13 {
14 
15  EventInfoUpdateFromContextAlg::EventInfoUpdateFromContextAlg(const std::string &name, ISvcLocator *pSvcLocator)
16  : AthReentrantAlgorithm(name, pSvcLocator) {}
17 
19  {
20  ATH_MSG_DEBUG("Initializing...");
21 
22  // Check and initialize keys
23 #if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
25 #endif
26 
28  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalInputKey);
30  ATH_MSG_VERBOSE("Initialized WriteHandleKey: " << m_outputKey);
31 
32  return StatusCode::SUCCESS;
33  }
34 
35 
36  StatusCode EventInfoUpdateFromContextAlg::execute(const EventContext& ctx) const
37  {
38  ATH_MSG_DEBUG("execute() begin");
39 
41  if (!signalEvent.isValid()) {
42  ATH_MSG_ERROR("Could not get signal xAOD::EventInfo " << signalEvent.name() << " from store " << signalEvent.store());
43  return StatusCode::FAILURE;
44  }
45  float sig_beamPosSigmaZ=-1;
46  try {
47  sig_beamPosSigmaZ=signalEvent->beamPosSigmaZ();
48  }
49  catch(const SG::ExcBadAuxVar&) {
50  }
51 
52  ATH_MSG_DEBUG("Found signal xAOD::EventInfo " << signalEvent.name() << " in store " << signalEvent.store()<<" : "<<*signalEvent<<" beamspot size z="<<sig_beamPosSigmaZ);
53 
54  // Creating output timings container
56  ATH_CHECK(outputEvent.record(std::make_unique<xAOD::EventInfo>(), std::make_unique<xAOD::EventAuxInfo>()));
57  if (!outputEvent.isValid()) {
58  ATH_MSG_ERROR("Could not record output xAOD::EventInfo " << outputEvent.name() << " to store " << outputEvent.store());
59  return StatusCode::FAILURE;
60  }
61  ATH_MSG_DEBUG("Recorded output xAOD::EventInfo " << outputEvent.name() << " in store " << outputEvent.store());
62 
63  // Copy the eventInfo data from background event
64  *outputEvent = *signalEvent;
65 
66  //Update run number, event number, lumi block and timestamp from EventContext
67  outputEvent->setRunNumber( ctx.eventID().run_number() );
68  outputEvent->setEventNumber( ctx.eventID().event_number() );
69  outputEvent->setLumiBlock( ctx.eventID().lumi_block() );
70  outputEvent->setTimeStamp( ctx.eventID().time_stamp() );
71 
72  // Propagate MC metadata
73  if (outputEvent->mcChannelNumber() == 0) {
74  if (m_mcChannelNumber.value() != 0) {
75  ATH_MSG_WARNING("Input mcChannelNumber is 0, setting it to " << m_mcChannelNumber.value());
76  outputEvent->setMCChannelNumber(m_mcChannelNumber.value());
77  } else {
78  ATH_MSG_WARNING("Input mcChannelNumber is 0");
79  }
80  } else {
81  if (m_mcChannelNumber.value() != 0 && signalEvent->mcChannelNumber() != m_mcChannelNumber.value()) {
82  ATH_MSG_WARNING("Input mcChannelNumber (" << signalEvent->mcChannelNumber()
83  << ") and provided mcChannelNumber (" << m_mcChannelNumber.value() << ") do not match.");
84  }
85  }
86 
87  if (signalEvent->mcEventNumber() == 0) {
88  if (signalEvent->eventNumber() != 0) {
89  ATH_MSG_WARNING("Input mcEventNumber is 0, setting it to match the eventNumber (" << signalEvent->eventNumber() << ")");
90  outputEvent->setMCEventNumber(signalEvent->eventNumber());
91  } else {
92  ATH_MSG_ERROR("Input eventNumber and mcEventNumber are 0");
93  return StatusCode::FAILURE;
94  }
95  }
96 
97  if (signalEvent->mcEventWeights().empty()) {
98  ATH_MSG_ERROR("Input mcEventWeights are empty. This should not happen.");
99  return StatusCode::FAILURE;
100  }
101  // This is sometimes marked as a decoration in the source, meaning
102  // it won't get copied by the assignment above. Make sure it
103  // gets copied.
104  outputEvent->setMCEventWeights (signalEvent->mcEventWeights());
105 
106  // Ensure correct beam spot info
107 #if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
109  if (!beamSpotHandle.isValid()) {
110  ATH_MSG_ERROR("Beam spot information not valid");
111  return StatusCode::FAILURE;
112  }
113  outputEvent->setBeamPos( beamSpotHandle->beamPos()[ Amg::x ],
114  beamSpotHandle->beamPos()[ Amg::y ],
115  beamSpotHandle->beamPos()[ Amg::z ] );
116  outputEvent->setBeamPosSigma( beamSpotHandle->beamSigma( 0 ),
117  beamSpotHandle->beamSigma( 1 ),
118  beamSpotHandle->beamSigma( 2 ) );
119  outputEvent->setBeamPosSigmaXY( beamSpotHandle->beamSigmaXY() );
120  outputEvent->setBeamTiltXZ( beamSpotHandle->beamTilt( 0 ) );
121  outputEvent->setBeamTiltYZ( beamSpotHandle->beamTilt( 1 ) );
122  outputEvent->setBeamStatus( beamSpotHandle->beamStatus() );
123 #endif
124 
125  ATH_MSG_DEBUG("Output xAOD::EventInfo " << outputEvent.name() << " : " << *outputEvent<<" beamspot size z="<<outputEvent->beamPosSigmaZ());
126  ATH_MSG_DEBUG("execute() end");
127  return StatusCode::SUCCESS;
128  }
129 
130 
131 } // namespace xAODMaker
xAODMaker::EventInfoUpdateFromContextAlg::EventInfoUpdateFromContextAlg
EventInfoUpdateFromContextAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: EventInfoUpdateFromContextAlg.cxx:15
xAOD::EventInfo_v1::setEventNumber
void setEventNumber(uint64_t value)
Set the current event's event number.
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
xAOD::EventInfo_v1::mcEventWeights
const std::vector< float > & mcEventWeights() const
The weights of all the MC events used in the simulation.
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
xAODMaker::EventInfoUpdateFromContextAlg::m_mcChannelNumber
Gaudi::Property< uint32_t > m_mcChannelNumber
Definition: EventInfoUpdateFromContextAlg.h:48
xAODMaker::EventInfoUpdateFromContextAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: EventInfoUpdateFromContextAlg.cxx:36
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
xAODMaker
Definition: StoreGateSvc.h:72
xAODMaker::EventInfoUpdateFromContextAlg::m_outputKey
SG::WriteHandleKey< xAOD::EventInfo > m_outputKey
Definition: EventInfoUpdateFromContextAlg.h:46
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
xAOD::EventInfo_v1::mcChannelNumber
uint32_t mcChannelNumber() const
The MC generator's channel number.
xAODMaker::EventInfoUpdateFromContextAlg::m_beamSpotKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Definition: EventInfoUpdateFromContextAlg.h:42
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.
Amg::z
@ z
Definition: GeoPrimitives.h:36
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::EventInfo_v1::setMCEventNumber
void setMCEventNumber(uint64_t value)
Set the MC generator's event number.
SG::ExcBadAuxVar
Exception — Attempt to retrieve nonexistent aux data item.
Definition: Control/AthContainers/AthContainers/exceptions.h:59
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:376
xAOD::EventInfo_v1::beamPosSigmaZ
float beamPosSigmaZ() const
The length of the beam spot in the Z direction.
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
xAOD::EventInfo_v1::setTimeStamp
void setTimeStamp(uint32_t value)
Set the POSIX time of the event.
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?
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:221
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
xAOD::EventInfo_v1::setMCChannelNumber
void setMCChannelNumber(uint32_t value)
Set the MC generator's channel number.
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.
EventInfoUpdateFromContextAlg.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::EventInfo_v1::setRunNumber
void setRunNumber(uint32_t value)
Set the current event's run number.
xAOD::EventInfo_v1::setBeamTiltXZ
void setBeamTiltXZ(float value)
Set the beam's tilt in radians in XZ.
xAODMaker::EventInfoUpdateFromContextAlg::initialize
virtual StatusCode initialize() override
Definition: EventInfoUpdateFromContextAlg.cxx:18
xAODMaker::EventInfoUpdateFromContextAlg::m_signalInputKey
SG::ReadHandleKey< xAOD::EventInfo > m_signalInputKey
Definition: EventInfoUpdateFromContextAlg.h:45
xAOD::EventInfo_v1::setLumiBlock
void setLumiBlock(uint32_t value)
Set the current event's luminosity block number.
xAOD::EventInfo_v1::mcEventNumber
uint64_t mcEventNumber() const
The MC generator's event number.
xAOD::EventInfo_v1::setMCEventWeights
void setMCEventWeights(const std::vector< float > &value)
Set the weights of all the MC events used in the simulation.