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" 15 #include "Dire/Dire.h" 26 #include "Pythia8Plugins/JetMatching.h" 27 #include "Pythia8Plugins/aMCatNLOHooks.h" 33 #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"; }
104 std::vector<std::string>
const&
doSharedResources()
const override {
return p8SharedResources; }
110 std::auto_ptr<LHAupLesHouches>
lhaUP;
112 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), nFSRvetoBB4L(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 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
228 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
230 if( params.
exists(
"reweightGenEmp" ) )
232 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
236 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
238 if( params.
exists(
"reweightGenRap" ) )
240 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
251 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
253 if( params.
exists(
"reweightGenPtHatRap" ) )
255 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
266 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
269 if( params.
exists(
"useUserHook" ) )
271 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
275 if ( params.
exists(
"jetMatching") )
280 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
288 if ( params.
exists(
"emissionVeto1") )
302 <<
" Wrong value for EV1_pTempMode code\n";
314 if( params.
exists(
"VinciaPlugin" ) ) {
318 if( params.
exists(
"DirePlugin" ) ) {
320 fDire.reset(
new Pythia8::Dire());
336 bool status =
false, status1 =
false;
347 fMasterGen->settings.mode(
"Beams:idB", -2212);
358 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
363 fMasterGen->settings.mode(
"Beams:frameType", 4);
375 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
379 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
383 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
387 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
391 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
393 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
398 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
400 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
406 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
407 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process")==
"void");
409 if (internalMatching && internalMerging) {
411 <<
" Only one jet matching/merging scheme can be used at a time. \n";
414 if (internalMatching) {
419 if (internalMerging) {
420 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
421 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
423 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
424 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
425 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
426 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
429 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
433 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
434 if (resonanceDecayFilter) {
439 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
449 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
451 fvincia->init(); status =
true;
453 else if(
fDire.get() ) {
455 fDire->weightsPtr->setup();
478 fDecayer->settings.flag(
"ProcessLevel:all",
false );
479 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
480 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
484 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
495 return (status&&status1);
502 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
504 bool status =
false, status1 =
false;
514 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
518 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
522 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
526 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
530 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
532 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
537 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
539 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
545 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
546 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process")==
"void");
548 if (internalMatching && internalMerging) {
550 <<
" Only one jet matching/merging scheme can be used at a time. \n";
553 if (internalMatching) {
558 if (internalMerging) {
559 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
560 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
562 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
563 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
564 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
565 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
568 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
572 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
573 if (resonanceDecayFilter) {
578 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
590 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file " 592 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
593 fMasterGen->settings.mode(
"Beams:frameType", 4);
600 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
608 fMasterGen->settings.mode(
"Beams:frameType", 5);
610 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
628 fDecayer->settings.flag(
"ProcessLevel:all",
false );
629 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
630 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
634 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
646 return (status&&status1);
656 <<
"Number of ISR vetoed = " <<
nISRveto;
658 <<
"Number of FSR vetoed = " <<
nFSRveto;
689 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
705 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
706 DJR.push_back(djrmatch[idjr]);
715 event().reset(
new HepMC::GenEvent);
723 if (mergeweight!=1.) {
724 event()->weights()[0] *= mergeweight;
736 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
737 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
738 double wgt = (*
fMasterGen->info.weights_detailed)[key];
739 event()->weights().push_back(wgt);
742 else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
743 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
744 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
745 event()->weights().push_back(wgt);
754 event()->weights().push_back(wgt);
762 for (
int iVar=1; iVar <
fvincia->nWeights(); iVar++) {
769 fDire->weightsPtr->calcWeight(0.);
770 fDire->weightsPtr->reset();
773 event()->weights()[0] *=
fDire->weightsPtr->getShowerWeight(
"base");
775 map<string, double>::iterator it;
776 for ( it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end(); it++ ) {
777 if (it->first ==
"base")
continue;
778 event()->weights().push_back(it->second);
802 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
809 if (!py8next ||
std::abs(mergeweight)==0.)
820 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
821 DJR.push_back(djrmatch[idjr]);
834 event().reset(
new HepMC::GenEvent);
841 if (mergeweight!=1.) {
842 event()->weights()[0] *= mergeweight;
855 event()->weights().push_back(wgt);
869 int NPartsBeforeDecays = pythiaEvent->size();
870 int NPartsAfterDecays =
event().get()->particles_size();
872 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
876 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
881 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
884 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
885 part->momentum().x(),
886 part->momentum().y(),
887 part->momentum().z(),
888 part->momentum().t(),
889 part->generated_mass() );
890 HepMC::GenVertex* ProdVtx = part->production_vertex();
891 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
892 ProdVtx->position().z(), ProdVtx->position().t() );
893 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
895 int nentries =
fDecayer->event.size();
896 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
898 int nentries1 =
fDecayer->event.size();
899 if ( nentries1 <= nentries )
continue;
946 <<
"----------------------" << std::endl;
952 <<
"----------------------" << std::endl;
968 int weights_number =
fMasterGen->info.nWeights();
970 if(weights_number > 1){
971 genLumiInfoHeader->
weightNames().reserve(weights_number + 1);
972 genLumiInfoHeader->
weightNames().push_back(
"nominal");
979 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
980 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
981 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
982 weightgroupname = wgtgrp.first;
986 std::ostringstream weightname;
987 weightname <<
"LHE, id = " << key <<
", ";
988 if (!weightgroupname.empty()) {
989 weightname <<
"group = " << weightgroupname <<
", ";
991 weightname<<
fMasterGen->info.initrwgt->weights[
key].contents;
992 genLumiInfoHeader->
weightNames().push_back(weightname.str());
1008 for (
int iVar=0; iVar <
fvincia->nWeights(); iVar++) {
1015 genLumiInfoHeader->
weightNames().push_back(
"base");
1017 map<string, double>::iterator it;
1018 for ( it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end(); it++ ) {
1019 if (it->first ==
"base")
continue;
1020 genLumiInfoHeader->
weightNames().push_back(it->first);
1024 return genLumiInfoHeader;
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::auto_ptr< PowhegHooks > fEmissionVetoHook
virtual bool residualDecay()
std::auto_ptr< Pythia8::Dire > fDire
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< UserHooks > fReweightEmpUserHook
std::auto_ptr< PowhegResHook > fPowhegResHook
unsigned int pythiaPylistVerbosity
std::vector< std::string > const & doSharedResources() const override
std::auto_ptr< GenEventInfoProduct > & eventInfo()
lhef::LHERunInfo * lheRunInfo()
bool generatePartonsAndHadronize() override
void doSetRandomEngine(CLHEP::HepRandomEngine *v) 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