10 #include "HepMC/GenEvent.h" 11 #include "HepMC/GenParticle.h" 13 #include "Pythia8/Pythia.h" 14 #include "Pythia8Plugins/HepMC2.h" 27 #include "Pythia8Plugins/JetMatching.h" 28 #include "Pythia8Plugins/aMCatNLOHooks.h" 32 #include "Pythia8Plugins/PowhegHooks.h" 33 #include "Pythia8Plugins/PowhegHooksVincia.h" 51 #include "Pythia8Plugins/EvtGen.h" 69 #include "HepPID/ParticleIDTranslations.hh" 75 class HepRandomEngine;
88 void xfUpdate(
int,
double x,
double)
override {
92 if (idBeam == 1000822080) {
97 else if (idBeam == 80160) {
107 double alphaEM = 0.007297353080;
108 double hbarc = 0.197;
110 double bK0 = besselK0(
xi);
111 double bK1 = besselK1(
xi);
113 xgamma = 2. * alphaEM *
pow2(z) /
M_PI * intB;
122 bool initializeForInternalPartons()
override;
123 bool initializeForExternalPartons();
125 bool generatePartonsAndHadronize()
override;
128 virtual bool residualDecay();
130 void finalizeEvent()
override;
134 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
136 std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader()
const override;
140 std::vector<std::string>
const &
doSharedResources()
const override {
return p8SharedResources; }
146 std::shared_ptr<LHAupLesHouches>
lhaUP;
148 enum { PP,
PPbar, ElectronPositron };
156 bool doProtonPhotonFlux =
false;
157 Pythia8::PDFPtr photonFlux =
nullptr;
227 LHEInputFileName(
params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
229 doProtonPhotonFlux(
params.getUntrackedParameter<
bool>(
"doProtonPhotonFlux",
false)),
238 if (
params.exists(
"PPbarInitialState")) {
242 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 243 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
247 }
else if (
params.exists(
"ElectronPositronInitialState")) {
251 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 252 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
256 }
else if (
params.exists(
"ElectronProtonInitialState") ||
params.exists(
"PositronProtonInitialState")) {
259 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
263 toHepMC.set_store_weights(
false);
267 if (
params.exists(
"reweightGen")) {
268 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
272 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
274 if (
params.exists(
"reweightGenEmp")) {
275 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
279 if (rgeParams.
exists(
"tune"))
282 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
284 if (
params.exists(
"reweightGenRap")) {
285 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
293 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
295 if (
params.exists(
"reweightGenPtHatRap")) {
296 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
304 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
307 if (
params.exists(
"useUserHook"))
309 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
313 if (
params.exists(
"jetMatching")) {
316 if (
scheme ==
"Madgraph" ||
scheme ==
"MadgraphFastJet") {
323 if (
params.exists(
"emissionVeto1")) {
325 if (
params.exists(
"EV1_nFinal"))
328 if (
params.exists(
"EV1_vetoOn"))
331 if (
params.exists(
"EV1_maxVetoCount"))
334 if (
params.exists(
"EV1_pThardMode"))
337 if (
params.exists(
"EV1_pTempMode"))
342 if (
params.exists(
"EV1_emittedMode"))
345 if (
params.exists(
"EV1_pTdefMode"))
348 if (
params.exists(
"EV1_MPIvetoOn"))
351 if (
params.exists(
"EV1_QEDvetoMode"))
354 if (
params.exists(
"EV1_nFinalMode"))
369 if (
params.exists(
"UserCustomization")) {
371 const std::vector<edm::ParameterSet> userParams =
372 params.getParameter<std::vector<edm::ParameterSet>>(
"UserCustomization");
373 for (
const auto &pluginParams : userParams) {
380 if (
params.exists(
"VinciaPlugin")) {
382 <<
" Obsolete parameter: VinciaPlugin \n Please use the parameter PartonShowers:model instead \n";
384 if (
params.exists(
"DirePlugin")) {
386 <<
" Obsolete parameter: DirePlugin \n Please use the parameter PartonShowers:model instead \n";
393 bool status =
false, status1 =
false;
402 fMasterGen->settings.mode(
"Beams:idB", -2212);
409 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
413 fMasterGen->settings.mode(
"Beams:frameType", 4);
418 photonFlux = make_shared<Nucleus2gamma2>(1000822080);
437 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
441 bool VinciaShower =
fMasterGen->settings.mode(
"PartonShowers:Model") == 2;
443 if ((
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) &&
447 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 448 "are : jetMatching, emissionVeto1 \n";
453 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
457 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 && VinciaShower) {
458 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Vincia Emission Veto Hook from pythia8 code";
464 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
466 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
472 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
474 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
480 bool TopRecoilHook1 =
fMasterGen->settings.flag(
"TopRecoilHook:doTopRecoilIn");
481 if (TopRecoilHook1) {
482 edm::LogInfo(
"Pythia8Interface") <<
"Turning on RecoilToTop hook from Pythia8Interface";
489 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
490 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
492 if (internalMatching && internalMerging) {
494 <<
" Only one jet matching/merging scheme can be used at a time. \n";
497 if (internalMatching) {
503 if (internalMerging) {
506 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
507 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
508 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
509 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
517 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
518 if (biasedTauDecayer) {
523 std::vector<int> handledParticles;
524 handledParticles.push_back(15);
528 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
529 if (resonanceDecayFilter) {
534 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
548 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hooks";
554 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
570 fDecayer->settings.flag(
"ProcessLevel:all",
false);
571 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
572 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
576 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
584 return (
status && status1);
588 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
590 bool status =
false, status1 =
false;
607 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
612 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hook";
618 bool VinciaShower =
fMasterGen->settings.mode(
"PartonShowers:Model") == 2;
620 if ((
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) &&
624 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 625 "are : jetMatching, emissionVeto1 \n";
630 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
634 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 && VinciaShower) {
635 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Vincia Emission Veto Hook from pythia8 code";
641 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
643 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
649 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
651 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
657 bool TopRecoilHook1 =
fMasterGen->settings.flag(
"TopRecoilHook:doTopRecoilIn");
658 if (TopRecoilHook1) {
659 edm::LogInfo(
"Pythia8Interface") <<
"Turning on RecoilToTop hook from Pythia8Interface";
665 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
666 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
668 if (internalMatching && internalMerging) {
670 <<
" Only one jet matching/merging scheme can be used at a time. \n";
673 if (internalMatching) {
679 if (internalMerging) {
682 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
683 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
684 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
685 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
693 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
694 if (biasedTauDecayer) {
699 std::vector<int> handledParticles;
700 handledParticles.push_back(15);
704 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
705 if (resonanceDecayFilter) {
710 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
725 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
726 fMasterGen->settings.mode(
"Beams:frameType", 4);
732 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
739 fMasterGen->settings.mode(
"Beams:frameType", 5);
741 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
758 fDecayer->settings.flag(
"ProcessLevel:all",
false);
759 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
760 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
764 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
772 return (
status && status1);
780 <<
"Number of ISR vetoed = " <<
nISRveto;
804 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
819 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
820 DJR.push_back(djrmatch[idjr]);
830 event() = std::make_unique<HepMC::GenEvent>();
841 if (mergeweight != 1.) {
842 event()->weights()[0] *= mergeweight;
851 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
852 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
854 event()->weights().push_back(wgt);
856 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
857 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
858 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
859 event()->weights().push_back(wgt);
868 event()->weights().push_back(wgt);
876 event()->weights()[0] *= fvincia->weight(0);
877 for (
int iVar = 1; iVar < fvincia->nWeights(); iVar++) {
878 event()->weights().push_back(fvincia->weight(iVar));
884 fDire->weightsPtr->calcWeight(0.);
885 fDire->weightsPtr->reset();
888 event()->weights()[0] *= fDire->weightsPtr->getShowerWeight(
"base");
890 unordered_map<string, double>::iterator it;
891 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
893 if (it->first ==
"base")
895 event()->weights().push_back(it->second);
917 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
923 if (!py8next ||
std::abs(mergeweight) == 0.) {
933 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
934 DJR.push_back(djrmatch[idjr]);
948 event() = std::make_unique<HepMC::GenEvent>();
960 if (mergeweight != 1.) {
961 event()->weights()[0] *= mergeweight;
974 event()->weights().push_back(wgt);
984 int NPartsBeforeDecays = pythiaEvent->size();
985 int NPartsAfterDecays =
event().get()->particles_size();
987 if (NPartsAfterDecays == NPartsBeforeDecays)
992 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
995 if (
part->status() == 1 && (
fDecayer->particleData).canDecay(
part->pdg_id())) {
1005 part->momentum().x(),
1006 part->momentum().y(),
1007 part->momentum().z(),
1008 part->momentum().t(),
1009 part->generated_mass());
1010 HepMC::GenVertex *ProdVtx =
part->production_vertex();
1011 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
1012 py8part.tau((
fDecayer->particleData).tau0(
part->pdg_id()));
1014 int nentries =
fDecayer->event.size();
1015 if (!
fDecayer->event[nentries - 1].mayDecay())
1018 int nentries1 =
fDecayer->event.size();
1019 if (nentries1 <= nentries)
1022 part->set_status(2);
1040 eventInfo() = std::make_unique<GenEventInfoProduct>(
event().get());
1064 <<
"----------------------" << std::endl;
1069 <<
"----------------------" << std::endl;
1085 int weights_number =
fMasterGen->info.nWeights();
1087 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
1088 if (weights_number > 1) {
1097 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
1098 const auto &wgtgrpwgt = wgtgrp.second.weights.find(
key);
1099 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
1100 weightgroupname = wgtgrp.first;
1104 std::ostringstream weightname;
1105 weightname <<
"LHE, id = " <<
key <<
", ";
1106 if (!weightgroupname.empty()) {
1107 weightname <<
"group = " << weightgroupname <<
", ";
1109 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
1126 if (fvincia.get()) {
1127 for (
int iVar = 0; iVar < fvincia->nWeights(); iVar++) {
1136 unordered_map<string, double>::iterator it;
1137 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
1139 if (it->first ==
"base")
edm::ConcurrentGeneratorFilter< Pythia8Hadronizer, ConcurrentExternalDecayDriver > Pythia8ConcurrentGeneratorFilter
std::shared_ptr< PowhegHooksBB4L > fPowhegHooksBB4L
virtual bool residualDecay()
std::shared_ptr< PowhegHooksVincia > fEmissionVetoHookVincia
T getParameter(std::string const &) const
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
std::shared_ptr< TopRecoilHook > fTopRecoilHook
HepMC::IO_AsciiParticles * ascii_io
bool initializeForExternalPartons()
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
Pythia8::PDFPtr photonFlux
void setInternalXSec(const XSec &xsec)
constexpr int pow2(int x)
std::shared_ptr< LHAupLesHouches > lhaUP
std::vector< std::string > evtgenUserFiles
edm::ConcurrentHadronizerFilter< Pythia8Hadronizer, ConcurrentExternalDecayDriver > Pythia8ConcurrentHadronizerFilter
GenRunInfoProduct & runInfo()
lhef::LHEEvent * lheEvent()
void xfUpdate(int, double x, double) override
static const std::vector< std::string > p8SharedResources
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
#define DEFINE_FWK_MODULE(type)
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
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
def remove(d, key, TELL=False)
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
Nucleus2gamma2(int idBeamIn)
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