7 #include "HepMC/GenEvent.h"
8 #include "HepMC/GenParticle.h"
10 #include "Pythia8/Pythia.h"
11 #include "Pythia8/Pythia8ToHepMC.h"
41 #include "HepPID/ParticleIDTranslations.hh"
46 using namespace Pythia8;
53 bool readSettings(
int );
54 bool initializeForInternalPartons();
55 bool initializeForExternalPartons();
57 bool declareStableParticles(
const std::vector<int> &pdgIds);
58 bool declareSpecialSettings(
const std::vector<std::string> );
62 bool generatePartonsAndHadronize();
68 const char *
classname()
const {
return "Pythia8Hadronizer"; }
84 std::auto_ptr<LHAupLesHouches>
lhaUP;
91 enum { PP,
PPbar, ElectronPositron };
126 comEnergy(params.getParameter<double>(
"comEnergy")),
130 LHEInputFileName(params.getUntrackedParameter<string>(
"LHEInputFileName",
"")),
132 fReweightUserHook(0),
134 fEmissionVetoHook(0),fEmissionVetoHook1(0)
152 if ( params.
exists(
"PPbarInitialState" ) )
158 <<
"Pythia6 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
159 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
160 std::cout <<
"Pythia6 will be initialized for PROTON-ANTIPROTON INITIAL STATE." << std::endl;
161 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
168 else if ( params.
exists(
"ElectronPositronInitialState" ) )
174 <<
"Pythia6 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
175 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
176 std::cout <<
"Pythia6 will be initialized for ELECTRON-POSITRON INITIAL STATE." << std::endl;
177 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
184 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
188 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
194 pythia->setRndmEnginePtr(RP8);
195 decayer->setRndmEnginePtr(RP8);
197 if( params.
exists(
"SLHAFileForPythia8" ) ) {
198 std::string slhafilenameshort = params.
getParameter<
string>(
"SLHAFileForPythia8");
201 std::string pythiacommandslha = std::string(
"SLHA:file = ") +
slhafile_;
202 pythia->readString(pythiacommandslha);
205 if (
line->find(
"SLHA:file") != std::string::npos)
206 throw cms::Exception(
"PythiaError") <<
"Attempted to set SLHA file name twice, "
207 <<
"using Pythia8 card SLHA:file and Pythia8Interface card SLHAFileForPythia8"
214 if( params.
exists(
"reweightGen" ) )
219 if ( params.
exists(
"jetMatching") )
228 if(params.
exists(
"EV_CheckHard"))
230 <<
" Parameter EV_CheckHard is no more used\n";
231 if(params.
exists(
"EV1_CheckHard"))
233 <<
" Parameter EV1_CheckHard does not exist\n";
235 if ( params.
exists(
"emissionVeto") )
242 if ( params.
exists(
"emissionVeto1") )
256 <<
" Wrong value for EV1_pTempMode code\n";
275 <<
" Too many User Hooks. \n Please choose one from: reweightGen, jetMatching, emissionVeto \n";
297 if (
line->find(
"Random:") != std::string::npos)
298 throw cms::Exception(
"PythiaError") <<
"Attempted to set random number "
299 "using Pythia commands. Please use " "the RandomNumberGeneratorService."
303 <<
"Pythia 8 did not accept \""
304 << *
line <<
"\"." << std::endl;
309 pythia->settings.listAll();
311 pythia->particleData.listAll();
339 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
342 pythia->settings.listChanged();
351 std::cout <<
"Initializing for external partons" << std::endl;
373 bool doslha = !slha.empty() &&
slhafile_.empty();
378 for(std::vector<std::string>::const_iterator iter = slha.begin();
379 iter != slha.end(); ++iter) {
384 std::string lhareadcmd =
"SLHA:readFrom = 2";
385 std::string lhafilecmd = std::string(
"SLHA:file = ") + std::string(fname);
387 pythia->readString(lhareadcmd);
388 pythia->readString(lhafilecmd);
419 else if (status > -30 && status < 0)
429 for (
size_t i=0;
i<pdgIds.size();
i++ )
437 int PyID = pdgIds[
i];
438 std::ostringstream pyCard ;
439 pyCard << PyID <<
":mayDecay=false";
440 pythia->readString( pyCard.str() );
448 decayer->readString(
"ProcessLevel:all = off");
457 for (
unsigned int iss=0; iss<settings.size(); iss++ )
459 if ( settings[iss].
find(
"QED-brem-off") == std::string::npos )
continue;
460 pythia->readString(
"TimeShower:QEDshowerByL=off" );
471 double xsec =
pythia->info.sigmaGen();
479 if (!
pythia->next())
return false;
481 event().reset(
new HepMC::GenEvent);
498 bool py8next =
pythia->next();
511 event().reset(
new HepMC::GenEvent);
528 int NPartsAfterDecays =
event().get()->particles_size();
529 int NewBarcode = NPartsAfterDecays;
531 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
536 if ( part->status() == 1 )
539 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
540 part->momentum().x(),
541 part->momentum().y(),
542 part->momentum().z(),
543 part->momentum().t(),
544 part->generated_mass() );
545 HepMC::GenVertex* ProdVtx = part->production_vertex();
546 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
547 ProdVtx->position().z(), ProdVtx->position().t() );
548 py8part.tau( (
decayer->particleData).tau0( part->pdg_id() ) );
549 decayer->event.append( py8part );
550 int nentries =
decayer->event.size();
551 if ( !
decayer->event[nentries-1].mayDecay() )
continue;
553 int nentries1 =
decayer->event.size();
555 if ( nentries1 <= nentries )
continue;
559 Particle& py8daughter =
decayer->event[nentries];
560 HepMC::GenVertex* DecVtx =
new HepMC::GenVertex( HepMC::FourVector(py8daughter.xProd(),
563 py8daughter.tProd()) );
565 DecVtx->add_particle_in( part );
568 HepMC::FourVector pmom( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
574 daughter->suggest_barcode( NewBarcode );
575 DecVtx->add_particle_out( daughter );
577 for (
int ipart1=nentries+1; ipart<nentries1; ipart++ )
579 py8daughter =
decayer->event[ipart1];
580 HepMC::FourVector pmomN( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
584 daughterN->suggest_barcode( NewBarcode );
585 DecVtx->add_particle_out( daughterN );
588 event().get()->add_vertex( DecVtx );
601 event()->set_signal_process_id(
pythia->info.code());
609 if (
event()->alphaQED() <= 0)
611 if (
event()->alphaQCD() <= 0)
614 HepMC::GenCrossSection xsec;
615 xsec.set_cross_section(
pythia->info.sigmaGen() * 1e9,
616 pythia->info.sigmaErr() * 1e9);
617 event()->set_cross_section(xsec);
626 int id1 =
pythia->info.id1();
627 int id2 =
pythia->info.id2();
628 if (id1 == 21) id1 = 0;
629 if (id2 == 21) id2 = 0;
630 double x1 =
pythia->info.x1();
631 double x2 =
pythia->info.x2();
633 double Q =
pythia->info.QFac();
636 event()->set_pdf_info(HepMC::PdfInfo(id1,id2,x1,x2,Q,pdf1,pdf2));
642 event()->weights().push_back(
pythia->info.weight() * 1.0e9 );
644 event()->weights().push_back(
pythia->info.weight() );
654 eventInfo()->setBinningValues(std::vector<double>(1,
pythia->info.pTHat()));
669 <<
pythia->info.code() <<
"\n"
670 <<
"----------------------" << std::endl;
bool pythiaHepMCVerbosity
HepMC verbosity flag.
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
bool initializeForInternalPartons()
double comEnergy
Center-of-Mass energy.
EmissionVetoHook1 * fEmissionVetoHook1
edm::GeneratorFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8GeneratorFilter
UserHooks * fReweightUserHook
bool declareStableParticles(const std::vector< int > &pdgIds)
CLHEP::HepRandomEngine * randomEngine
EmissionVetoHook * fEmissionVetoHook
std::auto_ptr< Pythia > decayer
bool initializeForExternalPartons()
std::auto_ptr< Pythia > pythia
#define DEFINE_FWK_MODULE(type)
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)
Double_t pdf1(double mHstar, double mHreq)
bool declareSpecialSettings(const std::vector< std::string >)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
void setInternalXSec(const XSec &xsec)
void beforeHadronization(lhef::LHEEvent *lhee)
std::auto_ptr< HepMC::GenEvent > & event()
CLHEP::HepRandomEngine & getEngineReference()
GenRunInfoProduct & runInfo()
std::auto_ptr< LHAupLesHouches > lhaUP
lhef::LHEEvent * lheEvent()
tuple pythiaPylistVerbosity
const char * classname() const
block
Formating index page's pieces.
unsigned int pythiaPylistVerbosity
Pythia PYLIST Verbosity flag.
std::auto_ptr< GenEventInfoProduct > & eventInfo()
lhef::LHERunInfo * lheRunInfo()
ParameterCollector parameters
void init(lhef::LHERunInfo *runInfo)
unsigned int maxEventsToPrint
Events to print if verbosity.
JetMatchingHook * fJetMatchingHook
bool generatePartonsAndHadronize()
Pythia8Hadronizer(const edm::ParameterSet ¶ms)
void resetMatchingStatus()
const_iterator end() const
const_iterator begin() const
tuple pythiaHepMCVerbosity
std::vector< std::string > findHeader(const std::string &tag) const
HepMC::Pythia8ToHepMC toHepMC
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter