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 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 = 0
 

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 25 of file Pythia6Service.h.

Constructor & Destructor Documentation

Pythia6Service::Pythia6Service ( )
gen::Pythia6Service::Pythia6Service ( edm::ParameterSet const &  )
Pythia6Service::~Pythia6Service ( )
override

Definition at line 161 of file Pythia6Service.cc.

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

162 {
163  if (fPythia6Owner == this)
164  fPythia6Owner = nullptr;
165 
166  fParamGeneral.clear();
167  fParamCSA.clear();
168  fParamSLHA.clear();
169  fParamPYUPDA.clear();
170 }
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

void Pythia6Service::closePYUPDA ( )

Definition at line 282 of file Pythia6Service.cc.

References fiocls_(), and fUnitPYUPDA.

283 {
284 
286 
287  return;
288 
289 }
void fiocls_(int *unit)
void Pythia6Service::closeSLHA ( )
void Pythia6Service::enter ( )
overridevirtual

Reimplemented from gen::FortranInstance.

Definition at line 172 of file Pythia6Service.cc.

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

173 {
175 
176  if (!fPythia6Owner) {
177  edm::LogInfo("Generator|Pythia6Interface") <<
178  "gen::Pythia6Service is going to initialise Pythia, as no other "
179  "instace has done so yet, and Pythia service routines have been "
180  "requested by a dummy instance." << std::endl;
181 
182  call_pygive("MSTU(12)=12345");
183  call_pyinit("NONE", "", "", 0.0);
184 
185  fPythia6Owner = this;
186  }
187 }
bool call_pygive(const std::string &line)
virtual void enter()
static Pythia6Service * fPythia6Owner
void Pythia6Service::openPYUPDA ( const char *  file,
bool  write_file 
)

Definition at line 255 of file Pythia6Service.cc.

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

Referenced by setPYUPDAParams().

256 {
257 
258  if (write_file) {
259  std::cout<<"=== WRITING PYUPDA FILE "<<file<<" ==="<<std::endl;
260  fioopnw_( &fUnitPYUPDA, file, strlen(file) );
261  // Write Pythia particle table to this card file.
263  } else {
264  std::cout<<"=== READING PYUPDA FILE "<<file<<" ==="<<std::endl;
265  fioopn_( &fUnitPYUPDA, file, strlen(file) );
266  // Update Pythia particle table with this card file.
268  }
269 
270  return;
271 
272 }
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)
void Pythia6Service::openSLHA ( const char *  file)

Definition at line 239 of file Pythia6Service.cc.

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

Referenced by setSLHAFromHeader(), and setSLHAParams().

240 {
241 
242  std::ostringstream pyCard1 ;
243  pyCard1 << "IMSS(21)=" << fUnitSLHA;
244  call_pygive( pyCard1.str() );
245  std::ostringstream pyCard2 ;
246  pyCard2 << "IMSS(22)=" << fUnitSLHA;
247  call_pygive( pyCard2.str() );
248 
249  fioopn_( &fUnitSLHA, file, strlen(file) );
250 
251  return;
252 
253 }
void fioopn_(int *unit, const char *line, int length)
bool call_pygive(const std::string &line)
CLHEP::HepRandomEngine* gen::Pythia6Service::randomEngine ( ) const
inline

Definition at line 47 of file Pythia6Service.h.

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

47 { return fRandomEngine; }
CLHEP::HepRandomEngine * fRandomEngine
void Pythia6Service::setCSAParams ( )

Definition at line 205 of file Pythia6Service.cc.

References fParamCSA, mps_fire::i, copyPickMerge_cfg::maxSize, reco::return(), SETCSAPARBUFSIZE, gen::txgive_(), and gen::txgive_init_().

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

206 {
207 #define SETCSAPARBUFSIZE 514
208  char buf[SETCSAPARBUFSIZE];
209 
210  txgive_init_();
211  for(std::vector<std::string>::const_iterator iter = fParamCSA.begin();
212  iter != fParamCSA.end(); ++iter)
213  {
214  // Null pad the string should not be needed because it uses
215  // read, which will look for \n, but just in case...
216  for (size_t i = 0; i < SETCSAPARBUFSIZE; ++i)
217  buf[i] = ' ';
218  // Skip empty parameters.
219  if (iter->length() <= 0)
220  continue;
221  // Limit the size of the string to something which fits the buffer.
222  size_t maxSize = iter->length() > (SETCSAPARBUFSIZE-2) ? (SETCSAPARBUFSIZE-2) : iter->length();
223  strncpy(buf, iter->c_str(), maxSize);
224  // Add extra \n if missing, otherwise "read" continues reading.
225  if (buf[maxSize-1] != '\n')
226  {
227  buf[maxSize] = '\n';
228  // Null terminate in case the string is passed back to C.
229  // Not sure that is actually needed.
230  buf[maxSize + 1] = 0;
231  }
232  txgive_(buf, iter->length() );
233  }
234 
235  return ;
236 #undef SETCSAPARBUFSIZE
237 }
#define SETCSAPARBUFSIZE
void txgive_init_(void)
std::vector< std::string > fParamCSA
return(e1-e2)*(e1-e2)+dp *dp
void txgive_(const char *, int)
void Pythia6Service::setGeneralParams ( )

Definition at line 189 of file Pythia6Service.cc.

References gen::call_pygive(), fParamGeneral, and reco::return().

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

190 {
191  // now pass general config cards
192  //
193  for(std::vector<std::string>::const_iterator iter = fParamGeneral.begin();
194  iter != fParamGeneral.end(); ++iter)
195  {
196  if (!call_pygive(*iter))
197  throw cms::Exception("PythiaError")
198  << "Pythia did not accept \""
199  << *iter << "\"." << std::endl;
200  }
201 
202  return ;
203 }
bool call_pygive(const std::string &line)
std::vector< std::string > fParamGeneral
return(e1-e2)*(e1-e2)+dp *dp
void Pythia6Service::setPYUPDAParams ( bool  afterPyinit)

Definition at line 332 of file Pythia6Service.cc.

References end, connectstrParser::f1, FrontierConditions_GlobalTag_cff::file, fParamPYUPDA, edm::FileInPath::fullPath(), openPYUPDA(), AlCaHLTBitMon_QueryRunRegistry::string, and groupFilesInBlocks::temp.

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

333 {
334  std::string shortfile;
335  bool write_file = false;
336  bool usePostPyinit = false;
337 
338  // std::cout<<"=== CALLING setPYUPDAParams === "<<afterPyinit<<" "<<fParamPYUPDA.size()<<std::endl;
339 
340  // This assumes that PYUPDAFILE only appears once ...
341 
342  for (std::vector<std::string>::const_iterator iter = fParamPYUPDA.begin();
343  iter != fParamPYUPDA.end(); iter++ )
344  {
345  // std::cout<<"PYUPDA check "<<*iter<<std::endl;
346  if( iter->find( "PYUPDAFILE", 0 ) != std::string::npos ) {
347  std::string::size_type start = iter->find_first_of( "=" ) + 1;
348  std::string::size_type end = iter->length() - 1;
349  std::string::size_type temp = iter->find_first_of( "'", start );
350  if( temp != std::string::npos ) {
351  start = temp + 1;
352  end = iter->find_last_of( "'" ) - 1;
353  }
354  start = iter->find_first_not_of( " ", start );
355  end = iter->find_last_not_of( " ", end );
356  //std::cout << " start, end = " << start << " " << end << std::endl;
357  shortfile = iter->substr( start, end - start + 1 );
358  } else if ( iter->find( "PYUPDAWRITE", 0 ) != std::string::npos ) {
359  write_file = true;
360  } else if ( iter->find( "PYUPDApostPYINIT", 0 ) != std::string::npos ) {
361  usePostPyinit = true;
362  }
363  }
364 
365  if (!shortfile.empty()) {
367  if (write_file) {
368  file = shortfile;
369  } else {
370  // If reading, get full path to file and require it to exist.
371  FileInPath f1( shortfile );
372  file = f1.fullPath();
373  }
374 
375  if (afterPyinit == usePostPyinit || (write_file && afterPyinit)) {
376  openPYUPDA( file.c_str(), write_file );
377  }
378  }
379 
380  return;
381 }
Definition: start.py:1
uint16_t size_type
std::vector< std::string > fParamPYUPDA
#define end
Definition: vmac.h:39
void openPYUPDA(const char *, bool write_file)
void gen::Pythia6Service::setRandomEngine ( CLHEP::HepRandomEngine *  v)
inline
void Pythia6Service::setSLHAFromHeader ( const std::vector< std::string > &  lines)

Definition at line 383 of file Pythia6Service.cc.

References groupFilesInBlocks::block, gather_cfg::blocks, call_pyslha(), FrontierConditions_GlobalTag_cff::file, alignmentValidation::fname, createfilelist::int, geometryCSVtoXML::line, openSLHA(), MillePedeFileConverter_cfg::out, gen::pydat1_, MatrixUtil::remove(), reco::return(), split, mathSSE::sqrt(), AlCaHLTBitMon_QueryRunRegistry::string, create_public_lumi_plots::transform, estimatePileup_makeJSON::trunc, and relativeConstraints::value.

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

384 {
385  std::set<std::string> blocks;
386  unsigned int model = 0, subModel = 0;
387 
388  std::string fnamest = boost::filesystem::unique_path().string();
389  const char *fname = fnamest.c_str();
390  std::ofstream file(fname, std::fstream::out | std::fstream::trunc);
392  for(std::vector<std::string>::const_iterator iter = lines.begin();
393  iter != lines.end(); ++iter) {
394  file << *iter;
395 
396  std::string line = *iter;
397  std::transform(line.begin(), line.end(),
398  line.begin(), (int(*)(int))std::toupper);
399  std::string::size_type pos = line.find('#');
400  if (pos != std::string::npos)
401  line.resize(pos);
402 
403  if (line.empty())
404  continue;
405 
406  if (!boost::algorithm::is_space()(line[0])) {
407  std::vector<std::string> tokens;
408  boost::split(tokens, line,
409  boost::algorithm::is_space(),
410  boost::token_compress_on);
411  if (tokens.empty())
412  continue;
413  block.clear();
414  if (tokens.size() < 2)
415  continue;
416  if (tokens[0] == "BLOCK") {
417  block = tokens[1];
418  blocks.insert(block);
419  continue;
420  }
421 
422  if (tokens[0] == "DECAY") {
423  block = "DECAY";
424  blocks.insert(block);
425  }
426  } else if (block == "MODSEL") {
427  std::istringstream ss(line);
428  ss >> model >> subModel;
429  } else if (block == "SMINPUTS") {
430  std::istringstream ss(line);
431  int index;
432  double value;
433  ss >> index >> value;
434  switch(index) {
435  case 1:
436  pydat1_.paru[103 - 1] = 1.0 / value;
437  break;
438  case 2:
439  pydat1_.paru[105 - 1] = value;
440  break;
441  case 4:
442  pydat2_.pmas[0][23 - 1] = value;
443  break;
444  case 6:
445  pydat2_.pmas[0][6 - 1] = value;
446  break;
447  case 7:
448  pydat2_.pmas[0][15 - 1] = value;
449  break;
450  }
451  }
452  }
453  file.close();
454 
455  if (blocks.count("SMINPUTS"))
456  pydat1_.paru[102 - 1] = 0.5 - std::sqrt(0.25 -
457  pydat1_.paru[0] * M_SQRT1_2 *
458  pydat1_.paru[103 - 1] / pydat1_.paru[105 - 1] /
459  (pydat2_.pmas[0][23 - 1] * pydat2_.pmas[0][23 - 1]));
460 
461 /*
462  int unit = 24;
463  fioopn_(&unit, fname, std::strlen(fname));
464  std::remove(fname);
465 
466  call_pygive("IMSS(21)=24");
467  call_pygive("IMSS(22)=24");
468 */
469 
470  openSLHA( fname ) ;
471  std::remove( fname );
472 
473  if (model ||
474  blocks.count("HIGMIX") ||
475  blocks.count("SBOTMIX") ||
476  blocks.count("STOPMIX") ||
477  blocks.count("STAUMIX") ||
478  blocks.count("AMIX") ||
479  blocks.count("NMIX") ||
480  blocks.count("UMIX") ||
481  blocks.count("VMIX"))
482  call_pyslha(1);
483  if (model ||
484  blocks.count("QNUMBERS") ||
485  blocks.count("PARTICLE") ||
486  blocks.count("MINPAR") ||
487  blocks.count("EXTPAR") ||
488  blocks.count("SMINPUTS") ||
489  blocks.count("SMINPUTS"))
490  call_pyslha(0);
491  if (blocks.count("MASS"))
492  call_pyslha(5, 0);
493  if (blocks.count("DECAY"))
494  call_pyslha(2);
495 
496  return ;
497 
498 }
uint16_t size_type
T sqrt(T t)
Definition: SSEVec.h:18
static int call_pyslha(int mupda, int kforig=0)
struct gen::@617 pydat1_
void openSLHA(const char *)
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:211
return(e1-e2)*(e1-e2)+dp *dp
string fname
main script
double split
Definition: MVATrainer.cc:139
void Pythia6Service::setSLHAParams ( )

Definition at line 291 of file Pythia6Service.cc.

References end, connectstrParser::f1, FrontierConditions_GlobalTag_cff::file, fParamSLHA, edm::FileInPath::fullPath(), openSLHA(), AlCaHLTBitMon_QueryRunRegistry::string, and groupFilesInBlocks::temp.

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

292 {
293  for (std::vector<std::string>::const_iterator iter = fParamSLHA.begin();
294  iter != fParamSLHA.end(); iter++ )
295  {
296 
297  if( iter->find( "SLHAFILE", 0 ) == std::string::npos ) continue;
298  std::string::size_type start = iter->find_first_of( "=" ) + 1;
299  std::string::size_type end = iter->length() - 1;
300  std::string::size_type temp = iter->find_first_of( "'", start );
301  if( temp != std::string::npos ) {
302  start = temp + 1;
303  end = iter->find_last_of( "'" ) - 1;
304  }
305  start = iter->find_first_not_of( " ", start );
306  end = iter->find_last_not_of( " ", end );
307  //std::cout << " start, end = " << start << " " << end << std::endl;
308  std::string shortfile = iter->substr( start, end - start + 1 );
309  FileInPath f1( shortfile );
310  std::string file = f1.fullPath();
311 
312 /*
313  //
314  // override what might have be given via the external config
315  //
316  std::ostringstream pyCard ;
317  pyCard << "IMSS(21)=" << fUnitSLHA;
318  call_pygive( pyCard.str() );
319  pyCard << "IMSS(22)=" << fUnitSLHA;
320  call_pygive( pyCard.str() );
321 
322  fioopn_( &fUnitSLHA, file.c_str(), file.length() );
323 */
324 
325  openSLHA( file.c_str() );
326 
327  }
328 
329  return;
330 }
Definition: start.py:1
uint16_t size_type
#define end
Definition: vmac.h:39
void openSLHA(const char *)
std::vector< std::string > fParamSLHA

Friends And Related Function Documentation

double gen::pyr_ ( int *  )
friend

Member Data Documentation

bool gen::Pythia6Service::fInitialising
private

Definition at line 53 of file Pythia6Service.h.

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

Definition at line 58 of file Pythia6Service.h.

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

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

Definition at line 57 of file Pythia6Service.h.

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

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

Definition at line 60 of file Pythia6Service.h.

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

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

Definition at line 59 of file Pythia6Service.h.

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

Pythia6Service * Pythia6Service::fPythia6Owner = 0
staticprivate

Definition at line 64 of file Pythia6Service.h.

Referenced by enter(), gen::pyr_(), Pythia6Service(), and ~Pythia6Service().

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

Definition at line 55 of file Pythia6Service.h.

Referenced by gen::pyr_(), and Pythia6Service().

int gen::Pythia6Service::fUnitPYUPDA
private

Definition at line 62 of file Pythia6Service.h.

Referenced by closePYUPDA(), openPYUPDA(), and Pythia6Service().

int gen::Pythia6Service::fUnitSLHA
private

Definition at line 61 of file Pythia6Service.h.

Referenced by closeSLHA(), openSLHA(), and Pythia6Service().