8 #include <HepMC/GenEvent.h>
9 #include <HepMC/GenParticle.h>
12 #include <HepMCInterface.h>
43 #include "HepPID/ParticleIDTranslations.hh"
48 class HepRandomEngine;
52 using namespace Pythia8;
61 bool initializeForInternalPartons()
override;
62 bool initializeForExternalPartons();
64 bool generatePartonsAndHadronize()
override;
67 virtual bool residualDecay();
69 void finalizeEvent()
override;
73 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
78 virtual std::vector<std::string>
const&
doSharedResources()
const override {
return p8SharedResources; }
84 std::auto_ptr<LHAupLesHouches>
lhaUP;
86 enum { PP,
PPbar, ElectronPositron };
121 comEnergy(params.getParameter<double>(
"comEnergy")),
122 LHEInputFileName(params.getUntrackedParameter<
string>(
"LHEInputFileName",
"")),
124 fReweightUserHook(0),
126 fEmissionVetoHook(0),fEmissionVetoHook1(0)
131 if ( params.
exists(
"PPbarInitialState" ) )
137 <<
"Pythia6 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
138 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
139 std::cout <<
"Pythia6 will be initialized for PROTON-ANTIPROTON INITIAL STATE." << std::endl;
140 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
147 else if ( params.
exists(
"ElectronPositronInitialState" ) )
153 <<
"Pythia6 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
154 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
155 std::cout <<
"Pythia6 will be initialized for ELECTRON-POSITRON INITIAL STATE." << std::endl;
156 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
163 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
167 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
170 if( params.
exists(
"SLHAFileForPythia8" ) ) {
178 if (
line->find(
"SLHA:file") != std::string::npos)
179 throw cms::Exception(
"PythiaError") <<
"Attempted to set SLHA file name twice, "
180 <<
"using Pythia8 card SLHA:file and Pythia8Interface card SLHAFileForPythia8"
187 if( params.
exists(
"reweightGen" ) )
190 if( params.
exists(
"useUserHook" ) )
192 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
196 if ( params.
exists(
"jetMatching") )
201 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
209 if ( params.
exists(
"emissionVeto") )
214 if ( params.
exists(
"emissionVeto1") )
228 <<
" Wrong value for EV1_pTempMode code\n";
247 <<
" Too many User Hooks. \n Please choose one from: reweightGen, jetMatching, emissionVeto \n";
252 cout <<
"Turning on Emission Veto Hook";
255 int nversion = (int)(1000.*(
fMasterGen->settings.parm(
"Pythia:versionNumber") - 8.));
257 cout <<
"obsolete pythia8 version for this Emission Veto code" << endl;
258 cout <<
"Please update pythia8 version using the instructions here:" << endl;
259 cout <<
"https://twiki.cern.ch/twiki/bin/view/CMS/Pythia8Interface" << endl;
260 cout <<
"or try to use tag V00-01-28 of this interface" << endl;
262 <<
" Obsolete pythia8 version for this Emission Veto code\n";
299 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
313 fDecayer->readString(
"ProcessLevel:all = off");
314 fDecayer->readString(
"Standalone:allowResDec=on");
325 std::cout <<
"Initializing for external partons" << std::endl;
359 fDecayer->readString(
"ProcessLevel:all = off");
360 fDecayer->readString(
"Standalone:allowResDec=on");
374 else if (status > -30 && status < 0)
397 event().reset(
new HepMC::GenEvent);
426 event().reset(
new HepMC::GenEvent);
437 int NPartsBeforeDecays = pythiaEvent->size();
438 int NPartsAfterDecays =
event().get()->particles_size();
439 int NewBarcode = NPartsAfterDecays;
441 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
446 if ( part->status() == 1 )
449 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
450 part->momentum().x(),
451 part->momentum().y(),
452 part->momentum().z(),
453 part->momentum().t(),
454 part->generated_mass() );
455 HepMC::GenVertex* ProdVtx = part->production_vertex();
456 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
457 ProdVtx->position().z(), ProdVtx->position().t() );
458 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
460 int nentries =
fDecayer->event.size();
461 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
463 int nentries1 =
fDecayer->event.size();
465 if ( nentries1 <= nentries )
continue;
469 Particle& py8daughter =
fDecayer->event[nentries];
470 HepMC::GenVertex* DecVtx =
new HepMC::GenVertex( HepMC::FourVector(py8daughter.xProd(),
473 py8daughter.tProd()) );
475 DecVtx->add_particle_in( part );
478 HepMC::FourVector pmom( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
484 daughter->suggest_barcode( NewBarcode );
485 DecVtx->add_particle_out( daughter );
487 for (
int ipart1=nentries+1; ipart1<nentries1; ipart1++ )
489 py8daughter =
fDecayer->event[ipart1];
490 HepMC::FourVector pmomN( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
494 daughterN->suggest_barcode( NewBarcode );
495 DecVtx->add_particle_out( daughterN );
498 event().get()->add_vertex( DecVtx );
536 <<
"----------------------" << 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
EmissionVetoHook * fEmissionVetoHook
bool initializeForExternalPartons()
#define DEFINE_FWK_MODULE(type)
void statistics() override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
void setInternalXSec(const XSec &xsec)
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()
static const std::vector< std::string > p8SharedResources
unsigned int pythiaPylistVerbosity
const char * classname() const override
std::auto_ptr< GenEventInfoProduct > & eventInfo()
lhef::LHERunInfo * lheRunInfo()
bool generatePartonsAndHadronize() override
virtual void init(lhef::LHERunInfo *runInfo)
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
static const std::string kPythia8
void finalizeEvent() override
virtual void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter