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" 32 #include "Pythia8Plugins/PowhegHooksVincia.h" 50 #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;
102 std::vector<std::string>
const &
doSharedResources()
const override {
return p8SharedResources; }
108 std::shared_ptr<LHAupLesHouches>
lhaUP;
110 enum { PP,
PPbar, ElectronPositron };
181 LHEInputFileName(
params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
191 if (
params.exists(
"PPbarInitialState")) {
195 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 196 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
200 }
else if (
params.exists(
"ElectronPositronInitialState")) {
204 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 205 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
209 }
else if (
params.exists(
"ElectronProtonInitialState") ||
params.exists(
"PositronProtonInitialState")) {
212 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
216 toHepMC.set_store_weights(
false);
220 if (
params.exists(
"reweightGen")) {
221 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
225 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
227 if (
params.exists(
"reweightGenEmp")) {
228 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
232 if (rgeParams.
exists(
"tune"))
235 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
237 if (
params.exists(
"reweightGenRap")) {
238 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
246 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
248 if (
params.exists(
"reweightGenPtHatRap")) {
249 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
257 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
260 if (
params.exists(
"useUserHook"))
262 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
266 if (
params.exists(
"jetMatching")) {
269 if (
scheme ==
"Madgraph" ||
scheme ==
"MadgraphFastJet") {
276 if (
params.exists(
"emissionVeto1")) {
278 if (
params.exists(
"EV1_nFinal"))
281 if (
params.exists(
"EV1_vetoOn"))
284 if (
params.exists(
"EV1_maxVetoCount"))
287 if (
params.exists(
"EV1_pThardMode"))
290 if (
params.exists(
"EV1_pTempMode"))
295 if (
params.exists(
"EV1_emittedMode"))
298 if (
params.exists(
"EV1_pTdefMode"))
301 if (
params.exists(
"EV1_MPIvetoOn"))
304 if (
params.exists(
"EV1_QEDvetoMode"))
307 if (
params.exists(
"EV1_nFinalMode"))
322 if (
params.exists(
"UserCustomization")) {
324 const std::vector<edm::ParameterSet> userParams =
325 params.getParameter<std::vector<edm::ParameterSet>>(
"UserCustomization");
326 for (
const auto &pluginParams : userParams) {
333 if (
params.exists(
"VinciaPlugin")) {
335 <<
" Obsolete parameter: VinciaPlugin \n Please use the parameter PartonShowers:model instead \n";
337 if (
params.exists(
"DirePlugin")) {
339 <<
" Obsolete parameter: DirePlugin \n Please use the parameter PartonShowers:model instead \n";
346 bool status =
false, status1 =
false;
355 fMasterGen->settings.mode(
"Beams:idB", -2212);
362 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
366 fMasterGen->settings.mode(
"Beams:frameType", 4);
385 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
389 bool VinciaShower =
fMasterGen->settings.mode(
"PartonShowers:Model") == 2;
391 if ((
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) &&
395 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 396 "are : jetMatching, emissionVeto1 \n";
401 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
405 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 && VinciaShower) {
406 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Vincia Emission Veto Hook from pythia8 code";
412 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
414 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
420 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
422 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
429 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
430 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
432 if (internalMatching && internalMerging) {
434 <<
" Only one jet matching/merging scheme can be used at a time. \n";
437 if (internalMatching) {
443 if (internalMerging) {
446 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
447 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
448 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
449 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
457 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
458 if (biasedTauDecayer) {
463 std::vector<int> handledParticles;
464 handledParticles.push_back(15);
468 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
469 if (resonanceDecayFilter) {
474 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
488 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hooks";
494 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
510 fDecayer->settings.flag(
"ProcessLevel:all",
false);
511 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
512 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
516 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
524 return (
status && status1);
528 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
530 bool status =
false, status1 =
false;
547 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
552 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hook";
558 bool VinciaShower =
fMasterGen->settings.mode(
"PartonShowers:Model") == 2;
560 if ((
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) &&
564 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 565 "are : jetMatching, emissionVeto1 \n";
570 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
574 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 && VinciaShower) {
575 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Vincia Emission Veto Hook from pythia8 code";
581 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
583 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
589 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
591 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
598 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
599 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
601 if (internalMatching && internalMerging) {
603 <<
" Only one jet matching/merging scheme can be used at a time. \n";
606 if (internalMatching) {
612 if (internalMerging) {
615 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
616 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
617 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
618 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
626 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
627 if (biasedTauDecayer) {
632 std::vector<int> handledParticles;
633 handledParticles.push_back(15);
637 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
638 if (resonanceDecayFilter) {
643 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
658 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
659 fMasterGen->settings.mode(
"Beams:frameType", 4);
665 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
672 fMasterGen->settings.mode(
"Beams:frameType", 5);
674 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
691 fDecayer->settings.flag(
"ProcessLevel:all",
false);
692 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
693 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
697 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
705 return (
status && status1);
713 <<
"Number of ISR vetoed = " <<
nISRveto;
737 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
752 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
753 DJR.push_back(djrmatch[idjr]);
763 event() = std::make_unique<HepMC::GenEvent>();
774 if (mergeweight != 1.) {
775 event()->weights()[0] *= mergeweight;
784 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
785 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
787 event()->weights().push_back(wgt);
789 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
790 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
791 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
792 event()->weights().push_back(wgt);
801 event()->weights().push_back(wgt);
809 event()->weights()[0] *= fvincia->weight(0);
810 for (
int iVar = 1; iVar < fvincia->nWeights(); iVar++) {
811 event()->weights().push_back(fvincia->weight(iVar));
817 fDire->weightsPtr->calcWeight(0.);
818 fDire->weightsPtr->reset();
821 event()->weights()[0] *= fDire->weightsPtr->getShowerWeight(
"base");
823 unordered_map<string, double>::iterator it;
824 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
826 if (it->first ==
"base")
828 event()->weights().push_back(it->second);
850 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
856 if (!py8next ||
std::abs(mergeweight) == 0.) {
866 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
867 DJR.push_back(djrmatch[idjr]);
881 event() = std::make_unique<HepMC::GenEvent>();
893 if (mergeweight != 1.) {
894 event()->weights()[0] *= mergeweight;
907 event()->weights().push_back(wgt);
917 int NPartsBeforeDecays = pythiaEvent->size();
918 int NPartsAfterDecays =
event().get()->particles_size();
920 if (NPartsAfterDecays == NPartsBeforeDecays)
925 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
928 if (
part->status() == 1 && (
fDecayer->particleData).canDecay(
part->pdg_id())) {
938 part->momentum().x(),
939 part->momentum().y(),
940 part->momentum().z(),
941 part->momentum().t(),
942 part->generated_mass());
943 HepMC::GenVertex *ProdVtx =
part->production_vertex();
944 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
945 py8part.tau((
fDecayer->particleData).tau0(
part->pdg_id()));
947 int nentries =
fDecayer->event.size();
948 if (!
fDecayer->event[nentries - 1].mayDecay())
951 int nentries1 =
fDecayer->event.size();
952 if (nentries1 <= nentries)
973 eventInfo() = std::make_unique<GenEventInfoProduct>(
event().get());
997 <<
"----------------------" << std::endl;
1002 <<
"----------------------" << std::endl;
1018 int weights_number =
fMasterGen->info.nWeights();
1020 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
1021 if (weights_number > 1) {
1030 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
1031 const auto &wgtgrpwgt = wgtgrp.second.weights.find(
key);
1032 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
1033 weightgroupname = wgtgrp.first;
1037 std::ostringstream weightname;
1038 weightname <<
"LHE, id = " <<
key <<
", ";
1039 if (!weightgroupname.empty()) {
1040 weightname <<
"group = " << weightgroupname <<
", ";
1042 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
1059 if (fvincia.get()) {
1060 for (
int iVar = 0; iVar < fvincia->nWeights(); iVar++) {
1069 unordered_map<string, double>::iterator it;
1070 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
1072 if (it->first ==
"base")
edm::ConcurrentGeneratorFilter< Pythia8Hadronizer, ConcurrentExternalDecayDriver > Pythia8ConcurrentGeneratorFilter
std::shared_ptr< PowhegHooksBB4L > fPowhegHooksBB4L
virtual bool residualDecay()
std::shared_ptr< PowhegHooksVincia > fEmissionVetoHookVincia
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