9 #include "HepMC3/GenEvent.h" 10 #include "HepMC3/GenParticle.h" 11 #include "HepMC3/Print.h" 13 #include "Pythia8/Pythia.h" 14 #include "Pythia8Plugins/HepMC3.h" 26 #include "Pythia8Plugins/JetMatching.h" 27 #include "Pythia8Plugins/aMCatNLOHooks.h" 31 #include "Pythia8Plugins/PowhegHooks.h" 49 #include "Pythia8Plugins/EvtGen.h" 67 #include "HepPID/ParticleIDTranslations.hh" 73 class HepRandomEngine;
83 bool initializeForInternalPartons()
override;
84 bool initializeForExternalPartons();
86 bool generatePartonsAndHadronize()
override;
89 virtual bool residualDecay();
91 void finalizeEvent()
override;
95 const char *
classname()
const override {
return "Pythia8HepMC3Hadronizer"; }
97 std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader()
const override;
101 std::vector<std::string>
const &
doSharedResources()
const override {
return p8SharedResources; }
107 std::shared_ptr<LHAupLesHouches>
lhaUP;
109 enum { PP,
PPbar, ElectronPositron };
179 LHEInputFileName(
params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
189 if (
params.exists(
"PPbarInitialState")) {
193 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 194 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
198 }
else if (
params.exists(
"ElectronPositronInitialState")) {
202 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 203 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
207 }
else if (
params.exists(
"ElectronProtonInitialState") ||
params.exists(
"PositronProtonInitialState")) {
210 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
214 toHepMC.set_store_weights(
false);
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"))
320 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) {
331 if (
params.exists(
"VinciaPlugin")) {
333 <<
" Obsolete parameter: VinciaPlugin \n Please use the parameter PartonShowers:model instead \n";
335 if (
params.exists(
"DirePlugin")) {
337 <<
" Obsolete parameter: DirePlugin \n Please use the parameter PartonShowers:model instead \n";
342 bool status =
false, status1 =
false;
351 fMasterGen->settings.mode(
"Beams:idB", -2212);
358 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
362 fMasterGen->settings.mode(
"Beams:frameType", 4);
381 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
385 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
388 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 389 "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";
406 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
408 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
415 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
416 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
418 if (internalMatching && internalMerging) {
420 <<
" Only one jet matching/merging scheme can be used at a time. \n";
423 if (internalMatching) {
429 if (internalMerging) {
432 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
433 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
434 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
435 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
443 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
444 if (biasedTauDecayer) {
449 std::vector<int> handledParticles;
450 handledParticles.push_back(15);
454 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
455 if (resonanceDecayFilter) {
460 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
474 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hooks";
480 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
496 fDecayer->settings.flag(
"ProcessLevel:all",
false);
497 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
498 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
502 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
510 return (
status && status1);
514 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
516 bool status =
false, status1 =
false;
533 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
538 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hook";
544 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
547 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 548 "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";
565 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
567 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
574 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
575 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
577 if (internalMatching && internalMerging) {
579 <<
" Only one jet matching/merging scheme can be used at a time. \n";
582 if (internalMatching) {
588 if (internalMerging) {
591 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
592 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
593 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
594 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
602 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
603 if (biasedTauDecayer) {
608 std::vector<int> handledParticles;
609 handledParticles.push_back(15);
613 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
614 if (resonanceDecayFilter) {
619 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
634 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
635 fMasterGen->settings.mode(
"Beams:frameType", 4);
641 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
648 fMasterGen->settings.mode(
"Beams:frameType", 5);
650 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
667 fDecayer->settings.flag(
"ProcessLevel:all",
false);
668 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
669 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
673 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
681 return (
status && status1);
689 <<
"Number of ISR vetoed = " <<
nISRveto;
713 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
728 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
729 DJR.push_back(djrmatch[idjr]);
740 event3() = std::make_unique<HepMC3::GenEvent>();
751 if (mergeweight != 1.) {
752 event3()->weights()[0] *= mergeweight;
761 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
762 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
764 event3()->weights().push_back(wgt);
766 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
767 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
768 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
769 event3()->weights().push_back(wgt);
778 event3()->weights().push_back(wgt);
786 event()->weights()[0] *= fvincia->weight(0);
787 for (
int iVar = 1; iVar < fvincia->nWeights(); iVar++) {
788 event()->weights().push_back(fvincia->weight(iVar));
794 fDire->weightsPtr->calcWeight(0.);
795 fDire->weightsPtr->reset();
798 event()->weights()[0] *= fDire->weightsPtr->getShowerWeight(
"base");
800 unordered_map<string, double>::iterator
it;
801 for (
it = fDire->weightsPtr->getShowerWeights()->begin();
it != fDire->weightsPtr->getShowerWeights()->end();
803 if (
it->first ==
"base")
805 event()->weights().push_back(
it->second);
827 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
833 if (!py8next ||
std::abs(mergeweight) == 0.) {
843 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
844 DJR.push_back(djrmatch[idjr]);
858 event() = std::make_unique<HepMC::GenEvent>();
859 event3() = std::make_unique<HepMC3::GenEvent>();
870 if (mergeweight != 1.) {
871 event3()->weights()[0] *= mergeweight;
884 event3()->weights().push_back(wgt);
894 int NPartsBeforeDecays = pythiaEvent->size() - 1;
899 int NPartsAfterDecays = 0;
904 if (NPartsAfterDecays == NPartsBeforeDecays)
911 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
914 if (
part->status() == 1 && (
fDecayer->particleData).canDecay(
part->pdg_id())) {
924 part->momentum().x(),
925 part->momentum().y(),
926 part->momentum().z(),
927 part->momentum().t(),
928 part->generated_mass());
929 HepMC::GenVertex *ProdVtx =
part->production_vertex();
930 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
931 py8part.tau((
fDecayer->particleData).tau0(
part->pdg_id()));
933 int nentries =
fDecayer->event.size();
934 if (!
fDecayer->event[nentries - 1].mayDecay())
937 int nentries1 =
fDecayer->event.size();
938 if (nentries1 <= nentries)
984 <<
"----------------------" << std::endl;
986 HepMC3::Print::listing(*(
event3().
get()));
990 <<
"----------------------" << std::endl;
1009 int weights_number =
fMasterGen->info.nWeights();
1011 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
1012 if (weights_number > 1) {
1021 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
1022 const auto &wgtgrpwgt = wgtgrp.second.weights.find(
key);
1023 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
1024 weightgroupname = wgtgrp.first;
1028 std::ostringstream weightname;
1029 weightname <<
"LHE, id = " <<
key <<
", ";
1030 if (!weightgroupname.empty()) {
1031 weightname <<
"group = " << weightgroupname <<
", ";
1033 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
1050 if (fvincia.get()) {
1051 for (
int iVar = 0; iVar < fvincia->nWeights(); iVar++) {
1060 unordered_map<string, double>::iterator
it;
1061 for (
it = fDire->weightsPtr->getShowerWeights()->begin();
it != fDire->weightsPtr->getShowerWeights()->end();
1063 if (
it->first ==
"base")
T getParameter(std::string const &) const
std::string LHEInputFileName
std::shared_ptr< JetMatchingHook > fJetMatchingHook
std::shared_ptr< Pythia8::JetMatchingMadgraph > fJetMatchingPy8InternalHook
std::shared_ptr< UserHooks > fReweightUserHook
HepMC3::Pythia8ToHepMC3 toHepMC
std::shared_ptr< PTFilterHook > fPTFilterHook
std::shared_ptr< UserHooks > fReweightRapUserHook
std::vector< std::string > const & doSharedResources() const override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::unique_ptr< Pythia8::Pythia > fDecayer
std::shared_ptr< PowhegHooks > fEmissionVetoHook
std::shared_ptr< LHAupLesHouches > lhaUP
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
std::shared_ptr< EmissionVetoHook1 > fEmissionVetoHook1
edm::ConcurrentHadronizerFilter< Pythia8HepMC3Hadronizer, ConcurrentExternalDecayDriver > Pythia8HepMC3ConcurrentHadronizerFilter
void setInternalXSec(const XSec &xsec)
std::shared_ptr< Pythia8::amcnlo_unitarised_interface > fMergingHook
edm::GeneratorFilter< Pythia8HepMC3Hadronizer, ExternalDecayDriver > Pythia8HepMC3GeneratorFilter
const char * classname() const override
GenRunInfoProduct & runInfo()
Pythia8HepMC3Hadronizer(const edm::ParameterSet ¶ms)
bool initializeForExternalPartons()
unsigned int maxEventsToPrint
lhef::LHEEvent * lheEvent()
std::string evtgenDecFile
std::shared_ptr< UserHooks > fReweightEmpUserHook
std::shared_ptr< PowhegResHook > fPowhegResHook
std::shared_ptr< PowhegHooksBB4L > fPowhegHooksBB4L
Abs< T >::type abs(const T &t)
std::shared_ptr< UserHooksVector > fUserHooksVector
Log< level::Error, true > LogImportant
key
prepare the HTCondor submission files and eventually submit them
#define DEFINE_FWK_MODULE(type)
std::unique_ptr< GenEventInfoProduct3 > & eventInfo3()
std::unique_ptr< HepMC::GenEvent > & event()
Log< level::Warning, true > LogPrint
edm::ConcurrentGeneratorFilter< Pythia8HepMC3Hadronizer, ConcurrentExternalDecayDriver > Pythia8HepMC3ConcurrentGeneratorFilter
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
bool initializeForInternalPartons() override
lhef::LHERunInfo * lheRunInfo()
unsigned int pythiaPylistVerbosity
std::shared_ptr< BiasedTauDecayer > fBiasedTauDecayer
bool pythiaHepMCVerbosity
Log< level::Info, false > LogInfo
std::unique_ptr< Pythia8::Pythia > fMasterGen
edm::HadronizerFilter< Pythia8HepMC3Hadronizer, ExternalDecayDriver > Pythia8HepMC3HadronizerFilter
std::shared_ptr< UserHooks > fReweightPtHatRapUserHook
std::unique_ptr< HepMC3::GenEvent > & event3()
def remove(d, key, TELL=False)
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
std::unique_ptr< GenLumiInfoHeader > getGenLumiInfoHeader() const override
double comEnergy
Center-of-Mass energy.
std::shared_ptr< Pythia8::EvtGenDecays > evtgenDecays
virtual bool residualDecay()
std::vector< std::string > evtgenUserFiles
void finalizeEvent() override
static const std::string kPythia8
std::shared_ptr< ResonanceDecayFilterHook > fResonanceDecayFilterHook
std::string evtgenPdlFile
bool pythiaHepMCVerbosityParticles
void statistics() override
bool generatePartonsAndHadronize() override
static const std::vector< std::string > p8SharedResources
std::shared_ptr< UserHooksVector > fCustomHooksVector