ATLAS Offline Software
BkgStreamsCache.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef PILEUPTOOLS_BKGSTREAMSCACHE_H
6 # define PILEUPTOOLS_BKGSTREAMSCACHE_H
7 
13 #include <string>
14 #include <vector>
15 #include <functional>
16 
19 #include "GaudiKernel/ServiceHandle.h"
20 #include "Gaudi/Property.h"
23 
24 class IEvtSelector;
25 class IBeamIntensity;
26 namespace CLHEP {
27  class RandFlat;
28  class RandPoisson;
29 }
30 
31 
36  public extends<AthAlgTool, IBkgStreamsCache>
37 {
38 public:
39  BkgStreamsCache( const std::string&, const std::string&, const IInterface*);
40  virtual ~BkgStreamsCache();
41 
42  virtual StatusCode initialize() override final;
43  virtual StatusCode finalize() override final;
48  virtual StatusCode setup(int firstXing,
49  unsigned int nXings,
50  unsigned int firstStore,
51  IBeamIntensity*) override final;
53  virtual void newEvent() override final;
55  virtual void resetEvtsPerXingScaleFactor(float sf) override final;
62  virtual StatusCode addSubEvts(unsigned int iXing,
63  xAOD::EventInfo* overlaidEvent,
64  int t0BinCenter) override final;
73  virtual StatusCode addSubEvts(unsigned int iXing,
74  xAOD::EventInfo* overEvent,
75  int t0BinCenter, bool loadEventProxies, unsigned int /*BCID*/) override final;
77  virtual unsigned int nStores() const override final { return m_nStores; }
78 
80  long collXing() { return m_collXing; }
81  long collXingPoisson();
83  unsigned int numberOfBkgForBunchCrossingIgnoringBeamIntensity(unsigned int iXing) const;
84  unsigned int numberOfBkgForBunchCrossingDefaultImpl(unsigned int iXing) const;
85  unsigned int numberOfCavernBkgForBunchCrossing(unsigned int iXing) const;
86 private:
88  const xAOD::EventInfo* nextEvent(bool isCentralBunchCrossing);
90  StatusCode nextEvent_passive(bool isCentralBunchCrossing);
93 
94  unsigned int setNEvtsXing(unsigned int iXing);
95  unsigned int nEvtsXing(unsigned int iXing) const;
96 
97  typedef std::vector<PileUpStream> StreamVector;
98  bool alreadyInUse(StreamVector::size_type iStream);
101  std::vector<bool> m_usedStreams;
102  unsigned int m_nXings{0};
103  unsigned int m_nStores{0};
104  std::vector<unsigned int> m_nEvtsXing;
105 
106  ServiceHandle<IEvtSelector> m_selecName{this, "EventSelector", "FakeEventSelector"};
107 
108  ServiceHandle<IAtRndmGenSvc> m_atRndmSvc{this, "RndmGenSvc", "AtRndmGenSvc",
109  "IAtRndmGenSvc controlling the distribution of bkg events/xing"};
110 
111  Gaudi::Property<float> m_collXing{this, "CollPerXing", 23.0,
112  "(average) number of collisions per beam crossing"};
113 
114  Gaudi::Property<float> m_occupationFraction{this, "OccupationFraction", 1.0,
115  "The maximum fraction of bunch-crossings which will be occupied."};
116 
117  Gaudi::Property<std::string> m_collDistrName{this, "CollDistribution", "Poisson",
118  "nEvts/Xings can be either Fixed at CollPerXing or Poisson with average CollPerXing"};
119 
120  Gaudi::Property<float> m_readDownscale{this, "ReadDownscaleFactor", 150,
121  "read one event every downscaleFactor accesses (asymptotically -> number of times "
122  "an event in the cache will be reused)"};
123 
124  Gaudi::Property<std::string> m_randomStreamName{this, "RndmStreamName", "PileUpCollXingStream",
125  "IAtRndmGenSvc stream used as engine for our various random distributions, including the CollPerXing one "};
126 
127  Gaudi::CheckedProperty<unsigned short> m_pileUpEventTypeProp{this, "PileUpEventType", 0,
129  "Type of the pileup events in this cache: 0:Signal, 1:MinimumBias, 2:Cavern, 3:HaloGas, "
130  "4:ZeroBias. Default=0 (Signal, Invalid)"};
131  void PileUpEventTypeHandler(Gaudi::Details::PropertyBase&);
132 
133  Gaudi::Property<unsigned short> m_subtractBC0{this, "SubtractBC0", 0,
134  "reduce the number of events at bunch xing t=0 by m_subtractBC0. Default=0, set to 1 when "
135  "using the same type of events (e.g. minbias) for original and background streams"};
136 
137  Gaudi::Property<bool> m_ignoreBM{this, "IgnoreBeamInt", false,
138  "Default=False, set to True to ignore the PileUpEventLoopMgr beam intensity "
139  "tool in setting the number of events per xing."};
140 
141  Gaudi::Property<bool> m_ignoreSF{this, "IgnoreBeamLumi", false,
142  "Default=False, set to True to ignore the PileUpEventLoopMgr beam luminosity "
143  "tool in setting the number of events per xing."};
144 
145  Gaudi::Property<bool> m_forceReadForBC0{this, "ForceReadForBC0", true,
146  "Force events used in the central bunch crossing to be refreshed"};
147 
151  CLHEP::RandFlat* m_readEventRand{nullptr};
153  CLHEP::RandFlat* m_chooseEventRand{nullptr};
155  CLHEP::RandPoisson* m_collXingPoisson{nullptr};
158  std::function< long() > m_f_collDistr;
161  std::function< unsigned int(unsigned int) > m_f_numberOfBackgroundForBunchCrossing;
163  float m_collXingSF{1.0};
165  int m_zeroXing{-1};
168 
169 };
170 
171 #endif // PILEUPTOOLS_BKGSTREAMSCACHE_H
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
BkgStreamsCache::finalize
virtual StatusCode finalize() override final
Definition: BkgStreamsCache.cxx:386
BkgStreamsCache::PileUpEventTypeHandler
void PileUpEventTypeHandler(Gaudi::Details::PropertyBase &)
Definition: BkgStreamsCache.cxx:42
BkgStreamsCache::m_cursor
StreamVector::iterator m_cursor
Definition: BkgStreamsCache.h:99
BkgStreamsCache::nextEvent_passive
StatusCode nextEvent_passive(bool isCentralBunchCrossing)
as nextEvent except don't actually load anything
Definition: BkgStreamsCache.cxx:174
BkgStreamsCache::m_pileUpEventTypeProp
Gaudi::CheckedProperty< unsigned short > m_pileUpEventTypeProp
Definition: BkgStreamsCache.h:127
BkgStreamsCache::m_ignoreBM
Gaudi::Property< bool > m_ignoreBM
Definition: BkgStreamsCache.h:137
BkgStreamsCache::m_chooseEventRand
CLHEP::RandFlat * m_chooseEventRand
pickup an event store at random from the cache
Definition: BkgStreamsCache.h:153
BkgStreamsCache::m_nEvtsXing
std::vector< unsigned int > m_nEvtsXing
Definition: BkgStreamsCache.h:104
BkgStreamsCache::m_atRndmSvc
ServiceHandle< IAtRndmGenSvc > m_atRndmSvc
Definition: BkgStreamsCache.h:108
BkgStreamsCache::m_pileUpEventType
xAOD::EventInfo::PileUpType m_pileUpEventType
the type of events in this cache
Definition: BkgStreamsCache.h:149
BkgStreamsCache::numberOfBkgForBunchCrossingDefaultImpl
unsigned int numberOfBkgForBunchCrossingDefaultImpl(unsigned int iXing) const
Definition: BkgStreamsCache.cxx:286
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:161
BkgStreamsCache::m_collXingSF
float m_collXingSF
float scaling number of collisions per bunch crossing
Definition: BkgStreamsCache.h:163
BkgStreamsCache::m_subtractBC0
Gaudi::Property< unsigned short > m_subtractBC0
Definition: BkgStreamsCache.h:133
BkgStreamsCache::StreamVector
std::vector< PileUpStream > StreamVector
Definition: BkgStreamsCache.h:97
BkgStreamsCache::m_nStores
unsigned int m_nStores
Definition: BkgStreamsCache.h:103
BkgStreamsCache::m_forceReadForBC0
Gaudi::Property< bool > m_forceReadForBC0
Definition: BkgStreamsCache.h:145
BkgStreamsCache::m_occupationFraction
Gaudi::Property< float > m_occupationFraction
Definition: BkgStreamsCache.h:114
xAOD::EventInfo_v1::PileUpType
PileUpType
Enumerator describing the types of pileup events.
Definition: EventInfo_v1.h:264
BkgStreamsCache::nStores
virtual unsigned int nStores() const override final
how many stores in this cache
Definition: BkgStreamsCache.h:77
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:158
BkgStreamsCache::m_collXing
Gaudi::Property< float > m_collXing
Definition: BkgStreamsCache.h:111
BkgStreamsCache::setup
virtual StatusCode setup(int firstXing, unsigned int nXings, unsigned int firstStore, IBeamIntensity *) override final
Definition: BkgStreamsCache.cxx:48
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
BkgStreamsCache::nEvtsXing
unsigned int nEvtsXing(unsigned int iXing) const
Definition: BkgStreamsCache.cxx:277
BkgStreamsCache::m_beamInt
IBeamIntensity * m_beamInt
pointer to the IBeamIntensity distribution tool
Definition: BkgStreamsCache.h:167
BkgStreamsCache::m_collDistrName
Gaudi::Property< std::string > m_collDistrName
Definition: BkgStreamsCache.h:117
BkgStreamsCache::alreadyInUse
bool alreadyInUse(StreamVector::size_type iStream)
Definition: BkgStreamsCache.cxx:199
BkgStreamsCache::m_readDownscale
Gaudi::Property< float > m_readDownscale
Definition: BkgStreamsCache.h:120
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
BkgStreamsCache::m_ignoreSF
Gaudi::Property< bool > m_ignoreSF
Definition: BkgStreamsCache.h:141
CLHEP
STD'S.
Definition: CaloNoiseCompCondAlg.h:58
BkgStreamsCache
In-memory cache for pileup events.
Definition: BkgStreamsCache.h:37
AthAlgTool.h
BkgStreamsCache::resetEvtsPerXingScaleFactor
virtual void resetEvtsPerXingScaleFactor(float sf) override final
reset scale factor at new run/lumiblk
Definition: BkgStreamsCache.cxx:116
PileUpStream
a triple selector/context/store defines a stream
Definition: PileUpStream.h:32
BkgStreamsCache::m_nXings
unsigned int m_nXings
Definition: BkgStreamsCache.h:102
columnar::final
CM final
Definition: ColumnAccessor.h:106
BkgStreamsCache::initialize
virtual StatusCode initialize() override final
Definition: BkgStreamsCache.cxx:218
BkgStreamsCache::numberOfCavernBkgForBunchCrossing
unsigned int numberOfCavernBkgForBunchCrossing(unsigned int iXing) const
Definition: BkgStreamsCache.cxx:290
IAtRndmGenSvc.h
BkgStreamsCache::m_zeroXing
int m_zeroXing
offset of BC=0 xing
Definition: BkgStreamsCache.h:165
BkgStreamsCache::collXing
long collXing()
meant to be used (mainly) via m_f_collDistr
Definition: BkgStreamsCache.h:80
BkgStreamsCache::m_collXingPoisson
CLHEP::RandPoisson * m_collXingPoisson
set number of collisions per bunch crossing (if Poisson distribution chosen)
Definition: BkgStreamsCache.h:155
BkgStreamsCache::m_selecName
ServiceHandle< IEvtSelector > m_selecName
Definition: BkgStreamsCache.h:106
BkgStreamsCache::setNEvtsXing
unsigned int setNEvtsXing(unsigned int iXing)
Definition: BkgStreamsCache.cxx:295
BkgStreamsCache::collXingPoisson
long collXingPoisson()
Definition: BkgStreamsCache.cxx:121
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
BkgStreamsCache::current
PileUpStream * current()
get current (last asked) stream
Definition: BkgStreamsCache.cxx:211
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
PileUpStream.h
a triple selector/context/store defines a stream
IBeamIntensity
Definition: IBeamIntensity.h:17
BkgStreamsCache::m_usedStreams
std::vector< bool > m_usedStreams
Definition: BkgStreamsCache.h:101
IBkgStreamsCache.h
Interface to in-memory cache for pileup events.
BkgStreamsCache::~BkgStreamsCache
virtual ~BkgStreamsCache()
Definition: BkgStreamsCache.cxx:34
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:319
BkgStreamsCache::BkgStreamsCache
BkgStreamsCache(const std::string &, const std::string &, const IInterface *)
Definition: BkgStreamsCache.cxx:26
BkgStreamsCache::newEvent
virtual void newEvent() override final
inform cache that we start overlaying a new event
Definition: BkgStreamsCache.cxx:127
BkgStreamsCache::numberOfBkgForBunchCrossingIgnoringBeamIntensity
unsigned int numberOfBkgForBunchCrossingIgnoringBeamIntensity(unsigned int iXing) const
meant to be used via m_f_numberOfBackgroundForBunchCrossing
Definition: BkgStreamsCache.cxx:282
BkgStreamsCache::m_randomStreamName
Gaudi::Property< std::string > m_randomStreamName
Definition: BkgStreamsCache.h:124
BkgStreamsCache::m_streams
StreamVector m_streams
Definition: BkgStreamsCache.h:100
ServiceHandle< IEvtSelector >
BkgStreamsCache::nextEvent
const xAOD::EventInfo * nextEvent(bool isCentralBunchCrossing)
get next bkg event from cache
Definition: BkgStreamsCache.cxx:147
BkgStreamsCache::m_readEventRand
CLHEP::RandFlat * m_readEventRand
read a new event every downscaleFactor accesses
Definition: BkgStreamsCache.h:151