33 #include <CLHEP/Random/RandomEngine.h>
61 :
firstRun_(ps.getParameter<unsigned int>(
"firstRun")),
65 if (p < 0. or p > 1.) {
67 <<
". The probability must be >= 0. and <= 1.";
74 unsigned int bin =
static_cast<unsigned int>(pileup);
77 <<
"Got pileup event with true pileup " << pileup
78 <<
" that is outside of the configured pileup adjustment bounds [" <<
firstBinPileup_ <<
", "
102 std::vector<std::unique_ptr<PreMixingWorker>>
workers_;
109 consumesCollector()),
114 return a.firstRun() <
b.firstRun();
124 std::vector<std::string>
tmp;
127 if (
i != names.end()) {
136 std::copy(names.begin(), names.end(), std::back_inserter(tmp));
140 for (
const auto&
name : names) {
141 if (
name ==
"pileup") {
153 w->initializeEvent(e, ES);
160 w->beginRun(run, ES);
174 LogDebug(
"PreMixingModule") <<
"===============> adding MC signals for " << e.
id();
177 w->addSignals(e, ES);
196 if (pileupAdjuster) {
198 double prob = pileupAdjuster->
probability(static_cast<unsigned int>(trueNumInteractions));
201 if (engine.flat() > prob) {
208 LogDebug(
"PreMixingModule") <<
"\n===============> adding pileups from event " << ep.
id() <<
" for bunchcrossing "
225 w->addPileups(pep, ES);
232 using namespace std::placeholders;
234 std::vector<edm::SecondaryEventIDAndFileInfo> recordEventID;
235 std::vector<int> PileupList;
247 [iRun = e.
id().
run()](
const auto& elem) {
return elem.firstRun() <= iRun; });
250 <<
", but the first run available in the pileup adjustment configuration is "
251 <<
pileupAdjusters_.front().firstRun() <<
". Please fix the configuration.";
253 pileupAdjuster = &*it;
257 for (
unsigned int isource = 0; isource <
maxNbSources_; ++isource) {
259 if (!source || !(source->doPileUp(bunchCrossing)))
265 int NumPU_Events = 0;
267 NumPU_Events = PileupList[bunchCrossing -
minBunch_];
274 w->initializeBunchCrossing(e, ES, bunchCrossing);
285 for (
auto&
w : workers_) {
286 w->finalizeBunchCrossing(e, ES, bunchCrossing);
299 w->put(e, ES, ps, bunchSpacing);
308 w->beginLuminosityBlock(l1, c);
void createnewEDProduct() override
std::vector< double > pileupProbabilities_
void beginRun(const edm::Run &r, const edm::EventSetup &setup) override
const edm::EventSetup & c
static std::string const source("source")
edm::RunNumber_t firstRun() const
#define DEFINE_FWK_MODULE(type)
void endRun(const edm::Run &r, const edm::EventSetup &setup) override
EventID const & id() const
void beginRun(edm::Run const &run, edm::EventSetup const &eventSetup) override
void putPileupInfo(edm::Event &e)
edm::RunNumber_t firstRun_
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
void endRun(const edm::Run &r, const edm::EventSetup &setup) override
bool pileWorker(const edm::EventPrincipal &, int bcr, int EventId, const edm::EventSetup &ES, ModuleCallingContext const *, AdjustPileupDistribution const *pileupAdjuster)
unsigned int firstBinPileup_
void initializeEvent(edm::Event const &e, edm::EventSetup const &eventSetup) override
void endLuminosityBlock(LuminosityBlock const &l1, EventSetup const &c) override
void addPileupInfo(PileUpEventPrincipal const &pep)
ModuleCallingContext const * moduleCallingContext() const
AdjustPileupDistribution(const edm::ParameterSet &ps)
StreamID streamID() const
void put(edm::Event &e, const edm::EventSetup &ES) override
double probability(float pileup) const
static const unsigned int maxNbSources_
std::vector< std::string > names
std::vector< float > TrueNumInteractions_
void beginLuminosityBlock(LuminosityBlock const &l1, EventSetup const &c) override
float getTrueNumInteractions(PileUpEventPrincipal const &pep) const
int getBunchSpacing() const
~PreMixingModule() override=default
std::vector< std::shared_ptr< PileUp > > inputSources_
std::vector< std::unique_ptr< PreMixingWorker > > workers_
void checkSignal(const edm::Event &e) override
void addSignals(const edm::Event &e, const edm::EventSetup &ES) override
StreamID streamID() const
std::vector< AdjustPileupDistribution > pileupAdjusters_
Log< level::Warning, false > LogWarning
void beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override
PreMixingPileupCopy puWorker_
const std::vector< PileupSummaryInfo > & getPileupSummaryInfo() const
void setupPileUpEvent(const edm::EventSetup &setup)
void endLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override
PreMixingModule(const edm::ParameterSet &ps, MixingCache::Config const *globalConf)
void doPileUp(edm::Event &e, const edm::EventSetup &ES) override