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

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 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 59 of file Pythia6Service.cc.

61 {
62 }
CLHEP::HepRandomEngine & getEngineReference()
CLHEP::HepRandomEngine * fRandomEngine
Pythia6Service::Pythia6Service ( edm::ParameterSet const &  ps)

Definition at line 64 of file Pythia6Service.cc.

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

66 {
67  if (fPythia6Owner)
68  throw cms::Exception("PythiaError") <<
69  "Two Pythia6Service instances claiming Pythia6 ownership." <<
70  std::endl;
71 
72  fPythia6Owner = this;
73 
74 /*
75  ParameterCollector collector(ps.getParameter<edm::ParameterSet>("PythiaParameters"));
76 
77  fParamGeneral.clear();
78  fParamCSA.clear();
79  fParamSLHA.clear();
80 
81  fParamGeneral = std::vector<std::string>(collector.begin(), collector.end());
82  fParamCSA = std::vector<std::string>(collector.begin("CSAParameters"), collector.end());
83  fParamSLHA = std::vector<std::string>(collector.begin("SLHAParameters"), collector.end());
84 */
85 
86 
87  // Set PYTHIA parameters in a single ParameterSet
88  //
89  edm::ParameterSet pythia_params =
90  ps.getParameter<edm::ParameterSet>("PythiaParameters") ;
91 
92  // read and sort Pythia6 cards
93  //
94  std::vector<std::string> setNames =
95  pythia_params.getParameter<std::vector<std::string> >("parameterSets");
96 
97  // std::vector<std::string> paramLines;
98  fParamGeneral.clear();
99  fParamCSA.clear();
100  fParamSLHA.clear();
101  fParamPYUPDA.clear();
102 
103 
104  for(std::vector<std::string>::const_iterator iter = setNames.begin();
105  iter != setNames.end(); ++iter)
106  {
107  std::vector<std::string> lines =
108  pythia_params.getParameter< std::vector<std::string> >(*iter);
109 
110  for(std::vector<std::string>::const_iterator line = lines.begin();
111  line != lines.end(); ++line )
112  {
113  if (line->substr(0, 7) == "MRPY(1)")
114  throw cms::Exception("PythiaError") <<
115  "Attempted to set random number"
116  " using Pythia command 'MRPY(1)'."
117  " Please use the"
118  " RandomNumberGeneratorService." <<
119  std::endl;
120 
121  if ( *iter == "CSAParameters" )
122  {
123  fParamCSA.push_back(*line);
124  }
125  else if ( *iter == "SLHAParameters" )
126  {
127  fParamSLHA.push_back(*line);
128  }
129  else if ( *iter == "PYUPDAParameters" )
130  {
131  fParamPYUPDA.push_back(*line);
132  }
133  else
134  {
135  fParamGeneral.push_back(*line);
136  }
137  }
138  }
139 }
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 141 of file Pythia6Service.cc.

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

142 {
143  if (fPythia6Owner == this)
144  fPythia6Owner = 0;
145 
146  fParamGeneral.clear();
147  fParamCSA.clear();
148  fParamSLHA.clear();
149  fParamPYUPDA.clear();
150 }
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 242 of file Pythia6Service.cc.

References fiocls_(), and fUnitPYUPDA.

243 {
244 
246 
247  return;
248 
249 }
void fiocls_(int *unit)
void Pythia6Service::closeSLHA ( )

Definition at line 234 of file Pythia6Service.cc.

References fiocls_(), and fUnitSLHA.

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

235 {
236 
237  fiocls_(&fUnitSLHA);
238 
239  return;
240 }
void fiocls_(int *unit)
void Pythia6Service::enter ( )
virtual

Reimplemented from gen::FortranInstance.

Definition at line 152 of file Pythia6Service.cc.

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

153 {
155 
156  if (!fPythia6Owner) {
157  edm::LogInfo("Generator|Pythia6Interface") <<
158  "gen::Pythia6Service is going to initialise Pythia, as no other "
159  "instace has done so yet, and Pythia service routines have been "
160  "requested by a dummy instance." << std::endl;
161 
162  call_pygive("MSTU(12)=12345");
163  call_pyinit("NONE", "", "", 0.0);
164 
165  fPythia6Owner = this;
166  }
167 }
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 215 of file Pythia6Service.cc.

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

Referenced by setPYUPDAParams().

216 {
217 
218  if (write_file) {
219  std::cout<<"=== WRITING PYUPDA FILE "<<file<<" ==="<<std::endl;
220  fioopnw_( &fUnitPYUPDA, file, strlen(file) );
221  // Write Pythia particle table to this card file.
223  } else {
224  std::cout<<"=== READING PYUPDA FILE "<<file<<" ==="<<std::endl;
225  fioopn_( &fUnitPYUPDA, file, strlen(file) );
226  // Update Pythia particle table with this card file.
228  }
229 
230  return;
231 
232 }
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:41
void Pythia6Service::openSLHA ( const char *  file)

Definition at line 199 of file Pythia6Service.cc.

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

Referenced by setSLHAFromHeader(), and setSLHAParams().

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

Definition at line 185 of file Pythia6Service.cc.

References fParamCSA, mathSSE::return(), gen::txgive_(), and gen::txgive_init_().

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

186 {
187 
188  txgive_init_();
189 
190  for(std::vector<std::string>::const_iterator iter = fParamCSA.begin();
191  iter != fParamCSA.end(); ++iter)
192  {
193  txgive_( iter->c_str(), iter->length() );
194  }
195 
196  return ;
197 }
return((rh^lh)&mask)
void txgive_init_(void)
std::vector< std::string > fParamCSA
void txgive_(const char *, int)
void Pythia6Service::setGeneralParams ( )

Definition at line 169 of file Pythia6Service.cc.

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

Referenced by gen::Pythia6Gun::beginRun(), gen::Pythia6Hadronizer::initializeForExternalPartons(), gen::PyquenHadronizer::initializeForInternalPartons(), gen::HydjetHadronizer::initializeForInternalPartons(), gen::Pythia6Hadronizer::initializeForInternalPartons(), and gen::ExhumeHadronizer::initializeForInternalPartons().

170 {
171  // now pass general config cards
172  //
173  for(std::vector<std::string>::const_iterator iter = fParamGeneral.begin();
174  iter != fParamGeneral.end(); ++iter)
175  {
176  if (!call_pygive(*iter))
177  throw cms::Exception("PythiaError")
178  << "Pythia did not accept \""
179  << *iter << "\"." << std::endl;
180  }
181 
182  return ;
183 }
bool call_pygive(const std::string &line)
return((rh^lh)&mask)
std::vector< std::string > fParamGeneral
void Pythia6Service::setPYUPDAParams ( bool  afterPyinit)

Definition at line 292 of file Pythia6Service.cc.

References end, connectstrParser::f1, mergeVDriftHistosByStation::file, fParamPYUPDA, edm::FileInPath::fullPath(), openPYUPDA(), and cond::rpcobtemp::temp.

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

293 {
294  std::string shortfile;
295  bool write_file = false;
296  bool usePostPyinit = false;
297 
298  // std::cout<<"=== CALLING setPYUPDAParams === "<<afterPyinit<<" "<<fParamPYUPDA.size()<<std::endl;
299 
300  // This assumes that PYUPDAFILE only appears once ...
301 
302  for (std::vector<std::string>::const_iterator iter = fParamPYUPDA.begin();
303  iter != fParamPYUPDA.end(); iter++ )
304  {
305  // std::cout<<"PYUPDA check "<<*iter<<std::endl;
306  if( iter->find( "PYUPDAFILE", 0 ) != std::string::npos ) {
307  std::string::size_type start = iter->find_first_of( "=" ) + 1;
308  std::string::size_type end = iter->length() - 1;
309  std::string::size_type temp = iter->find_first_of( "'", start );
310  if( temp != std::string::npos ) {
311  start = temp + 1;
312  end = iter->find_last_of( "'" ) - 1;
313  }
314  start = iter->find_first_not_of( " ", start );
315  end = iter->find_last_not_of( " ", end );
316  //std::cout << " start, end = " << start << " " << end << std::endl;
317  shortfile = iter->substr( start, end - start + 1 );
318  } else if ( iter->find( "PYUPDAWRITE", 0 ) != std::string::npos ) {
319  write_file = true;
320  } else if ( iter->find( "PYUPDApostPYINIT", 0 ) != std::string::npos ) {
321  usePostPyinit = true;
322  }
323  }
324 
325  if (!shortfile.empty()) {
326  std::string file;
327  if (write_file) {
328  file = shortfile;
329  } else {
330  // If reading, get full path to file and require it to exist.
331  FileInPath f1( shortfile );
332  file = f1.fullPath();
333  }
334 
335  if (afterPyinit == usePostPyinit || (write_file && afterPyinit)) {
336  openPYUPDA( file.c_str(), write_file );
337  }
338  }
339 
340  return;
341 }
uint16_t size_type
std::vector< std::string > fParamPYUPDA
#define end
Definition: vmac.h:38
void openPYUPDA(const char *, bool write_file)
void Pythia6Service::setSLHAFromHeader ( const std::vector< std::string > &  lines)

Definition at line 343 of file Pythia6Service.cc.

References createPayload::block, runregparse::blocks, call_pyslha(), mergeVDriftHistosByStation::file, alignmentValidation::fname, getHLTprescales::index, geometryCSVtoXML::line, NULL, openSLHA(), dbtoconf::out, pos, gen::pydat1_, python.multivaluedict::remove(), mathSSE::return(), split, mathSSE::sqrt(), EcalElecEmulTccFlatFileProducerFromTPG_cfg::tokens, and relativeConstraints::value.

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

344 {
345 
346  std::set<std::string> blocks;
347  unsigned int model = 0, subModel = 0;
348 
349  const char *fname = std::tmpnam(NULL);
350  std::ofstream file(fname, std::fstream::out | std::fstream::trunc);
351  std::string block;
352  for(std::vector<std::string>::const_iterator iter = lines.begin();
353  iter != lines.end(); ++iter) {
354  file << *iter;
355 
356  std::string line = *iter;
357  std::transform(line.begin(), line.end(),
358  line.begin(), (int(*)(int))std::toupper);
359  std::string::size_type pos = line.find('#');
360  if (pos != std::string::npos)
361  line.resize(pos);
362 
363  if (line.empty())
364  continue;
365 
366  if (!boost::algorithm::is_space()(line[0])) {
367  std::vector<std::string> tokens;
368  boost::split(tokens, line,
369  boost::algorithm::is_space(),
370  boost::token_compress_on);
371  if (!tokens.size())
372  continue;
373  block.clear();
374  if (tokens.size() < 2)
375  continue;
376  if (tokens[0] == "BLOCK") {
377  block = tokens[1];
378  blocks.insert(block);
379  continue;
380  }
381 
382  if (tokens[0] == "DECAY") {
383  block = "DECAY";
384  blocks.insert(block);
385  }
386  } else if (block == "MODSEL") {
387  std::istringstream ss(line);
388  ss >> model >> subModel;
389  } else if (block == "SMINPUTS") {
390  std::istringstream ss(line);
391  int index;
392  double value;
393  ss >> index >> value;
394  switch(index) {
395  case 1:
396  pydat1_.paru[103 - 1] = 1.0 / value;
397  break;
398  case 2:
399  pydat1_.paru[105 - 1] = value;
400  break;
401  case 4:
402  pydat2_.pmas[0][23 - 1] = value;
403  break;
404  case 6:
405  pydat2_.pmas[0][6 - 1] = value;
406  break;
407  case 7:
408  pydat2_.pmas[0][15 - 1] = value;
409  break;
410  }
411  }
412  }
413  file.close();
414 
415  if (blocks.count("SMINPUTS"))
416  pydat1_.paru[102 - 1] = 0.5 - std::sqrt(0.25 -
417  pydat1_.paru[0] * M_SQRT1_2 *
418  pydat1_.paru[103 - 1] / pydat1_.paru[105 - 1] /
419  (pydat2_.pmas[0][23 - 1] * pydat2_.pmas[0][23 - 1]));
420 
421 /*
422  int unit = 24;
423  fioopn_(&unit, fname, std::strlen(fname));
424  std::remove(fname);
425 
426  call_pygive("IMSS(21)=24");
427  call_pygive("IMSS(22)=24");
428 */
429 
430  openSLHA( fname ) ;
431  std::remove( fname );
432 
433  if (model ||
434  blocks.count("HIGMIX") ||
435  blocks.count("SBOTMIX") ||
436  blocks.count("STOPMIX") ||
437  blocks.count("STAUMIX") ||
438  blocks.count("AMIX") ||
439  blocks.count("NMIX") ||
440  blocks.count("UMIX") ||
441  blocks.count("VMIX"))
442  call_pyslha(1);
443  if (model ||
444  blocks.count("QNUMBERS") ||
445  blocks.count("PARTICLE") ||
446  blocks.count("MINPAR") ||
447  blocks.count("EXTPAR") ||
448  blocks.count("SMINPUTS") ||
449  blocks.count("SMINPUTS"))
450  call_pyslha(0);
451  if (blocks.count("MASS"))
452  call_pyslha(5, 0);
453  if (blocks.count("DECAY"))
454  call_pyslha(2);
455 
456  return ;
457 
458 }
struct gen::@243 pydat1_
#define NULL
Definition: scimark2.h:8
uint16_t size_type
return((rh^lh)&mask)
T sqrt(T t)
Definition: SSEVec.h:28
static int call_pyslha(int mupda, int kforig=0)
tuple out
Definition: dbtoconf.py:99
void openSLHA(const char *)
string fname
main script
double split
Definition: MVATrainer.cc:139
void Pythia6Service::setSLHAParams ( )

Definition at line 251 of file Pythia6Service.cc.

References end, connectstrParser::f1, mergeVDriftHistosByStation::file, fParamSLHA, edm::FileInPath::fullPath(), openSLHA(), and cond::rpcobtemp::temp.

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

252 {
253  for (std::vector<std::string>::const_iterator iter = fParamSLHA.begin();
254  iter != fParamSLHA.end(); iter++ )
255  {
256 
257  if( iter->find( "SLHAFILE", 0 ) == std::string::npos ) continue;
258  std::string::size_type start = iter->find_first_of( "=" ) + 1;
259  std::string::size_type end = iter->length() - 1;
260  std::string::size_type temp = iter->find_first_of( "'", start );
261  if( temp != std::string::npos ) {
262  start = temp + 1;
263  end = iter->find_last_of( "'" ) - 1;
264  }
265  start = iter->find_first_not_of( " ", start );
266  end = iter->find_last_not_of( " ", end );
267  //std::cout << " start, end = " << start << " " << end << std::endl;
268  std::string shortfile = iter->substr( start, end - start + 1 );
269  FileInPath f1( shortfile );
270  std::string file = f1.fullPath();
271 
272 /*
273  //
274  // override what might have be given via the external config
275  //
276  std::ostringstream pyCard ;
277  pyCard << "IMSS(21)=" << fUnitSLHA;
278  call_pygive( pyCard.str() );
279  pyCard << "IMSS(22)=" << fUnitSLHA;
280  call_pygive( pyCard.str() );
281 
282  fioopn_( &fUnitSLHA, file.c_str(), file.length() );
283 */
284 
285  openSLHA( file.c_str() );
286 
287  }
288 
289  return;
290 }
uint16_t size_type
#define end
Definition: vmac.h:38
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 51 of file Pythia6Service.h.

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

Definition at line 56 of file Pythia6Service.h.

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

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

Definition at line 55 of file Pythia6Service.h.

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

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

Definition at line 58 of file Pythia6Service.h.

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

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

Definition at line 57 of file Pythia6Service.h.

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

Pythia6Service * Pythia6Service::fPythia6Owner = 0
staticprivate

Definition at line 62 of file Pythia6Service.h.

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

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

Definition at line 53 of file Pythia6Service.h.

Referenced by gen::pyr_().

int gen::Pythia6Service::fUnitPYUPDA
private

Definition at line 60 of file Pythia6Service.h.

Referenced by closePYUPDA(), and openPYUPDA().

int gen::Pythia6Service::fUnitSLHA
private

Definition at line 59 of file Pythia6Service.h.

Referenced by closeSLHA(), and openSLHA().