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"
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 };
168 comEnergy(params.getParameter<double>(
"comEnergy")),
169 LHEInputFileName(params.getUntrackedParameter<std::
string>(
"LHEInputFileName",
"")),
171 nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0)
176 if ( params.
exists(
"PPbarInitialState" ) )
182 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
183 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
190 else if ( params.
exists(
"ElectronPositronInitialState" ) )
196 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
197 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
204 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
208 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
213 if( params.
exists(
"reweightGen" ) )
215 if( params.
exists(
"reweightGenRap" ) )
217 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
228 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
230 if( params.
exists(
"reweightGenPtHatRap" ) )
232 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
243 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
246 if( params.
exists(
"useUserHook" ) )
248 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
252 if ( params.
exists(
"jetMatching") )
257 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
265 if ( params.
exists(
"emissionVeto1") )
279 <<
" Wrong value for EV1_pTempMode code\n";
307 bool status =
false, status1 =
false;
318 fMasterGen->settings.mode(
"Beams:idB", -2212);
329 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
334 fMasterGen->settings.mode(
"Beams:frameType", 4);
345 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
349 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
353 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
357 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
361 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
363 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
368 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
370 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
376 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
377 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
379 if (internalMatching && internalMerging) {
381 <<
" Only one jet matching/merging scheme can be used at a time. \n";
384 if (internalMatching) {
389 if (internalMerging) {
390 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
391 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
393 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
394 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
395 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
396 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
399 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
403 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
404 if (resonanceDecayFilter) {
409 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
419 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
436 fDecayer->settings.flag(
"ProcessLevel:all",
false );
437 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
438 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
442 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
448 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
453 return (status&&status1);
460 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
462 bool status =
false, status1 =
false;
471 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
475 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
479 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
483 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
487 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
489 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
494 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
496 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
502 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
503 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
505 if (internalMatching && internalMerging) {
507 <<
" Only one jet matching/merging scheme can be used at a time. \n";
510 if (internalMatching) {
515 if (internalMerging) {
516 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
517 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
519 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
520 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
521 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
522 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
525 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
529 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
530 if (resonanceDecayFilter) {
535 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
547 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file "
549 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
550 fMasterGen->settings.mode(
"Beams:frameType", 4);
557 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
565 fMasterGen->settings.mode(
"Beams:frameType", 5);
567 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
585 fDecayer->settings.flag(
"ProcessLevel:all",
false );
586 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
587 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
591 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
598 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
603 return (status&&status1);
613 <<
"Number of ISR vetoed = " <<
nISRveto;
615 <<
"Number of FSR vetoed = " <<
nFSRveto;
641 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
657 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
658 DJR.push_back(djrmatch[idjr]);
667 event().reset(
new HepMC::GenEvent);
675 if (mergeweight!=1.) {
676 event()->weights()[0] *= mergeweight;
685 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
686 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
687 double wgt = (*
fMasterGen->info.weights_detailed)[key];
688 event()->weights().push_back(wgt);
691 else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
692 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
693 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
694 event()->weights().push_back(wgt);
703 event()->weights().push_back(wgt);
727 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
734 if (!py8next ||
std::abs(mergeweight)==0.)
745 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
746 DJR.push_back(djrmatch[idjr]);
759 event().reset(
new HepMC::GenEvent);
766 if (mergeweight!=1.) {
767 event()->weights()[0] *= mergeweight;
780 event()->weights().push_back(wgt);
794 int NPartsBeforeDecays = pythiaEvent->size();
795 int NPartsAfterDecays =
event().get()->particles_size();
797 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
801 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
806 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
809 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
810 part->momentum().x(),
811 part->momentum().y(),
812 part->momentum().z(),
813 part->momentum().t(),
814 part->generated_mass() );
815 HepMC::GenVertex* ProdVtx = part->production_vertex();
816 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
817 ProdVtx->position().z(), ProdVtx->position().t() );
818 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
820 int nentries =
fDecayer->event.size();
821 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
823 int nentries1 =
fDecayer->event.size();
824 if ( nentries1 <= nentries )
continue;
871 <<
"----------------------" << std::endl;
877 <<
"----------------------" << std::endl;
893 int weights_number =
fMasterGen->info.nWeights();
895 if(weights_number > 1){
896 genLumiInfoHeader->
weightNames().reserve(weights_number + 1);
897 genLumiInfoHeader->
weightNames().push_back(
"nominal");
904 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
905 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
906 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
907 weightgroupname = wgtgrp.first;
911 std::ostringstream weightname;
912 weightname <<
"LHE, id = " << key <<
", ";
913 if (!weightgroupname.empty()) {
914 weightname <<
"group = " << weightgroupname <<
", ";
916 weightname<<
fMasterGen->info.initrwgt->weights[
key].contents;
917 genLumiInfoHeader->
weightNames().push_back(weightname.str());
930 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)
void statistics() override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::string LHEInputFileName
GenLumiInfoHeader * getGenLumiInfoHeader() const override
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()
virtual std::vector< std::string > const & doSharedResources() const override
std::vector< std::string > evtgenUserFiles
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
const char * classname() const override
std::auto_ptr< GenEventInfoProduct > & eventInfo()
static std::vector< std::string > checklist lhe
lhef::LHERunInfo * lheRunInfo()
bool generatePartonsAndHadronize() override
std::auto_ptr< UserHooks > fReweightUserHook
std::string evtgenPdlFile
unsigned int maxEventsToPrint
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