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";
644 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
645 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
647 if (internalMatching && internalMerging) {
649 <<
" Only one jet matching/merging scheme can be used at a time. \n";
652 if (internalMatching) {
658 if (internalMerging) {
661 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
662 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
663 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
664 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
672 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
673 if (biasedTauDecayer) {
678 std::vector<int> handledParticles;
679 handledParticles.push_back(15);
683 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
684 if (resonanceDecayFilter) {
689 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
704 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
705 fMasterGen->settings.mode(
"Beams:frameType", 4);
711 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
718 fMasterGen->settings.mode(
"Beams:frameType", 5);
720 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
737 fDecayer->settings.flag(
"ProcessLevel:all",
false);
738 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
739 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
743 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
751 return (
status && status1);
759 <<
"Number of ISR vetoed = " <<
nISRveto;
783 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
798 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
799 DJR.push_back(djrmatch[idjr]);
809 event() = std::make_unique<HepMC::GenEvent>();
820 if (mergeweight != 1.) {
821 event()->weights()[0] *= mergeweight;
830 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
831 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
833 event()->weights().push_back(wgt);
835 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
836 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
837 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
838 event()->weights().push_back(wgt);
847 event()->weights().push_back(wgt);
855 event()->weights()[0] *= fvincia->weight(0);
856 for (
int iVar = 1; iVar < fvincia->nWeights(); iVar++) {
857 event()->weights().push_back(fvincia->weight(iVar));
863 fDire->weightsPtr->calcWeight(0.);
864 fDire->weightsPtr->reset();
867 event()->weights()[0] *= fDire->weightsPtr->getShowerWeight(
"base");
869 unordered_map<string, double>::iterator
it;
870 for (
it = fDire->weightsPtr->getShowerWeights()->begin();
it != fDire->weightsPtr->getShowerWeights()->end();
872 if (
it->first ==
"base")
874 event()->weights().push_back(
it->second);
896 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
902 if (!py8next ||
std::abs(mergeweight) == 0.) {
912 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
913 DJR.push_back(djrmatch[idjr]);
927 event() = std::make_unique<HepMC::GenEvent>();
939 if (mergeweight != 1.) {
940 event()->weights()[0] *= mergeweight;
953 event()->weights().push_back(wgt);
963 int NPartsBeforeDecays = pythiaEvent->size();
964 int NPartsAfterDecays =
event().get()->particles_size();
966 if (NPartsAfterDecays == NPartsBeforeDecays)
971 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
974 if (
part->status() == 1 && (
fDecayer->particleData).canDecay(
part->pdg_id())) {
984 part->momentum().x(),
985 part->momentum().y(),
986 part->momentum().z(),
987 part->momentum().t(),
988 part->generated_mass());
989 HepMC::GenVertex *ProdVtx =
part->production_vertex();
990 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
991 py8part.tau((
fDecayer->particleData).tau0(
part->pdg_id()));
993 int nentries =
fDecayer->event.size();
994 if (!
fDecayer->event[nentries - 1].mayDecay())
997 int nentries1 =
fDecayer->event.size();
998 if (nentries1 <= nentries)
1001 part->set_status(2);
1019 eventInfo() = std::make_unique<GenEventInfoProduct>(
event().get());
1043 <<
"----------------------" << std::endl;
1048 <<
"----------------------" << std::endl;
1064 int weights_number =
fMasterGen->info.nWeights();
1066 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
1067 if (weights_number > 1) {
1076 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
1077 const auto &wgtgrpwgt = wgtgrp.second.weights.find(
key);
1078 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
1079 weightgroupname = wgtgrp.first;
1083 std::ostringstream weightname;
1084 weightname <<
"LHE, id = " <<
key <<
", ";
1085 if (!weightgroupname.empty()) {
1086 weightname <<
"group = " << weightgroupname <<
", ";
1088 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
1105 if (fvincia.get()) {
1106 for (
int iVar = 0; iVar < fvincia->nWeights(); iVar++) {
1115 unordered_map<string, double>::iterator
it;
1116 for (
it = fDire->weightsPtr->getShowerWeights()->begin();
it != fDire->weightsPtr->getShowerWeights()->end();
1118 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)
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
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
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