8 #include "HepMC/GenEvent.h" 9 #include "HepMC/GenParticle.h" 11 #include "Pythia8/Pythia.h" 12 #include "Pythia8Plugins/HepMC2.h" 14 #include "Vincia/Vincia.h" 15 #include "Dire/Dire.h" 27 #include "Pythia8Plugins/JetMatching.h" 28 #include "Pythia8Plugins/aMCatNLOHooks.h" 34 #include "Pythia8Plugins/PowhegHooks.h" 52 #include "Pythia8Plugins/EvtGen.h" 70 #include "HepPID/ParticleIDTranslations.hh" 76 class HepRandomEngine;
86 bool initializeForInternalPartons()
override;
87 bool initializeForExternalPartons();
89 bool generatePartonsAndHadronize()
override;
92 virtual bool residualDecay();
94 void finalizeEvent()
override;
98 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
100 std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader()
const override;
103 std::unique_ptr<Vincia::VinciaPlugin>
fvincia;
104 std::unique_ptr<Pythia8::Dire>
fDire;
107 std::vector<std::string>
const &
doSharedResources()
const override {
return p8SharedResources; }
113 std::unique_ptr<LHAupLesHouches>
lhaUP;
115 enum { PP,
PPbar, ElectronPositron };
183 comEnergy(params.getParameter<double>(
"comEnergy")),
184 LHEInputFileName(params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
192 if (params.
exists(
"PPbarInitialState")) {
196 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 197 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
201 }
else if (params.
exists(
"ElectronPositronInitialState")) {
205 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 206 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
210 }
else if (params.
exists(
"ElectronProtonInitialState") || params.
exists(
"PositronProtonInitialState")) {
213 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
218 if (params.
exists(
"reweightGen")) {
219 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
223 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
225 if (params.
exists(
"reweightGenEmp")) {
226 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
230 if (rgeParams.
exists(
"tune"))
233 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
235 if (params.
exists(
"reweightGenRap")) {
236 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
244 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
246 if (params.
exists(
"reweightGenPtHatRap")) {
247 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
255 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
258 if (params.
exists(
"useUserHook"))
260 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
264 if (params.
exists(
"jetMatching")) {
267 if (scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet") {
274 if (params.
exists(
"emissionVeto1")) {
276 if (params.
exists(
"EV1_nFinal"))
279 if (params.
exists(
"EV1_vetoOn"))
282 if (params.
exists(
"EV1_maxVetoCount"))
285 if (params.
exists(
"EV1_pThardMode"))
288 if (params.
exists(
"EV1_pTempMode"))
293 if (params.
exists(
"EV1_emittedMode"))
296 if (params.
exists(
"EV1_pTdefMode"))
299 if (params.
exists(
"EV1_MPIvetoOn"))
302 if (params.
exists(
"EV1_QEDvetoMode"))
305 if (params.
exists(
"EV1_nFinalMode"))
321 if (params.
exists(
"UserCustomization")) {
322 const std::vector<edm::ParameterSet> userParams =
323 params.
getParameter<std::vector<edm::ParameterSet>>(
"UserCustomization");
324 for (
const auto &pluginParams : userParams) {
330 if (params.
exists(
"VinciaPlugin")) {
334 if (params.
exists(
"DirePlugin")) {
336 fDire.reset(
new Pythia8::Dire());
345 bool status =
false, status1 =
false;
354 fMasterGen->settings.mode(
"Beams:idB", -2212);
361 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
365 fMasterGen->settings.mode(
"Beams:frameType", 4);
382 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
386 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
389 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 390 "are : jetMatching, emissionVeto1 \n";
394 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
398 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
400 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
405 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
407 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) {
426 if (internalMerging) {
427 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree") ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt"))
429 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
430 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
431 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
432 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
435 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
439 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
440 if (biasedTauDecayer) {
446 std::vector<int> handledParticles;
447 handledParticles.push_back(15);
451 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
452 if (resonanceDecayFilter) {
457 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
464 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hooks";
474 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
478 }
else if (
fDire.get()) {
480 fDire->weightsPtr->setup();
501 fDecayer->settings.flag(
"ProcessLevel:all",
false);
502 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
503 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
507 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
513 return (status && status1);
517 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
519 bool status =
false, status1 =
false;
534 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
539 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hooks";
545 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
548 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 549 "are : jetMatching, emissionVeto1 \n";
553 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
557 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
559 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
564 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
566 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) {
585 if (internalMerging) {
586 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree") ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt"))
588 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
589 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
590 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
591 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
594 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
598 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
599 if (biasedTauDecayer) {
605 std::vector<int> handledParticles;
606 handledParticles.push_back(15);
610 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
611 if (resonanceDecayFilter) {
616 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
628 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
629 fMasterGen->settings.mode(
"Beams:frameType", 4);
635 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
642 fMasterGen->settings.mode(
"Beams:frameType", 5);
644 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
661 fDecayer->settings.flag(
"ProcessLevel:all",
false);
662 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
663 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
667 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
673 return (status && status1);
681 <<
"Number of ISR vetoed = " <<
nISRveto;
705 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
720 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
721 DJR.push_back(djrmatch[idjr]);
739 if (mergeweight != 1.) {
740 event()->weights()[0] *= mergeweight;
749 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
750 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
751 double wgt = (*
fMasterGen->info.weights_detailed)[key];
752 event()->weights().push_back(wgt);
754 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
755 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
756 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
757 event()->weights().push_back(wgt);
766 event()->weights().push_back(wgt);
774 for (
int iVar = 1; iVar <
fvincia->nWeights(); iVar++) {
781 fDire->weightsPtr->calcWeight(0.);
782 fDire->weightsPtr->reset();
785 event()->weights()[0] *=
fDire->weightsPtr->getShowerWeight(
"base");
787 map<string, double>::iterator it;
788 for (it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end();
790 if (it->first ==
"base")
792 event()->weights().push_back(it->second);
813 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
819 if (!py8next ||
std::abs(mergeweight) == 0.) {
829 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
830 DJR.push_back(djrmatch[idjr]);
851 if (mergeweight != 1.) {
852 event()->weights()[0] *= mergeweight;
865 event()->weights().push_back(wgt);
875 int NPartsBeforeDecays = pythiaEvent->size();
876 int NPartsAfterDecays =
event().get()->particles_size();
878 if (NPartsAfterDecays == NPartsBeforeDecays)
883 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
886 if (part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id())) {
896 part->momentum().x(),
897 part->momentum().y(),
898 part->momentum().z(),
899 part->momentum().t(),
900 part->generated_mass());
901 HepMC::GenVertex *ProdVtx = part->production_vertex();
902 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
903 py8part.tau((
fDecayer->particleData).tau0(part->pdg_id()));
905 int nentries =
fDecayer->event.size();
906 if (!
fDecayer->event[nentries - 1].mayDecay())
909 int nentries1 =
fDecayer->event.size();
910 if (nentries1 <= nentries)
951 <<
"----------------------" << std::endl;
956 <<
"----------------------" << std::endl;
972 int weights_number =
fMasterGen->info.nWeights();
974 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
975 if (weights_number > 1) {
984 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
985 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
986 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
987 weightgroupname = wgtgrp.first;
991 std::ostringstream weightname;
992 weightname <<
"LHE, id = " << key <<
", ";
993 if (!weightgroupname.empty()) {
994 weightname <<
"group = " << weightgroupname <<
", ";
996 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
1013 for (
int iVar = 0; iVar <
fvincia->nWeights(); iVar++) {
1022 map<string, double>::iterator it;
1023 for (it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end();
1025 if (it->first ==
"base")
std::unique_ptr< UserHooks > fReweightPtHatRapUserHook
edm::ConcurrentGeneratorFilter< Pythia8Hadronizer, ConcurrentExternalDecayDriver > Pythia8ConcurrentGeneratorFilter
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual bool residualDecay()
double comEnergy
Center-of-Mass energy.
std::unique_ptr< Pythia8::Pythia > fDecayer
edm::GeneratorFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8GeneratorFilter
bool initializeForInternalPartons() override
def create(alignables, pedeDump, additionalData, outputFile, config)
std::shared_ptr< EvtGenDecays > evtgenDecays
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
std::unique_ptr< EmissionVetoHook1 > fEmissionVetoHook1
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
std::unique_ptr< BiasedTauDecayer > fBiasedTauDecayer
std::unique_ptr< Pythia8::amcnlo_unitarised_interface > fMergingHook
bool pythiaHepMCVerbosityParticles
void setInternalXSec(const XSec &xsec)
std::unique_ptr< MultiUserHook > fCustomHooksVector
std::vector< std::string > evtgenUserFiles
std::unique_ptr< JetMatchingHook > fJetMatchingHook
edm::ConcurrentHadronizerFilter< Pythia8Hadronizer, ConcurrentExternalDecayDriver > Pythia8ConcurrentHadronizerFilter
const char * classname() const override
GenRunInfoProduct & runInfo()
#define DEFINE_FWK_MODULE(type)
lhef::LHEEvent * lheEvent()
std::unique_ptr< PowhegHooksBB4L > fPowhegHooksBB4L
std::unique_ptr< PowhegResHook > fPowhegResHook
std::unique_ptr< Pythia8::JetMatchingMadgraph > fJetMatchingPy8InternalHook
std::unique_ptr< PowhegHooks > fEmissionVetoHook
static const std::vector< std::string > p8SharedResources
Abs< T >::type abs(const T &t)
unsigned int pythiaPylistVerbosity
std::unique_ptr< GenLumiInfoHeader > getGenLumiInfoHeader() const override
std::unique_ptr< HepMC::GenEvent > & event()
std::vector< std::string > const & doSharedResources() const override
lhef::LHERunInfo * lheRunInfo()
bool generatePartonsAndHadronize() override
std::unique_ptr< LHAupLesHouches > lhaUP
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
std::unique_ptr< UserHooks > fReweightRapUserHook
std::unique_ptr< UserHooks > fReweightUserHook
std::string evtgenPdlFile
std::unique_ptr< GenEventInfoProduct > & eventInfo()
unsigned int maxEventsToPrint
def remove(d, key, TELL=False)
std::unique_ptr< UserHooks > fReweightEmpUserHook
Pythia8Hadronizer(const edm::ParameterSet ¶ms)
bool pythiaHepMCVerbosity
std::string evtgenDecFile
std::unique_ptr< ResonanceDecayFilterHook > fResonanceDecayFilterHook
std::unique_ptr< MultiUserHook > fMultiUserHook
HepMC::Pythia8ToHepMC toHepMC
std::unique_ptr< PTFilterHook > fPTFilterHook
std::unique_ptr< Pythia8::Pythia > fMasterGen
static const std::string kPythia8
void finalizeEvent() override
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter
T get(const Candidate &c)
std::unique_ptr< Pythia8::Dire > fDire
std::unique_ptr< Vincia::VinciaPlugin > fvincia
~Pythia8Hadronizer() override