8 #include "HepMC/GenEvent.h" 9 #include "HepMC/GenParticle.h" 11 #include "Pythia8/Pythia.h" 12 #include "Pythia8Plugins/HepMC2.h" 14 #include "Vincia/Vincia.h" 25 #include "Pythia8Plugins/JetMatching.h" 26 #include "Pythia8Plugins/aMCatNLOHooks.h" 32 #include "Pythia8Plugins/PowhegHooks.h" 50 #include "Pythia8Plugins/EvtGen.h" 66 #include "HepPID/ParticleIDTranslations.hh" 71 class HepRandomEngine;
84 bool initializeForInternalPartons()
override;
85 bool initializeForExternalPartons();
87 bool generatePartonsAndHadronize()
override;
90 virtual bool residualDecay();
92 void finalizeEvent()
override;
96 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
105 virtual std::vector<std::string>
const&
doSharedResources()
const override {
return p8SharedResources; }
111 std::auto_ptr<LHAupLesHouches>
lhaUP;
113 enum { PP,
PPbar, ElectronPositron };
178 comEnergy(params.getParameter<double>(
"comEnergy")),
179 LHEInputFileName(params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
181 nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0), nFSRvetoBB4L(0)
186 if ( params.
exists(
"PPbarInitialState" ) )
192 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 193 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
200 else if ( params.
exists(
"ElectronPositronInitialState" ) )
206 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 207 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
214 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
218 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
223 if( params.
exists(
"reweightGen" ) )
225 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
232 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
234 if( params.
exists(
"reweightGenEmp" ) )
236 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
240 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
242 if( params.
exists(
"reweightGenRap" ) )
244 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
255 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
257 if( params.
exists(
"reweightGenPtHatRap" ) )
259 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
270 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
273 if( params.
exists(
"useUserHook" ) )
275 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
279 if ( params.
exists(
"jetMatching") )
284 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
292 if ( params.
exists(
"emissionVeto1") )
306 <<
" Wrong value for EV1_pTempMode code\n";
318 if( params.
exists(
"VinciaPlugin" ) ) {
334 bool status =
false, status1 =
false;
345 fMasterGen->settings.mode(
"Beams:idB", -2212);
356 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
361 fMasterGen->settings.mode(
"Beams:frameType", 4);
373 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
377 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
381 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
385 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
389 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
391 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
396 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
398 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
404 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
405 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process")==
"void");
407 if (internalMatching && internalMerging) {
409 <<
" Only one jet matching/merging scheme can be used at a time. \n";
412 if (internalMatching) {
417 if (internalMerging) {
418 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
419 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
421 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
422 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
423 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
424 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
427 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
431 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
432 if (biasedTauDecayer) {
435 std::vector<int> handledParticles;
436 handledParticles.push_back(15);
440 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
441 if (resonanceDecayFilter) {
446 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
456 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
458 fvincia->init(); status =
true;
477 fDecayer->settings.flag(
"ProcessLevel:all",
false );
478 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
479 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
483 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
489 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
494 return (status&&status1);
501 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
503 bool status =
false, status1 =
false;
513 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
517 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
521 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
525 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
529 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
531 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
536 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
538 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
544 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
545 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process")==
"void");
547 if (internalMatching && internalMerging) {
549 <<
" Only one jet matching/merging scheme can be used at a time. \n";
552 if (internalMatching) {
557 if (internalMerging) {
558 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
559 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
561 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
562 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
563 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
564 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
567 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
571 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
572 if (biasedTauDecayer) {
575 std::vector<int> handledParticles;
576 handledParticles.push_back(15);
580 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
581 if (resonanceDecayFilter) {
586 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
598 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file " 600 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
601 fMasterGen->settings.mode(
"Beams:frameType", 4);
608 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
616 fMasterGen->settings.mode(
"Beams:frameType", 5);
618 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
636 fDecayer->settings.flag(
"ProcessLevel:all",
false );
637 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
638 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
642 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
649 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
654 return (status&&status1);
664 <<
"Number of ISR vetoed = " <<
nISRveto;
666 <<
"Number of FSR vetoed = " <<
nFSRveto;
697 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
713 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
714 DJR.push_back(djrmatch[idjr]);
731 if (mergeweight!=1.) {
732 event()->weights()[0] *= mergeweight;
744 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
745 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
746 double wgt = (*
fMasterGen->info.weights_detailed)[key];
747 event()->weights().push_back(wgt);
750 else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
751 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
752 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
753 event()->weights().push_back(wgt);
762 event()->weights().push_back(wgt);
786 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
793 if (!py8next ||
std::abs(mergeweight)==0.)
804 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
805 DJR.push_back(djrmatch[idjr]);
825 if (mergeweight!=1.) {
826 event()->weights()[0] *= mergeweight;
839 event()->weights().push_back(wgt);
853 int NPartsBeforeDecays = pythiaEvent->size();
854 int NPartsAfterDecays =
event().get()->particles_size();
856 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
860 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
865 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
868 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
869 part->momentum().x(),
870 part->momentum().y(),
871 part->momentum().z(),
872 part->momentum().t(),
873 part->generated_mass() );
874 HepMC::GenVertex* ProdVtx = part->production_vertex();
875 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
876 ProdVtx->position().z(), ProdVtx->position().t() );
877 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
879 int nentries =
fDecayer->event.size();
880 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
882 int nentries1 =
fDecayer->event.size();
883 if ( nentries1 <= nentries )
continue;
930 <<
"----------------------" << std::endl;
936 <<
"----------------------" << std::endl;
952 int weights_number =
fMasterGen->info.nWeights();
954 if(weights_number > 1){
955 genLumiInfoHeader->
weightNames().reserve(weights_number + 1);
956 genLumiInfoHeader->
weightNames().push_back(
"nominal");
963 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
964 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
965 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
966 weightgroupname = wgtgrp.first;
970 std::ostringstream weightname;
971 weightname <<
"LHE, id = " << key <<
", ";
972 if (!weightgroupname.empty()) {
973 weightname <<
"group = " << weightgroupname <<
", ";
975 weightname<<
fMasterGen->info.initrwgt->weights[
key].contents;
976 genLumiInfoHeader->
weightNames().push_back(weightname.str());
989 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
std::unique_ptr< BiasedTauDecayer > fBiasedTauDecayer
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< UserHooks > fReweightEmpUserHook
std::auto_ptr< PowhegResHook > fPowhegResHook
unsigned int pythiaPylistVerbosity
std::auto_ptr< GenEventInfoProduct > & eventInfo()
lhef::LHERunInfo * lheRunInfo()
bool generatePartonsAndHadronize() override
void doSetRandomEngine(CLHEP::HepRandomEngine *v) 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
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter
std::auto_ptr< Vincia::VinciaPlugin > fvincia
std::auto_ptr< EmissionVetoHook1 > fEmissionVetoHook1
std::auto_ptr< Pythia8::amcnlo_unitarised_interface > fMergingHook
~Pythia8Hadronizer() override