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 };
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";
237 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
239 if( params.
exists(
"reweightGenRap" ) )
241 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
252 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
254 if( params.
exists(
"reweightGenPtHatRap" ) )
256 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
267 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
270 if( params.
exists(
"useUserHook" ) )
272 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
276 if ( params.
exists(
"jetMatching") )
281 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
289 if ( params.
exists(
"emissionVeto1") )
303 <<
" Wrong value for EV1_pTempMode code\n";
320 if( params.
exists(
"VinciaPlugin" ) ) {
324 if( params.
exists(
"DirePlugin" ) ) {
326 fDire.reset(
new Pythia8::Dire());
342 bool status =
false, status1 =
false;
353 fMasterGen->settings.mode(
"Beams:idB", -2212);
364 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
369 fMasterGen->settings.mode(
"Beams:frameType", 4);
381 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
385 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
389 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
393 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
397 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
399 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
404 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
406 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
412 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
413 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process")==
"void");
415 if (internalMatching && internalMerging) {
417 <<
" Only one jet matching/merging scheme can be used at a time. \n";
420 if (internalMatching) {
425 if (internalMerging) {
426 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
427 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
429 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
430 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
431 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
432 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
435 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
439 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
440 if (resonanceDecayFilter) {
445 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
455 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
457 fvincia->init(); status =
true;
459 else if(
fDire.get() ) {
461 fDire->weightsPtr->setup();
484 fDecayer->settings.flag(
"ProcessLevel:all",
false );
485 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
486 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
490 edm::LogInfo(
"Pythia8Hadronizer") <<
"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(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
639 return (status&&status1);
649 <<
"Number of ISR vetoed = " <<
nISRveto;
651 <<
"Number of FSR vetoed = " <<
nFSRveto;
677 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
693 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
694 DJR.push_back(djrmatch[idjr]);
703 event().reset(
new HepMC::GenEvent);
711 if (mergeweight!=1.) {
712 event()->weights()[0] *= mergeweight;
721 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
722 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
723 double wgt = (*
fMasterGen->info.weights_detailed)[key];
724 event()->weights().push_back(wgt);
727 else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
728 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
729 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
730 event()->weights().push_back(wgt);
739 event()->weights().push_back(wgt);
747 for (
int iVar=1; iVar <
fvincia->nWeights(); iVar++) {
754 fDire->weightsPtr->calcWeight(0.);
755 fDire->weightsPtr->reset();
758 event()->weights()[0] *=
fDire->weightsPtr->getShowerWeight(
"base");
760 map<string, double>::iterator it;
761 for ( it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end(); it++ ) {
762 if (it->first ==
"base")
continue;
763 event()->weights().push_back(it->second);
787 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
794 if (!py8next ||
std::abs(mergeweight)==0.)
805 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
806 DJR.push_back(djrmatch[idjr]);
819 event().reset(
new HepMC::GenEvent);
826 if (mergeweight!=1.) {
827 event()->weights()[0] *= mergeweight;
840 event()->weights().push_back(wgt);
854 int NPartsBeforeDecays = pythiaEvent->size();
855 int NPartsAfterDecays =
event().get()->particles_size();
857 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
861 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
866 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
869 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
870 part->momentum().x(),
871 part->momentum().y(),
872 part->momentum().z(),
873 part->momentum().t(),
874 part->generated_mass() );
875 HepMC::GenVertex* ProdVtx = part->production_vertex();
876 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
877 ProdVtx->position().z(), ProdVtx->position().t() );
878 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
880 int nentries =
fDecayer->event.size();
881 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
883 int nentries1 =
fDecayer->event.size();
884 if ( nentries1 <= nentries )
continue;
931 <<
"----------------------" << std::endl;
937 <<
"----------------------" << std::endl;
953 int weights_number =
fMasterGen->info.nWeights();
955 if(weights_number > 1){
956 genLumiInfoHeader->
weightNames().reserve(weights_number + 1);
957 genLumiInfoHeader->
weightNames().push_back(
"nominal");
964 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
965 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
966 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
967 weightgroupname = wgtgrp.first;
971 std::ostringstream weightname;
972 weightname <<
"LHE, id = " << key <<
", ";
973 if (!weightgroupname.empty()) {
974 weightname <<
"group = " << weightgroupname <<
", ";
976 weightname<<
fMasterGen->info.initrwgt->weights[
key].contents;
977 genLumiInfoHeader->
weightNames().push_back(weightname.str());
993 for (
int iVar=0; iVar <
fvincia->nWeights(); iVar++) {
1000 genLumiInfoHeader->
weightNames().push_back(
"base");
1002 map<string, double>::iterator it;
1003 for ( it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end(); it++ ) {
1004 if (it->first ==
"base")
continue;
1005 genLumiInfoHeader->
weightNames().push_back(it->first);
1009 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