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 };
168 comEnergy(params.getParameter<double>(
"comEnergy")),
169 LHEInputFileName(params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
171 nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0), nFSRvetoBB4L(0)
176 if ( params.
exists(
"PPbarInitialState" ) )
182 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 183 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
190 else if ( params.
exists(
"ElectronPositronInitialState" ) )
196 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 197 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
204 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
208 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
213 if( params.
exists(
"reweightGen" ) )
215 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
222 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
224 if( params.
exists(
"reweightGenEmp" ) )
226 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
230 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
232 if( params.
exists(
"reweightGenRap" ) )
234 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
245 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
247 if( params.
exists(
"reweightGenPtHatRap" ) )
249 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
260 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
263 if( params.
exists(
"useUserHook" ) )
265 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
269 if ( params.
exists(
"jetMatching") )
274 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
282 if ( params.
exists(
"emissionVeto1") )
296 <<
" Wrong value for EV1_pTempMode code\n";
319 bool status =
false, status1 =
false;
330 fMasterGen->settings.mode(
"Beams:idB", -2212);
341 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
346 fMasterGen->settings.mode(
"Beams:frameType", 4);
358 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
362 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
366 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
370 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
374 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
376 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
381 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
383 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
389 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
390 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process")==
"void");
392 if (internalMatching && internalMerging) {
394 <<
" Only one jet matching/merging scheme can be used at a time. \n";
397 if (internalMatching) {
402 if (internalMerging) {
403 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
404 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
406 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
407 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
408 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
409 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
412 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
416 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
417 if (resonanceDecayFilter) {
422 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
432 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
449 fDecayer->settings.flag(
"ProcessLevel:all",
false );
450 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
451 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
455 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
461 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
466 return (status&&status1);
473 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
475 bool status =
false, status1 =
false;
485 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
489 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
493 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
497 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
501 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
503 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
508 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
510 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
516 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
517 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process")==
"void");
519 if (internalMatching && internalMerging) {
521 <<
" Only one jet matching/merging scheme can be used at a time. \n";
524 if (internalMatching) {
529 if (internalMerging) {
530 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
531 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
533 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
534 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
535 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
536 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
539 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
543 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
544 if (resonanceDecayFilter) {
549 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
561 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file " 563 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
564 fMasterGen->settings.mode(
"Beams:frameType", 4);
571 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
579 fMasterGen->settings.mode(
"Beams:frameType", 5);
581 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
599 fDecayer->settings.flag(
"ProcessLevel:all",
false );
600 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
601 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
605 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
612 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
617 return (status&&status1);
627 <<
"Number of ISR vetoed = " <<
nISRveto;
629 <<
"Number of FSR vetoed = " <<
nFSRveto;
660 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
676 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
677 DJR.push_back(djrmatch[idjr]);
686 event().reset(
new HepMC::GenEvent);
694 if (mergeweight!=1.) {
695 event()->weights()[0] *= mergeweight;
707 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
708 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
709 double wgt = (*
fMasterGen->info.weights_detailed)[key];
710 event()->weights().push_back(wgt);
713 else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
714 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
715 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
716 event()->weights().push_back(wgt);
725 event()->weights().push_back(wgt);
749 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
756 if (!py8next ||
std::abs(mergeweight)==0.)
767 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
768 DJR.push_back(djrmatch[idjr]);
781 event().reset(
new HepMC::GenEvent);
788 if (mergeweight!=1.) {
789 event()->weights()[0] *= mergeweight;
802 event()->weights().push_back(wgt);
817 int NPartsBeforeDecays = pythiaEvent->size();
818 int NPartsAfterDecays =
event().get()->particles_size();
820 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
824 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
829 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
832 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
833 part->momentum().x(),
834 part->momentum().y(),
835 part->momentum().z(),
836 part->momentum().t(),
837 part->generated_mass() );
838 HepMC::GenVertex* ProdVtx = part->production_vertex();
839 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
840 ProdVtx->position().z(), ProdVtx->position().t() );
841 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
843 int nentries =
fDecayer->event.size();
844 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
846 int nentries1 =
fDecayer->event.size();
847 if ( nentries1 <= nentries )
continue;
894 <<
"----------------------" << std::endl;
900 <<
"----------------------" << std::endl;
916 int weights_number =
fMasterGen->info.nWeights();
918 if(weights_number > 1){
919 genLumiInfoHeader->
weightNames().reserve(weights_number + 1);
920 genLumiInfoHeader->
weightNames().push_back(
"nominal");
927 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
928 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
929 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
930 weightgroupname = wgtgrp.first;
934 std::ostringstream weightname;
935 weightname <<
"LHE, id = " << key <<
", ";
936 if (!weightgroupname.empty()) {
937 weightname <<
"group = " << weightgroupname <<
", ";
939 weightname<<
fMasterGen->info.initrwgt->weights[
key].contents;
940 genLumiInfoHeader->
weightNames().push_back(weightname.str());
953 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