CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
Pythia8Hadronizer Class Reference
Inheritance diagram for Pythia8Hadronizer:
gen::Py8InterfaceBase gen::BaseHadronizer

Public Member Functions

const char * classname () const override
 
void finalizeEvent () override
 
bool generatePartonsAndHadronize () override
 
std::unique_ptr< GenLumiInfoHeadergetGenLumiInfoHeader () const override
 
bool hadronize ()
 
bool initializeForExternalPartons ()
 
bool initializeForInternalPartons () override
 
 Pythia8Hadronizer (const edm::ParameterSet &params)
 
virtual bool residualDecay ()
 
void statistics () override
 
 ~Pythia8Hadronizer () override
 
- Public Member Functions inherited from gen::Py8InterfaceBase
bool decay ()
 
bool declareSpecialSettings (const std::vector< std::string > &)
 
bool declareStableParticles (const std::vector< int > &)
 
void makeTmpSLHA (const std::string &)
 
void p8SetRandomEngine (CLHEP::HepRandomEngine *v)
 
 Py8InterfaceBase (edm::ParameterSet const &ps)
 
P8RndmEnginerandomEngine ()
 
bool readSettings (int)
 
 ~Py8InterfaceBase () override
 
- Public Member Functions inherited from gen::BaseHadronizer
 BaseHadronizer (edm::ParameterSet const &ps)
 
void cleanLHE ()
 
void generateLHE (edm::LuminosityBlock const &lumi, CLHEP::HepRandomEngine *rengine, unsigned int ncpu)
 
edm::EventgetEDMEvent () const
 
std::unique_ptr< HepMC::GenEventgetGenEvent ()
 
std::unique_ptr< HepMC3::GenEvent > getGenEvent3 ()
 
std::unique_ptr< GenEventInfoProductgetGenEventInfo ()
 
std::unique_ptr< GenEventInfoProduct3getGenEventInfo3 ()
 
GenRunInfoProductgetGenRunInfo ()
 
std::unique_ptr< lhef::LHEEventgetLHEEvent ()
 
const std::shared_ptr< lhef::LHERunInfo > & getLHERunInfo () const
 
unsigned int getVHepMC ()
 
const std::string & gridpackPath () const
 
int randomIndex () const
 
const std::string & randomInitConfigDescription () const
 
void randomizeIndex (edm::LuminosityBlock const &lumi, CLHEP::HepRandomEngine *rengine)
 
void resetEvent (std::unique_ptr< HepMC::GenEvent > event)
 
void resetEvent3 (std::unique_ptr< HepMC3::GenEvent > event3)
 
void resetEventInfo (std::unique_ptr< GenEventInfoProduct > eventInfo)
 
void resetEventInfo3 (std::unique_ptr< GenEventInfoProduct3 > eventInfo)
 
virtual bool select (HepMC::GenEvent *) const
 
void setEDMEvent (edm::Event &event)
 
void setLHEEvent (std::unique_ptr< lhef::LHEEvent > event)
 
void setLHERunInfo (std::unique_ptr< lhef::LHERunInfo > runInfo)
 
void setRandomEngine (CLHEP::HepRandomEngine *v)
 
std::vector< std::string > const & sharedResources () const
 
virtual ~BaseHadronizer () noexcept(false)
 

Private Types

enum  { PP, PPbar, ElectronPositron }
 

Private Member Functions

void doSetRandomEngine (CLHEP::HepRandomEngine *v) override
 
std::vector< std::string > const & doSharedResources () const override
 

Private Attributes

double comEnergy
 Center-of-Mass energy. More...
 
vector< float > DJR
 
int EV1_emittedMode
 
int EV1_maxVetoCount
 
bool EV1_MPIvetoOn
 
int EV1_nFinal
 
int EV1_nFinalMode
 
int EV1_pTdefMode
 
int EV1_pTempMode
 
int EV1_pThardMode
 
int EV1_QEDvetoMode
 
bool EV1_vetoOn
 
double fBeam1PZ
 
double fBeam2PZ
 
std::shared_ptr< BiasedTauDecayerfBiasedTauDecayer
 
std::shared_ptr< UserHooksVector > fCustomHooksVector
 
std::shared_ptr< PowhegHooks > fEmissionVetoHook
 
std::shared_ptr< EmissionVetoHook1fEmissionVetoHook1
 
int fInitialState
 
std::shared_ptr< JetMatchingHookfJetMatchingHook
 
std::shared_ptr< Pythia8::JetMatchingMadgraph > fJetMatchingPy8InternalHook
 
std::shared_ptr< Pythia8::amcnlo_unitarised_interface > fMergingHook
 
std::shared_ptr< PowhegHooksBB4LfPowhegHooksBB4L
 
std::shared_ptr< PowhegResHookfPowhegResHook
 
std::shared_ptr< PTFilterHookfPTFilterHook
 
std::shared_ptr< ResonanceDecayFilterHookfResonanceDecayFilterHook
 
std::shared_ptr< UserHooks > fReweightEmpUserHook
 
std::shared_ptr< UserHooks > fReweightPtHatRapUserHook
 
std::shared_ptr< UserHooks > fReweightRapUserHook
 
std::shared_ptr< UserHooks > fReweightUserHook
 
std::shared_ptr< UserHooksVector > fUserHooksVector
 
std::shared_ptr< LHAupLesHoucheslhaUP
 
std::string LHEInputFileName
 
int nFSRveto
 
int nISRveto
 
int nME
 
int nMEFiltered
 
bool UserHooksSet
 

Static Private Attributes

static const std::vector< std::string > p8SharedResources = {edm::SharedResourceNames::kPythia8}
 

Additional Inherited Members

- Protected Member Functions inherited from gen::BaseHadronizer
std::unique_ptr< HepMC::GenEvent > & event ()
 
std::unique_ptr< HepMC3::GenEvent > & event3 ()
 
std::unique_ptr< GenEventInfoProduct > & eventInfo ()
 
std::unique_ptr< GenEventInfoProduct3 > & eventInfo3 ()
 
lhef::LHEEventlheEvent ()
 
lhef::LHERunInfolheRunInfo ()
 
GenRunInfoProductrunInfo ()
 
- Protected Attributes inherited from gen::Py8InterfaceBase
HepMC::IO_AsciiParticles * ascii_io
 
std::shared_ptr< Pythia8::EvtGenDecays > evtgenDecays
 
std::string evtgenDecFile
 
std::string evtgenPdlFile
 
std::vector< std::string > evtgenUserFiles
 
std::unique_ptr< Pythia8::Pythia > fDecayer
 
std::unique_ptr< Pythia8::Pythia > fMasterGen
 
edm::ParameterSet fParameters
 
unsigned int maxEventsToPrint
 
bool pythiaHepMCVerbosity
 
bool pythiaHepMCVerbosityParticles
 
unsigned int pythiaPylistVerbosity
 
std::string slhafile_
 
HepMC::Pythia8ToHepMC toHepMC
 
bool useEvtGen
 
- Protected Attributes inherited from gen::BaseHadronizer
unsigned int ivhepmc = 2
 
std::string lheFile_
 
int randomIndex_
 

Detailed Description

Definition at line 78 of file Pythia8Hadronizer.cc.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

Constructor & Destructor Documentation

◆ Pythia8Hadronizer()

Pythia8Hadronizer::Pythia8Hadronizer ( const edm::ParameterSet params)

Definition at line 176 of file Pythia8Hadronizer.cc.

References edm::errors::Configuration, ElectronPositron, EV1_emittedMode, EV1_maxVetoCount, EV1_MPIvetoOn, EV1_nFinal, EV1_nFinalMode, EV1_pTdefMode, EV1_pTempMode, EV1_pThardMode, EV1_QEDvetoMode, EV1_vetoOn, Exception, edm::ParameterSet::exists(), fCustomHooksVector, fEmissionVetoHook1, fInitialState, fJetMatchingHook, gen::Py8InterfaceBase::fMasterGen, fReweightEmpUserHook, fReweightPtHatRapUserHook, fReweightRapUserHook, fReweightUserHook, get, edm::ParameterSet::getParameter(), gen::BaseHadronizer::ivhepmc, submitPVValidationJobs::params, PP, PPbar, push_back(), generator_cfi::scheme, AlCaHLTBitMon_QueryRunRegistry::string, and gen::Py8InterfaceBase::toHepMC.

178  comEnergy(params.getParameter<double>("comEnergy")),
179  LHEInputFileName(params.getUntrackedParameter<std::string>("LHEInputFileName", "")),
180  fInitialState(PP),
181  UserHooksSet(false),
182  nME(-1),
183  nMEFiltered(-1),
184  nISRveto(0),
185  nFSRveto(0) {
186  ivhepmc = 2;
187  // J.Y.: the following 3 parameters are hacked "for a reason"
188  //
189  if (params.exists("PPbarInitialState")) {
190  if (fInitialState == PP) {
192  edm::LogImportant("GeneratorInterface|Pythia8Interface")
193  << "Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
194  << "This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
195  } else {
196  // probably need to throw on attempt to override ?
197  }
198  } else if (params.exists("ElectronPositronInitialState")) {
199  if (fInitialState == PP) {
201  edm::LogInfo("GeneratorInterface|Pythia8Interface")
202  << "Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
203  << "This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
204  } else {
205  // probably need to throw on attempt to override ?
206  }
207  } else if (params.exists("ElectronProtonInitialState") || params.exists("PositronProtonInitialState")) {
208  // throw on unknown initial state !
209  throw edm::Exception(edm::errors::Configuration, "Pythia8Interface")
210  << " UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
211  }
212 
213  // avoid filling weights twice (from v8.30x)
214  toHepMC.set_store_weights(false);
215 
216  // Reweight user hook
217  //
218  if (params.exists("reweightGen")) {
219  edm::LogInfo("Pythia8Interface") << "Start setup for reweightGen";
220  edm::ParameterSet rgParams = params.getParameter<edm::ParameterSet>("reweightGen");
221  fReweightUserHook.reset(
222  new PtHatReweightUserHook(rgParams.getParameter<double>("pTRef"), rgParams.getParameter<double>("power")));
223  edm::LogInfo("Pythia8Interface") << "End setup for reweightGen";
224  }
225  if (params.exists("reweightGenEmp")) {
226  edm::LogInfo("Pythia8Interface") << "Start setup for reweightGenEmp";
227  edm::ParameterSet rgeParams = params.getParameter<edm::ParameterSet>("reweightGenEmp");
228 
229  std::string tuneName = "";
230  if (rgeParams.exists("tune"))
231  tuneName = rgeParams.getParameter<std::string>("tune");
232  fReweightEmpUserHook.reset(new PtHatEmpReweightUserHook(tuneName));
233  edm::LogInfo("Pythia8Interface") << "End setup for reweightGenEmp";
234  }
235  if (params.exists("reweightGenRap")) {
236  edm::LogInfo("Pythia8Interface") << "Start setup for reweightGenRap";
237  edm::ParameterSet rgrParams = params.getParameter<edm::ParameterSet>("reweightGenRap");
238  fReweightRapUserHook.reset(new RapReweightUserHook(rgrParams.getParameter<std::string>("yLabSigmaFunc"),
239  rgrParams.getParameter<double>("yLabPower"),
240  rgrParams.getParameter<std::string>("yCMSigmaFunc"),
241  rgrParams.getParameter<double>("yCMPower"),
242  rgrParams.getParameter<double>("pTHatMin"),
243  rgrParams.getParameter<double>("pTHatMax")));
244  edm::LogInfo("Pythia8Interface") << "End setup for reweightGenRap";
245  }
246  if (params.exists("reweightGenPtHatRap")) {
247  edm::LogInfo("Pythia8Interface") << "Start setup for reweightGenPtHatRap";
248  edm::ParameterSet rgrParams = params.getParameter<edm::ParameterSet>("reweightGenPtHatRap");
249  fReweightPtHatRapUserHook.reset(new PtHatRapReweightUserHook(rgrParams.getParameter<std::string>("yLabSigmaFunc"),
250  rgrParams.getParameter<double>("yLabPower"),
251  rgrParams.getParameter<std::string>("yCMSigmaFunc"),
252  rgrParams.getParameter<double>("yCMPower"),
253  rgrParams.getParameter<double>("pTHatMin"),
254  rgrParams.getParameter<double>("pTHatMax")));
255  edm::LogInfo("Pythia8Interface") << "End setup for reweightGenPtHatRap";
256  }
257 
258  if (params.exists("useUserHook"))
259  throw edm::Exception(edm::errors::Configuration, "Pythia8Interface")
260  << " Obsolete parameter: useUserHook \n Please use the actual one instead \n";
261 
262  // PS matching prototype
263  //
264  if (params.exists("jetMatching")) {
265  edm::ParameterSet jmParams = params.getUntrackedParameter<edm::ParameterSet>("jetMatching");
266  std::string scheme = jmParams.getParameter<std::string>("scheme");
267  if (scheme == "Madgraph" || scheme == "MadgraphFastJet") {
268  fJetMatchingHook.reset(new JetMatchingHook(jmParams, &fMasterGen->info));
269  }
270  }
271 
272  // Pythia8Interface emission veto
273  //
274  if (params.exists("emissionVeto1")) {
275  EV1_nFinal = -1;
276  if (params.exists("EV1_nFinal"))
277  EV1_nFinal = params.getParameter<int>("EV1_nFinal");
278  EV1_vetoOn = true;
279  if (params.exists("EV1_vetoOn"))
280  EV1_vetoOn = params.getParameter<bool>("EV1_vetoOn");
281  EV1_maxVetoCount = 10;
282  if (params.exists("EV1_maxVetoCount"))
283  EV1_maxVetoCount = params.getParameter<int>("EV1_maxVetoCount");
284  EV1_pThardMode = 1;
285  if (params.exists("EV1_pThardMode"))
286  EV1_pThardMode = params.getParameter<int>("EV1_pThardMode");
287  EV1_pTempMode = 0;
288  if (params.exists("EV1_pTempMode"))
289  EV1_pTempMode = params.getParameter<int>("EV1_pTempMode");
290  if (EV1_pTempMode > 2 || EV1_pTempMode < 0)
291  throw edm::Exception(edm::errors::Configuration, "Pythia8Interface") << " Wrong value for EV1_pTempMode code\n";
292  EV1_emittedMode = 0;
293  if (params.exists("EV1_emittedMode"))
294  EV1_emittedMode = params.getParameter<int>("EV1_emittedMode");
295  EV1_pTdefMode = 1;
296  if (params.exists("EV1_pTdefMode"))
297  EV1_pTdefMode = params.getParameter<int>("EV1_pTdefMode");
298  EV1_MPIvetoOn = false;
299  if (params.exists("EV1_MPIvetoOn"))
300  EV1_MPIvetoOn = params.getParameter<bool>("EV1_MPIvetoOn");
301  EV1_QEDvetoMode = 0;
302  if (params.exists("EV1_QEDvetoMode"))
303  EV1_QEDvetoMode = params.getParameter<int>("EV1_QEDvetoMode");
304  EV1_nFinalMode = 0;
305  if (params.exists("EV1_nFinalMode"))
306  EV1_nFinalMode = params.getParameter<int>("EV1_nFinalMode");
308  EV1_vetoOn,
317  0));
318  }
319 
320  if (params.exists("UserCustomization")) {
321  fCustomHooksVector = std::make_shared<UserHooksVector>();
322  const std::vector<edm::ParameterSet> userParams =
323  params.getParameter<std::vector<edm::ParameterSet>>("UserCustomization");
324  for (const auto &pluginParams : userParams) {
325  (fCustomHooksVector->hooks)
326  .push_back(
327  CustomHookFactory::get()->create(pluginParams.getParameter<std::string>("pluginName"), pluginParams));
328  }
329  }
330 
331  if (params.exists("VinciaPlugin")) {
332  throw edm::Exception(edm::errors::Configuration, "Pythia8Interface")
333  << " Obsolete parameter: VinciaPlugin \n Please use the parameter PartonShowers:model instead \n";
334  }
335  if (params.exists("DirePlugin")) {
336  throw edm::Exception(edm::errors::Configuration, "Pythia8Interface")
337  << " Obsolete parameter: DirePlugin \n Please use the parameter PartonShowers:model instead \n";
338  }
339 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double comEnergy
Center-of-Mass energy.
std::shared_ptr< EmissionVetoHook1 > fEmissionVetoHook1
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::string LHEInputFileName
Py8InterfaceBase(edm::ParameterSet const &ps)
std::shared_ptr< UserHooks > fReweightRapUserHook
unsigned int ivhepmc
std::shared_ptr< UserHooksVector > fCustomHooksVector
Log< level::Error, true > LogImportant
std::shared_ptr< JetMatchingHook > fJetMatchingHook
Log< level::Info, false > LogInfo
std::shared_ptr< UserHooks > fReweightUserHook
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
std::shared_ptr< UserHooks > fReweightEmpUserHook
HepMC::Pythia8ToHepMC toHepMC
std::shared_ptr< UserHooks > fReweightPtHatRapUserHook
std::unique_ptr< Pythia8::Pythia > fMasterGen
#define get

◆ ~Pythia8Hadronizer()

Pythia8Hadronizer::~Pythia8Hadronizer ( )
override

Definition at line 341 of file Pythia8Hadronizer.cc.

341 {}

Member Function Documentation

◆ classname()

const char* Pythia8Hadronizer::classname ( ) const
inlineoverridevirtual

Implements gen::Py8InterfaceBase.

Definition at line 95 of file Pythia8Hadronizer.cc.

95 { return "Pythia8Hadronizer"; }

◆ doSetRandomEngine()

void Pythia8Hadronizer::doSetRandomEngine ( CLHEP::HepRandomEngine *  v)
inlineoverrideprivatevirtual

Reimplemented from gen::BaseHadronizer.

Definition at line 100 of file Pythia8Hadronizer.cc.

References findQualityFiles::v.

100 { p8SetRandomEngine(v); }
void p8SetRandomEngine(CLHEP::HepRandomEngine *v)

◆ doSharedResources()

std::vector<std::string> const& Pythia8Hadronizer::doSharedResources ( ) const
inlineoverrideprivatevirtual

Reimplemented from gen::BaseHadronizer.

Definition at line 101 of file Pythia8Hadronizer.cc.

101 { return p8SharedResources; }
static const std::vector< std::string > p8SharedResources

◆ finalizeEvent()

void Pythia8Hadronizer::finalizeEvent ( )
overridevirtual

Implements gen::Py8InterfaceBase.

Definition at line 942 of file Pythia8Hadronizer.cc.

References gen::Py8InterfaceBase::ascii_io, gather_cfg::cout, DJR, relativeConstraints::empty, gen::BaseHadronizer::event(), gen::BaseHadronizer::eventInfo(), gen::Py8InterfaceBase::fMasterGen, gen::BaseHadronizer::lheEvent(), gen::Py8InterfaceBase::maxEventsToPrint, nME, nMEFiltered, push_back(), gen::Py8InterfaceBase::pythiaHepMCVerbosity, gen::Py8InterfaceBase::pythiaHepMCVerbosityParticles, gen::Py8InterfaceBase::pythiaPylistVerbosity, and hltDeepSecondaryVertexTagInfosPFPuppi_cfi::weights.

942  {
943  bool lhe = lheEvent() != nullptr;
944 
945  // protection against empty weight container
946  if ((event()->weights()).empty())
947  (event()->weights()).push_back(1.);
948 
949  // now create the GenEventInfo product from the GenEvent and fill
950  // the missing pieces
951  eventInfo() = std::make_unique<GenEventInfoProduct>(event().get());
952 
953  // in pythia pthat is used to subdivide samples into different bins
954  // in LHE mode the binning is done by the external ME generator
955  // which is likely not pthat, so only filling it for Py6 internal mode
956  if (!lhe) {
957  eventInfo()->setBinningValues(std::vector<double>(1, fMasterGen->info.pTHat()));
958  }
959 
960  eventInfo()->setDJR(DJR);
961  eventInfo()->setNMEPartons(nME);
962  eventInfo()->setNMEPartonsFiltered(nMEFiltered);
963 
964  //******** Verbosity ********
965 
968  if (pythiaPylistVerbosity) {
969  fMasterGen->info.list();
970  fMasterGen->event.list();
971  }
972 
973  if (pythiaHepMCVerbosity) {
974  std::cout << "Event process = " << fMasterGen->info.code() << "\n"
975  << "----------------------" << std::endl;
976  event()->print();
977  }
979  std::cout << "Event process = " << fMasterGen->info.code() << "\n"
980  << "----------------------" << std::endl;
981  ascii_io->write_event(event().get());
982  }
983  }
984 }
HepMC::IO_AsciiParticles * ascii_io
lhef::LHEEvent * lheEvent()
unsigned int pythiaPylistVerbosity
std::unique_ptr< HepMC::GenEvent > & event()
std::unique_ptr< GenEventInfoProduct > & eventInfo()
unsigned int maxEventsToPrint
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
vector< float > DJR
std::unique_ptr< Pythia8::Pythia > fMasterGen

◆ generatePartonsAndHadronize()

bool Pythia8Hadronizer::generatePartonsAndHadronize ( )
overridevirtual

Implements gen::Py8InterfaceBase.

Definition at line 702 of file Pythia8Hadronizer.cc.

References funct::abs(), DJR, gen::BaseHadronizer::event(), gen::Py8InterfaceBase::evtgenDecays, fEmissionVetoHook, fJetMatchingHook, fJetMatchingPy8InternalHook, gen::Py8InterfaceBase::fMasterGen, fMergingHook, mps_fire::i, crabWrapper::key, gen::BaseHadronizer::lheEvent(), SiStripPI::min, nFSRveto, nISRveto, nME, nMEFiltered, and gen::Py8InterfaceBase::toHepMC.

702  {
703  DJR.resize(0);
704  nME = -1;
705  nMEFiltered = -1;
706 
707  if (fJetMatchingHook.get()) {
708  fJetMatchingHook->resetMatchingStatus();
709  fJetMatchingHook->beforeHadronization(lheEvent());
710  }
711 
712  if (!fMasterGen->next())
713  return false;
714 
715  double mergeweight = fMasterGen.get()->info.mergingWeightNLO();
716  if (fMergingHook.get()) {
717  mergeweight *= fMergingHook->getNormFactor();
718  }
719 
720  //protect against 0-weight from ckkw or similar
721  if (std::abs(mergeweight) == 0.) {
722  event().reset();
723  return false;
724  }
725 
726  if (fJetMatchingPy8InternalHook.get()) {
727  const std::vector<double> djrmatch = fJetMatchingPy8InternalHook->getDJR();
728  //cap size of djr vector to save storage space (keep only up to first 6 elements)
729  unsigned int ndjr = std::min(djrmatch.size(), std::vector<double>::size_type(6));
730  for (unsigned int idjr = 0; idjr < ndjr; ++idjr) {
731  DJR.push_back(djrmatch[idjr]);
732  }
733 
734  nME = fJetMatchingPy8InternalHook->nMEpartons().first;
735  nMEFiltered = fJetMatchingPy8InternalHook->nMEpartons().second;
736  }
737 
738  if (evtgenDecays.get())
739  evtgenDecays->decay();
740 
741  event() = std::make_unique<HepMC::GenEvent>();
742  bool py8hepmc = toHepMC.fill_next_event(*(fMasterGen.get()), event().get());
743 
744  if (!py8hepmc) {
745  return false;
746  }
747 
748  // 0th weight is not filled anymore since v8.30x, pushback manually
749  event()->weights().push_back(fMasterGen->info.weight());
750 
751  //add ckkw/umeps/unlops merging weight
752  if (mergeweight != 1.) {
753  event()->weights()[0] *= mergeweight;
754  }
755 
756  if (fEmissionVetoHook.get()) {
757  nISRveto += fEmissionVetoHook->getNISRveto();
758  nFSRveto += fEmissionVetoHook->getNFSRveto();
759  }
760 
761  //fill additional weights for systematic uncertainties
762  if (fMasterGen->info.getWeightsDetailedSize() > 0) {
763  for (const string &key : fMasterGen->info.initrwgt->weightsKeys) {
764  double wgt = (*fMasterGen->info.weights_detailed)[key];
765  event()->weights().push_back(wgt);
766  }
767  } else if (fMasterGen->info.getWeightsCompressedSize() > 0) {
768  for (unsigned int i = 0; i < fMasterGen->info.getWeightsCompressedSize(); i++) {
769  double wgt = fMasterGen->info.getWeightsCompressedValue(i);
770  event()->weights().push_back(wgt);
771  }
772  }
773 
774  // fill shower weights
775  // http://home.thep.lu.se/~torbjorn/pythia82html/Variations.html
776  if (fMasterGen->info.nWeights() > 1) {
777  for (int i = 0; i < fMasterGen->info.nWeights(); ++i) {
778  double wgt = fMasterGen->info.weight(i);
779  event()->weights().push_back(wgt);
780  }
781  }
782 
783 #if 0
784  // VINCIA shower weights
785  // http://vincia.hepforge.org/current/share/Vincia/htmldoc/VinciaUncertainties.html
786  if (fvincia.get()) {
787  event()->weights()[0] *= fvincia->weight(0);
788  for (int iVar = 1; iVar < fvincia->nWeights(); iVar++) {
789  event()->weights().push_back(fvincia->weight(iVar));
790  }
791  }
792 
793  // Retrieve Dire shower weights
794  if (fDire.get()) {
795  fDire->weightsPtr->calcWeight(0.);
796  fDire->weightsPtr->reset();
797 
798  //Make sure the base weight comes first
799  event()->weights()[0] *= fDire->weightsPtr->getShowerWeight("base");
800 
801  unordered_map<string, double>::iterator it;
802  for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
803  it++) {
804  if (it->first == "base")
805  continue;
806  event()->weights().push_back(it->second);
807  }
808  }
809 #endif
810 
811  return true;
812 }
std::shared_ptr< PowhegHooks > fEmissionVetoHook
std::shared_ptr< Pythia8::EvtGenDecays > evtgenDecays
uint16_t size_type
lhef::LHEEvent * lheEvent()
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::shared_ptr< Pythia8::JetMatchingMadgraph > fJetMatchingPy8InternalHook
std::unique_ptr< HepMC::GenEvent > & event()
std::shared_ptr< JetMatchingHook > fJetMatchingHook
std::shared_ptr< Pythia8::amcnlo_unitarised_interface > fMergingHook
vector< float > DJR
HepMC::Pythia8ToHepMC toHepMC
std::unique_ptr< Pythia8::Pythia > fMasterGen

◆ getGenLumiInfoHeader()

std::unique_ptr< GenLumiInfoHeader > Pythia8Hadronizer::getGenLumiInfoHeader ( ) const
overridevirtual

Reimplemented from gen::BaseHadronizer.

Definition at line 986 of file Pythia8Hadronizer.cc.

References gen::Py8InterfaceBase::fMasterGen, genWeightsTable_cfi::genLumiInfoHeader, mps_fire::i, crabWrapper::key, and AlCaHLTBitMon_QueryRunRegistry::string.

986  {
987  auto genLumiInfoHeader = BaseHadronizer::getGenLumiInfoHeader();
988 
989  //fill lhe headers
990  //*FIXME* initrwgt header is corrupt due to pythia bug
991  for (const std::string &key : fMasterGen->info.headerKeys()) {
992  genLumiInfoHeader->lheHeaders().emplace_back(key, fMasterGen->info.header(key));
993  }
994 
995  //check, if it is not only nominal weight
996  int weights_number = fMasterGen->info.nWeights();
997  if (fMasterGen->info.initrwgt)
998  weights_number += fMasterGen->info.initrwgt->weightsKeys.size();
999  if (weights_number > 1) {
1000  genLumiInfoHeader->weightNames().reserve(weights_number + 1);
1001  genLumiInfoHeader->weightNames().push_back("nominal");
1002  }
1003 
1004  //fill weight names
1005  if (fMasterGen->info.initrwgt) {
1006  for (const std::string &key : fMasterGen->info.initrwgt->weightsKeys) {
1007  std::string weightgroupname;
1008  for (const auto &wgtgrp : fMasterGen->info.initrwgt->weightgroups) {
1009  const auto &wgtgrpwgt = wgtgrp.second.weights.find(key);
1010  if (wgtgrpwgt != wgtgrp.second.weights.end()) {
1011  weightgroupname = wgtgrp.first;
1012  }
1013  }
1014 
1015  std::ostringstream weightname;
1016  weightname << "LHE, id = " << key << ", ";
1017  if (!weightgroupname.empty()) {
1018  weightname << "group = " << weightgroupname << ", ";
1019  }
1020  weightname << fMasterGen->info.initrwgt->weights[key].contents;
1021  genLumiInfoHeader->weightNames().push_back(weightname.str());
1022  }
1023  }
1024 
1025  //fill shower labels
1026  // http://home.thep.lu.se/~torbjorn/pythia82html/Variations.html
1027  // http://home.thep.lu.se/~torbjorn/doxygen/classPythia8_1_1Info.html
1028  if (fMasterGen->info.nWeights() > 1) {
1029  for (int i = 0; i < fMasterGen->info.nWeights(); ++i) {
1030  genLumiInfoHeader->weightNames().push_back(fMasterGen->info.weightLabel(i));
1031  }
1032  }
1033 
1034 #if 0
1035  // VINCIA shower weights
1036  // http://vincia.hepforge.org/current/share/Vincia/htmldoc/VinciaUncertainties.html
1037  if (fvincia.get()) {
1038  for (int iVar = 0; iVar < fvincia->nWeights(); iVar++) {
1039  genLumiInfoHeader->weightNames().push_back(fvincia->weightLabel(iVar));
1040  }
1041  }
1042 
1043  if (fDire.get()) {
1044  //Make sure the base weight comes first
1045  genLumiInfoHeader->weightNames().push_back("base");
1046 
1047  unordered_map<string, double>::iterator it;
1048  for (it = fDire->weightsPtr->getShowerWeights()->begin(); it != fDire->weightsPtr->getShowerWeights()->end();
1049  it++) {
1050  if (it->first == "base")
1051  continue;
1052  genLumiInfoHeader->weightNames().push_back(it->first);
1053  }
1054  }
1055 #endif
1056 
1057  return genLumiInfoHeader;
1058 }
std::unique_ptr< Pythia8::Pythia > fMasterGen

◆ hadronize()

bool Pythia8Hadronizer::hadronize ( )

Definition at line 814 of file Pythia8Hadronizer.cc.

References funct::abs(), lhef::LHEEvent::count(), DJR, gen::BaseHadronizer::event(), gen::Py8InterfaceBase::evtgenDecays, fEmissionVetoHook, fJetMatchingHook, fJetMatchingPy8InternalHook, gen::Py8InterfaceBase::fMasterGen, fMergingHook, mps_fire::i, lhef::LHERunInfo::kAccepted, lhef::LHERunInfo::kSelected, lhaUP, gen::BaseHadronizer::lheEvent(), LHEInputFileName, SiStripPI::min, nFSRveto, nISRveto, nME, nMEFiltered, and gen::Py8InterfaceBase::toHepMC.

814  {
815  DJR.resize(0);
816  nME = -1;
817  nMEFiltered = -1;
818  if (LHEInputFileName.empty())
819  lhaUP->loadEvent(lheEvent());
820 
821  if (fJetMatchingHook.get()) {
822  fJetMatchingHook->resetMatchingStatus();
823  fJetMatchingHook->beforeHadronization(lheEvent());
824  }
825 
826  bool py8next = fMasterGen->next();
827 
828  double mergeweight = fMasterGen.get()->info.mergingWeightNLO();
829  if (fMergingHook.get()) {
830  mergeweight *= fMergingHook->getNormFactor();
831  }
832 
833  //protect against 0-weight from ckkw or similar
834  if (!py8next || std::abs(mergeweight) == 0.) {
835  lheEvent()->count(lhef::LHERunInfo::kSelected, 1.0, mergeweight);
836  event().reset();
837  return false;
838  }
839 
840  if (fJetMatchingPy8InternalHook.get()) {
841  const std::vector<double> djrmatch = fJetMatchingPy8InternalHook->getDJR();
842  //cap size of djr vector to save storage space (keep only up to first 6 elements)
843  unsigned int ndjr = std::min(djrmatch.size(), std::vector<double>::size_type(6));
844  for (unsigned int idjr = 0; idjr < ndjr; ++idjr) {
845  DJR.push_back(djrmatch[idjr]);
846  }
847 
848  nME = fJetMatchingPy8InternalHook->nMEpartons().first;
849  nMEFiltered = fJetMatchingPy8InternalHook->nMEpartons().second;
850  }
851 
852  // update LHE matching statistics
853  //
854  lheEvent()->count(lhef::LHERunInfo::kAccepted, 1.0, mergeweight);
855 
856  if (evtgenDecays.get())
857  evtgenDecays->decay();
858 
859  event() = std::make_unique<HepMC::GenEvent>();
860 
861  bool py8hepmc = toHepMC.fill_next_event(*(fMasterGen.get()), event().get());
862 
863  if (!py8hepmc) {
864  return false;
865  }
866 
867  // 0th weight is not filled anymore since v8.30x, pushback manually
868  event()->weights().push_back(fMasterGen->info.weight());
869 
870  //add ckkw/umeps/unlops merging weight
871  if (mergeweight != 1.) {
872  event()->weights()[0] *= mergeweight;
873  }
874 
875  if (fEmissionVetoHook.get()) {
876  nISRveto += fEmissionVetoHook->getNISRveto();
877  nFSRveto += fEmissionVetoHook->getNFSRveto();
878  }
879 
880  // fill shower weights
881  // http://home.thep.lu.se/~torbjorn/pythia82html/Variations.html
882  if (fMasterGen->info.nWeights() > 1) {
883  for (int i = 0; i < fMasterGen->info.nWeights(); ++i) {
884  double wgt = fMasterGen->info.weight(i);
885  event()->weights().push_back(wgt);
886  }
887  }
888 
889  return true;
890 }
std::shared_ptr< PowhegHooks > fEmissionVetoHook
std::shared_ptr< Pythia8::EvtGenDecays > evtgenDecays
std::string LHEInputFileName
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
Definition: LHEEvent.cc:184
uint16_t size_type
std::shared_ptr< LHAupLesHouches > lhaUP
lhef::LHEEvent * lheEvent()
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::shared_ptr< Pythia8::JetMatchingMadgraph > fJetMatchingPy8InternalHook
std::unique_ptr< HepMC::GenEvent > & event()
std::shared_ptr< JetMatchingHook > fJetMatchingHook
std::shared_ptr< Pythia8::amcnlo_unitarised_interface > fMergingHook
vector< float > DJR
HepMC::Pythia8ToHepMC toHepMC
std::unique_ptr< Pythia8::Pythia > fMasterGen

◆ initializeForExternalPartons()

bool Pythia8Hadronizer::initializeForExternalPartons ( )

Definition at line 515 of file Pythia8Hadronizer.cc.

References l1ct::clear(), edm::errors::Configuration, gen::Py8InterfaceBase::evtgenDecays, gen::Py8InterfaceBase::evtgenDecFile, gen::Py8InterfaceBase::evtgenPdlFile, gen::Py8InterfaceBase::evtgenUserFiles, Exception, fBiasedTauDecayer, fCustomHooksVector, gen::Py8InterfaceBase::fDecayer, fEmissionVetoHook, fEmissionVetoHook1, fJetMatchingHook, fJetMatchingPy8InternalHook, gen::Py8InterfaceBase::fMasterGen, fMergingHook, fPowhegHooksBB4L, fPowhegResHook, fPTFilterHook, fResonanceDecayFilterHook, fReweightEmpUserHook, fReweightPtHatRapUserHook, fReweightRapUserHook, fReweightUserHook, fUserHooksVector, mps_fire::i, lhaUP, LHEInputFileName, gen::BaseHadronizer::lheRunInfo(), push_back(), gen::Py8InterfaceBase::pythiaPylistVerbosity, MatrixUtil::remove(), generator_cfi::scheme, gen::Py8InterfaceBase::slhafile_, mps_update::status, gen::Py8InterfaceBase::useEvtGen, and UserHooksSet.

515  {
516  edm::LogInfo("Pythia8Interface") << "Initializing for external partons";
517 
518  bool status = false, status1 = false;
519 
520  if (!fUserHooksVector.get())
521  fUserHooksVector.reset(new UserHooksVector);
522  (fUserHooksVector->hooks).clear();
523 
524  if (fReweightUserHook.get())
525  (fUserHooksVector->hooks).push_back(fReweightUserHook);
526  if (fReweightEmpUserHook.get())
527  (fUserHooksVector->hooks).push_back(fReweightEmpUserHook);
528  if (fReweightRapUserHook.get())
529  (fUserHooksVector->hooks).push_back(fReweightRapUserHook);
530  if (fReweightPtHatRapUserHook.get())
531  (fUserHooksVector->hooks).push_back(fReweightPtHatRapUserHook);
532  if (fJetMatchingHook.get())
533  (fUserHooksVector->hooks).push_back(fJetMatchingHook);
534  if (fEmissionVetoHook1.get()) {
535  edm::LogInfo("Pythia8Interface") << "Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
537  }
538 
539  if (fCustomHooksVector.get()) {
540  edm::LogInfo("Pythia8Interface") << "Adding customized user hook";
541  for (const auto &fUserHook : fCustomHooksVector->hooks) {
542  (fUserHooksVector->hooks).push_back(fUserHook);
543  }
544  }
545 
546  if (fMasterGen->settings.mode("POWHEG:veto") > 0 || fMasterGen->settings.mode("POWHEG:MPIveto") > 0) {
547  if (fJetMatchingHook.get() || fEmissionVetoHook1.get())
548  throw edm::Exception(edm::errors::Configuration, "Pythia8Interface")
549  << " Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible "
550  "are : jetMatching, emissionVeto1 \n";
551 
552  if (!fEmissionVetoHook.get())
553  fEmissionVetoHook.reset(new PowhegHooks());
554 
555  edm::LogInfo("Pythia8Interface") << "Turning on Emission Veto Hook from pythia8 code";
557  }
558 
559  bool PowhegRes = fMasterGen->settings.flag("POWHEGres:calcScales");
560  if (PowhegRes) {
561  edm::LogInfo("Pythia8Interface") << "Turning on resonance scale setting from CMSSW Pythia8Interface";
562  if (!fPowhegResHook.get())
563  fPowhegResHook.reset(new PowhegResHook());
565  }
566 
567  bool PowhegBB4L = fMasterGen->settings.flag("POWHEG:bb4l");
568  if (PowhegBB4L) {
569  edm::LogInfo("Pythia8Interface") << "Turning on BB4l hook from CMSSW Pythia8Interface";
570  if (!fPowhegHooksBB4L.get())
571  fPowhegHooksBB4L.reset(new PowhegHooksBB4L());
573  }
574 
575  //adapted from main89.cc in pythia8 examples
576  bool internalMatching = fMasterGen->settings.flag("JetMatching:merge");
577  bool internalMerging = !(fMasterGen->settings.word("Merging:Process") == "void");
578 
579  if (internalMatching && internalMerging) {
580  throw edm::Exception(edm::errors::Configuration, "Pythia8Interface")
581  << " Only one jet matching/merging scheme can be used at a time. \n";
582  }
583 
584  if (internalMatching) {
585  if (!fJetMatchingPy8InternalHook.get())
586  fJetMatchingPy8InternalHook.reset(new Pythia8::JetMatchingMadgraph);
588  }
589 
590  if (internalMerging) {
591  int scheme = (fMasterGen->settings.flag("Merging:doUMEPSTree") || fMasterGen->settings.flag("Merging:doUMEPSSubt"))
592  ? 1
593  : ((fMasterGen->settings.flag("Merging:doUNLOPSTree") ||
594  fMasterGen->settings.flag("Merging:doUNLOPSSubt") ||
595  fMasterGen->settings.flag("Merging:doUNLOPSLoop") ||
596  fMasterGen->settings.flag("Merging:doUNLOPSSubtNLO"))
597  ? 2
598  : 0);
599  if (!fMergingHook.get())
600  fMergingHook.reset(new Pythia8::amcnlo_unitarised_interface(scheme));
602  }
603 
604  bool biasedTauDecayer = fMasterGen->settings.flag("BiasedTauDecayer:filter");
605  if (biasedTauDecayer) {
606  if (!fBiasedTauDecayer.get()) {
607  Pythia8::Info localInfo = fMasterGen->info;
608  fBiasedTauDecayer.reset(new BiasedTauDecayer(&localInfo, &(fMasterGen->settings)));
609  }
610  std::vector<int> handledParticles;
611  handledParticles.push_back(15);
612  fMasterGen->setDecayPtr(fBiasedTauDecayer, handledParticles);
613  }
614 
615  bool resonanceDecayFilter = fMasterGen->settings.flag("ResonanceDecayFilter:filter");
616  if (resonanceDecayFilter) {
619  }
620 
621  bool PTFilter = fMasterGen->settings.flag("PTFilter:filter");
622  if (PTFilter) {
623  fPTFilterHook.reset(new PTFilterHook);
625  }
626 
627  if (!(fUserHooksVector->hooks).empty() && !UserHooksSet) {
628  for (auto &fUserHook : fUserHooksVector->hooks) {
629  fMasterGen->addUserHooksPtr(fUserHook);
630  }
631  UserHooksSet = true;
632  }
633 
634  if (!LHEInputFileName.empty()) {
635  edm::LogInfo("Pythia8Interface") << "Initialize direct pythia8 reading from LHE file " << LHEInputFileName;
636  edm::LogInfo("Pythia8Interface") << "Some LHE information can be not stored";
637  fMasterGen->settings.mode("Beams:frameType", 4);
638  fMasterGen->settings.word("Beams:LHEF", LHEInputFileName);
639  status = fMasterGen->init();
640 
641  } else {
642  lhaUP.reset(new LHAupLesHouches());
643  lhaUP->setScalesFromLHEF(fMasterGen->settings.flag("Beams:setProductionScalesFromLHEF"));
644  lhaUP->loadRunInfo(lheRunInfo());
645 
646  if (fJetMatchingHook.get()) {
647  fJetMatchingHook->init(lheRunInfo());
648  }
649 
650  fMasterGen->settings.mode("Beams:frameType", 5);
651  fMasterGen->setLHAupPtr(lhaUP);
652  edm::LogInfo("Pythia8Interface") << "Initializing MasterGen";
653  status = fMasterGen->init();
654  }
655 
656  //clean up temp file
657  if (!slhafile_.empty()) {
658  std::remove(slhafile_.c_str());
659  }
660 
661  if (pythiaPylistVerbosity > 10) {
662  if (pythiaPylistVerbosity == 11 || pythiaPylistVerbosity == 13)
663  fMasterGen->settings.listAll();
664  if (pythiaPylistVerbosity == 12 || pythiaPylistVerbosity == 13)
665  fMasterGen->particleData.listAll();
666  }
667 
668  // init decayer
669  fDecayer->settings.flag("ProcessLevel:all", false); // trick
670  fDecayer->settings.flag("ProcessLevel:resonanceDecays", true);
671  edm::LogInfo("Pythia8Interface") << "Initializing Decayer";
672  status1 = fDecayer->init();
673 
674  if (useEvtGen) {
675  edm::LogInfo("Pythia8Hadronizer") << "Creating and initializing pythia8 EvtGen plugin";
676  if (!evtgenDecays.get()) {
677  evtgenDecays.reset(new EvtGenDecays(fMasterGen.get(), evtgenDecFile, evtgenPdlFile));
678  for (unsigned int i = 0; i < evtgenUserFiles.size(); i++)
679  evtgenDecays->readDecayFile(evtgenUserFiles.at(i));
680  }
681  }
682 
683  return (status && status1);
684 }
std::shared_ptr< PowhegHooksBB4L > fPowhegHooksBB4L
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
std::string LHEInputFileName
std::shared_ptr< UserHooks > fReweightRapUserHook
std::shared_ptr< LHAupLesHouches > lhaUP
std::vector< std::string > evtgenUserFiles
std::shared_ptr< UserHooksVector > fCustomHooksVector
std::shared_ptr< ResonanceDecayFilterHook > fResonanceDecayFilterHook
std::shared_ptr< UserHooksVector > fUserHooksVector
unsigned int pythiaPylistVerbosity
std::shared_ptr< PTFilterHook > fPTFilterHook
std::shared_ptr< Pythia8::JetMatchingMadgraph > fJetMatchingPy8InternalHook
lhef::LHERunInfo * lheRunInfo()
std::shared_ptr< JetMatchingHook > fJetMatchingHook
Log< level::Info, false > LogInfo
std::shared_ptr< UserHooks > fReweightUserHook
std::shared_ptr< Pythia8::amcnlo_unitarised_interface > fMergingHook
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:223
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
std::shared_ptr< UserHooks > fReweightEmpUserHook
std::shared_ptr< PowhegResHook > fPowhegResHook
std::shared_ptr< UserHooks > fReweightPtHatRapUserHook
std::unique_ptr< Pythia8::Pythia > fMasterGen
void clear(EGIsoObj &c)
Definition: egamma.h:82

◆ initializeForInternalPartons()

bool Pythia8Hadronizer::initializeForInternalPartons ( )
overridevirtual

Implements gen::Py8InterfaceBase.

Definition at line 343 of file Pythia8Hadronizer.cc.

References l1ct::clear(), comEnergy, edm::errors::Configuration, ElectronPositron, gen::Py8InterfaceBase::evtgenDecays, gen::Py8InterfaceBase::evtgenDecFile, gen::Py8InterfaceBase::evtgenPdlFile, gen::Py8InterfaceBase::evtgenUserFiles, Exception, fBiasedTauDecayer, fCustomHooksVector, gen::Py8InterfaceBase::fDecayer, fEmissionVetoHook, fEmissionVetoHook1, fInitialState, fJetMatchingHook, fJetMatchingPy8InternalHook, gen::Py8InterfaceBase::fMasterGen, fMergingHook, fPowhegHooksBB4L, fPowhegResHook, fPTFilterHook, fResonanceDecayFilterHook, fReweightEmpUserHook, fReweightPtHatRapUserHook, fReweightRapUserHook, fReweightUserHook, fUserHooksVector, mps_fire::i, gen::BaseHadronizer::lheFile_, PP, PPbar, push_back(), gen::Py8InterfaceBase::pythiaPylistVerbosity, MatrixUtil::remove(), generator_cfi::scheme, gen::Py8InterfaceBase::slhafile_, mps_update::status, gen::Py8InterfaceBase::useEvtGen, and UserHooksSet.

343  {
344  bool status = false, status1 = false;
345 
346  if (lheFile_.empty()) {
347  if (fInitialState == PP) // default
348  {
349  fMasterGen->settings.mode("Beams:idA", 2212);
350  fMasterGen->settings.mode("Beams:idB", 2212);
351  } else if (fInitialState == PPbar) {
352  fMasterGen->settings.mode("Beams:idA", 2212);
353  fMasterGen->settings.mode("Beams:idB", -2212);
354  } else if (fInitialState == ElectronPositron) {
355  fMasterGen->settings.mode("Beams:idA", 11);
356  fMasterGen->settings.mode("Beams:idB", -11);
357  } else {
358  // throw on unknown initial state !
359  throw edm::Exception(edm::errors::Configuration, "Pythia8Interface")
360  << " UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
361  }
362  fMasterGen->settings.parm("Beams:eCM", comEnergy);
363  } else {
364  fMasterGen->settings.mode("Beams:frameType", 4);
365  fMasterGen->settings.word("Beams:LHEF", lheFile_);
366  }
367 
368  if (!fUserHooksVector.get())
369  fUserHooksVector.reset(new UserHooksVector);
370  (fUserHooksVector->hooks).clear();
371 
372  if (fReweightUserHook.get())
373  (fUserHooksVector->hooks).push_back(fReweightUserHook);
374  if (fReweightEmpUserHook.get())
375  (fUserHooksVector->hooks).push_back(fReweightEmpUserHook);
376  if (fReweightRapUserHook.get())
377  (fUserHooksVector->hooks).push_back(fReweightRapUserHook);
378  if (fReweightPtHatRapUserHook.get())
379  (fUserHooksVector->hooks).push_back(fReweightPtHatRapUserHook);
380  if (fJetMatchingHook.get())
381  (fUserHooksVector->hooks).push_back(fJetMatchingHook);
382  if (fEmissionVetoHook1.get()) {
383  edm::LogInfo("Pythia8Interface") << "Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
385  }
386 
387  if (fMasterGen->settings.mode("POWHEG:veto") > 0 || fMasterGen->settings.mode("POWHEG:MPIveto") > 0) {
388  if (fJetMatchingHook.get() || fEmissionVetoHook1.get())
389  throw edm::Exception(edm::errors::Configuration, "Pythia8Interface")
390  << " Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible "
391  "are : jetMatching, emissionVeto1 \n";
392 
393  if (!fEmissionVetoHook.get())
394  fEmissionVetoHook.reset(new PowhegHooks());
395 
396  edm::LogInfo("Pythia8Interface") << "Turning on Emission Veto Hook from pythia8 code";
398  }
399 
400  bool PowhegRes = fMasterGen->settings.flag("POWHEGres:calcScales");
401  if (PowhegRes) {
402  edm::LogInfo("Pythia8Interface") << "Turning on resonance scale setting from CMSSW Pythia8Interface";
403  if (!fPowhegResHook.get())
404  fPowhegResHook.reset(new PowhegResHook());
406  }
407 
408  bool PowhegBB4L = fMasterGen->settings.flag("POWHEG:bb4l");
409  if (PowhegBB4L) {
410  edm::LogInfo("Pythia8Interface") << "Turning on BB4l hook from CMSSW Pythia8Interface";
411  if (!fPowhegHooksBB4L.get())
412  fPowhegHooksBB4L.reset(new PowhegHooksBB4L());
414  }
415 
416  //adapted from main89.cc in pythia8 examples
417  bool internalMatching = fMasterGen->settings.flag("JetMatching:merge");
418  bool internalMerging = !(fMasterGen->settings.word("Merging:Process") == "void");
419 
420  if (internalMatching && internalMerging) {
421  throw edm::Exception(edm::errors::Configuration, "Pythia8Interface")
422  << " Only one jet matching/merging scheme can be used at a time. \n";
423  }
424 
425  if (internalMatching) {
426  if (!fJetMatchingPy8InternalHook.get())
427  fJetMatchingPy8InternalHook.reset(new Pythia8::JetMatchingMadgraph);
429  }
430 
431  if (internalMerging) {
432  int scheme = (fMasterGen->settings.flag("Merging:doUMEPSTree") || fMasterGen->settings.flag("Merging:doUMEPSSubt"))
433  ? 1
434  : ((fMasterGen->settings.flag("Merging:doUNLOPSTree") ||
435  fMasterGen->settings.flag("Merging:doUNLOPSSubt") ||
436  fMasterGen->settings.flag("Merging:doUNLOPSLoop") ||
437  fMasterGen->settings.flag("Merging:doUNLOPSSubtNLO"))
438  ? 2
439  : 0);
440  if (!fMergingHook.get())
441  fMergingHook.reset(new Pythia8::amcnlo_unitarised_interface(scheme));
443  }
444 
445  bool biasedTauDecayer = fMasterGen->settings.flag("BiasedTauDecayer:filter");
446  if (biasedTauDecayer) {
447  if (!fBiasedTauDecayer.get()) {
448  Pythia8::Info localInfo = fMasterGen->info;
449  fBiasedTauDecayer.reset(new BiasedTauDecayer(&localInfo, &(fMasterGen->settings)));
450  }
451  std::vector<int> handledParticles;
452  handledParticles.push_back(15);
453  fMasterGen->setDecayPtr(fBiasedTauDecayer, handledParticles);
454  }
455 
456  bool resonanceDecayFilter = fMasterGen->settings.flag("ResonanceDecayFilter:filter");
457  if (resonanceDecayFilter) {
460  }
461 
462  bool PTFilter = fMasterGen->settings.flag("PTFilter:filter");
463  if (PTFilter) {
464  fPTFilterHook.reset(new PTFilterHook);
466  }
467 
468  if (!(fUserHooksVector->hooks).empty() && !UserHooksSet) {
469  for (auto &fUserHook : fUserHooksVector->hooks) {
470  fMasterGen->addUserHooksPtr(fUserHook);
471  }
472  UserHooksSet = true;
473  }
474 
475  if (fCustomHooksVector.get()) {
476  edm::LogInfo("Pythia8Interface") << "Adding customized user hooks";
477  for (const auto &fUserHook : fCustomHooksVector->hooks) {
478  fMasterGen->addUserHooksPtr(fUserHook);
479  }
480  }
481 
482  edm::LogInfo("Pythia8Interface") << "Initializing MasterGen";
483  status = fMasterGen->init();
484 
485  //clean up temp file
486  if (!slhafile_.empty()) {
487  std::remove(slhafile_.c_str());
488  }
489 
490  if (pythiaPylistVerbosity > 10) {
491  if (pythiaPylistVerbosity == 11 || pythiaPylistVerbosity == 13)
492  fMasterGen->settings.listAll();
493  if (pythiaPylistVerbosity == 12 || pythiaPylistVerbosity == 13)
494  fMasterGen->particleData.listAll();
495  }
496 
497  // init decayer
498  fDecayer->settings.flag("ProcessLevel:all", false); // trick
499  fDecayer->settings.flag("ProcessLevel:resonanceDecays", true);
500  edm::LogInfo("Pythia8Interface") << "Initializing Decayer";
501  status1 = fDecayer->init();
502 
503  if (useEvtGen) {
504  edm::LogInfo("Pythia8Hadronizer") << "Creating and initializing pythia8 EvtGen plugin";
505  if (!evtgenDecays.get()) {
506  evtgenDecays.reset(new EvtGenDecays(fMasterGen.get(), evtgenDecFile, evtgenPdlFile));
507  for (unsigned int i = 0; i < evtgenUserFiles.size(); i++)
508  evtgenDecays->readDecayFile(evtgenUserFiles.at(i));
509  }
510  }
511 
512  return (status && status1);
513 }
std::shared_ptr< PowhegHooksBB4L > fPowhegHooksBB4L
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
std::shared_ptr< UserHooks > fReweightRapUserHook
std::vector< std::string > evtgenUserFiles
std::shared_ptr< UserHooksVector > fCustomHooksVector
std::shared_ptr< ResonanceDecayFilterHook > fResonanceDecayFilterHook
std::shared_ptr< UserHooksVector > fUserHooksVector
unsigned int pythiaPylistVerbosity
std::shared_ptr< PTFilterHook > fPTFilterHook
std::shared_ptr< Pythia8::JetMatchingMadgraph > fJetMatchingPy8InternalHook
std::shared_ptr< JetMatchingHook > fJetMatchingHook
Log< level::Info, false > LogInfo
std::shared_ptr< UserHooks > fReweightUserHook
std::shared_ptr< Pythia8::amcnlo_unitarised_interface > fMergingHook
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:223
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
std::shared_ptr< UserHooks > fReweightEmpUserHook
std::shared_ptr< PowhegResHook > fPowhegResHook
std::shared_ptr< UserHooks > fReweightPtHatRapUserHook
std::unique_ptr< Pythia8::Pythia > fMasterGen
void clear(EGIsoObj &c)
Definition: egamma.h:82

◆ residualDecay()

bool Pythia8Hadronizer::residualDecay ( )
virtual

Definition at line 892 of file Pythia8Hadronizer.cc.

References gen::BaseHadronizer::event(), gen::Py8InterfaceBase::fDecayer, gen::Py8InterfaceBase::fMasterGen, GenParticle::GenParticle, mps_fire::result, and gen::Py8InterfaceBase::toHepMC.

892  {
893  Event *pythiaEvent = &(fMasterGen->event);
894 
895  int NPartsBeforeDecays = pythiaEvent->size();
896  int NPartsAfterDecays = event().get()->particles_size();
897 
898  if (NPartsAfterDecays == NPartsBeforeDecays)
899  return true;
900 
901  bool result = true;
902 
903  for (int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
904  HepMC::GenParticle *part = event().get()->barcode_to_particle(ipart);
905 
906  if (part->status() == 1 && (fDecayer->particleData).canDecay(part->pdg_id())) {
907  fDecayer->event.reset();
908  Particle py8part(part->pdg_id(),
909  93,
910  0,
911  0,
912  0,
913  0,
914  0,
915  0,
916  part->momentum().x(),
917  part->momentum().y(),
918  part->momentum().z(),
919  part->momentum().t(),
920  part->generated_mass());
921  HepMC::GenVertex *ProdVtx = part->production_vertex();
922  py8part.vProd(ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
923  py8part.tau((fDecayer->particleData).tau0(part->pdg_id()));
924  fDecayer->event.append(py8part);
925  int nentries = fDecayer->event.size();
926  if (!fDecayer->event[nentries - 1].mayDecay())
927  continue;
928  fDecayer->next();
929  int nentries1 = fDecayer->event.size();
930  if (nentries1 <= nentries)
931  continue; //same number of particles, no decays...
932 
933  part->set_status(2);
934 
935  result = toHepMC.fill_next_event(*(fDecayer.get()), event().get(), -1, true, part);
936  }
937  }
938 
939  return result;
940 }
std::unique_ptr< Pythia8::Pythia > fDecayer
std::unique_ptr< HepMC::GenEvent > & event()
part
Definition: HCALResponse.h:20
HepMC::Pythia8ToHepMC toHepMC
std::unique_ptr< Pythia8::Pythia > fMasterGen

◆ statistics()

void Pythia8Hadronizer::statistics ( )
overridevirtual

Reimplemented from gen::Py8InterfaceBase.

Definition at line 686 of file Pythia8Hadronizer.cc.

References submitPVResolutionJobs::err, fEmissionVetoHook, gen::Py8InterfaceBase::fMasterGen, nFSRveto, nISRveto, gen::BaseHadronizer::runInfo(), and GenRunInfoProduct::setInternalXSec().

686  {
687  fMasterGen->stat();
688 
689  if (fEmissionVetoHook.get()) {
690  edm::LogPrint("Pythia8Interface") << "\n"
691  << "Number of ISR vetoed = " << nISRveto;
692  edm::LogPrint("Pythia8Interface") << "Number of FSR vetoed = " << nFSRveto;
693  }
694 
695  double xsec = fMasterGen->info.sigmaGen(); // cross section in mb
696  xsec *= 1.0e9; // translate to pb (CMS/Gen "convention" as of May 2009)
697  double err = fMasterGen->info.sigmaErr(); // cross section err in mb
698  err *= 1.0e9; // translate to pb (CMS/Gen "convention" as of May 2009)
700 }
std::shared_ptr< PowhegHooks > fEmissionVetoHook
void setInternalXSec(const XSec &xsec)
GenRunInfoProduct & runInfo()
Log< level::Warning, true > LogPrint
std::unique_ptr< Pythia8::Pythia > fMasterGen

Member Data Documentation

◆ comEnergy

double Pythia8Hadronizer::comEnergy
private

Center-of-Mass energy.

Definition at line 104 of file Pythia8Hadronizer.cc.

Referenced by initializeForInternalPartons().

◆ DJR

vector<float> Pythia8Hadronizer::DJR
private

Definition at line 166 of file Pythia8Hadronizer.cc.

Referenced by finalizeEvent(), generatePartonsAndHadronize(), and hadronize().

◆ EV1_emittedMode

int Pythia8Hadronizer::EV1_emittedMode
private

Definition at line 158 of file Pythia8Hadronizer.cc.

Referenced by Pythia8Hadronizer().

◆ EV1_maxVetoCount

int Pythia8Hadronizer::EV1_maxVetoCount
private

Definition at line 155 of file Pythia8Hadronizer.cc.

Referenced by Pythia8Hadronizer().

◆ EV1_MPIvetoOn

bool Pythia8Hadronizer::EV1_MPIvetoOn
private

Definition at line 160 of file Pythia8Hadronizer.cc.

Referenced by Pythia8Hadronizer().

◆ EV1_nFinal

int Pythia8Hadronizer::EV1_nFinal
private

Definition at line 153 of file Pythia8Hadronizer.cc.

Referenced by Pythia8Hadronizer().

◆ EV1_nFinalMode

int Pythia8Hadronizer::EV1_nFinalMode
private

Definition at line 162 of file Pythia8Hadronizer.cc.

Referenced by Pythia8Hadronizer().

◆ EV1_pTdefMode

int Pythia8Hadronizer::EV1_pTdefMode
private

Definition at line 159 of file Pythia8Hadronizer.cc.

Referenced by Pythia8Hadronizer().

◆ EV1_pTempMode

int Pythia8Hadronizer::EV1_pTempMode
private

Definition at line 157 of file Pythia8Hadronizer.cc.

Referenced by Pythia8Hadronizer().

◆ EV1_pThardMode

int Pythia8Hadronizer::EV1_pThardMode
private

Definition at line 156 of file Pythia8Hadronizer.cc.

Referenced by Pythia8Hadronizer().

◆ EV1_QEDvetoMode

int Pythia8Hadronizer::EV1_QEDvetoMode
private

Definition at line 161 of file Pythia8Hadronizer.cc.

Referenced by Pythia8Hadronizer().

◆ EV1_vetoOn

bool Pythia8Hadronizer::EV1_vetoOn
private

Definition at line 154 of file Pythia8Hadronizer.cc.

Referenced by Pythia8Hadronizer().

◆ fBeam1PZ

double Pythia8Hadronizer::fBeam1PZ
private

Definition at line 112 of file Pythia8Hadronizer.cc.

◆ fBeam2PZ

double Pythia8Hadronizer::fBeam2PZ
private

Definition at line 113 of file Pythia8Hadronizer.cc.

◆ fBiasedTauDecayer

std::shared_ptr<BiasedTauDecayer> Pythia8Hadronizer::fBiasedTauDecayer
private

◆ fCustomHooksVector

std::shared_ptr<UserHooksVector> Pythia8Hadronizer::fCustomHooksVector
private

◆ fEmissionVetoHook

std::shared_ptr<PowhegHooks> Pythia8Hadronizer::fEmissionVetoHook
private

◆ fEmissionVetoHook1

std::shared_ptr<EmissionVetoHook1> Pythia8Hadronizer::fEmissionVetoHook1
private

◆ fInitialState

int Pythia8Hadronizer::fInitialState
private

Definition at line 110 of file Pythia8Hadronizer.cc.

Referenced by initializeForInternalPartons(), and Pythia8Hadronizer().

◆ fJetMatchingHook

std::shared_ptr<JetMatchingHook> Pythia8Hadronizer::fJetMatchingHook
private

◆ fJetMatchingPy8InternalHook

std::shared_ptr<Pythia8::JetMatchingMadgraph> Pythia8Hadronizer::fJetMatchingPy8InternalHook
private

◆ fMergingHook

std::shared_ptr<Pythia8::amcnlo_unitarised_interface> Pythia8Hadronizer::fMergingHook
private

◆ fPowhegHooksBB4L

std::shared_ptr<PowhegHooksBB4L> Pythia8Hadronizer::fPowhegHooksBB4L
private

◆ fPowhegResHook

std::shared_ptr<PowhegResHook> Pythia8Hadronizer::fPowhegResHook
private

◆ fPTFilterHook

std::shared_ptr<PTFilterHook> Pythia8Hadronizer::fPTFilterHook
private

◆ fResonanceDecayFilterHook

std::shared_ptr<ResonanceDecayFilterHook> Pythia8Hadronizer::fResonanceDecayFilterHook
private

◆ fReweightEmpUserHook

std::shared_ptr<UserHooks> Pythia8Hadronizer::fReweightEmpUserHook
private

◆ fReweightPtHatRapUserHook

std::shared_ptr<UserHooks> Pythia8Hadronizer::fReweightPtHatRapUserHook
private

◆ fReweightRapUserHook

std::shared_ptr<UserHooks> Pythia8Hadronizer::fReweightRapUserHook
private

◆ fReweightUserHook

std::shared_ptr<UserHooks> Pythia8Hadronizer::fReweightUserHook
private

◆ fUserHooksVector

std::shared_ptr<UserHooksVector> Pythia8Hadronizer::fUserHooksVector
private

◆ lhaUP

std::shared_ptr<LHAupLesHouches> Pythia8Hadronizer::lhaUP
private

Definition at line 107 of file Pythia8Hadronizer.cc.

Referenced by hadronize(), and initializeForExternalPartons().

◆ LHEInputFileName

std::string Pythia8Hadronizer::LHEInputFileName
private

Definition at line 106 of file Pythia8Hadronizer.cc.

Referenced by hadronize(), and initializeForExternalPartons().

◆ nFSRveto

int Pythia8Hadronizer::nFSRveto
private

Definition at line 171 of file Pythia8Hadronizer.cc.

Referenced by generatePartonsAndHadronize(), hadronize(), and statistics().

◆ nISRveto

int Pythia8Hadronizer::nISRveto
private

Definition at line 170 of file Pythia8Hadronizer.cc.

Referenced by generatePartonsAndHadronize(), hadronize(), and statistics().

◆ nME

int Pythia8Hadronizer::nME
private

Definition at line 167 of file Pythia8Hadronizer.cc.

Referenced by finalizeEvent(), generatePartonsAndHadronize(), and hadronize().

◆ nMEFiltered

int Pythia8Hadronizer::nMEFiltered
private

Definition at line 168 of file Pythia8Hadronizer.cc.

Referenced by finalizeEvent(), generatePartonsAndHadronize(), and hadronize().

◆ p8SharedResources

const std::vector< std::string > Pythia8Hadronizer::p8SharedResources = {edm::SharedResourceNames::kPythia8}
staticprivate

Definition at line 164 of file Pythia8Hadronizer.cc.

◆ UserHooksSet

bool Pythia8Hadronizer::UserHooksSet
private