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" 28 #include "Pythia8Plugins/JetMatching.h" 29 #include "Pythia8Plugins/aMCatNLOHooks.h" 35 #include "Pythia8Plugins/PowhegHooks.h" 53 #include "Pythia8Plugins/EvtGen.h" 71 #include "HepPID/ParticleIDTranslations.hh" 77 class HepRandomEngine;
87 bool initializeForInternalPartons()
override;
88 bool initializeForExternalPartons();
90 bool generatePartonsAndHadronize()
override;
93 virtual bool residualDecay();
95 void finalizeEvent()
override;
99 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
101 std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader()
const override;
104 std::unique_ptr<Vincia::VinciaPlugin>
fvincia;
105 std::unique_ptr<Pythia8::Dire>
fDire;
108 std::vector<std::string>
const &
doSharedResources()
const override {
return p8SharedResources; }
114 std::unique_ptr<LHAupLesHouches>
lhaUP;
116 enum { PP,
PPbar, ElectronPositron };
187 comEnergy(params.getParameter<double>(
"comEnergy")),
188 LHEInputFileName(params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
196 if (params.
exists(
"PPbarInitialState")) {
200 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 201 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
205 }
else if (params.
exists(
"ElectronPositronInitialState")) {
209 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 210 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
214 }
else if (params.
exists(
"ElectronProtonInitialState") || params.
exists(
"PositronProtonInitialState")) {
217 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
222 if (params.
exists(
"reweightGen")) {
223 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
227 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
229 if (params.
exists(
"reweightGenEmp")) {
230 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
234 if (rgeParams.
exists(
"tune"))
237 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
239 if (params.
exists(
"reweightGenRap")) {
240 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
248 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
250 if (params.
exists(
"reweightGenPtHatRap")) {
251 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
259 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
262 if (params.
exists(
"useUserHook"))
264 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
268 if (params.
exists(
"jetMatching")) {
271 if (scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet") {
278 if (params.
exists(
"emissionVeto1")) {
280 if (params.
exists(
"EV1_nFinal"))
283 if (params.
exists(
"EV1_vetoOn"))
286 if (params.
exists(
"EV1_maxVetoCount"))
289 if (params.
exists(
"EV1_pThardMode"))
292 if (params.
exists(
"EV1_pTempMode"))
297 if (params.
exists(
"EV1_emittedMode"))
300 if (params.
exists(
"EV1_pTdefMode"))
303 if (params.
exists(
"EV1_MPIvetoOn"))
306 if (params.
exists(
"EV1_QEDvetoMode"))
309 if (params.
exists(
"EV1_nFinalMode"))
325 if (params.
exists(
"UserCustomization")) {
326 const std::vector<edm::ParameterSet> userParams =
327 params.
getParameter<std::vector<edm::ParameterSet>>(
"UserCustomization");
328 for (
const auto &pluginParams : userParams) {
334 if (params.
exists(
"VinciaPlugin")) {
338 if (params.
exists(
"DirePlugin")) {
340 fDire.reset(
new Pythia8::Dire());
349 bool status =
false, status1 =
false;
358 fMasterGen->settings.mode(
"Beams:idB", -2212);
365 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
369 fMasterGen->settings.mode(
"Beams:frameType", 4);
386 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
390 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
393 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 394 "are : jetMatching, emissionVeto1 \n";
398 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
402 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
404 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
409 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
411 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
416 bool TopRecoilHook1 =
fMasterGen->settings.flag(
"TopRecoilHook:doTopRecoilIn");
417 if (TopRecoilHook1) {
418 edm::LogInfo(
"Pythia8Interface") <<
"Turning on RecoilToTop hook from Pythia8Interface";
425 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
426 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
428 if (internalMatching && internalMerging) {
430 <<
" Only one jet matching/merging scheme can be used at a time. \n";
433 if (internalMatching) {
438 if (internalMerging) {
439 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree") ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt"))
441 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
442 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
443 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
444 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
447 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
451 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
452 if (biasedTauDecayer) {
458 std::vector<int> handledParticles;
459 handledParticles.push_back(15);
463 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
464 if (resonanceDecayFilter) {
469 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
476 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hooks";
486 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
490 }
else if (
fDire.get()) {
492 fDire->weightsPtr->setup();
513 fDecayer->settings.flag(
"ProcessLevel:all",
false);
514 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
515 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
519 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
525 return (status && status1);
529 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
531 bool status =
false, status1 =
false;
546 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
551 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hooks";
557 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
560 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 561 "are : jetMatching, emissionVeto1 \n";
565 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
569 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
571 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
576 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
578 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
583 bool TopRecoilHook1 =
fMasterGen->settings.flag(
"TopRecoilHook:doTopRecoilIn");
584 if (TopRecoilHook1) {
585 edm::LogInfo(
"Pythia8Interface") <<
"Turning on RecoilToTop hook from Pythia8Interface";
592 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
593 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
595 if (internalMatching && internalMerging) {
597 <<
" Only one jet matching/merging scheme can be used at a time. \n";
600 if (internalMatching) {
605 if (internalMerging) {
606 int scheme = (
fMasterGen->settings.flag(
"Merging:doUMEPSTree") ||
fMasterGen->settings.flag(
"Merging:doUMEPSSubt"))
608 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
609 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
610 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
611 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
614 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
618 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
619 if (biasedTauDecayer) {
625 std::vector<int> handledParticles;
626 handledParticles.push_back(15);
630 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
631 if (resonanceDecayFilter) {
636 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
648 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
649 fMasterGen->settings.mode(
"Beams:frameType", 4);
655 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
662 fMasterGen->settings.mode(
"Beams:frameType", 5);
664 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
681 fDecayer->settings.flag(
"ProcessLevel:all",
false);
682 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
683 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
687 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
693 return (status && status1);
701 <<
"Number of ISR vetoed = " <<
nISRveto;
725 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
740 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
741 DJR.push_back(djrmatch[idjr]);
759 if (mergeweight != 1.) {
760 event()->weights()[0] *= mergeweight;
769 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
770 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
771 double wgt = (*
fMasterGen->info.weights_detailed)[key];
772 event()->weights().push_back(wgt);
774 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
775 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
776 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
777 event()->weights().push_back(wgt);
786 event()->weights().push_back(wgt);
794 for (
int iVar = 1; iVar <
fvincia->nWeights(); iVar++) {
801 fDire->weightsPtr->calcWeight(0.);
802 fDire->weightsPtr->reset();
805 event()->weights()[0] *=
fDire->weightsPtr->getShowerWeight(
"base");
807 map<string, double>::iterator it;
808 for (it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end();
810 if (it->first ==
"base")
812 event()->weights().push_back(it->second);
833 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
839 if (!py8next ||
std::abs(mergeweight) == 0.) {
849 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
850 DJR.push_back(djrmatch[idjr]);
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)
971 <<
"----------------------" << std::endl;
976 <<
"----------------------" << std::endl;
992 int weights_number =
fMasterGen->info.nWeights();
994 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
995 if (weights_number > 1) {
1004 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
1005 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
1006 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
1007 weightgroupname = wgtgrp.first;
1011 std::ostringstream weightname;
1012 weightname <<
"LHE, id = " << key <<
", ";
1013 if (!weightgroupname.empty()) {
1014 weightname <<
"group = " << weightgroupname <<
", ";
1016 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
1033 for (
int iVar = 0; iVar <
fvincia->nWeights(); iVar++) {
1042 map<string, double>::iterator it;
1043 for (it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end();
1045 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< TopRecoilHook > fTopRecoilHook
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