8 #include "HepMC/GenEvent.h" 9 #include "HepMC/GenParticle.h" 11 #include "Pythia8/Pythia.h" 12 #include "Pythia8Plugins/HepMC2.h" 14 #include "Pythia8/Vincia.h" 15 #include "Dire/Dire.h" 26 #include "Pythia8Plugins/JetMatching.h" 27 #include "Pythia8Plugins/aMCatNLOHooks.h" 33 #include "Pythia8Plugins/PowhegHooks.h" 48 #include "Pythia8Plugins/EvtGen.h" 64 #include "HepPID/ParticleIDTranslations.hh" 69 class HepRandomEngine;
79 bool initializeForInternalPartons()
override;
80 bool initializeForExternalPartons();
82 bool generatePartonsAndHadronize()
override;
85 virtual bool residualDecay();
87 void finalizeEvent()
override;
91 const char *
classname()
const override {
return "Pythia8Hadronizer"; }
93 std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader()
const override;
96 std::unique_ptr<Pythia8::VinciaPlugin>
fvincia;
97 std::unique_ptr<Pythia8::Dire>
fDire;
100 std::vector<std::string>
const &
doSharedResources()
const override {
return p8SharedResources; }
106 std::unique_ptr<LHAupLesHouches>
lhaUP;
108 enum { PP,
PPbar, ElectronPositron };
170 comEnergy(params.getParameter<double>(
"comEnergy")),
171 LHEInputFileName(params.getUntrackedParameter<
std::
string>(
"LHEInputFileName",
"")),
179 if (params.
exists(
"PPbarInitialState")) {
183 <<
"Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. " 184 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
188 }
else if (params.
exists(
"ElectronPositronInitialState")) {
192 <<
"Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. " 193 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
197 }
else if (params.
exists(
"ElectronProtonInitialState") || params.
exists(
"PositronProtonInitialState")) {
200 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
205 if (params.
exists(
"reweightGen")) {
206 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGen";
210 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGen";
212 if (params.
exists(
"reweightGenEmp")) {
213 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenEmp";
217 if (rgeParams.
exists(
"tune"))
220 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenEmp";
222 if (params.
exists(
"reweightGenRap")) {
223 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenRap";
231 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenRap";
233 if (params.
exists(
"reweightGenPtHatRap")) {
234 edm::LogInfo(
"Pythia8Interface") <<
"Start setup for reweightGenPtHatRap";
242 edm::LogInfo(
"Pythia8Interface") <<
"End setup for reweightGenPtHatRap";
245 if (params.
exists(
"useUserHook"))
247 <<
" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
251 if (params.
exists(
"jetMatching")) {
254 if (scheme ==
"Madgraph" || scheme ==
"MadgraphFastJet") {
261 if (params.
exists(
"emissionVeto1")) {
263 if (params.
exists(
"EV1_nFinal"))
266 if (params.
exists(
"EV1_vetoOn"))
269 if (params.
exists(
"EV1_maxVetoCount"))
272 if (params.
exists(
"EV1_pThardMode"))
275 if (params.
exists(
"EV1_pTempMode"))
280 if (params.
exists(
"EV1_emittedMode"))
283 if (params.
exists(
"EV1_pTdefMode"))
286 if (params.
exists(
"EV1_MPIvetoOn"))
289 if (params.
exists(
"EV1_QEDvetoMode"))
292 if (params.
exists(
"EV1_nFinalMode"))
307 if (params.
exists(
"VinciaPlugin")) {
311 if (params.
exists(
"DirePlugin")) {
313 fDire.reset(
new Pythia8::Dire());
322 bool status =
false, status1 =
false;
331 fMasterGen->settings.mode(
"Beams:idB", -2212);
338 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
342 fMasterGen->settings.mode(
"Beams:frameType", 4);
359 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
363 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
366 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 367 "are : jetMatching, emissionVeto1 \n";
371 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
375 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
377 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
382 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
384 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
390 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
391 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
393 if (internalMatching && internalMerging) {
395 <<
" Only one jet matching/merging scheme can be used at a time. \n";
398 if (internalMatching) {
403 if (internalMerging) {
406 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
407 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
408 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
409 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
412 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
416 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
417 if (resonanceDecayFilter) {
422 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
432 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
436 }
else if (
fDire.get()) {
438 fDire->weightsPtr->setup();
459 fDecayer->settings.flag(
"ProcessLevel:all",
false);
460 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
461 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
465 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
471 return (status && status1);
475 edm::LogInfo(
"Pythia8Interface") <<
"Initializing for external partons";
477 bool status =
false, status1 =
false;
492 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
496 if (
fMasterGen->settings.mode(
"POWHEG:veto") > 0 ||
fMasterGen->settings.mode(
"POWHEG:MPIveto") > 0) {
499 <<
" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible " 500 "are : jetMatching, emissionVeto1 \n";
504 edm::LogInfo(
"Pythia8Interface") <<
"Turning on Emission Veto Hook from pythia8 code";
508 bool PowhegRes =
fMasterGen->settings.flag(
"POWHEGres:calcScales");
510 edm::LogInfo(
"Pythia8Interface") <<
"Turning on resonance scale setting from CMSSW Pythia8Interface";
515 bool PowhegBB4L =
fMasterGen->settings.flag(
"POWHEG:bb4l");
517 edm::LogInfo(
"Pythia8Interface") <<
"Turning on BB4l hook from CMSSW Pythia8Interface";
523 bool internalMatching =
fMasterGen->settings.flag(
"JetMatching:merge");
524 bool internalMerging = !(
fMasterGen->settings.word(
"Merging:Process") ==
"void");
526 if (internalMatching && internalMerging) {
528 <<
" Only one jet matching/merging scheme can be used at a time. \n";
531 if (internalMatching) {
536 if (internalMerging) {
539 : ((
fMasterGen->settings.flag(
"Merging:doUNLOPSTree") ||
540 fMasterGen->settings.flag(
"Merging:doUNLOPSSubt") ||
541 fMasterGen->settings.flag(
"Merging:doUNLOPSLoop") ||
542 fMasterGen->settings.flag(
"Merging:doUNLOPSSubtNLO"))
545 fMergingHook.reset(
new Pythia8::amcnlo_unitarised_interface(scheme));
549 bool resonanceDecayFilter =
fMasterGen->settings.flag(
"ResonanceDecayFilter:filter");
550 if (resonanceDecayFilter) {
555 bool PTFilter =
fMasterGen->settings.flag(
"PTFilter:filter");
567 edm::LogInfo(
"Pythia8Interface") <<
"Some LHE information can be not stored";
568 fMasterGen->settings.mode(
"Beams:frameType", 4);
574 lhaUP->setScalesFromLHEF(
fMasterGen->settings.flag(
"Beams:setProductionScalesFromLHEF"));
581 fMasterGen->settings.mode(
"Beams:frameType", 5);
583 edm::LogInfo(
"Pythia8Interface") <<
"Initializing MasterGen";
600 fDecayer->settings.flag(
"ProcessLevel:all",
false);
601 fDecayer->settings.flag(
"ProcessLevel:resonanceDecays",
true);
602 edm::LogInfo(
"Pythia8Interface") <<
"Initializing Decayer";
606 edm::LogInfo(
"Pythia8Hadronizer") <<
"Creating and initializing pythia8 EvtGen plugin";
612 return (status && status1);
620 <<
"Number of ISR vetoed = " <<
nISRveto;
644 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
659 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
660 DJR.push_back(djrmatch[idjr]);
678 if (mergeweight != 1.) {
679 event()->weights()[0] *= mergeweight;
688 if (
fMasterGen->info.getWeightsDetailedSize() > 0) {
689 for (
const string &
key :
fMasterGen->info.initrwgt->weightsKeys) {
690 double wgt = (*
fMasterGen->info.weights_detailed)[key];
691 event()->weights().push_back(wgt);
693 }
else if (
fMasterGen->info.getWeightsCompressedSize() > 0) {
694 for (
unsigned int i = 0;
i <
fMasterGen->info.getWeightsCompressedSize();
i++) {
695 double wgt =
fMasterGen->info.getWeightsCompressedValue(
i);
696 event()->weights().push_back(wgt);
705 event()->weights().push_back(wgt);
713 for (
int iVar = 1; iVar <
fvincia->nWeights(); iVar++) {
720 fDire->weightsPtr->calcWeight(0.);
721 fDire->weightsPtr->reset();
724 event()->weights()[0] *=
fDire->weightsPtr->getShowerWeight(
"base");
726 unordered_map<string, double>::iterator it;
727 for (it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end();
729 if (it->first ==
"base")
731 event()->weights().push_back(it->second);
752 double mergeweight =
fMasterGen.get()->info.mergingWeightNLO();
758 if (!py8next ||
std::abs(mergeweight) == 0.) {
768 for (
unsigned int idjr = 0; idjr < ndjr; ++idjr) {
769 DJR.push_back(djrmatch[idjr]);
790 if (mergeweight != 1.) {
791 event()->weights()[0] *= mergeweight;
804 event()->weights().push_back(wgt);
814 int NPartsBeforeDecays = pythiaEvent->size();
815 int NPartsAfterDecays =
event().get()->particles_size();
817 if (NPartsAfterDecays == NPartsBeforeDecays)
822 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
825 if (part->status() == 1 && (
fDecayer->particleData).canDecay(part->pdg_id())) {
835 part->momentum().x(),
836 part->momentum().y(),
837 part->momentum().z(),
838 part->momentum().t(),
839 part->generated_mass());
840 HepMC::GenVertex *ProdVtx = part->production_vertex();
841 py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
842 py8part.tau((
fDecayer->particleData).tau0(part->pdg_id()));
844 int nentries =
fDecayer->event.size();
845 if (!
fDecayer->event[nentries - 1].mayDecay())
848 int nentries1 =
fDecayer->event.size();
849 if (nentries1 <= nentries)
890 <<
"----------------------" << std::endl;
895 <<
"----------------------" << std::endl;
911 int weights_number =
fMasterGen->info.nWeights();
913 weights_number +=
fMasterGen->info.initrwgt->weightsKeys.size();
914 if (weights_number > 1) {
923 for (
const auto &wgtgrp :
fMasterGen->info.initrwgt->weightgroups) {
924 const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
925 if (wgtgrpwgt != wgtgrp.second.weights.end()) {
926 weightgroupname = wgtgrp.first;
930 std::ostringstream weightname;
931 weightname <<
"LHE, id = " << key <<
", ";
932 if (!weightgroupname.empty()) {
933 weightname <<
"group = " << weightgroupname <<
", ";
935 weightname <<
fMasterGen->info.initrwgt->weights[
key].contents;
952 for (
int iVar = 0; iVar <
fvincia->nWeights(); iVar++) {
961 unordered_map<string, double>::iterator it;
962 for (it =
fDire->weightsPtr->getShowerWeights()->begin(); it !=
fDire->weightsPtr->getShowerWeights()->end();
964 if (it->first ==
"base")
std::unique_ptr< UserHooks > fReweightPtHatRapUserHook
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual bool residualDecay()
double comEnergy
Center-of-Mass energy.
std::unique_ptr< Pythia8::Pythia > fDecayer
edm::GeneratorFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8GeneratorFilter
bool initializeForInternalPartons() override
std::shared_ptr< EvtGenDecays > evtgenDecays
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
std::unique_ptr< EmissionVetoHook1 > fEmissionVetoHook1
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
std::unique_ptr< Pythia8::amcnlo_unitarised_interface > fMergingHook
bool pythiaHepMCVerbosityParticles
void setInternalXSec(const XSec &xsec)
std::vector< std::string > evtgenUserFiles
std::unique_ptr< JetMatchingHook > fJetMatchingHook
const char * classname() const override
GenRunInfoProduct & runInfo()
#define DEFINE_FWK_MODULE(type)
lhef::LHEEvent * lheEvent()
std::unique_ptr< PowhegHooksBB4L > fPowhegHooksBB4L
std::unique_ptr< Pythia8::VinciaPlugin > fvincia
std::unique_ptr< PowhegResHook > fPowhegResHook
std::unique_ptr< Pythia8::JetMatchingMadgraph > fJetMatchingPy8InternalHook
std::unique_ptr< PowhegHooks > fEmissionVetoHook
static const std::vector< std::string > p8SharedResources
Abs< T >::type abs(const T &t)
unsigned int pythiaPylistVerbosity
std::unique_ptr< GenLumiInfoHeader > getGenLumiInfoHeader() const override
std::unique_ptr< HepMC::GenEvent > & event()
std::vector< std::string > const & doSharedResources() const override
lhef::LHERunInfo * lheRunInfo()
bool generatePartonsAndHadronize() override
std::unique_ptr< LHAupLesHouches > lhaUP
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
std::unique_ptr< UserHooks > fReweightRapUserHook
std::unique_ptr< UserHooks > fReweightUserHook
std::string evtgenPdlFile
std::unique_ptr< GenEventInfoProduct > & eventInfo()
unsigned int maxEventsToPrint
def remove(d, key, TELL=False)
std::unique_ptr< UserHooks > fReweightEmpUserHook
Pythia8Hadronizer(const edm::ParameterSet ¶ms)
bool pythiaHepMCVerbosity
std::string evtgenDecFile
std::unique_ptr< ResonanceDecayFilterHook > fResonanceDecayFilterHook
std::unique_ptr< MultiUserHook > fMultiUserHook
HepMC::Pythia8ToHepMC toHepMC
std::unique_ptr< PTFilterHook > fPTFilterHook
std::unique_ptr< Pythia8::Pythia > fMasterGen
static const std::string kPythia8
void finalizeEvent() override
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter
std::unique_ptr< Pythia8::Dire > fDire
~Pythia8Hadronizer() override