ATLAS Offline Software
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
BkgStreamsCache Class Reference

In-memory cache for pileup events. More...

#include <BkgStreamsCache.h>

Inheritance diagram for BkgStreamsCache:
Collaboration diagram for BkgStreamsCache:

Public Member Functions

 BkgStreamsCache (const std::string &, const std::string &, const IInterface *)
 
virtual ~BkgStreamsCache ()
 
virtual StatusCode initialize () override final
 
virtual StatusCode finalize () override final
 
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 More...
 
virtual void resetEvtsPerXingScaleFactor (float sf) override final
 reset scale factor at new run/lumiblk More...
 
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. More...
 
virtual StatusCode addSubEvts (unsigned int iXing, xAOD::EventInfo *overEvent, int t0BinCenter, bool loadEventProxies, unsigned int) override final
 Read input events in bkg stores and link them to overlay store. More...
 
virtual unsigned int nStores () const override final
 how many stores in this cache More...
 
long collXing ()
 meant to be used (mainly) via m_f_collDistr More...
 
long collXingPoisson ()
 
unsigned int numberOfBkgForBunchCrossingIgnoringBeamIntensity (unsigned int iXing) const
 meant to be used via m_f_numberOfBackgroundForBunchCrossing More...
 
unsigned int numberOfBkgForBunchCrossingDefaultImpl (unsigned int iXing) const
 
unsigned int numberOfCavernBkgForBunchCrossing (unsigned int iXing) const
 

Private Types

typedef std::vector< PileUpStreamStreamVector
 

Private Member Functions

const xAOD::EventInfonextEvent (bool isCentralBunchCrossing)
 get next bkg event from cache More...
 
StatusCode nextEvent_passive (bool isCentralBunchCrossing)
 as nextEvent except don't actually load anything More...
 
PileUpStreamcurrent ()
 get current (last asked) stream More...
 
unsigned int setNEvtsXing (unsigned int iXing)
 
unsigned int nEvtsXing (unsigned int iXing) const
 
bool alreadyInUse (StreamVector::size_type iStream)
 

Private Attributes

StreamVector::iterator m_cursor
 
StreamVector m_streams
 
std::vector< bool > m_usedStreams
 
unsigned int m_nXings
 
unsigned int m_nStores
 
std::vector< unsigned int > m_nEvtsXing
 

Properties

Gaudi::Property< float > m_collXing
 
Gaudi::Property< float > m_occupationFraction
 The maximum fraction of bunch-crossings which will be occupied. More...
 
Gaudi::Property< std::string > m_collDistrName
 select collision distribution More...
 
ServiceHandle< IEvtSelector > m_selecName
 
Gaudi::Property< float > m_readDownscale
 read downscale factor (average number of times a min bias is reused) More...
 
ServiceHandle< IAtRndmGenSvcm_atRndmSvc
 IAtRndmGenSvc controlling the distribution of bkg events per bunch crossing. More...
 
Gaudi::Property< std::string > m_randomStreamName
 the IAtRndmGenSvc stream to generate number of bkg events per bunch crossing More...
 
Gaudi::CheckedProperty< unsigned short > m_pileUpEventTypeProp
 the type of events in this cache More...
 
xAOD::EventInfo::PileUpType m_pileUpEventType
 the type of events in this cache More...
 
Gaudi::Property< unsigned short > m_subtractBC0
 subtract from number of events at bunch xing = 0 More...
 
Gaudi::Property< bool > m_ignoreBM
 ignore the PileUpEventLoopMgr beam intensity tool More...
 
CLHEP::RandFlat * m_readEventRand
 read a new event every downscaleFactor accesses More...
 
CLHEP::RandFlat * m_chooseEventRand
 pickup an event store at random from the cache More...
 
CLHEP::RandPoisson * m_collXingPoisson
 set number of collisions per bunch crossing (if Poisson distribution chosen) More...
 
std::function< long() > m_f_collDistr
 function returning the number of collisions per bunch crossing before bunch structure modulation More...
 
std::function< unsigned int(unsigned int) > m_f_numberOfBackgroundForBunchCrossing
 function returning the number of bkg events per bunch crossing after bunch structure modulation More...
 
float m_collXingSF
 float scaling number of collisions per bunch crossing More...
 
Gaudi::Property< bool > m_ignoreSF
 bool apply scaling number of collisions per bunch crossing ? More...
 
int m_zeroXing
 offset of BC=0 xing More...
 
IBeamIntensitym_beamInt
 pointer to the IBeamIntensity distribution tool More...
 
Gaudi::Property< bool > m_forceReadForBC0
 Force events used in the central bunch crossing to be refreshed. More...
 
void PileUpEventTypeHandler (Gaudi::Details::PropertyBase &)
 

Detailed Description

In-memory cache for pileup events.

Definition at line 36 of file BkgStreamsCache.h.

Member Typedef Documentation

◆ StreamVector

typedef std::vector<PileUpStream> BkgStreamsCache::StreamVector
private

Definition at line 98 of file BkgStreamsCache.h.

Constructor & Destructor Documentation

◆ BkgStreamsCache()

BkgStreamsCache::BkgStreamsCache ( const std::string &  type,
const std::string &  name,
const IInterface *  parent 
)

Definition at line 28 of file BkgStreamsCache.cxx.

31  : base_class( type, name, parent )
32  , m_nXings(0)
33  , m_nStores(0)
34  , m_collXing(23.0)
36  , m_collDistrName("Poisson")
37  , m_selecName("FakeEventSelector", name)
38  , m_readDownscale(150)
39  , m_atRndmSvc("AtRndmGenSvc", name)
40  , m_randomStreamName("PileUpCollXingStream")
43  , m_subtractBC0(0)
44  , m_ignoreBM(false)
45  , m_readEventRand(nullptr)
46  , m_chooseEventRand(nullptr)
47  , m_collXingPoisson(nullptr)
48  , m_f_collDistr(0)
50  , m_collXingSF(1.0)
51  , m_ignoreSF(false)
52  , m_zeroXing(-1)
53  , m_beamInt(nullptr)
54  , m_forceReadForBC0(true)
55 {
56  declareProperty("CollPerXing", m_collXing, "(average) number of collisions per beam crossing");
57  declareProperty("OccupationFraction", m_occupationFraction, "The maximum fraction of bunch-crossings which will be occupied.");
58  declareProperty("CollDistribution", m_collDistrName, "nEvts/Xings can be either Fixed at CollPerXing or Poisson with average CollPerXing");
59  declareProperty("EventSelector", m_selecName);
60  declareProperty("PileUpEventType", m_pileUpEventTypeProp, "Type of the pileup events in this cache: 0:Signal, 1:MinimumBias, 2:Cavern, 3:HaloGas, 4:ZeroBias. Default=0 (Signal, Invalid)");
61  declareProperty("ReadDownscaleFactor", m_readDownscale, "read one event every downscaleFactor accesses (asymptotically -> number of times an event in the cache will be reused)");
62  declareProperty("RndmGenSvc", m_atRndmSvc, "IAtRndmGenSvc controlling the distribution of bkg events/xing");
63  declareProperty("RndmStreamName", m_randomStreamName, "IAtRndmGenSvc stream used as engine for our various random distributions, including the CollPerXing one ");
64  declareProperty("SubtractBC0", m_subtractBC0, "reduce the number of events at bunch xing t=0 by m_subtractBC0. Default=0, set to 1 when using the same type of events (e.g. minbias) for original and background streams");
67  declareProperty("IgnoreBeamInt", m_ignoreBM, "Default=False, set to True to ignore the PileUpEventLoopMgr beam intensity tool in setting the number of events per xing.");
68  declareProperty("IgnoreBeamLumi", m_ignoreSF, "Default=False, set to True to ignore the PileUpEventLoopMgr beam luminosity tool in setting the number of events per xing.");
69  declareProperty("ForceReadForBC0",m_forceReadForBC0,"Force events used in the central bunch crossing to be refreshed");
70 }

◆ ~BkgStreamsCache()

BkgStreamsCache::~BkgStreamsCache ( )
virtual

Definition at line 72 of file BkgStreamsCache.cxx.

73 {
74  delete m_collXingPoisson;
75  delete m_chooseEventRand;
76  delete m_readEventRand;
77 }

Member Function Documentation

◆ addSubEvts() [1/2]

StatusCode BkgStreamsCache::addSubEvts ( unsigned int  iXing,
xAOD::EventInfo overEvent,
int  t0BinCenter,
bool  loadEventProxies,
unsigned int  BCID 
)
finaloverridevirtual

Read input events in bkg stores and link them to overlay store.

Parameters
iXingoffset to first xing number (=0 first Xing, =nXings for last xing)
overlaidEventreference to resulting overlaid event
t0BinCentertime wrto t0 of current bin center in ns
loadEventProxiesshould we load the event proxies or not.
BCIDbunch-crossing ID of signal bunch crossing

Definition at line 365 of file BkgStreamsCache.cxx.

368 {
369  for (unsigned int iEvt=0; iEvt<nEvtsXing(iXing); ++iEvt)
370  {
371  // check if we're picking events for the central bunch-crossing,
372  // so we can choose to only use fresh events here.
373  bool isCentralBunchCrossing((0==t0BinCenter)&&m_forceReadForBC0);
374  // increment event iterators
375  if(!loadEventProxies) {
376  return this->nextEvent_passive(isCentralBunchCrossing);
377  }
378  const xAOD::EventInfo* pBkgEvent = nextEvent( isCentralBunchCrossing ); //FIXME update this for the case where loadProxies=False
379 
380  //check input selector is not empty
381  PileUpStream* currStream(this->current());
382  if (0 == pBkgEvent || 0 == currStream)
383  {
384  // This is the end of the loop. No more events in the selection
385  ATH_MSG_INFO ( "end of loop: background cache has no more events" );
386  return StatusCode::FAILURE;
387  }
388  StoreGateSvc* pBkgStore = &(currStream->store());
389  ATH_MSG_DEBUG ( "added event " << pBkgEvent->eventNumber()
390  << " run " << pBkgEvent->runNumber()
391  << " from store "
392  << pBkgStore->name()
393  << " @ Xing " << iXing );
394 
395  // register as sub event of the overlaid
396 
397  // get the SG container for subevents infos
398  xAOD::EventInfoContainer *subEvCnt (nullptr);
399  ATH_CHECK( overEvent->evtStore()->retrieve(subEvCnt, c_pileUpEventInfoContName) );
400  // temporary EI instance to modify BCID before adding the EI
401  xAOD::EventInfo tmp_ei( *pBkgEvent );
402  tmp_ei.setBCID( BCID );
403  tmp_ei.setEvtStore(pBkgStore);
404  // add subevent
405  addSubEvent( overEvent, &tmp_ei, t0BinCenter, m_pileUpEventType, subEvCnt, c_pileUpEventInfoContName );
406 
407 #ifdef DEBUG_PILEUP
408  const xAOD::EventInfo* pStoreInfo(nullptr);
409  if (pBkgStore->retrieve(pStoreInfo).isSuccess() && pStoreInfo &&
410  pBkgEvent->eventNumber() != pStoreInfo->eventNumber())
411  {
412  ATH_MSG_ERROR ( "added event " << pBkgEvent->eventNumber()
413  << " run " << pBkgEvent->runNumber()
414  << " differ from current store "
415  << pBkgStore->name()
416  << " event " << pStoreInfo->eventNumber()
417  << " run " << pStoreInfo->runNumber()
418  );
419  assert(1);
420  }
421 #endif
422  } //loop over evts in xing
423  return StatusCode::SUCCESS;
424 }

◆ addSubEvts() [2/2]

StatusCode BkgStreamsCache::addSubEvts ( unsigned int  iXing,
xAOD::EventInfo overlaidEvent,
int  t0BinCenter 
)
finaloverridevirtual

Read input events in bkg stores and link them to overlay store.

Parameters
iXingoffset to first xing number (=0 first Xing, =nXings for last xing)
overlaidEventreference to resulting overlaid event
t0BinCentertime wrto t0 of current bin center in ns

Definition at line 357 of file BkgStreamsCache.cxx.

360 {
361  return this->addSubEvts(iXing, overEvent, t0BinCenter, true, 0);
362 }

◆ alreadyInUse()

bool BkgStreamsCache::alreadyInUse ( StreamVector::size_type  iStream)
private

Definition at line 237 of file BkgStreamsCache.cxx.

238 {
239  assert(iS<m_usedStreams.size());
240  bool inUse(m_usedStreams[iS]);
241  if (!inUse) m_usedStreams[iS] = true;
242 #ifndef NDEBUG
243  ATH_MSG_VERBOSE ( "alreadyInUse: store " << iS << ' '
244  << (inUse ? "already" : "not yet") << " in use" );
245 #endif
246  return inUse;
247 }

◆ collXing()

long BkgStreamsCache::collXing ( )
inline

meant to be used (mainly) via m_f_collDistr

Definition at line 81 of file BkgStreamsCache.h.

81 { return m_collXing; }

◆ collXingPoisson()

long BkgStreamsCache::collXingPoisson ( )

Definition at line 159 of file BkgStreamsCache.cxx.

160 {
161  if (!m_collXingPoisson) { return collXing(); }
162  return m_collXingPoisson->fire(m_collXing * m_collXingSF);
163 }

◆ current()

PileUpStream * BkgStreamsCache::current ( )
private

get current (last asked) stream

Definition at line 249 of file BkgStreamsCache.cxx.

250 {
251  if (m_cursor != m_streams.end()) return &*m_cursor;
252  // m_cursor->isNotEmpty()) return &*m_cursor;
253  else return 0; //FIXME should reomve empty stream and keep going
254 }

◆ finalize()

StatusCode BkgStreamsCache::finalize ( )
finaloverridevirtual

Definition at line 426 of file BkgStreamsCache.cxx.

427 {
428  StatusCode sc(StatusCode::SUCCESS);
429  ATH_MSG_DEBUG ( "Finalizing " << name()
430  << " - cache for events of type "
432  while (sc.isSuccess() && m_streams.size()>0)
433  {
434  sc=m_streams.back().finalize();
435  m_streams.pop_back();
436  }
437  return sc;
438 }

◆ initialize()

StatusCode BkgStreamsCache::initialize ( )
finaloverridevirtual

Definition at line 256 of file BkgStreamsCache.cxx.

257 {
258  ATH_MSG_DEBUG ( "Initializing " << name()
259  << " - cache for events of type "
261 
263 
264  //create random number generators
265  ATH_CHECK(m_atRndmSvc.retrieve());
266  CLHEP::HepRandomEngine* collEng(m_atRndmSvc->GetEngine(m_randomStreamName.value()));
267  if( 0 == collEng )
268  {
269  ATH_MSG_ERROR ( "can not get random stream " << m_randomStreamName.value() );
270  return StatusCode::FAILURE;
271  }
272 
273  //setup distribution to read a new event every downscaleFactor accesses
274  //notice how we pass collEng by reference. If ! CLHEP will take ownership...
275  m_readEventRand = new CLHEP::RandFlat(*(collEng),
276  0.0, double(m_readDownscale));
277 
278  // select collision distribution functions
279  if (m_collDistrName.value() == "Fixed")
280  {
281  m_f_collDistr = std::bind(&BkgStreamsCache::collXing, this);
282  using namespace std::placeholders;
283  if(m_ignoreBM.value())
284  {
286  }
287  else
288  {
290  }
291  return StatusCode::SUCCESS;
292  }
293  if (m_collDistrName.value() == "Poisson")
294  {
295  //pass collEng by reference. If Not CLHEP will take ownership...
296  m_collXingPoisson = new CLHEP::RandPoisson(*(collEng), m_collXing);
297  // m_f_collDistr will call m_collXingPoisson->fire(m_collXing) USED TO BE boost::bind(&CLHEP::RandPoisson::fire, m_collXingPoisson);
299  using namespace std::placeholders;
300  if(m_ignoreBM.value())
301  {
303  }
304  else
305  {
307  }
308  return StatusCode::SUCCESS;
309  }
311  << " is not a know collision distribution function" );
312  return StatusCode::FAILURE;
313 }

◆ nEvtsXing()

unsigned int BkgStreamsCache::nEvtsXing ( unsigned int  iXing) const
private

Definition at line 315 of file BkgStreamsCache.cxx.

316 {
317  return (iXing + 1 > m_nEvtsXing.size()) ? 0 : m_nEvtsXing[iXing];
318 }

◆ newEvent()

void BkgStreamsCache::newEvent ( )
finaloverridevirtual

inform cache that we start overlaying a new event

Definition at line 165 of file BkgStreamsCache.cxx.

166 {
167  ATH_MSG_DEBUG ( "newEvent called resetting used event set" );
168  unsigned int totEvts(0);
169  do {
170  totEvts = 0;
171  for (unsigned int iXing=0; iXing<m_nXings; ++iXing) {
172  totEvts += setNEvtsXing(iXing);
173  if (totEvts > m_nStores) {
174  ATH_MSG_WARNING ( "newEvent: number of required evts (" << totEvts << ") exceeds number of available stores "
175  << m_nStores << ". Regenerating bkg sequence for this event \n"
176  << " the total number of bkg events may not exceed average by more than 6 sigmas"
177  );
178  break;
179  }
180  }
181  } while(totEvts > m_nStores);
182  m_usedStreams.assign(m_streams.size(), false);
183 }

◆ nextEvent()

const xAOD::EventInfo * BkgStreamsCache::nextEvent ( bool  isCentralBunchCrossing)
private

get next bkg event from cache

Definition at line 185 of file BkgStreamsCache.cxx.

186 {
187  const xAOD::EventInfo* pNextEvt(nullptr);
188  StreamVector::size_type iS(0);
189  do {
190  iS = (StreamVector::size_type)m_chooseEventRand->fire();
191  } while (alreadyInUse(iS));
192 
193  //set current store to iS
194  m_cursor = m_streams.begin();
195  std::advance(m_cursor, iS);
196 
197  ATH_MSG_DEBUG ( "using store " << iS );
198  PileUpStream* pCurrStream(current());
199  if (0 != pCurrStream) {
200  pCurrStream->store().makeCurrent();
201  //read a new event every downscaleFactor accesses
202  //force reading of new event if the event is being used for in-time pile-up
203  //FIXME a more careful strategy would have the PileUpStreams knowing if
204  //they have been used for the central bunch-crossing already.
205  bool readEvent(isCentralBunchCrossing || (m_readEventRand->fire()<1.0));
206  pNextEvt = pCurrStream->nextEventPre( readEvent );
207  }
208  return pNextEvt;
209 }

◆ nextEvent_passive()

StatusCode BkgStreamsCache::nextEvent_passive ( bool  isCentralBunchCrossing)
private

as nextEvent except don't actually load anything

Definition at line 212 of file BkgStreamsCache.cxx.

213 {
214  StreamVector::size_type iS(0);
215  do {
216  iS = (StreamVector::size_type)m_chooseEventRand->fire();
217  } while (alreadyInUse(iS));
218 
219  //set current store to iS
220  m_cursor = m_streams.begin();
221  std::advance(m_cursor, iS);
222 
223  ATH_MSG_DEBUG ( "using store " << iS );
224  PileUpStream* pCurrStream(current());
225  if (0 != pCurrStream) {
226  pCurrStream->store().makeCurrent();
227  //read a new event every downscaleFactor accesses
228  //force reading of new event if the event is being used for in-time pile-up
229  //FIXME a more careful strategy would have the PileUpStreams knowing if
230  //they have been used for the central bunch-crossing already.
231  bool readEvent(isCentralBunchCrossing || (m_readEventRand->fire()<1.0));
232  if(pCurrStream->nextEventPre_Passive(readEvent)) return StatusCode::SUCCESS;
233  }
234  return StatusCode::FAILURE;
235 }

◆ nStores()

virtual unsigned int BkgStreamsCache::nStores ( ) const
inlinefinaloverridevirtual

how many stores in this cache

Definition at line 78 of file BkgStreamsCache.h.

78 { return m_nStores; }

◆ numberOfBkgForBunchCrossingDefaultImpl()

unsigned int BkgStreamsCache::numberOfBkgForBunchCrossingDefaultImpl ( unsigned int  iXing) const

Definition at line 324 of file BkgStreamsCache.cxx.

325 {
326  return static_cast<unsigned int>(m_beamInt->normFactor(iXing-m_zeroXing)*static_cast<float>(m_f_collDistr()));
327 }

◆ numberOfBkgForBunchCrossingIgnoringBeamIntensity()

unsigned int BkgStreamsCache::numberOfBkgForBunchCrossingIgnoringBeamIntensity ( unsigned int  iXing) const

meant to be used via m_f_numberOfBackgroundForBunchCrossing

Definition at line 320 of file BkgStreamsCache.cxx.

321 {
322  return m_f_collDistr();
323 }

◆ numberOfCavernBkgForBunchCrossing()

unsigned int BkgStreamsCache::numberOfCavernBkgForBunchCrossing ( unsigned int  iXing) const

Definition at line 328 of file BkgStreamsCache.cxx.

329 {
330  return static_cast<unsigned int>(m_beamInt->normFactor(iXing-m_zeroXing)>0.0)*m_f_collDistr();
331 }

◆ PileUpEventTypeHandler()

void BkgStreamsCache::PileUpEventTypeHandler ( Gaudi::Details::PropertyBase &  )
private

Definition at line 80 of file BkgStreamsCache.cxx.

◆ resetEvtsPerXingScaleFactor()

void BkgStreamsCache::resetEvtsPerXingScaleFactor ( float  sf)
finaloverridevirtual

reset scale factor at new run/lumiblk

Definition at line 154 of file BkgStreamsCache.cxx.

155 {
156  if (!m_ignoreSF) m_collXingSF = sf;
157 }

◆ setNEvtsXing()

unsigned int BkgStreamsCache::setNEvtsXing ( unsigned int  iXing)
private

Definition at line 333 of file BkgStreamsCache.cxx.

334 {
335  if (iXing + 1 > m_nEvtsXing.size()) m_nEvtsXing.resize(2 * iXing + 1);
336  unsigned int nEvts(m_f_numberOfBackgroundForBunchCrossing(iXing));
337  //this is done mainly to handle the case in which original and backround
338  //events belong to the same stream. Of course we do not want m_nEvtsXing[m_zeroXing]<0
339  if ((int)iXing==m_zeroXing)
340  {
341  unsigned int subValue(m_subtractBC0.value());
342  while (nEvts<subValue) nEvts = m_f_numberOfBackgroundForBunchCrossing(iXing);
343  nEvts -= subValue;
344 #ifndef NDEBUG
345  ATH_MSG_VERBOSE ( "Subtracted " << m_subtractBC0.value()
346  << " events from BC=0 Xing " << iXing << " - Events at BC=0 "
347  << nEvts
348  );
349 #endif
350  }
351  ATH_MSG_VERBOSE ( "Will pile-up " << nEvts
352  << " events for BCID " << iXing );
353  m_nEvtsXing[iXing] = nEvts;
354  return nEvts;
355 }

◆ setup()

StatusCode BkgStreamsCache::setup ( int  firstXing,
unsigned int  nXings,
unsigned int  firstStore,
IBeamIntensity iBM 
)
finaloverridevirtual
Parameters
nXingsbunch Xings to be processed
firstStoreid of first store in cache

Definition at line 86 of file BkgStreamsCache.cxx.

90 {
91  assert (0 < nXings);
92  m_nXings = nXings;
93  m_zeroXing = -firstXing;
94  if (m_zeroXing >= (int)nXings) m_zeroXing = -99;
95  m_beamInt = (m_ignoreBM.value() ? 0 : iBM);
96  float largestElement( ( m_ignoreBM.value() || m_collDistrName.value() == "Fixed" ) ? 1.0 : m_beamInt->largestElementInPattern() );
97  //ceil (cmath) rounds up to the nearest integer ceil(1.5)= 2
98  float occupiedCrossings = ceil(static_cast<float>(m_nXings) * m_occupationFraction);
99  m_nStores = static_cast<unsigned int>(ceil( m_collXing * occupiedCrossings * largestElement));
100  if (m_collDistrName.value() == "Poisson")
101  {
102  //allow for fluctuations in # of overlaid events
103  m_nStores += static_cast<unsigned int>(6.0 * sqrt(static_cast<float>(m_nStores)));
104  }
105 
106  //get bkg selectors, stores and iterators
107  ATH_MSG_DEBUG ( "Set up " << m_nStores << " stores" );
108 
109  m_nEvtsXing.reserve(m_nStores);
110  m_streams.reserve(m_nStores);
111  m_usedStreams.reserve(m_nStores);
112  m_usedStreams.assign(m_nStores, false);
113 
114  const std::string& selecName(m_selecName.name());
115  for (unsigned int i=0; i < m_nStores; ++i)
116  {
117  std::stringstream bufName;
118  bufName << "BkgEvent_" << i + firstStore;
119  const std::string& streamName(bufName.str());
120  try
121  {
122  m_streams.emplace_back(streamName,serviceLocator(),selecName);
123  }
124  catch (const std::runtime_error& e)
125  {
126  ATH_MSG_ERROR ( "Exception thrown while creating PileUpStream "
127  << streamName << " : " << e.what() );
128  return StatusCode::FAILURE;
129  }
130 
131  if(!(m_streams.back().setupStore()))
132  {
133  ATH_MSG_ERROR ( "Can not setup bkg evt store for stream "
134  << streamName );
135  return StatusCode::FAILURE;
136  }
137  }
138  m_cursor = m_streams.begin();
139 
140  CLHEP::HepRandomEngine* collEng(m_atRndmSvc->GetEngine(m_randomStreamName.value()));
141  if( !collEng )
142  {
143  ATH_MSG_ERROR ( "can not get random stream " << m_randomStreamName.value() );
144  return StatusCode::FAILURE;
145  }
146  //setup generator to pickup an event store at random from the cache
147  //notice how we pass collEng by reference. If ! CLHEP will take ownership...
148  m_chooseEventRand = new CLHEP::RandFlat(*(collEng),
149  0.0, double(m_nStores));
150 
151  return StatusCode::SUCCESS;
152 }

Member Data Documentation

◆ m_atRndmSvc

ServiceHandle<IAtRndmGenSvc> BkgStreamsCache::m_atRndmSvc
private

IAtRndmGenSvc controlling the distribution of bkg events per bunch crossing.

Definition at line 119 of file BkgStreamsCache.h.

◆ m_beamInt

IBeamIntensity* BkgStreamsCache::m_beamInt
private

pointer to the IBeamIntensity distribution tool

Definition at line 151 of file BkgStreamsCache.h.

◆ m_chooseEventRand

CLHEP::RandFlat* BkgStreamsCache::m_chooseEventRand
private

pickup an event store at random from the cache

Definition at line 135 of file BkgStreamsCache.h.

◆ m_collDistrName

Gaudi::Property<std::string> BkgStreamsCache::m_collDistrName
private

select collision distribution

Definition at line 114 of file BkgStreamsCache.h.

◆ m_collXing

Gaudi::Property<float> BkgStreamsCache::m_collXing
private

of collisions per bunch crossing (~beam intensity)

Definition at line 110 of file BkgStreamsCache.h.

◆ m_collXingPoisson

CLHEP::RandPoisson* BkgStreamsCache::m_collXingPoisson
private

set number of collisions per bunch crossing (if Poisson distribution chosen)

Definition at line 137 of file BkgStreamsCache.h.

◆ m_collXingSF

float BkgStreamsCache::m_collXingSF
private

float scaling number of collisions per bunch crossing

Definition at line 145 of file BkgStreamsCache.h.

◆ m_cursor

StreamVector::iterator BkgStreamsCache::m_cursor
private

Definition at line 100 of file BkgStreamsCache.h.

◆ m_f_collDistr

std::function< long() > BkgStreamsCache::m_f_collDistr
private

function returning the number of collisions per bunch crossing before bunch structure modulation

Definition at line 140 of file BkgStreamsCache.h.

◆ m_f_numberOfBackgroundForBunchCrossing

std::function< unsigned int(unsigned int) > BkgStreamsCache::m_f_numberOfBackgroundForBunchCrossing
private

function returning the number of bkg events per bunch crossing after bunch structure modulation

Definition at line 143 of file BkgStreamsCache.h.

◆ m_forceReadForBC0

Gaudi::Property<bool> BkgStreamsCache::m_forceReadForBC0
private

Force events used in the central bunch crossing to be refreshed.

Definition at line 153 of file BkgStreamsCache.h.

◆ m_ignoreBM

Gaudi::Property<bool> BkgStreamsCache::m_ignoreBM
private

ignore the PileUpEventLoopMgr beam intensity tool

Definition at line 130 of file BkgStreamsCache.h.

◆ m_ignoreSF

Gaudi::Property<bool> BkgStreamsCache::m_ignoreSF
private

bool apply scaling number of collisions per bunch crossing ?

Definition at line 147 of file BkgStreamsCache.h.

◆ m_nEvtsXing

std::vector<unsigned int> BkgStreamsCache::m_nEvtsXing
private

Definition at line 105 of file BkgStreamsCache.h.

◆ m_nStores

unsigned int BkgStreamsCache::m_nStores
private

Definition at line 104 of file BkgStreamsCache.h.

◆ m_nXings

unsigned int BkgStreamsCache::m_nXings
private

Definition at line 103 of file BkgStreamsCache.h.

◆ m_occupationFraction

Gaudi::Property<float> BkgStreamsCache::m_occupationFraction
private

The maximum fraction of bunch-crossings which will be occupied.

Definition at line 112 of file BkgStreamsCache.h.

◆ m_pileUpEventType

xAOD::EventInfo::PileUpType BkgStreamsCache::m_pileUpEventType
private

the type of events in this cache

Definition at line 126 of file BkgStreamsCache.h.

◆ m_pileUpEventTypeProp

Gaudi::CheckedProperty<unsigned short> BkgStreamsCache::m_pileUpEventTypeProp
private

the type of events in this cache

Definition at line 123 of file BkgStreamsCache.h.

◆ m_randomStreamName

Gaudi::Property<std::string> BkgStreamsCache::m_randomStreamName
private

the IAtRndmGenSvc stream to generate number of bkg events per bunch crossing

Definition at line 121 of file BkgStreamsCache.h.

◆ m_readDownscale

Gaudi::Property<float> BkgStreamsCache::m_readDownscale
private

read downscale factor (average number of times a min bias is reused)

Definition at line 117 of file BkgStreamsCache.h.

◆ m_readEventRand

CLHEP::RandFlat* BkgStreamsCache::m_readEventRand
private

read a new event every downscaleFactor accesses

Definition at line 133 of file BkgStreamsCache.h.

◆ m_selecName

ServiceHandle<IEvtSelector> BkgStreamsCache::m_selecName
private

Definition at line 115 of file BkgStreamsCache.h.

◆ m_streams

StreamVector BkgStreamsCache::m_streams
private

Definition at line 101 of file BkgStreamsCache.h.

◆ m_subtractBC0

Gaudi::Property<unsigned short> BkgStreamsCache::m_subtractBC0
private

subtract from number of events at bunch xing = 0

Definition at line 128 of file BkgStreamsCache.h.

◆ m_usedStreams

std::vector<bool> BkgStreamsCache::m_usedStreams
private

Definition at line 102 of file BkgStreamsCache.h.

◆ m_zeroXing

int BkgStreamsCache::m_zeroXing
private

offset of BC=0 xing

Definition at line 149 of file BkgStreamsCache.h.


The documentation for this class was generated from the following files:
c_pileUpEventInfoContName
const std::string c_pileUpEventInfoContName
default value for the EventInfoContainer storing subevents for PileUp
Definition: PileUpMisc.h:15
BkgStreamsCache::PileUpEventTypeHandler
void PileUpEventTypeHandler(Gaudi::Details::PropertyBase &)
Definition: BkgStreamsCache.cxx:80
BkgStreamsCache::m_cursor
StreamVector::iterator m_cursor
Definition: BkgStreamsCache.h:100
BkgStreamsCache::nextEvent_passive
StatusCode nextEvent_passive(bool isCentralBunchCrossing)
as nextEvent except don't actually load anything
Definition: BkgStreamsCache.cxx:212
BkgStreamsCache::m_pileUpEventTypeProp
Gaudi::CheckedProperty< unsigned short > m_pileUpEventTypeProp
the type of events in this cache
Definition: BkgStreamsCache.h:123
xAOD::EventInfo_v1::PileUp_NTYPES
@ PileUp_NTYPES
Definition: EventInfo_v1.h:272
BkgStreamsCache::m_ignoreBM
Gaudi::Property< bool > m_ignoreBM
ignore the PileUpEventLoopMgr beam intensity tool
Definition: BkgStreamsCache.h:130
BkgStreamsCache::m_chooseEventRand
CLHEP::RandFlat * m_chooseEventRand
pickup an event store at random from the cache
Definition: BkgStreamsCache.h:135
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.
IBeamIntensity::largestElementInPattern
virtual float largestElementInPattern() const =0
the largest element in the beam intensity pattern.
BkgStreamsCache::m_nEvtsXing
std::vector< unsigned int > m_nEvtsXing
Definition: BkgStreamsCache.h:105
BkgStreamsCache::m_atRndmSvc
ServiceHandle< IAtRndmGenSvc > m_atRndmSvc
IAtRndmGenSvc controlling the distribution of bkg events per bunch crossing.
Definition: BkgStreamsCache.h:119
BkgStreamsCache::m_pileUpEventType
xAOD::EventInfo::PileUpType m_pileUpEventType
the type of events in this cache
Definition: BkgStreamsCache.h:126
BkgStreamsCache::numberOfBkgForBunchCrossingDefaultImpl
unsigned int numberOfBkgForBunchCrossingDefaultImpl(unsigned int iXing) const
Definition: BkgStreamsCache.cxx:324
BkgStreamsCache::m_f_numberOfBackgroundForBunchCrossing
std::function< unsigned int(unsigned int) > m_f_numberOfBackgroundForBunchCrossing
function returning the number of bkg events per bunch crossing after bunch structure modulation
Definition: BkgStreamsCache.h:143
BkgStreamsCache::m_collXingSF
float m_collXingSF
float scaling number of collisions per bunch crossing
Definition: BkgStreamsCache.h:145
BkgStreamsCache::m_subtractBC0
Gaudi::Property< unsigned short > m_subtractBC0
subtract from number of events at bunch xing = 0
Definition: BkgStreamsCache.h:128
BkgStreamsCache::m_nStores
unsigned int m_nStores
Definition: BkgStreamsCache.h:104
BkgStreamsCache::m_forceReadForBC0
Gaudi::Property< bool > m_forceReadForBC0
Force events used in the central bunch crossing to be refreshed.
Definition: BkgStreamsCache.h:153
BkgStreamsCache::m_occupationFraction
Gaudi::Property< float > m_occupationFraction
The maximum fraction of bunch-crossings which will be occupied.
Definition: BkgStreamsCache.h:112
BkgStreamsCache::m_f_collDistr
std::function< long() > m_f_collDistr
function returning the number of collisions per bunch crossing before bunch structure modulation
Definition: BkgStreamsCache.h:140
BkgStreamsCache::m_collXing
Gaudi::Property< float > m_collXing
Definition: BkgStreamsCache.h:110
trigbs_truncateEvents.readEvent
def readEvent(file)
Definition: trigbs_truncateEvents.py:10
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
BkgStreamsCache::nEvtsXing
unsigned int nEvtsXing(unsigned int iXing) const
Definition: BkgStreamsCache.cxx:315
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
BkgStreamsCache::m_beamInt
IBeamIntensity * m_beamInt
pointer to the IBeamIntensity distribution tool
Definition: BkgStreamsCache.h:151
StoreGateSvc::retrieve
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
PixelByteStreamErrors::BCID
@ BCID
Definition: PixelByteStreamErrors.h:13
IBeamIntensity::normFactor
virtual float normFactor(int bunchXing) const =0
a scale factor (average value 1.0) for the beam intensity at a given xing.
BkgStreamsCache::m_collDistrName
Gaudi::Property< std::string > m_collDistrName
select collision distribution
Definition: BkgStreamsCache.h:114
BkgStreamsCache::alreadyInUse
bool alreadyInUse(StreamVector::size_type iStream)
Definition: BkgStreamsCache.cxx:237
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
python.PileUpEventType.Signal
int Signal
Definition: PileUpEventType.py:3
lumiFormat.i
int i
Definition: lumiFormat.py:92
BkgStreamsCache::m_readDownscale
Gaudi::Property< float > m_readDownscale
read downscale factor (average number of times a min bias is reused)
Definition: BkgStreamsCache.h:117
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
BkgStreamsCache::m_ignoreSF
Gaudi::Property< bool > m_ignoreSF
bool apply scaling number of collisions per bunch crossing ?
Definition: BkgStreamsCache.h:147
test_pyathena.parent
parent
Definition: test_pyathena.py:15
PileUpStream
a triple selector/context/store defines a stream
Definition: PileUpStream.h:33
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
BkgStreamsCache::m_nXings
unsigned int m_nXings
Definition: BkgStreamsCache.h:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
BkgStreamsCache::numberOfCavernBkgForBunchCrossing
unsigned int numberOfCavernBkgForBunchCrossing(unsigned int iXing) const
Definition: BkgStreamsCache.cxx:328
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
BkgStreamsCache::m_zeroXing
int m_zeroXing
offset of BC=0 xing
Definition: BkgStreamsCache.h:149
BkgStreamsCache::collXing
long collXing()
meant to be used (mainly) via m_f_collDistr
Definition: BkgStreamsCache.h:81
BkgStreamsCache::m_collXingPoisson
CLHEP::RandPoisson * m_collXingPoisson
set number of collisions per bunch crossing (if Poisson distribution chosen)
Definition: BkgStreamsCache.h:137
BkgStreamsCache::m_selecName
ServiceHandle< IEvtSelector > m_selecName
Definition: BkgStreamsCache.h:115
BkgStreamsCache::setNEvtsXing
unsigned int setNEvtsXing(unsigned int iXing)
Definition: BkgStreamsCache.cxx:333
BkgStreamsCache::collXingPoisson
long collXingPoisson()
Definition: BkgStreamsCache.cxx:159
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
xAOD::EventInfo_v1::PileUpInt2Type
static PileUpType PileUpInt2Type(unsigned short typ)
Convert int to PileUpType enum value.
Definition: EventInfo_v1.cxx:672
AthenaPoolExample_Copy.streamName
string streamName
Definition: AthenaPoolExample_Copy.py:39
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
BkgStreamsCache::current
PileUpStream * current()
get current (last asked) stream
Definition: BkgStreamsCache.cxx:249
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
xAOD::EventInfo_v1::PileUpType2Name
static const std::string & PileUpType2Name(PileUpType typ)
Convert PileUpType enum value to string.
Definition: EventInfo_v1.cxx:658
BkgStreamsCache::m_usedStreams
std::vector< bool > m_usedStreams
Definition: BkgStreamsCache.h:102
BkgStreamsCache::addSubEvts
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.
Definition: BkgStreamsCache.cxx:357
BkgStreamsCache::numberOfBkgForBunchCrossingIgnoringBeamIntensity
unsigned int numberOfBkgForBunchCrossingIgnoringBeamIntensity(unsigned int iXing) const
meant to be used via m_f_numberOfBackgroundForBunchCrossing
Definition: BkgStreamsCache.cxx:320
BkgStreamsCache::m_randomStreamName
Gaudi::Property< std::string > m_randomStreamName
the IAtRndmGenSvc stream to generate number of bkg events per bunch crossing
Definition: BkgStreamsCache.h:121
addSubEvent
xAOD::EventInfo * addSubEvent(xAOD::EventInfo *targetEv, const xAOD::EventInfo::SubEvent &subev, xAOD::EventInfoContainer *eiContainer, const std::string &eiContKey, StoreGateSvc *subev_store=nullptr)
Definition: PileUpMisc.cxx:17
BkgStreamsCache::m_streams
StreamVector m_streams
Definition: BkgStreamsCache.h:101
BkgStreamsCache::nextEvent
const xAOD::EventInfo * nextEvent(bool isCentralBunchCrossing)
get next bkg event from cache
Definition: BkgStreamsCache.cxx:185
BkgStreamsCache::m_readEventRand
CLHEP::RandFlat * m_readEventRand
read a new event every downscaleFactor accesses
Definition: BkgStreamsCache.h:133