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" 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 };
183 LHEInputFileName(
params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
193 if (
params.exists(
"PPbarInitialState")) {
197 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 198 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
202 }
else if (
params.exists(
"ElectronPositronInitialState")) {
206 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 207 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
211 }
else if (
params.exists(
"ElectronProtonInitialState") ||
params.exists(
"PositronProtonInitialState")) {
214 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
218 toHepMC.set_store_weights(
false);
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"))
324 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) {
335 if (
params.exists(
"VinciaPlugin")) {
337 <<
" Obsolete parameter: VinciaPlugin \n Please use the parameter PartonShowers:model instead \n";
339 if (
params.exists(
"DirePlugin")) {
341 <<
" Obsolete parameter: DirePlugin \n Please use the parameter PartonShowers:model instead \n";
348 bool status =
false, status1 =
false;
357 fMasterGen->settings.mode(
"Beams:idB", -2212);
364 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
368 fMasterGen->settings.mode(
"Beams:frameType", 4);
387 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
391 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
394 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 395 "are : jetMatching, emissionVeto1 \n";
400 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
404 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
406 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
412 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
414 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
420 bool TopRecoilHook1 =
fMasterGen->settings.flag(
"TopRecoilHook:doTopRecoilIn");
421 if (TopRecoilHook1) {
422 edm::LogInfo(
"Pythia8Interface") <<
"Turning on RecoilToTop hook from 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 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
561 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 562 "are : jetMatching, emissionVeto1 \n";
567 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
571 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
573 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
579 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
581 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
587 bool TopRecoilHook1 =
fMasterGen->settings.flag(
"TopRecoilHook:doTopRecoilIn");
588 if (TopRecoilHook1) {
589 edm::LogInfo(
"Pythia8Interface") <<
"Turning on RecoilToTop hook from Pythia8Interface";
595 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
596 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
598 if (internalMatching && internalMerging) {
600 <<
" Only one jet matching/merging scheme can be used at a time. \n";
603 if (internalMatching) {
609 if (internalMerging) {
612 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
613 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
614 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
615 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
623 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
624 if (biasedTauDecayer) {
629 std::vector<int> handledParticles;
630 handledParticles.push_back(15);
634 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
635 if (resonanceDecayFilter) {
640 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
655 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
656 fMasterGen->settings.mode(
"Beams:frameType", 4);
662 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
669 fMasterGen->settings.mode(
"Beams:frameType", 5);
671 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
688 fDecayer->settings.flag(
"ProcessLevel:all",
false);
689 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
690 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
694 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
702 return (
status && status1);
710 <<
"Number of ISR vetoed = " <<
nISRveto;
734 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
749 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
750 DJR.push_back(djrmatch[idjr]);
760 event() = std::make_unique<HepMC::GenEvent>();
771 if (mergeweight != 1.) {
772 event()->weights()[0] *= mergeweight;
781 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
782 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
784 event()->weights().push_back(wgt);
786 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
787 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
788 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
789 event()->weights().push_back(wgt);
798 event()->weights().push_back(wgt);
806 event()->weights()[0] *= fvincia->weight(0);
807 for (
int iVar = 1; iVar < fvincia->nWeights(); iVar++) {
808 event()->weights().push_back(fvincia->weight(iVar));
814 fDire->weightsPtr->calcWeight(0.);
815 fDire->weightsPtr->reset();
818 event()->weights()[0] *= fDire->weightsPtr->getShowerWeight(
"base");
820 unordered_map<string, double>::iterator it;
821 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
823 if (it->first ==
"base")
825 event()->weights().push_back(it->second);
847 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
853 if (!py8next ||
std::abs(mergeweight) == 0.) {
863 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
864 DJR.push_back(djrmatch[idjr]);
878 event() = std::make_unique<HepMC::GenEvent>();
890 if (mergeweight != 1.) {
891 event()->weights()[0] *= mergeweight;
904 event()->weights().push_back(wgt);
914 int NPartsBeforeDecays = pythiaEvent->size();
915 int NPartsAfterDecays =
event().get()->particles_size();
917 if (NPartsAfterDecays == NPartsBeforeDecays)
922 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
925 if (
part->status() == 1 && (
fDecayer->particleData).canDecay(
part->pdg_id())) {
935 part->momentum().x(),
936 part->momentum().y(),
937 part->momentum().z(),
938 part->momentum().t(),
939 part->generated_mass());
940 HepMC::GenVertex *ProdVtx =
part->production_vertex();
941 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
942 py8part.tau((
fDecayer->particleData).tau0(
part->pdg_id()));
944 int nentries =
fDecayer->event.size();
945 if (!
fDecayer->event[nentries - 1].mayDecay())
948 int nentries1 =
fDecayer->event.size();
949 if (nentries1 <= nentries)
970 eventInfo() = std::make_unique<GenEventInfoProduct>(
event().get());
994 <<
"----------------------" << std::endl;
999 <<
"----------------------" << std::endl;
1015 int weights_number =
fMasterGen->info.nWeights();
1017 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
1018 if (weights_number > 1) {
1027 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
1028 const auto &wgtgrpwgt = wgtgrp.second.weights.find(
key);
1029 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
1030 weightgroupname = wgtgrp.first;
1034 std::ostringstream weightname;
1035 weightname <<
"LHE, id = " <<
key <<
", ";
1036 if (!weightgroupname.empty()) {
1037 weightname <<
"group = " << weightgroupname <<
", ";
1039 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
1056 if (fvincia.get()) {
1057 for (
int iVar = 0; iVar < fvincia->nWeights(); iVar++) {
1066 unordered_map<string, double>::iterator it;
1067 for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
1069 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
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