CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes | Static Private Attributes | Friends
gen::Pythia6Service Class Reference

#include <Pythia6Service.h>

Inheritance diagram for gen::Pythia6Service:
gen::FortranInstance gen::Pythia6ServiceWithCallback

Public Member Functions

void closePYUPDA ()
 
void closeSLHA ()
 
void enter () override
 
void openPYUPDA (const char *, bool write_file)
 
void openSLHA (const char *)
 
 Pythia6Service ()
 
 Pythia6Service (edm::ParameterSet const &)
 
CLHEP::HepRandomEngine * randomEngine () const
 
void setCSAParams ()
 
void setGeneralParams ()
 
void setPYUPDAParams (bool afterPyinit)
 
void setRandomEngine (CLHEP::HepRandomEngine *v)
 
void setSLHAFromHeader (const std::vector< std::string > &lines)
 
void setSLHAParams ()
 
 ~Pythia6Service () override
 
- Public Member Functions inherited from gen::FortranInstance
void call (void(&fn)())
 
template<typename T >
T call (T(&fn)())
 
template<typename A >
void call (void(&fn)(A), A a)
 
template<typename T , typename A >
T call (T(&fn)(A), A a)
 
template<typename A1 , typename A2 >
void call (void(&fn)(A1, A2), A1 a1, A2 a2)
 
template<typename T , typename A1 , typename A2 >
T call (T(&fn)(A1, A2), A1 a1, A2 a2)
 
 FortranInstance ()
 
virtual void leave ()
 
virtual void upEvnt ()
 
virtual void upInit ()
 
virtual bool upVeto ()
 
virtual ~FortranInstance () noexcept(false)
 

Private Attributes

bool fInitialising
 
std::vector< std::string > fParamCSA
 
std::vector< std::string > fParamGeneral
 
std::vector< std::string > fParamPYUPDA
 
std::vector< std::string > fParamSLHA
 
CLHEP::HepRandomEngine * fRandomEngine
 
int fUnitPYUPDA
 
int fUnitSLHA
 

Static Private Attributes

static Pythia6ServicefPythia6Owner = nullptr
 

Friends

double gen::pyr_ (int *)
 

Additional Inherited Members

- Static Public Member Functions inherited from gen::FortranInstance
template<typename T >
static TgetInstance ()
 
- Static Public Attributes inherited from gen::FortranInstance
static const std::string kFortranInstance = "FortranInstance"
 

Detailed Description

Definition at line 24 of file Pythia6Service.h.

Constructor & Destructor Documentation

◆ Pythia6Service() [1/2]

Pythia6Service::Pythia6Service ( )

Definition at line 72 of file Pythia6Service.cc.

72 : fRandomEngine(nullptr), fUnitSLHA(24), fUnitPYUPDA(25) {}
CLHEP::HepRandomEngine * fRandomEngine

◆ Pythia6Service() [2/2]

Pythia6Service::Pythia6Service ( edm::ParameterSet const &  ps)

Definition at line 74 of file Pythia6Service.cc.

References Exception, fParamCSA, fParamGeneral, fParamPYUPDA, fParamSLHA, fPythia6Owner, edm::ParameterSet::getParameter(), mps_splice::line, and groupFilesInBlocks::lines.

74  : fRandomEngine(nullptr), fUnitSLHA(24), fUnitPYUPDA(25) {
75  if (fPythia6Owner)
76  throw cms::Exception("PythiaError") << "Two Pythia6Service instances claiming Pythia6 ownership." << std::endl;
77 
78  fPythia6Owner = this;
79 
80  /*
81  ParameterCollector collector(ps.getParameter<edm::ParameterSet>("PythiaParameters"));
82 
83  fParamGeneral.clear();
84  fParamCSA.clear();
85  fParamSLHA.clear();
86 
87  fParamGeneral = std::vector<std::string>(collector.begin(), collector.end());
88  fParamCSA = std::vector<std::string>(collector.begin("CSAParameters"), collector.end());
89  fParamSLHA = std::vector<std::string>(collector.begin("SLHAParameters"), collector.end());
90 */
91 
92  // Set PYTHIA parameters in a single ParameterSet
93  //
94  edm::ParameterSet pythia_params = ps.getParameter<edm::ParameterSet>("PythiaParameters");
95 
96  // read and sort Pythia6 cards
97  //
98  std::vector<std::string> setNames = pythia_params.getParameter<std::vector<std::string> >("parameterSets");
99 
100  // std::vector<std::string> paramLines;
101  fParamGeneral.clear();
102  fParamCSA.clear();
103  fParamSLHA.clear();
104  fParamPYUPDA.clear();
105 
106  for (std::vector<std::string>::const_iterator iter = setNames.begin(); iter != setNames.end(); ++iter) {
107  std::vector<std::string> lines = pythia_params.getParameter<std::vector<std::string> >(*iter);
108 
109  for (std::vector<std::string>::const_iterator line = lines.begin(); line != lines.end(); ++line) {
110  if (line->substr(0, 7) == "MRPY(1)")
111  throw cms::Exception("PythiaError") << "Attempted to set random number"
112  " using Pythia command 'MRPY(1)'."
113  " Please use the"
114  " RandomNumberGeneratorService."
115  << std::endl;
116 
117  if (*iter == "CSAParameters") {
118  fParamCSA.push_back(*line);
119  } else if (*iter == "SLHAParameters") {
120  fParamSLHA.push_back(*line);
121  } else if (*iter == "PYUPDAParameters") {
122  fParamPYUPDA.push_back(*line);
123  } else {
124  fParamGeneral.push_back(*line);
125  }
126  }
127  }
128 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< std::string > fParamPYUPDA
std::vector< std::string > fParamGeneral
static Pythia6Service * fPythia6Owner
CLHEP::HepRandomEngine * fRandomEngine
std::vector< std::string > fParamCSA
std::vector< std::string > fParamSLHA

◆ ~Pythia6Service()

Pythia6Service::~Pythia6Service ( )
override

Definition at line 130 of file Pythia6Service.cc.

References fParamCSA, fParamGeneral, fParamPYUPDA, fParamSLHA, and fPythia6Owner.

130  {
131  if (fPythia6Owner == this)
132  fPythia6Owner = nullptr;
133 
134  fParamGeneral.clear();
135  fParamCSA.clear();
136  fParamSLHA.clear();
137  fParamPYUPDA.clear();
138 }
std::vector< std::string > fParamPYUPDA
std::vector< std::string > fParamGeneral
static Pythia6Service * fPythia6Owner
std::vector< std::string > fParamCSA
std::vector< std::string > fParamSLHA

Member Function Documentation

◆ closePYUPDA()

void Pythia6Service::closePYUPDA ( )

Definition at line 232 of file Pythia6Service.cc.

References fiocls_(), and fUnitPYUPDA.

232  {
234 
235  return;
236 }
void fiocls_(int *unit)

◆ closeSLHA()

void Pythia6Service::closeSLHA ( )

Definition at line 226 of file Pythia6Service.cc.

References fiocls_(), and fUnitSLHA.

Referenced by gen::Pythia6Hadronizer::initializeForExternalPartons(), and gen::Pythia6Hadronizer::initializeForInternalPartons().

226  {
227  fiocls_(&fUnitSLHA);
228 
229  return;
230 }
void fiocls_(int *unit)

◆ enter()

void Pythia6Service::enter ( )
overridevirtual

Reimplemented from gen::FortranInstance.

Definition at line 140 of file Pythia6Service.cc.

References gen::call_pygive(), gen::FortranInstance::enter(), and fPythia6Owner.

140  {
142 
143  if (!fPythia6Owner) {
144  edm::LogInfo("Generator|Pythia6Interface") << "gen::Pythia6Service is going to initialise Pythia, as no other "
145  "instace has done so yet, and Pythia service routines have been "
146  "requested by a dummy instance."
147  << std::endl;
148 
149  call_pygive("MSTU(12)=12345");
150  call_pyinit("NONE", "", "", 0.0);
151 
152  fPythia6Owner = this;
153  }
154 }
bool call_pygive(const std::string &line)
virtual void enter()
static Pythia6Service * fPythia6Owner
Log< level::Info, false > LogInfo

◆ openPYUPDA()

void Pythia6Service::openPYUPDA ( const char *  file,
bool  write_file 
)

Definition at line 210 of file Pythia6Service.cc.

References call_pyupda(), gather_cfg::cout, geometryDiff::file, fioopn_(), fioopnw_(), and fUnitPYUPDA.

Referenced by setPYUPDAParams().

210  {
211  if (write_file) {
212  std::cout << "=== WRITING PYUPDA FILE " << file << " ===" << std::endl;
213  fioopnw_(&fUnitPYUPDA, file, strlen(file));
214  // Write Pythia particle table to this card file.
216  } else {
217  std::cout << "=== READING PYUPDA FILE " << file << " ===" << std::endl;
218  fioopn_(&fUnitPYUPDA, file, strlen(file));
219  // Update Pythia particle table with this card file.
221  }
222 
223  return;
224 }
static void call_pyupda(int opt, int iunit)
void fioopn_(int *unit, const char *line, int length)
void fioopnw_(int *unit, const char *line, int length)

◆ openSLHA()

void Pythia6Service::openSLHA ( const char *  file)

Definition at line 197 of file Pythia6Service.cc.

References gen::call_pygive(), geometryDiff::file, fioopn_(), and fUnitSLHA.

Referenced by setSLHAFromHeader(), and setSLHAParams().

197  {
198  std::ostringstream pyCard1;
199  pyCard1 << "IMSS(21)=" << fUnitSLHA;
200  call_pygive(pyCard1.str());
201  std::ostringstream pyCard2;
202  pyCard2 << "IMSS(22)=" << fUnitSLHA;
203  call_pygive(pyCard2.str());
204 
205  fioopn_(&fUnitSLHA, file, strlen(file));
206 
207  return;
208 }
void fioopn_(int *unit, const char *line, int length)
bool call_pygive(const std::string &line)

◆ randomEngine()

CLHEP::HepRandomEngine* gen::Pythia6Service::randomEngine ( ) const
inline

Definition at line 45 of file Pythia6Service.h.

References fRandomEngine.

Referenced by gen::Pythia6Gun::produce().

45 { return fRandomEngine; }
CLHEP::HepRandomEngine * fRandomEngine

◆ setCSAParams()

void Pythia6Service::setCSAParams ( )

Definition at line 167 of file Pythia6Service.cc.

References visDQMUpload::buf, fParamCSA, mps_fire::i, reco_skim_cfg_mod::maxSize, SETCSAPARBUFSIZE, gen::txgive_(), and gen::txgive_init_().

Referenced by gen::Pythia6Gun::beginLuminosityBlock(), gen::PyquenHadronizer::readSettings(), and gen::Pythia6Hadronizer::readSettings().

167  {
168 #define SETCSAPARBUFSIZE 514
169  char buf[SETCSAPARBUFSIZE];
170 
171  txgive_init_();
172  for (std::vector<std::string>::const_iterator iter = fParamCSA.begin(); iter != fParamCSA.end(); ++iter) {
173  // Null pad the string should not be needed because it uses
174  // read, which will look for \n, but just in case...
175  for (size_t i = 0; i < SETCSAPARBUFSIZE; ++i)
176  buf[i] = ' ';
177  // Skip empty parameters.
178  if (iter->length() <= 0)
179  continue;
180  // Limit the size of the string to something which fits the buffer.
181  size_t maxSize = iter->length() > (SETCSAPARBUFSIZE - 2) ? (SETCSAPARBUFSIZE - 2) : iter->length();
182  strncpy(buf, iter->c_str(), maxSize);
183  // Add extra \n if missing, otherwise "read" continues reading.
184  if (buf[maxSize - 1] != '\n') {
185  buf[maxSize] = '\n';
186  // Null terminate in case the string is passed back to C.
187  // Not sure that is actually needed.
188  buf[maxSize + 1] = 0;
189  }
190  txgive_(buf, iter->length());
191  }
192 
193  return;
194 #undef SETCSAPARBUFSIZE
195 }
#define SETCSAPARBUFSIZE
void txgive_init_(void)
std::vector< std::string > fParamCSA
void txgive_(const char *, int)

◆ setGeneralParams()

void Pythia6Service::setGeneralParams ( )

Definition at line 156 of file Pythia6Service.cc.

References gen::call_pygive(), and fParamGeneral.

Referenced by gen::Pythia6Gun::beginLuminosityBlock(), gen::PyquenHadronizer::readSettings(), gen::ExhumeHadronizer::readSettings(), gen::Pythia6Hadronizer::readSettings(), gen::Hydjet2Hadronizer::readSettings(), and gen::HydjetHadronizer::readSettings().

156  {
157  // now pass general config cards
158  //
159  for (std::vector<std::string>::const_iterator iter = fParamGeneral.begin(); iter != fParamGeneral.end(); ++iter) {
160  if (!call_pygive(*iter))
161  throw cms::Exception("PythiaError") << "Pythia did not accept \"" << *iter << "\"." << std::endl;
162  }
163 
164  return;
165 }
bool call_pygive(const std::string &line)
std::vector< std::string > fParamGeneral

◆ setPYUPDAParams()

void Pythia6Service::setPYUPDAParams ( bool  afterPyinit)

Definition at line 275 of file Pythia6Service.cc.

References DeadROC_duringRun::f1, geometryDiff::file, fParamPYUPDA, openPYUPDA(), AlCaHLTBitMon_QueryRunRegistry::string, and groupFilesInBlocks::temp.

Referenced by gen::Pythia6Hadronizer::initializeForExternalPartons(), and gen::Pythia6Hadronizer::initializeForInternalPartons().

275  {
276  std::string shortfile;
277  bool write_file = false;
278  bool usePostPyinit = false;
279 
280  // std::cout<<"=== CALLING setPYUPDAParams === "<<afterPyinit<<" "<<fParamPYUPDA.size()<<std::endl;
281 
282  // This assumes that PYUPDAFILE only appears once ...
283 
284  for (std::vector<std::string>::const_iterator iter = fParamPYUPDA.begin(); iter != fParamPYUPDA.end(); iter++) {
285  // std::cout<<"PYUPDA check "<<*iter<<std::endl;
286  if (iter->find("PYUPDAFILE", 0) != std::string::npos) {
287  std::string::size_type start = iter->find_first_of("=") + 1;
288  std::string::size_type end = iter->length() - 1;
289  std::string::size_type temp = iter->find_first_of("'", start);
290  if (temp != std::string::npos) {
291  start = temp + 1;
292  end = iter->find_last_of("'") - 1;
293  }
294  start = iter->find_first_not_of(" ", start);
295  end = iter->find_last_not_of(" ", end);
296  //std::cout << " start, end = " << start << " " << end << std::endl;
297  shortfile = iter->substr(start, end - start + 1);
298  } else if (iter->find("PYUPDAWRITE", 0) != std::string::npos) {
299  write_file = true;
300  } else if (iter->find("PYUPDApostPYINIT", 0) != std::string::npos) {
301  usePostPyinit = true;
302  }
303  }
304 
305  if (!shortfile.empty()) {
307  if (write_file) {
308  file = shortfile;
309  } else {
310  // If reading, get full path to file and require it to exist.
311  FileInPath f1(shortfile);
312  file = f1.fullPath();
313  }
314 
315  if (afterPyinit == usePostPyinit || (write_file && afterPyinit)) {
316  openPYUPDA(file.c_str(), write_file);
317  }
318  }
319 
320  return;
321 }
Definition: start.py:1
uint16_t size_type
std::vector< std::string > fParamPYUPDA
void openPYUPDA(const char *, bool write_file)

◆ setRandomEngine()

void gen::Pythia6Service::setRandomEngine ( CLHEP::HepRandomEngine *  v)
inline

◆ setSLHAFromHeader()

void Pythia6Service::setSLHAFromHeader ( const std::vector< std::string > &  lines)

Definition at line 323 of file Pythia6Service.cc.

References groupFilesInBlocks::block, gather_cfg::blocks, call_pyslha(), ztee::fd, createfilelist::int, mps_splice::line, groupFilesInBlocks::lines, ReggeGribovPartonMC_EposLHC_2760GeV_PbPb_cfi::model, openSLHA(), gen::pydat1_, MatrixUtil::remove(), submitPVValidationJobs::split(), mathSSE::sqrt(), contentValuesCheck::ss, AlCaHLTBitMon_QueryRunRegistry::string, HcalDetIdTransform::transform(), relativeConstraints::value, and writeEcalDQMStatus::write.

Referenced by gen::Pythia6Hadronizer::initializeForExternalPartons().

323  {
324  std::set<std::string> blocks;
325  unsigned int model = 0, subModel = 0;
326  char tempslhaname[] = "pythia6slhaXXXXXX";
327  int fd = mkstemp(tempslhaname);
328 
330  std::stringstream f_info;
331  for (std::vector<std::string>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter) {
332  f_info << *iter;
333 
334  std::string line = *iter;
335  std::transform(line.begin(), line.end(), line.begin(), (int (*)(int))std::toupper);
336  std::string::size_type pos = line.find('#');
337  if (pos != std::string::npos)
338  line.resize(pos);
339 
340  if (line.empty())
341  continue;
342 
343  if (!boost::algorithm::is_space()(line[0])) {
344  std::vector<std::string> tokens;
345  boost::split(tokens, line, boost::algorithm::is_space(), boost::token_compress_on);
346  if (tokens.empty())
347  continue;
348  block.clear();
349  if (tokens.size() < 2)
350  continue;
351  if (tokens[0] == "BLOCK") {
352  block = tokens[1];
353  blocks.insert(block);
354  continue;
355  }
356 
357  if (tokens[0] == "DECAY") {
358  block = "DECAY";
359  blocks.insert(block);
360  }
361  } else if (block == "MODSEL") {
362  std::istringstream ss(line);
363  ss >> model >> subModel;
364  } else if (block == "SMINPUTS") {
365  std::istringstream ss(line);
366  int index;
367  double value;
368  ss >> index >> value;
369  switch (index) {
370  case 1:
371  pydat1_.paru[103 - 1] = 1.0 / value;
372  break;
373  case 2:
374  pydat1_.paru[105 - 1] = value;
375  break;
376  case 4:
377  pydat2_.pmas[0][23 - 1] = value;
378  break;
379  case 6:
380  pydat2_.pmas[0][6 - 1] = value;
381  break;
382  case 7:
383  pydat2_.pmas[0][15 - 1] = value;
384  break;
385  }
386  }
387  }
388  write(fd, f_info.str().c_str(), f_info.str().size());
389  close(fd);
390 
391  if (blocks.count("SMINPUTS"))
392  pydat1_.paru[102 - 1] =
393  0.5 - std::sqrt(0.25 - pydat1_.paru[0] * M_SQRT1_2 * pydat1_.paru[103 - 1] / pydat1_.paru[105 - 1] /
394  (pydat2_.pmas[0][23 - 1] * pydat2_.pmas[0][23 - 1]));
395 
396  /*
397  int unit = 24;
398  fioopn_(&unit, fname, std::strlen(fname));
399  std::remove(fname);
400 
401  call_pygive("IMSS(21)=24");
402  call_pygive("IMSS(22)=24");
403 */
404 
405  openSLHA(tempslhaname);
406  std::remove(tempslhaname);
407 
408  if (model || blocks.count("HIGMIX") || blocks.count("SBOTMIX") || blocks.count("STOPMIX") ||
409  blocks.count("STAUMIX") || blocks.count("AMIX") || blocks.count("NMIX") || blocks.count("UMIX") ||
410  blocks.count("VMIX"))
411  call_pyslha(1);
412  if (model || blocks.count("QNUMBERS") || blocks.count("PARTICLE") || blocks.count("MINPAR") ||
413  blocks.count("EXTPAR") || blocks.count("SMINPUTS") || blocks.count("SMINPUTS"))
414  call_pyslha(0);
415  if (blocks.count("MASS"))
416  call_pyslha(5, 0);
417  if (blocks.count("DECAY"))
418  call_pyslha(2);
419 
420  return;
421 }
uint16_t size_type
struct gen::@735 pydat1_
T sqrt(T t)
Definition: SSEVec.h:19
static int call_pyslha(int mupda, int kforig=0)
void openSLHA(const char *)
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:223
fd
Definition: ztee.py:136
unsigned transform(const HcalDetId &id, unsigned transformCode)

◆ setSLHAParams()

void Pythia6Service::setSLHAParams ( )

Definition at line 238 of file Pythia6Service.cc.

References DeadROC_duringRun::f1, geometryDiff::file, fParamSLHA, openSLHA(), AlCaHLTBitMon_QueryRunRegistry::string, and groupFilesInBlocks::temp.

Referenced by gen::Pythia6Gun::beginLuminosityBlock(), and gen::Pythia6Hadronizer::readSettings().

238  {
239  for (std::vector<std::string>::const_iterator iter = fParamSLHA.begin(); iter != fParamSLHA.end(); iter++) {
240  if (iter->find("SLHAFILE", 0) == std::string::npos)
241  continue;
242  std::string::size_type start = iter->find_first_of("=") + 1;
243  std::string::size_type end = iter->length() - 1;
244  std::string::size_type temp = iter->find_first_of("'", start);
245  if (temp != std::string::npos) {
246  start = temp + 1;
247  end = iter->find_last_of("'") - 1;
248  }
249  start = iter->find_first_not_of(" ", start);
250  end = iter->find_last_not_of(" ", end);
251  //std::cout << " start, end = " << start << " " << end << std::endl;
252  std::string shortfile = iter->substr(start, end - start + 1);
253  FileInPath f1(shortfile);
254  std::string file = f1.fullPath();
255 
256  /*
257  //
258  // override what might have be given via the external config
259  //
260  std::ostringstream pyCard ;
261  pyCard << "IMSS(21)=" << fUnitSLHA;
262  call_pygive( pyCard.str() );
263  pyCard << "IMSS(22)=" << fUnitSLHA;
264  call_pygive( pyCard.str() );
265 
266  fioopn_( &fUnitSLHA, file.c_str(), file.length() );
267 */
268 
269  openSLHA(file.c_str());
270  }
271 
272  return;
273 }
Definition: start.py:1
uint16_t size_type
void openSLHA(const char *)
std::vector< std::string > fParamSLHA

Friends And Related Function Documentation

◆ gen::pyr_

double gen::pyr_ ( int *  )
friend

Member Data Documentation

◆ fInitialising

bool gen::Pythia6Service::fInitialising
private

Definition at line 51 of file Pythia6Service.h.

◆ fParamCSA

std::vector<std::string> gen::Pythia6Service::fParamCSA
private

Definition at line 56 of file Pythia6Service.h.

Referenced by Pythia6Service(), setCSAParams(), and ~Pythia6Service().

◆ fParamGeneral

std::vector<std::string> gen::Pythia6Service::fParamGeneral
private

Definition at line 55 of file Pythia6Service.h.

Referenced by Pythia6Service(), setGeneralParams(), and ~Pythia6Service().

◆ fParamPYUPDA

std::vector<std::string> gen::Pythia6Service::fParamPYUPDA
private

Definition at line 58 of file Pythia6Service.h.

Referenced by Pythia6Service(), setPYUPDAParams(), and ~Pythia6Service().

◆ fParamSLHA

std::vector<std::string> gen::Pythia6Service::fParamSLHA
private

Definition at line 57 of file Pythia6Service.h.

Referenced by Pythia6Service(), setSLHAParams(), and ~Pythia6Service().

◆ fPythia6Owner

Pythia6Service * Pythia6Service::fPythia6Owner = nullptr
staticprivate

Definition at line 62 of file Pythia6Service.h.

Referenced by enter(), Pythia6Service(), and ~Pythia6Service().

◆ fRandomEngine

CLHEP::HepRandomEngine* gen::Pythia6Service::fRandomEngine
private

Definition at line 53 of file Pythia6Service.h.

Referenced by randomEngine(), and setRandomEngine().

◆ fUnitPYUPDA

int gen::Pythia6Service::fUnitPYUPDA
private

Definition at line 60 of file Pythia6Service.h.

Referenced by closePYUPDA(), and openPYUPDA().

◆ fUnitSLHA

int gen::Pythia6Service::fUnitSLHA
private

Definition at line 59 of file Pythia6Service.h.

Referenced by closeSLHA(), and openSLHA().