File indexing completed on 2025-01-18 10:06:39
0001
0002
0003
0004
0005
0006
0007 #ifndef Pythia8_LHAPowheg_H
0008 #define Pythia8_LHAPowheg_H
0009
0010 #include "Pythia8/Plugins.h"
0011 #include "Pythia8Plugins/LHAFortran.h"
0012 #include <sys/stat.h>
0013 #include <unistd.h>
0014
0015 namespace Pythia8 {
0016
0017
0018
0019
0020
0021 extern "C" {
0022
0023
0024 extern struct {
0025 int rnd_numseeds, rnd_initialseed, rnd_iwhichseed;
0026 char rnd_cwhichseed[4];
0027 int rnd_i1, rnd_i2;
0028 } pwhg_rnd_;
0029
0030
0031 extern struct {
0032 double u[97];
0033 double c;
0034 int i97, j97;
0035 } r48st1_;
0036
0037
0038 void pwhginit_();
0039
0040
0041 void resetcnt_(const char *string, int length);
0042
0043
0044 void pwhgevent_();
0045
0046
0047 double powheginput_(const char *string, int length);
0048
0049 }
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 class LHAupPowheg : public LHAupFortran {
0064
0065 public:
0066
0067
0068 LHAupPowheg(Pythia* pythiaPtr, Settings* settingsPtr, Logger* loggerPtr);
0069
0070
0071 bool fillHepRup();
0072
0073
0074 bool fillHepEup();
0075
0076 private:
0077
0078
0079 bool readString(string line);
0080
0081
0082 bool readFile(string name);
0083
0084
0085 bool init();
0086
0087
0088 Rndm* rndmPtr{};
0089
0090
0091 Logger* loggerPtr{};
0092
0093
0094 string dir, pdf;
0095
0096
0097 map<string, string> settings;
0098
0099
0100 char cwd[FILENAME_MAX];
0101
0102 };
0103
0104
0105
0106
0107
0108 LHAupPowheg::LHAupPowheg(Pythia *pythiaPtr, Settings *settingsPtr,
0109 Logger* loggerPtrIn) : loggerPtr(loggerPtrIn), dir("powhegrun"), pdf("") {
0110
0111
0112 if (settingsPtr != nullptr) {
0113 dir = settingsPtr->word("POWHEG:dir");
0114 pdf = settingsPtr->word("POWHEG:pdf");
0115
0116
0117 for (string cmndFile : settingsPtr->wvec("POWHEG:cmndFiles"))
0118 readFile(cmndFile);
0119 for (string cmnd : settingsPtr->wvec("POWHEG:cmnds"))
0120 readString(cmnd);
0121 }
0122
0123
0124 if (pythiaPtr != nullptr) {
0125 if (settingsPtr->isFlag("POWHEG:pythiaRandom")) rndmPtr = &pythiaPtr->rndm;
0126 }
0127 mkdir(dir.c_str(), 0777);
0128 init();
0129
0130 }
0131
0132
0133
0134
0135
0136 bool LHAupPowheg::fillHepRup() {
0137
0138
0139 getcwd(cwd, sizeof(cwd));
0140 chdir(dir.c_str());
0141 strcpy(pwhg_rnd_.rnd_cwhichseed, "none");
0142
0143
0144 pwhginit_();
0145
0146
0147 resetcnt_("upper bound failure in inclusive cross section", 46);
0148 resetcnt_("vetoed calls in inclusive cross section", 39);
0149 resetcnt_("upper bound failures in generation of radiation", 47);
0150 resetcnt_("vetoed radiation", 16);
0151 chdir(cwd);
0152 return fillHepEup();
0153
0154 }
0155
0156
0157
0158
0159
0160 bool LHAupPowheg::fillHepEup() {
0161
0162
0163 getcwd(cwd, sizeof(cwd));
0164 chdir(dir.c_str());
0165
0166
0167 if (rndmPtr != nullptr) {
0168 r48st1_.i97 = 97;
0169 r48st1_.j97 = 33;
0170 r48st1_.c = rndmPtr->flat();
0171 for (int i = 0; i < 97; ++i) r48st1_.u[i] = rndmPtr->flat();
0172 }
0173
0174
0175 pwhgevent_();
0176 chdir(cwd);
0177 return true;
0178
0179 }
0180
0181
0182
0183
0184
0185
0186 bool LHAupPowheg::readString(string line) {
0187
0188
0189 if (line.find_first_not_of(" \n\t\v\b\r\f\a") == string::npos) return true;
0190 int firstChar = line.find_first_not_of(" \n\t\v\b\r\f\a");
0191 int lastChar = line.find_last_not_of(" \n\t\v\b\r\f\a");
0192 line = line.substr(firstChar, lastChar + 1 - firstChar);
0193
0194
0195 firstChar = line.find_first_of(" \t\f\v\n\r");
0196 string key = toLower( line.substr(0, firstChar), false);
0197
0198
0199 if (key.size() > 0
0200 && key.find_first_of("abcdedfghijklmnopqrtsuvwxyz") == 0) {
0201 map<string, string>::iterator setting = settings.find(key);
0202 if (setting != settings.end()) {
0203 if (loggerPtr) loggerPtr->WARNING_MSG(
0204 "replacing previous POWHEG setting for " + key);
0205 setting->second = line;
0206 } else settings[key] = line;
0207 }
0208 return true;
0209
0210 }
0211
0212
0213
0214
0215
0216 bool LHAupPowheg::readFile(string name) {
0217
0218 fstream config(name.c_str(), ios::in); string line;
0219 while (getline(config, line, '\n')) readString(line);
0220 config.close();
0221 return true;
0222
0223 }
0224
0225
0226
0227
0228
0229 bool LHAupPowheg::init() {
0230
0231
0232 if (pdf != "") {
0233 fstream pdfin(pdf.c_str(), ios::in | ios::binary);
0234 fstream pdfout((dir + "/" + pdf.substr(0, pdf.find_last_of("/"))).c_str(),
0235 ios::out | ios::binary);
0236 pdfout << pdfin.rdbuf();
0237 pdfin.close();
0238 pdfout.close();
0239 }
0240
0241
0242 fstream config((dir + "/" + "powheg.input").c_str(), ios::out);
0243 for (map<string, string>::iterator setting = settings.begin();
0244 setting != settings.end(); ++setting) config << setting->second << "\n";
0245 config.close();
0246 return true;
0247
0248 }
0249
0250
0251
0252
0253
0254 void powhegSettings(Settings *settingsPtr) {
0255 settingsPtr->addWord("POWHEG:dir", "powhegrun");
0256 settingsPtr->addWord("POWHEG:pdf", "");
0257 settingsPtr->addWVec("POWHEG:cmnds", {});
0258 settingsPtr->addWVec("POWHEG:cmndFiles", {});
0259 settingsPtr->addFlag("POWHEG:pythiaRandom", true);
0260 }
0261
0262
0263
0264
0265
0266 PYTHIA8_PLUGIN_CLASS(LHAup, LHAupPowheg, true, true, true)
0267 PYTHIA8_PLUGIN_SETTINGS(powhegSettings)
0268 PYTHIA8_PLUGIN_VERSIONS(PYTHIA_VERSION_INTEGER)
0269
0270
0271
0272 }
0273
0274 #endif