8 #include "HepMC/GenEvent.h"
9 #include "HepMC/GenParticle.h"
11 #include "Pythia8/Pythia.h"
12 #include "Pythia8Plugins/HepMC2.h"
14 using namespace Pythia8;
23 #include "Pythia8Plugins/JetMatching.h"
24 #include "Pythia8Plugins/aMCatNLOHooks.h"
30 #include "Pythia8Plugins/PowhegHooks.h"
41 #include "Pythia8Plugins/EvtGen.h"
58 #include "HepPID/ParticleIDTranslations.hh"
63 class HepRandomEngine;
76 bool initializeForInternalPartons()
override;
77 bool initializeForExternalPartons();
79 bool generatePartonsAndHadronize()
override;
82 virtual bool residualDecay();
84 void finalizeEvent()
override;
88 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
93 virtual std::vector<std::string>
const&
doSharedResources()
const override {
return p8SharedResources; }
99 std::auto_ptr<LHAupLesHouches>
lhaUP;
101 enum { PP,
PPbar, ElectronPositron };
161 comEnergy(params.getParameter<double>(
"comEnergy")),
162 LHEInputFileName(params.getUntrackedParameter<std::
string>(
"LHEInputFileName",
"")),
164 fMultiUserHook(new
MultiUserHook), fReweightUserHook(0),fReweightRapUserHook(0),fReweightPtHatRapUserHook(0),
165 fJetMatchingHook(0),fJetMatchingPy8InternalHook(0), fMergingHook(0),
166 fEmissionVetoHook(0), fEmissionVetoHook1(0), fResonanceDecayFilterHook(0), fPTFilterHook(0), nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0),
172 if ( params.
exists(
"PPbarInitialState" ) )
178 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
179 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
186 else if ( params.
exists(
"ElectronPositronInitialState" ) )
192 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
193 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
200 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
204 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
207 if( params.
exists(
"SLHAFileForPythia8" ) ) {
211 fMasterGen->settings.mode(
"SLHA:readFrom", 2);
212 fMasterGen->settings.word(
"SLHA:file", f1.fullPath());
216 if (
line->find(
"SLHA:file") != std::string::npos)
217 throw cms::Exception(
"PythiaError") <<
"Attempted to set SLHA file name twice, "
218 <<
"using Pythia8 card SLHA:file and Pythia8Interface card SLHAFileForPythia8"
222 else if( params.
exists(
"SLHATableForPythia8" ) ) {
225 char tempslhaname[] =
"pythia8SLHAtableXXXXXX";
226 int fd = mkstemp(tempslhaname);
227 write(fd,slhatable.c_str(),slhatable.size());
232 fMasterGen->settings.mode(
"SLHA:readFrom", 2);
237 if (
line->find(
"SLHA:file") != std::string::npos)
238 throw cms::Exception(
"PythiaError") <<
"Attempted to set SLHA file name twice, "
239 <<
"using Pythia8 card SLHA:file and Pythia8Interface card SLHATableForPythia8"
245 fMasterGen->settings.addFlag(
"ResonanceDecayFilter:filter",
false);
246 fMasterGen->settings.addFlag(
"ResonanceDecayFilter:exclusive",
false);
247 fMasterGen->settings.addFlag(
"ResonanceDecayFilter:eMuAsEquivalent",
false);
248 fMasterGen->settings.addFlag(
"ResonanceDecayFilter:eMuTauAsEquivalent",
false);
249 fMasterGen->settings.addFlag(
"ResonanceDecayFilter:allNuAsEquivalent",
false);
250 fMasterGen->settings.addFlag(
"ResonanceDecayFilter:udscAsEquivalent",
false);
251 fMasterGen->settings.addFlag(
"ResonanceDecayFilter:udscbAsEquivalent",
false);
252 fMasterGen->settings.addMVec(
"ResonanceDecayFilter:mothers",std::vector<int>(),
false,
false,0,0);
253 fMasterGen->settings.addMVec(
"ResonanceDecayFilter:daughters",std::vector<int>(),
false,
false,0,0);
256 fMasterGen->settings.addFlag(
"PTFilter:filter",
false);
257 fMasterGen->settings.addMode(
"PTFilter:quarkToFilter", 5 ,
true,
true,3, 6);
258 fMasterGen->settings.addParm(
"PTFilter:scaleToFilter", 0.4,
true,
true,0.0, 10.);
259 fMasterGen->settings.addParm(
"PTFilter:quarkRapidity",10.0,
true,
true,0.0, 10.);
260 fMasterGen->settings.addParm(
"PTFilter:quarkPt", -.1,
true,
true,-.1,100.);
264 if( params.
exists(
"reweightGen" ) )
266 if( params.
exists(
"reweightGenRap" ) )
268 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
278 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
280 if( params.
exists(
"reweightGenPtHatRap" ) )
282 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
292 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
295 if( params.
exists(
"useUserHook" ) )
297 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
301 if ( params.
exists(
"jetMatching") )
306 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
314 if ( params.
exists(
"emissionVeto1") )
328 <<
" Wrong value for EV1_pTempMode code\n";
347 <<
" Too many User Hooks. \n Please choose one from: reweightGen, reweightGenRap, reweightGenPtHatRap, jetMatching, emissionVeto1 \n";
353 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
380 bool status =
false, status1 =
false;
390 fMasterGen->settings.mode(
"Beams:idB", -2212);
401 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
404 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
410 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
421 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
433 fDecayer->settings.flag(
"ProcessLevel:all",
false );
434 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
435 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
439 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
445 return (status&&status1);
452 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
454 bool status =
false, status1 =
false;
460 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
464 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
470 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
471 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
473 if (internalMatching && internalMerging) {
475 <<
" Only one jet matching/merging scheme can be used at a time. \n";
484 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
485 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
487 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
488 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
489 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
490 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
493 fMergingHook =
new Pythia8::amcnlo_unitarised_interface(scheme);
497 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
503 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
515 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file "
517 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
518 fMasterGen->settings.mode(
"Beams:frameType", 4);
525 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
533 fMasterGen->settings.mode(
"Beams:frameType", 5);
535 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
548 fDecayer->settings.flag(
"ProcessLevel:all",
false );
549 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
550 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
554 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
561 return (status&&status1);
571 <<
"Number of ISR vetoed = " <<
nISRveto;
573 <<
"Number of FSR vetoed = " <<
nFSRveto;
591 event().reset(
new HepMC::GenEvent);
612 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
619 if (!py8next ||
std::abs(mergeweight)==0.)
630 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
631 DJR.push_back(djrmatch[idjr]);
644 event().reset(
new HepMC::GenEvent);
651 if (mergeweight!=1.) {
652 event()->weights()[0] *= mergeweight;
670 int NPartsBeforeDecays = pythiaEvent->size();
671 int NPartsAfterDecays =
event().get()->particles_size();
673 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
677 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
682 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
685 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
686 part->momentum().x(),
687 part->momentum().y(),
688 part->momentum().z(),
689 part->momentum().t(),
690 part->generated_mass() );
691 HepMC::GenVertex* ProdVtx = part->production_vertex();
692 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
693 ProdVtx->position().z(), ProdVtx->position().t() );
694 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
696 int nentries =
fDecayer->event.size();
697 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
699 int nentries1 =
fDecayer->event.size();
700 if ( nentries1 <= nentries )
continue;
747 <<
"----------------------" << std::endl;
753 <<
"----------------------" << 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
void addHook(Pythia8::UserHooks *hook)
HepMC::IO_AsciiParticles * ascii_io
bool initializeForExternalPartons()
#define DEFINE_FWK_MODULE(type)
void statistics() override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::string LHEInputFileName
Pythia8::JetMatchingMadgraph * fJetMatchingPy8InternalHook
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
bool pythiaHepMCVerbosityParticles
void setInternalXSec(const XSec &xsec)
PowhegHooks * fEmissionVetoHook
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
EvtGenDecays * evtgenDecays
static const std::vector< std::string > p8SharedResources
Abs< T >::type abs(const T &t)
unsigned int pythiaPylistVerbosity
const char * classname() const override
PTFilterHook * fPTFilterHook
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
std::string evtgenPdlFile
unsigned int maxEventsToPrint
MultiUserHook * fMultiUserHook
std::auto_ptr< Pythia8::Pythia > fDecayer
Pythia8Hadronizer(const edm::ParameterSet ¶ms)
void resetMatchingStatus()
bool pythiaHepMCVerbosity
const_iterator end() const
std::string evtgenDecFile
const_iterator begin() const
HepMC::Pythia8ToHepMC toHepMC
ResonanceDecayFilterHook * fResonanceDecayFilterHook
unsigned int nHooks() const
static const std::string kPythia8
void finalizeEvent() override
virtual void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter