CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
edm::ConcurrentHadronizerFilter< HAD, DEC > Class Template Reference

#include <ConcurrentHadronizerFilter.h>

Inheritance diagram for edm::ConcurrentHadronizerFilter< HAD, DEC >:
edm::global::EDFilter< EndRunProducer, BeginLuminosityBlockProducer, EndLuminosityBlockProducer, RunCache< gen::RunCache >, LuminosityBlockSummaryCache< gen::LumiSummary >, StreamCache< gen::StreamCache< HAD, DEC > > > edm::global::EDFilterBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Types

typedef DEC Decayer
 
typedef HAD Hadronizer
 
- Public Types inherited from edm::global::EDFilterBase
typedef EDFilterBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 

Public Member Functions

std::unique_ptr< gen::StreamCache< HAD, DEC > > beginStream (edm::StreamID) const override
 
 ConcurrentHadronizerFilter (ParameterSet const &ps)
 
bool filter (StreamID id, Event &e, EventSetup const &es) const override
 
void globalBeginLuminosityBlockProduce (LuminosityBlock &, EventSetup const &) const override
 
std::shared_ptr< gen::LumiSummaryglobalBeginLuminosityBlockSummary (edm::LuminosityBlock const &, edm::EventSetup const &) const override
 
std::shared_ptr< gen::RunCacheglobalBeginRun (edm::Run const &, edm::EventSetup const &) const override
 
void globalEndLuminosityBlockProduce (LuminosityBlock &, EventSetup const &, gen::LumiSummary const *) const override
 
void globalEndLuminosityBlockSummary (edm::LuminosityBlock const &, edm::EventSetup const &, gen::LumiSummary *) const override
 
void globalEndRun (edm::Run const &, edm::EventSetup const &) const override
 
void globalEndRunProduce (Run &, EventSetup const &) const override
 
void streamBeginLuminosityBlock (StreamID, LuminosityBlock const &, EventSetup const &) const override
 
void streamBeginRun (StreamID, Run const &, EventSetup const &) const override
 
void streamEndLuminosityBlockSummary (StreamID, LuminosityBlock const &, EventSetup const &, gen::LumiSummary *) const override
 
void streamEndRun (StreamID, Run const &, EventSetup const &) const override
 
- Public Member Functions inherited from edm::global::EDFilter< EndRunProducer, BeginLuminosityBlockProducer, EndLuminosityBlockProducer, RunCache< gen::RunCache >, LuminosityBlockSummaryCache< gen::LumiSummary >, StreamCache< gen::StreamCache< HAD, DEC > > >
 EDFilter ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDFilterBase
 EDFilterBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDFilterBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void initLumi (gen::StreamCache< HAD, DEC > *cache, LuminosityBlock const &index, EventSetup const &es) const
 

Private Attributes

ParameterSet config_
 
unsigned int counterRunInfoProducts_
 
EDGetTokenT< LHEEventProducteventProductToken_
 
bool const hasFilter_
 
unsigned int nAttempts_
 
InputTag runInfoProductTag_
 
EDGetTokenT< LHERunInfoProductrunInfoProductToken_
 
std::atomic< gen::StreamCache< HAD, DEC > * > useInLumi_ { 0 }
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::global::EDFilterBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

template<class HAD, class DEC>
class edm::ConcurrentHadronizerFilter< HAD, DEC >

Definition at line 79 of file ConcurrentHadronizerFilter.h.

Member Typedef Documentation

template<class HAD , class DEC >
typedef DEC edm::ConcurrentHadronizerFilter< HAD, DEC >::Decayer

Definition at line 87 of file ConcurrentHadronizerFilter.h.

template<class HAD , class DEC >
typedef HAD edm::ConcurrentHadronizerFilter< HAD, DEC >::Hadronizer

Definition at line 86 of file ConcurrentHadronizerFilter.h.

Constructor & Destructor Documentation

template<class HAD , class DEC >
edm::ConcurrentHadronizerFilter< HAD, DEC >::ConcurrentHadronizerFilter ( ParameterSet const &  ps)
explicit

Definition at line 130 of file ConcurrentHadronizerFilter.h.

References edm::BranchDescription::branchType(), edm::ProducerBase::callWhenNewProductsRegistered(), edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), edm::ConcurrentHadronizerFilter< HAD, DEC >::hasFilter_, edm::InRun, edm::BranchDescription::moduleLabel(), edm::ConcurrentHadronizerFilter< HAD, DEC >::nAttempts_, edm::BranchDescription::processName(), edm::BranchDescription::productInstanceName(), and edm::BranchDescription::unwrappedTypeID().

131  : config_(ps),
136  nAttempts_(1),
137  hasFilter_(ps.exists("HepMCFilter")) {
138  auto ptrThis = this;
139  this->callWhenNewProductsRegistered([ptrThis](BranchDescription const& iBD) {
140  //this is called each time a module registers that it will produce a LHERunInfoProduct
141  if (iBD.unwrappedTypeID() == edm::TypeID(typeid(LHERunInfoProduct)) && iBD.branchType() == InRun) {
142  ++(ptrThis->counterRunInfoProducts_);
143  ptrThis->eventProductToken_ = ptrThis->template consumes<LHEEventProduct>(
144  InputTag((iBD.moduleLabel() == "externalLHEProducer") ? "externalLHEProducer" : "source"));
145  ptrThis->runInfoProductTag_ = InputTag(iBD.moduleLabel(), iBD.productInstanceName(), iBD.processName());
146  ptrThis->runInfoProductToken_ = ptrThis->template consumes<LHERunInfoProduct, InRun>(
147  InputTag(iBD.moduleLabel(), iBD.productInstanceName(), iBD.processName()));
148  }
149  });
150 
151  // TODO:
152  // Put the list of types produced by the filters here.
153  // The current design calls for:
154  // * LHEGeneratorInfo
155  // * LHEEvent
156  // * HepMCProduct
157  // But I can not find the LHEGeneratorInfo class; it might need to
158  // be invented.
159 
160  //initialize setting for multiple hadronization attempts
161  if (ps.exists("nAttempts")) {
162  nAttempts_ = ps.getParameter<unsigned int>("nAttempts");
163  }
164 
165  this->template produces<edm::HepMCProduct>("unsmeared");
166  this->template produces<GenEventInfoProduct>();
167  this->template produces<GenLumiInfoHeader, edm::Transition::BeginLuminosityBlock>();
168  this->template produces<GenLumiInfoProduct, edm::Transition::EndLuminosityBlock>();
169  this->template produces<GenRunInfoProduct, edm::Transition::EndRun>();
170  if (hasFilter_)
171  this->template produces<GenFilterInfo, edm::Transition::EndLuminosityBlock>();
172  }
void callWhenNewProductsRegistered(std::function< void(BranchDescription const &)> const &func)
Definition: ProducerBase.h:79
EDGetTokenT< LHEEventProduct > eventProductToken_
EDGetTokenT< LHERunInfoProduct > runInfoProductToken_

Member Function Documentation

template<class HAD , class DEC >
std::unique_ptr< gen::StreamCache< HAD, DEC > > edm::ConcurrentHadronizerFilter< HAD, DEC >::beginStream ( edm::StreamID  ) const
override

Definition at line 175 of file ConcurrentHadronizerFilter.h.

References utilities::cache(), edm::ConcurrentHadronizerFilter< HAD, DEC >::config_, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), and edm::ConcurrentHadronizerFilter< HAD, DEC >::useInLumi_.

175  {
176  auto cache = std::make_unique<gen::StreamCache<HAD, DEC>>(config_);
177 
178  if (config_.exists("ExternalDecays")) {
179  ParameterSet ps1 = config_.getParameter<ParameterSet>("ExternalDecays");
180  cache->decayer_.reset(new Decayer(ps1));
181  }
182 
183  if (config_.exists("HepMCFilter")) {
184  ParameterSet psfilter = config_.getParameter<ParameterSet>("HepMCFilter");
185  cache->filter_.reset(new HepMCFilterDriver(psfilter));
186  }
187 
188  //We need a hadronizer during globalBeginLumiProduce, doesn't matter which one
189  gen::StreamCache<HAD, DEC>* expected = nullptr;
190  useInLumi_.compare_exchange_strong(expected, cache.get());
191 
192  return cache;
193  }
T getParameter(std::string const &) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::atomic< gen::StreamCache< HAD, DEC > * > useInLumi_
def cache(function)
Definition: utilities.py:3
template<class HAD , class DEC >
bool edm::ConcurrentHadronizerFilter< HAD, DEC >::filter ( StreamID  id,
Event e,
EventSetup const &  es 
) const
overridevirtual

Implements edm::global::EDFilterBase.

Definition at line 196 of file ConcurrentHadronizerFilter.h.

References utilities::cache(), edm::EventID::event(), event(), edm::ConcurrentHadronizerFilter< HAD, DEC >::eventProductToken_, particlelevel_cff::genEventInfo, edm::Event::getByToken(), edm::EventBase::id(), eostools::move(), edm::ConcurrentHadronizerFilter< HAD, DEC >::nAttempts_, edm::Event::put(), edm::Event::streamID(), and protons_cff::t.

Referenced by edm::ConcurrentHadronizerFilter< HAD, DEC >::streamEndLuminosityBlockSummary().

196  {
197  auto cache = this->streamCache(id);
198  RandomEngineSentry<HAD> randomEngineSentry(&cache->hadronizer_, ev.streamID());
199  RandomEngineSentry<DEC> randomEngineSentryDecay(cache->decayer_.get(), ev.streamID());
200 
201  cache->hadronizer_.setEDMEvent(ev);
202 
203  // get LHE stuff and pass to hadronizer!
204  //
206  ev.getByToken(eventProductToken_, product);
207 
208  std::unique_ptr<HepMC::GenEvent> finalEvent;
209  std::unique_ptr<GenEventInfoProduct> finalGenEventInfo;
210 
211  //sum of weights for events passing hadronization
212  double waccept = 0;
213  //number of accepted events
214  unsigned int naccept = 0;
215 
216  for (unsigned int itry = 0; itry < nAttempts_; ++itry) {
217  cache->hadronizer_.setLHEEvent(std::make_unique<lhef::LHEEvent>(cache->hadronizer_.getLHERunInfo(), *product));
218 
219  // cache->hadronizer_.generatePartons();
220  if (!cache->hadronizer_.hadronize())
221  continue;
222 
223  // this is "fake" stuff
224  // in principle, decays are done as part of full event generation,
225  // except for particles that are marked as to be kept stable
226  // but we currently keep in it the design, because we might want
227  // to use such feature for other applications
228  //
229  if (!cache->hadronizer_.decay())
230  continue;
231 
232  std::unique_ptr<HepMC::GenEvent> event(cache->hadronizer_.getGenEvent());
233  if (!event.get())
234  continue;
235 
236  // The external decay driver is being added to the system,
237  // it should be called here
238  //
239  if (cache->decayer_) {
240  auto lheEvent = cache->hadronizer_.getLHEEvent();
241  auto t = cache->decayer_->decay(event.get(), lheEvent.get());
242  if (t != event.get()) {
243  event.reset(t);
244  }
245  cache->hadronizer_.setLHEEvent(std::move(lheEvent));
246  }
247 
248  if (!event.get())
249  continue;
250 
251  // check and perform if there're any unstable particles after
252  // running external decay packges
253  //
254  cache->hadronizer_.resetEvent(std::move(event));
255  if (!cache->hadronizer_.residualDecay())
256  continue;
257 
258  cache->hadronizer_.finalizeEvent();
259 
260  event = cache->hadronizer_.getGenEvent();
261  if (!event.get())
262  continue;
263 
264  event->set_event_number(ev.id().event());
265 
266  std::unique_ptr<GenEventInfoProduct> genEventInfo(cache->hadronizer_.getGenEventInfo());
267  if (!genEventInfo.get()) {
268  // create GenEventInfoProduct from HepMC event in case hadronizer didn't provide one
269  genEventInfo.reset(new GenEventInfoProduct(event.get()));
270  }
271 
272  //if HepMCFilter was specified, test event
273  if (cache->filter_ && !cache->filter_->filter(event.get(), genEventInfo->weight()))
274  continue;
275 
276  waccept += genEventInfo->weight();
277  ++naccept;
278 
279  //keep the LAST accepted event (which is equivalent to choosing randomly from the accepted events)
280  finalEvent = std::move(event);
281  finalGenEventInfo = std::move(genEventInfo);
282  }
283 
284  if (!naccept)
285  return false;
286 
287  //adjust event weights if necessary (in case input event was attempted multiple times)
288  if (nAttempts_ > 1) {
289  double multihadweight = double(naccept) / double(nAttempts_);
290 
291  //adjust weight for GenEventInfoProduct
292  finalGenEventInfo->weights()[0] *= multihadweight;
293 
294  //adjust weight for HepMC GenEvent (used e.g for RIVET)
295  finalEvent->weights()[0] *= multihadweight;
296  }
297 
298  ev.put(std::move(finalGenEventInfo));
299 
300  std::unique_ptr<HepMCProduct> bare_product(new HepMCProduct());
301  bare_product->addHepMCData(finalEvent.release());
302  ev.put(std::move(bare_product), "unsmeared");
303 
304  return true;
305  }
EDGetTokenT< LHEEventProduct > eventProductToken_
bool ev
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
def cache(function)
Definition: utilities.py:3
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
template<class HAD , class DEC >
void edm::ConcurrentHadronizerFilter< HAD, DEC >::globalBeginLuminosityBlockProduce ( LuminosityBlock lumi,
EventSetup const &  es 
) const
override

Definition at line 441 of file ConcurrentHadronizerFilter.h.

References genWeightsTable_cfi::genLumiInfoHeader, edm::ConcurrentHadronizerFilter< HAD, DEC >::initLumi(), eostools::move(), edm::LuminosityBlock::put(), and edm::ConcurrentHadronizerFilter< HAD, DEC >::useInLumi_.

442  {
443  //need one of the streams to finish
444  while (useInLumi_.load() == nullptr) {
445  }
446  initLumi(useInLumi_, lumi, es);
447  std::unique_ptr<GenLumiInfoHeader> genLumiInfoHeader(useInLumi_.load()->hadronizer_.getGenLumiInfoHeader());
448  lumi.put(std::move(genLumiInfoHeader));
449  }
std::atomic< gen::StreamCache< HAD, DEC > * > useInLumi_
void initLumi(gen::StreamCache< HAD, DEC > *cache, LuminosityBlock const &index, EventSetup const &es) const
def move(src, dest)
Definition: eostools.py:511
template<class HAD , class DEC >
std::shared_ptr< gen::LumiSummary > edm::ConcurrentHadronizerFilter< HAD, DEC >::globalBeginLuminosityBlockSummary ( edm::LuminosityBlock const &  ,
edm::EventSetup const &   
) const
override

Definition at line 512 of file ConcurrentHadronizerFilter.h.

513  {
514  return std::make_shared<gen::LumiSummary>();
515  }
template<class HAD , class DEC >
std::shared_ptr< gen::RunCache > edm::ConcurrentHadronizerFilter< HAD, DEC >::globalBeginRun ( edm::Run const &  ,
edm::EventSetup const &   
) const
override

Definition at line 368 of file ConcurrentHadronizerFilter.h.

369  {
370  return std::make_shared<gen::RunCache>();
371  }
template<class HAD , class DEC >
void edm::ConcurrentHadronizerFilter< HAD, DEC >::globalEndLuminosityBlockProduce ( LuminosityBlock lumi,
EventSetup const &  ,
gen::LumiSummary const *  iSummary 
) const
override

Definition at line 523 of file ConcurrentHadronizerFilter.h.

References edm::gen::LumiSummary::filterInfo_, edm::ConcurrentHadronizerFilter< HAD, DEC >::hasFilter_, edm::LuminosityBlock::index(), edm::gen::LumiSummary::lumiInfo_, eostools::move(), and edm::LuminosityBlock::put().

525  {
526  //Advance the random number generator so next begin lumi starts with new seed
528  rng->getEngine(lumi.index()).flat();
529 
530  lumi.put(std::move(iSummary->lumiInfo_));
531 
532  // produce GenFilterInfo if HepMCFilter is called
533  if (hasFilter_) {
534  lumi.put(std::move(iSummary->filterInfo_));
535  }
536  }
def move(src, dest)
Definition: eostools.py:511
template<class HAD , class DEC >
void edm::ConcurrentHadronizerFilter< HAD, DEC >::globalEndLuminosityBlockSummary ( edm::LuminosityBlock const &  ,
edm::EventSetup const &  ,
gen::LumiSummary  
) const
override

Definition at line 518 of file ConcurrentHadronizerFilter.h.

520  {}
template<class HAD , class DEC >
void edm::ConcurrentHadronizerFilter< HAD, DEC >::globalEndRun ( edm::Run const &  ,
edm::EventSetup const &   
) const
override

Definition at line 374 of file ConcurrentHadronizerFilter.h.

374 {}
template<class HAD , class DEC >
void edm::ConcurrentHadronizerFilter< HAD, DEC >::globalEndRunProduce ( Run r,
EventSetup const &   
) const
override

Definition at line 377 of file ConcurrentHadronizerFilter.h.

References edm::Run::index(), edm::Run::put(), and fetchall_from_DQM_v2::release.

377  {
378  r.put(this->runCache(r.index())->release());
379  }
template<class HAD , class DEC >
void edm::ConcurrentHadronizerFilter< HAD, DEC >::initLumi ( gen::StreamCache< HAD, DEC > *  cache,
LuminosityBlock const &  index,
EventSetup const &  es 
) const
private

Definition at line 393 of file ConcurrentHadronizerFilter.h.

References edm::errors::Configuration, edmIntegrityCheck::d, edm::gen::StreamCache< HAD, DEC >::decayer_, Exception, edm::gen::StreamCache< HAD, DEC >::filter_, edm::LuminosityBlock::get(), h, edm::gen::StreamCache< HAD, DEC >::hadronizer_, edm::LuminosityBlock::index(), edm::gen::StreamCache< HAD, DEC >::initialized_, and lhef::LHERunInfo::initLumi().

Referenced by edm::ConcurrentHadronizerFilter< HAD, DEC >::globalBeginLuminosityBlockProduce(), and edm::ConcurrentHadronizerFilter< HAD, DEC >::streamBeginLuminosityBlock().

395  {
396  lhef::LHERunInfo* lheRunInfo = cache->hadronizer_.getLHERunInfo().get();
397  lheRunInfo->initLumi();
398 
399  //We need all copies to see same random # for begin lumi
401  auto enginePtr = rng->cloneEngine(lumi.index());
402  cache->hadronizer_.setRandomEngine(enginePtr.get());
403  cache->decayer_->setRandomEngine(enginePtr.get());
404 
405  auto unsetH = [](HAD* h) { h->setRandomEngine(nullptr); };
406  auto unsetD = [](DEC* d) { d->setRandomEngine(nullptr); };
407 
408  std::unique_ptr<HAD, decltype(unsetH)> randomEngineSentry(&cache->hadronizer_, unsetH);
409  std::unique_ptr<DEC, decltype(unsetD)> randomEngineSentryDecay(cache->decayer_.get(), unsetD);
410 
411  cache->hadronizer_.randomizeIndex(lumi, enginePtr.get());
412 
413  if (!cache->hadronizer_.readSettings(1))
415  << "Failed to read settings for the hadronizer " << cache->hadronizer_.classname() << " \n";
416 
417  if (cache->decayer_) {
418  cache->decayer_->init(es);
419  if (!cache->hadronizer_.declareStableParticles(cache->decayer_->operatesOnParticles()))
421  << "Failed to declare stable particles in hadronizer " << cache->hadronizer_.classname()
422  << " for internal parton generation\n";
423  if (!cache->hadronizer_.declareSpecialSettings(cache->decayer_->specialSettings()))
425  << "Failed to declare special settings in hadronizer " << cache->hadronizer_.classname() << "\n";
426  }
427 
428  if (cache->filter_) {
429  cache->filter_->resetStatistics();
430  }
431 
432  if (!cache->hadronizer_.initializeForExternalPartons())
434  << "Failed to initialize hadronizer " << cache->hadronizer_.classname()
435  << " for external parton generation\n";
436 
437  cache->initialized_ = true;
438  }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
def cache(function)
Definition: utilities.py:3
template<class HAD , class DEC >
void edm::ConcurrentHadronizerFilter< HAD, DEC >::streamBeginLuminosityBlock ( StreamID  id,
LuminosityBlock const &  lumi,
EventSetup const &  es 
) const
override

Definition at line 382 of file ConcurrentHadronizerFilter.h.

References edm::ConcurrentHadronizerFilter< HAD, DEC >::initLumi(), and edm::ConcurrentHadronizerFilter< HAD, DEC >::useInLumi_.

384  {
385  if (useInLumi_ != this->streamCache(id)) {
386  initLumi(this->streamCache(id), lumi, es);
387  } else {
388  useInLumi_.store(nullptr);
389  }
390  }
std::atomic< gen::StreamCache< HAD, DEC > * > useInLumi_
void initLumi(gen::StreamCache< HAD, DEC > *cache, LuminosityBlock const &index, EventSetup const &es) const
template<class HAD , class DEC >
void edm::ConcurrentHadronizerFilter< HAD, DEC >::streamBeginRun ( StreamID  id,
Run const &  run,
EventSetup const &  es 
) const
override

Definition at line 308 of file ConcurrentHadronizerFilter.h.

References edm::ConcurrentHadronizerFilter< HAD, DEC >::counterRunInfoProducts_, edm::errors::EventCorruption, Exception, edm::Run::getByLabel(), lhef::LHERunInfo::initLumi(), and edm::ConcurrentHadronizerFilter< HAD, DEC >::runInfoProductTag_.

308  {
309  // this is run-specific
310 
311  // get LHE stuff and pass to hadronizer!
312 
313  if (counterRunInfoProducts_ > 1)
314  throw edm::Exception(errors::EventCorruption) << "More than one LHERunInfoProduct present";
315 
316  if (counterRunInfoProducts_ == 0)
317  throw edm::Exception(errors::EventCorruption) << "No LHERunInfoProduct present";
318 
319  edm::Handle<LHERunInfoProduct> lheRunInfoProduct;
320  run.getByLabel(runInfoProductTag_, lheRunInfoProduct);
321  //TODO: fix so that this actually works with getByToken commented below...
322  //run.getByToken(runInfoProductToken_, lheRunInfoProduct);
323  auto& hadronizer = this->streamCache(id)->hadronizer_;
324 
325  hadronizer.setLHERunInfo(std::make_unique<lhef::LHERunInfo>(*lheRunInfoProduct));
326  lhef::LHERunInfo* lheRunInfo = hadronizer.getLHERunInfo().get();
327  lheRunInfo->initLumi();
328  }
template<class HAD , class DEC >
void edm::ConcurrentHadronizerFilter< HAD, DEC >::streamEndLuminosityBlockSummary ( StreamID  id,
LuminosityBlock const &  ,
EventSetup const &  ,
gen::LumiSummary iSummary 
) const
override

Definition at line 452 of file ConcurrentHadronizerFilter.h.

References lhef::LHERunInfo::Process::accepted(), lhef::LHERunInfo::Process::acceptedBr(), lhef::LHERunInfo::XSec::error(), edm::ConcurrentHadronizerFilter< HAD, DEC >::filter(), edm::gen::LumiSummary::filterInfo_, lhef::LHERunInfo::getHEPRUP(), lhef::LHERunInfo::Process::getLHEXSec(), lhef::LHERunInfo::getLumiProcesses(), edm::ConcurrentHadronizerFilter< HAD, DEC >::hasFilter_, mps_fire::i, lhef::HEPRUP::IDWTUP, lhef::LHERunInfo::Process::killed(), edm::gen::LumiSummary::lumiInfo_, eostools::move(), lhef::LHERunInfo::Counter::n(), lhef::LHERunInfo::Process::nPassNeg(), lhef::LHERunInfo::Process::nPassPos(), lhef::LHERunInfo::Process::nTotalNeg(), lhef::LHERunInfo::Process::nTotalPos(), lhef::LHERunInfo::Process::process(), lhef::LHERunInfo::Process::selected(), GenLumiInfoProduct::ProcessInfo::setAccepted(), GenLumiInfoProduct::ProcessInfo::setAcceptedBr(), GenLumiInfoProduct::setHEPIDWTUP(), GenLumiInfoProduct::ProcessInfo::setKilled(), GenLumiInfoProduct::ProcessInfo::setLheXSec(), GenLumiInfoProduct::ProcessInfo::setNPassNeg(), GenLumiInfoProduct::ProcessInfo::setNPassPos(), GenLumiInfoProduct::ProcessInfo::setNTotalNeg(), GenLumiInfoProduct::ProcessInfo::setNTotalPos(), GenLumiInfoProduct::ProcessInfo::setProcess(), GenLumiInfoProduct::setProcessInfo(), GenLumiInfoProduct::ProcessInfo::setSelected(), GenLumiInfoProduct::ProcessInfo::setTried(), lhef::LHERunInfo::Counter::sum(), lhef::LHERunInfo::Counter::sum2(), groupFilesInBlocks::temp, lhef::LHERunInfo::Process::tried(), edm::ConcurrentHadronizerFilter< HAD, DEC >::useInLumi_, and lhef::LHERunInfo::XSec::value().

455  {
456  const lhef::LHERunInfo* lheRunInfo = this->streamCache(id)->hadronizer_.getLHERunInfo().get();
457 
458  std::vector<lhef::LHERunInfo::Process> LHELumiProcess = lheRunInfo->getLumiProcesses();
459  std::vector<GenLumiInfoProduct::ProcessInfo> GenLumiProcess;
460  for (unsigned int i = 0; i < LHELumiProcess.size(); i++) {
461  lhef::LHERunInfo::Process thisProcess = LHELumiProcess[i];
462 
464  temp.setProcess(thisProcess.process());
465  temp.setLheXSec(thisProcess.getLHEXSec().value(), thisProcess.getLHEXSec().error());
466  temp.setNPassPos(thisProcess.nPassPos());
467  temp.setNPassNeg(thisProcess.nPassNeg());
468  temp.setNTotalPos(thisProcess.nTotalPos());
469  temp.setNTotalNeg(thisProcess.nTotalNeg());
470  temp.setTried(thisProcess.tried().n(), thisProcess.tried().sum(), thisProcess.tried().sum2());
471  temp.setSelected(thisProcess.selected().n(), thisProcess.selected().sum(), thisProcess.selected().sum2());
472  temp.setKilled(thisProcess.killed().n(), thisProcess.killed().sum(), thisProcess.killed().sum2());
473  temp.setAccepted(thisProcess.accepted().n(), thisProcess.accepted().sum(), thisProcess.accepted().sum2());
474  temp.setAcceptedBr(thisProcess.acceptedBr().n(), thisProcess.acceptedBr().sum(), thisProcess.acceptedBr().sum2());
475  GenLumiProcess.push_back(temp);
476  }
477  GenLumiInfoProduct genLumiInfo;
478  genLumiInfo.setHEPIDWTUP(lheRunInfo->getHEPRUP()->IDWTUP);
479  genLumiInfo.setProcessInfo(GenLumiProcess);
480 
481  if (iSummary->lumiInfo_) {
482  iSummary->lumiInfo_->setHEPIDWTUP(lheRunInfo->getHEPRUP()->IDWTUP);
483  iSummary->lumiInfo_->mergeProduct(genLumiInfo);
484  } else {
485  iSummary->lumiInfo_ = std::make_unique<GenLumiInfoProduct>(std::move(genLumiInfo));
486  }
487 
488  // produce GenFilterInfo if HepMCFilter is called
489  if (hasFilter_) {
490  auto filter = this->streamCache(id)->filter_.get();
491  GenFilterInfo thisProduct(filter->numEventsPassPos(),
492  filter->numEventsPassNeg(),
493  filter->numEventsTotalPos(),
494  filter->numEventsTotalNeg(),
495  filter->sumpass_w(),
496  filter->sumpass_w2(),
497  filter->sumtotal_w(),
498  filter->sumtotal_w2());
499  if (not iSummary->filterInfo_) {
500  iSummary->filterInfo_ = std::make_unique<GenFilterInfo>(std::move(thisProduct));
501  } else {
502  iSummary->filterInfo_->mergeProduct(thisProduct);
503  }
504  }
505 
506  gen::StreamCache<HAD, DEC>* expected = nullptr;
507  //make it available for beginLuminosityBlockProduce
508  useInLumi_.compare_exchange_strong(expected, this->streamCache(id));
509  }
unsigned int nTotalPos() const
Definition: LHERunInfo.h:122
void setTried(unsigned int n, double sum, double sum2)
unsigned int n() const
Definition: LHERunInfo.h:102
void setSelected(unsigned int n, double sum, double sum2)
void setKilled(unsigned int n, double sum, double sum2)
const std::vector< Process > & getLumiProcesses() const
Definition: LHERunInfo.h:171
XSec getLHEXSec() const
Definition: LHERunInfo.h:118
bool mergeProduct(GenFilterInfo const &other)
void setAccepted(unsigned int n, double sum, double sum2)
std::atomic< gen::StreamCache< HAD, DEC > * > useInLumi_
void setAcceptedBr(unsigned int n, double sum, double sum2)
unsigned int nTotalNeg() const
Definition: LHERunInfo.h:123
double sum2() const
Definition: LHERunInfo.h:104
unsigned int nPassPos() const
Definition: LHERunInfo.h:120
const HEPRUP * getHEPRUP() const
Definition: LHERunInfo.h:52
Counter killed() const
Definition: LHERunInfo.h:127
void setLheXSec(double value, double err)
void setHEPIDWTUP(const int id)
double sum() const
Definition: LHERunInfo.h:103
Counter acceptedBr() const
Definition: LHERunInfo.h:129
Counter accepted() const
Definition: LHERunInfo.h:128
Counter selected() const
Definition: LHERunInfo.h:126
Counter tried() const
Definition: LHERunInfo.h:125
unsigned int nPassNeg() const
Definition: LHERunInfo.h:121
bool filter(StreamID id, Event &e, EventSetup const &es) const override
void setProcessInfo(const std::vector< ProcessInfo > &processes)
def move(src, dest)
Definition: eostools.py:511
template<class HAD , class DEC >
void edm::ConcurrentHadronizerFilter< HAD, DEC >::streamEndRun ( StreamID  id,
Run const &  r,
EventSetup const &   
) const
override

Definition at line 331 of file ConcurrentHadronizerFilter.h.

References utilities::cache(), lhef::LHERunInfo::XSec::error(), edm::Run::index(), GenRunInfoProduct::setInternalXSec(), lhef::LHERunInfo::statistics(), lhef::LHERunInfo::XSec::value(), and lhef::LHERunInfo::xsec().

331  {
332  auto rCache = this->runCache(r.index());
333  auto cache = this->streamCache(id);
334 
335  // Retrieve the LHE run info summary and transfer determined
336  // cross-section into the generator run info
337 
338  const lhef::LHERunInfo* lheRunInfo = cache->hadronizer_.getLHERunInfo().get();
339  lhef::LHERunInfo::XSec xsec = lheRunInfo->xsec();
340 
341  GenRunInfoProduct& genRunInfo = cache->hadronizer_.getGenRunInfo();
342  genRunInfo.setInternalXSec(GenRunInfoProduct::XSec(xsec.value(), xsec.error()));
343 
344  // If relevant, record the integrated luminosity for this run
345  // here. To do so, we would need a standard function to invoke on
346  // the contained hadronizer that would report the integrated
347  // luminosity.
348 
349  if (cache->initialized_) {
350  cache->hadronizer_.statistics();
351  if (cache->decayer_)
352  cache->decayer_->statistics();
353  if (cache->filter_)
354  cache->filter_->statistics();
355  lheRunInfo->statistics();
356  }
357  GenRunInfoProduct* expect = nullptr;
358 
359  std::unique_ptr<GenRunInfoProduct> griproduct(new GenRunInfoProduct(genRunInfo));
360  //All the GenRunInfoProducts for all streams shoule be identical, therefore we only
361  // need one
362  if (rCache->product_.compare_exchange_strong(expect, griproduct.get())) {
363  griproduct.release();
364  }
365  }
XSec xsec() const
Definition: LHERunInfo.cc:199
void setInternalXSec(const XSec &xsec)
def cache(function)
Definition: utilities.py:3
void statistics() const
Definition: LHERunInfo.cc:297

Member Data Documentation

template<class HAD , class DEC >
ParameterSet edm::ConcurrentHadronizerFilter< HAD, DEC >::config_
private
template<class HAD , class DEC >
unsigned int edm::ConcurrentHadronizerFilter< HAD, DEC >::counterRunInfoProducts_
private
template<class HAD , class DEC >
EDGetTokenT<LHEEventProduct> edm::ConcurrentHadronizerFilter< HAD, DEC >::eventProductToken_
private
template<class HAD , class DEC >
bool const edm::ConcurrentHadronizerFilter< HAD, DEC >::hasFilter_
private
template<class HAD , class DEC >
unsigned int edm::ConcurrentHadronizerFilter< HAD, DEC >::nAttempts_
private
template<class HAD , class DEC >
InputTag edm::ConcurrentHadronizerFilter< HAD, DEC >::runInfoProductTag_
private
template<class HAD , class DEC >
EDGetTokenT<LHERunInfoProduct> edm::ConcurrentHadronizerFilter< HAD, DEC >::runInfoProductToken_
private

Definition at line 117 of file ConcurrentHadronizerFilter.h.

template<class HAD , class DEC >
std::atomic<gen::StreamCache<HAD, DEC>*> edm::ConcurrentHadronizerFilter< HAD, DEC >::useInLumi_ { 0 }
mutableprivate