ATLAS Offline Software
Loading...
Searching...
No Matches
EventInfoOverlay.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "EventInfoOverlay.h"
8
10
11// For treatment of decorations that should be passed along
13
14namespace xAODMaker
15{
16
17
18EventInfoOverlay::EventInfoOverlay(const std::string &name, ISvcLocator *pSvcLocator)
19 : AthReentrantAlgorithm(name, pSvcLocator) {}
20
21
23{
24 ATH_MSG_DEBUG("Initializing...");
25
26 ATH_MSG_INFO("Data overlay: " << m_dataOverlay.value());
27 if (m_validateBeamSpot.value()) {
28 ATH_MSG_INFO("Will validate beam spot size");
29 }
30
31 // Check and initialize keys
32#if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
33 ATH_CHECK(m_beamSpotKey.initialize());
34#endif
35
36 ATH_CHECK( m_bkgInputKey.initialize(!m_bkgInputKey.key().empty()) );
37 ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgInputKey);
38 ATH_CHECK( m_signalInputKey.initialize() );
39 ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalInputKey);
40 ATH_CHECK( m_outputKey.initialize() );
41 ATH_MSG_VERBOSE("Initialized WriteHandleKey: " << m_outputKey);
42
43 return StatusCode::SUCCESS;
44}
45
46
47#if !defined(XAOD_ANALYSIS)
48 StatusCode EventInfoOverlay::decorationsToKeep(const xAOD::EventInfo* signalEvent, std::vector<std::string>& keep_ids) const
49 {
50 // Get the aux type registry in order to decode aux IDs
52
53 // Get the aux IDs from the signal event info; we need some of them
54 auto signalAIDs = signalEvent->getAuxIDs();
55 for (const auto id : signalAIDs) {
56 if (registry.getName(id).find("mcFilter") != std::string::npos) { // TODO This could be made configurable in future.
57 keep_ids.push_back(registry.getName(id));
58 }
59 }
60 return StatusCode::SUCCESS;
61 }
62#endif
63
64
65StatusCode EventInfoOverlay::execute(const EventContext& ctx) const
66{
67 ATH_MSG_DEBUG("execute() begin");
68
70 if (!bkgEvent.isValid()) {
71 ATH_MSG_ERROR("Could not get background xAOD::EventInfo " << bkgEvent.name() << " from store " << bkgEvent.store());
72 return StatusCode::FAILURE;
73 }
74 ATH_MSG_DEBUG("Found background xAOD::EventInfo " << bkgEvent.name() << " in store " << bkgEvent.store());
75
77 if (!signalEvent.isValid()) {
78 ATH_MSG_ERROR("Could not get signal xAOD::EventInfo " << signalEvent.name() << " from store " << signalEvent.store());
79 return StatusCode::FAILURE;
80 }
81 ATH_MSG_DEBUG("Found signal xAOD::EventInfo " << signalEvent.name() << " in store " << signalEvent.store());
82
83 std::vector<std::string> keep_ids;
84#if !defined(XAOD_ANALYSIS)
85 ATH_CHECK(decorationsToKeep(signalEvent.cptr(), keep_ids));
86#endif
87
88 auto outputEvent = std::make_unique<xAOD::EventInfo>();
89 auto outputEventAux = std::make_unique<xAOD::EventAuxInfo>();
90 outputEvent->setStore (outputEventAux.get());
91
92 // Copy the eventInfo data from background event
93 *outputEvent = *bkgEvent;
94 // Remove all subevents for now
95 outputEvent->clearSubEvents();
96
97 if (!m_dataOverlay.value()) {
98 outputEvent->setEventNumber(signalEvent->eventNumber());
99 }
100
101 // Propagate MC metadata
102 if (signalEvent->mcChannelNumber() == 0) {
103 if (m_mcChannelNumber.value() != 0) {
104 ATH_MSG_WARNING("Signal mcChannelNumber is 0, setting it to " << m_mcChannelNumber.value());
105 outputEvent->setMCChannelNumber(m_mcChannelNumber.value());
106 } else {
107 ATH_MSG_WARNING("Signal mcChannelNumber is 0");
108 outputEvent->setMCChannelNumber(signalEvent->mcChannelNumber());
109 }
110 } else {
111 if (m_mcChannelNumber.value() != 0 && signalEvent->mcChannelNumber() != m_mcChannelNumber.value()) {
112 ATH_MSG_WARNING("Signal mcChannelNumber (" << signalEvent->mcChannelNumber()
113 << ") and provided mcChannelNumber (" << m_mcChannelNumber.value() << ") do not match.");
114 }
115 outputEvent->setMCChannelNumber(signalEvent->mcChannelNumber());
116 }
117
118 if (signalEvent->mcEventNumber() == 0) {
119 if (signalEvent->eventNumber() != 0) {
120 ATH_MSG_WARNING("Signal mcEventNumber is 0, setting it to match the eventNumber (" << signalEvent->eventNumber() << ")");
121 outputEvent->setMCEventNumber(signalEvent->eventNumber());
122 } else {
123 ATH_MSG_ERROR("Signal eventNumber and mcEventNumber are 0");
124 return StatusCode::FAILURE;
125 }
126 } else {
127 outputEvent->setMCEventNumber(signalEvent->mcEventNumber());
128 }
129
130 if (signalEvent->mcEventWeights().empty()) {
131 ATH_MSG_ERROR("Signal mcEventWeights are empty. This should not happen.");
132 return StatusCode::FAILURE;
133 }
134 outputEvent->setMCEventWeights(signalEvent->mcEventWeights());
135
136 // MC+MC overlay should always be marked as simulation
137 if (!m_dataOverlay.value()) {
138 outputEvent->setEventTypeBitmask(xAOD::EventInfo::IS_SIMULATION);
139 }
140
141 // Propagate core event flags
142 outputEvent->setEventFlags(xAOD::EventInfo::Core,
143 signalEvent->eventFlags(xAOD::EventInfo::Core)
144 | bkgEvent->eventFlags(xAOD::EventInfo::Core) );
145 outputEvent->setErrorState(xAOD::EventInfo::Core,
146 std::max(signalEvent->errorState(xAOD::EventInfo::Core),
147 bkgEvent->errorState(xAOD::EventInfo::Core)));
148
149 // But clear other detector flags.
150 // They'll get set again during reconstruction, if appropriate.
151 for (unsigned idet = 0; idet < xAOD::EventInfo::nDets; ++idet) {
152 auto det = static_cast<xAOD::EventInfo::EventFlagSubDet> (idet);
153 if (det != xAOD::EventInfo::Core) {
154 outputEvent->setEventFlags (det, 0);
155 outputEvent->setErrorState (det, xAOD::EventInfo::NotSet);
156 }
157 }
158
159 // Ensure correct beam spot info
160#if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
161 if (m_validateBeamSpot.value()) {
162 if (std::abs(signalEvent->beamPosSigmaZ() - bkgEvent->beamPosSigmaZ()) > 1e-5f) {
163 ATH_MSG_ERROR("Beam spot size does not match between signal and background events ("
164 << signalEvent->beamPosSigmaZ() << " vs " << bkgEvent->beamPosSigmaZ() << ")");
165 return StatusCode::FAILURE;
166 }
167 } else {
169 if (!beamSpotHandle.isValid()) {
170 ATH_MSG_ERROR("Beam spot information not valid");
171 return StatusCode::FAILURE;
172 }
173 outputEvent->setBeamPos( beamSpotHandle->beamPos()[ Amg::x ],
174 beamSpotHandle->beamPos()[ Amg::y ],
175 beamSpotHandle->beamPos()[ Amg::z ] );
176 outputEvent->setBeamPosSigma( beamSpotHandle->beamSigma( 0 ),
177 beamSpotHandle->beamSigma( 1 ),
178 beamSpotHandle->beamSigma( 2 ) );
179 outputEvent->setBeamPosSigmaXY( beamSpotHandle->beamSigmaXY() );
180 outputEvent->setBeamTiltXZ( beamSpotHandle->beamTilt( 0 ) );
181 outputEvent->setBeamTiltYZ( beamSpotHandle->beamTilt( 1 ) );
182 outputEvent->setBeamStatus( beamSpotHandle->beamStatus() );
183 }
184#endif
185
186 // Add decorations that are required
187 for (const std::string& id : keep_ids){
188 SG::ConstAccessor<float> origDecor(id);
189 SG::Accessor<float> filtDecor(id);
190 filtDecor(*outputEvent) = origDecor(*signalEvent);
191 }
192
193 // Creating output timings container
195 ATH_CHECK(outputEventH.record(std::move(outputEvent), std::move(outputEventAux)));
196 ATH_MSG_DEBUG("Recorded output xAOD::EventInfo " << outputEventH.name() << " in store " << outputEventH.store());
197
198 ATH_MSG_DEBUG("execute() end");
199 return StatusCode::SUCCESS;
200}
201
202
203} // namespace xAODMaker
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle mappings between names and auxid_t.
An algorithm to produce a proper final xAOD::EventInfo from signal and background ones.
An algorithm that can be simultaneously executed in multiple threads.
Helper class to provide type-safe access to aux data.
Handle mappings between names and auxid_t.
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Helper class to provide constant type-safe access to aux data.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
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.
Gaudi::Property< uint32_t > m_mcChannelNumber
SG::WriteHandleKey< xAOD::EventInfo > m_outputKey
EventInfoOverlay(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
SG::ReadHandleKey< xAOD::EventInfo > m_signalInputKey
Gaudi::Property< bool > m_validateBeamSpot
Gaudi::Property< bool > m_dataOverlay
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< xAOD::EventInfo > m_bkgInputKey
StatusCode decorationsToKeep(const xAOD::EventInfo *signalEvent, std::vector< std::string > &keep_ids) const
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
EventFlagSubDet
Sub-detector types for which we store event-level flags.
@ Core
Core flags describing the event.
@ nDets
Number of sub-detector type in this enumeration.
@ NotSet
The flag was not set to anything.
@ IS_SIMULATION
true: simulation, false: data
EventInfo_v1 EventInfo
Definition of the latest event info version.