CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 myPythia6ServiceWithCallback

Public Member Functions

void closePYUPDA ()
 
void closeSLHA ()
 
virtual void enter ()
 
void openPYUPDA (const char *, bool write_file)
 
void openSLHA (const char *)
 
 Pythia6Service ()
 
 Pythia6Service (edm::ParameterSet 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 ()
 
- 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 ()
 

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 ()
 

Detailed Description

Definition at line 26 of file Pythia6Service.h.

Constructor & Destructor Documentation

Pythia6Service::Pythia6Service ( )

Definition at line 80 of file Pythia6Service.cc.

81  : fRandomEngine(nullptr), fUnitSLHA(24), fUnitPYUPDA(25)
82 {
83 }
CLHEP::HepRandomEngine * fRandomEngine
Pythia6Service::Pythia6Service ( edm::ParameterSet const &  ps)

Definition at line 85 of file Pythia6Service.cc.

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

87 {
88  if (fPythia6Owner)
89  throw cms::Exception("PythiaError") <<
90  "Two Pythia6Service instances claiming Pythia6 ownership." <<
91  std::endl;
92 
93  fPythia6Owner = this;
94 
95 /*
96  ParameterCollector collector(ps.getParameter<edm::ParameterSet>("PythiaParameters"));
97 
98  fParamGeneral.clear();
99  fParamCSA.clear();
100  fParamSLHA.clear();
101 
102  fParamGeneral = std::vector<std::string>(collector.begin(), collector.end());
103  fParamCSA = std::vector<std::string>(collector.begin("CSAParameters"), collector.end());
104  fParamSLHA = std::vector<std::string>(collector.begin("SLHAParameters"), collector.end());
105 */
106 
107 
108  // Set PYTHIA parameters in a single ParameterSet
109  //
110  edm::ParameterSet pythia_params =
111  ps.getParameter<edm::ParameterSet>("PythiaParameters") ;
112 
113  // read and sort Pythia6 cards
114  //
115  std::vector<std::string> setNames =
116  pythia_params.getParameter<std::vector<std::string> >("parameterSets");
117 
118  // std::vector<std::string> paramLines;
119  fParamGeneral.clear();
120  fParamCSA.clear();
121  fParamSLHA.clear();
122  fParamPYUPDA.clear();
123 
124 
125  for(std::vector<std::string>::const_iterator iter = setNames.begin();
126  iter != setNames.end(); ++iter)
127  {
128  std::vector<std::string> lines =
129  pythia_params.getParameter< std::vector<std::string> >(*iter);
130 
131  for(std::vector<std::string>::const_iterator line = lines.begin();
132  line != lines.end(); ++line )
133  {
134  if (line->substr(0, 7) == "MRPY(1)")
135  throw cms::Exception("PythiaError") <<
136  "Attempted to set random number"
137  " using Pythia command 'MRPY(1)'."
138  " Please use the"
139  " RandomNumberGeneratorService." <<
140  std::endl;
141 
142  if ( *iter == "CSAParameters" )
143  {
144  fParamCSA.push_back(*line);
145  }
146  else if ( *iter == "SLHAParameters" )
147  {
148  fParamSLHA.push_back(*line);
149  }
150  else if ( *iter == "PYUPDAParameters" )
151  {
152  fParamPYUPDA.push_back(*line);
153  }
154  else
155  {
156  fParamGeneral.push_back(*line);
157  }
158  }
159  }
160 }
T getParameter(std::string const &) const
CLHEP::HepRandomEngine & getEngineReference()
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 ( )

Definition at line 162 of file Pythia6Service.cc.

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

163 {
164  if (fPythia6Owner == this)
165  fPythia6Owner = 0;
166 
167  fParamGeneral.clear();
168  fParamCSA.clear();
169  fParamSLHA.clear();
170  fParamPYUPDA.clear();
171 }
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 283 of file Pythia6Service.cc.

References fiocls_(), and fUnitPYUPDA.

284 {
285 
287 
288  return;
289 
290 }
void fiocls_(int *unit)
void Pythia6Service::closeSLHA ( )
void Pythia6Service::enter ( )
virtual

Reimplemented from gen::FortranInstance.

Definition at line 173 of file Pythia6Service.cc.

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

174 {
176 
177  if (!fPythia6Owner) {
178  edm::LogInfo("Generator|Pythia6Interface") <<
179  "gen::Pythia6Service is going to initialise Pythia, as no other "
180  "instace has done so yet, and Pythia service routines have been "
181  "requested by a dummy instance." << std::endl;
182 
183  call_pygive("MSTU(12)=12345");
184  call_pyinit("NONE", "", "", 0.0);
185 
186  fPythia6Owner = this;
187  }
188 }
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 256 of file Pythia6Service.cc.

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

Referenced by setPYUPDAParams().

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

Definition at line 240 of file Pythia6Service.cc.

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

Referenced by setSLHAFromHeader(), and setSLHAParams().

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

Definition at line 206 of file Pythia6Service.cc.

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

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

207 {
208 #define SETCSAPARBUFSIZE 514
209  char buf[SETCSAPARBUFSIZE];
210 
211  txgive_init_();
212  for(std::vector<std::string>::const_iterator iter = fParamCSA.begin();
213  iter != fParamCSA.end(); ++iter)
214  {
215  // Null pad the string should not be needed because it uses
216  // read, which will look for \n, but just in case...
217  for (size_t i = 0; i < SETCSAPARBUFSIZE; ++i)
218  buf[i] = ' ';
219  // Skip empty parameters.
220  if (iter->length() <= 0)
221  continue;
222  // Limit the size of the string to something which fits the buffer.
223  size_t maxSize = iter->length() > (SETCSAPARBUFSIZE-2) ? (SETCSAPARBUFSIZE-2) : iter->length();
224  strncpy(buf, iter->c_str(), maxSize);
225  // Add extra \n if missing, otherwise "read" continues reading.
226  if (buf[maxSize-1] != '\n')
227  {
228  buf[maxSize] = '\n';
229  // Null terminate in case the string is passed back to C.
230  // Not sure that is actually needed.
231  buf[maxSize + 1] = 0;
232  }
233  txgive_(buf, iter->length() );
234  }
235 
236  return ;
237 #undef SETCSAPARBUFSIZE
238 }
int i
Definition: DBlmapReader.cc:9
tuple maxSize
&#39;/store/data/Commissioning08/BeamHalo/RECO/StuffAlmostToP5_v1/000/061/642/10A0FE34-A67D-DD11-AD05-000...
#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 190 of file Pythia6Service.cc.

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

Referenced by ParticleReplacerParticleGun::beginJob(), ParticleReplacerZtautau::beginJob(), gen::Pythia6Gun::beginRun(), GenMuonRadiationAlgorithm::compFSR(), gen::Cascade2Hadronizer::initializeForInternalPartons(), gen::Cascade2Hadronizer::readSettings(), gen::PyquenHadronizer::readSettings(), gen::HydjetHadronizer::readSettings(), gen::Pythia6Hadronizer::readSettings(), and gen::ExhumeHadronizer::readSettings().

191 {
192  // now pass general config cards
193  //
194  for(std::vector<std::string>::const_iterator iter = fParamGeneral.begin();
195  iter != fParamGeneral.end(); ++iter)
196  {
197  if (!call_pygive(*iter))
198  throw cms::Exception("PythiaError")
199  << "Pythia did not accept \""
200  << *iter << "\"." << std::endl;
201  }
202 
203  return ;
204 }
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 333 of file Pythia6Service.cc.

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

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

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

Definition at line 48 of file Pythia6Service.h.

References fRandomEngine, and gen::v.

48 { fRandomEngine = v; }
double v[5][pyjets_maxn]
CLHEP::HepRandomEngine * fRandomEngine
void Pythia6Service::setSLHAFromHeader ( const std::vector< std::string > &  lines)

Definition at line 384 of file Pythia6Service.cc.

References createPayload::block, gather_cfg::blocks, call_pyslha(), mergeVDriftHistosByStation::file, alignmentValidation::fname, getHLTprescales::index, geometryCSVtoXML::line, NULL, openSLHA(), dbtoconf::out, gen::pydat1_, python.multivaluedict::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().

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

Definition at line 292 of file Pythia6Service.cc.

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

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

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

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

Definition at line 55 of file Pythia6Service.h.

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

int gen::Pythia6Service::fUnitPYUPDA
private

Definition at line 62 of file Pythia6Service.h.

Referenced by closePYUPDA(), and openPYUPDA().

int gen::Pythia6Service::fUnitSLHA
private

Definition at line 61 of file Pythia6Service.h.

Referenced by closeSLHA(), and openSLHA().