10 #include <boost/bind.hpp> 11 #include <boost/algorithm/string/classification.hpp> 12 #include <boost/algorithm/string/split.hpp> 13 #include <boost/filesystem.hpp> 15 #include "CLHEP/Random/RandomEngine.h" 34 char* dummy3 =
nullptr;
38 py1ent_(dummy, dummy, dummy2, dummy2, dummy2);
48 void fioopnw_(
int* unit,
const char* line,
int length);
53 pyslha_(&mupda, &kforig, &iretrn);
77 throw cms::Exception(
"PythiaError") <<
"Two Pythia6Service instances claiming Pythia6 ownership." << std::endl;
99 std::vector<std::string> setNames = pythia_params.
getParameter<std::vector<std::string> >(
"parameterSets");
107 for (std::vector<std::string>::const_iterator iter = setNames.begin(); iter != setNames.end(); ++iter) {
108 std::vector<std::string>
lines = pythia_params.
getParameter<std::vector<std::string> >(*iter);
110 for (std::vector<std::string>::const_iterator
line = lines.begin();
line != lines.end(); ++
line) {
111 if (
line->substr(0, 7) ==
"MRPY(1)")
112 throw cms::Exception(
"PythiaError") <<
"Attempted to set random number" 113 " using Pythia command 'MRPY(1)'." 115 " RandomNumberGeneratorService." 118 if (*iter ==
"CSAParameters") {
120 }
else if (*iter ==
"SLHAParameters") {
122 }
else if (*iter ==
"PYUPDAParameters") {
145 edm::LogInfo(
"Generator|Pythia6Interface") <<
"gen::Pythia6Service is going to initialise Pythia, as no other " 146 "instace has done so yet, and Pythia service routines have been " 147 "requested by a dummy instance." 151 call_pyinit(
"NONE",
"",
"", 0.0);
162 throw cms::Exception(
"PythiaError") <<
"Pythia did not accept \"" << *iter <<
"\"." << std::endl;
169 #define SETCSAPARBUFSIZE 514 173 for (std::vector<std::string>::const_iterator iter =
fParamCSA.begin(); iter !=
fParamCSA.end(); ++iter) {
179 if (iter->length() <= 0)
182 size_t maxSize = iter->length() > (SETCSAPARBUFSIZE - 2) ? (SETCSAPARBUFSIZE - 2) : iter->length();
183 strncpy(buf, iter->c_str(),
maxSize);
185 if (buf[maxSize - 1] !=
'\n') {
189 buf[maxSize + 1] = 0;
195 #undef SETCSAPARBUFSIZE 199 std::ostringstream pyCard1;
202 std::ostringstream pyCard2;
206 fioopn_(&fUnitSLHA, file, strlen(file));
213 std::cout <<
"=== WRITING PYUPDA FILE " << file <<
" ===" << std::endl;
218 std::cout <<
"=== READING PYUPDA FILE " << file <<
" ===" << std::endl;
240 for (std::vector<std::string>::const_iterator iter =
fParamSLHA.begin(); iter !=
fParamSLHA.end(); iter++) {
241 if (iter->find(
"SLHAFILE", 0) == std::string::npos)
246 if (temp != std::string::npos) {
248 end = iter->find_last_of(
"'") - 1;
250 start = iter->find_first_not_of(
" ", start);
251 end = iter->find_last_not_of(
" ", end);
253 std::string shortfile = iter->substr(start, end - start + 1);
278 bool write_file =
false;
279 bool usePostPyinit =
false;
287 if (iter->find(
"PYUPDAFILE", 0) != std::string::npos) {
291 if (temp != std::string::npos) {
293 end = iter->find_last_of(
"'") - 1;
295 start = iter->find_first_not_of(
" ", start);
296 end = iter->find_last_not_of(
" ", end);
298 shortfile = iter->substr(start, end - start + 1);
299 }
else if (iter->find(
"PYUPDAWRITE", 0) != std::string::npos) {
301 }
else if (iter->find(
"PYUPDApostPYINIT", 0) != std::string::npos) {
302 usePostPyinit =
true;
306 if (!shortfile.empty()) {
316 if (afterPyinit == usePostPyinit || (write_file && afterPyinit)) {
325 std::set<std::string>
blocks;
326 unsigned int model = 0, subModel = 0;
328 std::string fnamest = boost::filesystem::unique_path().string();
329 const char*
fname = fnamest.c_str();
332 for (std::vector<std::string>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter) {
338 if (pos != std::string::npos)
344 if (!boost::algorithm::is_space()(line[0])) {
345 std::vector<std::string> tokens;
346 boost::split(tokens, line, boost::algorithm::is_space(), boost::token_compress_on);
350 if (tokens.size() < 2)
352 if (tokens[0] ==
"BLOCK") {
354 blocks.insert(block);
358 if (tokens[0] ==
"DECAY") {
360 blocks.insert(block);
362 }
else if (block ==
"MODSEL") {
363 std::istringstream
ss(line);
364 ss >> model >> subModel;
365 }
else if (block ==
"SMINPUTS") {
366 std::istringstream
ss(line);
369 ss >> index >>
value;
378 pydat2_.pmas[0][23 - 1] =
value;
381 pydat2_.pmas[0][6 - 1] =
value;
384 pydat2_.pmas[0][15 - 1] =
value;
391 if (blocks.count(
"SMINPUTS"))
394 (pydat2_.pmas[0][23 - 1] * pydat2_.pmas[0][23 - 1]));
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"))
412 if (model || blocks.count(
"QNUMBERS") || blocks.count(
"PARTICLE") || blocks.count(
"MINPAR") ||
413 blocks.count(
"EXTPAR") || blocks.count(
"SMINPUTS") || blocks.count(
"SMINPUTS"))
415 if (blocks.count(
"MASS"))
417 if (blocks.count(
"DECAY"))
std::vector< std::string_view > split(std::string_view, const char *)
T getParameter(std::string const &) const
static void call_pyupda(int opt, int iunit)
__attribute__((visibility("hidden"))) void dummy()
void pyupda_(int *, int *)
void fioopn_(int *unit, const char *line, int length)
bool call_pygive(const std::string &line)
void pyjoin_(int &njoin, int ijoin[])
void pygive_(const char *, int)
void fioopnw_(int *unit, const char *line, int length)
void pyslha_(int *, int *, int *)
void setSLHAFromHeader(const std::vector< std::string > &lines)
~Pythia6Service() override
std::vector< std::string > fParamPYUPDA
static int call_pyslha(int mupda, int kforig=0)
void setPYUPDAParams(bool afterPyinit)
std::vector< std::string > fParamGeneral
static Pythia6Service * fPythia6Owner
CLHEP::HepRandomEngine * fRandomEngine
std::vector< std::string > fParamCSA
void openSLHA(const char *)
def remove(d, key, TELL=False)
void py1ent_(int &ip, int &kf, double &pe, double &the, double &phi)
void openPYUPDA(const char *, bool write_file)
std::string fullPath() const
std::vector< std::string > fParamSLHA
void txgive_(const char *, int)
Basic3DVector unit() const