ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
PileUpComps
src
PileUpToolsAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// Class header
6
#include "
PileUpToolsAlg.h
"
7
#include <algorithm>
8
10
11
PileUpToolsAlg::PileUpToolsAlg
(
const
std::string& name, ISvcLocator* pSvcLocator)
12
:
AthAlgorithm
(name, pSvcLocator)
13
{
14
}
15
16
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
17
18
StatusCode
PileUpToolsAlg::initialize
()
19
{
20
ATH_MSG_DEBUG
(
"Initializing "
<< name());
21
//locate the pu tools and initialize them
22
ATH_CHECK
(
m_puTools
.retrieve());
23
// initialise read handle keys
24
ATH_CHECK
(
m_eventInfoKey
.initialize());
25
return
StatusCode::SUCCESS;
26
}
27
28
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
29
30
bool
differentBunchXing
(
xAOD::EventInfo::SubEvent
i,
xAOD::EventInfo::SubEvent
j)
31
{
32
return
(i.time()!=j.time());
33
}
34
35
36
StatusCode
PileUpToolsAlg::execute
(
const
EventContext& ctx)
37
{
38
ATH_MSG_DEBUG
(
"in execute()"
);
39
41
// Get the overlaid event header, print out event and run number
42
43
SG::ReadHandle<xAOD::EventInfo>
evt(
m_eventInfoKey
, ctx);
44
if
(!evt.isValid()) {
45
ATH_MSG_ERROR
(
"Could not get xAOD::EventInfo "
<< evt.name() <<
" from store "
<< evt.store());
46
return
StatusCode::FAILURE;
47
}
48
49
ATH_MSG_INFO
(
"Hard-scatter xAOD::EventInfo : "
<<
" event: "
<< evt->eventNumber() <<
" run: "
<< evt->runNumber());
50
51
// access the sub events...
52
SubEventIterator
iEvt(evt->subEvents().begin());
53
const
SubEventIterator
endEvt(evt->subEvents().end());
54
55
ATH_MSG_DEBUG
(
"There are "
<< std::distance(iEvt,endEvt) <<
" subevents in this Event."
);
56
57
// Group subevents by bunch-crossing and work out the number of
58
// subevents that each PileUpTools will need to process.
59
std::map<const IPileUpTool*, unsigned int> eventsToProcessByTool;
60
std::map<SubEventIterator, SubEventIterator> bunchCrossingRanges;
61
while
(iEvt != endEvt)
62
{
63
const
SubEventIterator
fEvt(iEvt);
64
// find the next SubEvent where the SubEvent after it has a
65
// different bunch crossing time.
66
iEvt = std::adjacent_find(fEvt, endEvt,
differentBunchXing
);
67
const
SubEventIterator
lEvt = (iEvt==endEvt) ? iEvt : ++iEvt;
68
const
unsigned
int
nEventsInXing = std::distance(fEvt,lEvt);
69
ATH_MSG_VERBOSE
(
"Found "
<< nEventsInXing <<
" consecutive subevents with a bunch crossing time of "
<< fEvt->time() <<
" ns."
);
70
bunchCrossingRanges[lEvt]=fEvt;
//FIXME storing range "backwards" as the first part of the pair is const when accessed later
71
// loop over PileUpTools to check if they will need to process
72
// the current bunch crossing
73
for
(
auto
& puToolHandle :
m_puTools
)
74
{
75
ATH_MSG_VERBOSE
(__FILE__<<
":"
<<__LINE__<<
" --- Call toProcess on "
<<puToolHandle->name());
76
if
(puToolHandle->toProcess(fEvt->time()))
77
{
78
eventsToProcessByTool[&(*puToolHandle)] += nEventsInXing;
79
}
80
}
81
}
82
83
// call prepareEvent for all PileUpTools to set nInputEvents
84
for
(
auto
& puToolHandle :
m_puTools
)
85
{
86
// Reset the filters
87
puToolHandle->resetFilter();
88
ATH_MSG_VERBOSE
( puToolHandle->name() <<
" will get "
<< eventsToProcessByTool[&(*puToolHandle)] <<
" subevents to process."
);
89
ATH_CHECK
(puToolHandle->prepareEvent(ctx, eventsToProcessByTool[&(*puToolHandle)]));
90
}
91
92
// Loop over bunch-crossings and call processBunchXing for each
93
// PileUpTool
94
for
(
auto
& bunch : bunchCrossingRanges)
95
{
96
SubEventIterator
fEvt(bunch.second);
97
const
SubEventIterator
lEvt(bunch.first);
98
const
int
bunchXing(fEvt->time());
99
ATH_MSG_DEBUG
(
"Processing bunch-crossing at "
<< bunchXing <<
" ns."
);
100
for
(
auto
& puToolHandle :
m_puTools
)
101
{
102
103
ATH_MSG_VERBOSE
(__FILE__<<
":"
<<__LINE__<<
" --- call toProcess on "
<<puToolHandle->name());
104
if
(puToolHandle->toProcess(bunchXing))
105
{
106
ATH_CHECK
(puToolHandle->processBunchXing(bunchXing, fEvt, lEvt));
107
}
108
else
109
{
110
ATH_MSG_VERBOSE
(
"Skipping "
<< puToolHandle->name() <<
" for bunch crossing at "
<< bunchXing <<
" ns."
);
111
}
112
}
113
// clear the bkg events from the bunch xing we have just processed.
114
ATH_CHECK
(this->
clearXing
(fEvt, lEvt));
115
}
116
117
// call mergeEvent for all PileUpTools
118
for
(
auto
& puToolHandle :
m_puTools
)
119
{
120
ATH_MSG_VERBOSE
(__FILE__<<
":"
<<__LINE__<<
" --- Call to mergeEvent on "
<<puToolHandle->name());
121
ATH_CHECK
(puToolHandle->mergeEvent(ctx));
122
// Check if the event was filtered out by the current PileUpTool.
123
if
(!puToolHandle->filterPassed())
124
{
125
ATH_MSG_VERBOSE
(
"Filter "
<< puToolHandle->name() <<
" failed - will stop the event"
);
126
this->
setFilterPassed
(
false
, ctx);
127
}
128
}
129
130
return
StatusCode::SUCCESS;
131
}
132
133
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
134
135
StatusCode
PileUpToolsAlg::finalize
()
136
{
137
ATH_MSG_DEBUG
(
"in finalize()"
);
138
return
StatusCode::SUCCESS;
139
}
140
141
142
StatusCode
PileUpToolsAlg::clearXing
(
SubEventIterator
& fEvt,
const
SubEventIterator
& lEvt)
143
{
144
SubEventIterator
iClearEvt=fEvt;
145
while
(iClearEvt != lEvt)
146
{
147
ATH_CHECK
(iClearEvt->ptr()->evtStore()->clearStore());
148
#ifndef NDEBUG
149
ATH_MSG_VERBOSE
(
"Cleared store "
<< iClearEvt->ptr()->evtStore()->name());
150
#endif
151
++iClearEvt;
152
}
153
return
StatusCode::SUCCESS;
154
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
SubEventIterator
std::vector< xAOD::EventInfo::SubEvent >::const_iterator SubEventIterator
Definition
IPileUpTool.h:22
differentBunchXing
bool differentBunchXing(xAOD::EventInfo::SubEvent i, xAOD::EventInfo::SubEvent j)
Definition
PileUpToolsAlg.cxx:30
PileUpToolsAlg.h
an algorithm to steer the IPileUpTools
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::setFilterPassed
virtual void setFilterPassed(bool state, const EventContext &ctx) const
Definition
AthCommonAlgorithm.h:99
PileUpToolsAlg::m_puTools
ToolHandleArray< IPileUpTool > m_puTools
Definition
PileUpToolsAlg.h:36
PileUpToolsAlg::initialize
virtual StatusCode initialize() override
Definition
PileUpToolsAlg.cxx:18
PileUpToolsAlg::PileUpToolsAlg
PileUpToolsAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
PileUpToolsAlg.cxx:11
PileUpToolsAlg::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
PileUpToolsAlg.cxx:36
PileUpToolsAlg::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition
PileUpToolsAlg.h:38
PileUpToolsAlg::clearXing
StatusCode clearXing(SubEventIterator &fEvt, const SubEventIterator &lEvt)
Definition
PileUpToolsAlg.cxx:142
PileUpToolsAlg::finalize
virtual StatusCode finalize() override
Definition
PileUpToolsAlg.cxx:135
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
xAOD::EventInfo_v1::SubEvent
Class describing the properties of one pileup sub-event.
Definition
EventInfo_v1.h:286
Generated on
for ATLAS Offline Software by
1.17.0