8 #include "HepMC/GenEvent.h"
9 #include "HepMC/GenParticle.h"
11 #include "Pythia8/Pythia.h"
12 #include "Pythia8Plugins/HepMC2.h"
21 #include "Pythia8Plugins/JetMatching.h"
22 #include "Pythia8Plugins/aMCatNLOHooks.h"
26 #include "Pythia8Plugins/PowhegHooks.h"
44 #include "HepPID/ParticleIDTranslations.hh"
49 class HepRandomEngine;
53 using namespace Pythia8;
62 bool initializeForInternalPartons()
override;
63 bool initializeForExternalPartons();
65 bool generatePartonsAndHadronize()
override;
68 virtual bool residualDecay();
70 void finalizeEvent()
override;
74 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
79 virtual std::vector<std::string>
const&
doSharedResources()
const override {
return p8SharedResources; }
85 std::auto_ptr<LHAupLesHouches>
lhaUP;
87 enum { PP,
PPbar, ElectronPositron };
138 comEnergy(params.getParameter<double>(
"comEnergy")),
139 LHEInputFileName(params.getUntrackedParameter<
string>(
"LHEInputFileName",
"")),
141 fReweightUserHook(0),fReweightRapUserHook(0),fReweightPtHatRapUserHook(0),
142 fJetMatchingHook(0),fJetMatchingPy8InternalHook(0), fMergingHook(0),
143 fEmissionVetoHook(0), fEmissionVetoHook1(0), nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0),
149 if ( params.
exists(
"PPbarInitialState" ) )
155 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
156 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
163 else if ( params.
exists(
"ElectronPositronInitialState" ) )
169 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
170 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
177 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
181 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
184 if( params.
exists(
"SLHAFileForPythia8" ) ) {
188 fMasterGen->settings.mode(
"SLHA:readFrom", 2);
189 fMasterGen->settings.word(
"SLHA:file", f1.fullPath());
193 if (
line->find(
"SLHA:file") != std::string::npos)
194 throw cms::Exception(
"PythiaError") <<
"Attempted to set SLHA file name twice, "
195 <<
"using Pythia8 card SLHA:file and Pythia8Interface card SLHAFileForPythia8"
199 else if( params.
exists(
"SLHATableForPythia8" ) ) {
202 char tempslhaname[] =
"pythia8SLHAtableXXXXXX";
203 int fd = mkstemp(tempslhaname);
204 write(fd,slhatable.c_str(),slhatable.size());
209 fMasterGen->settings.mode(
"SLHA:readFrom", 2);
214 if (
line->find(
"SLHA:file") != std::string::npos)
215 throw cms::Exception(
"PythiaError") <<
"Attempted to set SLHA file name twice, "
216 <<
"using Pythia8 card SLHA:file and Pythia8Interface card SLHATableForPythia8"
223 if( params.
exists(
"reweightGen" ) )
225 if( params.
exists(
"reweightGenRap" ) )
227 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
237 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
239 if( params.
exists(
"reweightGenPtHatRap" ) )
241 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") )
265 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
273 if ( params.
exists(
"emissionVeto1") )
287 <<
" Wrong value for EV1_pTempMode code\n";
306 <<
" Too many User Hooks. \n Please choose one from: reweightGen, reweightGenRap, reweightGenPtHatRap, jetMatching, emissionVeto1 \n";
312 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
335 bool status =
false, status1 =
false;
345 fMasterGen->settings.mode(
"Beams:idB", -2212);
356 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
360 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
372 fDecayer->settings.flag(
"ProcessLevel:all",
false );
373 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
374 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
377 return (status&&status1);
384 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
386 bool status =
false, status1 =
false;
392 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
396 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
402 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
403 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
405 if (internalMatching && internalMerging) {
407 <<
" Only one jet matching/merging scheme can be used at a time. \n";
416 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
417 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
419 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
420 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
421 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
422 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
425 fMergingHook =
new Pythia8::amcnlo_unitarised_interface(scheme);
432 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file "
434 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
435 fMasterGen->settings.mode(
"Beams:frameType", 4);
442 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
450 fMasterGen->settings.mode(
"Beams:frameType", 5);
452 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
465 fDecayer->settings.flag(
"ProcessLevel:all",
false );
466 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
467 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
470 return (status&&status1);
480 <<
"Number of ISR vetoed = " <<
nISRveto;
482 <<
"Number of FSR vetoed = " <<
nFSRveto;
498 event().reset(
new HepMC::GenEvent);
519 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
526 if (!py8next ||
std::abs(mergeweight)==0.)
537 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
538 DJR.push_back(djrmatch[idjr]);
549 event().reset(
new HepMC::GenEvent);
556 if (mergeweight!=1.) {
557 event()->weights()[0] *= mergeweight;
576 int NPartsBeforeDecays = pythiaEvent->size();
577 int NPartsAfterDecays =
event().get()->particles_size();
579 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
583 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
588 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
591 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
592 part->momentum().x(),
593 part->momentum().y(),
594 part->momentum().z(),
595 part->momentum().t(),
596 part->generated_mass() );
597 HepMC::GenVertex* ProdVtx = part->production_vertex();
598 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
599 ProdVtx->position().z(), ProdVtx->position().t() );
600 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
602 int nentries =
fDecayer->event.size();
603 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
605 int nentries1 =
fDecayer->event.size();
606 if ( nentries1 <= nentries )
continue;
653 <<
"----------------------" << std::endl;
659 <<
"----------------------" << 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
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter