10 #include "HepMC/GenEvent.h"
11 #include "HepMC/GenParticle.h"
13 #include "Pythia8/Pythia.h"
14 #include "Pythia8Plugins/HepMC2.h"
16 using namespace Pythia8;
26 #include "Pythia8Plugins/JetMatching.h"
27 #include "Pythia8Plugins/aMCatNLOHooks.h"
31 #include "Pythia8Plugins/PowhegHooks.h"
49 #include "Pythia8Plugins/EvtGen.h"
67 #include "HepPID/ParticleIDTranslations.hh"
73 class HepRandomEngine;
83 bool initializeForInternalPartons()
override;
84 bool initializeForExternalPartons();
86 bool generatePartonsAndHadronize()
override;
89 virtual bool residualDecay();
91 void finalizeEvent()
override;
93 void statistics()
override;
95 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
97 std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader()
const override;
101 std::vector<std::string>
const &
doSharedResources()
const override {
return p8SharedResources; }
107 std::shared_ptr<LHAupLesHouches>
lhaUP;
109 enum { PP,
PPbar, ElectronPositron };
178 comEnergy(params.getParameter<double>(
"comEnergy")),
179 LHEInputFileName(params.getUntrackedParameter<std::
string>(
"LHEInputFileName",
"")),
188 if (params.
exists(
"PPbarInitialState")) {
192 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
193 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
197 }
else if (params.
exists(
"ElectronPositronInitialState")) {
201 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
202 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
206 }
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")) {
215 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
219 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
221 if (params.
exists(
"reweightGenEmp")) {
222 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
226 if (rgeParams.
exists(
"tune"))
229 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
231 if (params.
exists(
"reweightGenRap")) {
232 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
240 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
242 if (params.
exists(
"reweightGenPtHatRap")) {
243 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
251 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
254 if (params.
exists(
"useUserHook"))
256 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
260 if (params.
exists(
"jetMatching")) {
263 if (scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet") {
270 if (params.
exists(
"emissionVeto1")) {
272 if (params.
exists(
"EV1_nFinal"))
275 if (params.
exists(
"EV1_vetoOn"))
278 if (params.
exists(
"EV1_maxVetoCount"))
281 if (params.
exists(
"EV1_pThardMode"))
284 if (params.
exists(
"EV1_pTempMode"))
289 if (params.
exists(
"EV1_emittedMode"))
292 if (params.
exists(
"EV1_pTdefMode"))
295 if (params.
exists(
"EV1_MPIvetoOn"))
298 if (params.
exists(
"EV1_QEDvetoMode"))
301 if (params.
exists(
"EV1_nFinalMode"))
316 if (params.
exists(
"UserCustomization")) {
318 const std::vector<edm::ParameterSet> userParams =
319 params.
getParameter<std::vector<edm::ParameterSet>>(
"UserCustomization");
320 for (
const auto &pluginParams : userParams) {
327 if (params.
exists(
"VinciaPlugin")) {
329 <<
" Obsolete parameter: VinciaPlugin \n Please use the parameter PartonShowers:model instead \n";
331 if (params.
exists(
"DirePlugin")) {
333 <<
" Obsolete parameter: DirePlugin \n Please use the parameter PartonShowers:model instead \n";
340 bool status =
false, status1 =
false;
349 fMasterGen->settings.mode(
"Beams:idB", -2212);
356 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
360 fMasterGen->settings.mode(
"Beams:frameType", 4);
379 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
383 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
386 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible "
387 "are : jetMatching, emissionVeto1 \n";
392 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
396 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
398 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
404 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
406 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
413 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
414 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
416 if (internalMatching && internalMerging) {
418 <<
" Only one jet matching/merging scheme can be used at a time. \n";
421 if (internalMatching) {
427 if (internalMerging) {
428 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree") ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt"))
430 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
431 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
432 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
433 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
437 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
441 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
442 if (biasedTauDecayer) {
447 std::vector<int> handledParticles;
448 handledParticles.push_back(15);
452 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
453 if (resonanceDecayFilter) {
458 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
472 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hooks";
478 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
494 fDecayer->settings.flag(
"ProcessLevel:all",
false);
495 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
496 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
500 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
508 return (status && status1);
512 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
514 bool status =
false, status1 =
false;
531 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
536 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hook";
542 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
545 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible "
546 "are : jetMatching, emissionVeto1 \n";
551 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
555 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
557 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
563 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
565 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
572 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
573 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
575 if (internalMatching && internalMerging) {
577 <<
" Only one jet matching/merging scheme can be used at a time. \n";
580 if (internalMatching) {
586 if (internalMerging) {
587 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree") ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt"))
589 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
590 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
591 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
592 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
596 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
600 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
601 if (biasedTauDecayer) {
606 std::vector<int> handledParticles;
607 handledParticles.push_back(15);
611 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
612 if (resonanceDecayFilter) {
617 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
632 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
633 fMasterGen->settings.mode(
"Beams:frameType", 4);
639 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
646 fMasterGen->settings.mode(
"Beams:frameType", 5);
648 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
665 fDecayer->settings.flag(
"ProcessLevel:all",
false);
666 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
667 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
671 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
679 return (status && status1);
687 <<
"Number of ISR vetoed = " <<
nISRveto;
711 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
726 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
727 DJR.push_back(djrmatch[idjr]);
737 event() = std::make_unique<HepMC::GenEvent>();
745 if (mergeweight != 1.) {
746 event()->weights()[0] *= mergeweight;
755 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
756 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
757 double wgt = (*
fMasterGen->info.weights_detailed)[key];
758 event()->weights().push_back(wgt);
760 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
761 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
762 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
763 event()->weights().push_back(wgt);
772 event()->weights().push_back(wgt);
780 event()->weights()[0] *= fvincia->weight(0);
781 for (
int iVar = 1; iVar < fvincia->nWeights(); iVar++) {
782 event()->weights().push_back(fvincia->weight(iVar));
788 fDire->weightsPtr->calcWeight(0.);
789 fDire->weightsPtr->reset();
792 event()->weights()[0] *= fDire->weightsPtr->getShowerWeight(
"base");
794 unordered_map<string, double>::iterator it;
795 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
797 if (it->first ==
"base")
799 event()->weights().push_back(it->second);
821 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
827 if (!py8next ||
std::abs(mergeweight) == 0.) {
837 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
838 DJR.push_back(djrmatch[idjr]);
852 event() = std::make_unique<HepMC::GenEvent>();
859 if (mergeweight != 1.) {
860 event()->weights()[0] *= mergeweight;
873 event()->weights().push_back(wgt);
883 int NPartsBeforeDecays = pythiaEvent->size();
884 int NPartsAfterDecays =
event().get()->particles_size();
886 if (NPartsAfterDecays == NPartsBeforeDecays)
891 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
894 if (part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id())) {
896 Particle py8part(part->pdg_id(),
904 part->momentum().x(),
905 part->momentum().y(),
906 part->momentum().z(),
907 part->momentum().t(),
908 part->generated_mass());
909 HepMC::GenVertex *ProdVtx = part->production_vertex();
910 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
911 py8part.tau((
fDecayer->particleData).tau0(part->pdg_id()));
913 int nentries =
fDecayer->event.size();
914 if (!
fDecayer->event[nentries - 1].mayDecay())
917 int nentries1 =
fDecayer->event.size();
918 if (nentries1 <= nentries)
939 eventInfo() = std::make_unique<GenEventInfoProduct>(
event().get());
963 <<
"----------------------" << std::endl;
968 <<
"----------------------" << std::endl;
975 auto genLumiInfoHeader = BaseHadronizer::getGenLumiInfoHeader();
980 genLumiInfoHeader->lheHeaders().emplace_back(
key,
fMasterGen->info.header(
key));
984 int weights_number =
fMasterGen->info.nWeights();
986 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
987 if (weights_number > 1) {
988 genLumiInfoHeader->weightNames().reserve(weights_number + 1);
989 genLumiInfoHeader->weightNames().push_back(
"nominal");
996 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
997 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
998 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
999 weightgroupname = wgtgrp.first;
1003 std::ostringstream weightname;
1004 weightname <<
"LHE, id = " << key <<
", ";
1005 if (!weightgroupname.empty()) {
1006 weightname <<
"group = " << weightgroupname <<
", ";
1008 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
1009 genLumiInfoHeader->weightNames().push_back(weightname.str());
1018 genLumiInfoHeader->weightNames().push_back(
fMasterGen->info.weightLabel(
i));
1025 if (fvincia.get()) {
1026 for (
int iVar = 0; iVar < fvincia->nWeights(); iVar++) {
1027 genLumiInfoHeader->weightNames().push_back(fvincia->weightLabel(iVar));
1033 genLumiInfoHeader->weightNames().push_back(
"base");
1035 unordered_map<string, double>::iterator it;
1036 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
1038 if (it->first ==
"base")
1040 genLumiInfoHeader->weightNames().push_back(it->first);
1045 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
std::shared_ptr< UserHooksVector > fCustomHooksVector
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
deadvectors[0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
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