8 #include "HepMC/GenEvent.h" 9 #include "HepMC/GenParticle.h" 11 #include "Pythia8/Pythia.h" 12 #include "Pythia8Plugins/HepMC2.h" 14 #include "Vincia/Vincia.h" 15 #include "Dire/Dire.h" 26 #include "Pythia8Plugins/JetMatching.h" 27 #include "Pythia8Plugins/aMCatNLOHooks.h" 33 #include "Pythia8Plugins/PowhegHooks.h" 51 #include "Pythia8Plugins/EvtGen.h" 69 #include "HepPID/ParticleIDTranslations.hh" 75 class HepRandomEngine;
85 bool initializeForInternalPartons()
override;
86 bool initializeForExternalPartons();
88 bool generatePartonsAndHadronize()
override;
91 virtual bool residualDecay();
93 void finalizeEvent()
override;
97 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
99 std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader()
const override;
102 std::unique_ptr<Vincia::VinciaPlugin>
fvincia;
103 std::unique_ptr<Pythia8::Dire>
fDire;
106 std::vector<std::string>
const &
doSharedResources()
const override {
return p8SharedResources; }
112 std::unique_ptr<LHAupLesHouches>
lhaUP;
114 enum { PP,
PPbar, ElectronPositron };
179 comEnergy(params.getParameter<double>(
"comEnergy")),
180 LHEInputFileName(params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
188 if (params.
exists(
"PPbarInitialState")) {
192 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 193 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
197 }
else if (params.
exists(
"ElectronPositronInitialState")) {
201 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 202 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
206 }
else if (params.
exists(
"ElectronProtonInitialState") || params.
exists(
"PositronProtonInitialState")) {
209 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
214 if (params.
exists(
"reweightGen")) {
215 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
219 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
221 if (params.
exists(
"reweightGenEmp")) {
222 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
226 if (rgeParams.
exists(
"tune"))
229 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
231 if (params.
exists(
"reweightGenRap")) {
232 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
240 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
242 if (params.
exists(
"reweightGenPtHatRap")) {
243 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
251 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
254 if (params.
exists(
"useUserHook"))
256 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
260 if (params.
exists(
"jetMatching")) {
263 if (scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet") {
270 if (params.
exists(
"emissionVeto1")) {
272 if (params.
exists(
"EV1_nFinal"))
275 if (params.
exists(
"EV1_vetoOn"))
278 if (params.
exists(
"EV1_maxVetoCount"))
281 if (params.
exists(
"EV1_pThardMode"))
284 if (params.
exists(
"EV1_pTempMode"))
289 if (params.
exists(
"EV1_emittedMode"))
292 if (params.
exists(
"EV1_pTdefMode"))
295 if (params.
exists(
"EV1_MPIvetoOn"))
298 if (params.
exists(
"EV1_QEDvetoMode"))
301 if (params.
exists(
"EV1_nFinalMode"))
316 if (params.
exists(
"VinciaPlugin")) {
320 if (params.
exists(
"DirePlugin")) {
322 fDire.reset(
new Pythia8::Dire());
331 bool status =
false, status1 =
false;
340 fMasterGen->settings.mode(
"Beams:idB", -2212);
347 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
351 fMasterGen->settings.mode(
"Beams:frameType", 4);
368 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
372 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
375 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 376 "are : jetMatching, emissionVeto1 \n";
380 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
384 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
386 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
391 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
393 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
399 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
400 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
402 if (internalMatching && internalMerging) {
404 <<
" Only one jet matching/merging scheme can be used at a time. \n";
407 if (internalMatching) {
412 if (internalMerging) {
413 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree") ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt"))
415 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
416 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
417 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
418 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
421 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
425 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
426 if (biasedTauDecayer) {
432 std::vector<int> handledParticles;
433 handledParticles.push_back(15);
437 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
438 if (resonanceDecayFilter) {
443 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
453 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
457 }
else if (
fDire.get()) {
459 fDire->weightsPtr->setup();
480 fDecayer->settings.flag(
"ProcessLevel:all",
false);
481 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
482 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
486 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
492 return (status && status1);
496 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
498 bool status =
false, status1 =
false;
513 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
517 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
520 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 521 "are : jetMatching, emissionVeto1 \n";
525 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
529 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
531 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
536 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
538 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
544 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
545 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
547 if (internalMatching && internalMerging) {
549 <<
" Only one jet matching/merging scheme can be used at a time. \n";
552 if (internalMatching) {
557 if (internalMerging) {
558 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree") ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt"))
560 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
561 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
562 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
563 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
566 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
570 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
571 if (biasedTauDecayer) {
577 std::vector<int> handledParticles;
578 handledParticles.push_back(15);
582 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
583 if (resonanceDecayFilter) {
588 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
600 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
601 fMasterGen->settings.mode(
"Beams:frameType", 4);
607 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
614 fMasterGen->settings.mode(
"Beams:frameType", 5);
616 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
633 fDecayer->settings.flag(
"ProcessLevel:all",
false);
634 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
635 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
639 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
645 return (status && status1);
653 <<
"Number of ISR vetoed = " <<
nISRveto;
677 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
692 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
693 DJR.push_back(djrmatch[idjr]);
711 if (mergeweight != 1.) {
712 event()->weights()[0] *= mergeweight;
721 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
722 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
723 double wgt = (*
fMasterGen->info.weights_detailed)[key];
724 event()->weights().push_back(wgt);
726 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
727 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
728 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
729 event()->weights().push_back(wgt);
738 event()->weights().push_back(wgt);
746 for (
int iVar = 1; iVar <
fvincia->nWeights(); iVar++) {
753 fDire->weightsPtr->calcWeight(0.);
754 fDire->weightsPtr->reset();
757 event()->weights()[0] *=
fDire->weightsPtr->getShowerWeight(
"base");
759 map<string, double>::iterator it;
760 for (it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end();
762 if (it->first ==
"base")
764 event()->weights().push_back(it->second);
785 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
791 if (!py8next ||
std::abs(mergeweight) == 0.) {
801 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
802 DJR.push_back(djrmatch[idjr]);
823 if (mergeweight != 1.) {
824 event()->weights()[0] *= mergeweight;
837 event()->weights().push_back(wgt);
847 int NPartsBeforeDecays = pythiaEvent->size();
848 int NPartsAfterDecays =
event().get()->particles_size();
850 if (NPartsAfterDecays == NPartsBeforeDecays)
855 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
858 if (part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id())) {
868 part->momentum().x(),
869 part->momentum().y(),
870 part->momentum().z(),
871 part->momentum().t(),
872 part->generated_mass());
873 HepMC::GenVertex *ProdVtx = part->production_vertex();
874 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
875 py8part.tau((
fDecayer->particleData).tau0(part->pdg_id()));
877 int nentries =
fDecayer->event.size();
878 if (!
fDecayer->event[nentries - 1].mayDecay())
881 int nentries1 =
fDecayer->event.size();
882 if (nentries1 <= nentries)
923 <<
"----------------------" << std::endl;
928 <<
"----------------------" << std::endl;
944 int weights_number =
fMasterGen->info.nWeights();
946 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
947 if (weights_number > 1) {
956 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
957 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
958 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
959 weightgroupname = wgtgrp.first;
963 std::ostringstream weightname;
964 weightname <<
"LHE, id = " << key <<
", ";
965 if (!weightgroupname.empty()) {
966 weightname <<
"group = " << weightgroupname <<
", ";
968 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
985 for (
int iVar = 0; iVar <
fvincia->nWeights(); iVar++) {
994 map<string, double>::iterator it;
995 for (it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end();
997 if (it->first ==
"base")
std::unique_ptr< UserHooks > fReweightPtHatRapUserHook
edm::ConcurrentGeneratorFilter< Pythia8Hadronizer, ConcurrentExternalDecayDriver > Pythia8ConcurrentGeneratorFilter
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual bool residualDecay()
double comEnergy
Center-of-Mass energy.
std::unique_ptr< Pythia8::Pythia > fDecayer
edm::GeneratorFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8GeneratorFilter
bool initializeForInternalPartons() override
std::shared_ptr< EvtGenDecays > evtgenDecays
HepMC::IO_AsciiParticles * ascii_io
bool initializeForExternalPartons()
void statistics() override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::string LHEInputFileName
std::unique_ptr< EmissionVetoHook1 > fEmissionVetoHook1
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
std::unique_ptr< BiasedTauDecayer > fBiasedTauDecayer
std::unique_ptr< Pythia8::amcnlo_unitarised_interface > fMergingHook
bool pythiaHepMCVerbosityParticles
void setInternalXSec(const XSec &xsec)
std::vector< std::string > evtgenUserFiles
std::unique_ptr< JetMatchingHook > fJetMatchingHook
edm::ConcurrentHadronizerFilter< Pythia8Hadronizer, ConcurrentExternalDecayDriver > Pythia8ConcurrentHadronizerFilter
const char * classname() const override
GenRunInfoProduct & runInfo()
#define DEFINE_FWK_MODULE(type)
lhef::LHEEvent * lheEvent()
std::unique_ptr< PowhegHooksBB4L > fPowhegHooksBB4L
std::unique_ptr< PowhegResHook > fPowhegResHook
std::unique_ptr< Pythia8::JetMatchingMadgraph > fJetMatchingPy8InternalHook
std::unique_ptr< PowhegHooks > fEmissionVetoHook
static const std::vector< std::string > p8SharedResources
Abs< T >::type abs(const T &t)
unsigned int pythiaPylistVerbosity
std::unique_ptr< GenLumiInfoHeader > getGenLumiInfoHeader() const override
std::unique_ptr< HepMC::GenEvent > & event()
std::vector< std::string > const & doSharedResources() const override
lhef::LHERunInfo * lheRunInfo()
bool generatePartonsAndHadronize() override
std::unique_ptr< LHAupLesHouches > lhaUP
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
std::unique_ptr< UserHooks > fReweightRapUserHook
std::unique_ptr< UserHooks > fReweightUserHook
std::string evtgenPdlFile
std::unique_ptr< GenEventInfoProduct > & eventInfo()
unsigned int maxEventsToPrint
def remove(d, key, TELL=False)
std::unique_ptr< UserHooks > fReweightEmpUserHook
Pythia8Hadronizer(const edm::ParameterSet ¶ms)
bool pythiaHepMCVerbosity
std::string evtgenDecFile
std::unique_ptr< ResonanceDecayFilterHook > fResonanceDecayFilterHook
std::unique_ptr< MultiUserHook > fMultiUserHook
HepMC::Pythia8ToHepMC toHepMC
std::unique_ptr< PTFilterHook > fPTFilterHook
std::unique_ptr< Pythia8::Pythia > fMasterGen
static const std::string kPythia8
void finalizeEvent() override
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter
std::unique_ptr< Pythia8::Dire > fDire
std::unique_ptr< Vincia::VinciaPlugin > fvincia
~Pythia8Hadronizer() override