CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Attributes | Private Attributes
gen::Py8InterfaceBase Class Referenceabstract

#include <Py8InterfaceBase.h>

Inheritance diagram for gen::Py8InterfaceBase:
gen::BaseHadronizer gen::Py8GunBase Pythia8Hadronizer gen::Py8EGun gen::Py8JetGun gen::Py8PtAndDxyGun gen::Py8PtGun

Public Member Functions

virtual const char * classname () const =0
 
bool decay ()
 
bool declareSpecialSettings (const std::vector< std::string > &)
 
bool declareStableParticles (const std::vector< int > &)
 
virtual void finalizeEvent ()=0
 
virtual bool generatePartonsAndHadronize ()=0
 
virtual bool initializeForInternalPartons ()=0
 
void makeTmpSLHA (const std::string &)
 
void p8SetRandomEngine (CLHEP::HepRandomEngine *v)
 
 Py8InterfaceBase (edm::ParameterSet const &ps)
 
P8RndmEnginerandomEngine ()
 
bool readSettings (int)
 
virtual void statistics ()
 
 ~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< GenEventInfoProductgetGenEventInfo ()
 
virtual std::unique_ptr< GenLumiInfoHeadergetGenLumiInfoHeader () const
 
GenRunInfoProductgetGenRunInfo ()
 
std::unique_ptr< lhef::LHEEventgetLHEEvent ()
 
const std::shared_ptr< lhef::LHERunInfo > & getLHERunInfo () const
 
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 resetEventInfo (std::unique_ptr< GenEventInfoProduct > 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 ()(false)
 

Protected Attributes

HepMC::IO_AsciiParticles * ascii_io
 
std::shared_ptr< 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
std::string lheFile_
 
int randomIndex_
 

Private Attributes

P8RndmEngine p8RndmEngine_
 

Additional Inherited Members

- Protected Member Functions inherited from gen::BaseHadronizer
std::unique_ptr< HepMC::GenEvent > & event ()
 
std::unique_ptr< GenEventInfoProduct > & eventInfo ()
 
lhef::LHEEventlheEvent ()
 
lhef::LHERunInfolheRunInfo ()
 
GenRunInfoProductrunInfo ()
 

Detailed Description

Definition at line 25 of file Py8InterfaceBase.h.

Constructor & Destructor Documentation

gen::Py8InterfaceBase::Py8InterfaceBase ( edm::ParameterSet const &  ps)

Definition at line 21 of file Py8InterfaceBase.cc.

References ascii_io, evtgenDecFile, evtgenPdlFile, evtgenUserFiles, edm::ParameterSet::exists(), cmsRelvalreport::exit, fParameters, edm::FileInPath::fullPath(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), mps_fire::i, maxEventsToPrint, MillePedeFileConverter_cfg::out, pythiaHepMCVerbosity, pythiaHepMCVerbosityParticles, pythiaPylistVerbosity, AlCaHLTBitMon_QueryRunRegistry::string, and useEvtGen.

22  : BaseHadronizer(ps), useEvtGen(false), evtgenDecays(nullptr) {
23  fParameters = ps;
24 
25  pythiaPylistVerbosity = ps.getUntrackedParameter<int>("pythiaPylistVerbosity", 0);
26  pythiaHepMCVerbosity = ps.getUntrackedParameter<bool>("pythiaHepMCVerbosity", false);
27  pythiaHepMCVerbosityParticles = ps.getUntrackedParameter<bool>("pythiaHepMCVerbosityParticles", false);
28  maxEventsToPrint = ps.getUntrackedParameter<int>("maxEventsToPrint", 0);
29 
30  if (pythiaHepMCVerbosityParticles)
31  ascii_io = new HepMC::IO_AsciiParticles("cout", std::ios::out);
32 
33  if (ps.exists("useEvtGenPlugin")) {
34  useEvtGen = true;
35  string evtgenpath(getenv("EVTGENDATA"));
36  evtgenDecFile = evtgenpath + string("/DECAY_2010.DEC");
37  evtgenPdlFile = evtgenpath + string("/evt.pdl");
38 
39  if (ps.exists("evtgenDecFile")) {
40  edm::FileInPath decay_table(ps.getParameter<std::string>("evtgenDecFile"));
41  evtgenDecFile = decay_table.fullPath();
42  }
43 
44  if (ps.exists("evtgenPdlFile")) {
45  edm::FileInPath pdt(ps.getParameter<std::string>("evtgenPdlFile"));
46  evtgenPdlFile = pdt.fullPath();
47  }
48 
49  if (ps.exists("evtgenUserFile")) {
50  std::vector<std::string> user_decays = ps.getParameter<std::vector<std::string> >("evtgenUserFile");
51  for (unsigned int i = 0; i < user_decays.size(); i++) {
52  edm::FileInPath user_decay(user_decays.at(i));
53  evtgenUserFiles.push_back(user_decay.fullPath());
54  }
55  //evtgenUserFiles = ps.getParameter< std::vector<std::string> >("evtgenUserFile");
56  }
57 
58  if (ps.exists("evtgenUserFileEmbedded")) {
59  std::vector<std::string> user_decay_lines =
60  ps.getParameter<std::vector<std::string> >("evtgenUserFileEmbedded");
61  auto tmp_dir = boost::filesystem::temp_directory_path();
62  tmp_dir += "/%%%%-%%%%-%%%%-%%%%";
63  auto tmp_path = boost::filesystem::unique_path(tmp_dir);
64  std::string user_decay_tmp = std::string(tmp_path.c_str());
65  FILE* tmpf = std::fopen(user_decay_tmp.c_str(), "w");
66  if (!tmpf) {
67  edm::LogError("Py8InterfaceBase::~Py8InterfaceBase")
68  << "Py8InterfaceBase::Py8InterfaceBase fails when trying to open a temporary file for embedded user.dec "
69  "for EvtGenPlugin. Terminating program ";
70  exit(0);
71  }
72  for (unsigned int i = 0; i < user_decay_lines.size(); i++) {
73  user_decay_lines.at(i) += "\n";
74  std::fputs(user_decay_lines.at(i).c_str(), tmpf);
75  }
76  std::fclose(tmpf);
77  evtgenUserFiles.push_back(user_decay_tmp);
78  }
79  }
80  }
std::shared_ptr< EvtGenDecays > evtgenDecays
HepMC::IO_AsciiParticles * ascii_io
BaseHadronizer(edm::ParameterSet const &ps)
std::vector< std::string > evtgenUserFiles
unsigned int pythiaPylistVerbosity
unsigned int maxEventsToPrint
edm::ParameterSet fParameters
gen::Py8InterfaceBase::~Py8InterfaceBase ( )
inlineoverride

Definition at line 30 of file Py8InterfaceBase.h.

30 {}

Member Function Documentation

virtual const char* gen::Py8InterfaceBase::classname ( ) const
pure virtual
bool gen::Py8InterfaceBase::decay ( )
inline

Definition at line 33 of file Py8InterfaceBase.h.

References data-class-funcs::classname, myMessageLogger_cff::statistics, and AlCaHLTBitMon_QueryRunRegistry::string.

33 { return true; } // NOT used - let's call it "design imperfection"
bool gen::Py8InterfaceBase::declareSpecialSettings ( const std::vector< std::string > &  settings)

Definition at line 226 of file Py8InterfaceBase.cc.

References fDecayer, spr::find(), fMasterGen, and AlCaHLTBitMon_QueryRunRegistry::string.

226  {
227  for (unsigned int iss = 0; iss < settings.size(); iss++) {
228  if (settings[iss].find("QED-brem-off") != std::string::npos) {
229  fMasterGen->readString("TimeShower:QEDshowerByL=off");
230  } else {
231  size_t fnd1 = settings[iss].find("Pythia8:");
232  if (fnd1 != std::string::npos) {
233  std::string value = settings[iss].substr(fnd1 + 8);
234  fDecayer->readString(value);
235  }
236  }
237  }
238  return true;
239  }
std::unique_ptr< Pythia8::Pythia > fDecayer
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
Definition: value.py:1
std::unique_ptr< Pythia8::Pythia > fMasterGen
bool gen::Py8InterfaceBase::declareStableParticles ( const std::vector< int > &  pdgIds)

Definition at line 199 of file Py8InterfaceBase.cc.

References fMasterGen, and mps_fire::i.

199  {
200  for (size_t i = 0; i < pdgIds.size(); i++) {
201  // FIXME: need to double check if PID's are the same in Py6 & Py8,
202  // because the HepPDT translation tool is actually for **Py6**
203  //
204  // well, actually it looks like Py8 operates in PDT id's rather than Py6's
205  //
206  // int PyID = HepPID::translatePDTtoPythia( pdgIds[i] );
207  int PyID = pdgIds[i];
208  std::ostringstream pyCard;
209  pyCard << PyID << ":mayDecay=false";
210 
211  if (fMasterGen->particleData.isParticle(PyID)) {
212  fMasterGen->readString(pyCard.str());
213  } else {
214  edm::LogWarning("DataNotUnderstood") << "Pythia8 does not "
215  << "recognize particle id = " << PyID << std::endl;
216  }
217  // alternative:
218  // set the 2nd input argument warn=false
219  // - this way Py8 will NOT print warnings about unknown particle code(s)
220  // fMasterPtr->readString( pyCard.str(), false )
221  }
222 
223  return true;
224  }
std::unique_ptr< Pythia8::Pythia > fMasterGen
virtual void gen::Py8InterfaceBase::finalizeEvent ( )
pure virtual

Implemented in Pythia8Hadronizer, and gen::Py8GunBase.

virtual bool gen::Py8InterfaceBase::generatePartonsAndHadronize ( )
pure virtual
virtual bool gen::Py8InterfaceBase::initializeForInternalPartons ( )
pure virtual

Implemented in Pythia8Hadronizer, and gen::Py8GunBase.

void gen::Py8InterfaceBase::makeTmpSLHA ( const std::string &  slhatable)

Definition at line 187 of file Py8InterfaceBase.cc.

References fMasterGen, slhafile_, and TriggerAnalyzer::write().

Referenced by readSettings().

187  {
188  char tempslhaname[] = "pythia8SLHAtableXXXXXX";
189  int fd = mkstemp(tempslhaname);
190  write(fd, slhatable.c_str(), slhatable.size());
191  close(fd);
192 
193  slhafile_ = tempslhaname;
194 
195  fMasterGen->settings.mode("SLHA:readFrom", 2);
196  fMasterGen->settings.word("SLHA:file", slhafile_);
197  }
std::unique_ptr< Pythia8::Pythia > fMasterGen
def write(self, setup)
void gen::Py8InterfaceBase::p8SetRandomEngine ( CLHEP::HepRandomEngine *  v)
inline

Definition at line 43 of file Py8InterfaceBase.h.

double v[5][pyjets_maxn]
void setRandomEngine(CLHEP::HepRandomEngine *v)
Definition: P8RndmEngine.h:35
P8RndmEngine p8RndmEngine_
P8RndmEngine& gen::Py8InterfaceBase::randomEngine ( )
inline
bool gen::Py8InterfaceBase::readSettings ( int  )

Definition at line 82 of file Py8InterfaceBase.cc.

References gen::ParameterCollector::begin(), beamerCreator::create(), gen::ParameterCollector::end(), edm::ParameterSet::exists(), connectstrParser::f1, fDecayer, fMasterGen, fParameters, reco::get(), edm::ParameterSet::getParameter(), mps_splice::line, makeTmpSLHA(), p8RndmEngine_, gen::BaseHadronizer::randomIndex(), matplotRender::reader, slhafile_, and AlCaHLTBitMon_QueryRunRegistry::string.

82  {
83  if (!fMasterGen.get())
84  fMasterGen.reset(new Pythia);
85  fDecayer.reset(new Pythia);
86 
87  //add settings for resonance decay filter
88  fMasterGen->settings.addFlag("BiasedTauDecayer:filter", false);
89  fMasterGen->settings.addFlag("BiasedTauDecayer:eDecays", true);
90  fMasterGen->settings.addFlag("BiasedTauDecayer:muDecays", true);
91 
92  //add settings for resonance decay filter
93  fMasterGen->settings.addFlag("ResonanceDecayFilter:filter", false);
94  fMasterGen->settings.addFlag("ResonanceDecayFilter:exclusive", false);
95  fMasterGen->settings.addFlag("ResonanceDecayFilter:eMuAsEquivalent", false);
96  fMasterGen->settings.addFlag("ResonanceDecayFilter:eMuTauAsEquivalent", false);
97  fMasterGen->settings.addFlag("ResonanceDecayFilter:allNuAsEquivalent", false);
98  fMasterGen->settings.addFlag("ResonanceDecayFilter:udscAsEquivalent", false);
99  fMasterGen->settings.addFlag("ResonanceDecayFilter:udscbAsEquivalent", false);
100  fMasterGen->settings.addFlag("ResonanceDecayFilter:wzAsEquivalent", false);
101  fMasterGen->settings.addMVec("ResonanceDecayFilter:mothers", std::vector<int>(), false, false, 0, 0);
102  fMasterGen->settings.addMVec("ResonanceDecayFilter:daughters", std::vector<int>(), false, false, 0, 0);
103 
104  //add settings for PT filter
105  fMasterGen->settings.addFlag("PTFilter:filter", false);
106  fMasterGen->settings.addMode("PTFilter:quarkToFilter", 5, true, true, 3, 6);
107  fMasterGen->settings.addParm("PTFilter:scaleToFilter", 0.4, true, true, 0.0, 10.);
108  fMasterGen->settings.addParm("PTFilter:quarkRapidity", 10.0, true, true, 0.0, 10.);
109  fMasterGen->settings.addParm("PTFilter:quarkPt", -.1, true, true, -.1, 100.);
110 
111  //add settings for RecoilToTop tool
112  fMasterGen->settings.addFlag("TopRecoilHook:doTopRecoilIn", false);
113  fMasterGen->settings.addFlag("TopRecoilHook:useOldDipoleIn", false);
114  fMasterGen->settings.addFlag("TopRecoilHook:doListIn", false);
115 
116  //add settings for powheg resonance scale calculation
117  fMasterGen->settings.addFlag("POWHEGres:calcScales", false);
118  fMasterGen->settings.addFlag("POWHEG:bb4l", false);
119  fMasterGen->settings.addFlag("POWHEG:bb4l:FSREmission:onlyDistance1", false);
120  fMasterGen->settings.addFlag("POWHEG:bb4l:FSREmission:veto", false);
121  fMasterGen->settings.addFlag("POWHEG:bb4l:FSREmission:dryRun", false);
122  fMasterGen->settings.addFlag("POWHEG:bb4l:FSREmission:vetoAtPL", false);
123  fMasterGen->settings.addFlag("POWHEG:bb4l:FSREmission:vetoQED", false);
124  fMasterGen->settings.addFlag("POWHEG:bb4l:PartonLevel:veto", false);
125  fMasterGen->settings.addFlag("POWHEG:bb4l:PartonLevel:excludeFSRConflicting", false);
126  fMasterGen->settings.addFlag("POWHEG:bb4l:DEBUG", false);
127  fMasterGen->settings.addFlag("POWHEG:bb4l:ScaleResonance:veto", false);
128  fMasterGen->settings.addFlag("POWHEG:bb4l:FSREmission:vetoDipoleFrame", false);
129  fMasterGen->settings.addFlag("POWHEG:bb4l:FSREmission:pTpythiaVeto", false);
130  fMasterGen->settings.addParm("POWHEG:bb4l:pTminVeto", 10.0, true, true, 0.0, 10.);
131 
132  fMasterGen->setRndmEnginePtr(&p8RndmEngine_);
133  fDecayer->setRndmEnginePtr(&p8RndmEngine_);
134 
135  fMasterGen->readString("Next:numberShowEvent = 0");
136  fDecayer->readString("Next:numberShowEvent = 0");
137 
138  edm::ParameterSet currentParameters;
139  if (randomIndex() >= 0) {
140  std::vector<edm::ParameterSet> randomizedParameters =
141  fParameters.getParameter<std::vector<edm::ParameterSet> >("RandomizedParameters");
142  currentParameters = randomizedParameters[randomIndex()];
143  } else {
144  currentParameters = fParameters;
145  }
146 
147  ParameterCollector pCollector = currentParameters.getParameter<edm::ParameterSet>("PythiaParameters");
148 
149  for (ParameterCollector::const_iterator line = pCollector.begin(); line != pCollector.end(); ++line) {
150  if (line->find("Random:") != std::string::npos)
151  throw cms::Exception("PythiaError") << "Attempted to set random number "
152  "using Pythia commands. Please use "
153  "the RandomNumberGeneratorService."
154  << std::endl;
155 
156  if (!fMasterGen->readString(*line))
157  throw cms::Exception("PythiaError") << "Pythia 8 did not accept \"" << *line << "\"." << std::endl;
158 
159  if (line->find("ParticleDecays:") != std::string::npos) {
160  if (!fDecayer->readString(*line))
161  throw cms::Exception("PythiaError") << "Pythia 8 Decayer did not accept \"" << *line << "\"." << std::endl;
162  }
163  }
164 
165  slhafile_.clear();
166 
167  if (currentParameters.exists("SLHAFileForPythia8")) {
168  std::string slhafilenameshort = currentParameters.getParameter<std::string>("SLHAFileForPythia8");
169  edm::FileInPath f1(slhafilenameshort);
170 
171  fMasterGen->settings.mode("SLHA:readFrom", 2);
172  fMasterGen->settings.word("SLHA:file", f1.fullPath());
173  } else if (currentParameters.exists("SLHATableForPythia8")) {
174  std::string slhatable = currentParameters.getParameter<std::string>("SLHATableForPythia8");
175 
176  makeTmpSLHA(slhatable);
177  } else if (currentParameters.exists("SLHATreeForPythia8")) {
178  auto slhaReaderParams = currentParameters.getParameter<edm::ParameterSet>("SLHATreeForPythia8");
179  std::unique_ptr<SLHAReaderBase> reader(
180  SLHAReaderFactory::get()->create(slhaReaderParams.getParameter<std::string>("name"), slhaReaderParams));
181  makeTmpSLHA(reader->getSLHA(currentParameters.getParameter<std::string>("ConfigDescription")));
182  }
183 
184  return true;
185  }
T getParameter(std::string const &) const
std::unique_ptr< Pythia8::Pythia > fDecayer
def create(alignables, pedeDump, additionalData, outputFile, config)
void makeTmpSLHA(const std::string &)
bool exists(std::string const &parameterName) const
checks if a parameter exists
P8RndmEngine p8RndmEngine_
int randomIndex() const
std::unique_ptr< Pythia8::Pythia > fMasterGen
edm::ParameterSet fParameters
T get(const Candidate &c)
Definition: component.h:55
void gen::Py8InterfaceBase::statistics ( )
virtual

Reimplemented in Pythia8Hadronizer, and gen::Py8GunBase.

Definition at line 241 of file Py8InterfaceBase.cc.

References fMasterGen.

241  {
242  fMasterGen->stat();
243  return;
244  }
std::unique_ptr< Pythia8::Pythia > fMasterGen

Member Data Documentation

HepMC::IO_AsciiParticles* gen::Py8InterfaceBase::ascii_io
protected
std::shared_ptr<EvtGenDecays> gen::Py8InterfaceBase::evtgenDecays
protected
std::string gen::Py8InterfaceBase::evtgenDecFile
protected
std::string gen::Py8InterfaceBase::evtgenPdlFile
protected
std::vector<std::string> gen::Py8InterfaceBase::evtgenUserFiles
protected
std::unique_ptr<Pythia8::Pythia> gen::Py8InterfaceBase::fDecayer
protected
std::unique_ptr<Pythia8::Pythia> gen::Py8InterfaceBase::fMasterGen
protected
edm::ParameterSet gen::Py8InterfaceBase::fParameters
protected

Definition at line 52 of file Py8InterfaceBase.h.

Referenced by Py8InterfaceBase(), and readSettings().

unsigned int gen::Py8InterfaceBase::maxEventsToPrint
protected
P8RndmEngine gen::Py8InterfaceBase::p8RndmEngine_
private

Definition at line 72 of file Py8InterfaceBase.h.

Referenced by readSettings().

bool gen::Py8InterfaceBase::pythiaHepMCVerbosity
protected
bool gen::Py8InterfaceBase::pythiaHepMCVerbosityParticles
protected
unsigned int gen::Py8InterfaceBase::pythiaPylistVerbosity
protected
std::string gen::Py8InterfaceBase::slhafile_
protected
HepMC::Pythia8ToHepMC gen::Py8InterfaceBase::toHepMC
protected
bool gen::Py8InterfaceBase::useEvtGen
protected