9 #ifndef GeneratorInterface_Core_ConcurrentGeneratorFilter_h 10 #define GeneratorInterface_Core_ConcurrentGeneratorFilter_h 31 #include "CLHEP/Random/RandomEngine.h" 50 mutable std::atomic<GenRunInfoProduct*>
product_{
nullptr};
59 return std::unique_ptr<GenRunInfoProduct>(retValue);
63 mutable std::unique_ptr<GenLumiInfoProduct>
lumiInfo_;
65 template <
typename HAD,
typename DEC>
71 bool initialized_ =
false;
75 template <
class HAD,
class DEC>
77 BeginLuminosityBlockProducer,
78 EndLuminosityBlockProducer,
79 RunCache<gen::GenRunCache>,
80 LuminosityBlockSummaryCache<gen::GenLumiSummary>,
81 StreamCache<gen::GenStreamCache<HAD, DEC>>> {
90 std::unique_ptr<gen::GenStreamCache<HAD, DEC>> beginStream(
StreamID)
const override;
91 std::shared_ptr<gen::GenRunCache> globalBeginRun(
Run const&,
EventSetup const&)
const override;
92 std::shared_ptr<gen::GenLumiSummary> globalBeginLuminosityBlockSummary(
LuminosityBlock const&,
97 void streamEndLuminosityBlockSummary(
StreamID,
108 void globalEndRun(
Run const&,
EventSetup const&)
const override;
109 void globalEndRunProduce(
Run&,
EventSetup const&)
const override;
114 mutable std::atomic<gen::GenStreamCache<HAD, DEC>*> useInLumi_{
nullptr};
121 template <
class HAD,
class DEC>
132 this->
template produces<HepMCProduct>(
"unsmeared");
133 this->
template produces<GenEventInfoProduct>();
134 this->
template produces<GenLumiInfoHeader, edm::Transition::BeginLuminosityBlock>();
135 this->
template produces<GenLumiInfoProduct, edm::Transition::EndLuminosityBlock>();
136 this->
template produces<GenRunInfoProduct, edm::Transition::EndRun>();
139 template <
class HAD,
class DEC>
141 auto cache = std::make_unique<gen::GenStreamCache<HAD, DEC>>(
config_);
155 template <
class HAD,
class DEC>
158 return std::make_shared<gen::GenRunCache>();
161 template <
class HAD,
class DEC>
164 return std::make_shared<gen::GenLumiSummary>();
167 template <
class HAD,
class DEC>
175 auto enginePtr = rng->cloneEngine(lumi.
index());
176 cache->
hadronizer_.setRandomEngine(enginePtr.get());
177 cache->
decayer_->setRandomEngine(enginePtr.get());
179 auto unsetH = [](HAD*
h) {
h->setRandomEngine(
nullptr); };
180 auto unsetD = [](DEC*
d) {
d->setRandomEngine(
nullptr); };
182 std::unique_ptr<HAD, decltype(unsetH)> randomEngineSentry(&cache->
hadronizer_, unsetH);
183 std::unique_ptr<DEC, decltype(unsetD)> randomEngineSentryDecay(cache->
decayer_.get(), unsetD);
189 <<
"Failed to read settings for the hadronizer " << cache->
hadronizer_.classname() <<
" \n";
195 <<
"Failed to declare stable particles in hadronizer " << cache->
hadronizer_.classname()
196 <<
" for internal parton generation\n";
199 <<
"Failed to declare special settings in hadronizer " << cache->
hadronizer_.classname() <<
"\n";
202 if (!cache->
hadronizer_.initializeForInternalPartons())
204 <<
"Failed to initialize hadronizer " << cache->
hadronizer_.classname()
205 <<
" for internal parton generation\n";
210 template <
class HAD,
class DEC>
212 auto cache = this->streamCache(
id);
216 cache->hadronizer_.setEDMEvent(ev);
218 bool passEvtGenSelector =
false;
219 std::unique_ptr<HepMC::GenEvent>
event(
nullptr);
221 while (!passEvtGenSelector) {
223 cache->hadronizer_.setEDMEvent(ev);
225 if (!
cache->hadronizer_.generatePartonsAndHadronize())
234 if (!
cache->hadronizer_.decay())
237 event =
cache->hadronizer_.getGenEvent();
244 if (
cache->decayer_) {
245 auto t =
cache->decayer_->decay(event.get());
246 if (
t != event.get()) {
253 passEvtGenSelector =
cache->hadronizer_.select(event.get());
266 if (!
cache->hadronizer_.residualDecay())
269 cache->hadronizer_.finalizeEvent();
271 event =
cache->hadronizer_.getGenEvent();
275 event->set_event_number(ev.
id().
event());
280 std::unique_ptr<GenEventInfoProduct>
genEventInfo(
cache->hadronizer_.getGenEventInfo());
283 genEventInfo = std::make_unique<GenEventInfoProduct>(
event.get());
288 std::unique_ptr<HepMCProduct> bare_product(
new HepMCProduct());
289 bare_product->addHepMCData(event.release());
291 cache->nEventsInLumiBlock_++;
295 template <
class HAD,
class DEC>
306 template <
class HAD,
class DEC>
311 initLumi(this->streamCache(
id), lumi, es);
317 template <
class HAD,
class DEC>
321 this->streamCache(
id)->hadronizer_.cleanLHE();
324 template <
class HAD,
class DEC>
329 auto cache = this->streamCache(
id);
330 cache->hadronizer_.statistics();
332 cache->decayer_->statistics();
335 std::vector<GenLumiInfoProduct::ProcessInfo> GenLumiProcess;
338 unsigned int nEvtInLumiBlock_ =
cache->nEventsInLumiBlock_;
345 temp.
setTried(nEvtInLumiBlock_, nEvtInLumiBlock_, nEvtInLumiBlock_);
346 temp.
setSelected(nEvtInLumiBlock_, nEvtInLumiBlock_, nEvtInLumiBlock_);
347 temp.
setKilled(nEvtInLumiBlock_, nEvtInLumiBlock_, nEvtInLumiBlock_);
350 GenLumiProcess.push_back(temp);
357 iSummary->
lumiInfo_->mergeProduct(genLumiInfo);
362 cache->nEventsInLumiBlock_ = 0;
366 useInLumi_.compare_exchange_strong(expected, this->streamCache(
id));
369 template <
class HAD,
class DEC>
374 template <
class HAD,
class DEC>
381 template <
class HAD,
class DEC>
383 auto rCache = this->runCache(run.
index());
384 auto cache = this->streamCache(
id);
391 if (cache->initialized_) {
392 cache->hadronizer_.statistics();
394 cache->decayer_->statistics();
399 std::unique_ptr<GenRunInfoProduct> griproduct(
new GenRunInfoProduct(genRunInfo));
401 if (rCache->product_.compare_exchange_strong(expect, griproduct.get())) {
402 griproduct.release();
406 template <
class HAD,
class DEC>
409 template <
class HAD,
class DEC>
416 #endif // GeneratorInterface_Core_ConcurrentGeneratorFilter_h ConcurrentGeneratorFilter(ParameterSet const &ps)
void setNPassNeg(unsigned int n)
T getParameter(std::string const &) const
EventNumber_t event() const
void setTried(unsigned int n, double sum, double sum2)
void setNTotalNeg(unsigned int n)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void streamEndLuminosityBlock(StreamID, LuminosityBlock const &, EventSetup const &) const override
void setSelected(unsigned int n, double sum, double sum2)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
LuminosityBlockIndex index() const
std::unique_ptr< GenRunInfoProduct > release() const
void streamBeginLuminosityBlock(StreamID, LuminosityBlock const &, EventSetup const &) const override
std::atomic< GenRunInfoProduct * > product_
void setKilled(unsigned int n, double sum, double sum2)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
PROD const & get(EDGetTokenT< PROD > token) const (false)
void initLumi(gen::GenStreamCache< HAD, DEC > *cache, LuminosityBlock const &index, EventSetup const &es) const
void globalEndLuminosityBlockProduce(LuminosityBlock &, EventSetup const &, gen::GenLumiSummary const *) const override
std::atomic< gen::GenStreamCache< HAD, DEC > * > useInLumi_
void setAccepted(unsigned int n, double sum, double sum2)
bool filter(StreamID id, Event &e, EventSetup const &es) const override
void setAcceptedBr(unsigned int n, double sum, double sum2)
void globalEndRun(Run const &, EventSetup const &) const override
void globalEndLuminosityBlockSummary(LuminosityBlock const &, EventSetup const &, gen::GenLumiSummary *) const override
void put(std::unique_ptr< PROD > product)
Put a new product.
GenStreamCache(ParameterSet const &iPSet)
void setNTotalPos(unsigned int n)
void streamEndRun(StreamID, Run const &, EventSetup const &) const override
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
unsigned int nEventsInLumiBlock_
std::shared_ptr< gen::GenRunCache > globalBeginRun(Run const &, EventSetup const &) const override
void globalEndRunProduce(Run &, EventSetup const &) const override
void put(std::unique_ptr< PROD > product)
Put a new product.
void setLheXSec(double value, double err)
void setHEPIDWTUP(const int id)
std::shared_ptr< gen::GenLumiSummary > globalBeginLuminosityBlockSummary(LuminosityBlock const &, EventSetup const &) const override
const XSec & internalXSec() const
StreamID streamID() const
void streamEndLuminosityBlockSummary(StreamID, LuminosityBlock const &, EventSetup const &, gen::GenLumiSummary *) const override
std::unique_ptr< gen::GenStreamCache< HAD, DEC > > beginStream(StreamID) const override
std::unique_ptr< GenLumiInfoProduct > lumiInfo_
void setNPassPos(unsigned int n)
std::unique_ptr< DEC > decayer_
void globalBeginLuminosityBlockProduce(LuminosityBlock &, EventSetup const &) const override
void setProcessInfo(const std::vector< ProcessInfo > &processes)