CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
edm::PreMixingModule Class Reference
Inheritance diagram for edm::PreMixingModule:
edm::BMixingModule edm::stream::EDProducer< GlobalCache< MixingCache::Config > >

Classes

class  AdjustPileupDistribution
 

Public Member Functions

void addSignals (const edm::Event &e, const edm::EventSetup &ES) override
 
void beginLuminosityBlock (LuminosityBlock const &l1, EventSetup const &c) override
 
void beginRun (edm::Run const &run, edm::EventSetup const &eventSetup) override
 
void checkSignal (const edm::Event &e) override
 
void createnewEDProduct () override
 
void doPileUp (edm::Event &e, const edm::EventSetup &ES) override
 
void endLuminosityBlock (LuminosityBlock const &l1, EventSetup const &c) override
 
void endRun (const edm::Run &r, const edm::EventSetup &setup) override
 
void initializeEvent (edm::Event const &e, edm::EventSetup const &eventSetup) override
 
 PreMixingModule (const edm::ParameterSet &ps, MixingCache::Config const *globalConf)
 
void put (edm::Event &e, const edm::EventSetup &ES) override
 
 ~PreMixingModule () override=default
 
- Public Member Functions inherited from edm::BMixingModule
virtual void addPileups (const int bcr, EventPrincipal *ep, unsigned int eventId, unsigned int worker, const edm::EventSetup &c)
 
double averageNumber () const
 
void beginLuminosityBlock (const edm::LuminosityBlock &l, const edm::EventSetup &setup) override
 
void beginRun (const edm::Run &r, const edm::EventSetup &setup) override
 
 BMixingModule (const edm::ParameterSet &ps, MixingCache::Config const *globalConf)
 
void endLuminosityBlock (const edm::LuminosityBlock &l, const edm::EventSetup &setup) override
 
void endRun (const edm::Run &r, const edm::EventSetup &setup) override
 
virtual void finalizeEvent (edm::Event &event, const edm::EventSetup &setup)
 
bool poisson () const
 
void produce (edm::Event &e1, const edm::EventSetup &c) override
 
void registerLateConsumes (eventsetup::ESRecordsToProductResolverIndices const &) override
 
virtual void reload (const edm::EventSetup &setup)
 
virtual void setBcrOffset ()
 
virtual void setSourceOffset (const unsigned int s)
 
 ~BMixingModule () override
 
- Public Member Functions inherited from edm::stream::EDProducer< GlobalCache< MixingCache::Config > >
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Member Functions

bool pileWorker (const edm::EventPrincipal &, int bcr, int EventId, const edm::EventSetup &ES, ModuleCallingContext const *, AdjustPileupDistribution const *pileupAdjuster)
 

Private Attributes

bool addedPileup_ = false
 
std::vector< AdjustPileupDistributionpileupAdjusters_
 
PreMixingPileupCopy puWorker_
 
std::vector< std::unique_ptr< PreMixingWorker > > workers_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer< GlobalCache< MixingCache::Config > >
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 
- Static Public Member Functions inherited from edm::BMixingModule
static void globalEndJob (MixingCache::Config *)
 
static std::unique_ptr< MixingCache::ConfiginitializeGlobalCache (edm::ParameterSet const &)
 
- Protected Member Functions inherited from edm::BMixingModule
void beginStream (edm::StreamID) override
 
void dropUnwantedBranches (std::vector< std::string > const &wantedBranches)
 
void endStream () override
 
void setupPileUpEvent (const edm::EventSetup &setup)
 
void update (edm::EventSetup const &)
 
- Protected Attributes inherited from edm::BMixingModule
int bunchSpace_
 
bool checktof_
 
bool doit_ [4]
 
unsigned int eventId_
 
std::vector< std::shared_ptr< PileUp > > inputSources_
 
int maxBunch_
 
int minBunch_
 
bool const mixProdStep1_
 
bool const mixProdStep2_
 
edm::ESWatcher< MixingRcdparameterWatcher_
 
bool playback_
 
bool readDB_
 
std::vector< float > TrueNumInteractions_
 
int vertexOffset_
 
- Static Protected Attributes inherited from edm::BMixingModule
static const unsigned int maxNbSources_ = 4
 

Detailed Description

Definition at line 39 of file PreMixingModule.cc.

Constructor & Destructor Documentation

◆ PreMixingModule()

PreMixingModule::PreMixingModule ( const edm::ParameterSet ps,
MixingCache::Config const *  globalConf 
)

Definition at line 105 of file PreMixingModule.cc.

106  : BMixingModule(ps, globalConf),
108  producesCollector(),
109  consumesCollector()),
111  edm::vector_transform(ps.getParameter<std::vector<edm::ParameterSet>>("adjustPileupDistribution"),
112  [](const auto& ps) { return AdjustPileupDistribution(ps); })) {
113  std::sort(pileupAdjusters_.begin(), pileupAdjusters_.end(), [](const auto& a, const auto& b) {
114  return a.firstRun() < b.firstRun();
115  });
116 
117  const auto& workers = ps.getParameter<edm::ParameterSet>("workers");
118  std::vector<std::string> names = workers.getParameterNames();
119 
120  // Hack to keep the random number sequence unchanged for migration
121  // from DataMixingModule to PreMixingModule. To be removed in a
122  // subsequent PR doing only that.
123  {
124  std::vector<std::string> tmp;
125  auto hack = [&](const std::string& name) {
126  auto i = std::find(names.begin(), names.end(), name);
127  if (i != names.end()) {
128  tmp.push_back(*i);
129  names.erase(i);
130  }
131  };
132  hack("ecal");
133  hack("hcal");
134  hack("strip");
135  hack("pixel");
136  std::copy(names.begin(), names.end(), std::back_inserter(tmp));
137  names = std::move(tmp);
138  }
139 
140  for (const auto& name : names) {
141  if (name == "pileup") {
142  continue;
143  }
144  const auto& pset = workers.getParameter<edm::ParameterSet>(name);
145  std::string type = pset.getParameter<std::string>("workerType");
146  workers_.emplace_back(
147  PreMixingWorkerFactory::get()->create(type, pset, producesCollector(), consumesCollector()));
148  }
149  }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
def create(alignables, pedeDump, additionalData, outputFile, config)
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 >
Definition: transform.h:11
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const std::string names[nVars_]
double b
Definition: hdecay.h:120
std::vector< std::unique_ptr< PreMixingWorker > > workers_
double a
Definition: hdecay.h:121
std::vector< AdjustPileupDistribution > pileupAdjusters_
#define get
PreMixingPileupCopy puWorker_
tmp
align.sh
Definition: createJobs.py:716
def move(src, dest)
Definition: eostools.py:511
BMixingModule(const edm::ParameterSet &ps, MixingCache::Config const *globalConf)

◆ ~PreMixingModule()

edm::PreMixingModule::~PreMixingModule ( )
overridedefault

Member Function Documentation

◆ addSignals()

void PreMixingModule::addSignals ( const edm::Event e,
const edm::EventSetup ES 
)
overridevirtual

Reimplemented from edm::BMixingModule.

Definition at line 171 of file PreMixingModule.cc.

References addedPileup_, MillePedeFileConverter_cfg::e, LogDebug, w(), and workers_.

171  {
172  // fill in maps of hits
173 
174  LogDebug("PreMixingModule") << "===============> adding MC signals for " << e.id();
175 
176  for (auto& w : workers_) {
177  w->addSignals(e, ES);
178  }
179 
180  addedPileup_ = false;
181  }
T w() const
std::vector< std::unique_ptr< PreMixingWorker > > workers_
#define LogDebug(id)

◆ beginLuminosityBlock()

void PreMixingModule::beginLuminosityBlock ( LuminosityBlock const &  l1,
EventSetup const &  c 
)
override

Definition at line 305 of file PreMixingModule.cc.

References edm::BMixingModule::beginLuminosityBlock(), HltBtagPostValidation_cff::c, w(), and workers_.

305  {
307  for (auto& w : workers_) {
308  w->beginLuminosityBlock(l1, c);
309  }
310  }
T w() const
std::vector< std::unique_ptr< PreMixingWorker > > workers_
void beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override

◆ beginRun()

void PreMixingModule::beginRun ( edm::Run const &  run,
edm::EventSetup const &  eventSetup 
)
override

Definition at line 157 of file PreMixingModule.cc.

References edm::BMixingModule::beginRun(), writedatasetfile::run, w(), and workers_.

157  {
159  for (auto& w : workers_) {
160  w->beginRun(run, ES);
161  }
162  }
void beginRun(const edm::Run &r, const edm::EventSetup &setup) override
T w() const
std::vector< std::unique_ptr< PreMixingWorker > > workers_

◆ checkSignal()

void edm::PreMixingModule::checkSignal ( const edm::Event e)
inlineoverridevirtual

Reimplemented from edm::BMixingModule.

Definition at line 45 of file PreMixingModule.cc.

45 {};

◆ createnewEDProduct()

void edm::PreMixingModule::createnewEDProduct ( )
inlineoverridevirtual

Reimplemented from edm::BMixingModule.

Definition at line 46 of file PreMixingModule.cc.

46 {}

◆ doPileUp()

void PreMixingModule::doPileUp ( edm::Event e,
const edm::EventSetup ES 
)
overridevirtual

Reimplemented from edm::BMixingModule.

Definition at line 231 of file PreMixingModule.cc.

References MillePedeFileConverter_cfg::e, Exception, edm::BMixingModule::inputSources_, edm::BMixingModule::maxBunch_, edm::BMixingModule::maxNbSources_, edm::BMixingModule::minBunch_, pileupAdjusters_, pileWorker(), edm::source(), edm::BMixingModule::TrueNumInteractions_, w(), and workers_.

231  {
232  using namespace std::placeholders;
233 
234  std::vector<edm::SecondaryEventIDAndFileInfo> recordEventID;
235  std::vector<int> PileupList;
236  TrueNumInteractions_.clear();
237 
238  ModuleCallingContext const* mcc = e.moduleCallingContext();
239 
240  AdjustPileupDistribution const* pileupAdjuster = nullptr;
241  if (not pileupAdjusters_.empty()) {
242  // Find the adjustment settings for the run of the signal event
243  // the container should be small-enough to not really gain
244  // anything with binary search
245  auto it = std::find_if(pileupAdjusters_.rbegin(),
246  pileupAdjusters_.rend(),
247  [iRun = e.id().run()](const auto& elem) { return elem.firstRun() <= iRun; });
248  if (it == pileupAdjusters_.rend()) {
249  throw cms::Exception("LogicError") << "Encountered run " << e.id().run()
250  << ", but the first run available in the pileup adjustment configuration is "
251  << pileupAdjusters_.front().firstRun() << ". Please fix the configuration.";
252  }
253  pileupAdjuster = &*it;
254  }
255 
256  for (int bunchCrossing = minBunch_; bunchCrossing <= maxBunch_; ++bunchCrossing) {
257  for (unsigned int isource = 0; isource < maxNbSources_; ++isource) {
258  std::shared_ptr<PileUp> source = inputSources_[isource];
259  if (!source || !(source->doPileUp(bunchCrossing)))
260  continue;
261 
262  if (isource == 0)
263  source->CalculatePileup(minBunch_, maxBunch_, PileupList, TrueNumInteractions_, e.streamID());
264 
265  int NumPU_Events = 0;
266  if (isource == 0) {
267  NumPU_Events = PileupList[bunchCrossing - minBunch_];
268  } else {
269  // non-minbias pileup only gets one event for now. Fix later if desired.
270  NumPU_Events = 1;
271  }
272 
273  for (auto& w : workers_) {
274  w->initializeBunchCrossing(e, ES, bunchCrossing);
275  }
276 
277  source->readPileUp(
278  e.id(),
279  recordEventID,
280  std::bind(
281  &PreMixingModule::pileWorker, std::ref(*this), _1, bunchCrossing, _2, std::cref(ES), mcc, pileupAdjuster),
282  NumPU_Events,
283  e.streamID());
284 
285  for (auto& w : workers_) {
286  w->finalizeBunchCrossing(e, ES, bunchCrossing);
287  }
288  }
289  }
290  }
static std::string const source("source")
T w() const
bool pileWorker(const edm::EventPrincipal &, int bcr, int EventId, const edm::EventSetup &ES, ModuleCallingContext const *, AdjustPileupDistribution const *pileupAdjuster)
static const unsigned int maxNbSources_
std::vector< float > TrueNumInteractions_
std::vector< std::shared_ptr< PileUp > > inputSources_
std::vector< std::unique_ptr< PreMixingWorker > > workers_
std::vector< AdjustPileupDistribution > pileupAdjusters_

◆ endLuminosityBlock()

void PreMixingModule::endLuminosityBlock ( LuminosityBlock const &  l1,
EventSetup const &  c 
)
override

Definition at line 312 of file PreMixingModule.cc.

References HltBtagPostValidation_cff::c, and edm::BMixingModule::endLuminosityBlock().

312  {
314  }
void endLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override

◆ endRun()

void PreMixingModule::endRun ( const edm::Run r,
const edm::EventSetup setup 
)
override

Definition at line 164 of file PreMixingModule.cc.

References edm::BMixingModule::endRun(), writedatasetfile::run, w(), and workers_.

164  {
165  for (auto& w : workers_) {
166  w->endRun();
167  }
169  }
T w() const
void endRun(const edm::Run &r, const edm::EventSetup &setup) override
std::vector< std::unique_ptr< PreMixingWorker > > workers_

◆ initializeEvent()

void PreMixingModule::initializeEvent ( edm::Event const &  e,
edm::EventSetup const &  eventSetup 
)
overridevirtual

Reimplemented from edm::BMixingModule.

Definition at line 151 of file PreMixingModule.cc.

References MillePedeFileConverter_cfg::e, w(), and workers_.

151  {
152  for (auto& w : workers_) {
153  w->initializeEvent(e, ES);
154  }
155  }
T w() const
std::vector< std::unique_ptr< PreMixingWorker > > workers_

◆ pileWorker()

bool PreMixingModule::pileWorker ( const edm::EventPrincipal ep,
int  bcr,
int  EventId,
const edm::EventSetup ES,
edm::ModuleCallingContext const *  mcc,
AdjustPileupDistribution const *  pileupAdjuster 
)
private

Definition at line 183 of file PreMixingModule.cc.

References addedPileup_, edm::PreMixingPileupCopy::addPileupInfo(), SiStripBadComponentsDQMServiceTemplate_cfg::ep, edm::RandomNumberGenerator::getEngine(), edm::PreMixingPileupCopy::getTrueNumInteractions(), LogDebug, TtFullHadEvtBuilder_cfi::prob, edm::PreMixingModule::AdjustPileupDistribution::probability(), puWorker_, edm::BMixingModule::setupPileUpEvent(), w(), and workers_.

Referenced by doPileUp().

188  {
189  InternalContext internalContext(ep.id(), mcc);
190  ParentContext parentContext(&internalContext);
191  ModuleCallingContext moduleCallingContext(&moduleDescription());
192  ModuleContextSentry moduleContextSentry(&moduleCallingContext, parentContext);
193 
194  PileUpEventPrincipal pep(ep, &moduleCallingContext, bcr);
195 
196  if (pileupAdjuster) {
197  float trueNumInteractions = puWorker_.getTrueNumInteractions(pep);
198  double prob = pileupAdjuster->probability(static_cast<unsigned int>(trueNumInteractions));
200  CLHEP::HepRandomEngine& engine = rng->getEngine(ep.streamID());
201  if (engine.flat() > prob) {
202  // engine.flat() should give a double in ]0,1[ range
203  // the choice above means that "prob = 1-ulp" is treatead as 1
204  return false;
205  }
206  }
207 
208  LogDebug("PreMixingModule") << "\n===============> adding pileups from event " << ep.id() << " for bunchcrossing "
209  << bcr;
210 
211  // Note: setupPileUpEvent may modify the run and lumi numbers of the EventPrincipal to match that of the primary event.
212  setupPileUpEvent(ES);
213 
214  // check and see if we need to copy the pileup information from
215  // secondary stream to the output stream
216  // We only have the pileup event here, so pick the first time and store the info
217  if (!addedPileup_) {
219  addedPileup_ = true;
220  }
221 
222  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
223 
224  for (auto& w : workers_) {
225  w->addPileups(pep, ES);
226  }
227 
228  return true;
229  }
T w() const
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
void addPileupInfo(PileUpEventPrincipal const &pep)
float getTrueNumInteractions(PileUpEventPrincipal const &pep) const
std::vector< std::unique_ptr< PreMixingWorker > > workers_
PreMixingPileupCopy puWorker_
void setupPileUpEvent(const edm::EventSetup &setup)
#define LogDebug(id)

◆ put()

void PreMixingModule::put ( edm::Event e,
const edm::EventSetup ES 
)
overridevirtual

Reimplemented from edm::BMixingModule.

Definition at line 292 of file PreMixingModule.cc.

References hltParticleFlowClusterECALL1Seeded_cfi::bunchSpacing, MillePedeFileConverter_cfg::e, edm::PreMixingPileupCopy::getBunchSpacing(), edm::PreMixingPileupCopy::getPileupSummaryInfo(), edm::PreMixingPileupCopy::putPileupInfo(), puWorker_, w(), and workers_.

292  {
293  // individual workers...
294  // move pileup first so we have access to the information for the put step
295  const auto& ps = puWorker_.getPileupSummaryInfo();
297 
298  for (auto& w : workers_) {
299  w->put(e, ES, ps, bunchSpacing);
300  }
301 
303  }
T w() const
void putPileupInfo(edm::Event &e)
const std::vector< PileupSummaryInfo > & getPileupSummaryInfo() const
std::vector< std::unique_ptr< PreMixingWorker > > workers_
PreMixingPileupCopy puWorker_

Member Data Documentation

◆ addedPileup_

bool edm::PreMixingModule::addedPileup_ = false
private

Definition at line 99 of file PreMixingModule.cc.

Referenced by addSignals(), and pileWorker().

◆ pileupAdjusters_

std::vector<AdjustPileupDistribution> edm::PreMixingModule::pileupAdjusters_
private

Definition at line 101 of file PreMixingModule.cc.

Referenced by doPileUp().

◆ puWorker_

PreMixingPileupCopy edm::PreMixingModule::puWorker_
private

Definition at line 98 of file PreMixingModule.cc.

Referenced by pileWorker(), and put().

◆ workers_

std::vector<std::unique_ptr<PreMixingWorker> > edm::PreMixingModule::workers_
private