9 #ifndef GeneratorInterface_Core_ConcurrentHadronizerFilter_h 10 #define GeneratorInterface_Core_ConcurrentHadronizerFilter_h 31 #include "CLHEP/Random/RandomEngine.h" 52 mutable std::atomic<GenRunInfoProduct*>
product_{
nullptr};
61 return std::unique_ptr<GenRunInfoProduct>(retValue);
65 mutable std::unique_ptr<GenLumiInfoProduct>
lumiInfo_;
68 template <
typename HAD,
typename DEC>
73 std::unique_ptr<HepMCFilterDriver>
filter_;
74 bool initialized_ =
false;
78 template <
class HAD,
class DEC>
80 BeginLuminosityBlockProducer,
81 EndLuminosityBlockProducer,
82 RunCache<gen::RunCache>,
83 LuminosityBlockSummaryCache<gen::LumiSummary>,
84 StreamCache<gen::StreamCache<HAD, DEC>>> {
93 std::unique_ptr<gen::StreamCache<HAD, DEC>> beginStream(
edm::StreamID)
const override;
99 void globalEndRunProduce(
Run&,
EventSetup const&)
const override;
102 void streamEndLuminosityBlockSummary(
StreamID,
106 std::shared_ptr<gen::LumiSummary> globalBeginLuminosityBlockSummary(
edm::LuminosityBlock const&,
121 mutable std::atomic<gen::StreamCache<HAD, DEC>*> useInLumi_{
nullptr};
129 template <
class HAD,
class DEC>
132 runInfoProductTag_(),
133 runInfoProductToken_(),
134 eventProductToken_(),
135 counterRunInfoProducts_(0),
137 hasFilter_(ps.exists(
"HepMCFilter")) {
142 ++(ptrThis->counterRunInfoProducts_);
143 ptrThis->eventProductToken_ = ptrThis->template consumes<LHEEventProduct>(
144 InputTag((iBD.
moduleLabel() ==
"externalLHEProducer") ?
"externalLHEProducer" :
"source"));
146 ptrThis->runInfoProductToken_ = ptrThis->template consumes<LHERunInfoProduct, InRun>(
161 if (ps.
exists(
"nAttempts")) {
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>();
171 this->
template produces<GenFilterInfo, edm::Transition::EndLuminosityBlock>();
174 template <
class HAD,
class DEC>
176 auto cache = std::make_unique<gen::StreamCache<HAD, DEC>>(
config_);
195 template <
class HAD,
class DEC>
197 auto cache = this->streamCache(
id);
201 cache->hadronizer_.setEDMEvent(ev);
208 std::unique_ptr<HepMC::GenEvent> finalEvent;
209 std::unique_ptr<GenEventInfoProduct> finalGenEventInfo;
214 unsigned int naccept = 0;
216 for (
unsigned int itry = 0; itry <
nAttempts_; ++itry) {
217 cache->hadronizer_.setLHEEvent(std::make_unique<lhef::LHEEvent>(
cache->hadronizer_.getLHERunInfo(), *product));
220 if (!
cache->hadronizer_.hadronize())
229 if (!
cache->hadronizer_.decay())
232 std::unique_ptr<HepMC::GenEvent>
event(
cache->hadronizer_.getGenEvent());
239 if (
cache->decayer_) {
240 auto lheEvent =
cache->hadronizer_.getLHEEvent();
241 auto t =
cache->decayer_->decay(
event.get(), lheEvent.get());
255 if (!
cache->hadronizer_.residualDecay())
258 cache->hadronizer_.finalizeEvent();
260 event =
cache->hadronizer_.getGenEvent();
264 event->set_event_number(ev.
id().
event());
266 std::unique_ptr<GenEventInfoProduct>
genEventInfo(
cache->hadronizer_.getGenEventInfo());
288 if (nAttempts_ > 1) {
289 double multihadweight = double(naccept) / double(nAttempts_);
292 finalGenEventInfo->weights()[0] *= multihadweight;
295 finalEvent->weights()[0] *= multihadweight;
300 std::unique_ptr<HepMCProduct> bare_product(
new HepMCProduct());
301 bare_product->addHepMCData(finalEvent.release());
307 template <
class HAD,
class DEC>
323 auto& hadronizer = this->streamCache(
id)->hadronizer_;
325 hadronizer.setLHERunInfo(std::make_unique<lhef::LHERunInfo>(*lheRunInfoProduct));
330 template <
class HAD,
class DEC>
332 auto rCache = this->runCache(r.
index());
333 auto cache = this->streamCache(
id);
338 const lhef::LHERunInfo* lheRunInfo = cache->hadronizer_.getLHERunInfo().get();
349 if (cache->initialized_) {
350 cache->hadronizer_.statistics();
352 cache->decayer_->statistics();
354 cache->filter_->statistics();
359 std::unique_ptr<GenRunInfoProduct> griproduct(
new GenRunInfoProduct(genRunInfo));
362 if (rCache->product_.compare_exchange_strong(expect, griproduct.get())) {
363 griproduct.release();
367 template <
class HAD,
class DEC>
370 return std::make_shared<gen::RunCache>();
373 template <
class HAD,
class DEC>
376 template <
class HAD,
class DEC>
381 template <
class HAD,
class DEC>
386 initLumi(this->streamCache(
id), lumi, es);
392 template <
class HAD,
class DEC>
401 auto enginePtr = rng->cloneEngine(lumi.
index());
402 cache->
hadronizer_.setRandomEngine(enginePtr.get());
403 cache->
decayer_->setRandomEngine(enginePtr.get());
405 auto unsetH = [](HAD*
h) {
h->setRandomEngine(
nullptr); };
406 auto unsetD = [](DEC*
d) {
d->setRandomEngine(
nullptr); };
408 std::unique_ptr<HAD, decltype(unsetH)> randomEngineSentry(&cache->
hadronizer_, unsetH);
409 std::unique_ptr<DEC, decltype(unsetD)> randomEngineSentryDecay(cache->
decayer_.get(), unsetD);
415 <<
"Failed to read settings for the hadronizer " << cache->
hadronizer_.classname() <<
" \n";
421 <<
"Failed to declare stable particles in hadronizer " << cache->
hadronizer_.classname()
422 <<
" for internal parton generation\n";
425 <<
"Failed to declare special settings in hadronizer " << cache->
hadronizer_.classname() <<
"\n";
429 cache->
filter_->resetStatistics();
432 if (!cache->
hadronizer_.initializeForExternalPartons())
434 <<
"Failed to initialize hadronizer " << cache->
hadronizer_.classname()
435 <<
" for external parton generation\n";
440 template <
class HAD,
class DEC>
451 template <
class HAD,
class DEC>
456 const lhef::LHERunInfo* lheRunInfo = this->streamCache(
id)->hadronizer_.getLHERunInfo().get();
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++) {
475 GenLumiProcess.push_back(temp);
483 iSummary->
lumiInfo_->mergeProduct(genLumiInfo);
490 auto filter = this->streamCache(
id)->filter_.get();
492 filter->numEventsPassNeg(),
493 filter->numEventsTotalPos(),
494 filter->numEventsTotalNeg(),
508 useInLumi_.compare_exchange_strong(expected, this->streamCache(
id));
511 template <
class HAD,
class DEC>
514 return std::make_shared<gen::LumiSummary>();
517 template <
class HAD,
class DEC>
522 template <
class HAD,
class DEC>
528 rng->getEngine(lumi.
index()).flat();
540 #endif // GeneratorInterface_Core_ConcurrentHadronizerFilter_h void setNPassNeg(unsigned int n)
std::atomic< GenRunInfoProduct * > product_
T getParameter(std::string const &) const
void callWhenNewProductsRegistered(std::function< void(BranchDescription const &)> const &func)
EventNumber_t event() const
unsigned int nTotalPos() const
bool getByLabel(std::string const &label, Handle< PROD > &result) const
ConcurrentHadronizerFilter(ParameterSet const &ps)
void setTried(unsigned int n, double sum, double sum2)
void globalEndRun(edm::Run const &, edm::EventSetup const &) const override
void setNTotalNeg(unsigned int n)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
BranchType const & branchType() const
EDGetTokenT< LHEEventProduct > eventProductToken_
std::unique_ptr< DEC > decayer_
void setSelected(unsigned int n, double sum, double sum2)
std::unique_ptr< GenLumiInfoProduct > lumiInfo_
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
LuminosityBlockIndex index() const
EDGetTokenT< LHERunInfoProduct > runInfoProductToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
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 streamBeginLuminosityBlock(StreamID, LuminosityBlock const &, EventSetup const &) const override
std::string const & processName() const
std::unique_ptr< GenFilterInfo > filterInfo_
InputTag runInfoProductTag_
void globalEndLuminosityBlockProduce(LuminosityBlock &, EventSetup const &, gen::LumiSummary const *) const override
void setInternalXSec(const XSec &xsec)
const std::vector< Process > & getLumiProcesses() const
void globalEndRunProduce(Run &, EventSetup const &) const override
std::unique_ptr< gen::StreamCache< HAD, DEC > > beginStream(edm::StreamID) const override
void setAccepted(unsigned int n, double sum, double sum2)
std::atomic< gen::StreamCache< HAD, DEC > * > useInLumi_
std::string const & moduleLabel() const
void setAcceptedBr(unsigned int n, double sum, double sum2)
std::string const & productInstanceName() const
void globalEndLuminosityBlockSummary(edm::LuminosityBlock const &, edm::EventSetup const &, gen::LumiSummary *) const override
void put(std::unique_ptr< PROD > product)
Put a new product.
std::shared_ptr< gen::RunCache > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override
std::unique_ptr< GenRunInfoProduct > release() const
TypeID unwrappedTypeID() const
unsigned int counterRunInfoProducts_
void initLumi(gen::StreamCache< HAD, DEC > *cache, LuminosityBlock const &index, EventSetup const &es) const
void setNTotalPos(unsigned int n)
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
void streamBeginRun(StreamID, Run const &, EventSetup const &) const override
unsigned int nTotalNeg() const
unsigned int nPassPos() const
const HEPRUP * getHEPRUP() const
void globalBeginLuminosityBlockProduce(LuminosityBlock &, EventSetup const &) const override
StreamCache(ParameterSet const &iPSet)
void put(std::unique_ptr< PROD > product)
Put a new product.
std::unique_ptr< HepMCFilterDriver > filter_
void setLheXSec(double value, double err)
void setHEPIDWTUP(const int id)
void streamEndRun(StreamID, Run const &, EventSetup const &) const override
StreamID streamID() const
Counter acceptedBr() const
void setNPassPos(unsigned int n)
unsigned int nPassNeg() const
std::shared_ptr< gen::LumiSummary > globalBeginLuminosityBlockSummary(edm::LuminosityBlock const &, edm::EventSetup const &) const override
bool filter(StreamID id, Event &e, EventSetup const &es) const override
void setProcessInfo(const std::vector< ProcessInfo > &processes)
void streamEndLuminosityBlockSummary(StreamID, LuminosityBlock const &, EventSetup const &, gen::LumiSummary *) const override