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 mCalc()
const {
double temp = tt*tt - xx*xx - yy*yy - zz*zz;
141 return (temp >= 0.) ? sqrt(temp) : -sqrt(-temp);}
142 double m2Calc()
const {
return tt*tt - xx*xx - yy*yy - zz*zz;}
143 double pT()
const {
return sqrt(xx*xx + yy*yy);}
144 double pT2()
const {
return xx*xx + yy*yy;}
145 double pAbs()
const {
return sqrt(xx*xx + yy*yy + zz*zz);}
146 double pAbs2()
const {
return xx*xx + yy*yy + zz*zz;}
147 double eT()
const {
double temp = xx*xx + yy*yy;
148 return tt * sqrt( temp / (temp + zz*zz) );}
149 double eT2()
const {
double temp = xx*xx + yy*yy;
150 return tt*tt * temp / (temp + zz*zz);}
151 double theta()
const {
return atan2(sqrt(xx*xx + yy*yy), zz);}
152 double phi()
const {
return atan2(yy,xx);}
153 double thetaXZ()
const {
return atan2(xx,zz);}
154 double pPos()
const {
return tt + zz;}
155 double pNeg()
const {
return tt - zz;}
156 double rap()
const {
return 0.5 * log( (tt + zz) / (tt - zz) );}
157 double eta()
const {
double xyz = sqrt(xx*xx + yy*yy + zz*zz);
158 return 0.5 * log( (xyz + zz) / (xyz - zz) );}
161 void rescale3(
double fac) {xx *= fac; yy *= fac; zz *= fac;}
162 void rescale4(
double fac) {xx *= fac; yy *= fac; zz *= fac; tt *= fac;}
163 void flip3() {xx = -xx; yy = -yy; zz = -zz;}
164 void flip4() {xx = -xx; yy = -yy; zz = -zz; tt = -tt;}
165 void rot(
double thetaIn,
double phiIn);
166 void rotaxis(
double phiIn,
double nx,
double ny,
double nz);
167 void rotaxis(
double phiIn,
const Vec4& n);
168 void bst(
double betaX,
double betaY,
double betaZ);
169 void bst(
double betaX,
double betaY,
double betaZ,
double gamma);
170 void bst(
const Vec4& pIn);
171 void bst(
const Vec4& pIn,
double mIn);
172 void bstback(
const Vec4& pIn);
173 void bstback(
const Vec4& pIn,
double mIn);
174 void rotbst(
const RotBstMatrix& M);
177 Vec4 operator-() {Vec4 tmp; tmp.xx = -xx; tmp.yy = -yy; tmp.zz = -zz;
178 tmp.tt = -tt;
return tmp;}
179 Vec4& operator+=(
const Vec4& v) {xx += v.xx; yy += v.yy; zz += v.zz;
180 tt += v.tt;
return *
this;}
181 Vec4& operator-=(
const Vec4& v) {xx -= v.xx; yy -= v.yy; zz -= v.zz;
182 tt -= v.tt;
return *
this;}
183 Vec4& operator*=(
double f) {xx *= f; yy *= f; zz *= f;
184 tt *= f;
return *
this;}
185 Vec4& operator/=(
double f) {xx /= f; yy /= f; zz /= f;
186 tt /= f;
return *
this;}
189 friend Vec4 operator+(
const Vec4& v1,
const Vec4& v2);
190 friend Vec4 operator-(
const Vec4& v1,
const Vec4& v2);
191 friend Vec4 operator*(
double f,
const Vec4& v1);
192 friend Vec4 operator*(
const Vec4& v1,
double f);
193 friend Vec4 operator/(
const Vec4& v1,
double f);
194 friend double operator*(
const Vec4& v1,
const Vec4& v2);
197 friend double m(
const Vec4& v1,
const Vec4& v2);
198 friend double m2(
const Vec4& v1,
const Vec4& v2);
201 friend double dot3(
const Vec4& v1,
const Vec4& v2);
202 friend Vec4 cross3(
const Vec4& v1,
const Vec4& v2);
205 friend double theta(
const Vec4& v1,
const Vec4& v2);
206 friend double costheta(
const Vec4& v1,
const Vec4& v2);
209 friend double phi(
const Vec4& v1,
const Vec4& v2);
210 friend double cosphi(
const Vec4& v1,
const Vec4& v2);
213 friend double phi(
const Vec4& v1,
const Vec4& v2,
const Vec4& n);
214 friend double cosphi(
const Vec4& v1,
const Vec4& v2,
const Vec4& n);
217 friend double RRapPhi(
const Vec4& v1,
const Vec4& v2);
218 friend double REtaPhi(
const Vec4& v1,
const Vec4& v2);
221 friend ostream& operator<<(ostream&,
const Vec4& v) ;
226 static const double TINY;
229 double xx, yy, zz, tt;
239 inline Vec4 operator+(
const Vec4& v1,
const Vec4& v2)
240 {Vec4 v = v1 ;
return v += v2;}
242 inline Vec4 operator-(
const Vec4& v1,
const Vec4& v2)
243 {Vec4 v = v1 ;
return v -= v2;}
245 inline Vec4 operator*(
double f,
const Vec4& v1)
246 {Vec4 v = v1;
return v *= f;}
248 inline Vec4 operator*(
const Vec4& v1,
double f)
249 {Vec4 v = v1;
return v *= f;}
251 inline Vec4 operator/(
const Vec4& v1,
double f)
252 {Vec4 v = v1;
return v /= f;}
254 inline double operator*(
const Vec4& v1,
const Vec4& v2)
255 {
return v1.tt*v2.tt - v1.xx*v2.xx - v1.yy*v2.yy - v1.zz*v2.zz;}
258 double m(
const Vec4& v1,
const Vec4& v2);
259 double m2(
const Vec4& v1,
const Vec4& v2);
262 double dot3(
const Vec4& v1,
const Vec4& v2);
263 Vec4 cross3(
const Vec4& v1,
const Vec4& v2);
266 double theta(
const Vec4& v1,
const Vec4& v2);
267 double costheta(
const Vec4& v1,
const Vec4& v2);
270 double phi(
const Vec4& v1,
const Vec4& v2);
271 double cosphi(
const Vec4& v1,
const Vec4& v2);
274 double phi(
const Vec4& v1,
const Vec4& v2,
const Vec4& n);
275 double cosphi(
const Vec4& v1,
const Vec4& v2,
const Vec4& n);
278 double RRapPhi(
const Vec4& v1,
const Vec4& v2);
279 double REtaPhi(
const Vec4& v1,
const Vec4& v2);
282 ostream& operator<<(ostream&,
const Vec4& v) ;
295 RotBstMatrix() {
for (
int i = 0; i < 4; ++i) {
for (
int j = 0; j < 4; ++j)
296 { M[i][j] = (i==j) ? 1. : 0.; } } }
297 RotBstMatrix(
const RotBstMatrix& Min) {
298 for (
int i = 0; i < 4; ++i) {
for (
int j = 0; j < 4; ++j) {
299 M[i][j] = Min.M[i][j]; } } }
300 RotBstMatrix& operator=(
const RotBstMatrix& Min) {
if (
this != &Min) {
301 for (
int i = 0; i < 4; ++i) {
for (
int j = 0; j < 4; ++j) {
302 M[i][j] = Min.M[i][j]; } } }
return *
this; }
305 void rot(
double = 0.,
double = 0.);
306 void rot(
const Vec4& p);
307 void bst(
double = 0.,
double = 0.,
double = 0.);
308 void bst(
const Vec4&);
309 void bstback(
const Vec4&);
310 void bst(
const Vec4&,
const Vec4&);
311 void toCMframe(
const Vec4&,
const Vec4&);
312 void fromCMframe(
const Vec4&,
const Vec4&);
313 void rotbst(
const RotBstMatrix&);
318 double deviation()
const;
321 friend ostream& operator<<(ostream&,
const RotBstMatrix&) ;
329 static const double TINY;
341 ostream& operator<<(ostream&,
const RotBstMatrix&) ;
354 Hist(
string titleIn,
int nBinIn = 100,
double xMinIn = 0.,
355 double xMaxIn = 1.) {
356 book(titleIn, nBinIn, xMinIn, xMaxIn);}
358 : title(h.title), nBin(h.nBin), nFill(h.nFill), xMin(h.xMin),
359 xMax(h.xMax), dx(h.dx), under(h.under), inside(h.inside),
360 over(h.over), res(h.res) { }
361 Hist(
string titleIn,
const Hist& h)
362 : title(titleIn), nBin(h.nBin), nFill(h.nFill), xMin(h.xMin),
363 xMax(h.xMax), dx(h.dx), under(h.under), inside(h.inside),
364 over(h.over), res(h.res) { }
365 Hist& operator=(
const Hist& h) {
if(
this != &h) {
366 nBin = h.nBin; nFill = h.nFill; xMin = h.xMin; xMax = h.xMax;
367 dx = h.dx; under = h.under; inside = h.inside; over = h.over;
368 res = h.res; }
return *
this; }
371 void book(
string titleIn =
" ",
int nBinIn = 100,
double xMinIn = 0.,
372 double xMaxIn = 1.) ;
375 void name(
string titleIn =
" ") {title = titleIn; }
381 void fill(
double x,
double w = 1.) ;
384 friend ostream& operator<<(ostream& os,
const Hist& h) ;
387 void table(ostream& os = cout,
bool printOverUnder =
false,
388 bool xMidBin =
true)
const ;
389 void table(
string fileName,
bool printOverUnder =
false,
390 bool xMidBin =
true)
const { ofstream streamName(fileName.c_str());
391 table(streamName, printOverUnder, xMidBin);}
394 friend void table(
const Hist& h1,
const Hist& h2, ostream& os,
395 bool printOverUnder,
bool xMidBin) ;
396 friend void table(
const Hist& h1,
const Hist& h2,
string fileName,
397 bool printOverUnder,
bool xMidBin) ;
400 double getBinContent(
int iBin)
const;
403 int getEntries()
const {
return nFill; }
406 bool sameSize(
const Hist& h)
const ;
409 void takeLog(
bool tenLog =
true) ;
415 Hist& operator+=(
const Hist& h) ;
416 Hist& operator-=(
const Hist& h) ;
417 Hist& operator*=(
const Hist& h) ;
418 Hist& operator/=(
const Hist& h) ;
419 Hist& operator+=(
double f) ;
420 Hist& operator-=(
double f) ;
421 Hist& operator*=(
double f) ;
422 Hist& operator/=(
double f) ;
425 friend Hist operator+(
double f,
const Hist& h1);
426 friend Hist operator+(
const Hist& h1,
double f);
427 friend Hist operator+(
const Hist& h1,
const Hist& h2);
428 friend Hist operator-(
double f,
const Hist& h1);
429 friend Hist operator-(
const Hist& h1,
double f);
430 friend Hist operator-(
const Hist& h1,
const Hist& h2);
431 friend Hist operator*(
double f,
const Hist& h1);
432 friend Hist operator*(
const Hist& h1,
double f);
433 friend Hist operator*(
const Hist& h1,
const Hist& h2);
434 friend Hist operator/(
double f,
const Hist& h1);
435 friend Hist operator/(
const Hist& h1,
double f);
436 friend Hist operator/(
const Hist& h1,
const Hist& h2);
441 static const int NBINMAX, NCOLMAX, NLINES;
442 static const double TOLERANCE, TINY, LARGE, SMALLFRAC, DYAC[];
443 static const char NUMBER[];
448 double xMin, xMax, dx, under, inside, over;
458 ostream& operator<<(ostream& os,
const Hist& h) ;
461 void table(
const Hist& h1,
const Hist& h2, ostream& os = cout,
462 bool printOverUnder =
false,
bool xMidBin =
true) ;
463 void table(
const Hist& h1,
const Hist& h2,
string fileName,
464 bool printOverUnder =
false,
bool xMidBin =
true) ;
467 Hist operator+(
double f,
const Hist& h1);
468 Hist operator+(
const Hist& h1,
double f);
469 Hist operator+(
const Hist& h1,
const Hist& h2);
470 Hist operator-(
double f,
const Hist& h1);
471 Hist operator-(
const Hist& h1,
double f);
472 Hist operator-(
const Hist& h1,
const Hist& h2);
473 Hist operator*(
double f,
const Hist& h1);
474 Hist operator*(
const Hist& h1,
double f);
475 Hist operator*(
const Hist& h1,
const Hist& h2);
476 Hist operator/(
double f,
const Hist& h1);
477 Hist operator/(
const Hist& h1,
double f);
478 Hist operator/(
const Hist& h1,
const Hist& h2);
484 #endif // end Pythia8_Basics_H