ATLAS Offline Software
EventInfoOverlay.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "EventInfoOverlay.h"
8 
10 
11 
12 namespace xAODMaker
13 {
14 
15 
16 EventInfoOverlay::EventInfoOverlay(const std::string &name, ISvcLocator *pSvcLocator)
17  : AthReentrantAlgorithm(name, pSvcLocator) {}
18 
19 
21 {
22  ATH_MSG_DEBUG("Initializing...");
23 
24  ATH_MSG_INFO("Data overlay: " << m_dataOverlay.value());
25  if (m_validateBeamSpot.value()) {
26  ATH_MSG_INFO("Will validate beam spot size");
27  }
28 
29  // Check and initialize keys
30 #if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
32 #endif
33 
35  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgInputKey);
37  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalInputKey);
39  ATH_MSG_VERBOSE("Initialized WriteHandleKey: " << m_outputKey);
40 
41  return StatusCode::SUCCESS;
42 }
43 
44 
45 StatusCode EventInfoOverlay::execute(const EventContext& ctx) const
46 {
47  ATH_MSG_DEBUG("execute() begin");
48 
50  if (!bkgEvent.isValid()) {
51  ATH_MSG_ERROR("Could not get background xAOD::EventInfo " << bkgEvent.name() << " from store " << bkgEvent.store());
52  return StatusCode::FAILURE;
53  }
54  ATH_MSG_DEBUG("Found background xAOD::EventInfo " << bkgEvent.name() << " in store " << bkgEvent.store());
55 
57  if (!signalEvent.isValid()) {
58  ATH_MSG_ERROR("Could not get signal xAOD::EventInfo " << signalEvent.name() << " from store " << signalEvent.store());
59  return StatusCode::FAILURE;
60  }
61  ATH_MSG_DEBUG("Found signal xAOD::EventInfo " << signalEvent.name() << " in store " << signalEvent.store());
62 
63  auto outputEvent = std::make_unique<xAOD::EventInfo>();
64  auto outputEventAux = std::make_unique<xAOD::EventAuxInfo>();
65  outputEvent->setStore (outputEventAux.get());
66 
67  // Copy the eventInfo data from background event
68  *outputEvent = *bkgEvent;
69  // Remove all subevents for now
70  outputEvent->clearSubEvents();
71 
72  if (!m_dataOverlay.value()) {
73  outputEvent->setEventNumber(signalEvent->eventNumber());
74  }
75 
76  // Propagate MC metadata
77  if (signalEvent->mcChannelNumber() == 0) {
78  if (m_mcChannelNumber.value() != 0) {
79  ATH_MSG_WARNING("Signal mcChannelNumber is 0, setting it to " << m_mcChannelNumber.value());
80  outputEvent->setMCChannelNumber(m_mcChannelNumber.value());
81  } else {
82  ATH_MSG_WARNING("Signal mcChannelNumber is 0");
83  outputEvent->setMCChannelNumber(signalEvent->mcChannelNumber());
84  }
85  } else {
86  if (m_mcChannelNumber.value() != 0 && signalEvent->mcChannelNumber() != m_mcChannelNumber.value()) {
87  ATH_MSG_WARNING("Signal mcChannelNumber (" << signalEvent->mcChannelNumber()
88  << ") and provided mcChannelNumber (" << m_mcChannelNumber.value() << ") do not match.");
89  }
90  outputEvent->setMCChannelNumber(signalEvent->mcChannelNumber());
91  }
92 
93  if (signalEvent->mcEventNumber() == 0) {
94  if (signalEvent->eventNumber() != 0) {
95  ATH_MSG_WARNING("Signal mcEventNumber is 0, setting it to match the eventNumber (" << signalEvent->eventNumber() << ")");
96  outputEvent->setMCEventNumber(signalEvent->eventNumber());
97  } else {
98  ATH_MSG_ERROR("Signal eventNumber and mcEventNumber are 0");
99  return StatusCode::FAILURE;
100  }
101  } else {
102  outputEvent->setMCEventNumber(signalEvent->mcEventNumber());
103  }
104 
105  if (signalEvent->mcEventWeights().empty()) {
106  ATH_MSG_ERROR("Signal mcEventWeights are empty. This should not happen.");
107  return StatusCode::FAILURE;
108  }
109  outputEvent->setMCEventWeights(signalEvent->mcEventWeights());
110 
111  // MC+MC overlay should always be marked as simulation
112  if (!m_dataOverlay.value()) {
113  outputEvent->setEventTypeBitmask(xAOD::EventInfo::IS_SIMULATION);
114  }
115 
116  // Propagate core event flags
117  outputEvent->setEventFlags(xAOD::EventInfo::Core,
118  signalEvent->eventFlags(xAOD::EventInfo::Core)
119  | bkgEvent->eventFlags(xAOD::EventInfo::Core) );
120  outputEvent->setErrorState(xAOD::EventInfo::Core,
122  bkgEvent->errorState(xAOD::EventInfo::Core)));
123 
124  // But clear other detector flags.
125  // They'll get set again during reconstruction, if appropriate.
126  // (For now, do this only for simulation.)
127  if (!m_dataOverlay.value()) {
128  for (unsigned idet = 0; idet < xAOD::EventInfo::nDets; ++idet) {
129  auto det = static_cast<xAOD::EventInfo::EventFlagSubDet> (idet);
130  if (det != xAOD::EventInfo::Core) {
131  outputEvent->setEventFlags (det, 0);
132  outputEvent->setErrorState (det, xAOD::EventInfo::NotSet);
133  }
134  }
135  }
136 
137  // Ensure correct beam spot info
138 #if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
139  if (m_validateBeamSpot.value()) {
140  if (std::abs(signalEvent->beamPosSigmaZ() - bkgEvent->beamPosSigmaZ()) > 1e-5f) {
141  ATH_MSG_ERROR("Beam spot size does not match between signal and background events ("
142  << signalEvent->beamPosSigmaZ() << " vs " << bkgEvent->beamPosSigmaZ() << ")");
143  return StatusCode::FAILURE;
144  }
145  } else {
147  if (!beamSpotHandle.isValid()) {
148  ATH_MSG_ERROR("Beam spot information not valid");
149  return StatusCode::FAILURE;
150  }
151  outputEvent->setBeamPos( beamSpotHandle->beamPos()[ Amg::x ],
152  beamSpotHandle->beamPos()[ Amg::y ],
153  beamSpotHandle->beamPos()[ Amg::z ] );
154  outputEvent->setBeamPosSigma( beamSpotHandle->beamSigma( 0 ),
155  beamSpotHandle->beamSigma( 1 ),
156  beamSpotHandle->beamSigma( 2 ) );
157  outputEvent->setBeamPosSigmaXY( beamSpotHandle->beamSigmaXY() );
158  outputEvent->setBeamTiltXZ( beamSpotHandle->beamTilt( 0 ) );
159  outputEvent->setBeamTiltYZ( beamSpotHandle->beamTilt( 1 ) );
160  outputEvent->setBeamStatus( beamSpotHandle->beamStatus() );
161  }
162 #endif
163 
164  // Creating output timings container
166  ATH_CHECK(outputEventH.record(std::move(outputEvent), std::move(outputEventAux)));
167  ATH_MSG_DEBUG("Recorded output xAOD::EventInfo " << outputEventH.name() << " in store " << outputEventH.store());
168 
169  ATH_MSG_DEBUG("execute() end");
170  return StatusCode::SUCCESS;
171 }
172 
173 
174 } // namespace xAODMaker
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
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.
TRTCalib_Extractor.det
det
Definition: TRTCalib_Extractor.py:36
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::EventInfoOverlay::m_signalInputKey
SG::ReadHandleKey< xAOD::EventInfo > m_signalInputKey
Definition: EventInfoOverlay.h:43
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
xAODMaker::EventInfoOverlay::m_beamSpotKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Definition: EventInfoOverlay.h:39
xAOD::EventInfo_v1::clearSubEvents
void clearSubEvents()
Clear all the currently held sub-events.
Definition: EventInfo_v1.cxx:647
Amg::y
@ y
Definition: GeoPrimitives.h:35
xAOD::EventInfo_v1::NotSet
@ NotSet
The flag was not set to anything.
Definition: EventInfo_v1.h:347
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
xAODMaker
Definition: StoreGateSvc.h:72
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition: EventInfo_v1.h:151
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.
Amg::z
@ z
Definition: GeoPrimitives.h:36
xAODMaker::EventInfoOverlay::m_bkgInputKey
SG::ReadHandleKey< xAOD::EventInfo > m_bkgInputKey
Definition: EventInfoOverlay.h:42
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:376
xAODMaker::EventInfoOverlay::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: EventInfoOverlay.cxx:45
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
hist_file_dump.f
f
Definition: hist_file_dump.py:135
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
xAODMaker::EventInfoOverlay::EventInfoOverlay
EventInfoOverlay(const std::string &name, ISvcLocator *pSvcLocator)
Definition: EventInfoOverlay.cxx:16
xAODMaker::EventInfoOverlay::m_mcChannelNumber
Gaudi::Property< uint32_t > m_mcChannelNumber
Definition: EventInfoOverlay.h:48
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAODMaker::EventInfoOverlay::m_outputKey
SG::WriteHandleKey< xAOD::EventInfo > m_outputKey
Definition: EventInfoOverlay.h:44
EventAuxInfo.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
xAODMaker::EventInfoOverlay::initialize
virtual StatusCode initialize() override
Definition: EventInfoOverlay.cxx:20
xAOD::EventInfo_v1::EventFlagSubDet
EventFlagSubDet
Sub-detector types for which we store event-level flags.
Definition: EventInfo_v1.h:331
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
xAOD::EventInfo_v1::eventFlags
uint32_t eventFlags(EventFlagSubDet subDet) const
Get the event flags for a particular sub-detector.
Definition: EventInfo_v1.cxx:697
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::nDets
@ nDets
Number of sub-detector type in this enumeration.
Definition: EventInfo_v1.h:342
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::EventInfo_v1::errorState
EventFlagErrorState errorState(EventFlagSubDet subDet) const
Get the error state for a particular sub-detector.
Definition: EventInfo_v1.cxx:817
xAODMaker::EventInfoOverlay::m_dataOverlay
Gaudi::Property< bool > m_dataOverlay
Definition: EventInfoOverlay.h:46
EventInfoOverlay.h
xAODMaker::EventInfoOverlay::m_validateBeamSpot
Gaudi::Property< bool > m_validateBeamSpot
Definition: EventInfoOverlay.h:47
xAOD::EventInfo_v1::Core
@ Core
Core flags describing the event.
Definition: EventInfo_v1.h:339
xAOD::EventInfo_v1::mcEventNumber
uint64_t mcEventNumber() const
The MC generator's event number.