8 #include "HepMC/GenEvent.h"
9 #include "HepMC/GenParticle.h"
11 #include "Pythia8/Pythia.h"
12 #include "Pythia8Plugins/HepMC2.h"
22 #include "Pythia8Plugins/JetMatching.h"
23 #include "Pythia8Plugins/aMCatNLOHooks.h"
27 #include "Pythia8Plugins/PowhegHooks.h"
45 #include "HepPID/ParticleIDTranslations.hh"
50 class HepRandomEngine;
54 using namespace Pythia8;
63 bool initializeForInternalPartons()
override;
64 bool initializeForExternalPartons();
66 bool generatePartonsAndHadronize()
override;
69 virtual bool residualDecay();
71 void finalizeEvent()
override;
75 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
80 virtual std::vector<std::string>
const&
doSharedResources()
const override {
return p8SharedResources; }
86 std::auto_ptr<LHAupLesHouches>
lhaUP;
88 enum { PP,
PPbar, ElectronPositron };
139 comEnergy(params.getParameter<double>(
"comEnergy")),
140 LHEInputFileName(params.getUntrackedParameter<
string>(
"LHEInputFileName",
"")),
142 fReweightUserHook(0),fReweightRapUserHook(0),fReweightPtHatRapUserHook(0),
143 fJetMatchingHook(0),fJetMatchingPy8InternalHook(0), fMergingHook(0),
144 fEmissionVetoHook(0), fEmissionVetoHook1(0), nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0),
150 if ( params.
exists(
"PPbarInitialState" ) )
156 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
157 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
164 else if ( params.
exists(
"ElectronPositronInitialState" ) )
170 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
171 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
178 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
182 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
185 if( params.
exists(
"SLHAFileForPythia8" ) ) {
189 fMasterGen->settings.mode(
"SLHA:readFrom", 2);
190 fMasterGen->settings.word(
"SLHA:file", f1.fullPath());
194 if (
line->find(
"SLHA:file") != std::string::npos)
195 throw cms::Exception(
"PythiaError") <<
"Attempted to set SLHA file name twice, "
196 <<
"using Pythia8 card SLHA:file and Pythia8Interface card SLHAFileForPythia8"
200 else if( params.
exists(
"SLHATableForPythia8" ) ) {
203 char tempslhaname[] =
"pythia8SLHAtableXXXXXX";
204 int fd = mkstemp(tempslhaname);
205 write(fd,slhatable.c_str(),slhatable.size());
210 fMasterGen->settings.mode(
"SLHA:readFrom", 2);
215 if (
line->find(
"SLHA:file") != std::string::npos)
216 throw cms::Exception(
"PythiaError") <<
"Attempted to set SLHA file name twice, "
217 <<
"using Pythia8 card SLHA:file and Pythia8Interface card SLHATableForPythia8"
224 if( params.
exists(
"reweightGen" ) )
226 if( params.
exists(
"reweightGenRap" ) )
228 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
238 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
240 if( params.
exists(
"reweightGenPtHatRap" ) )
242 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
252 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
255 if( params.
exists(
"useUserHook" ) )
257 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
261 if ( params.
exists(
"jetMatching") )
266 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
274 if ( params.
exists(
"emissionVeto1") )
288 <<
" Wrong value for EV1_pTempMode code\n";
307 <<
" Too many User Hooks. \n Please choose one from: reweightGen, reweightGenRap, reweightGenPtHatRap, jetMatching, emissionVeto1 \n";
313 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
336 bool status =
false, status1 =
false;
346 fMasterGen->settings.mode(
"Beams:idB", -2212);
357 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
361 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
373 fDecayer->settings.flag(
"ProcessLevel:all",
false );
374 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
375 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
378 return (status&&status1);
385 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
387 bool status =
false, status1 =
false;
393 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
397 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
403 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
404 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
406 if (internalMatching && internalMerging) {
408 <<
" Only one jet matching/merging scheme can be used at a time. \n";
417 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
418 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
420 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
421 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
422 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
423 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
426 fMergingHook =
new Pythia8::amcnlo_unitarised_interface(scheme);
433 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file "
435 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
436 fMasterGen->settings.mode(
"Beams:frameType", 4);
443 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
451 fMasterGen->settings.mode(
"Beams:frameType", 5);
453 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
466 fDecayer->settings.flag(
"ProcessLevel:all",
false );
467 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
468 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
471 return (status&&status1);
481 <<
"Number of ISR vetoed = " <<
nISRveto;
483 <<
"Number of FSR vetoed = " <<
nFSRveto;
499 event().reset(
new HepMC::GenEvent);
520 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
527 if (!py8next ||
std::abs(mergeweight)==0.)
538 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
539 DJR.push_back(djrmatch[idjr]);
550 event().reset(
new HepMC::GenEvent);
557 if (mergeweight!=1.) {
558 event()->weights()[0] *= mergeweight;
577 int NPartsBeforeDecays = pythiaEvent->size();
578 int NPartsAfterDecays =
event().get()->particles_size();
580 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
585 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
590 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
593 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
594 part->momentum().x(),
595 part->momentum().y(),
596 part->momentum().z(),
597 part->momentum().t(),
598 part->generated_mass() );
599 HepMC::GenVertex* ProdVtx = part->production_vertex();
600 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
601 ProdVtx->position().z(), ProdVtx->position().t() );
602 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
604 int nentries =
fDecayer->event.size();
605 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
607 int nentries1 =
fDecayer->event.size();
608 if ( nentries1 <= nentries )
continue;
655 <<
"----------------------" << std::endl;
661 <<
"----------------------" << 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
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
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
unsigned int maxEventsToPrint
std::auto_ptr< Pythia8::Pythia > fDecayer
Pythia8Hadronizer(const edm::ParameterSet ¶ms)
void resetMatchingStatus()
bool pythiaHepMCVerbosity
const_iterator end() const
const_iterator begin() const
HepMC::Pythia8ToHepMC toHepMC
static const std::string kPythia8
void finalizeEvent() override
virtual void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
bool append_event(Pythia8::Event &pyev, GenEvent *evt, GenParticle *rootpart, int ibarcode=-1, Pythia8::Info *pyinfo=0, Pythia8::Settings *pyset=0)
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter