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";
596 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
597 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
599 if (internalMatching && internalMerging) {
601 <<
" Only one jet matching/merging scheme can be used at a time. \n";
604 if (internalMatching) {
610 if (internalMerging) {
613 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
614 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
615 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
616 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
624 bool biasedTauDecayer =
fMasterGen->settings.flag(
"BiasedTauDecayer:filter");
625 if (biasedTauDecayer) {
630 std::vector<int> handledParticles;
631 handledParticles.push_back(15);
635 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
636 if (resonanceDecayFilter) {
641 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
656 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
657 fMasterGen->settings.mode(
"Beams:frameType", 4);
663 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
670 fMasterGen->settings.mode(
"Beams:frameType", 5);
672 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
689 fDecayer->settings.flag(
"ProcessLevel:all",
false);
690 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
691 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
695 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
703 return (
status && status1);
711 <<
"Number of ISR vetoed = " <<
nISRveto;
735 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
750 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
751 DJR.push_back(djrmatch[idjr]);
761 event() = std::make_unique<HepMC::GenEvent>();
772 if (mergeweight != 1.) {
773 event()->weights()[0] *= mergeweight;
782 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
783 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
785 event()->weights().push_back(wgt);
787 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
788 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
789 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
790 event()->weights().push_back(wgt);
799 event()->weights().push_back(wgt);
807 event()->weights()[0] *= fvincia->weight(0);
808 for (
int iVar = 1; iVar < fvincia->nWeights(); iVar++) {
809 event()->weights().push_back(fvincia->weight(iVar));
815 fDire->weightsPtr->calcWeight(0.);
816 fDire->weightsPtr->reset();
819 event()->weights()[0] *= fDire->weightsPtr->getShowerWeight(
"base");
821 unordered_map<string, double>::iterator
it;
822 for (
it = fDire->weightsPtr->getShowerWeights()->begin();
it != fDire->weightsPtr->getShowerWeights()->end();
824 if (
it->first ==
"base")
826 event()->weights().push_back(
it->second);
848 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
854 if (!py8next ||
std::abs(mergeweight) == 0.) {
864 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
865 DJR.push_back(djrmatch[idjr]);
879 event() = std::make_unique<HepMC::GenEvent>();
891 if (mergeweight != 1.) {
892 event()->weights()[0] *= mergeweight;
905 event()->weights().push_back(wgt);
915 int NPartsBeforeDecays = pythiaEvent->size();
916 int NPartsAfterDecays =
event().get()->particles_size();
918 if (NPartsAfterDecays == NPartsBeforeDecays)
923 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
926 if (
part->status() == 1 && (
fDecayer->particleData).canDecay(
part->pdg_id())) {
936 part->momentum().x(),
937 part->momentum().y(),
938 part->momentum().z(),
939 part->momentum().t(),
940 part->generated_mass());
941 HepMC::GenVertex *ProdVtx =
part->production_vertex();
942 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
943 py8part.tau((
fDecayer->particleData).tau0(
part->pdg_id()));
945 int nentries =
fDecayer->event.size();
946 if (!
fDecayer->event[nentries - 1].mayDecay())
949 int nentries1 =
fDecayer->event.size();
950 if (nentries1 <= nentries)
971 eventInfo() = std::make_unique<GenEventInfoProduct>(
event().get());
995 <<
"----------------------" << std::endl;
1000 <<
"----------------------" << std::endl;
1016 int weights_number =
fMasterGen->info.nWeights();
1018 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
1019 if (weights_number > 1) {
1028 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
1029 const auto &wgtgrpwgt = wgtgrp.second.weights.find(
key);
1030 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
1031 weightgroupname = wgtgrp.first;
1035 std::ostringstream weightname;
1036 weightname <<
"LHE, id = " <<
key <<
", ";
1037 if (!weightgroupname.empty()) {
1038 weightname <<
"group = " << weightgroupname <<
", ";
1040 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
1057 if (fvincia.get()) {
1058 for (
int iVar = 0; iVar < fvincia->nWeights(); iVar++) {
1067 unordered_map<string, double>::iterator
it;
1068 for (
it = fDire->weightsPtr->getShowerWeights()->begin();
it != fDire->weightsPtr->getShowerWeights()->end();
1070 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
key
prepare the HTCondor submission files and eventually submit them
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