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" 25 #include "Pythia8Plugins/JetMatching.h" 26 #include "Pythia8Plugins/aMCatNLOHooks.h" 32 #include "Pythia8Plugins/PowhegHooks.h" 47 #include "Pythia8Plugins/EvtGen.h" 63 #include "HepPID/ParticleIDTranslations.hh" 68 class HepRandomEngine;
81 bool initializeForInternalPartons()
override;
82 bool initializeForExternalPartons();
84 bool generatePartonsAndHadronize()
override;
87 virtual bool residualDecay();
89 void finalizeEvent()
override;
93 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
99 std::auto_ptr<Vincia::VinciaPlugin>
fvincia;
102 virtual std::vector<std::string>
const&
doSharedResources()
const override {
return p8SharedResources; }
108 std::auto_ptr<LHAupLesHouches>
lhaUP;
110 enum { PP,
PPbar, ElectronPositron };
172 comEnergy(params.getParameter<double>(
"comEnergy")),
173 LHEInputFileName(params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
175 nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0), nFSRvetoBB4L(0)
180 if ( params.
exists(
"PPbarInitialState" ) )
186 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 187 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
194 else if ( params.
exists(
"ElectronPositronInitialState" ) )
200 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 201 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
208 else if ( params.
exists(
"ElectronProtonInitialState" ) || params.
exists(
"PositronProtonInitialState" ) )
212 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
217 if( params.
exists(
"reweightGen" ) )
219 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
226 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
228 if( params.
exists(
"reweightGenEmp" ) )
230 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
234 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
236 if( params.
exists(
"reweightGenRap" ) )
238 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
249 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
251 if( params.
exists(
"reweightGenPtHatRap" ) )
253 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
264 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
267 if( params.
exists(
"useUserHook" ) )
269 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
273 if ( params.
exists(
"jetMatching") )
278 if ( scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet" )
286 if ( params.
exists(
"emissionVeto1") )
300 <<
" Wrong value for EV1_pTempMode code\n";
312 if( params.
exists(
"VinciaPlugin" ) ) {
328 bool status =
false, status1 =
false;
339 fMasterGen->settings.mode(
"Beams:idB", -2212);
350 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
355 fMasterGen->settings.mode(
"Beams:frameType", 4);
367 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
371 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
375 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
379 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
383 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
385 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
390 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
392 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
398 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
399 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process")==
"void");
401 if (internalMatching && internalMerging) {
403 <<
" Only one jet matching/merging scheme can be used at a time. \n";
406 if (internalMatching) {
411 if (internalMerging) {
412 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
413 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
415 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
416 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
417 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
418 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
421 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
425 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
426 if (resonanceDecayFilter) {
431 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
441 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
443 fvincia->init(); status =
true;
462 fDecayer->settings.flag(
"ProcessLevel:all",
false );
463 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
464 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
468 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
474 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
479 return (status&&status1);
486 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
488 bool status =
false, status1 =
false;
498 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
502 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
506 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
510 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
514 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
516 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
521 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
523 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
529 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
530 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process")==
"void");
532 if (internalMatching && internalMerging) {
534 <<
" Only one jet matching/merging scheme can be used at a time. \n";
537 if (internalMatching) {
542 if (internalMerging) {
543 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree")
544 ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt")) ?
546 ( (
fMasterGen->settings.flag(
"Merging:doUNLOPSTree")
547 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubt")
548 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSLoop")
549 ||
fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO")) ?
552 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
556 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
557 if (resonanceDecayFilter) {
562 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
574 edm::LogInfo(
"Pythia8Interface") <<
"Initialize direct pythia8 reading from LHE file " 576 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
577 fMasterGen->settings.mode(
"Beams:frameType", 4);
584 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
592 fMasterGen->settings.mode(
"Beams:frameType", 5);
594 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
612 fDecayer->settings.flag(
"ProcessLevel:all",
false );
613 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true );
614 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
618 edm::LogInfo(
"Pythia8Interface") <<
"Creating and initializing pythia8 EvtGen plugin";
625 evtgenDecays->readDecayFile(evtgenUserFile.fullPath().c_str());
630 return (status&&status1);
640 <<
"Number of ISR vetoed = " <<
nISRveto;
642 <<
"Number of FSR vetoed = " <<
nFSRveto;
673 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
689 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
690 DJR.push_back(djrmatch[idjr]);
707 if (mergeweight!=1.) {
708 event()->weights()[0] *= mergeweight;
720 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
721 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
722 double wgt = (*
fMasterGen->info.weights_detailed)[key];
723 event()->weights().push_back(wgt);
726 else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
727 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
728 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
729 event()->weights().push_back(wgt);
738 event()->weights().push_back(wgt);
762 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
769 if (!py8next ||
std::abs(mergeweight)==0.)
780 for (
unsigned int idjr=0; idjr<ndjr; ++idjr) {
781 DJR.push_back(djrmatch[idjr]);
801 if (mergeweight!=1.) {
802 event()->weights()[0] *= mergeweight;
815 event()->weights().push_back(wgt);
829 int NPartsBeforeDecays = pythiaEvent->size();
830 int NPartsAfterDecays =
event().get()->particles_size();
832 if(NPartsAfterDecays == NPartsBeforeDecays)
return true;
836 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
841 if ( part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id()) )
844 Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
845 part->momentum().x(),
846 part->momentum().y(),
847 part->momentum().z(),
848 part->momentum().t(),
849 part->generated_mass() );
850 HepMC::GenVertex* ProdVtx = part->production_vertex();
851 py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
852 ProdVtx->position().z(), ProdVtx->position().t() );
853 py8part.tau( (
fDecayer->particleData).tau0( part->pdg_id() ) );
855 int nentries =
fDecayer->event.size();
856 if ( !
fDecayer->event[nentries-1].mayDecay() )
continue;
858 int nentries1 =
fDecayer->event.size();
859 if ( nentries1 <= nentries )
continue;
906 <<
"----------------------" << std::endl;
912 <<
"----------------------" << std::endl;
928 int weights_number =
fMasterGen->info.nWeights();
930 if(weights_number > 1){
931 genLumiInfoHeader->
weightNames().reserve(weights_number + 1);
932 genLumiInfoHeader->
weightNames().push_back(
"nominal");
939 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
940 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
941 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
942 weightgroupname = wgtgrp.first;
946 std::ostringstream weightname;
947 weightname <<
"LHE, id = " << key <<
", ";
948 if (!weightgroupname.empty()) {
949 weightname <<
"group = " << weightgroupname <<
", ";
951 weightname<<
fMasterGen->info.initrwgt->weights[
key].contents;
952 genLumiInfoHeader->
weightNames().push_back(weightname.str());
965 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
void doSetRandomEngine(CLHEP::HepRandomEngine *v) 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
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