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"; }
96 std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader()
const override;
100 std::unique_ptr<Vincia::VinciaPlugin>
fvincia;
101 std::unique_ptr<Pythia8::Dire>
fDire;
104 std::vector<std::string>
const&
doSharedResources()
const override {
return p8SharedResources; }
110 std::unique_ptr<LHAupLesHouches>
lhaUP;
112 enum { PP,
PPbar, ElectronPositron };
175 comEnergy(params.getParameter<double>(
"comEnergy")),
176 LHEInputFileName(params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
178 nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0)
183 if ( params.
exists(
"PPbarInitialState" ) )
189 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 190 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
197 else if ( params.
exists(
"ElectronPositronInitialState" ) )
203 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 204 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
211 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
215 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
220 if( params.
exists(
"reweightGen" ) )
222 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
229 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
231 if( params.
exists(
"reweightGenEmp" ) )
233 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
238 if(rgeParams.
exists(
"tune"))
241 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
243 if( params.
exists(
"reweightGenRap" ) )
245 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
256 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
258 if( params.
exists(
"reweightGenPtHatRap" ) )
260 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
271 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
274 if( params.
exists(
"useUserHook" ) )
276 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
280 if ( params.
exists(
"jetMatching") )
285 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
293 if ( params.
exists(
"emissionVeto1") )
307 <<
" Wrong value for EV1_pTempMode code\n";
324 if( params.
exists(
"VinciaPlugin" ) ) {
328 if( params.
exists(
"DirePlugin" ) ) {
330 fDire.reset(
new Pythia8::Dire());
346 bool status =
false, status1 =
false;
357 fMasterGen->settings.mode(
"Beams:idB", -2212);
368 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
373 fMasterGen->settings.mode(
"Beams:frameType", 4);
385 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
389 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
393 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
397 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
401 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
403 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
408 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
410 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
416 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
417 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process")==
"void");
419 if (internalMatching && internalMerging) {
421 <<
" Only one jet matching/merging scheme can be used at a time. \n";
424 if (internalMatching) {
429 if (internalMerging) {
430 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
431 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
433 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
434 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
435 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
436 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
439 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
443 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
444 if (resonanceDecayFilter) {
449 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
459 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
461 fvincia->init(); status =
true;
463 else if(
fDire.get() ) {
465 fDire->weightsPtr->setup();
488 fDecayer->settings.flag(
"ProcessLevel:all",
false );
489 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
490 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
494 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
499 return (status&&status1);
506 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
508 bool status =
false, status1 =
false;
518 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
522 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
526 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
530 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
534 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
536 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
541 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
543 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
549 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
550 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process")==
"void");
552 if (internalMatching && internalMerging) {
554 <<
" Only one jet matching/merging scheme can be used at a time. \n";
557 if (internalMatching) {
562 if (internalMerging) {
563 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
564 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
566 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
567 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
568 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
569 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
572 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
576 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
577 if (resonanceDecayFilter) {
582 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
594 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file " 596 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
597 fMasterGen->settings.mode(
"Beams:frameType", 4);
604 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
612 fMasterGen->settings.mode(
"Beams:frameType", 5);
614 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
632 fDecayer->settings.flag(
"ProcessLevel:all",
false );
633 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
634 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
638 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
643 return (status&&status1);
653 <<
"Number of ISR vetoed = " <<
nISRveto;
655 <<
"Number of FSR vetoed = " <<
nFSRveto;
681 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
697 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
698 DJR.push_back(djrmatch[idjr]);
715 if (mergeweight!=1.) {
716 event()->weights()[0] *= mergeweight;
725 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
726 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
727 double wgt = (*
fMasterGen->info.weights_detailed)[key];
728 event()->weights().push_back(wgt);
731 else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
732 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
733 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
734 event()->weights().push_back(wgt);
743 event()->weights().push_back(wgt);
751 for (
int iVar=1; iVar <
fvincia->nWeights(); iVar++) {
758 fDire->weightsPtr->calcWeight(0.);
759 fDire->weightsPtr->reset();
762 event()->weights()[0] *=
fDire->weightsPtr->getShowerWeight(
"base");
764 map<string, double>::iterator it;
765 for ( it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end(); it++ ) {
766 if (it->first ==
"base")
continue;
767 event()->weights().push_back(it->second);
791 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
798 if (!py8next ||
std::abs(mergeweight)==0.)
809 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
810 DJR.push_back(djrmatch[idjr]);
830 if (mergeweight!=1.) {
831 event()->weights()[0] *= mergeweight;
844 event()->weights().push_back(wgt);
858 int NPartsBeforeDecays = pythiaEvent->size();
859 int NPartsAfterDecays =
event().get()->particles_size();
861 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
865 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
870 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
873 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
874 part->momentum().x(),
875 part->momentum().y(),
876 part->momentum().z(),
877 part->momentum().t(),
878 part->generated_mass() );
879 HepMC::GenVertex* ProdVtx = part->production_vertex();
880 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
881 ProdVtx->position().z(), ProdVtx->position().t() );
882 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
884 int nentries =
fDecayer->event.size();
885 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
887 int nentries1 =
fDecayer->event.size();
888 if ( nentries1 <= nentries )
continue;
935 <<
"----------------------" << std::endl;
941 <<
"----------------------" << std::endl;
948 auto genLumiInfoHeader = BaseHadronizer::getGenLumiInfoHeader();
953 genLumiInfoHeader->lheHeaders().emplace_back(
key,
fMasterGen->info.header(
key));
957 int weights_number =
fMasterGen->info.nWeights();
959 if(weights_number > 1){
960 genLumiInfoHeader->weightNames().reserve(weights_number + 1);
961 genLumiInfoHeader->weightNames().push_back(
"nominal");
968 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
969 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
970 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
971 weightgroupname = wgtgrp.first;
975 std::ostringstream weightname;
976 weightname <<
"LHE, id = " << key <<
", ";
977 if (!weightgroupname.empty()) {
978 weightname <<
"group = " << weightgroupname <<
", ";
980 weightname<<
fMasterGen->info.initrwgt->weights[
key].contents;
981 genLumiInfoHeader->weightNames().push_back(weightname.str());
990 genLumiInfoHeader->weightNames().push_back(
fMasterGen->info.weightLabel(
i) );
997 for (
int iVar=0; iVar <
fvincia->nWeights(); iVar++) {
998 genLumiInfoHeader->weightNames().push_back(
fvincia->weightLabel(iVar) );
1004 genLumiInfoHeader->weightNames().push_back(
"base");
1006 map<string, double>::iterator it;
1007 for ( it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end(); it++ ) {
1008 if (it->first ==
"base")
continue;
1009 genLumiInfoHeader->weightNames().push_back(it->first);
1013 return genLumiInfoHeader;
std::unique_ptr< UserHooks > fReweightPtHatRapUserHook
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual bool residualDecay()
double comEnergy
Center-of-Mass energy.
std::unique_ptr< Pythia8::Pythia > fDecayer
edm::GeneratorFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8GeneratorFilter
bool initializeForInternalPartons() override
std::shared_ptr< EvtGenDecays > evtgenDecays
HepMC::IO_AsciiParticles * ascii_io
bool initializeForExternalPartons()
void statistics() override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::string LHEInputFileName
std::unique_ptr< EmissionVetoHook1 > fEmissionVetoHook1
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
std::unique_ptr< Pythia8::amcnlo_unitarised_interface > fMergingHook
bool pythiaHepMCVerbosityParticles
void setInternalXSec(const XSec &xsec)
std::vector< std::string > evtgenUserFiles
std::unique_ptr< JetMatchingHook > fJetMatchingHook
const char * classname() const override
GenRunInfoProduct & runInfo()
#define DEFINE_FWK_MODULE(type)
lhef::LHEEvent * lheEvent()
std::unique_ptr< PowhegHooksBB4L > fPowhegHooksBB4L
std::unique_ptr< PowhegResHook > fPowhegResHook
std::unique_ptr< Pythia8::JetMatchingMadgraph > fJetMatchingPy8InternalHook
std::unique_ptr< PowhegHooks > fEmissionVetoHook
static const std::vector< std::string > p8SharedResources
Abs< T >::type abs(const T &t)
unsigned int pythiaPylistVerbosity
std::unique_ptr< GenLumiInfoHeader > getGenLumiInfoHeader() const override
std::unique_ptr< HepMC::GenEvent > & event()
std::vector< std::string > const & doSharedResources() const override
lhef::LHERunInfo * lheRunInfo()
bool generatePartonsAndHadronize() override
std::unique_ptr< LHAupLesHouches > lhaUP
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
std::unique_ptr< UserHooks > fReweightRapUserHook
std::unique_ptr< UserHooks > fReweightUserHook
std::string evtgenPdlFile
std::unique_ptr< GenEventInfoProduct > & eventInfo()
unsigned int maxEventsToPrint
def remove(d, key, TELL=False)
std::unique_ptr< UserHooks > fReweightEmpUserHook
Pythia8Hadronizer(const edm::ParameterSet ¶ms)
bool pythiaHepMCVerbosity
std::string evtgenDecFile
std::unique_ptr< ResonanceDecayFilterHook > fResonanceDecayFilterHook
std::unique_ptr< MultiUserHook > fMultiUserHook
HepMC::Pythia8ToHepMC toHepMC
std::unique_ptr< PTFilterHook > fPTFilterHook
std::unique_ptr< Pythia8::Pythia > fMasterGen
static const std::string kPythia8
void finalizeEvent() override
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter
std::unique_ptr< Pythia8::Dire > fDire
std::unique_ptr< Vincia::VinciaPlugin > fvincia
~Pythia8Hadronizer() override