10 #include "HepMC/GenEvent.h"
11 #include "HepMC/GenParticle.h"
13 #include "Pythia8/Pythia.h"
14 #include "Pythia8Plugins/HepMC2.h"
16 using namespace Pythia8;
25 #include "Pythia8Plugins/JetMatching.h"
26 #include "Pythia8Plugins/aMCatNLOHooks.h"
30 #include "Pythia8Plugins/PowhegHooks.h"
48 #include "Pythia8Plugins/EvtGen.h"
66 #include "HepPID/ParticleIDTranslations.hh"
72 class HepRandomEngine;
82 bool initializeForInternalPartons()
override;
83 bool initializeForExternalPartons();
85 bool generatePartonsAndHadronize()
override;
88 virtual bool residualDecay();
90 void finalizeEvent()
override;
92 void statistics()
override;
94 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
96 std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader()
const override;
100 std::vector<std::string>
const &
doSharedResources()
const override {
return p8SharedResources; }
106 std::shared_ptr<LHAupLesHouches>
lhaUP;
108 enum { PP,
PPbar, ElectronPositron };
174 comEnergy(params.getParameter<double>(
"comEnergy")),
175 LHEInputFileName(params.getUntrackedParameter<std::
string>(
"LHEInputFileName",
"")),
184 if (params.
exists(
"PPbarInitialState")) {
188 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
189 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
193 }
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.";
202 }
else if (params.
exists(
"ElectronProtonInitialState") || params.
exists(
"PositronProtonInitialState")) {
205 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
210 if (params.
exists(
"reweightGen")) {
211 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
215 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
217 if (params.
exists(
"reweightGenEmp")) {
218 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
222 if (rgeParams.
exists(
"tune"))
225 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
227 if (params.
exists(
"reweightGenRap")) {
228 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
236 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
238 if (params.
exists(
"reweightGenPtHatRap")) {
239 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
247 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
250 if (params.
exists(
"useUserHook"))
252 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
256 if (params.
exists(
"jetMatching")) {
259 if (scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet") {
266 if (params.
exists(
"emissionVeto1")) {
268 if (params.
exists(
"EV1_nFinal"))
271 if (params.
exists(
"EV1_vetoOn"))
274 if (params.
exists(
"EV1_maxVetoCount"))
277 if (params.
exists(
"EV1_pThardMode"))
280 if (params.
exists(
"EV1_pTempMode"))
285 if (params.
exists(
"EV1_emittedMode"))
288 if (params.
exists(
"EV1_pTdefMode"))
291 if (params.
exists(
"EV1_MPIvetoOn"))
294 if (params.
exists(
"EV1_QEDvetoMode"))
297 if (params.
exists(
"EV1_nFinalMode"))
312 if (params.
exists(
"VinciaPlugin")) {
314 <<
" Obsolete parameter: VinciaPlugin \n Please use the parameter PartonShowers:model instead \n";
316 if (params.
exists(
"DirePlugin")) {
318 <<
" Obsolete parameter: DirePlugin \n Please use the parameter PartonShowers:model instead \n";
325 bool status =
false, status1 =
false;
334 fMasterGen->settings.mode(
"Beams:idB", -2212);
341 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
345 fMasterGen->settings.mode(
"Beams:frameType", 4);
364 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
368 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
371 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible "
372 "are : jetMatching, emissionVeto1 \n";
377 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
381 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
383 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
389 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
391 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) {
412 if (internalMerging) {
413 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree") ||
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"))
422 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
426 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
427 if (biasedTauDecayer) {
432 std::vector<int> handledParticles;
433 handledParticles.push_back(15);
437 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
438 if (resonanceDecayFilter) {
443 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
456 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
472 fDecayer->settings.flag(
"ProcessLevel:all",
false);
473 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
474 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
478 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
486 return (status && status1);
490 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
492 bool status =
false, status1 =
false;
509 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
513 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
516 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible "
517 "are : jetMatching, emissionVeto1 \n";
522 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
526 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
528 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
534 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
536 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
543 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
544 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
546 if (internalMatching && internalMerging) {
548 <<
" Only one jet matching/merging scheme can be used at a time. \n";
551 if (internalMatching) {
557 if (internalMerging) {
558 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree") ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt"))
560 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
561 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
562 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
563 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
567 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
571 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
572 if (biasedTauDecayer) {
577 std::vector<int> handledParticles;
578 handledParticles.push_back(15);
582 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
583 if (resonanceDecayFilter) {
588 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
603 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
604 fMasterGen->settings.mode(
"Beams:frameType", 4);
610 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
617 fMasterGen->settings.mode(
"Beams:frameType", 5);
619 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
636 fDecayer->settings.flag(
"ProcessLevel:all",
false);
637 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
638 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
642 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
650 return (status && status1);
658 <<
"Number of ISR vetoed = " <<
nISRveto;
682 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
697 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
698 DJR.push_back(djrmatch[idjr]);
708 event() = std::make_unique<HepMC::GenEvent>();
716 if (mergeweight != 1.) {
717 event()->weights()[0] *= mergeweight;
726 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
727 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
728 double wgt = (*
fMasterGen->info.weights_detailed)[key];
729 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 event()->weights()[0] *= fvincia->weight(0);
752 for (
int iVar = 1; iVar < fvincia->nWeights(); iVar++) {
753 event()->weights().push_back(fvincia->weight(iVar));
759 fDire->weightsPtr->calcWeight(0.);
760 fDire->weightsPtr->reset();
763 event()->weights()[0] *= fDire->weightsPtr->getShowerWeight(
"base");
765 unordered_map<string, double>::iterator it;
766 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
768 if (it->first ==
"base")
770 event()->weights().push_back(it->second);
792 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
798 if (!py8next ||
std::abs(mergeweight) == 0.) {
808 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
809 DJR.push_back(djrmatch[idjr]);
823 event() = std::make_unique<HepMC::GenEvent>();
830 if (mergeweight != 1.) {
831 event()->weights()[0] *= mergeweight;
844 event()->weights().push_back(wgt);
854 int NPartsBeforeDecays = pythiaEvent->size();
855 int NPartsAfterDecays =
event().get()->particles_size();
857 if (NPartsAfterDecays == NPartsBeforeDecays)
862 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
865 if (part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id())) {
867 Particle py8part(part->pdg_id(),
875 part->momentum().x(),
876 part->momentum().y(),
877 part->momentum().z(),
878 part->momentum().t(),
879 part->generated_mass());
880 HepMC::GenVertex *ProdVtx = part->production_vertex();
881 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), 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())
888 int nentries1 =
fDecayer->event.size();
889 if (nentries1 <= nentries)
906 (
event()->weights()).push_back(1.);
910 eventInfo() = std::make_unique<GenEventInfoProduct>(
event().get());
934 <<
"----------------------" << std::endl;
939 <<
"----------------------" << std::endl;
946 auto genLumiInfoHeader = BaseHadronizer::getGenLumiInfoHeader();
951 genLumiInfoHeader->lheHeaders().emplace_back(
key,
fMasterGen->info.header(
key));
955 int weights_number =
fMasterGen->info.nWeights();
957 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
958 if (weights_number > 1) {
959 genLumiInfoHeader->weightNames().reserve(weights_number + 1);
960 genLumiInfoHeader->weightNames().push_back(
"nominal");
967 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
968 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
969 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
970 weightgroupname = wgtgrp.first;
974 std::ostringstream weightname;
975 weightname <<
"LHE, id = " << key <<
", ";
976 if (!weightgroupname.empty()) {
977 weightname <<
"group = " << weightgroupname <<
", ";
979 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
980 genLumiInfoHeader->weightNames().push_back(weightname.str());
989 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 unordered_map<string, double>::iterator it;
1007 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
1009 if (it->first ==
"base")
1011 genLumiInfoHeader->weightNames().push_back(it->first);
1016 return genLumiInfoHeader;
edm::ConcurrentGeneratorFilter< Pythia8Hadronizer, ConcurrentExternalDecayDriver > Pythia8ConcurrentGeneratorFilter
T getUntrackedParameter(std::string const &, T const &) const
std::shared_ptr< PowhegHooksBB4L > fPowhegHooksBB4L
virtual bool residualDecay()
double comEnergy
Center-of-Mass energy.
std::shared_ptr< PowhegHooks > fEmissionVetoHook
std::shared_ptr< EmissionVetoHook1 > fEmissionVetoHook1
std::shared_ptr< BiasedTauDecayer > fBiasedTauDecayer
std::shared_ptr< Pythia8::EvtGenDecays > evtgenDecays
std::unique_ptr< Pythia8::Pythia > fDecayer
edm::GeneratorFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8GeneratorFilter
bool initializeForInternalPartons() override
HepMC::IO_AsciiParticles * ascii_io
bool initializeForExternalPartons()
#define DEFINE_FWK_MODULE(type)
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)
bool pythiaHepMCVerbosityParticles
std::shared_ptr< UserHooks > fReweightRapUserHook
void setInternalXSec(const XSec &xsec)
std::shared_ptr< LHAupLesHouches > lhaUP
std::vector< std::string > evtgenUserFiles
edm::ConcurrentHadronizerFilter< Pythia8Hadronizer, ConcurrentExternalDecayDriver > Pythia8ConcurrentHadronizerFilter
GenRunInfoProduct & runInfo()
lhef::LHEEvent * lheEvent()
static const std::vector< std::string > p8SharedResources
tuple key
prepare the HTCondor submission files and eventually submit them
Abs< T >::type abs(const T &t)
Log< level::Error, true > LogImportant
std::shared_ptr< ResonanceDecayFilterHook > fResonanceDecayFilterHook
std::shared_ptr< UserHooksVector > fUserHooksVector
unsigned int pythiaPylistVerbosity
const char * classname() const override
std::shared_ptr< PTFilterHook > fPTFilterHook
std::shared_ptr< Pythia8::JetMatchingMadgraph > fJetMatchingPy8InternalHook
std::unique_ptr< HepMC::GenEvent > & event()
Log< level::Warning, true > LogPrint
static std::vector< std::string > checklist lhe
lhef::LHERunInfo * lheRunInfo()
std::shared_ptr< JetMatchingHook > fJetMatchingHook
bool generatePartonsAndHadronize() override
Log< level::Info, false > LogInfo
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
std::shared_ptr< UserHooks > fReweightUserHook
std::shared_ptr< Pythia8::amcnlo_unitarised_interface > fMergingHook
std::string evtgenPdlFile
std::unique_ptr< GenEventInfoProduct > & eventInfo()
unsigned int maxEventsToPrint
T getParameter(std::string const &) const
std::shared_ptr< UserHooks > fReweightEmpUserHook
Pythia8Hadronizer(const edm::ParameterSet ¶ms)
std::shared_ptr< PowhegResHook > fPowhegResHook
bool pythiaHepMCVerbosity
std::string evtgenDecFile
HepMC::Pythia8ToHepMC toHepMC
std::unique_ptr< GenLumiInfoHeader > getGenLumiInfoHeader() const override
std::shared_ptr< UserHooks > fReweightPtHatRapUserHook
std::unique_ptr< Pythia8::Pythia > fMasterGen
std::vector< std::string > const & doSharedResources() const override
static const std::string kPythia8
void finalizeEvent() override
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter
~Pythia8Hadronizer() override