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";
209 toHepMC.set_store_weights(
false);
213 if (params.
exists(
"reweightGen")) {
214 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
218 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
220 if (params.
exists(
"reweightGenEmp")) {
221 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
225 if (rgeParams.
exists(
"tune"))
228 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
230 if (params.
exists(
"reweightGenRap")) {
231 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
239 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
241 if (params.
exists(
"reweightGenPtHatRap")) {
242 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
250 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
253 if (params.
exists(
"useUserHook"))
255 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
259 if (params.
exists(
"jetMatching")) {
262 if (scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet") {
269 if (params.
exists(
"emissionVeto1")) {
271 if (params.
exists(
"EV1_nFinal"))
274 if (params.
exists(
"EV1_vetoOn"))
277 if (params.
exists(
"EV1_maxVetoCount"))
280 if (params.
exists(
"EV1_pThardMode"))
283 if (params.
exists(
"EV1_pTempMode"))
288 if (params.
exists(
"EV1_emittedMode"))
291 if (params.
exists(
"EV1_pTdefMode"))
294 if (params.
exists(
"EV1_MPIvetoOn"))
297 if (params.
exists(
"EV1_QEDvetoMode"))
300 if (params.
exists(
"EV1_nFinalMode"))
315 if (params.
exists(
"VinciaPlugin")) {
317 <<
" Obsolete parameter: VinciaPlugin \n Please use the parameter PartonShowers:model instead \n";
319 if (params.
exists(
"DirePlugin")) {
321 <<
" Obsolete parameter: DirePlugin \n Please use the parameter PartonShowers:model instead \n";
328 bool status =
false, status1 =
false;
337 fMasterGen->settings.mode(
"Beams:idB", -2212);
344 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
348 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) {
374 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible "
375 "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";
392 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
394 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
401 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
402 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
404 if (internalMatching && internalMerging) {
406 <<
" Only one jet matching/merging scheme can be used at a time. \n";
409 if (internalMatching) {
415 if (internalMerging) {
416 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree") ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt"))
418 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
419 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
420 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
421 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
425 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
429 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
430 if (biasedTauDecayer) {
435 std::vector<int> handledParticles;
436 handledParticles.push_back(15);
440 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
441 if (resonanceDecayFilter) {
446 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
459 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
475 fDecayer->settings.flag(
"ProcessLevel:all",
false);
476 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
477 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
481 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
489 return (status && status1);
493 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
495 bool status =
false, status1 =
false;
512 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
516 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
519 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible "
520 "are : jetMatching, emissionVeto1 \n";
525 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
529 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
531 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";
546 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
547 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
549 if (internalMatching && internalMerging) {
551 <<
" Only one jet matching/merging scheme can be used at a time. \n";
554 if (internalMatching) {
560 if (internalMerging) {
561 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree") ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt"))
563 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
564 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
565 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
566 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
570 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
574 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
575 if (biasedTauDecayer) {
580 std::vector<int> handledParticles;
581 handledParticles.push_back(15);
585 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
586 if (resonanceDecayFilter) {
591 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
606 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
607 fMasterGen->settings.mode(
"Beams:frameType", 4);
613 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
620 fMasterGen->settings.mode(
"Beams:frameType", 5);
622 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
639 fDecayer->settings.flag(
"ProcessLevel:all",
false);
640 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
641 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
645 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
653 return (status && status1);
661 <<
"Number of ISR vetoed = " <<
nISRveto;
685 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
700 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
701 DJR.push_back(djrmatch[idjr]);
711 event() = std::make_unique<HepMC::GenEvent>();
722 if (mergeweight != 1.) {
723 event()->weights()[0] *= mergeweight;
732 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
733 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
734 double wgt = (*
fMasterGen->info.weights_detailed)[key];
735 event()->weights().push_back(wgt);
737 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
738 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
739 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
740 event()->weights().push_back(wgt);
749 event()->weights().push_back(wgt);
757 event()->weights()[0] *= fvincia->weight(0);
758 for (
int iVar = 1; iVar < fvincia->nWeights(); iVar++) {
759 event()->weights().push_back(fvincia->weight(iVar));
765 fDire->weightsPtr->calcWeight(0.);
766 fDire->weightsPtr->reset();
769 event()->weights()[0] *= fDire->weightsPtr->getShowerWeight(
"base");
771 unordered_map<string, double>::iterator it;
772 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
774 if (it->first ==
"base")
776 event()->weights().push_back(it->second);
798 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
804 if (!py8next ||
std::abs(mergeweight) == 0.) {
814 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
815 DJR.push_back(djrmatch[idjr]);
829 event() = std::make_unique<HepMC::GenEvent>();
839 if (mergeweight != 1.) {
840 event()->weights()[0] *= mergeweight;
853 event()->weights().push_back(wgt);
863 int NPartsBeforeDecays = pythiaEvent->size();
864 int NPartsAfterDecays =
event().get()->particles_size();
866 if (NPartsAfterDecays == NPartsBeforeDecays)
871 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
874 if (part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id())) {
876 Particle py8part(part->pdg_id(),
884 part->momentum().x(),
885 part->momentum().y(),
886 part->momentum().z(),
887 part->momentum().t(),
888 part->generated_mass());
889 HepMC::GenVertex *ProdVtx = part->production_vertex();
890 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
891 py8part.tau((
fDecayer->particleData).tau0(part->pdg_id()));
893 int nentries =
fDecayer->event.size();
894 if (!
fDecayer->event[nentries - 1].mayDecay())
897 int nentries1 =
fDecayer->event.size();
898 if (nentries1 <= nentries)
915 (
event()->weights()).push_back(1.);
919 eventInfo() = std::make_unique<GenEventInfoProduct>(
event().get());
943 <<
"----------------------" << std::endl;
948 <<
"----------------------" << std::endl;
955 auto genLumiInfoHeader = BaseHadronizer::getGenLumiInfoHeader();
960 genLumiInfoHeader->lheHeaders().emplace_back(
key,
fMasterGen->info.header(
key));
964 int weights_number =
fMasterGen->info.nWeights();
966 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
967 if (weights_number > 1) {
968 genLumiInfoHeader->weightNames().reserve(weights_number + 1);
969 genLumiInfoHeader->weightNames().push_back(
"nominal");
976 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
977 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
978 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
979 weightgroupname = wgtgrp.first;
983 std::ostringstream weightname;
984 weightname <<
"LHE, id = " << key <<
", ";
985 if (!weightgroupname.empty()) {
986 weightname <<
"group = " << weightgroupname <<
", ";
988 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
989 genLumiInfoHeader->weightNames().push_back(weightname.str());
998 genLumiInfoHeader->weightNames().push_back(
fMasterGen->info.weightLabel(
i));
1005 if (fvincia.get()) {
1006 for (
int iVar = 0; iVar < fvincia->nWeights(); iVar++) {
1007 genLumiInfoHeader->weightNames().push_back(fvincia->weightLabel(iVar));
1013 genLumiInfoHeader->weightNames().push_back(
"base");
1015 unordered_map<string, double>::iterator it;
1016 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
1018 if (it->first ==
"base")
1020 genLumiInfoHeader->weightNames().push_back(it->first);
1025 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