8 #ifndef Pythia8_LHAHelaconia_H
9 #define Pythia8_LHAHelaconia_H
11 #include "Pythia8/Pythia.h"
41 string exeIn =
"ho_cluster");
47 bool readString(
string line);
50 void setEvents(
int eventsIn);
53 bool setSeed(
int seedIn,
int runsIn = 30081);
59 bool setEvent(
int = 0);
64 bool execute(
string line);
67 bool run(
int eventsIn,
int seedIn = -1);
70 bool reader(
bool init);
73 int convert(
int idIn);
80 int events, seed, runs, nRuns, nId, nQ, nR, nL, nJ;
81 string dir, exe, lhegz;
82 double sigWgt, wgt, mQ;
93 LHAupHelaconia::LHAupHelaconia(
Pythia *pythiaIn,
string dirIn,
string exeIn) :
94 pythia(pythiaIn), lhef(0), events(10000), seed(-1), runs(30081),
95 nRuns(0), nId(443), nQ(4), nR(0), nL(0), nJ(3),
96 dir(dirIn), exe(exeIn), lhegz(dirIn +
"/events.lhe"), mQ(-2) {
97 mkdir(dir.c_str(), 0777);
98 if (pythia) pythia->readString(
"Beams:frameType = 5");
99 pythia->settings.addMode(
"Onia:state", -1,
false,
false, 0, 0);
106 LHAupHelaconia::~LHAupHelaconia() {
if (lhef)
delete lhef;}
119 bool LHAupHelaconia::readString(
string line) {
121 size_t n = line.find(
"state");
122 if (line.find(
"8)") != string::npos) mQ = -1;
123 if (n != string::npos && pythia) {
124 pythia->settings.readString(
"Onia:" + line.substr(n));
125 nId = abs(pythia->settings.mode(
"Onia:state"));
126 nQ = int(nId/1e2) % 10;
127 nR = int(nId/1e5) % 10;
128 nL = int(nId/1e4) % 10;
129 nJ = int(nId/1e0) % 10;
130 }
else lines.push_back(line);
155 bool LHAupHelaconia::setSeed(
int seedIn,
int runsIn) {
157 if (!pythia)
return false;
160 seed = pythia->settings.mode(
"Random:seed");
162 pythia->info.errorMsg(
"Error from LHAupHelaconia::setSeed: the given "
163 "Pythia seed is less than 1.");
return false;}
166 if (seed * runs > 30081 * 30081) {
167 pythia->info.errorMsg(
"Error from LHAupHelaconia::setSeed: the given seed "
168 "exceeds the HelacOnia limit.");
return false;}
178 void LHAupHelaconia::setEvents(
int eventsIn) {events = eventsIn;}
184 bool LHAupHelaconia::execute(
string line) {
return system(line.c_str()) != -1;}
190 bool LHAupHelaconia::run(
int eventsIn,
int seedIn) {
193 if (!pythia)
return false;
195 pythia->info.errorMsg(
"Error from LHAupHelaconia::run: maximum number "
196 "of allowed runs exceeded.");
return false;}
197 if (seed < 0 && !setSeed(seed, runs))
return false;
198 if (seedIn < 0) seedIn = (seed - 1) * runs + nRuns + 1;
202 mQ = (pythia->particleData.m0(nId)
203 + pythia->settings.parm(
"Onia:massSplit"))/2.0;
206 if (!pythia)
return false;
207 fstream config((dir +
"/generate.py").c_str(), ios::out);
208 for (
int iLine = 0; iLine < (int)lines.size(); ++iLine)
209 config << lines[iLine] <<
"\n";
210 config <<
"set seed = " << seedIn <<
"\n"
212 <<
"set unwevt = " << eventsIn <<
"\n"
213 <<
"set preunw = " << 3.0/2.0*eventsIn <<
"\n";
214 if (mQ > 0) config <<
"set " << (nQ == 4 ?
"c" :
"b") <<
"mass = " << mQ
216 config <<
"launch\n";
220 fstream shuffle((dir +
"/shuffle.py").c_str(), ios::out);
222 "import random, os\n"
223 "random.seed(" << seedIn <<
"); tag, pre, post, events = '', [], [], []\n"
224 "for line in open('events.lhe').readlines():\n"
225 " if line.strip().startswith('<'):\n"
226 " tag = line.strip()\n"
227 " if tag == '<event>': events += ['<event>\\n']; continue\n"
228 " if tag == '</event>': events[-1] += '</event>\\n'; continue\n"
229 " if tag == '<event>': events[-1] += line\n"
230 " elif len(events) == 0: pre += [line]\n"
231 " else: post += [line]\n"
232 "random.shuffle(events); os.unlink('events.lhe')\n"
233 "open('events.lhe', 'w').writelines(pre + events + post)\n";
237 if (!execute(
"rm -rf " + dir +
"/PROC* " + lhegz))
return false;
238 if (!execute(
"cd " + dir +
"; cat generate.py | " + exe))
return false;
239 if (!execute(
"cd " + dir +
"; ln -s PROC_HO_0/P0_calc_0/output/*.lhe "
240 "events.lhe;# python shuffle.py"))
return false;
241 if (access(lhegz.c_str(), F_OK) == -1)
return false;
251 bool LHAupHelaconia::reader(
bool init) {
254 if (!pythia)
return false;
255 if (lhef)
delete lhef;
256 bool setScales(pythia->settings.flag(
"Beams:setProductionScalesFromLHEF"));
257 lhef =
new LHAupLHEF(&pythia->info, lhegz.c_str(), NULL,
false, setScales);
258 if (!lhef->setInit()) {
259 pythia->info.errorMsg(
"Error from LHAupHelaconia::reader: failed to "
260 "initialize the LHEF reader");
return false;}
261 if (lhef->sizeProc() != 1) {
262 pythia->info.errorMsg(
"Error from LHAupHelaconia::reader: number of "
263 "processes is not 1");
return false;}
268 double sig(lhef->xSec(0)), err(lhef->xErr(0));
271 setBeamA(lhef->idBeamA(), lhef->eBeamA(), lhef->pdfGroupBeamA(),
272 lhef->pdfSetBeamA());
273 setBeamB(lhef->idBeamB(), lhef->eBeamB(), lhef->pdfGroupBeamB(),
274 lhef->pdfSetBeamB());
275 setStrategy(lhef->strategy());
276 addProcess(lhef->idProcess(0), sig, err, lhef->xMax(0));
277 xSecSumSave = sig; xErrSumSave = err;
287 int LHAupHelaconia::convert(
int idIn) {
289 if (abs(idIn) < 9900000)
return idIn;
290 else idIn = abs(idIn) - 9900000;
292 if (idIn == nQ*110 + 3) nS = 0;
293 else if (idIn == nQ*110 + 1) nS = 1;
294 return 9900000 + 10000*nQ + 1000*nS + 100*nR + 10*nL + nJ;
302 bool LHAupHelaconia::setInit() {
305 if (!pythia)
return false;
306 if (!run(events))
return false;
307 if (!reader(
true))
return false;
317 bool LHAupHelaconia::setEvent(
int) {
320 if (!pythia)
return false;
322 pythia->info.errorMsg(
"Error from LHAupHelaconia::setEvent: LHAupLHEF "
323 "object not correctly initialized");
return false;}
324 if (!lhef->fileFound()) {
325 pythia->info.errorMsg(
"Error from LHAupHelaconia::setEvent: LHEF "
326 "event file was not found");
return false;}
327 if (!lhef->setEvent()) {
328 if (!run(events))
return false;
329 if (!reader(
false))
return false;
334 particlesSave.clear();
336 for (
int ip = 1; ip < lhef->sizePart(); ++ip) {
337 mom1 = lhef->mother1(ip);
338 mom2 = lhef->mother2(ip);
339 particlesSave.push_back
340 (LHAParticle(convert(lhef->id(ip)),
341 lhef->status(ip), mom1, mom2, lhef->col1(ip),
342 lhef->col2(ip), lhef->px(ip), lhef->py(ip), lhef->pz(ip),
343 lhef->e(ip), lhef->m(ip), lhef->tau(ip), lhef->spin(ip),
345 if (mom1 > 0 && mom1 < (
int)particlesSave.size() && mom2 == 0)
346 particlesSave[mom1 - 1].statusPart = 2;
350 setProcess(lhef->idProcess(), lhef->weight(), lhef->scale(),
351 lhef->alphaQED(), lhef->alphaQCD());
352 for (
int ip = 0; ip < (int)particlesSave.size(); ++ip)
353 addParticle(particlesSave[ip]);
354 setIdX(lhef->id1(), lhef->id2(), lhef->x1(), lhef->x2());
355 setPdf(lhef->id1pdf(), lhef->id2pdf(), lhef->x1pdf(), lhef->x2pdf(),
356 lhef->scalePDF(), lhef->pdf1(), lhef->pdf2(), lhef->pdfIsSet());
365 #endif // Pythia8_LHAHelaconia_H