8 #include "HepMC/GenEvent.h"
9 #include "HepMC/GenParticle.h"
11 #include "Pythia8/Pythia.h"
12 #include "Pythia8Plugins/HepMC2.h"
14 using namespace Pythia8;
23 #include "Pythia8Plugins/JetMatching.h"
24 #include "Pythia8Plugins/aMCatNLOHooks.h"
30 #include "Pythia8Plugins/PowhegHooks.h"
38 #include "Pythia8Plugins/EvtGen.h"
54 #include "HepPID/ParticleIDTranslations.hh"
59 class HepRandomEngine;
72 bool initializeForInternalPartons()
override;
73 bool initializeForExternalPartons();
75 bool generatePartonsAndHadronize()
override;
78 virtual bool residualDecay();
80 void finalizeEvent()
override;
84 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
91 virtual std::vector<std::string>
const&
doSharedResources()
const override {
return p8SharedResources; }
97 std::auto_ptr<LHAupLesHouches>
lhaUP;
99 enum { PP,
PPbar, ElectronPositron };
154 comEnergy(params.getParameter<double>(
"comEnergy")),
155 LHEInputFileName(params.getUntrackedParameter<std::
string>(
"LHEInputFileName",
"")),
157 nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0)
162 if ( params.
exists(
"PPbarInitialState" ) )
168 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
169 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
176 else if ( params.
exists(
"ElectronPositronInitialState" ) )
182 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
183 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
190 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
194 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
199 if( params.
exists(
"reweightGen" ) )
201 if( params.
exists(
"reweightGenRap" ) )
203 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
214 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
216 if( params.
exists(
"reweightGenPtHatRap" ) )
218 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
229 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
232 if( params.
exists(
"useUserHook" ) )
234 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
238 if ( params.
exists(
"jetMatching") )
243 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
251 if ( params.
exists(
"emissionVeto1") )
265 <<
" Wrong value for EV1_pTempMode code\n";
288 bool status =
false, status1 =
false;
299 fMasterGen->settings.mode(
"Beams:idB", -2212);
310 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
315 fMasterGen->settings.mode(
"Beams:frameType", 4);
326 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
330 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
334 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
338 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
343 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
344 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
346 if (internalMatching && internalMerging) {
348 <<
" Only one jet matching/merging scheme can be used at a time. \n";
351 if (internalMatching) {
356 if (internalMerging) {
357 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
358 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
360 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
361 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
362 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
363 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
366 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
370 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
371 if (resonanceDecayFilter) {
380 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
397 fDecayer->settings.flag(
"ProcessLevel:all",
false );
398 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
399 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
403 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
409 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
422 std::vector<std::pair<int,std::string> > fWeightKeysTmp;
423 fWeightKeysTmp.reserve(
fMasterGen->info.initrwgt->weights.size());
425 for (
const auto &wgt :
fMasterGen->info.initrwgt->weights) {
426 fWeightKeysTmp.emplace_back(std::stoi(wgt.first),wgt.first);
429 std::sort(fWeightKeysTmp.begin(),fWeightKeysTmp.end());
431 for (
const auto &wgt : fWeightKeysTmp) {
436 return (status&&status1);
443 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
445 bool status =
false, status1 =
false;
454 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
458 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
462 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
466 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
471 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
472 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
474 if (internalMatching && internalMerging) {
476 <<
" Only one jet matching/merging scheme can be used at a time. \n";
479 if (internalMatching) {
484 if (internalMerging) {
485 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
486 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
488 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
489 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
490 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
491 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
494 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
498 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
499 if (resonanceDecayFilter) {
510 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file "
512 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
513 fMasterGen->settings.mode(
"Beams:frameType", 4);
520 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
528 fMasterGen->settings.mode(
"Beams:frameType", 5);
530 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
548 fDecayer->settings.flag(
"ProcessLevel:all",
false );
549 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
550 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
554 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
561 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
566 return (status&&status1);
576 <<
"Number of ISR vetoed = " <<
nISRveto;
578 <<
"Number of FSR vetoed = " <<
nFSRveto;
604 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
620 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
621 DJR.push_back(djrmatch[idjr]);
630 event().reset(
new HepMC::GenEvent);
638 if (mergeweight!=1.) {
639 event()->weights()[0] *= mergeweight;
652 event()->weights().push_back(wgt);
675 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
682 if (!py8next ||
std::abs(mergeweight)==0.)
693 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
694 DJR.push_back(djrmatch[idjr]);
707 event().reset(
new HepMC::GenEvent);
714 if (mergeweight!=1.) {
715 event()->weights()[0] *= mergeweight;
733 int NPartsBeforeDecays = pythiaEvent->size();
734 int NPartsAfterDecays =
event().get()->particles_size();
736 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
740 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
745 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
748 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
749 part->momentum().x(),
750 part->momentum().y(),
751 part->momentum().z(),
752 part->momentum().t(),
753 part->generated_mass() );
754 HepMC::GenVertex* ProdVtx = part->production_vertex();
755 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
756 ProdVtx->position().z(), ProdVtx->position().t() );
757 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
759 int nentries =
fDecayer->event.size();
760 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
762 int nentries1 =
fDecayer->event.size();
763 if ( nentries1 <= nentries )
continue;
810 <<
"----------------------" << std::endl;
816 <<
"----------------------" << std::endl;
837 genLumiInfoHeader->
weightNames().push_back(
"nominal");
840 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
841 if (wgtgrp.second.weights.count(
key)) {
842 if (!wgtgrp.first.empty()) {
843 weightgroupname = wgtgrp.first;
845 else if (wgtgrp.second.attributes.count(
"type")) {
846 weightgroupname = wgtgrp.second.attributes.find(
"type")->second;
852 std::ostringstream weightname;
853 weightname <<
"LHE, id = " <<
key <<
", ";
854 if (!weightgroupname.empty()) {
855 weightname << weightgroupname <<
", ";
857 weightname<<
fMasterGen->info.initrwgt->weights[
key].contents;
858 genLumiInfoHeader->
weightNames().push_back(weightname.str());
861 return genLumiInfoHeader;
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::auto_ptr< PowhegHooks > fEmissionVetoHook
virtual bool residualDecay()
double comEnergy
Center-of-Mass energy.
std::auto_ptr< Pythia8::Pythia > fMasterGen
edm::GeneratorFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8GeneratorFilter
std::auto_ptr< ResonanceDecayFilterHook > fResonanceDecayFilterHook
bool initializeForInternalPartons() override
std::auto_ptr< EvtGenDecays > evtgenDecays
HepMC::IO_AsciiParticles * ascii_io
bool initializeForExternalPartons()
#define DEFINE_FWK_MODULE(type)
void statistics() override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::string LHEInputFileName
GenLumiInfoHeader * getGenLumiInfoHeader() const override
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
std::auto_ptr< JetMatchingHook > fJetMatchingHook
bool pythiaHepMCVerbosityParticles
void setInternalXSec(const XSec &xsec)
std::auto_ptr< HepMC::GenEvent > & event()
virtual std::vector< std::string > const & doSharedResources() const override
std::vector< std::string > fSortedWeightKeys
std::vector< std::string > evtgenUserFiles
GenRunInfoProduct & runInfo()
std::auto_ptr< LHAupLesHouches > lhaUP
lhef::LHEEvent * lheEvent()
std::auto_ptr< MultiUserHook > fMultiUserHook
static const std::vector< std::string > p8SharedResources
Abs< T >::type abs(const T &t)
std::auto_ptr< UserHooks > fReweightPtHatRapUserHook
unsigned int pythiaPylistVerbosity
const char * classname() const override
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
std::auto_ptr< GenEventInfoProduct > & eventInfo()
lhef::LHERunInfo * lheRunInfo()
bool generatePartonsAndHadronize() override
std::auto_ptr< UserHooks > fReweightUserHook
std::string evtgenPdlFile
unsigned int maxEventsToPrint
std::auto_ptr< UserHooks > fReweightRapUserHook
std::auto_ptr< Pythia8::Pythia > fDecayer
Pythia8Hadronizer(const edm::ParameterSet ¶ms)
bool pythiaHepMCVerbosity
std::string evtgenDecFile
HepMC::Pythia8ToHepMC toHepMC
static const std::string kPythia8
void finalizeEvent() override
std::auto_ptr< Pythia8::JetMatchingMadgraph > fJetMatchingPy8InternalHook
virtual void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter
std::auto_ptr< EmissionVetoHook1 > fEmissionVetoHook1
std::auto_ptr< Pythia8::amcnlo_unitarised_interface > fMergingHook