ATLAS Offline Software
Loading...
Searching...
No Matches
EventInfoCnvTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Gaudi/Athena include(s):
7
8// EDM include(s):
9#include "EventInfo/EventInfo.h"
10#include "EventInfo/EventID.h"
11#include "EventInfo/EventType.h"
19
20// Local include(s):
21#include "EventInfoCnvTool.h"
22
23namespace xAODMaker {
24
25 // maps to copy the flags
26 static const std::map< xAOD::EventInfo::EventFlagSubDet,
27 EventInfo::EventFlagSubDet > subDetMap =
28 { {xAOD::EventInfo::Pixel, EventInfo::Pixel},
29 {xAOD::EventInfo::SCT, EventInfo::SCT},
30 {xAOD::EventInfo::TRT, EventInfo::TRT},
31 {xAOD::EventInfo::LAr, EventInfo::LAr},
32 {xAOD::EventInfo::Tile, EventInfo::Tile},
33 {xAOD::EventInfo::Muon, EventInfo::Muon},
34 {xAOD::EventInfo::ForwardDet, EventInfo::ForwardDet},
35 {xAOD::EventInfo::Core, EventInfo::Core},
36 {xAOD::EventInfo::Background, EventInfo::Background},
37 {xAOD::EventInfo::Lumi, EventInfo::Lumi} };
38
39 static const std::map< EventInfo::EventFlagErrorState,
41 { { EventInfo::NotSet, xAOD::EventInfo::NotSet },
42 { EventInfo::Warning, xAOD::EventInfo::Warning },
43 { EventInfo::Error, xAOD::EventInfo::Error}
44 };
45
46#if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
48 static const std::string INDET_BEAMPOS = "/Indet/Beampos";
49#endif
50
51
53 const std::string& name,
54 const IInterface* parent )
55 : AthAlgTool( type, name, parent )
56 {
57 // Declare the interface(s) provided by the tool:
58 declareInterface< IEventInfoCnvTool >( this );
59 }
60
62 {
63
64#if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
65 // Check if the beam position will be available or not:
68 } else {
69 // This is normal in some cases, but tell the user anyway
70 ATH_MSG_INFO( "Beam spot information not available" );
71 ATH_MSG_INFO( "Will not fill beam spot information into "
72 "xAOD::EventInfo" );
74 }
76 ATH_MSG_WARNING( "Beam spot information manually disabled on EventInfo object" );
78 }
79
81#endif // not XAOD_ANALYSIS or GENERATIONBASE
82
83#if !defined(XAOD_ANALYSIS) && !defined(SIMULATIONBASE) && !defined(GENERATIONBASE)
84 CHECK( m_lumiDataKey.initialize (SG::AllowEmpty) );
85#endif // not XAOD_ANALYSIS or GENERATIONBASE
86
87 // Return gracefully:
88 return StatusCode::SUCCESS;
89 }
90
103 StatusCode EventInfoCnvTool::convert( const EventInfo* aod,
104 xAOD::EventInfo* xaod,
105 bool pileUpInfo,
106 bool copyPileUpLinks,
107 [[maybe_unused]] const EventContext& ctx /*= Gaudi::Hive::currentContext()*/) const
108 {
109
110 if( ! aod ) {
111 ATH_MSG_WARNING( "Null pointer received for input!" );
112 return StatusCode::SUCCESS;
113 }
114
115 // Copy the basic properties into the xAOD object:
116 if( aod->event_ID() ) {
117 xaod->setRunNumber( aod->event_ID()->run_number() );
118 xaod->setEventNumber( aod->event_ID()->event_number() );
119 xaod->setLumiBlock( aod->event_ID()->lumi_block() );
120 xaod->setTimeStamp( aod->event_ID()->time_stamp() );
121 xaod->setTimeStampNSOffset( aod->event_ID()->time_stamp_ns_offset() );
122 xaod->setBCID( aod->event_ID()->bunch_crossing_id() );
123 xaod->setDetectorMask( aod->event_ID()->detector_mask0(),
124 aod->event_ID()->detector_mask1() );
126 aod->event_ID()->detector_mask3() );
127 }
128
129 // Copy the event type properties:
130 std::vector< float > eventWeights;
131 if( aod->event_type() ) {
132 EventType::NameTagPairVec detDescrTags;
133 aod->event_type()->get_detdescr_tags( detDescrTags );
134 xaod->setDetDescrTags( detDescrTags );
135 uint32_t eventTypeBitmask = 0;
136 if( aod->event_type()->test( EventType::IS_SIMULATION ) ) {
137 eventTypeBitmask |= xAOD::EventInfo::IS_SIMULATION;
138 }
139 if( aod->event_type()->test( EventType::IS_TESTBEAM ) ) {
140 eventTypeBitmask |= xAOD::EventInfo::IS_TESTBEAM;
141 }
142 if( aod->event_type()->test( EventType::IS_CALIBRATION ) ) {
143 eventTypeBitmask |= xAOD::EventInfo::IS_CALIBRATION;
144 }
145 xaod->setEventTypeBitmask( eventTypeBitmask );
146 // Only add MC information for simulation files:
150 eventWeights.resize( aod->event_type()->n_mc_event_weights(), 0.0 );
151 for( unsigned int i = 0; i < aod->event_type()->n_mc_event_weights();
152 ++i ) {
153 eventWeights[ i ] = aod->event_type()->mc_event_weight( i );
154 }
155 }
156 }
157
158 // Copy the trigger properties into the xAOD object:
159 if( aod->trigger_info() && !pileUpInfo ) {
163 std::vector< xAOD::EventInfo::StreamTag > streamTags;
164 std::vector< TriggerInfo::StreamTag >::const_iterator st_itr =
165 aod->trigger_info()->streamTags().begin();
166 std::vector< TriggerInfo::StreamTag >::const_iterator st_end =
167 aod->trigger_info()->streamTags().end();
168 for( ; st_itr != st_end; ++st_itr ) {
169 streamTags.emplace_back( st_itr->name(), st_itr->type(),
170 st_itr->obeysLumiblock(),
171 st_itr->robs(), st_itr->dets() );
172 }
173 xaod->setStreamTags( streamTags );
174 }
175
176 // Copy/calculate the pileup information:
177 if( ! pileUpInfo ) {
178 bool haveLumi = false;
179#if !defined(XAOD_ANALYSIS) && !defined(SIMULATIONBASE) && !defined(GENERATIONBASE)
180 if (!m_lumiDataKey.empty()) {
182 if (lumiData->lbAverageLuminosity() != 0 ||
183 lumiData->lbAverageInteractionsPerCrossing() != 0)
184 {
185 float actualMu = 0.0;
186 const float muToLumi = lumiData->muToLumi();
187 if( std::abs( muToLumi ) > 0.00001 ) {
188 unsigned int bcid = ctx.eventID().bunch_crossing_id();
189 actualMu = lumiData->lbLuminosityPerBCIDVector().at(bcid) / muToLumi;
190 }
191 xaod->setActualInteractionsPerCrossing( actualMu );
193 lumiData->lbAverageInteractionsPerCrossing() );
194 }
195 haveLumi = true;
196 }
197#endif // not XAOD_ANALYSIS or SIMULATIONBASE or GENERATIONBASE
198 if (!haveLumi) {
203 }
204 }
205
206 // Copy the sub-detector flags:
208 EventInfo::EventFlagSubDet >::const_iterator sd_itr =
209 subDetMap.begin();
211 EventInfo::EventFlagSubDet >::const_iterator sd_end =
212 subDetMap.end();
213 for( ; sd_itr != sd_end; ++sd_itr ) {
214
215 // Lumi does not store event flags, or an error state:
216 if( (int)sd_itr->first == (int)EventInfo::Lumi ) {
217 continue;
218 }
219
220 // Set the event flags for this sub-detector:
221 xaod->setEventFlags( sd_itr->first, aod->eventFlags( sd_itr->second ) );
222
223 // Look up the error state of this sub-detector:
224 std::map< EventInfo::EventFlagErrorState,
226 errorStateMap.find( aod->errorState( sd_itr->second ) );
227 if( state == errorStateMap.end() ) {
228 REPORT_MESSAGE( MSG::FATAL )
229 << "Unknown error state found for sub-detector "
230 << sd_itr->second << ": " << aod->errorState( sd_itr->second );
231 return StatusCode::FAILURE;
232 }
233
234 // Set the error state for the sub-detector:
235 xaod->setErrorState( sd_itr->first, state->second );
236 }
237
238 // Check if it is a PileUpEventInfo object:
239 const PileUpEventInfo* puei =
240 dynamic_cast< const PileUpEventInfo* >( aod );
241 if( puei && copyPileUpLinks ) {
242 // Create the sub-event objects to fill into the output object:
243 std::vector< xAOD::EventInfo::SubEvent > subEvents;
244 PileUpEventInfo::SubEvent::const_iterator itr = puei->beginSubEvt();
245 PileUpEventInfo::SubEvent::const_iterator end = puei->endSubEvt();
246 for( ; itr != end; ++itr ) {
247 // Look up the sub-event type:
248
250 switch (itr->type()) {
253 break;
256 break;
259 break;
262 break;
265 break;
268 break;
270 break;
271 default:
272 ATH_MSG_WARNING( "Unknown sub-event type ("
273 << itr->type() << ") encountered" );
274 break;
275 }
276
277 // Construct the link to the pile-up EventInfo object:
279 link.resetWithKeyAndIndex( "PileUpEventInfo", itr->index() );
280
281 // Add the new object
282 subEvents.emplace_back( itr->time(),
283 itr->index(),
284 type, link );
285 }
286
287 // Add the vector to the EventInfo:
288 xaod->setSubEvents( subEvents );
289 }
290
291#if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
292 // Fill the beam spot variables if the necessary service is available:
293 if( m_beamSpotInformationAvailable && ( ! pileUpInfo ) ) {
295 xaod->setBeamPos( beamSpotHandle->beamPos()[ Amg::x ],
296 beamSpotHandle->beamPos()[ Amg::y ],
297 beamSpotHandle->beamPos()[ Amg::z ] );
298 xaod->setBeamPosSigma( beamSpotHandle->beamSigma( 0 ),
299 beamSpotHandle->beamSigma( 1 ),
300 beamSpotHandle->beamSigma( 2 ) );
301 xaod->setBeamPosSigmaXY( beamSpotHandle->beamSigmaXY() );
302 xaod->setBeamTiltXZ( beamSpotHandle->beamTilt( 0 ) );
303 xaod->setBeamTiltYZ( beamSpotHandle->beamTilt( 1 ) );
304 xaod->setBeamStatus( beamSpotHandle->beamStatus() );
305 }
306#endif // not XAOD_ANALYSIS or GENERATIONBASE
307
308 if (!eventWeights.empty()) {
309 if (xaod->getStore()) {
310 // Ensure that this gets added as a decoration.
311 xaod->getStore()->lock();
312 }
313 static const xAOD::EventInfo::Decorator<std::vector<float> > ew ("mcEventWeights");
314 ew (*xaod) = std::move (eventWeights);
315 }
316
317 // Finish with some printout:
318 ATH_MSG_DEBUG( "Finished conversion EventInfo="<<aod<<" xAOD::EventInfo="<<xaod<<" content=" << *xaod );
319
320 // Return gracefully:
321 return StatusCode::SUCCESS;
322 }
323
324} // namespace xAODMaker
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE(LVL)
Report a message.
#define CHECK(...)
Evaluate an expression and check for errors.
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
This class provides general information about an event.
This class provides information about an overlaid event.
This class contains trigger related information.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
number_type detector_mask3(void) const
detector mask1 - bit field indicating which TTC zones have been built into the event,...
Definition EventID.h:149
number_type detector_mask2(void) const
detector mask0 - bit field indicating which TTC zones have been built into the event,...
Definition EventID.h:143
number_type detector_mask1(void) const
detector mask1 - bit field indicating which TTC zones have been built into the event,...
Definition EventID.h:137
number_type detector_mask0(void) const
detector mask0 - bit field indicating which TTC zones have been built into the event,...
Definition EventID.h:131
float actualInteractionsPerCrossing() const
Access to number of interactions per crossing:
EventID * event_ID()
the unique identification of the event.
EventFlagErrorState errorState(EventFlagSubDet subDet) const
return error state for a particular sub-detector
TriggerInfo * trigger_info()
trigger information (ptr may be NULL)
float averageInteractionsPerCrossing() const
average interactions per crossing for all BCIDs - for out-of-time pile-up
unsigned int eventFlags(EventFlagSubDet subDet) const
event flags for a particular sub-detector
EventType * event_type()
the type of the event, e.g. simulation, testbeam, etc
float mc_event_weight(unsigned int iweight=0) const
Access to MC weight.
static const EventTypeCode IS_CALIBRATION
true: IS_CALIBRATION, false: IS_PHYSICS
Definition EventType.h:162
std::vector< NameTagPair > NameTagPairVec
Definition EventType.h:101
void get_detdescr_tags(NameTagPairVec &pairs) const
Access DetDescr tags.
number_type mc_channel_number() const
Access to the MC generator channel number (was used as run number for generator events)
static const EventTypeCode IS_SIMULATION
true: IS_SIMULATION, false: IS_DATA
Definition EventType.h:156
unsigned int n_mc_event_weights() const
Total number of MC weights.
bool test(EventTypeCode type_code) const
Tests for standard characteristics.
Definition EventType.cxx:62
uint64_t mc_event_number() const
Access to the MC generator event number.
static const EventTypeCode IS_TESTBEAM
true: IS_TESTBEAM, false: IS_FROM_ATLAS_DET
Definition EventType.h:159
This class provides information about an overlaid event.
SubEvent::iterator endSubEvt()
SubEvent::iterator beginSubEvt()
SG::IAuxStore * getStore() const
Return the current store, as a non-const interface.
SG::Decorator< T, ALLOC > Decorator
class to provide type-safe access to aux data.
Definition AuxElement.h:135
virtual void lock()=0
Lock the container.
number_type level1TriggerType() const
get level1 trigger type
number_type extendedLevel1ID() const
get extended level1 ID
number_type statusElement() const
get status element
const std::vector< StreamTag > & streamTags() const
get stream tags
SG::ReadCondHandleKey< LuminosityCondData > m_lumiDataKey
Gaudi::Property< bool > m_disableBeamSpot
EventInfoCnvTool(const std::string &type, const std::string &name, const IInterface *parent)
Regular AlgTool constructor.
virtual StatusCode initialize() override
Function initialising the tool.
virtual StatusCode convert(const EventInfo *aod, xAOD::EventInfo *xaod, bool pileUpInfo=false, bool copyPileUpLinks=true, const EventContext &ctx=Gaudi::Hive::currentContext()) const override
Function that fills an existing xAOD::EventInfo object with data.
bool m_beamSpotInformationAvailable
Internal flag for the availability of the beam spot information.
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
void setBeamPosSigma(float x, float y, float z)
Set the size of the beam spot.
void setAverageInteractionsPerCrossing(float value)
Set average interactions per crossing for all BCIDs.
void setBCID(uint32_t value)
Set the bunch crossing ID of the event.
void setDetectorMask(uint32_t mask0, uint32_t mask1)
Set the bit fields indicating with TTC timezones were present.
void setTimeStampNSOffset(uint32_t value)
Set the nanosecond offset wrt. the time stamp.
void setMCEventNumber(uint64_t value)
Set the MC generator's event number.
bool eventType(EventType type) const
Check for one particular bitmask value.
EventFlagSubDet
Sub-detector types for which we store event-level flags.
@ Background
The beam background detectors.
@ Tile
The Tile calorimeter.
@ Muon
The muon spectrometer.
@ Core
Core flags describing the event.
@ Pixel
The pixel tracker.
@ ForwardDet
The forward detectors.
@ LAr
The LAr calorimeter.
@ Lumi
The luminosity detectors.
void setStreamTags(const std::vector< StreamTag > &value)
Set the streams that the event was put in.
void setBeamTiltYZ(float value)
Set the beam's tilt in radians in YZ.
void setTimeStamp(uint32_t value)
Set the POSIX time of the event.
bool setErrorState(EventFlagSubDet subDet, EventFlagErrorState state)
Set the error state for a particular sub-detector.
void setLevel1TriggerType(uint16_t value)
Set the Level-1 trigger type.
bool setEventFlags(EventFlagSubDet subDet, uint32_t flags)
Set the event flags for a particular sub-detector.
void setDetectorMaskExt(uint32_t mask2, uint32_t mask3)
Set the bit fields indicating with TTC timezones were present.
void setEventNumber(uint64_t value)
Set the current event's event number.
void setSubEvents(const std::vector< SubEvent > &value)
Set the pileup events that were used in the simulation.
void setBeamPos(float x, float y, float z)
Set the beam spot position.
EventFlagErrorState
States that a given sub-detector could be in.
@ Warning
The sub-detector issued a warning.
@ NotSet
The flag was not set to anything.
@ Error
The sub-detector issued an error.
void setBeamPosSigmaXY(float value)
Set the beam spot shape's X-Y correlation.
void setEventTypeBitmask(uint32_t value)
Set the event type bitmask.
void setBeamStatus(uint32_t value)
Set the beam spot's status word.
void setMCChannelNumber(uint32_t value)
Set the MC generator's channel number.
void setExtendedLevel1ID(uint32_t value)
Set the extended Level-1 identifier.
void setDetDescrTags(const DetDescrTags_t &value)
Set the detector description tags.
void setRunNumber(uint32_t value)
Set the current event's run number.
PileUpType
Enumerator describing the types of pileup events.
@ HaloGas
Halo-gas non-collision background.
@ HighPtMinimumBias
High pT Minimum bias pileup event.
@ MinimumBias
(Low pT) Minimum bias pileup event
@ ZeroBias
Zero bias pileup event.
@ Signal
The signal event.
@ Cavern
Cavern background pileup event.
@ Unknown
Type not known/specified.
void setBeamTiltXZ(float value)
Set the beam's tilt in radians in XZ.
@ IS_CALIBRATION
true: calibration, false: physics
@ IS_SIMULATION
true: simulation, false: data
@ IS_TESTBEAM
true: testbeam, false: full detector
void setStatusElement(uint32_t value)
Set the trigger status element.
void setLumiBlock(uint32_t value)
Set the current event's luminosity block number.
void setActualInteractionsPerCrossing(float value)
Set average interactions per crossing for the current BCID.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
static const std::map< xAOD::EventInfo::EventFlagSubDet, EventInfo::EventFlagSubDet > subDetMap
static const std::map< EventInfo::EventFlagErrorState, xAOD::EventInfo::EventFlagErrorState > errorStateMap
static const std::string INDET_BEAMPOS
Hard-coded location of the beam position information.
EventInfo_v1 EventInfo
Definition of the latest event info version.