8#include "GaudiKernel/IEvtSelector.h"
10#include "CLHEP/Random/RandFlat.h"
11#include "CLHEP/Random/RandPoisson.h"
27 const std::string& name,
28 const IInterface* parent)
29 : base_class(
type, name, parent )
50 unsigned int firstStore,
61 m_nStores =
static_cast<unsigned int>(ceil(
m_collXing * occupiedCrossings * largestElement));
77 for (
unsigned int i=0; i <
m_nStores; ++i)
79 std::stringstream bufName;
80 bufName <<
"BkgEvent_" << i + firstStore;
81 const std::string& streamName(bufName.str());
84 m_streams.emplace_back(streamName,serviceLocator(),selecName);
86 catch (
const std::runtime_error& e)
88 ATH_MSG_ERROR (
"Exception thrown while creating PileUpStream "
89 << streamName <<
" : " << e.what() );
90 return StatusCode::FAILURE;
97 return StatusCode::FAILURE;
106 return StatusCode::FAILURE;
113 return StatusCode::SUCCESS;
129 ATH_MSG_DEBUG (
"newEvent called resetting used event set" );
130 unsigned int totEvts(0);
133 for (
unsigned int iXing=0; iXing<
m_nXings; ++iXing) {
136 ATH_MSG_WARNING (
"newEvent: number of required evts (" << totEvts <<
") exceeds number of available stores "
137 <<
m_nStores <<
". Regenerating bkg sequence for this event \n"
138 <<
" the total number of bkg events may not exceed average by more than 6 sigmas"
150 StreamVector::size_type iS(0);
161 if (0 != pCurrStream) {
167 bool readEvent(isCentralBunchCrossing || (
m_readEventRand->fire()<1.0));
176 StreamVector::size_type iS(0);
187 if (0 != pCurrStream) {
193 bool readEvent(isCentralBunchCrossing || (
m_readEventRand->fire()<1.0));
196 return StatusCode::FAILURE;
206 << (inUse ?
"already" :
"not yet") <<
" in use" );
221 <<
" - cache for events of type "
232 return StatusCode::FAILURE;
244 using namespace std::placeholders;
253 return StatusCode::SUCCESS;
261 using namespace std::placeholders;
270 return StatusCode::SUCCESS;
273 <<
" is not a know collision distribution function" );
274 return StatusCode::FAILURE;
308 <<
" events from BC=0 Xing " << iXing <<
" - Events at BC=0 "
314 <<
" events for BCID " << iXing );
323 return this->
addSubEvts(iXing, overEvent, t0BinCenter,
true, 0);
329 int t0BinCenter,
bool loadEventProxies,
unsigned int BCID)
331 for (
unsigned int iEvt=0; iEvt<
nEvtsXing(iXing); ++iEvt)
337 if(!loadEventProxies) {
344 if (0 == pBkgEvent || 0 == currStream)
347 ATH_MSG_INFO (
"end of loop: background cache has no more events" );
348 return StatusCode::FAILURE;
355 <<
" @ Xing " << iXing );
364 subEvCnt->
back()->setBCID( BCID );
365 subEvCnt->
back()->setEvtStore( pBkgStore );
369 if (pBkgStore->
retrieve(pStoreInfo).isSuccess() && pStoreInfo &&
374 <<
" differ from current store "
383 return StatusCode::SUCCESS;
388 StatusCode
sc(StatusCode::SUCCESS);
390 <<
" - cache for events of type "
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
In memory cache for pileup events.
Helpers for checking error return status codes and reporting errors.
provides the relative beam intensity as a function of the bunch xing.
xAOD::EventInfo * addSubEvent(xAOD::EventInfo *targetEv, const xAOD::EventInfo::SubEvent &subev, xAOD::EventInfoContainer *eiContainer, const std::string &eiContKey, StoreGateSvc *subev_store=nullptr)
const std::string c_pileUpEventInfoContName
default value for the EventInfoContainer storing subevents for PileUp
Gaudi::Property< unsigned short > m_subtractBC0
unsigned int numberOfBkgForBunchCrossingIgnoringBeamIntensity(unsigned int iXing) const
meant to be used via m_f_numberOfBackgroundForBunchCrossing
ServiceHandle< IAtRndmGenSvc > m_atRndmSvc
Gaudi::Property< float > m_occupationFraction
Gaudi::Property< std::string > m_collDistrName
Gaudi::Property< float > m_readDownscale
ServiceHandle< IEvtSelector > m_selecName
virtual StatusCode setup(int firstXing, unsigned int nXings, unsigned int firstStore, IBeamIntensity *) override final
virtual void newEvent() override final
inform cache that we start overlaying a new event
Gaudi::Property< std::string > m_randomStreamName
int m_zeroXing
offset of BC=0 xing
CLHEP::RandPoisson * m_collXingPoisson
set number of collisions per bunch crossing (if Poisson distribution chosen)
float m_collXingSF
float scaling number of collisions per bunch crossing
const xAOD::EventInfo * nextEvent(bool isCentralBunchCrossing)
get next bkg event from cache
virtual StatusCode addSubEvts(unsigned int iXing, xAOD::EventInfo *overlaidEvent, int t0BinCenter) override final
Read input events in bkg stores and link them to overlay store.
Gaudi::Property< bool > m_ignoreBM
StreamVector::iterator m_cursor
xAOD::EventInfo::PileUpType m_pileUpEventType
the type of events in this cache
CLHEP::RandFlat * m_readEventRand
read a new event every downscaleFactor accesses
PileUpStream * current()
get current (last asked) stream
unsigned int nEvtsXing(unsigned int iXing) const
std::function< long() > m_f_collDistr
function returning the number of collisions per bunch crossing before bunch structure modulation
virtual ~BkgStreamsCache()
unsigned int setNEvtsXing(unsigned int iXing)
long collXing()
meant to be used (mainly) via m_f_collDistr
unsigned int numberOfBkgForBunchCrossingDefaultImpl(unsigned int iXing) const
Gaudi::Property< float > m_collXing
virtual StatusCode finalize() override final
BkgStreamsCache(const std::string &, const std::string &, const IInterface *)
Gaudi::Property< bool > m_ignoreSF
CLHEP::RandFlat * m_chooseEventRand
pickup an event store at random from the cache
virtual void resetEvtsPerXingScaleFactor(float sf) override final
reset scale factor at new run/lumiblk
bool alreadyInUse(StreamVector::size_type iStream)
unsigned int numberOfCavernBkgForBunchCrossing(unsigned int iXing) const
void PileUpEventTypeHandler(Gaudi::Details::PropertyBase &)
std::vector< bool > m_usedStreams
std::function< unsigned int(unsigned int) > m_f_numberOfBackgroundForBunchCrossing
function returning the number of bkg events per bunch crossing after bunch structure modulation
IBeamIntensity * m_beamInt
pointer to the IBeamIntensity distribution tool
Gaudi::CheckedProperty< unsigned short > m_pileUpEventTypeProp
virtual StatusCode initialize() override final
std::vector< unsigned int > m_nEvtsXing
Gaudi::Property< bool > m_forceReadForBC0
StatusCode nextEvent_passive(bool isCentralBunchCrossing)
as nextEvent except don't actually load anything
const T * back() const
Access the last element in the collection as an rvalue.
a triple selector/context/store defines a stream
const xAOD::EventInfo * nextEventPre(bool readRecord=true)
return next Event, load store with next Event
bool nextEventPre_Passive(bool readRecord)
like nextEventPre, but doesn't actually load anything
The Athena Transient Store API.
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
void makeCurrent()
The current store is becoming the active store.
static const std::string & PileUpType2Name(PileUpType typ)
Convert PileUpType enum value to string.
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
static PileUpType PileUpInt2Type(unsigned short typ)
Convert int to PileUpType enum value.
EventInfoContainer_v1 EventInfoContainer
Define the latest version of the container.
EventInfo_v1 EventInfo
Definition of the latest event info version.