8 #include "HepMC/GenEvent.h"
9 #include "HepMC/GenParticle.h"
11 #include "Pythia8/Pythia.h"
12 #include "Pythia8Plugins/HepMC2.h"
21 #include "Pythia8Plugins/JetMatching.h"
22 #include "Pythia8Plugins/aMCatNLOHooks.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), fMergingHook(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" ) ) {
182 fMasterGen->settings.mode(
"SLHA:readFrom", 2);
187 if (
line->find(
"SLHA:file") != std::string::npos)
188 throw cms::Exception(
"PythiaError") <<
"Attempted to set SLHA file name twice, "
189 <<
"using Pythia8 card SLHA:file and Pythia8Interface card SLHAFileForPythia8"
196 if( params.
exists(
"reweightGen" ) )
198 if( params.
exists(
"reweightGenRap" ) )
200 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
210 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
212 if( params.
exists(
"reweightGenPtHatRap" ) )
214 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
224 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
227 if( params.
exists(
"useUserHook" ) )
229 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
233 if ( params.
exists(
"jetMatching") )
238 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
246 if ( params.
exists(
"emissionVeto") )
251 if ( params.
exists(
"emissionVeto1") )
265 <<
" Wrong value for EV1_pTempMode code\n";
286 <<
" Too many User Hooks. \n Please choose one from: reweightGen, reweightGenRap, reweightGenPtHatRap, jetMatching, emissionVeto, emissionVeto1 \n";
292 std::cout <<
"Turning on Emission Veto Hook";
323 fMasterGen->settings.mode(
"Beams:idB", -2212);
339 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
355 fDecayer->settings.flag(
"ProcessLevel:all",
false );
356 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
366 std::cout <<
"Initializing for external partons" << std::endl;
369 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
370 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
372 if (internalMatching && internalMerging) {
374 <<
" Only one jet matching/merging scheme can be used at a time. \n";
383 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
384 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
386 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
387 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
388 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
389 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
392 fMergingHook =
new Pythia8::amcnlo_unitarised_interface(scheme);
399 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file "
401 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
403 fMasterGen->settings.mode(
"Beams:frameType", 4);
418 fMasterGen->settings.mode(
"Beams:frameType", 5);
434 fDecayer->settings.flag(
"ProcessLevel:all",
false );
435 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
457 event().reset(
new HepMC::GenEvent);
478 double mergeweight =
fMasterGen.get()->info.mergingWeight();
481 if (!py8next ||
std::abs(mergeweight)==0.)
492 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
493 DJR.push_back(djrmatch[idjr]);
504 event().reset(
new HepMC::GenEvent);
511 if (mergeweight!=1.) {
512 event()->weights().push_back(mergeweight);
526 int NPartsBeforeDecays = pythiaEvent->size();
527 int NPartsAfterDecays =
event().get()->particles_size();
528 int NewBarcode = NPartsAfterDecays;
530 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
535 if ( part->status() == 1 )
538 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
539 part->momentum().x(),
540 part->momentum().y(),
541 part->momentum().z(),
542 part->momentum().t(),
543 part->generated_mass() );
544 HepMC::GenVertex* ProdVtx = part->production_vertex();
545 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
546 ProdVtx->position().z(), ProdVtx->position().t() );
547 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
549 int nentries =
fDecayer->event.size();
550 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
552 int nentries1 =
fDecayer->event.size();
553 if ( nentries1 <= nentries )
continue;
557 Particle& py8daughter =
fDecayer->event[nentries];
558 HepMC::GenVertex* DecVtx =
new HepMC::GenVertex( HepMC::FourVector(py8daughter.xProd(),
561 py8daughter.tProd()) );
563 DecVtx->add_particle_in( part );
566 HepMC::FourVector pmom( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
572 daughter->suggest_barcode( NewBarcode );
573 DecVtx->add_particle_out( daughter );
575 for (
int ipart1=nentries+1; ipart1<nentries1; ipart1++ )
577 py8daughter =
fDecayer->event[ipart1];
578 HepMC::FourVector pmomN( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
582 daughterN->suggest_barcode( NewBarcode );
583 DecVtx->add_particle_out( daughterN );
586 event().get()->add_vertex( DecVtx );
627 <<
"----------------------" << 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
Pythia8::JetMatchingMadgraph * fJetMatchingPy8InternalHook
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
Abs< T >::type abs(const T &t)
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)
Pythia8::amcnlo_unitarised_interface * fMergingHook
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
static const std::string kPythia8
void finalizeEvent() override
virtual void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter