8 #include "HepMC/GenEvent.h" 9 #include "HepMC/GenParticle.h" 11 #include "Pythia8/Pythia.h" 12 #include "Pythia8Plugins/HepMC2.h" 23 #include "Pythia8Plugins/JetMatching.h" 24 #include "Pythia8Plugins/aMCatNLOHooks.h" 30 #include "Pythia8Plugins/PowhegHooks.h" 45 #include "Pythia8Plugins/EvtGen.h" 61 #include "HepPID/ParticleIDTranslations.hh" 66 class HepRandomEngine;
79 bool initializeForInternalPartons()
override;
80 bool initializeForExternalPartons();
82 bool generatePartonsAndHadronize()
override;
85 virtual bool residualDecay();
87 void finalizeEvent()
override;
91 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
98 virtual std::vector<std::string>
const&
doSharedResources()
const override {
return p8SharedResources; }
104 std::auto_ptr<LHAupLesHouches>
lhaUP;
106 enum { PP,
PPbar, ElectronPositron };
169 comEnergy(params.getParameter<double>(
"comEnergy")),
170 LHEInputFileName(params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
172 nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0)
177 if ( params.
exists(
"PPbarInitialState" ) )
183 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 184 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
191 else if ( params.
exists(
"ElectronPositronInitialState" ) )
197 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 198 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
205 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
209 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
214 if( params.
exists(
"reweightGen" ) )
216 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
223 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
225 if( params.
exists(
"reweightGenEmp" ) )
227 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
232 if(rgeParams.
exists(
"tune"))
235 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
237 if( params.
exists(
"reweightGenRap" ) )
239 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
250 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
252 if( params.
exists(
"reweightGenPtHatRap" ) )
254 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
265 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
268 if( params.
exists(
"useUserHook" ) )
270 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
274 if ( params.
exists(
"jetMatching") )
279 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
287 if ( params.
exists(
"emissionVeto1") )
301 <<
" Wrong value for EV1_pTempMode code\n";
329 bool status =
false, status1 =
false;
340 fMasterGen->settings.mode(
"Beams:idB", -2212);
351 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
356 fMasterGen->settings.mode(
"Beams:frameType", 4);
368 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
372 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
376 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
380 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
384 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
386 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
391 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
393 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
399 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
400 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process")==
"void");
402 if (internalMatching && internalMerging) {
404 <<
" Only one jet matching/merging scheme can be used at a time. \n";
407 if (internalMatching) {
412 if (internalMerging) {
413 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
414 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
416 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
417 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
418 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
419 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
422 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
426 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
427 if (resonanceDecayFilter) {
432 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
442 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
459 fDecayer->settings.flag(
"ProcessLevel:all",
false );
460 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
461 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
465 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
471 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
476 return (status&&status1);
483 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
485 bool status =
false, status1 =
false;
495 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
499 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
503 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
507 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
511 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
513 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
518 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
520 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
526 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
527 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process")==
"void");
529 if (internalMatching && internalMerging) {
531 <<
" Only one jet matching/merging scheme can be used at a time. \n";
534 if (internalMatching) {
539 if (internalMerging) {
540 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
541 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
543 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
544 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
545 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
546 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
549 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
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);
819 int NPartsBeforeDecays = pythiaEvent->size();
820 int NPartsAfterDecays =
event().get()->particles_size();
822 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
826 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
831 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
834 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
835 part->momentum().x(),
836 part->momentum().y(),
837 part->momentum().z(),
838 part->momentum().t(),
839 part->generated_mass() );
840 HepMC::GenVertex* ProdVtx = part->production_vertex();
841 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
842 ProdVtx->position().z(), ProdVtx->position().t() );
843 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
845 int nentries =
fDecayer->event.size();
846 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
848 int nentries1 =
fDecayer->event.size();
849 if ( nentries1 <= nentries )
continue;
896 <<
"----------------------" << std::endl;
902 <<
"----------------------" << std::endl;
918 int weights_number =
fMasterGen->info.nWeights();
920 if(weights_number > 1){
921 genLumiInfoHeader->
weightNames().reserve(weights_number + 1);
922 genLumiInfoHeader->
weightNames().push_back(
"nominal");
929 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
930 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
931 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
932 weightgroupname = wgtgrp.first;
936 std::ostringstream weightname;
937 weightname <<
"LHE, id = " << key <<
", ";
938 if (!weightgroupname.empty()) {
939 weightname <<
"group = " << weightgroupname <<
", ";
941 weightname<<
fMasterGen->info.initrwgt->weights[
key].contents;
942 genLumiInfoHeader->
weightNames().push_back(weightname.str());
955 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
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
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
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