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",
"")),
188 if (
params.exists(
"PPbarInitialState")) {
192 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 193 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
197 }
else if (
params.exists(
"ElectronPositronInitialState")) {
201 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 202 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
206 }
else if (
params.exists(
"ElectronProtonInitialState") ||
params.exists(
"PositronProtonInitialState")) {
209 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
213 toHepMC.set_store_weights(
false);
217 if (
params.exists(
"reweightGen")) {
218 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
222 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
224 if (
params.exists(
"reweightGenEmp")) {
225 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
229 if (rgeParams.
exists(
"tune"))
232 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
234 if (
params.exists(
"reweightGenRap")) {
235 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
243 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
245 if (
params.exists(
"reweightGenPtHatRap")) {
246 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
254 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
257 if (
params.exists(
"useUserHook"))
259 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
263 if (
params.exists(
"jetMatching")) {
266 if (
scheme ==
"Madgraph" ||
scheme ==
"MadgraphFastJet") {
273 if (
params.exists(
"emissionVeto1")) {
275 if (
params.exists(
"EV1_nFinal"))
278 if (
params.exists(
"EV1_vetoOn"))
281 if (
params.exists(
"EV1_maxVetoCount"))
284 if (
params.exists(
"EV1_pThardMode"))
287 if (
params.exists(
"EV1_pTempMode"))
292 if (
params.exists(
"EV1_emittedMode"))
295 if (
params.exists(
"EV1_pTdefMode"))
298 if (
params.exists(
"EV1_MPIvetoOn"))
301 if (
params.exists(
"EV1_QEDvetoMode"))
304 if (
params.exists(
"EV1_nFinalMode"))
319 if (
params.exists(
"UserCustomization")) {
321 const std::vector<edm::ParameterSet> userParams =
322 params.getParameter<std::vector<edm::ParameterSet>>(
"UserCustomization");
323 for (
const auto &pluginParams : userParams) {
330 if (
params.exists(
"VinciaPlugin")) {
332 <<
" Obsolete parameter: VinciaPlugin \n Please use the parameter PartonShowers:model instead \n";
334 if (
params.exists(
"DirePlugin")) {
336 <<
" Obsolete parameter: DirePlugin \n Please use the parameter PartonShowers:model instead \n";
343 bool status =
false, status1 =
false;
352 fMasterGen->settings.mode(
"Beams:idB", -2212);
359 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
363 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";
395 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
399 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
401 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
407 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
409 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
416 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
417 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
419 if (internalMatching && internalMerging) {
421 <<
" Only one jet matching/merging scheme can be used at a time. \n";
424 if (internalMatching) {
430 if (internalMerging) {
433 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
434 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
435 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
436 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
444 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
445 if (biasedTauDecayer) {
450 std::vector<int> handledParticles;
451 handledParticles.push_back(15);
455 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
456 if (resonanceDecayFilter) {
461 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
475 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hooks";
481 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
497 fDecayer->settings.flag(
"ProcessLevel:all",
false);
498 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
499 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
503 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
511 return (
status && status1);
515 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
517 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 hook";
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";
554 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
558 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
560 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
566 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
568 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
575 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
576 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
578 if (internalMatching && internalMerging) {
580 <<
" Only one jet matching/merging scheme can be used at a time. \n";
583 if (internalMatching) {
589 if (internalMerging) {
592 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
593 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
594 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
595 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
603 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
604 if (biasedTauDecayer) {
609 std::vector<int> handledParticles;
610 handledParticles.push_back(15);
614 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
615 if (resonanceDecayFilter) {
620 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
635 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
636 fMasterGen->settings.mode(
"Beams:frameType", 4);
642 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
649 fMasterGen->settings.mode(
"Beams:frameType", 5);
651 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
668 fDecayer->settings.flag(
"ProcessLevel:all",
false);
669 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
670 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
674 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
682 return (
status && status1);
690 <<
"Number of ISR vetoed = " <<
nISRveto;
714 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
729 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
730 DJR.push_back(djrmatch[idjr]);
740 event() = std::make_unique<HepMC::GenEvent>();
751 if (mergeweight != 1.) {
752 event()->weights()[0] *= mergeweight;
761 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
762 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
764 event()->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 event()->weights().push_back(wgt);
778 event()->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>();
870 if (mergeweight != 1.) {
871 event()->weights()[0] *= mergeweight;
884 event()->weights().push_back(wgt);
894 int NPartsBeforeDecays = pythiaEvent->size();
895 int NPartsAfterDecays =
event().get()->particles_size();
897 if (NPartsAfterDecays == NPartsBeforeDecays)
902 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
905 if (
part->status() == 1 && (
fDecayer->particleData).canDecay(
part->pdg_id())) {
915 part->momentum().x(),
916 part->momentum().y(),
917 part->momentum().z(),
918 part->momentum().t(),
919 part->generated_mass());
920 HepMC::GenVertex *ProdVtx =
part->production_vertex();
921 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
922 py8part.tau((
fDecayer->particleData).tau0(
part->pdg_id()));
924 int nentries =
fDecayer->event.size();
925 if (!
fDecayer->event[nentries - 1].mayDecay())
928 int nentries1 =
fDecayer->event.size();
929 if (nentries1 <= nentries)
950 eventInfo() = std::make_unique<GenEventInfoProduct>(
event().get());
974 <<
"----------------------" << std::endl;
979 <<
"----------------------" << std::endl;
995 int weights_number =
fMasterGen->info.nWeights();
997 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
998 if (weights_number > 1) {
1007 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
1008 const auto &wgtgrpwgt = wgtgrp.second.weights.find(
key);
1009 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
1010 weightgroupname = wgtgrp.first;
1014 std::ostringstream weightname;
1015 weightname <<
"LHE, id = " <<
key <<
", ";
1016 if (!weightgroupname.empty()) {
1017 weightname <<
"group = " << weightgroupname <<
", ";
1019 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
1036 if (fvincia.get()) {
1037 for (
int iVar = 0; iVar < fvincia->nWeights(); iVar++) {
1046 unordered_map<string, double>::iterator it;
1047 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
1049 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()
#define DEFINE_FWK_MODULE(type)
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
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
void clear(HadCaloObj &c)
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