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"
28 #include "Pythia8Plugins/PowhegHooks.h"
33 #include "Pythia8Plugins/EvtGen.h"
50 #include "HepPID/ParticleIDTranslations.hh"
55 class HepRandomEngine;
68 bool initializeForInternalPartons()
override;
69 bool initializeForExternalPartons();
71 bool generatePartonsAndHadronize()
override;
74 virtual bool residualDecay();
76 void finalizeEvent()
override;
80 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
85 virtual std::vector<std::string>
const&
doSharedResources()
const override {
return p8SharedResources; }
91 std::auto_ptr<LHAupLesHouches>
lhaUP;
93 enum { PP,
PPbar, ElectronPositron };
144 comEnergy(params.getParameter<double>(
"comEnergy")),
145 LHEInputFileName(params.getUntrackedParameter<std::
string>(
"LHEInputFileName",
"")),
147 fReweightUserHook(0),fReweightRapUserHook(0),fReweightPtHatRapUserHook(0),
148 fJetMatchingHook(0),fJetMatchingPy8InternalHook(0), fMergingHook(0),
149 fEmissionVetoHook(0), fEmissionVetoHook1(0), nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0),
155 if ( params.
exists(
"PPbarInitialState" ) )
161 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
162 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
169 else if ( params.
exists(
"ElectronPositronInitialState" ) )
175 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
176 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
183 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
187 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
190 if( params.
exists(
"SLHAFileForPythia8" ) ) {
194 fMasterGen->settings.mode(
"SLHA:readFrom", 2);
195 fMasterGen->settings.word(
"SLHA:file", f1.fullPath());
199 if (
line->find(
"SLHA:file") != std::string::npos)
200 throw cms::Exception(
"PythiaError") <<
"Attempted to set SLHA file name twice, "
201 <<
"using Pythia8 card SLHA:file and Pythia8Interface card SLHAFileForPythia8"
205 else if( params.
exists(
"SLHATableForPythia8" ) ) {
208 char tempslhaname[] =
"pythia8SLHAtableXXXXXX";
209 int fd = mkstemp(tempslhaname);
210 write(fd,slhatable.c_str(),slhatable.size());
215 fMasterGen->settings.mode(
"SLHA:readFrom", 2);
220 if (
line->find(
"SLHA:file") != std::string::npos)
221 throw cms::Exception(
"PythiaError") <<
"Attempted to set SLHA file name twice, "
222 <<
"using Pythia8 card SLHA:file and Pythia8Interface card SLHATableForPythia8"
229 if( params.
exists(
"reweightGen" ) )
231 if( params.
exists(
"reweightGenRap" ) )
233 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
243 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
245 if( params.
exists(
"reweightGenPtHatRap" ) )
247 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
257 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
260 if( params.
exists(
"useUserHook" ) )
262 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
266 if ( params.
exists(
"jetMatching") )
271 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
279 if ( params.
exists(
"emissionVeto1") )
293 <<
" Wrong value for EV1_pTempMode code\n";
312 <<
" Too many User Hooks. \n Please choose one from: reweightGen, reweightGenRap, reweightGenPtHatRap, jetMatching, emissionVeto1 \n";
318 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
341 bool status =
false, status1 =
false;
351 fMasterGen->settings.mode(
"Beams:idB", -2212);
362 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
366 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
378 fDecayer->settings.flag(
"ProcessLevel:all",
false );
379 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
380 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
384 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
390 return (status&&status1);
397 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
399 bool status =
false, status1 =
false;
405 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
409 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
415 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
416 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
418 if (internalMatching && internalMerging) {
420 <<
" Only one jet matching/merging scheme can be used at a time. \n";
429 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
430 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
432 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
433 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
434 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
435 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
438 fMergingHook =
new Pythia8::amcnlo_unitarised_interface(scheme);
445 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file "
447 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
448 fMasterGen->settings.mode(
"Beams:frameType", 4);
455 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
463 fMasterGen->settings.mode(
"Beams:frameType", 5);
465 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
478 fDecayer->settings.flag(
"ProcessLevel:all",
false );
479 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
480 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
484 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
491 return (status&&status1);
501 <<
"Number of ISR vetoed = " <<
nISRveto;
503 <<
"Number of FSR vetoed = " <<
nFSRveto;
521 event().reset(
new HepMC::GenEvent);
542 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
549 if (!py8next ||
std::abs(mergeweight)==0.)
560 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
561 DJR.push_back(djrmatch[idjr]);
574 event().reset(
new HepMC::GenEvent);
581 if (mergeweight!=1.) {
582 event()->weights()[0] *= mergeweight;
600 int NPartsBeforeDecays = pythiaEvent->size();
601 int NPartsAfterDecays =
event().get()->particles_size();
603 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
607 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
612 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
615 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
616 part->momentum().x(),
617 part->momentum().y(),
618 part->momentum().z(),
619 part->momentum().t(),
620 part->generated_mass() );
621 HepMC::GenVertex* ProdVtx = part->production_vertex();
622 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
623 ProdVtx->position().z(), ProdVtx->position().t() );
624 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
626 int nentries =
fDecayer->event.size();
627 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
629 int nentries1 =
fDecayer->event.size();
630 if ( nentries1 <= nentries )
continue;
677 <<
"----------------------" << std::endl;
683 <<
"----------------------" << std::endl;
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual bool residualDecay()
ParameterCollector fParameters
double comEnergy
Center-of-Mass energy.
std::auto_ptr< Pythia8::Pythia > fMasterGen
EmissionVetoHook1 * fEmissionVetoHook1
edm::GeneratorFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8GeneratorFilter
bool initializeForInternalPartons() override
UserHooks * fReweightUserHook
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
Pythia8::JetMatchingMadgraph * fJetMatchingPy8InternalHook
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
bool pythiaHepMCVerbosityParticles
void setInternalXSec(const XSec &xsec)
PowhegHooks * fEmissionVetoHook
virtual void beforeHadronization(lhef::LHEEvent *lhee)
std::auto_ptr< HepMC::GenEvent > & event()
virtual std::vector< std::string > const & doSharedResources() const override
GenRunInfoProduct & runInfo()
std::auto_ptr< LHAupLesHouches > lhaUP
lhef::LHEEvent * lheEvent()
UserHooks * fReweightPtHatRapUserHook
EvtGenDecays * evtgenDecays
static const std::vector< std::string > p8SharedResources
Abs< T >::type abs(const T &t)
unsigned int pythiaPylistVerbosity
const char * classname() const override
UserHooks * fReweightRapUserHook
std::auto_ptr< GenEventInfoProduct > & eventInfo()
lhef::LHERunInfo * lheRunInfo()
bool generatePartonsAndHadronize() override
virtual void init(lhef::LHERunInfo *runInfo)
Pythia8::amcnlo_unitarised_interface * fMergingHook
JetMatchingHook * fJetMatchingHook
std::string evtgenPdlFile
unsigned int maxEventsToPrint
std::auto_ptr< Pythia8::Pythia > fDecayer
Pythia8Hadronizer(const edm::ParameterSet ¶ms)
void resetMatchingStatus()
bool pythiaHepMCVerbosity
const_iterator end() const
std::string evtgenDecFile
const_iterator begin() const
HepMC::Pythia8ToHepMC toHepMC
static const std::string kPythia8
void finalizeEvent() override
virtual void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter