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 };
137 comEnergy(params.getParameter<double>(
"comEnergy")),
138 LHEInputFileName(params.getUntrackedParameter<
string>(
"LHEInputFileName",
"")),
140 fReweightUserHook(0),fReweightRapUserHook(0),fReweightPtHatRapUserHook(0),
141 fJetMatchingHook(0),fJetMatchingPy8InternalHook(0), fMergingHook(0),
142 fEmissionVetoHook(0), fEmissionVetoHook1(0), nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0),
148 if ( params.
exists(
"PPbarInitialState" ) )
154 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
155 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
162 else if ( params.
exists(
"ElectronPositronInitialState" ) )
168 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
169 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
176 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
180 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
183 if( params.
exists(
"SLHAFileForPythia8" ) ) {
188 fMasterGen->settings.mode(
"SLHA:readFrom", 2);
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"
202 if( params.
exists(
"reweightGen" ) )
204 if( params.
exists(
"reweightGenRap" ) )
206 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
216 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
218 if( params.
exists(
"reweightGenPtHatRap" ) )
220 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
230 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
233 if( params.
exists(
"useUserHook" ) )
235 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
239 if ( params.
exists(
"jetMatching") )
244 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
252 if ( params.
exists(
"emissionVeto1") )
266 <<
" Wrong value for EV1_pTempMode code\n";
285 <<
" Too many User Hooks. \n Please choose one from: reweightGen, reweightGenRap, reweightGenPtHatRap, jetMatching, emissionVeto1 \n";
291 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
322 fMasterGen->settings.mode(
"Beams:idB", -2212);
338 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
354 fDecayer->settings.flag(
"ProcessLevel:all",
false );
355 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
365 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
373 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
377 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
383 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
384 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
386 if (internalMatching && internalMerging) {
388 <<
" Only one jet matching/merging scheme can be used at a time. \n";
397 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
398 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
400 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
401 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
402 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
403 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
406 fMergingHook =
new Pythia8::amcnlo_unitarised_interface(scheme);
413 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file "
415 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
417 fMasterGen->settings.mode(
"Beams:frameType", 4);
432 fMasterGen->settings.mode(
"Beams:frameType", 5);
448 fDecayer->settings.flag(
"ProcessLevel:all",
false );
449 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
462 <<
"Number of ISR vetoed = " <<
nISRveto;
464 <<
"Number of FSR vetoed = " <<
nFSRveto;
480 event().reset(
new HepMC::GenEvent);
501 double mergeweight =
fMasterGen.get()->info.mergingWeight();
504 if (!py8next ||
std::abs(mergeweight)==0.)
515 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
516 DJR.push_back(djrmatch[idjr]);
527 event().reset(
new HepMC::GenEvent);
534 if (mergeweight!=1.) {
535 event()->weights().push_back(mergeweight);
554 int NPartsBeforeDecays = pythiaEvent->size();
555 int NPartsAfterDecays =
event().get()->particles_size();
556 int NewBarcode = NPartsAfterDecays;
558 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
563 if ( part->status() == 1 )
566 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
567 part->momentum().x(),
568 part->momentum().y(),
569 part->momentum().z(),
570 part->momentum().t(),
571 part->generated_mass() );
572 HepMC::GenVertex* ProdVtx = part->production_vertex();
573 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
574 ProdVtx->position().z(), ProdVtx->position().t() );
575 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
577 int nentries =
fDecayer->event.size();
578 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
580 int nentries1 =
fDecayer->event.size();
581 if ( nentries1 <= nentries )
continue;
585 Particle& py8daughter =
fDecayer->event[nentries];
586 HepMC::GenVertex* DecVtx =
new HepMC::GenVertex( HepMC::FourVector(py8daughter.xProd(),
589 py8daughter.tProd()) );
591 DecVtx->add_particle_in( part );
594 HepMC::FourVector pmom( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
600 daughter->suggest_barcode( NewBarcode );
601 DecVtx->add_particle_out( daughter );
603 for (
int ipart1=nentries+1; ipart1<nentries1; ipart1++ )
605 py8daughter =
fDecayer->event[ipart1];
606 HepMC::FourVector pmomN( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
610 daughterN->suggest_barcode( NewBarcode );
611 DecVtx->add_particle_out( daughterN );
614 event().get()->add_vertex( DecVtx );
655 <<
"----------------------" << 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
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)
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