13 #ifndef Pythia8_LesHouches_H
14 #define Pythia8_LesHouches_H
16 #include "Pythia8/Event.h"
17 #include "Pythia8/Info.h"
18 #include "Pythia8/PythiaStdlib.h"
19 #include "Pythia8/Settings.h"
20 #include "Pythia8/Streams.h"
33 LHAProcess() : idProc(0), xSecProc(0.), xErrProc(0.), xMaxProc(0.) { }
34 LHAProcess(
int idProcIn,
double xSecIn,
double xErrIn,
double xMaxIn) :
35 idProc(idProcIn), xSecProc(xSecIn), xErrProc(xErrIn),
40 double xSecProc, xErrProc, xMaxProc;
53 LHAParticle() : idPart(0), statusPart(0), mother1Part(0),
54 mother2Part(0), col1Part(0), col2Part(0), pxPart(0.), pyPart(0.),
55 pzPart(0.), ePart(0.), mPart(0.), tauPart(0.), spinPart(9.),
57 LHAParticle(
int idIn,
int statusIn,
int mother1In,
int mother2In,
58 int col1In,
int col2In,
double pxIn,
double pyIn,
double pzIn,
59 double eIn,
double mIn,
double tauIn,
double spinIn,
61 idPart(idIn), statusPart(statusIn), mother1Part(mother1In),
62 mother2Part(mother2In), col1Part(col1In), col2Part(col2In),
63 pxPart(pxIn), pyPart(pyIn), pzPart(pzIn), ePart(eIn), mPart(mIn),
64 tauPart(tauIn), spinPart(spinIn), scalePart(scaleIn) { }
67 int idPart, statusPart, mother1Part, mother2Part, col1Part, col2Part;
68 double pxPart, pyPart, pzPart, ePart, mPart, tauPart, spinPart,
86 void setPtr(Info* infoPtrIn) {infoPtr = infoPtrIn;}
89 virtual void newEventFile(
const char*) {}
90 virtual bool fileFound() {
return true;}
91 virtual bool useExternal() {
return false;}
96 virtual bool setInit() = 0;
99 int idBeamA()
const {
return idBeamASave;}
100 int idBeamB()
const {
return idBeamBSave;}
101 double eBeamA()
const {
return eBeamASave;}
102 double eBeamB()
const {
return eBeamBSave;}
103 int pdfGroupBeamA()
const {
return pdfGroupBeamASave;}
104 int pdfGroupBeamB()
const {
return pdfGroupBeamBSave;}
105 int pdfSetBeamA()
const {
return pdfSetBeamASave;}
106 int pdfSetBeamB()
const {
return pdfSetBeamBSave;}
109 int strategy()
const {
return strategySave;}
112 int sizeProc()
const {
return processes.size();}
113 int idProcess(
int proc)
const {
return processes[proc].idProc;}
114 double xSec(
int proc)
const {
return processes[proc].xSecProc;}
115 double xErr(
int proc)
const {
return processes[proc].xErrProc;}
116 double xMax(
int proc)
const {
return processes[proc].xMaxProc;}
117 double xSecSum()
const {
return xSecSumSave;}
118 double xErrSum()
const {
return xErrSumSave;}
130 virtual bool setEvent(
int idProcIn = 0) = 0;
133 int idProcess()
const {
return idProc;}
134 double weight()
const {
return weightProc;}
135 double scale()
const {
return scaleProc;}
136 double alphaQED()
const {
return alphaQEDProc;}
137 double alphaQCD()
const {
return alphaQCDProc;}
140 int sizePart()
const {
return particles.size();}
141 int id(
int part)
const {
return particles[part].idPart;}
142 int status(
int part)
const {
return particles[part].statusPart;}
143 int mother1(
int part)
const {
return particles[part].mother1Part;}
144 int mother2(
int part)
const {
return particles[part].mother2Part;}
145 int col1(
int part)
const {
return particles[part].col1Part;}
146 int col2(
int part)
const {
return particles[part].col2Part;}
147 double px(
int part)
const {
return particles[part].pxPart;}
148 double py(
int part)
const {
return particles[part].pyPart;}
149 double pz(
int part)
const {
return particles[part].pzPart;}
150 double e(
int part)
const {
return particles[part].ePart;}
151 double m(
int part)
const {
return particles[part].mPart;}
152 double tau(
int part)
const {
return particles[part].tauPart;}
153 double spin(
int part)
const {
return particles[part].spinPart;}
154 double scale(
int part)
const {
return particles[part].scalePart;}
157 int id1()
const {
return id1Save;}
158 int id2()
const {
return id2Save;}
159 double x1()
const {
return x1Save;}
160 double x2()
const {
return x2Save;}
163 bool pdfIsSet()
const {
return pdfIsSetSave;}
164 int id1pdf()
const {
return id1pdfSave;}
165 int id2pdf()
const {
return id2pdfSave;}
166 double x1pdf()
const {
return x1pdfSave;}
167 double x2pdf()
const {
return x2pdfSave;}
168 double scalePDF()
const {
return scalePDFSave;}
169 double pdf1()
const {
return pdf1Save;}
170 double pdf2()
const {
return pdf2Save;}
173 bool scaleShowersIsSet()
const {
return scaleShowersIsSetSave;}
174 double scaleShowers(
int i)
const {
return scaleShowersSave[i];}
181 virtual bool skipEvent(
int nSkip) {
182 for (
int iSkip = 0; iSkip < nSkip; ++iSkip)
if (!setEvent())
return false;
186 virtual bool openLHEF(
string fileNameIn);
187 virtual bool closeLHEF(
bool updateInit =
false);
189 bool eventLHEF(
bool verbose =
true);
192 string getFileName()
const {
return fileName;}
197 LHAup(
int strategyIn = 3) : infoPtr(), nupSave(), idprupSave(),
198 xwgtupSave(), scalupSave(), aqedupSave(), aqcdupSave(), xSecSumSave(),
199 xErrSumSave(), getPDFSave(), getScale(), getScaleShowers(),
200 id1InSave(), id2InSave(), id1pdfInSave(), id2pdfInSave(), x1InSave(),
201 x2InSave(), x1pdfInSave(), x2pdfInSave(), scalePDFInSave(),
202 pdf1InSave(), pdf2InSave(), scaleShowersInSave(), fileName(
"void"),
203 dateNow(), timeNow(), strategySave(strategyIn), idBeamASave(),
204 idBeamBSave(), eBeamASave(), eBeamBSave(), pdfGroupBeamASave(),
205 pdfGroupBeamBSave(), pdfSetBeamASave(), pdfSetBeamBSave(), idProc(),
206 weightProc(), scaleProc(), alphaQEDProc(), alphaQCDProc(),
207 pdfIsSetSave(), scaleShowersIsSetSave(false), id1Save(),
208 id2Save(), id1pdfSave(), id2pdfSave(), x1Save(), x2Save(), x1pdfSave(),
209 x2pdfSave(), scalePDFSave(), pdf1Save(), pdf2Save(), scaleShowersSave() {
210 processes.reserve(10); particles.reserve(20);
211 setBeamA( 0, 0., 0, 0); setBeamB( 0, 0., 0, 0); }
214 static const double CONVERTMB2PB;
220 void setBeamA(
int idIn,
double eIn,
int pdfGroupIn = 0,
int pdfSetIn = 0)
221 { idBeamASave = idIn; eBeamASave = eIn; pdfGroupBeamASave = pdfGroupIn;
222 pdfSetBeamASave = pdfSetIn;}
223 void setBeamB(
int idIn,
double eIn,
int pdfGroupIn = 0,
int pdfSetIn = 0)
224 { idBeamBSave = idIn; eBeamBSave = eIn; pdfGroupBeamBSave = pdfGroupIn;
225 pdfSetBeamBSave = pdfSetIn;}
228 void setStrategy(
int strategyIn) {strategySave = strategyIn;}
231 void addProcess(
int idProcIn,
double xSecIn = 1.,
double xErrIn = 0.,
232 double xMaxIn = 1.) { processes.push_back( LHAProcess( idProcIn,
233 xSecIn, xErrIn, xMaxIn)); }
236 void setXSec(
int iP,
double xSecIn) {processes[iP].xSecProc = xSecIn;}
237 void setXErr(
int iP,
double xErrIn) {processes[iP].xErrProc = xErrIn;}
238 void setXMax(
int iP,
double xMaxIn) {processes[iP].xMaxProc = xMaxIn;}
241 void setProcess(
int idProcIn = 0,
double weightIn = 1.,
double
242 scaleIn = 0.,
double alphaQEDIn = 0.0073,
double alphaQCDIn = 0.12) {
243 idProc = idProcIn; weightProc = weightIn; scaleProc = scaleIn;
244 alphaQEDProc = alphaQEDIn; alphaQCDProc = alphaQCDIn;
246 particles.clear(); addParticle(0); pdfIsSetSave =
false;
247 scaleShowersIsSetSave =
false;}
250 void addParticle(LHAParticle particleIn) {
251 particles.push_back(particleIn);}
252 void addParticle(
int idIn,
int statusIn = 0,
int mother1In = 0,
253 int mother2In = 0,
int col1In = 0,
int col2In = 0,
double pxIn = 0.,
254 double pyIn = 0.,
double pzIn = 0.,
double eIn = 0.,
double mIn = 0.,
255 double tauIn = 0.,
double spinIn = 9.,
double scaleIn = -1.) {
256 particles.push_back( LHAParticle( idIn, statusIn, mother1In, mother2In,
257 col1In, col2In, pxIn, pyIn, pzIn, eIn, mIn, tauIn, spinIn,
261 void setIdX(
int id1In,
int id2In,
double x1In,
double x2In)
262 { id1Save = id1In; id2Save = id2In; x1Save = x1In; x2Save = x2In;}
265 void setPdf(
int id1pdfIn,
int id2pdfIn,
double x1pdfIn,
double x2pdfIn,
266 double scalePDFIn,
double pdf1In,
double pdf2In,
bool pdfIsSetIn)
267 { id1pdfSave = id1pdfIn; id2pdfSave = id2pdfIn; x1pdfSave = x1pdfIn;
268 x2pdfSave = x2pdfIn; scalePDFSave = scalePDFIn; pdf1Save = pdf1In;
269 pdf2Save = pdf2In; pdfIsSetSave = pdfIsSetIn;}
272 void setScaleShowers(
double scaleIn1,
double scaleIn2 = 0.)
273 { scaleShowersSave[0] = scaleIn1; scaleShowersSave[1] = scaleIn2;
274 scaleShowersIsSetSave =
true;}
277 bool setInitLHEF(istream& is,
bool readHeaders =
false);
278 bool setNewEventLHEF(istream& is);
279 bool setOldEventLHEF();
286 istream* openFile(
const char *fn, ifstream &ifs);
287 void closeFile(istream *&is, ifstream &ifs);
292 void setInfoHeader(
const string &key,
const string &val) {
293 infoPtr->setHeader(key, val); }
296 int nupSave, idprupSave;
297 double xwgtupSave, scalupSave, aqedupSave, aqcdupSave, xSecSumSave,
299 vector<LHAParticle> particlesSave;
300 bool getPDFSave, getScale, getScaleShowers;
301 int id1InSave, id2InSave, id1pdfInSave, id2pdfInSave;
302 double x1InSave, x2InSave, x1pdfInSave, x2pdfInSave, scalePDFInSave,
303 pdf1InSave, pdf2InSave, scaleShowersInSave[2];
317 int idBeamASave, idBeamBSave;
318 double eBeamASave, eBeamBSave;
319 int pdfGroupBeamASave, pdfGroupBeamBSave, pdfSetBeamASave,
323 vector<LHAProcess> processes;
327 double weightProc, scaleProc, alphaQEDProc, alphaQCDProc;
330 vector<LHAParticle> particles;
333 bool pdfIsSetSave, scaleShowersIsSetSave;
334 int id1Save, id2Save, id1pdfSave, id2pdfSave;
335 double x1Save, x2Save, x1pdfSave, x2pdfSave, scalePDFSave, pdf1Save,
336 pdf2Save, scaleShowersSave[2];
344 class LHAupLHEF :
public LHAup {
349 LHAupLHEF(
Pythia8::Info* infoPtrIn, istream* isIn, istream* isHeadIn,
350 bool readHeadersIn =
false,
bool setScalesFromLHEFIn =
false ) :
351 filename(
""), headerfile(
""),
352 is(isIn), is_gz(NULL), isHead(isHeadIn), isHead_gz(NULL),
353 readHeaders(readHeadersIn), reader(is),
354 setScalesFromLHEF(setScalesFromLHEFIn), hasExtFileStream(true),
355 hasExtHeaderStream(true) {setPtr(infoPtrIn);}
358 const char* headerIn = NULL,
bool readHeadersIn =
false,
359 bool setScalesFromLHEFIn =
false ) :
360 filename(filenameIn), headerfile(headerIn),
361 is(NULL), is_gz(NULL), isHead(NULL), isHead_gz(NULL),
362 readHeaders(readHeadersIn), reader(filenameIn),
363 setScalesFromLHEF(setScalesFromLHEFIn), hasExtFileStream(false),
364 hasExtHeaderStream(false) {
366 is = (openFile(filenameIn, ifs));
367 isHead = (headerfile == NULL) ? is : openFile(headerfile, ifsHead);
368 is_gz =
new igzstream(filename);
369 isHead_gz = (headerfile == NULL) ? is_gz :
new igzstream(headerfile);
379 void closeAllFiles() {
381 if (!hasExtHeaderStream && isHead_gz != is_gz) isHead_gz->close();
382 if (isHead_gz != is_gz)
delete isHead_gz;
383 if (is_gz) is_gz->close();
384 if (is_gz)
delete is_gz;
387 if (!hasExtHeaderStream && isHead != is) closeFile(isHead, ifsHead);
388 if (!hasExtFileStream) closeFile(is, ifs);
392 void newEventFile(
const char* filenameIn) {
395 is = (openFile(filenameIn, ifs));
396 is_gz =
new igzstream(filenameIn);
398 reader.setup(filenameIn);
406 bool fileFound() {
return (useExternal() || (isHead->good() && is->good()));}
407 bool useExternal() {
return (hasExtHeaderStream && hasExtFileStream);}
411 return setInitLHEF(*isHead, readHeaders);
415 bool setInitLHEF( istream & isIn,
bool readHead);
418 bool setEvent(
int = 0) {
419 if (!setNewEventLHEF())
return false;
420 return setOldEventLHEF();
424 bool skipEvent(
int nSkip) {
425 for (
int iSkip = 0; iSkip < nSkip; ++iSkip)
426 if (!setNewEventLHEF())
return false;
431 bool setNewEventLHEF();
434 bool updateSigma() {
return true;}
439 bool getLine(
string & line,
bool header =
true) {
441 if ( isHead_gz && header && !getline(*isHead_gz, line))
return false;
442 else if ( is_gz && !header && !getline(*is_gz, line))
return false;
443 if (header && !getline(*isHead, line))
return false;
444 else if (!header && !getline(*is, line))
return false;
446 if (header && !getline(*isHead, line))
return false;
447 else if (!header && !getline(*is, line))
return false;
450 replace(line.begin(),line.end(),
'\'',
'\"');
456 const char* filename;
457 const char* headerfile;
465 igzstream *isHead_gz;
474 bool setScalesFromLHEF, hasExtFileStream, hasExtHeaderStream;
491 bool setInit()
override {
492 return lhaPtr !=
nullptr ? lhaPtr->setInit() :
false;}
494 bool setEvent(
int idProcIn = 0)
override {
495 return lhaPtr !=
nullptr ? lhaPtr->setEvent(idProcIn) :
false;}
501 typedef void DeleteLHAup(
LHAup*);
520 processPtr = processPtrIn; infoPtr = infoPtrIn;}
523 ~LHAupFromPYTHIA8() {}
529 bool setEvent(
int = 0);
547 class LHEF3FromPythia8 :
public LHAup {
552 LHEF3FromPythia8(
Event* eventPtrIn,
const Info* infoPtrIn,
553 int pDigitsIn = 15,
bool writeToFileIn =
true) :
554 eventPtr(eventPtrIn),infoPtr(infoPtrIn),
555 settingsPtr(infoPtrIn->settingsPtr),
556 particleDataPtr(infoPtrIn->particleDataPtr), writer(osLHEF),
557 pDigits(pDigitsIn), writeToFile(writeToFileIn) {}
563 void setEventPtr(
Event* evPtr) { eventPtr = evPtr; }
564 bool setEvent(
int = 0);
565 string getEventString() {
return writer.getEventString(&hepeup); }
568 bool openLHEF(
string fileNameIn);
571 bool closeLHEF(
bool updateInit =
false);
580 Settings* settingsPtr;
581 ParticleData* particleDataPtr;
600 #endif // Pythia8_LesHouches_H