10 #include "HepMC/GenEvent.h" 11 #include "HepMC/GenParticle.h" 13 #include "Pythia8/Pythia.h" 14 #include "Pythia8Plugins/HepMC2.h" 27 #include "Pythia8Plugins/JetMatching.h" 28 #include "Pythia8Plugins/aMCatNLOHooks.h" 32 #include "Pythia8Plugins/PowhegHooks.h" 33 #include "Pythia8Plugins/PowhegHooksVincia.h" 51 #include "Pythia8Plugins/EvtGen.h" 69 #include "HepPID/ParticleIDTranslations.hh" 75 class HepRandomEngine;
85 bool initializeForInternalPartons()
override;
86 bool initializeForExternalPartons();
88 bool generatePartonsAndHadronize()
override;
91 virtual bool residualDecay();
93 void finalizeEvent()
override;
97 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
99 std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader()
const override;
103 std::vector<std::string>
const &
doSharedResources()
const override {
return p8SharedResources; }
109 std::shared_ptr<LHAupLesHouches>
lhaUP;
111 enum { PP,
PPbar, ElectronPositron };
185 LHEInputFileName(
params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
195 if (
params.exists(
"PPbarInitialState")) {
199 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 200 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
204 }
else if (
params.exists(
"ElectronPositronInitialState")) {
208 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 209 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
213 }
else if (
params.exists(
"ElectronProtonInitialState") ||
params.exists(
"PositronProtonInitialState")) {
216 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
220 toHepMC.set_store_weights(
false);
224 if (
params.exists(
"reweightGen")) {
225 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
229 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
231 if (
params.exists(
"reweightGenEmp")) {
232 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
236 if (rgeParams.
exists(
"tune"))
239 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
241 if (
params.exists(
"reweightGenRap")) {
242 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
250 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
252 if (
params.exists(
"reweightGenPtHatRap")) {
253 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
261 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
264 if (
params.exists(
"useUserHook"))
266 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
270 if (
params.exists(
"jetMatching")) {
273 if (
scheme ==
"Madgraph" ||
scheme ==
"MadgraphFastJet") {
280 if (
params.exists(
"emissionVeto1")) {
282 if (
params.exists(
"EV1_nFinal"))
285 if (
params.exists(
"EV1_vetoOn"))
288 if (
params.exists(
"EV1_maxVetoCount"))
291 if (
params.exists(
"EV1_pThardMode"))
294 if (
params.exists(
"EV1_pTempMode"))
299 if (
params.exists(
"EV1_emittedMode"))
302 if (
params.exists(
"EV1_pTdefMode"))
305 if (
params.exists(
"EV1_MPIvetoOn"))
308 if (
params.exists(
"EV1_QEDvetoMode"))
311 if (
params.exists(
"EV1_nFinalMode"))
326 if (
params.exists(
"UserCustomization")) {
328 const std::vector<edm::ParameterSet> userParams =
329 params.getParameter<std::vector<edm::ParameterSet>>(
"UserCustomization");
330 for (
const auto &pluginParams : userParams) {
337 if (
params.exists(
"VinciaPlugin")) {
339 <<
" Obsolete parameter: VinciaPlugin \n Please use the parameter PartonShowers:model instead \n";
341 if (
params.exists(
"DirePlugin")) {
343 <<
" Obsolete parameter: DirePlugin \n Please use the parameter PartonShowers:model instead \n";
350 bool status =
false, status1 =
false;
359 fMasterGen->settings.mode(
"Beams:idB", -2212);
366 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
370 fMasterGen->settings.mode(
"Beams:frameType", 4);
389 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
393 bool VinciaShower =
fMasterGen->settings.mode(
"PartonShowers:Model") == 2;
395 if ((
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) &&
399 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 400 "are : jetMatching, emissionVeto1 \n";
405 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
409 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 && VinciaShower) {
410 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Vincia Emission Veto Hook from pythia8 code";
416 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
418 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
424 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
426 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
432 bool TopRecoilHook1 =
fMasterGen->settings.flag(
"TopRecoilHook:doTopRecoilIn");
433 if (TopRecoilHook1) {
434 edm::LogInfo(
"Pythia8Interface") <<
"Turning on RecoilToTop hook from Pythia8Interface";
441 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
442 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
444 if (internalMatching && internalMerging) {
446 <<
" Only one jet matching/merging scheme can be used at a time. \n";
449 if (internalMatching) {
455 if (internalMerging) {
458 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
459 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
460 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
461 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
469 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
470 if (biasedTauDecayer) {
475 std::vector<int> handledParticles;
476 handledParticles.push_back(15);
480 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
481 if (resonanceDecayFilter) {
486 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
500 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hooks";
506 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
522 fDecayer->settings.flag(
"ProcessLevel:all",
false);
523 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
524 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
528 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
536 return (
status && status1);
540 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
542 bool status =
false, status1 =
false;
559 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
564 edm::LogInfo(
"Pythia8Interface") <<
"Adding customized user hook";
570 bool VinciaShower =
fMasterGen->settings.mode(
"PartonShowers:Model") == 2;
572 if ((
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) &&
576 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 577 "are : jetMatching, emissionVeto1 \n";
582 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
586 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 && VinciaShower) {
587 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Vincia Emission Veto Hook from pythia8 code";
593 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
595 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
601 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
603 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
609 bool TopRecoilHook1 =
fMasterGen->settings.flag(
"TopRecoilHook:doTopRecoilIn");
610 if (TopRecoilHook1) {
611 edm::LogInfo(
"Pythia8Interface") <<
"Turning on RecoilToTop hook from Pythia8Interface";
617 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
618 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
620 if (internalMatching && internalMerging) {
622 <<
" Only one jet matching/merging scheme can be used at a time. \n";
625 if (internalMatching) {
631 if (internalMerging) {
634 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
635 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
636 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
637 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
645 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
646 if (biasedTauDecayer) {
651 std::vector<int> handledParticles;
652 handledParticles.push_back(15);
656 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
657 if (resonanceDecayFilter) {
662 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
677 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
678 fMasterGen->settings.mode(
"Beams:frameType", 4);
684 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
691 fMasterGen->settings.mode(
"Beams:frameType", 5);
693 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
710 fDecayer->settings.flag(
"ProcessLevel:all",
false);
711 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
712 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
716 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
724 return (
status && status1);
732 <<
"Number of ISR vetoed = " <<
nISRveto;
756 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
771 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
772 DJR.push_back(djrmatch[idjr]);
782 event() = std::make_unique<HepMC::GenEvent>();
793 if (mergeweight != 1.) {
794 event()->weights()[0] *= mergeweight;
803 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
804 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
806 event()->weights().push_back(wgt);
808 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
809 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
810 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
811 event()->weights().push_back(wgt);
820 event()->weights().push_back(wgt);
828 event()->weights()[0] *= fvincia->weight(0);
829 for (
int iVar = 1; iVar < fvincia->nWeights(); iVar++) {
830 event()->weights().push_back(fvincia->weight(iVar));
836 fDire->weightsPtr->calcWeight(0.);
837 fDire->weightsPtr->reset();
840 event()->weights()[0] *= fDire->weightsPtr->getShowerWeight(
"base");
842 unordered_map<string, double>::iterator it;
843 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
845 if (it->first ==
"base")
847 event()->weights().push_back(it->second);
869 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
875 if (!py8next ||
std::abs(mergeweight) == 0.) {
885 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
886 DJR.push_back(djrmatch[idjr]);
900 event() = std::make_unique<HepMC::GenEvent>();
912 if (mergeweight != 1.) {
913 event()->weights()[0] *= mergeweight;
926 event()->weights().push_back(wgt);
936 int NPartsBeforeDecays = pythiaEvent->size();
937 int NPartsAfterDecays =
event().get()->particles_size();
939 if (NPartsAfterDecays == NPartsBeforeDecays)
944 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
947 if (
part->status() == 1 && (
fDecayer->particleData).canDecay(
part->pdg_id())) {
957 part->momentum().x(),
958 part->momentum().y(),
959 part->momentum().z(),
960 part->momentum().t(),
961 part->generated_mass());
962 HepMC::GenVertex *ProdVtx =
part->production_vertex();
963 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
964 py8part.tau((
fDecayer->particleData).tau0(
part->pdg_id()));
966 int nentries =
fDecayer->event.size();
967 if (!
fDecayer->event[nentries - 1].mayDecay())
970 int nentries1 =
fDecayer->event.size();
971 if (nentries1 <= nentries)
992 eventInfo() = std::make_unique<GenEventInfoProduct>(
event().get());
1016 <<
"----------------------" << std::endl;
1021 <<
"----------------------" << std::endl;
1037 int weights_number =
fMasterGen->info.nWeights();
1039 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
1040 if (weights_number > 1) {
1049 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
1050 const auto &wgtgrpwgt = wgtgrp.second.weights.find(
key);
1051 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
1052 weightgroupname = wgtgrp.first;
1056 std::ostringstream weightname;
1057 weightname <<
"LHE, id = " <<
key <<
", ";
1058 if (!weightgroupname.empty()) {
1059 weightname <<
"group = " << weightgroupname <<
", ";
1061 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
1078 if (fvincia.get()) {
1079 for (
int iVar = 0; iVar < fvincia->nWeights(); iVar++) {
1088 unordered_map<string, double>::iterator it;
1089 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
1091 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
std::shared_ptr< TopRecoilHook > fTopRecoilHook
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