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;
90 void xfUpdate(
int,
double x,
double)
override {
93 if (idBeam == 1000822080)
98 if (idBeam == 1000822080)
104 <<
" Invalid photon flux input parameters: beam ID= " << idBeam <<
" , radius= " <<
radius <<
" , z= " << z
112 double alphaEM = 0.007297353080;
113 double hbarc = 0.197;
115 double bK0 = besselK0(
xi);
116 double bK1 = besselK1(
xi);
118 xgamma = 2. * alphaEM *
pow2(z) /
M_PI * intB;
127 bool initializeForInternalPartons()
override;
128 bool initializeForExternalPartons();
130 bool generatePartonsAndHadronize()
override;
133 virtual bool residualDecay();
135 void finalizeEvent()
override;
139 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
141 std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader()
const override;
145 std::vector<std::string>
const &
doSharedResources()
const override {
return p8SharedResources; }
151 std::shared_ptr<LHAupLesHouches>
lhaUP;
153 enum { PP,
PPbar, ElectronPositron };
230 LHEInputFileName(
params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
240 if (
params.exists(
"PPbarInitialState")) {
244 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 245 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
249 }
else if (
params.exists(
"ElectronPositronInitialState")) {
253 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 254 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
258 }
else if (
params.exists(
"ElectronProtonInitialState") ||
params.exists(
"PositronProtonInitialState")) {
261 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
265 toHepMC.set_store_weights(
false);
267 if (
params.exists(
"PhotonFlux")) {
273 if (
params.exists(
"reweightGen")) {
274 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
278 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
280 if (
params.exists(
"reweightGenEmp")) {
281 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
285 if (rgeParams.
exists(
"tune"))
288 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
290 if (
params.exists(
"reweightGenRap")) {
291 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
299 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
301 if (
params.exists(
"reweightGenPtHatRap")) {
302 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
310 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
313 if (
params.exists(
"useUserHook"))
315 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
319 if (
params.exists(
"jetMatching")) {
322 if (
scheme ==
"Madgraph" ||
scheme ==
"MadgraphFastJet") {
329 if (
params.exists(
"emissionVeto1")) {
331 if (
params.exists(
"EV1_nFinal"))
334 if (
params.exists(
"EV1_vetoOn"))
337 if (
params.exists(
"EV1_maxVetoCount"))
340 if (
params.exists(
"EV1_pThardMode"))
343 if (
params.exists(
"EV1_pTempMode"))
348 if (
params.exists(
"EV1_emittedMode"))
351 if (
params.exists(
"EV1_pTdefMode"))
354 if (
params.exists(
"EV1_MPIvetoOn"))
357 if (
params.exists(
"EV1_QEDvetoMode"))
360 if (
params.exists(
"EV1_nFinalMode"))
375 if (
params.exists(
"UserCustomization")) {
377 const std::vector<edm::ParameterSet> userParams =
378 params.getParameter<std::vector<edm::ParameterSet>>(
"UserCustomization");
379 for (
const auto &pluginParams : userParams) {
386 if (
params.exists(
"VinciaPlugin")) {
388 <<
" Obsolete parameter: VinciaPlugin \n Please use the parameter PartonShowers:model instead \n";
390 if (
params.exists(
"DirePlugin")) {
392 <<
" Obsolete parameter: DirePlugin \n Please use the parameter PartonShowers:model instead \n";
399 bool status =
false, status1 =
false;
408 fMasterGen->settings.mode(
"Beams:idB", -2212);
415 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
419 fMasterGen->settings.mode(
"Beams:frameType", 4);
430 Pythia8::PDFPtr photonFluxA =
431 fMasterGen->settings.flag(
"PDF:beamA2gamma") ? make_shared<Nucleus2gamma2>(beamTypeA, radiusA, zA) :
nullptr;
432 Pythia8::PDFPtr photonFluxB =
433 fMasterGen->settings.flag(
"PDF:beamB2gamma") ? make_shared<Nucleus2gamma2>(beamTypeB, radiusB, zB) :
nullptr;
434 fMasterGen->setPhotonFluxPtr(photonFluxA, photonFluxB);
452 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
456 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
459 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 460 "are : jetMatching, emissionVeto1 \n";
465 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
469 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
471 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
477 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
479 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
485 bool TopRecoilHook1 =
fMasterGen->settings.flag(
"TopRecoilHook:doTopRecoilIn");
486 if (TopRecoilHook1) {
487 edm::LogInfo(
"Pythia8Interface") <<
"Turning on RecoilToTop hook from Pythia8Interface";
494 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
495 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
497 if (internalMatching && internalMerging) {
499 <<
" Only one jet matching/merging scheme can be used at a time. \n";
502 if (internalMatching) {
508 if (internalMerging) {
511 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
512 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
513 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
514 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
522 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
523 if (biasedTauDecayer) {
528 std::vector<int> handledParticles;
529 handledParticles.push_back(15);
533 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
534 if (resonanceDecayFilter) {
539 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
553 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hooks";
559 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
575 fDecayer->settings.flag(
"ProcessLevel:all",
false);
576 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
577 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
581 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
589 return (
status && status1);
593 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
595 bool status =
false, status1 =
false;
612 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
617 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hook";
623 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
626 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 627 "are : jetMatching, emissionVeto1 \n";
632 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
636 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
638 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
644 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
646 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
652 bool TopRecoilHook1 =
fMasterGen->settings.flag(
"TopRecoilHook:doTopRecoilIn");
653 if (TopRecoilHook1) {
654 edm::LogInfo(
"Pythia8Interface") <<
"Turning on RecoilToTop hook from Pythia8Interface";
661 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
662 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
664 if (internalMatching && internalMerging) {
666 <<
" Only one jet matching/merging scheme can be used at a time. \n";
669 if (internalMatching) {
675 if (internalMerging) {
678 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
679 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
680 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
681 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
689 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
690 if (biasedTauDecayer) {
695 std::vector<int> handledParticles;
696 handledParticles.push_back(15);
700 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
701 if (resonanceDecayFilter) {
706 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
721 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
722 fMasterGen->settings.mode(
"Beams:frameType", 4);
728 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
735 fMasterGen->settings.mode(
"Beams:frameType", 5);
737 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
754 fDecayer->settings.flag(
"ProcessLevel:all",
false);
755 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
756 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
760 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
768 return (
status && status1);
776 <<
"Number of ISR vetoed = " <<
nISRveto;
800 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
815 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
816 DJR.push_back(djrmatch[idjr]);
826 event() = std::make_unique<HepMC::GenEvent>();
837 if (mergeweight != 1.) {
838 event()->weights()[0] *= mergeweight;
847 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
848 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
850 event()->weights().push_back(wgt);
852 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
853 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
854 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
855 event()->weights().push_back(wgt);
864 event()->weights().push_back(wgt);
872 event()->weights()[0] *= fvincia->weight(0);
873 for (
int iVar = 1; iVar < fvincia->nWeights(); iVar++) {
874 event()->weights().push_back(fvincia->weight(iVar));
880 fDire->weightsPtr->calcWeight(0.);
881 fDire->weightsPtr->reset();
884 event()->weights()[0] *= fDire->weightsPtr->getShowerWeight(
"base");
886 unordered_map<string, double>::iterator
it;
887 for (
it = fDire->weightsPtr->getShowerWeights()->begin();
it != fDire->weightsPtr->getShowerWeights()->end();
889 if (
it->first ==
"base")
891 event()->weights().push_back(
it->second);
913 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
919 if (!py8next ||
std::abs(mergeweight) == 0.) {
929 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
930 DJR.push_back(djrmatch[idjr]);
944 event() = std::make_unique<HepMC::GenEvent>();
956 if (mergeweight != 1.) {
957 event()->weights()[0] *= mergeweight;
970 event()->weights().push_back(wgt);
980 int NPartsBeforeDecays = pythiaEvent->size();
981 int NPartsAfterDecays =
event().get()->particles_size();
983 if (NPartsAfterDecays == NPartsBeforeDecays)
988 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
991 if (
part->status() == 1 && (
fDecayer->particleData).canDecay(
part->pdg_id())) {
1001 part->momentum().x(),
1002 part->momentum().y(),
1003 part->momentum().z(),
1004 part->momentum().t(),
1005 part->generated_mass());
1006 HepMC::GenVertex *ProdVtx =
part->production_vertex();
1007 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
1008 py8part.tau((
fDecayer->particleData).tau0(
part->pdg_id()));
1010 int nentries =
fDecayer->event.size();
1011 if (!
fDecayer->event[nentries - 1].mayDecay())
1014 int nentries1 =
fDecayer->event.size();
1015 if (nentries1 <= nentries)
1018 part->set_status(2);
1036 eventInfo() = std::make_unique<GenEventInfoProduct>(
event().get());
1060 <<
"----------------------" << std::endl;
1065 <<
"----------------------" << std::endl;
1081 int weights_number =
fMasterGen->info.nWeights();
1083 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
1084 if (weights_number > 1) {
1093 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
1094 const auto &wgtgrpwgt = wgtgrp.second.weights.find(
key);
1095 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
1096 weightgroupname = wgtgrp.first;
1100 std::ostringstream weightname;
1101 weightname <<
"LHE, id = " <<
key <<
", ";
1102 if (!weightgroupname.empty()) {
1103 weightname <<
"group = " << weightgroupname <<
", ";
1105 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
1122 if (fvincia.get()) {
1123 for (
int iVar = 0; iVar < fvincia->nWeights(); iVar++) {
1132 unordered_map<string, double>::iterator
it;
1133 for (
it = fDire->weightsPtr->getShowerWeights()->begin();
it != fDire->weightsPtr->getShowerWeights()->end();
1135 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
Nucleus2gamma2(int idBeamIn, double R=-1.0, int Z=-1)
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)
constexpr int pow2(int x)
std::shared_ptr< LHAupLesHouches > lhaUP
std::vector< std::string > evtgenUserFiles
edm::ConcurrentHadronizerFilter< Pythia8Hadronizer, ConcurrentExternalDecayDriver > Pythia8ConcurrentHadronizerFilter
T getUntrackedParameter(std::string const &, T const &) const
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
key
prepare the HTCondor submission files and eventually submit them
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
edm::ParameterSet photonFluxParams
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
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