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" 26 #include "Pythia8Plugins/JetMatching.h" 27 #include "Pythia8Plugins/aMCatNLOHooks.h" 33 #include "Pythia8Plugins/PowhegHooks.h" 51 #include "Pythia8Plugins/EvtGen.h" 68 #include "HepPID/ParticleIDTranslations.hh" 74 class HepRandomEngine;
84 bool initializeForInternalPartons()
override;
85 bool initializeForExternalPartons();
87 bool generatePartonsAndHadronize()
override;
90 virtual bool residualDecay();
92 void finalizeEvent()
override;
96 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
98 std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader()
const override;
101 std::unique_ptr<Vincia::VinciaPlugin>
fvincia;
102 std::unique_ptr<Pythia8::Dire>
fDire;
105 std::vector<std::string>
const &
doSharedResources()
const override {
return p8SharedResources; }
111 std::unique_ptr<LHAupLesHouches>
lhaUP;
113 enum { PP,
PPbar, ElectronPositron };
178 comEnergy(params.getParameter<double>(
"comEnergy")),
179 LHEInputFileName(params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
187 if (params.
exists(
"PPbarInitialState")) {
191 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 192 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
196 }
else if (params.
exists(
"ElectronPositronInitialState")) {
200 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 201 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
205 }
else if (params.
exists(
"ElectronProtonInitialState") || params.
exists(
"PositronProtonInitialState")) {
208 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
213 if (params.
exists(
"reweightGen")) {
214 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
218 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
220 if (params.
exists(
"reweightGenEmp")) {
221 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
225 if (rgeParams.
exists(
"tune"))
228 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
230 if (params.
exists(
"reweightGenRap")) {
231 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
239 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
241 if (params.
exists(
"reweightGenPtHatRap")) {
242 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
250 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
253 if (params.
exists(
"useUserHook"))
255 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
259 if (params.
exists(
"jetMatching")) {
262 if (scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet") {
269 if (params.
exists(
"emissionVeto1")) {
271 if (params.
exists(
"EV1_nFinal"))
274 if (params.
exists(
"EV1_vetoOn"))
277 if (params.
exists(
"EV1_maxVetoCount"))
280 if (params.
exists(
"EV1_pThardMode"))
283 if (params.
exists(
"EV1_pTempMode"))
288 if (params.
exists(
"EV1_emittedMode"))
291 if (params.
exists(
"EV1_pTdefMode"))
294 if (params.
exists(
"EV1_MPIvetoOn"))
297 if (params.
exists(
"EV1_QEDvetoMode"))
300 if (params.
exists(
"EV1_nFinalMode"))
315 if (params.
exists(
"VinciaPlugin")) {
319 if (params.
exists(
"DirePlugin")) {
321 fDire.reset(
new Pythia8::Dire());
330 bool status =
false, status1 =
false;
339 fMasterGen->settings.mode(
"Beams:idB", -2212);
346 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
350 fMasterGen->settings.mode(
"Beams:frameType", 4);
367 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
371 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
374 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 375 "are : jetMatching, emissionVeto1 \n";
379 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
383 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
385 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
390 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
392 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
398 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
399 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
401 if (internalMatching && internalMerging) {
403 <<
" Only one jet matching/merging scheme can be used at a time. \n";
406 if (internalMatching) {
411 if (internalMerging) {
412 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree") ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt"))
414 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
415 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
416 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
417 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
420 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
424 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
425 if (biasedTauDecayer) {
431 std::vector<int> handledParticles;
432 handledParticles.push_back(15);
436 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
437 if (resonanceDecayFilter) {
442 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
452 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
456 }
else if (
fDire.get()) {
458 fDire->weightsPtr->setup();
479 fDecayer->settings.flag(
"ProcessLevel:all",
false);
480 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
481 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
485 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
491 return (status && status1);
495 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
497 bool status =
false, status1 =
false;
512 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
516 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
519 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 520 "are : jetMatching, emissionVeto1 \n";
524 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
528 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
530 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
535 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
537 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
543 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
544 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
546 if (internalMatching && internalMerging) {
548 <<
" Only one jet matching/merging scheme can be used at a time. \n";
551 if (internalMatching) {
556 if (internalMerging) {
557 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree") ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt"))
559 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
560 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
561 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
562 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
565 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
569 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
570 if (biasedTauDecayer) {
576 std::vector<int> handledParticles;
577 handledParticles.push_back(15);
581 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
582 if (resonanceDecayFilter) {
587 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
599 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
600 fMasterGen->settings.mode(
"Beams:frameType", 4);
606 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
613 fMasterGen->settings.mode(
"Beams:frameType", 5);
615 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
632 fDecayer->settings.flag(
"ProcessLevel:all",
false);
633 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
634 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
638 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
644 return (status && status1);
652 <<
"Number of ISR vetoed = " <<
nISRveto;
676 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
691 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
692 DJR.push_back(djrmatch[idjr]);
710 if (mergeweight != 1.) {
711 event()->weights()[0] *= mergeweight;
720 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
721 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
722 double wgt = (*
fMasterGen->info.weights_detailed)[key];
723 event()->weights().push_back(wgt);
725 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
726 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
727 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
728 event()->weights().push_back(wgt);
737 event()->weights().push_back(wgt);
745 for (
int iVar = 1; iVar <
fvincia->nWeights(); iVar++) {
752 fDire->weightsPtr->calcWeight(0.);
753 fDire->weightsPtr->reset();
756 event()->weights()[0] *=
fDire->weightsPtr->getShowerWeight(
"base");
758 map<string, double>::iterator it;
759 for (it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end();
761 if (it->first ==
"base")
763 event()->weights().push_back(it->second);
784 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
790 if (!py8next ||
std::abs(mergeweight) == 0.) {
800 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
801 DJR.push_back(djrmatch[idjr]);
822 if (mergeweight != 1.) {
823 event()->weights()[0] *= mergeweight;
836 event()->weights().push_back(wgt);
846 int NPartsBeforeDecays = pythiaEvent->size();
847 int NPartsAfterDecays =
event().get()->particles_size();
849 if (NPartsAfterDecays == NPartsBeforeDecays)
854 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
857 if (part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id())) {
867 part->momentum().x(),
868 part->momentum().y(),
869 part->momentum().z(),
870 part->momentum().t(),
871 part->generated_mass());
872 HepMC::GenVertex *ProdVtx = part->production_vertex();
873 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
874 py8part.tau((
fDecayer->particleData).tau0(part->pdg_id()));
876 int nentries =
fDecayer->event.size();
877 if (!
fDecayer->event[nentries - 1].mayDecay())
880 int nentries1 =
fDecayer->event.size();
881 if (nentries1 <= nentries)
922 <<
"----------------------" << std::endl;
927 <<
"----------------------" << std::endl;
943 int weights_number =
fMasterGen->info.nWeights();
945 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
946 if (weights_number > 1) {
955 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
956 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
957 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
958 weightgroupname = wgtgrp.first;
962 std::ostringstream weightname;
963 weightname <<
"LHE, id = " << key <<
", ";
964 if (!weightgroupname.empty()) {
965 weightname <<
"group = " << weightgroupname <<
", ";
967 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
984 for (
int iVar = 0; iVar <
fvincia->nWeights(); iVar++) {
993 map<string, double>::iterator it;
994 for (it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end();
996 if (it->first ==
"base")
std::unique_ptr< UserHooks > fReweightPtHatRapUserHook
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
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::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
std::unique_ptr< Pythia8::Dire > fDire
std::unique_ptr< Vincia::VinciaPlugin > fvincia
~Pythia8Hadronizer() override