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"
48 #include "Pythia8Plugins/EvtGen.h"
64 #include "HepPID/ParticleIDTranslations.hh"
69 class HepRandomEngine;
82 bool initializeForInternalPartons()
override;
83 bool initializeForExternalPartons();
85 bool generatePartonsAndHadronize()
override;
88 virtual bool residualDecay();
90 void finalizeEvent()
override;
94 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
101 virtual std::vector<std::string>
const&
doSharedResources()
const override {
return p8SharedResources; }
107 std::auto_ptr<LHAupLesHouches>
lhaUP;
109 enum { PP,
PPbar, ElectronPositron };
174 comEnergy(params.getParameter<double>(
"comEnergy")),
175 LHEInputFileName(params.getUntrackedParameter<std::
string>(
"LHEInputFileName",
"")),
177 nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0)
182 if ( params.
exists(
"PPbarInitialState" ) )
188 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
189 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
196 else if ( params.
exists(
"ElectronPositronInitialState" ) )
202 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
203 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
210 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
214 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
219 if( params.
exists(
"reweightGen" ) )
221 if( params.
exists(
"reweightGenRap" ) )
223 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
234 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
236 if( params.
exists(
"reweightGenPtHatRap" ) )
238 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
249 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
252 if( params.
exists(
"useUserHook" ) )
254 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
258 if ( params.
exists(
"jetMatching") )
263 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
271 if ( params.
exists(
"emissionVeto1") )
285 <<
" Wrong value for EV1_pTempMode code\n";
313 bool status =
false, status1 =
false;
324 fMasterGen->settings.mode(
"Beams:idB", -2212);
335 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
340 fMasterGen->settings.mode(
"Beams:frameType", 4);
351 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
355 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
359 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
363 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
367 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
369 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
374 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
376 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
382 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
383 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
385 if (internalMatching && internalMerging) {
387 <<
" Only one jet matching/merging scheme can be used at a time. \n";
390 if (internalMatching) {
395 if (internalMerging) {
396 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
397 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
399 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
400 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
401 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
402 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
405 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
409 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
410 if (biasedTauDecayer) {
413 std::vector<int> handledParticles;
414 handledParticles.push_back(15);
418 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
419 if (resonanceDecayFilter) {
424 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
434 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
451 fDecayer->settings.flag(
"ProcessLevel:all",
false );
452 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
453 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
457 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
463 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
468 return (status&&status1);
475 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
477 bool status =
false, status1 =
false;
486 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
490 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
494 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
498 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
502 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
504 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
509 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
511 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
517 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
518 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process").compare(
"void")==0);
520 if (internalMatching && internalMerging) {
522 <<
" Only one jet matching/merging scheme can be used at a time. \n";
525 if (internalMatching) {
530 if (internalMerging) {
531 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
532 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
534 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
535 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
536 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
537 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
540 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
544 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
545 if (biasedTauDecayer) {
548 std::vector<int> handledParticles;
549 handledParticles.push_back(15);
553 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
554 if (resonanceDecayFilter) {
559 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
571 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file "
573 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
574 fMasterGen->settings.mode(
"Beams:frameType", 4);
581 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
589 fMasterGen->settings.mode(
"Beams:frameType", 5);
591 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
609 fDecayer->settings.flag(
"ProcessLevel:all",
false );
610 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
611 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
615 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
622 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
627 return (status&&status1);
637 <<
"Number of ISR vetoed = " <<
nISRveto;
639 <<
"Number of FSR vetoed = " <<
nFSRveto;
665 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
681 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
682 DJR.push_back(djrmatch[idjr]);
691 event().reset(
new HepMC::GenEvent);
699 if (mergeweight!=1.) {
700 event()->weights()[0] *= mergeweight;
709 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
710 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
711 double wgt = (*
fMasterGen->info.weights_detailed)[key];
712 event()->weights().push_back(wgt);
715 else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
716 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
717 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
718 event()->weights().push_back(wgt);
727 event()->weights().push_back(wgt);
751 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
758 if (!py8next ||
std::abs(mergeweight)==0.)
769 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
770 DJR.push_back(djrmatch[idjr]);
783 event().reset(
new HepMC::GenEvent);
790 if (mergeweight!=1.) {
791 event()->weights()[0] *= mergeweight;
804 event()->weights().push_back(wgt);
818 int NPartsBeforeDecays = pythiaEvent->size();
819 int NPartsAfterDecays =
event().get()->particles_size();
821 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
825 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
830 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
833 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
834 part->momentum().x(),
835 part->momentum().y(),
836 part->momentum().z(),
837 part->momentum().t(),
838 part->generated_mass() );
839 HepMC::GenVertex* ProdVtx = part->production_vertex();
840 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
841 ProdVtx->position().z(), ProdVtx->position().t() );
842 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
844 int nentries =
fDecayer->event.size();
845 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
847 int nentries1 =
fDecayer->event.size();
848 if ( nentries1 <= nentries )
continue;
895 <<
"----------------------" << std::endl;
901 <<
"----------------------" << std::endl;
917 int weights_number =
fMasterGen->info.nWeights();
919 if(weights_number > 1){
920 genLumiInfoHeader->
weightNames().reserve(weights_number + 1);
921 genLumiInfoHeader->
weightNames().push_back(
"nominal");
928 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
929 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
930 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
931 weightgroupname = wgtgrp.first;
935 std::ostringstream weightname;
936 weightname <<
"LHE, id = " << key <<
", ";
937 if (!weightgroupname.empty()) {
938 weightname <<
"group = " << weightgroupname <<
", ";
940 weightname<<
fMasterGen->info.initrwgt->weights[
key].contents;
941 genLumiInfoHeader->
weightNames().push_back(weightname.str());
954 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
std::unique_ptr< BiasedTauDecayer > fBiasedTauDecayer
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