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)
 
virtual void initializeEvent (const edm::Event &event, const edm::EventSetup &setup)
 
bool poisson () const
 
void produce (edm::Event &e1, const edm::EventSetup &c) 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
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

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 > >
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache 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 40 of file PreMixingModule.cc.

Constructor & Destructor Documentation

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

Definition at line 98 of file PreMixingModule.cc.

References a, b, popcon2dropbox::copy(), beamerCreator::create(), spr::find(), reco::get(), mps_fire::i, eostools::move(), dataset::name, names, pileupAdjusters_, muonDTDigis_cfi::pset, AlCaHLTBitMon_QueryRunRegistry::string, tmp, mixOne_premix_on_sim_cfi::workers, and workers_.

98  :
99  BMixingModule(ps, globalConf),
100  puWorker_(ps.getParameter<edm::ParameterSet>("workers").getParameter<edm::ParameterSet>("pileup"), *this, consumesCollector()),
101  pileupAdjusters_(edm::vector_transform(ps.getParameter<std::vector<edm::ParameterSet> >("adjustPileupDistribution"),
102  [](const auto& ps) { return AdjustPileupDistribution(ps); }))
103  {
104  std::sort(pileupAdjusters_.begin(), pileupAdjusters_.end(),
105  [](const auto& a, const auto& b) {
106  return a.firstRun() < b.firstRun();
107  });
108 
109  const auto& workers = ps.getParameter<edm::ParameterSet>("workers");
110  std::vector<std::string> names = workers.getParameterNames();
111 
112  // Hack to keep the random number sequence unchanged for migration
113  // from DataMixingModule to PreMixingModule. To be removed in a
114  // subsequent PR doing only that.
115  {
116  std::vector<std::string> tmp;
117  auto hack = [&](const std::string& name) {
118  auto i = std::find(names.begin(), names.end(), name);
119  if(i != names.end()) {
120  tmp.push_back(*i);
121  names.erase(i);
122  }
123  };
124  hack("ecal");
125  hack("hcal");
126  hack("strip");
127  hack("pixel");
128  std::copy(names.begin(), names.end(), std::back_inserter(tmp));
129  names = std::move(tmp);
130  }
131 
132  for(const auto& name: names) {
133  if(name == "pileup") {
134  continue;
135  }
136  const auto& pset = workers.getParameter<edm::ParameterSet>(name);
137  std::string type = pset.getParameter<std::string>("workerType");
138  workers_.emplace_back(PreMixingWorkerFactory::get()->create(type, pset, *this, consumesCollector()));
139  }
140  }
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
def copy(args, dbName)
def create(alignables, pedeDump, additionalData, outputFile, config)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
const std::string names[nVars_]
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
double b
Definition: hdecay.h:120
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::vector< std::unique_ptr< PreMixingWorker > > workers_
double a
Definition: hdecay.h:121
std::vector< AdjustPileupDistribution > pileupAdjusters_
PreMixingPileupCopy puWorker_
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55
BMixingModule(const edm::ParameterSet &ps, MixingCache::Config const *globalConf)
edm::PreMixingModule::~PreMixingModule ( )
overridedefault

Member Function Documentation

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

Reimplemented from edm::BMixingModule.

Definition at line 164 of file PreMixingModule.cc.

References addedPileup_, edm::EventBase::id(), LogDebug, w, and workers_.

Referenced by createnewEDProduct().

164  {
165  // fill in maps of hits
166 
167  LogDebug("PreMixingModule")<<"===============> adding MC signals for "<<e.id();
168 
169  for(auto& w: workers_) {
170  w->addSignals(e, ES);
171  }
172 
173  addedPileup_ = false;
174  }
#define LogDebug(id)
const double w
Definition: UKUtility.cc:23
edm::EventID id() const
Definition: EventBase.h:59
std::vector< std::unique_ptr< PreMixingWorker > > workers_
void PreMixingModule::beginLuminosityBlock ( LuminosityBlock const &  l1,
EventSetup const &  c 
)
override

Definition at line 296 of file PreMixingModule.cc.

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

Referenced by createnewEDProduct().

296  {
298  for(auto& w: workers_) {
299  w->beginLuminosityBlock(l1,c);
300  }
301  }
const double w
Definition: UKUtility.cc:23
std::vector< std::unique_ptr< PreMixingWorker > > workers_
void beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override
void PreMixingModule::beginRun ( edm::Run const &  run,
edm::EventSetup const &  eventSetup 
)
override

Definition at line 150 of file PreMixingModule.cc.

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

Referenced by createnewEDProduct().

150  {
152  for(auto& w: workers_) {
153  w->beginRun(run, ES);
154  }
155  }
void beginRun(const edm::Run &r, const edm::EventSetup &setup) override
const double w
Definition: UKUtility.cc:23
std::vector< std::unique_ptr< PreMixingWorker > > workers_
void edm::PreMixingModule::checkSignal ( const edm::Event e)
inlineoverridevirtual

Reimplemented from edm::BMixingModule.

Definition at line 46 of file PreMixingModule.cc.

46 {};
void edm::PreMixingModule::createnewEDProduct ( )
inlineoverridevirtual
void PreMixingModule::doPileUp ( edm::Event e,
const edm::EventSetup ES 
)
overridevirtual

Reimplemented from edm::BMixingModule.

Definition at line 220 of file PreMixingModule.cc.

References HTMLExport::elem(), Exception, edm::EventBase::id(), edm::BMixingModule::inputSources_, edm::BMixingModule::maxBunch_, edm::BMixingModule::maxNbSources_, edm::BMixingModule::minBunch_, edm::Event::moduleCallingContext(), pileupAdjusters_, pileWorker(), edm::EventID::run(), edm::source(), edm::Event::streamID(), edm::BMixingModule::TrueNumInteractions_, w, and workers_.

Referenced by createnewEDProduct().

221  {
222  using namespace std::placeholders;
223 
224  std::vector<edm::SecondaryEventIDAndFileInfo> recordEventID;
225  std::vector<int> PileupList;
226  TrueNumInteractions_.clear();
227 
228  ModuleCallingContext const* mcc = e.moduleCallingContext();
229 
230  AdjustPileupDistribution const* pileupAdjuster = nullptr;
231  if(not pileupAdjusters_.empty()) {
232  // Find the adjustment settings for the run of the signal event
233  // the container should be small-enough to not really gain
234  // anything with binary search
235  auto it = std::find_if(pileupAdjusters_.rbegin(), pileupAdjusters_.rend(),
236  [iRun=e.id().run()](const auto& elem) {
237  return elem.firstRun() <= iRun;
238  });
239  if(it == pileupAdjusters_.rend()) {
240  throw cms::Exception("LogicError") << "Encountered run " << e.id().run() << ", but the first run available in the pileup adjustment configuration is "
241  << pileupAdjusters_.front().firstRun() << ". Please fix the configuration.";
242  }
243  pileupAdjuster = &*it;
244  }
245 
246  for (int bunchCrossing=minBunch_;bunchCrossing<=maxBunch_;++bunchCrossing) {
247  for (unsigned int isource=0;isource<maxNbSources_;++isource) {
248  std::shared_ptr<PileUp> source = inputSources_[isource];
249  if (!source || !(source->doPileUp(bunchCrossing)))
250  continue;
251 
252  if (isource==0)
253  source->CalculatePileup(minBunch_, maxBunch_, PileupList, TrueNumInteractions_, e.streamID());
254 
255  int NumPU_Events = 0;
256  if (isource ==0) {
257  NumPU_Events = PileupList[bunchCrossing - minBunch_];
258  } else {
259  // non-minbias pileup only gets one event for now. Fix later if desired.
260  NumPU_Events = 1;
261  }
262 
263  for(auto& w: workers_) {
264  w->initializeBunchCrossing(e, ES, bunchCrossing);
265  }
266 
267  source->readPileUp(
268  e.id(),
269  recordEventID,
270  std::bind(&PreMixingModule::pileWorker, std::ref(*this),
271  _1, bunchCrossing, _2, std::cref(ES), mcc, pileupAdjuster),
272  NumPU_Events,
273  e.streamID()
274  );
275 
276  for(auto& w: workers_) {
277  w->finalizeBunchCrossing(e, ES, bunchCrossing);
278  }
279  }
280  }
281  }
RunNumber_t run() const
Definition: EventID.h:39
static std::string const source("source")
const double w
Definition: UKUtility.cc:23
std::vector< float > TrueNumInteractions_
bool pileWorker(const edm::EventPrincipal &, int bcr, int EventId, const edm::EventSetup &ES, ModuleCallingContext const *, AdjustPileupDistribution const *pileupAdjuster)
ModuleCallingContext const * moduleCallingContext() const
Definition: Event.h:241
static const unsigned int maxNbSources_
def elem(elemtype, innerHTML='', html_class='', kwargs)
Definition: HTMLExport.py:19
edm::EventID id() const
Definition: EventBase.h:59
std::vector< std::shared_ptr< PileUp > > inputSources_
std::vector< std::unique_ptr< PreMixingWorker > > workers_
StreamID streamID() const
Definition: Event.h:95
std::vector< AdjustPileupDistribution > pileupAdjusters_
void PreMixingModule::endLuminosityBlock ( LuminosityBlock const &  l1,
EventSetup const &  c 
)
override

Definition at line 303 of file PreMixingModule.cc.

References DEFINE_FWK_MODULE, and edm::BMixingModule::endLuminosityBlock().

Referenced by createnewEDProduct().

303  {
305  }
void endLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override
void PreMixingModule::endRun ( const edm::Run r,
const edm::EventSetup setup 
)
override

Definition at line 157 of file PreMixingModule.cc.

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

Referenced by createnewEDProduct().

157  {
158  for(auto& w: workers_) {
159  w->endRun();
160  }
162  }
const double w
Definition: UKUtility.cc:23
void endRun(const edm::Run &r, const edm::EventSetup &setup) override
std::vector< std::unique_ptr< PreMixingWorker > > workers_
void PreMixingModule::initializeEvent ( edm::Event const &  e,
edm::EventSetup const &  eventSetup 
)
override

Definition at line 143 of file PreMixingModule.cc.

References w, and workers_.

Referenced by createnewEDProduct().

143  {
144  for(auto& w: workers_) {
145  w->initializeEvent(e, ES);
146  }
147  }
const double w
Definition: UKUtility.cc:23
std::vector< std::unique_ptr< PreMixingWorker > > workers_
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 176 of file PreMixingModule.cc.

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

Referenced by doPileUp().

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

Reimplemented from edm::BMixingModule.

Definition at line 283 of file PreMixingModule.cc.

References edm::PreMixingPileupCopy::getBunchSpacing(), edm::PreMixingPileupCopy::getPileupSummaryInfo(), edm::PreMixingPileupCopy::putPileupInfo(), puWorker_, w, and workers_.

Referenced by createnewEDProduct().

283  {
284  // individual workers...
285  // move pileup first so we have access to the information for the put step
286  const auto& ps = puWorker_.getPileupSummaryInfo();
287  int bunchSpacing = puWorker_.getBunchSpacing();
288 
289  for(auto& w: workers_) {
290  w->put(e, ES, ps, bunchSpacing);
291  }
292 
294  }
const double w
Definition: UKUtility.cc:23
void putPileupInfo(edm::Event &e)
std::vector< std::unique_ptr< PreMixingWorker > > workers_
PreMixingPileupCopy puWorker_
const std::vector< PileupSummaryInfo > & getPileupSummaryInfo() const

Member Data Documentation

bool edm::PreMixingModule::addedPileup_ = false
private

Definition at line 92 of file PreMixingModule.cc.

Referenced by addSignals(), and pileWorker().

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

Definition at line 94 of file PreMixingModule.cc.

Referenced by doPileUp(), and PreMixingModule().

PreMixingPileupCopy edm::PreMixingModule::puWorker_
private

Definition at line 91 of file PreMixingModule.cc.

Referenced by pileWorker(), and put().

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