10 #include "HepMC/GenEvent.h" 11 #include "HepMC/GenParticle.h" 13 #include "Pythia8/Pythia.h" 14 #include "Pythia8Plugins/HepMC2.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 "Pythia8Hadronizer"; }
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";
344 bool status =
false, status1 =
false;
353 fMasterGen->settings.mode(
"Beams:idB", -2212);
360 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
364 fMasterGen->settings.mode(
"Beams:frameType", 4);
383 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
387 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
390 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 391 "are : jetMatching, emissionVeto1 \n";
396 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
400 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
402 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
408 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
410 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
417 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
418 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
420 if (internalMatching && internalMerging) {
422 <<
" Only one jet matching/merging scheme can be used at a time. \n";
425 if (internalMatching) {
431 if (internalMerging) {
434 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
435 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
436 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
437 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
445 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
446 if (biasedTauDecayer) {
451 std::vector<int> handledParticles;
452 handledParticles.push_back(15);
456 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
457 if (resonanceDecayFilter) {
462 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
476 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hooks";
482 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
498 fDecayer->settings.flag(
"ProcessLevel:all",
false);
499 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
500 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
504 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
512 return (
status && status1);
516 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
518 bool status =
false, status1 =
false;
535 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
540 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hook";
546 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
549 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 550 "are : jetMatching, emissionVeto1 \n";
555 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
559 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
561 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
567 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
569 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
576 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
577 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
579 if (internalMatching && internalMerging) {
581 <<
" Only one jet matching/merging scheme can be used at a time. \n";
584 if (internalMatching) {
590 if (internalMerging) {
593 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
594 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
595 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
596 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
604 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
605 if (biasedTauDecayer) {
610 std::vector<int> handledParticles;
611 handledParticles.push_back(15);
615 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
616 if (resonanceDecayFilter) {
621 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
636 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
637 fMasterGen->settings.mode(
"Beams:frameType", 4);
643 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
650 fMasterGen->settings.mode(
"Beams:frameType", 5);
652 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
669 fDecayer->settings.flag(
"ProcessLevel:all",
false);
670 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
671 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
675 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
683 return (
status && status1);
691 <<
"Number of ISR vetoed = " <<
nISRveto;
715 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
730 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
731 DJR.push_back(djrmatch[idjr]);
741 event() = std::make_unique<HepMC::GenEvent>();
752 if (mergeweight != 1.) {
753 event()->weights()[0] *= mergeweight;
762 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
763 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
765 event()->weights().push_back(wgt);
767 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
768 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
769 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
770 event()->weights().push_back(wgt);
779 event()->weights().push_back(wgt);
787 event()->weights()[0] *= fvincia->weight(0);
788 for (
int iVar = 1; iVar < fvincia->nWeights(); iVar++) {
789 event()->weights().push_back(fvincia->weight(iVar));
795 fDire->weightsPtr->calcWeight(0.);
796 fDire->weightsPtr->reset();
799 event()->weights()[0] *= fDire->weightsPtr->getShowerWeight(
"base");
801 unordered_map<string, double>::iterator it;
802 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
804 if (it->first ==
"base")
806 event()->weights().push_back(it->second);
828 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
834 if (!py8next ||
std::abs(mergeweight) == 0.) {
844 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
845 DJR.push_back(djrmatch[idjr]);
859 event() = std::make_unique<HepMC::GenEvent>();
871 if (mergeweight != 1.) {
872 event()->weights()[0] *= mergeweight;
885 event()->weights().push_back(wgt);
895 int NPartsBeforeDecays = pythiaEvent->size();
896 int NPartsAfterDecays =
event().get()->particles_size();
898 if (NPartsAfterDecays == NPartsBeforeDecays)
903 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
906 if (
part->status() == 1 && (
fDecayer->particleData).canDecay(
part->pdg_id())) {
916 part->momentum().x(),
917 part->momentum().y(),
918 part->momentum().z(),
919 part->momentum().t(),
920 part->generated_mass());
921 HepMC::GenVertex *ProdVtx =
part->production_vertex();
922 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
923 py8part.tau((
fDecayer->particleData).tau0(
part->pdg_id()));
925 int nentries =
fDecayer->event.size();
926 if (!
fDecayer->event[nentries - 1].mayDecay())
929 int nentries1 =
fDecayer->event.size();
930 if (nentries1 <= nentries)
951 eventInfo() = std::make_unique<GenEventInfoProduct>(
event().get());
975 <<
"----------------------" << std::endl;
980 <<
"----------------------" << std::endl;
996 int weights_number =
fMasterGen->info.nWeights();
998 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
999 if (weights_number > 1) {
1008 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
1009 const auto &wgtgrpwgt = wgtgrp.second.weights.find(
key);
1010 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
1011 weightgroupname = wgtgrp.first;
1015 std::ostringstream weightname;
1016 weightname <<
"LHE, id = " <<
key <<
", ";
1017 if (!weightgroupname.empty()) {
1018 weightname <<
"group = " << weightgroupname <<
", ";
1020 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
1037 if (fvincia.get()) {
1038 for (
int iVar = 0; iVar < fvincia->nWeights(); iVar++) {
1047 unordered_map<string, double>::iterator it;
1048 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
1050 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
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
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()
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
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