8 #include "HepMC/GenEvent.h"
9 #include "HepMC/GenParticle.h"
11 #include "Pythia8/Pythia.h"
12 #include "Pythia8/Pythia8ToHepMC.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 };
132 comEnergy(params.getParameter<double>(
"comEnergy")),
133 LHEInputFileName(params.getUntrackedParameter<
string>(
"LHEInputFileName",
"")),
135 fReweightUserHook(0),fReweightRapUserHook(0),fReweightPtHatRapUserHook(0),
136 fJetMatchingHook(0),fJetMatchingPy8InternalHook(0), fSetNumberOfPartonsDynamicallyHook(0),
137 fEmissionVetoHook(0),fEmissionVetoHook1(0), nME(-1), nMEFiltered(-1)
142 if ( params.
exists(
"PPbarInitialState" ) )
148 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
149 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
156 else if ( params.
exists(
"ElectronPositronInitialState" ) )
162 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
163 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
170 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
174 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
177 if( params.
exists(
"SLHAFileForPythia8" ) ) {
185 if (
line->find(
"SLHA:file") != std::string::npos)
186 throw cms::Exception(
"PythiaError") <<
"Attempted to set SLHA file name twice, "
187 <<
"using Pythia8 card SLHA:file and Pythia8Interface card SLHAFileForPythia8"
194 if( params.
exists(
"reweightGen" ) )
196 if( params.
exists(
"reweightGenRap" ) )
198 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
208 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
210 if( params.
exists(
"reweightGenPtHatRap" ) )
212 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
222 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
225 if( params.
exists(
"useUserHook" ) )
227 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
231 if ( params.
exists(
"jetMatching") )
236 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
240 else if (scheme ==
"MadgraphPy8Internal") {
243 else if (scheme ==
"CKKWPy8Internal") {
250 if ( params.
exists(
"emissionVeto") )
255 if ( params.
exists(
"emissionVeto1") )
269 <<
" Wrong value for EV1_pTempMode code\n";
292 <<
" Too many User Hooks. \n Please choose one from: reweightGen, reweightGenRap, reweightGenPtHatRap, jetMatching, emissionVeto, emissionVeto1 \n";
300 std::cout <<
"Turning on Emission Veto Hook";
338 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
352 fDecayer->readString(
"ProcessLevel:all = off");
353 fDecayer->readString(
"ProcessLevel::resonanceDecays=on");
363 std::cout <<
"Initializing for external partons" << std::endl;
388 bool doslha = !slha.empty() &&
slhafile_.empty();
393 for(std::vector<std::string>::const_iterator
iter = slha.begin();
423 fDecayer->readString(
"ProcessLevel:all = off");
424 fDecayer->readString(
"ProcessLevel::resonanceDecays=on");
446 event().reset(
new HepMC::GenEvent);
467 double mergeweight =
fMasterGen.get()->info.mergingWeight();
470 if (!py8next || mergeweight<=0.)
481 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
482 DJR.push_back(djrmatch[idjr]);
493 event().reset(
new HepMC::GenEvent);
500 if (mergeweight!=1.) {
501 event()->weights().push_back(mergeweight);
515 int NPartsBeforeDecays = pythiaEvent->size();
516 int NPartsAfterDecays =
event().get()->particles_size();
517 int NewBarcode = NPartsAfterDecays;
519 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
524 if ( part->status() == 1 )
527 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
528 part->momentum().x(),
529 part->momentum().y(),
530 part->momentum().z(),
531 part->momentum().t(),
532 part->generated_mass() );
533 HepMC::GenVertex* ProdVtx = part->production_vertex();
534 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
535 ProdVtx->position().z(), ProdVtx->position().t() );
536 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
538 int nentries =
fDecayer->event.size();
539 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
541 int nentries1 =
fDecayer->event.size();
542 if ( nentries1 <= nentries )
continue;
546 Particle& py8daughter =
fDecayer->event[nentries];
547 HepMC::GenVertex* DecVtx =
new HepMC::GenVertex( HepMC::FourVector(py8daughter.xProd(),
550 py8daughter.tProd()) );
552 DecVtx->add_particle_in( part );
555 HepMC::FourVector pmom( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
561 daughter->suggest_barcode( NewBarcode );
562 DecVtx->add_particle_out( daughter );
564 for (
int ipart1=nentries+1; ipart1<nentries1; ipart1++ )
566 py8daughter =
fDecayer->event[ipart1];
567 HepMC::FourVector pmomN( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
571 daughterN->suggest_barcode( NewBarcode );
572 DecVtx->add_particle_out( daughterN );
575 event().get()->add_vertex( DecVtx );
616 <<
"----------------------" << 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
JetMatchingMadgraph * fJetMatchingPy8InternalHook
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
SetNumberOfPartonsDynamically * fSetNumberOfPartonsDynamicallyHook