8 #include "HepMC/GenEvent.h"
9 #include "HepMC/GenParticle.h"
11 #include "Pythia8/Pythia.h"
12 #include "Pythia8/Pythia8ToHepMC.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 };
125 comEnergy(params.getParameter<double>(
"comEnergy")),
126 LHEInputFileName(params.getUntrackedParameter<
string>(
"LHEInputFileName",
"")),
128 fReweightUserHook(0),fReweightRapUserHook(0),fReweightPtHatRapUserHook(0),
130 fEmissionVetoHook(0),fEmissionVetoHook1(0)
135 if ( params.
exists(
"PPbarInitialState" ) )
141 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
142 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
149 else if ( params.
exists(
"ElectronPositronInitialState" ) )
155 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
156 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
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" ) )
189 if( params.
exists(
"reweightGenRap" ) )
191 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
201 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
203 if( params.
exists(
"reweightGenPtHatRap" ) )
205 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
215 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
218 if( params.
exists(
"useUserHook" ) )
220 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
224 if ( params.
exists(
"jetMatching") )
229 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
237 if ( params.
exists(
"emissionVeto") )
242 if ( params.
exists(
"emissionVeto1") )
256 <<
" Wrong value for EV1_pTempMode code\n";
277 <<
" Too many User Hooks. \n Please choose one from: reweightGen, reweightGenRap, reweightGenPtHatRap, jetMatching, emissionVeto, emissionVeto1 \n";
283 std::cout <<
"Turning on Emission Veto Hook";
321 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
335 fDecayer->readString(
"ProcessLevel:all = off");
336 fDecayer->readString(
"ProcessLevel::resonanceDecays=on");
346 std::cout <<
"Initializing for external partons" << std::endl;
371 bool doslha = !slha.empty() &&
slhafile_.empty();
376 for(std::vector<std::string>::const_iterator iter = slha.begin();
377 iter != slha.end(); ++iter) {
406 fDecayer->readString(
"ProcessLevel:all = off");
407 fDecayer->readString(
"ProcessLevel::resonanceDecays=on");
429 event().reset(
new HepMC::GenEvent);
458 event().reset(
new HepMC::GenEvent);
469 int NPartsBeforeDecays = pythiaEvent->size();
470 int NPartsAfterDecays =
event().get()->particles_size();
471 int NewBarcode = NPartsAfterDecays;
473 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
478 if ( part->status() == 1 )
481 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
482 part->momentum().x(),
483 part->momentum().y(),
484 part->momentum().z(),
485 part->momentum().t(),
486 part->generated_mass() );
487 HepMC::GenVertex* ProdVtx = part->production_vertex();
488 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
489 ProdVtx->position().z(), ProdVtx->position().t() );
490 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
492 int nentries =
fDecayer->event.size();
493 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
495 int nentries1 =
fDecayer->event.size();
496 if ( nentries1 <= nentries )
continue;
500 Particle& py8daughter =
fDecayer->event[nentries];
501 HepMC::GenVertex* DecVtx =
new HepMC::GenVertex( HepMC::FourVector(py8daughter.xProd(),
504 py8daughter.tProd()) );
506 DecVtx->add_particle_in( part );
509 HepMC::FourVector pmom( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
515 daughter->suggest_barcode( NewBarcode );
516 DecVtx->add_particle_out( daughter );
518 for (
int ipart1=nentries+1; ipart1<nentries1; ipart1++ )
520 py8daughter =
fDecayer->event[ipart1];
521 HepMC::FourVector pmomN( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
525 daughterN->suggest_barcode( NewBarcode );
526 DecVtx->add_particle_out( daughterN );
529 event().get()->add_vertex( DecVtx );
566 <<
"----------------------" << 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()
UserHooks * fReweightPtHatRapUserHook
static const std::vector< std::string > p8SharedResources
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)
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
std::vector< std::string > findHeader(const std::string &tag) const
static const std::string kPythia8
void finalizeEvent() override
virtual void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter