7 #include "HepMC/GenEvent.h"
8 #include "HepMC/GenParticle.h"
10 #include "Pythia8/Pythia.h"
11 #include "Pythia8Plugins/HepMC2.h"
20 #include "Pythia8Plugins/JetMatching.h"
21 #include "Pythia8Plugins/aMCatNLOHooks.h"
25 #include "Pythia8Plugins/PowhegHooks.h"
42 #include "HepPID/ParticleIDTranslations.hh"
47 using namespace Pythia8;
56 bool initializeForInternalPartons();
57 bool initializeForExternalPartons();
59 bool generatePartonsAndHadronize();
62 virtual bool residualDecay();
68 const char *
classname()
const {
return "Pythia8Hadronizer"; }
76 std::auto_ptr<LHAupLesHouches>
lhaUP;
78 enum { PP,
PPbar, ElectronPositron };
125 comEnergy(params.getParameter<double>(
"comEnergy")),
126 LHEInputFileName(params.getUntrackedParameter<string>(
"LHEInputFileName",
"")),
128 fReweightUserHook(0),fReweightRapUserHook(0),fReweightPtHatRapUserHook(0),
129 fJetMatchingHook(0),fJetMatchingPy8InternalHook(0), fMergingHook(0),
130 fEmissionVetoHook(0), fEmissionVetoHook1(0), nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0),
136 if ( params.
exists(
"PPbarInitialState" ) )
142 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
143 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
150 else if ( params.
exists(
"ElectronPositronInitialState" ) )
156 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
157 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
164 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
168 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
171 if( params.
exists(
"SLHAFileForPythia8" ) ) {
172 std::string slhafilenameshort = params.
getParameter<
string>(
"SLHAFileForPythia8");
176 fMasterGen->settings.mode(
"SLHA:readFrom", 2);
181 if (
line->find(
"SLHA:file") != std::string::npos)
182 throw cms::Exception(
"PythiaError") <<
"Attempted to set SLHA file name twice, "
183 <<
"using Pythia8 card SLHA:file and Pythia8Interface card SLHAFileForPythia8"
190 if( params.
exists(
"reweightGen" ) )
192 if( params.
exists(
"reweightGenRap" ) )
194 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
204 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
206 if( params.
exists(
"reweightGenPtHatRap" ) )
208 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
218 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
221 if( params.
exists(
"useUserHook" ) )
223 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
227 if ( params.
exists(
"jetMatching") )
231 std::string scheme = jmParams.
getParameter<std::string>(
"scheme");
232 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
240 if ( params.
exists(
"emissionVeto1") )
254 <<
" Wrong value for EV1_pTempMode code\n";
273 <<
" Too many User Hooks. \n Please choose one from: reweightGen, reweightGenRap, reweightGenPtHatRap, jetMatching, emissionVeto1 \n";
279 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
310 fMasterGen->settings.mode(
"Beams:idB", -2212);
326 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
342 fDecayer->settings.flag(
"ProcessLevel:all",
false );
343 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
353 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
361 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
365 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
371 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
372 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
374 if (internalMatching && internalMerging) {
376 <<
" Only one jet matching/merging scheme can be used at a time. \n";
385 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
386 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
388 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
389 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
390 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
391 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
394 fMergingHook =
new Pythia8::amcnlo_unitarised_interface(scheme);
401 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file "
403 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
405 fMasterGen->settings.mode(
"Beams:frameType", 4);
412 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
421 fMasterGen->settings.mode(
"Beams:frameType", 5);
437 fDecayer->settings.flag(
"ProcessLevel:all",
false );
438 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
451 <<
"Number of ISR vetoed = " <<
nISRveto;
453 <<
"Number of FSR vetoed = " <<
nFSRveto;
467 event().reset(
new HepMC::GenEvent);
488 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
495 if (!py8next ||
std::abs(mergeweight)==0.)
506 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
507 DJR.push_back(djrmatch[idjr]);
518 event().reset(
new HepMC::GenEvent);
525 if (mergeweight!=1.) {
526 event()->weights()[0] *= mergeweight;
545 int NPartsBeforeDecays = pythiaEvent->size();
546 int NPartsAfterDecays =
event().get()->particles_size();
547 int NewBarcode = NPartsAfterDecays;
549 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
554 if ( part->status() == 1 )
557 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
558 part->momentum().x(),
559 part->momentum().y(),
560 part->momentum().z(),
561 part->momentum().t(),
562 part->generated_mass() );
563 HepMC::GenVertex* ProdVtx = part->production_vertex();
564 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
565 ProdVtx->position().z(), ProdVtx->position().t() );
566 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
568 int nentries =
fDecayer->event.size();
569 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
571 int nentries1 =
fDecayer->event.size();
572 if ( nentries1 <= nentries )
continue;
576 Particle& py8daughter =
fDecayer->event[nentries];
577 HepMC::GenVertex* DecVtx =
new HepMC::GenVertex( HepMC::FourVector(py8daughter.xProd(),
580 py8daughter.tProd()) );
582 DecVtx->add_particle_in( part );
585 HepMC::FourVector pmom( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
591 daughter->suggest_barcode( NewBarcode );
592 DecVtx->add_particle_out( daughter );
594 for (
int ipart1=nentries+1; ipart1<nentries1; ipart1++ )
596 py8daughter =
fDecayer->event[ipart1];
597 HepMC::FourVector pmomN( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
601 daughterN->suggest_barcode( NewBarcode );
602 DecVtx->add_particle_out( daughterN );
605 event().get()->add_vertex( DecVtx );
646 <<
"----------------------" << std::endl;
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual bool residualDecay()
bool initializeForInternalPartons()
ParameterCollector fParameters
double comEnergy
Center-of-Mass energy.
std::auto_ptr< Pythia8::Pythia > fMasterGen
EmissionVetoHook1 * fEmissionVetoHook1
edm::GeneratorFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8GeneratorFilter
UserHooks * fReweightUserHook
bool initializeForExternalPartons()
#define DEFINE_FWK_MODULE(type)
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
void beforeHadronization(lhef::LHEEvent *lhee)
std::auto_ptr< HepMC::GenEvent > & event()
GenRunInfoProduct & runInfo()
std::auto_ptr< LHAupLesHouches > lhaUP
lhef::LHEEvent * lheEvent()
UserHooks * fReweightPtHatRapUserHook
const char * classname() const
unsigned int pythiaPylistVerbosity
UserHooks * fReweightRapUserHook
std::auto_ptr< GenEventInfoProduct > & eventInfo()
lhef::LHERunInfo * lheRunInfo()
void init(lhef::LHERunInfo *runInfo)
Pythia8::amcnlo_unitarised_interface * fMergingHook
JetMatchingHook * fJetMatchingHook
unsigned int maxEventsToPrint
bool generatePartonsAndHadronize()
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
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter