13 #ifndef Pythia8_Basics_H
14 #define Pythia8_Basics_H
16 #include "Pythia8/PythiaStdlib.h"
30 virtual ~RndmEngine() {}
34 virtual double flat() = 0;
49 Rndm() : initRndm(false), seedSave(0), sequence(0),
50 useExternalRndm(false), rndmEngPtr(0) { }
51 Rndm(
int seedIn) : initRndm(false), seedSave(0), sequence(0),
52 useExternalRndm(false), rndmEngPtr(0) { init(seedIn);}
55 bool rndmEnginePtr( RndmEngine* rndmEngPtrIn);
58 void init(
int seedIn = 0) ;
64 double exp() {
return -log(flat()) ;}
67 double xexp() {
return -log(flat() * flat()) ;}
70 double gauss() {
return sqrt(-2. * log(flat())) * cos(M_PI * flat());}
73 pair<double, double> gauss2() {
double r = sqrt(-2. * log(flat()));
74 double phi = 2. * M_PI * flat();
75 return pair<double, double>(r * sin(phi), r * cos(phi));}
78 int pick(
const vector<double>& prob) ;
81 bool dumpState(
string fileName);
82 bool readState(
string fileName);
87 static const int DEFAULTSEED;
91 int i97, j97, seedSave;
93 double u[97], c, cd, cm;
97 RndmEngine* rndmEngPtr;
117 Vec4(
double xIn = 0.,
double yIn = 0.,
double zIn = 0.,
double tIn = 0.)
118 : xx(xIn), yy(yIn), zz(zIn), tt(tIn) { }
119 Vec4(
const Vec4& v) : xx(v.xx), yy(v.yy), zz(v.zz), tt(v.tt) { }
120 Vec4& operator=(
const Vec4& v) {
if (
this != &v) { xx = v.xx; yy = v.yy;
121 zz = v.zz; tt = v.tt; }
return *
this; }
122 Vec4& operator=(
double value) { xx = value; yy = value; zz = value;
123 tt = value;
return *
this; }
126 void reset() {xx = 0.; yy = 0.; zz = 0.; tt = 0.;}
127 void p(
double xIn,
double yIn,
double zIn,
double tIn)
128 {xx = xIn; yy = yIn; zz = zIn; tt = tIn;}
129 void p(Vec4 pIn) {xx = pIn.xx; yy = pIn.yy; zz = pIn.zz; tt = pIn.tt;}
130 void px(
double xIn) {xx = xIn;}
131 void py(
double yIn) {yy = yIn;}
132 void pz(
double zIn) {zz = zIn;}
133 void e(
double tIn) {tt = tIn;}
136 double px()
const {
return xx;}
137 double py()
const {
return yy;}
138 double pz()
const {
return zz;}
139 double e()
const {
return tt;}
140 double& operator[](
int i) {
141 if (i == 1)
return xx;
142 else if (i == 2)
return yy;
143 else if (i == 3)
return zz;
146 double mCalc()
const {
double temp = tt*tt - xx*xx - yy*yy - zz*zz;
147 return (temp >= 0.) ? sqrt(temp) : -sqrt(-temp);}
148 double m2Calc()
const {
return tt*tt - xx*xx - yy*yy - zz*zz;}
149 double pT()
const {
return sqrt(xx*xx + yy*yy);}
150 double pT2()
const {
return xx*xx + yy*yy;}
151 double pAbs()
const {
return sqrt(xx*xx + yy*yy + zz*zz);}
152 double pAbs2()
const {
return xx*xx + yy*yy + zz*zz;}
153 double eT()
const {
double temp = xx*xx + yy*yy;
154 return tt * sqrt( temp / (temp + zz*zz) );}
155 double eT2()
const {
double temp = xx*xx + yy*yy;
156 return tt*tt * temp / (temp + zz*zz);}
157 double theta()
const {
return atan2(sqrt(xx*xx + yy*yy), zz);}
158 double phi()
const {
return atan2(yy,xx);}
159 double thetaXZ()
const {
return atan2(xx,zz);}
160 double pPos()
const {
return tt + zz;}
161 double pNeg()
const {
return tt - zz;}
162 double rap()
const {
return 0.5 * log( (tt + zz) / (tt - zz) );}
163 double eta()
const {
double xyz = sqrt(xx*xx + yy*yy + zz*zz);
164 return 0.5 * log( (xyz + zz) / (xyz - zz) );}
167 void rescale3(
double fac) {xx *= fac; yy *= fac; zz *= fac;}
168 void rescale4(
double fac) {xx *= fac; yy *= fac; zz *= fac; tt *= fac;}
169 void flip3() {xx = -xx; yy = -yy; zz = -zz;}
170 void flip4() {xx = -xx; yy = -yy; zz = -zz; tt = -tt;}
171 void rot(
double thetaIn,
double phiIn);
172 void rotaxis(
double phiIn,
double nx,
double ny,
double nz);
173 void rotaxis(
double phiIn,
const Vec4& n);
174 void bst(
double betaX,
double betaY,
double betaZ);
175 void bst(
double betaX,
double betaY,
double betaZ,
double gamma);
176 void bst(
const Vec4& pIn);
177 void bst(
const Vec4& pIn,
double mIn);
178 void bstback(
const Vec4& pIn);
179 void bstback(
const Vec4& pIn,
double mIn);
180 void rotbst(
const RotBstMatrix& M);
183 inline Vec4 operator-()
const {Vec4 tmp; tmp.xx = -xx; tmp.yy = -yy;
184 tmp.zz = -zz; tmp.tt = -tt;
return tmp;}
185 inline Vec4& operator+=(
const Vec4& v) {xx += v.xx; yy += v.yy; zz += v.zz;
186 tt += v.tt;
return *
this;}
187 inline Vec4& operator-=(
const Vec4& v) {xx -= v.xx; yy -= v.yy; zz -= v.zz;
188 tt -= v.tt;
return *
this;}
189 inline Vec4& operator*=(
double f) {xx *= f; yy *= f; zz *= f;
190 tt *= f;
return *
this;}
191 inline Vec4& operator/=(
double f) {xx /= f; yy /= f; zz /= f;
192 tt /= f;
return *
this;}
193 inline Vec4 operator+(
const Vec4& v)
const {
194 Vec4 tmp = *
this;
return tmp += v;}
195 inline Vec4 operator-(
const Vec4& v)
const {
196 Vec4 tmp = *
this;
return tmp -= v;}
197 inline Vec4 operator*(
double f)
const {
198 Vec4 tmp = *
this;
return tmp *= f;}
199 inline Vec4 operator/(
double f)
const {
200 Vec4 tmp = *
this;
return tmp /= f;}
201 inline double operator*(
const Vec4& v)
const {
202 return tt*v.tt - xx*v.xx - yy*v.yy - zz*v.zz;}
205 friend Vec4 operator*(
double f,
const Vec4& v1);
208 friend ostream& operator<<(ostream&,
const Vec4& v) ;
211 friend double m(
const Vec4& v1,
const Vec4& v2);
212 friend double m2(
const Vec4& v1,
const Vec4& v2);
215 friend double dot3(
const Vec4& v1,
const Vec4& v2);
216 friend Vec4 cross3(
const Vec4& v1,
const Vec4& v2);
219 friend Vec4 cross4(
const Vec4& a,
const Vec4& b,
const Vec4& c);
222 friend double theta(
const Vec4& v1,
const Vec4& v2);
223 friend double costheta(
const Vec4& v1,
const Vec4& v2);
226 friend double phi(
const Vec4& v1,
const Vec4& v2);
227 friend double cosphi(
const Vec4& v1,
const Vec4& v2);
230 friend double phi(
const Vec4& v1,
const Vec4& v2,
const Vec4& n);
231 friend double cosphi(
const Vec4& v1,
const Vec4& v2,
const Vec4& n);
234 friend double RRapPhi(
const Vec4& v1,
const Vec4& v2);
235 friend double REtaPhi(
const Vec4& v1,
const Vec4& v2);
238 friend bool pShift( Vec4& p1Move, Vec4& p2Move,
double m1New,
double m2New);
241 friend pair<Vec4,Vec4> getTwoPerpendicular(
const Vec4& v1,
const Vec4& v2);
246 static const double TINY;
249 double xx, yy, zz, tt;
258 inline Vec4 operator*(
double f,
const Vec4& v1)
259 {Vec4 v = v1;
return v *= f;}
262 double m(
const Vec4& v1,
const Vec4& v2);
263 double m2(
const Vec4& v1,
const Vec4& v2);
266 double dot3(
const Vec4& v1,
const Vec4& v2);
267 Vec4 cross3(
const Vec4& v1,
const Vec4& v2);
270 Vec4 cross4(
const Vec4& a,
const Vec4& b,
const Vec4& c);
273 double theta(
const Vec4& v1,
const Vec4& v2);
274 double costheta(
const Vec4& v1,
const Vec4& v2);
277 double phi(
const Vec4& v1,
const Vec4& v2);
278 double cosphi(
const Vec4& v1,
const Vec4& v2);
281 double phi(
const Vec4& v1,
const Vec4& v2,
const Vec4& n);
282 double cosphi(
const Vec4& v1,
const Vec4& v2,
const Vec4& n);
285 double RRapPhi(
const Vec4& v1,
const Vec4& v2);
286 double REtaPhi(
const Vec4& v1,
const Vec4& v2);
289 ostream& operator<<(ostream&,
const Vec4& v) ;
292 bool pShift( Vec4& p1Move, Vec4& p2Move,
double m1New,
double m2New);
295 pair<Vec4,Vec4> getTwoPerpendicular(
const Vec4& v1,
const Vec4& v2);
308 RotBstMatrix() {
for (
int i = 0; i < 4; ++i) {
for (
int j = 0; j < 4; ++j)
309 { M[i][j] = (i==j) ? 1. : 0.; } } }
310 RotBstMatrix(
const RotBstMatrix& Min) {
311 for (
int i = 0; i < 4; ++i) {
for (
int j = 0; j < 4; ++j) {
312 M[i][j] = Min.M[i][j]; } } }
313 RotBstMatrix& operator=(
const RotBstMatrix& Min) {
if (
this != &Min) {
314 for (
int i = 0; i < 4; ++i) {
for (
int j = 0; j < 4; ++j) {
315 M[i][j] = Min.M[i][j]; } } }
return *
this; }
318 void rot(
double = 0.,
double = 0.);
319 void rot(
const Vec4& p);
320 void bst(
double = 0.,
double = 0.,
double = 0.);
321 void bst(
const Vec4&);
322 void bstback(
const Vec4&);
323 void bst(
const Vec4&,
const Vec4&);
324 void toCMframe(
const Vec4&,
const Vec4&);
325 void fromCMframe(
const Vec4&,
const Vec4&);
326 void rotbst(
const RotBstMatrix&);
331 double value(
int i,
int j) {
return M[i][j];}
334 double deviation()
const;
337 friend ostream& operator<<(ostream&,
const RotBstMatrix&) ;
345 static const double TINY;
357 ostream& operator<<(ostream&,
const RotBstMatrix&) ;
369 Hist() {titleSave =
"";}
370 Hist(
string titleIn,
int nBinIn = 100,
double xMinIn = 0.,
371 double xMaxIn = 1.,
bool logXIn =
false) {
372 book(titleIn, nBinIn, xMinIn, xMaxIn, logXIn);}
374 : titleSave(h.titleSave), nBin(h.nBin), nFill(h.nFill), xMin(h.xMin),
375 xMax(h.xMax), linX(h.linX), dx(h.dx), under(h.under), inside(h.inside),
376 over(h.over), res(h.res) { }
377 Hist(
string titleIn,
const Hist& h)
378 : titleSave(titleIn), nBin(h.nBin), nFill(h.nFill), xMin(h.xMin),
379 xMax(h.xMax), linX(h.linX), dx(h.dx), under(h.under), inside(h.inside),
380 over(h.over), res(h.res) { }
381 Hist& operator=(
const Hist& h) {
if(
this != &h) {
382 nBin = h.nBin; nFill = h.nFill; xMin = h.xMin; xMax = h.xMax;
383 linX = h.linX; dx = h.dx; under = h.under; inside = h.inside;
384 over = h.over; res = h.res; }
return *
this; }
387 void book(
string titleIn =
" ",
int nBinIn = 100,
double xMinIn = 0.,
388 double xMaxIn = 1.,
bool logXIn =
false) ;
391 void title(
string titleIn =
" ") {titleSave = titleIn; }
397 void fill(
double x,
double w = 1.) ;
400 friend ostream& operator<<(ostream& os,
const Hist& h) ;
403 void table(ostream& os = cout,
bool printOverUnder =
false,
404 bool xMidBin =
true)
const ;
405 void table(
string fileName,
bool printOverUnder =
false,
406 bool xMidBin =
true)
const { ofstream streamName(fileName.c_str());
407 table(streamName, printOverUnder, xMidBin);}
408 void rivetTable(ostream& os = cout,
bool printError =
false)
const ;
409 void rivetTable(
string fileName,
bool printError =
false)
const {
410 ofstream streamName(fileName.c_str()); rivetTable(streamName, printError);}
411 void pyplotTable(ostream& os = cout,
bool isHist =
true)
const ;
412 void pyplotTable(
string fileName,
bool isHist =
true)
const {
413 ofstream streamName(fileName.c_str()); pyplotTable(streamName, isHist);}
416 friend void table(
const Hist& h1,
const Hist& h2, ostream& os,
417 bool printOverUnder,
bool xMidBin) ;
418 friend void table(
const Hist& h1,
const Hist& h2,
string fileName,
419 bool printOverUnder,
bool xMidBin) ;
422 string getTitle()
const {
return titleSave;}
423 int getBinNumber()
const {
return nBin;}
424 bool getLinX()
const {
return linX;}
427 double getBinContent(
int iBin)
const;
430 int getEntries()
const {
return nFill; }
433 bool sameSize(
const Hist& h)
const ;
436 void takeLog(
bool tenLog =
true) ;
442 double smallestAbsValue()
const ;
445 Hist& operator+=(
const Hist& h) ;
446 Hist& operator-=(
const Hist& h) ;
447 Hist& operator*=(
const Hist& h) ;
448 Hist& operator/=(
const Hist& h) ;
449 Hist& operator+=(
double f) ;
450 Hist& operator-=(
double f) ;
451 Hist& operator*=(
double f) ;
452 Hist& operator/=(
double f) ;
453 Hist operator+(
double f)
const;
454 Hist operator+(
const Hist& h2)
const;
455 Hist operator-(
double f)
const;
456 Hist operator-(
const Hist& h2)
const;
457 Hist operator*(
double f)
const;
458 Hist operator*(
const Hist& h2)
const;
459 Hist operator/(
double f)
const;
460 Hist operator/(
const Hist& h2)
const;
463 friend Hist operator+(
double f,
const Hist& h1);
464 friend Hist operator-(
double f,
const Hist& h1);
465 friend Hist operator*(
double f,
const Hist& h1);
466 friend Hist operator/(
double f,
const Hist& h1);
471 static const int NBINMAX, NCOLMAX, NLINES;
472 static const double TOLERANCE, TINY, LARGE, SMALLFRAC, DYAC[];
473 static const char NUMBER[];
480 double dx, under, inside, over;
490 ostream& operator<<(ostream& os,
const Hist& h) ;
493 void table(
const Hist& h1,
const Hist& h2, ostream& os = cout,
494 bool printOverUnder =
false,
bool xMidBin =
true) ;
495 void table(
const Hist& h1,
const Hist& h2,
string fileName,
496 bool printOverUnder =
false,
bool xMidBin =
true) ;
499 Hist operator+(
double f,
const Hist& h1);
500 Hist operator-(
double f,
const Hist& h1);
501 Hist operator*(
double f,
const Hist& h1);
502 Hist operator/(
double f,
const Hist& h1);
514 HistPlot(
string pythonName) { toPython.open( (pythonName +
".py").c_str() );
515 toPython <<
"from matplotlib import pyplot as plt" << endl
516 <<
"from matplotlib.backends.backend_pdf import PdfPages" << endl;
520 ~
HistPlot() { toPython <<
"pp.close()" << endl; }
523 void frame(
string frameIn,
string titleIn =
"",
string xLabIn =
"",
524 string yLabIn =
"") {frameName = frameIn; title = titleIn; xLabel = xLabIn;
525 yLabel = yLabIn; histos.clear(); styles.clear(); legends.clear(); }
528 void add(
const Hist& histIn,
string styleIn =
"h",
529 string legendIn =
"void") { histos.push_back(&histIn);
530 styles.push_back(styleIn); legends.push_back(legendIn); }
533 void plot(
bool logY =
false);
536 void plotFrame(
string frameIn,
const Hist& histIn,
string titleIn =
"",
537 string xLabIn =
"",
string yLabIn =
"",
string styleIn =
"h",
538 string legendIn =
"void",
bool logY =
false) {
539 frame( frameIn, titleIn, xLabIn, yLabIn);
540 add( histIn, styleIn, legendIn); plot( logY); }
545 void init(
string pythonName);
549 int nPDF, nFrame, nTable;
550 string frameName, title, xLabel, yLabel, fileName, tmpFig;
551 vector<const Hist*> histos;
552 vector<string> styles, legends;
560 #endif // end Pythia8_Basics_H