8 #include "HepMC/GenEvent.h" 9 #include "HepMC/GenParticle.h" 11 #include "Pythia8/Pythia.h" 12 #include "Pythia8Plugins/HepMC2.h" 23 #include "Pythia8Plugins/JetMatching.h" 24 #include "Pythia8Plugins/aMCatNLOHooks.h" 30 #include "Pythia8Plugins/PowhegHooks.h" 45 #include "Pythia8Plugins/EvtGen.h" 61 #include "HepPID/ParticleIDTranslations.hh" 66 class HepRandomEngine;
79 bool initializeForInternalPartons()
override;
80 bool initializeForExternalPartons();
82 bool generatePartonsAndHadronize()
override;
85 virtual bool residualDecay();
87 void finalizeEvent()
override;
91 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
98 virtual std::vector<std::string>
const&
doSharedResources()
const override {
return p8SharedResources; }
104 std::auto_ptr<LHAupLesHouches>
lhaUP;
106 enum { PP,
PPbar, ElectronPositron };
167 comEnergy(params.getParameter<double>(
"comEnergy")),
168 LHEInputFileName(params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
170 nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0), nFSRvetoBB4L(0)
175 if ( params.
exists(
"PPbarInitialState" ) )
181 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 182 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
189 else if ( params.
exists(
"ElectronPositronInitialState" ) )
195 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 196 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
203 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
207 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
212 if( params.
exists(
"reweightGen" ) )
214 if( params.
exists(
"reweightGenRap" ) )
216 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
227 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
229 if( params.
exists(
"reweightGenPtHatRap" ) )
231 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
242 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
245 if( params.
exists(
"useUserHook" ) )
247 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
251 if ( params.
exists(
"jetMatching") )
256 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
264 if ( params.
exists(
"emissionVeto1") )
278 <<
" Wrong value for EV1_pTempMode code\n";
301 bool status =
false, status1 =
false;
312 fMasterGen->settings.mode(
"Beams:idB", -2212);
323 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
328 fMasterGen->settings.mode(
"Beams:frameType", 4);
339 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
343 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
347 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
351 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
355 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
357 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
362 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
364 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
370 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
371 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
373 if (internalMatching && internalMerging) {
375 <<
" Only one jet matching/merging scheme can be used at a time. \n";
378 if (internalMatching) {
383 if (internalMerging) {
384 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
385 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
387 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
388 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
389 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
390 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
393 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
397 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
398 if (resonanceDecayFilter) {
403 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
413 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
430 fDecayer->settings.flag(
"ProcessLevel:all",
false );
431 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
432 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
436 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
442 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
447 return (status&&status1);
454 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
456 bool status =
false, status1 =
false;
465 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
469 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
473 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
477 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
481 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
483 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
488 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
490 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
496 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
497 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
499 if (internalMatching && internalMerging) {
501 <<
" Only one jet matching/merging scheme can be used at a time. \n";
504 if (internalMatching) {
509 if (internalMerging) {
510 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
511 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
513 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
514 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
515 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
516 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
519 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
523 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
524 if (resonanceDecayFilter) {
529 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
541 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file " 543 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
544 fMasterGen->settings.mode(
"Beams:frameType", 4);
551 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
559 fMasterGen->settings.mode(
"Beams:frameType", 5);
561 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
579 fDecayer->settings.flag(
"ProcessLevel:all",
false );
580 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
581 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
585 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
592 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
597 return (status&&status1);
607 <<
"Number of ISR vetoed = " <<
nISRveto;
609 <<
"Number of FSR vetoed = " <<
nFSRveto;
640 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
656 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
657 DJR.push_back(djrmatch[idjr]);
666 event().reset(
new HepMC::GenEvent);
674 if (mergeweight!=1.) {
675 event()->weights()[0] *= mergeweight;
687 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
688 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
689 double wgt = (*
fMasterGen->info.weights_detailed)[key];
690 event()->weights().push_back(wgt);
693 else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
694 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
695 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
696 event()->weights().push_back(wgt);
705 event()->weights().push_back(wgt);
729 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
736 if (!py8next ||
std::abs(mergeweight)==0.)
747 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
748 DJR.push_back(djrmatch[idjr]);
761 event().reset(
new HepMC::GenEvent);
768 if (mergeweight!=1.) {
769 event()->weights()[0] *= mergeweight;
787 int NPartsBeforeDecays = pythiaEvent->size();
788 int NPartsAfterDecays =
event().get()->particles_size();
790 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
794 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
799 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
802 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
803 part->momentum().x(),
804 part->momentum().y(),
805 part->momentum().z(),
806 part->momentum().t(),
807 part->generated_mass() );
808 HepMC::GenVertex* ProdVtx = part->production_vertex();
809 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
810 ProdVtx->position().z(), ProdVtx->position().t() );
811 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
813 int nentries =
fDecayer->event.size();
814 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
816 int nentries1 =
fDecayer->event.size();
817 if ( nentries1 <= nentries )
continue;
864 <<
"----------------------" << std::endl;
870 <<
"----------------------" << std::endl;
886 int weights_number =
fMasterGen->info.nWeights();
888 if(weights_number > 1){
889 genLumiInfoHeader->
weightNames().reserve(weights_number + 1);
890 genLumiInfoHeader->
weightNames().push_back(
"nominal");
897 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
898 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
899 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
900 weightgroupname = wgtgrp.first;
904 std::ostringstream weightname;
905 weightname <<
"LHE, id = " << key <<
", ";
906 if (!weightgroupname.empty()) {
907 weightname <<
"group = " << weightgroupname <<
", ";
909 weightname<<
fMasterGen->info.initrwgt->weights[
key].contents;
910 genLumiInfoHeader->
weightNames().push_back(weightname.str());
923 return genLumiInfoHeader;
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::auto_ptr< PowhegHooks > fEmissionVetoHook
virtual bool residualDecay()
double comEnergy
Center-of-Mass energy.
std::auto_ptr< Pythia8::Pythia > fMasterGen
edm::GeneratorFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8GeneratorFilter
std::auto_ptr< ResonanceDecayFilterHook > fResonanceDecayFilterHook
bool initializeForInternalPartons() override
std::auto_ptr< EvtGenDecays > evtgenDecays
std::auto_ptr< PowhegHooksBB4L > fPowhegHooksBB4L
HepMC::IO_AsciiParticles * ascii_io
std::auto_ptr< PTFilterHook > fPTFilterHook
bool initializeForExternalPartons()
#define DEFINE_FWK_MODULE(type)
GenLumiInfoHeader * getGenLumiInfoHeader() const override
void statistics() override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::string LHEInputFileName
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
std::auto_ptr< JetMatchingHook > fJetMatchingHook
bool pythiaHepMCVerbosityParticles
void setInternalXSec(const XSec &xsec)
std::auto_ptr< HepMC::GenEvent > & event()
std::vector< std::string > evtgenUserFiles
const char * classname() const override
GenRunInfoProduct & runInfo()
std::auto_ptr< LHAupLesHouches > lhaUP
lhef::LHEEvent * lheEvent()
std::auto_ptr< MultiUserHook > fMultiUserHook
static const std::vector< std::string > p8SharedResources
Abs< T >::type abs(const T &t)
std::auto_ptr< UserHooks > fReweightPtHatRapUserHook
std::auto_ptr< PowhegResHook > fPowhegResHook
unsigned int pythiaPylistVerbosity
std::auto_ptr< GenEventInfoProduct > & eventInfo()
lhef::LHERunInfo * lheRunInfo()
bool generatePartonsAndHadronize() override
virtual std::vector< std::string > const & doSharedResources() const override
std::auto_ptr< UserHooks > fReweightUserHook
std::string evtgenPdlFile
unsigned int maxEventsToPrint
def remove(d, key, TELL=False)
std::auto_ptr< UserHooks > fReweightRapUserHook
std::auto_ptr< Pythia8::Pythia > fDecayer
Pythia8Hadronizer(const edm::ParameterSet ¶ms)
bool pythiaHepMCVerbosity
std::string evtgenDecFile
HepMC::Pythia8ToHepMC toHepMC
static const std::string kPythia8
void finalizeEvent() override
std::auto_ptr< Pythia8::JetMatchingMadgraph > fJetMatchingPy8InternalHook
virtual void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter
std::auto_ptr< EmissionVetoHook1 > fEmissionVetoHook1
std::auto_ptr< Pythia8::amcnlo_unitarised_interface > fMergingHook