ATLAS Offline Software
Loading...
Searching...
No Matches
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
12namespace 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)
24 ATH_CHECK(m_beamSpotKey.initialize());
25#endif
26
27 ATH_CHECK( m_signalInputKey.initialize() );
28 ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalInputKey);
29 ATH_CHECK( m_outputKey.initialize() );
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
An algorithm to produce an updated final xAOD::EventInfo with possible run number,...
An algorithm that can be simultaneously executed in multiple threads.
Exception — Attempt to retrieve nonexistent aux data item.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::string store() const
Return the name of the store holding the object we are proxying.
const std::string & name() const
Return the StoreGate ID for the referenced object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
EventInfoUpdateFromContextAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
SG::ReadHandleKey< xAOD::EventInfo > m_signalInputKey
SG::WriteHandleKey< xAOD::EventInfo > m_outputKey