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" 50 #include "Pythia8Plugins/EvtGen.h" 68 #include "HepPID/ParticleIDTranslations.hh" 74 class HepRandomEngine;
87 void xfUpdate(
int,
double x,
double)
override {
91 if (idBeam == 1000822080) {
96 else if (idBeam == 80160) {
106 double alphaEM = 0.007297353080;
107 double hbarc = 0.197;
109 double bK0 = besselK0(
xi);
110 double bK1 = besselK1(
xi);
112 xgamma = 2. * alphaEM *
pow2(z) /
M_PI * intB;
121 bool initializeForInternalPartons()
override;
122 bool initializeForExternalPartons();
124 bool generatePartonsAndHadronize()
override;
127 virtual bool residualDecay();
129 void finalizeEvent()
override;
133 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
135 std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader()
const override;
139 std::vector<std::string>
const &
doSharedResources()
const override {
return p8SharedResources; }
145 std::shared_ptr<LHAupLesHouches>
lhaUP;
147 enum { PP,
PPbar, ElectronPositron };
155 bool doProtonPhotonFlux =
false;
156 Pythia8::PDFPtr photonFlux =
nullptr;
225 LHEInputFileName(
params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
227 doProtonPhotonFlux(
params.getUntrackedParameter<
bool>(
"doProtonPhotonFlux",
false)),
236 if (
params.exists(
"PPbarInitialState")) {
240 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 241 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
245 }
else if (
params.exists(
"ElectronPositronInitialState")) {
249 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 250 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
254 }
else if (
params.exists(
"ElectronProtonInitialState") ||
params.exists(
"PositronProtonInitialState")) {
257 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
261 toHepMC.set_store_weights(
false);
265 if (
params.exists(
"reweightGen")) {
266 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
270 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
272 if (
params.exists(
"reweightGenEmp")) {
273 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
277 if (rgeParams.
exists(
"tune"))
280 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
282 if (
params.exists(
"reweightGenRap")) {
283 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
291 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
293 if (
params.exists(
"reweightGenPtHatRap")) {
294 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
302 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
305 if (
params.exists(
"useUserHook"))
307 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
311 if (
params.exists(
"jetMatching")) {
314 if (
scheme ==
"Madgraph" ||
scheme ==
"MadgraphFastJet") {
321 if (
params.exists(
"emissionVeto1")) {
323 if (
params.exists(
"EV1_nFinal"))
326 if (
params.exists(
"EV1_vetoOn"))
329 if (
params.exists(
"EV1_maxVetoCount"))
332 if (
params.exists(
"EV1_pThardMode"))
335 if (
params.exists(
"EV1_pTempMode"))
340 if (
params.exists(
"EV1_emittedMode"))
343 if (
params.exists(
"EV1_pTdefMode"))
346 if (
params.exists(
"EV1_MPIvetoOn"))
349 if (
params.exists(
"EV1_QEDvetoMode"))
352 if (
params.exists(
"EV1_nFinalMode"))
367 if (
params.exists(
"UserCustomization")) {
369 const std::vector<edm::ParameterSet> userParams =
370 params.getParameter<std::vector<edm::ParameterSet>>(
"UserCustomization");
371 for (
const auto &pluginParams : userParams) {
378 if (
params.exists(
"VinciaPlugin")) {
380 <<
" Obsolete parameter: VinciaPlugin \n Please use the parameter PartonShowers:model instead \n";
382 if (
params.exists(
"DirePlugin")) {
384 <<
" Obsolete parameter: DirePlugin \n Please use the parameter PartonShowers:model instead \n";
391 bool status =
false, status1 =
false;
400 fMasterGen->settings.mode(
"Beams:idB", -2212);
407 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
411 fMasterGen->settings.mode(
"Beams:frameType", 4);
416 photonFlux = make_shared<Nucleus2gamma2>(1000822080);
435 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
439 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
442 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 443 "are : jetMatching, emissionVeto1 \n";
448 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
452 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
454 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
460 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
462 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
468 bool TopRecoilHook1 =
fMasterGen->settings.flag(
"TopRecoilHook:doTopRecoilIn");
469 if (TopRecoilHook1) {
470 edm::LogInfo(
"Pythia8Interface") <<
"Turning on RecoilToTop hook from Pythia8Interface";
477 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
478 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
480 if (internalMatching && internalMerging) {
482 <<
" Only one jet matching/merging scheme can be used at a time. \n";
485 if (internalMatching) {
491 if (internalMerging) {
494 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
495 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
496 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
497 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
505 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
506 if (biasedTauDecayer) {
511 std::vector<int> handledParticles;
512 handledParticles.push_back(15);
516 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
517 if (resonanceDecayFilter) {
522 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
536 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hooks";
542 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
558 fDecayer->settings.flag(
"ProcessLevel:all",
false);
559 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
560 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
564 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
572 return (
status && status1);
576 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
578 bool status =
false, status1 =
false;
595 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
600 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hook";
606 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
609 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 610 "are : jetMatching, emissionVeto1 \n";
615 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
619 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
621 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
627 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
629 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
635 bool TopRecoilHook1 =
fMasterGen->settings.flag(
"TopRecoilHook:doTopRecoilIn");
636 if (TopRecoilHook1) {
637 edm::LogInfo(
"Pythia8Interface") <<
"Turning on RecoilToTop hook from Pythia8Interface";
643 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
644 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
646 if (internalMatching && internalMerging) {
648 <<
" Only one jet matching/merging scheme can be used at a time. \n";
651 if (internalMatching) {
657 if (internalMerging) {
660 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
661 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
662 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
663 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
671 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
672 if (biasedTauDecayer) {
677 std::vector<int> handledParticles;
678 handledParticles.push_back(15);
682 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
683 if (resonanceDecayFilter) {
688 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
703 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
704 fMasterGen->settings.mode(
"Beams:frameType", 4);
710 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
717 fMasterGen->settings.mode(
"Beams:frameType", 5);
719 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
736 fDecayer->settings.flag(
"ProcessLevel:all",
false);
737 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
738 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
742 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
750 return (
status && status1);
758 <<
"Number of ISR vetoed = " <<
nISRveto;
782 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
797 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
798 DJR.push_back(djrmatch[idjr]);
808 event() = std::make_unique<HepMC::GenEvent>();
819 if (mergeweight != 1.) {
820 event()->weights()[0] *= mergeweight;
829 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
830 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
832 event()->weights().push_back(wgt);
834 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
835 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
836 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
837 event()->weights().push_back(wgt);
846 event()->weights().push_back(wgt);
854 event()->weights()[0] *= fvincia->weight(0);
855 for (
int iVar = 1; iVar < fvincia->nWeights(); iVar++) {
856 event()->weights().push_back(fvincia->weight(iVar));
862 fDire->weightsPtr->calcWeight(0.);
863 fDire->weightsPtr->reset();
866 event()->weights()[0] *= fDire->weightsPtr->getShowerWeight(
"base");
868 unordered_map<string, double>::iterator it;
869 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
871 if (it->first ==
"base")
873 event()->weights().push_back(it->second);
895 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
901 if (!py8next ||
std::abs(mergeweight) == 0.) {
911 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
912 DJR.push_back(djrmatch[idjr]);
926 event() = std::make_unique<HepMC::GenEvent>();
938 if (mergeweight != 1.) {
939 event()->weights()[0] *= mergeweight;
952 event()->weights().push_back(wgt);
962 int NPartsBeforeDecays = pythiaEvent->size();
963 int NPartsAfterDecays =
event().get()->particles_size();
965 if (NPartsAfterDecays == NPartsBeforeDecays)
970 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
973 if (
part->status() == 1 && (
fDecayer->particleData).canDecay(
part->pdg_id())) {
983 part->momentum().x(),
984 part->momentum().y(),
985 part->momentum().z(),
986 part->momentum().t(),
987 part->generated_mass());
988 HepMC::GenVertex *ProdVtx =
part->production_vertex();
989 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
990 py8part.tau((
fDecayer->particleData).tau0(
part->pdg_id()));
992 int nentries =
fDecayer->event.size();
993 if (!
fDecayer->event[nentries - 1].mayDecay())
996 int nentries1 =
fDecayer->event.size();
997 if (nentries1 <= nentries)
1000 part->set_status(2);
1018 eventInfo() = std::make_unique<GenEventInfoProduct>(
event().get());
1042 <<
"----------------------" << std::endl;
1047 <<
"----------------------" << std::endl;
1063 int weights_number =
fMasterGen->info.nWeights();
1065 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
1066 if (weights_number > 1) {
1075 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
1076 const auto &wgtgrpwgt = wgtgrp.second.weights.find(
key);
1077 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
1078 weightgroupname = wgtgrp.first;
1082 std::ostringstream weightname;
1083 weightname <<
"LHE, id = " <<
key <<
", ";
1084 if (!weightgroupname.empty()) {
1085 weightname <<
"group = " << weightgroupname <<
", ";
1087 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
1104 if (fvincia.get()) {
1105 for (
int iVar = 0; iVar < fvincia->nWeights(); iVar++) {
1114 unordered_map<string, double>::iterator it;
1115 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
1117 if (it->first ==
"base")
edm::ConcurrentGeneratorFilter< Pythia8Hadronizer, ConcurrentExternalDecayDriver > Pythia8ConcurrentGeneratorFilter
std::shared_ptr< PowhegHooksBB4L > fPowhegHooksBB4L
virtual bool residualDecay()
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)
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
constexpr int pow2(int x)
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