28 const int Rndm::DEFAULTSEED = 19780503;
34 bool Rndm::rndmEnginePtr( RndmEngine* rndmEngPtrIn) {
37 if (rndmEngPtrIn == 0)
return false;
38 rndmEngPtr = rndmEngPtrIn;
39 useExternalRndm =
true;
50 void Rndm::init(
int seedIn) {
54 if (seedIn < 0) seed = DEFAULTSEED;
55 else if (seedIn == 0) seed = int(time(0));
56 if (seed < 0) seed = -seed;
59 int ij = (seed/30082) % 31329;
60 int kl = seed % 30082;
61 int i = (ij/177) % 177 + 2;
63 int k = (kl/169) % 178 + 1;
67 for (
int ii = 0; ii < 97; ++ii) {
70 for (
int jj = 0; jj < 48; ++jj) {
71 int m = (( (i*j)%179 )*k) % 179;
76 if ( (l*m) % 64 >= 32) s += t;
84 for (
int i24 = 0; i24 < 24; ++i24) twom24 *= 0.5;
86 cd = 7654321. * twom24;
87 cm = 16777213. * twom24;
102 double Rndm::flat() {
105 if (useExternalRndm)
return rndmEngPtr->flat();
108 if (!initRndm) init(DEFAULTSEED);
114 uni = u[i97] - u[j97];
115 if (uni < 0.) uni += 1.;
117 if (--i97 < 0) i97 = 96;
118 if (--j97 < 0) j97 = 96;
122 if(uni < 0.) uni += 1.;
123 }
while (uni <= 0. || uni >= 1.);
132 int Rndm::pick(
const vector<double>& prob) {
135 for (
int i = 0; i < int(prob.size()); ++i) work += prob[i];
138 do work -= prob[++index];
139 while (work > 0. && index <
int(prob.size()));
148 bool Rndm::dumpState(
string fileName) {
151 const char* fn = fileName.c_str();
152 ofstream ofs(fn, ios::binary);
155 cout <<
" Rndm::dumpState: could not open output file" << endl;
160 ofs.write((
char *) &seedSave,
sizeof(
int));
161 ofs.write((
char *) &sequence,
sizeof(
long));
162 ofs.write((
char *) &i97,
sizeof(
int));
163 ofs.write((
char *) &j97,
sizeof(
int));
164 ofs.write((
char *) &c,
sizeof(
double));
165 ofs.write((
char *) &cd,
sizeof(
double));
166 ofs.write((
char *) &cm,
sizeof(
double));
167 ofs.write((
char *) &u,
sizeof(
double) * 97);
170 cout <<
" PYTHIA Rndm::dumpState: seed = " << seedSave
171 <<
", sequence no = " << sequence << endl;
180 bool Rndm::readState(
string fileName) {
183 const char* fn = fileName.c_str();
184 ifstream ifs(fn, ios::binary);
187 cout <<
" Rndm::readState: could not open input file" << endl;
192 ifs.read((
char *) &seedSave,
sizeof(
int));
193 ifs.read((
char *) &sequence,
sizeof(
long));
194 ifs.read((
char *) &i97,
sizeof(
int));
195 ifs.read((
char *) &j97,
sizeof(
int));
196 ifs.read((
char *) &c,
sizeof(
double));
197 ifs.read((
char *) &cd,
sizeof(
double));
198 ifs.read((
char *) &cm,
sizeof(
double));
199 ifs.read((
char *) &u,
sizeof(
double) *97);
202 cout <<
" PYTHIA Rndm::readState: seed " << seedSave
203 <<
", sequence no = " << sequence << endl;
220 const double Vec4::TINY = 1e-20;
226 void Vec4::rot(
double thetaIn,
double phiIn) {
228 double cthe = cos(thetaIn);
229 double sthe = sin(thetaIn);
230 double cphi = cos(phiIn);
231 double sphi = sin(phiIn);
232 double tmpx = cthe * cphi * xx - sphi * yy + sthe * cphi * zz;
233 double tmpy = cthe * sphi * xx + cphi * yy + sthe * sphi * zz;
234 double tmpz = -sthe * xx + cthe * zz;
245 void Vec4::rotaxis(
double phiIn,
double nx,
double ny,
double nz) {
247 double norm = 1./sqrt(nx*nx + ny*ny + nz*nz);
251 double cphi = cos(phiIn);
252 double sphi = sin(phiIn);
253 double comb = (nx * xx + ny * yy + nz * zz) * (1. - cphi);
254 double tmpx = cphi * xx + comb * nx + sphi * (ny * zz - nz * yy);
255 double tmpy = cphi * yy + comb * ny + sphi * (nz * xx - nx * zz);
256 double tmpz = cphi * zz + comb * nz + sphi * (nx * yy - ny * xx);
267 void Vec4::rotaxis(
double phiIn,
const Vec4& n) {
272 double norm = 1./sqrt(nx*nx + ny*ny + nz*nz);
276 double cphi = cos(phiIn);
277 double sphi = sin(phiIn);
278 double comb = (nx * xx + ny * yy + nz * zz) * (1. - cphi);
279 double tmpx = cphi * xx + comb * nx + sphi * (ny * zz - nz * yy);
280 double tmpy = cphi * yy + comb * ny + sphi * (nz * xx - nx * zz);
281 double tmpz = cphi * zz + comb * nz + sphi * (nx * yy - ny * xx);
292 void Vec4::bst(
double betaX,
double betaY,
double betaZ) {
294 double beta2 = betaX*betaX + betaY*betaY + betaZ*betaZ;
295 double gamma = 1. / sqrt(1. - beta2);
296 double prod1 = betaX * xx + betaY * yy + betaZ * zz;
297 double prod2 = gamma * (gamma * prod1 / (1. + gamma) + tt);
301 tt = gamma * (tt + prod1);
309 void Vec4::bst(
double betaX,
double betaY,
double betaZ,
double gamma) {
311 double prod1 = betaX * xx + betaY * yy + betaZ * zz;
312 double prod2 = gamma * (gamma * prod1 / (1. + gamma) + tt);
316 tt = gamma * (tt + prod1);
324 void Vec4::bst(
const Vec4& pIn) {
326 double betaX = pIn.xx / pIn.tt;
327 double betaY = pIn.yy / pIn.tt;
328 double betaZ = pIn.zz / pIn.tt;
329 double beta2 = betaX*betaX + betaY*betaY + betaZ*betaZ;
330 double gamma = 1. / sqrt(1. - beta2);
331 double prod1 = betaX * xx + betaY * yy + betaZ * zz;
332 double prod2 = gamma * (gamma * prod1 / (1. + gamma) + tt);
336 tt = gamma * (tt + prod1);
344 void Vec4::bst(
const Vec4& pIn,
double mIn) {
346 double betaX = pIn.xx / pIn.tt;
347 double betaY = pIn.yy / pIn.tt;
348 double betaZ = pIn.zz / pIn.tt;
349 double gamma = pIn.tt / mIn;
350 double prod1 = betaX * xx + betaY * yy + betaZ * zz;
351 double prod2 = gamma * (gamma * prod1 / (1. + gamma) + tt);
355 tt = gamma * (tt + prod1);
363 void Vec4::bstback(
const Vec4& pIn) {
365 double betaX = -pIn.xx / pIn.tt;
366 double betaY = -pIn.yy / pIn.tt;
367 double betaZ = -pIn.zz / pIn.tt;
368 double beta2 = betaX*betaX + betaY*betaY + betaZ*betaZ;
369 double gamma = 1. / sqrt(1. - beta2);
370 double prod1 = betaX * xx + betaY * yy + betaZ * zz;
371 double prod2 = gamma * (gamma * prod1 / (1. + gamma) + tt);
375 tt = gamma * (tt + prod1);
383 void Vec4::bstback(
const Vec4& pIn,
double mIn) {
385 double betaX = -pIn.xx / pIn.tt;
386 double betaY = -pIn.yy / pIn.tt;
387 double betaZ = -pIn.zz / pIn.tt;
388 double gamma = pIn.tt / mIn;
389 double prod1 = betaX * xx + betaY * yy + betaZ * zz;
390 double prod2 = gamma * (gamma * prod1 / (1. + gamma) + tt);
394 tt = gamma * (tt + prod1);
402 void Vec4::rotbst(
const RotBstMatrix& M) {
404 double x = xx;
double y = yy;
double z = zz;
double t = tt;
405 tt = M.M[0][0] * t + M.M[0][1] * x + M.M[0][2] * y + M.M[0][3] * z;
406 xx = M.M[1][0] * t + M.M[1][1] * x + M.M[1][2] * y + M.M[1][3] * z;
407 yy = M.M[2][0] * t + M.M[2][1] * x + M.M[2][2] * y + M.M[2][3] * z;
408 zz = M.M[3][0] * t + M.M[3][1] * x + M.M[3][2] * y + M.M[3][3] * z;
416 double m(
const Vec4& v1,
const Vec4& v2) {
417 double m2 = pow2(v1.tt + v2.tt) - pow2(v1.xx + v2.xx)
418 - pow2(v1.yy + v2.yy) - pow2(v1.zz + v2.zz);
419 return (m2 > 0.) ? sqrt(m2) : 0.;
426 double m2(
const Vec4& v1,
const Vec4& v2) {
427 double m2 = pow2(v1.tt + v2.tt) - pow2(v1.xx + v2.xx)
428 - pow2(v1.yy + v2.yy) - pow2(v1.zz + v2.zz);
436 double dot3(
const Vec4& v1,
const Vec4& v2) {
437 return v1.xx*v2.xx + v1.yy*v2.yy + v1.zz*v2.zz;
444 Vec4 cross3(
const Vec4& v1,
const Vec4& v2) {
446 v.xx = v1.yy * v2.zz - v1.zz * v2.yy;
447 v.yy = v1.zz * v2.xx - v1.xx * v2.zz;
448 v.zz = v1.xx * v2.yy - v1.yy * v2.xx;
return v;
455 double theta(
const Vec4& v1,
const Vec4& v2) {
456 double cthe = (v1.xx * v2.xx + v1.yy * v2.yy + v1.zz * v2.zz)
457 / sqrt( (v1.xx*v1.xx + v1.yy*v1.yy + v1.zz*v1.zz)
458 * (v2.xx*v2.xx + v2.yy*v2.yy + v2.zz*v2.zz) );
459 cthe = max(-1., min(1., cthe));
467 double costheta(
const Vec4& v1,
const Vec4& v2) {
468 double cthe = (v1.xx * v2.xx + v1.yy * v2.yy + v1.zz * v2.zz)
469 / sqrt( (v1.xx*v1.xx + v1.yy*v1.yy + v1.zz*v1.zz)
470 * (v2.xx*v2.xx + v2.yy*v2.yy + v2.zz*v2.zz) );
471 cthe = max(-1., min(1., cthe));
479 double phi(
const Vec4& v1,
const Vec4& v2) {
480 double cphi = (v1.xx * v2.xx + v1.yy * v2.yy) / sqrt( max( Vec4::TINY,
481 (v1.xx*v1.xx + v1.yy*v1.yy) * (v2.xx*v2.xx + v2.yy*v2.yy) ));
482 cphi = max(-1., min(1., cphi));
490 double cosphi(
const Vec4& v1,
const Vec4& v2) {
491 double cphi = (v1.xx * v2.xx + v1.yy * v2.yy) / sqrt( max( Vec4::TINY,
492 (v1.xx*v1.xx + v1.yy*v1.yy) * (v2.xx*v2.xx + v2.yy*v2.yy) ));
493 cphi = max(-1., min(1., cphi));
501 double phi(
const Vec4& v1,
const Vec4& v2,
const Vec4& n) {
502 double nx = n.xx;
double ny = n.yy;
double nz = n.zz;
503 double norm = 1. / sqrt(nx*nx + ny*ny + nz*nz);
504 nx *= norm; ny *=norm; nz *=norm;
505 double v1s = v1.xx * v1.xx + v1.yy * v1.yy + v1.zz * v1.zz;
506 double v2s = v2.xx * v2.xx + v2.yy * v2.yy + v2.zz * v2.zz;
507 double v1v2 = v1.xx * v2.xx + v1.yy * v2.yy + v1.zz * v2.zz;
508 double v1n = v1.xx * nx + v1.yy * ny + v1.zz * nz;
509 double v2n = v2.xx * nx + v2.yy * ny + v2.zz * nz;
510 double cphi = (v1v2 - v1n * v2n) / sqrt( max( Vec4::TINY,
511 (v1s - v1n*v1n) * (v2s - v2n*v2n) ));
512 cphi = max(-1., min(1., cphi));
520 double cosphi(
const Vec4& v1,
const Vec4& v2,
const Vec4& n) {
521 double nx = n.xx;
double ny = n.yy;
double nz = n.zz;
522 double norm = 1. / sqrt(nx*nx + ny*ny + nz*nz);
523 nx *= norm; ny *=norm; nz *=norm;
524 double v1s = v1.xx * v1.xx + v1.yy * v1.yy + v1.zz * v1.zz;
525 double v2s = v2.xx * v2.xx + v2.yy * v2.yy + v2.zz * v2.zz;
526 double v1v2 = v1.xx * v2.xx + v1.yy * v2.yy + v1.zz * v2.zz;
527 double v1n = v1.xx * nx + v1.yy * ny + v1.zz * nz;
528 double v2n = v2.xx * nx + v2.yy * ny + v2.zz * nz;
529 double cphi = (v1v2 - v1n * v2n) / sqrt( max( Vec4::TINY,
530 (v1s - v1n*v1n) * (v2s - v2n*v2n) ));
531 cphi = max(-1., min(1., cphi));
539 ostream& operator<<(ostream& os,
const Vec4& v) {
540 os << fixed << setprecision(3) <<
" " << setw(9) << v.xx <<
" "
541 << setw(9) << v.yy <<
" " << setw(9) << v.zz <<
" " << setw(9)
542 << v.tt <<
" (" << setw(9) << v.mCalc() <<
")\n";
558 const double RotBstMatrix::TINY = 1e-20;
564 void RotBstMatrix::rot(
double theta,
double phi) {
567 double cthe = cos(theta);
568 double sthe = sin(theta);
569 double cphi = cos(phi);
570 double sphi = sin(phi);
571 double Mrot[4][4] = {
573 {0., cthe * cphi, - sphi, sthe * cphi},
574 {0., cthe * sphi, cphi, sthe * sphi},
575 {0., -sthe, 0., cthe } };
579 for (
int i = 0; i < 4; ++i)
580 for (
int j = 0; j < 4; ++j)
581 Mtmp[i][j] = M[i][j];
582 for (
int i = 0; i < 4; ++i)
583 for (
int j = 0; j < 4; ++j)
584 M[i][j] = Mrot[i][0] * Mtmp[0][j] + Mrot[i][1] * Mtmp[1][j]
585 + Mrot[i][2] * Mtmp[2][j] + Mrot[i][3] * Mtmp[3][j];
593 void RotBstMatrix::rot(
const Vec4& p) {
595 double theta = p.theta();
596 double phi = p.phi();
606 void RotBstMatrix::bst(
double betaX,
double betaY,
double betaZ) {
609 double gm = 1. / sqrt( max( TINY, 1. - betaX*betaX - betaY*betaY
611 double gf = gm*gm / (1. + gm);
612 double Mbst[4][4] = {
613 { gm, gm*betaX, gm*betaY, gm*betaZ },
614 { gm*betaX, 1. + gf*betaX*betaX, gf*betaX*betaY, gf*betaX*betaZ },
615 { gm*betaY, gf*betaY*betaX, 1. + gf*betaY*betaY, gf*betaY*betaZ },
616 { gm*betaZ, gf*betaZ*betaX, gf*betaZ*betaY, 1. + gf*betaZ*betaZ } };
620 for (
int i = 0; i < 4; ++i)
621 for (
int j = 0; j < 4; ++j)
622 Mtmp[i][j] = M[i][j];
623 for (
int i = 0; i < 4; ++i)
624 for (
int j = 0; j < 4; ++j)
625 M[i][j] = Mbst[i][0] * Mtmp[0][j] + Mbst[i][1] * Mtmp[1][j]
626 + Mbst[i][2] * Mtmp[2][j] + Mbst[i][3] * Mtmp[3][j];
634 void RotBstMatrix::bst(
const Vec4& p) {
635 double betaX = p.px() / p.e();
636 double betaY = p.py() / p.e();
637 double betaZ = p.pz() / p.e();
638 bst(betaX, betaY, betaZ);
645 void RotBstMatrix::bstback(
const Vec4& p) {
646 double betaX = -p.px() / p.e();
647 double betaY = -p.py() / p.e();
648 double betaZ = -p.pz() / p.e();
649 bst(betaX, betaY, betaZ);
656 void RotBstMatrix::bst(
const Vec4& p1,
const Vec4& p2) {
657 double eSum = p1.e() + p2.e();
658 double betaX = (p2.px() - p1.px()) / eSum;
659 double betaY = (p2.py() - p1.py()) / eSum;
660 double betaZ = (p2.pz() - p1.pz()) / eSum;
661 double fac = 2. / (1. + betaX*betaX + betaY*betaY + betaZ*betaZ);
662 betaX *= fac; betaY *= fac; betaZ *= fac;
663 bst(betaX, betaY, betaZ);
671 void RotBstMatrix::toCMframe(
const Vec4& p1,
const Vec4& p2) {
675 double theta = dir.theta();
676 double phi = dir.phi();
687 void RotBstMatrix::fromCMframe(
const Vec4& p1,
const Vec4& p2) {
691 double theta = dir.theta();
692 double phi = dir.phi();
702 void RotBstMatrix::rotbst(
const RotBstMatrix& Mrb) {
704 for (
int i = 0; i < 4; ++i)
705 for (
int j = 0; j < 4; ++j)
706 Mtmp[i][j] = M[i][j];
707 for (
int i = 0; i < 4; ++i)
708 for (
int j = 0; j < 4; ++j)
709 M[i][j] = Mrb.M[i][0] * Mtmp[0][j] + Mrb.M[i][1] * Mtmp[1][j]
710 + Mrb.M[i][2] * Mtmp[2][j] + Mrb.M[i][3] * Mtmp[3][j];
717 void RotBstMatrix::invert() {
719 for (
int i = 0; i < 4; ++i)
720 for (
int j = 0; j < 4; ++j)
721 Mtmp[i][j] = M[i][j];
722 for (
int i = 0; i < 4; ++i)
723 for (
int j = 0; j < 4; ++j)
724 M[i][j] = ( (i == 0 && j > 0) || (i > 0 && j == 0) )
725 ? - Mtmp[j][i] : Mtmp[j][i];
732 void RotBstMatrix::reset() {
733 for (
int i = 0; i < 4; ++i)
734 for (
int j = 0; j < 4; ++j)
735 M[i][j] = (i==j) ? 1. : 0.;
742 double RotBstMatrix::deviation()
const {
744 for (
int i = 0; i < 4; ++i)
745 for (
int j = 0; j < 4; ++j)
746 devSum += (i==j) ? abs(M[i][j] - 1.) : abs(M[i][j]);
754 ostream& operator<<(ostream& os,
const RotBstMatrix& M) {
755 os << fixed << setprecision(5) <<
" Rotation/boost matrix: \n";
756 for (
int i = 0; i <4; ++i)
757 os << setw(10) << M.M[i][0] << setw(10) << M.M[i][1]
758 << setw(10) << M.M[i][2] << setw(10) << M.M[i][3] <<
"\n";
774 const int Hist::NBINMAX = 1000;
777 const int Hist::NCOLMAX = 100;
780 const int Hist::NLINES = 30;
783 const double Hist::TOLERANCE = 0.001;
786 const double Hist::TINY = 1e-20;
789 const double Hist::SMALLFRAC = 0.1;
792 const double DYAC[] = {0.04, 0.05, 0.06, 0.08, 0.10,
793 0.12, 0.15, 0.20, 0.25, 0.30};
794 const char NUMBER[] = {
'0',
'1',
'2',
'3',
'4',
'5',
795 '6',
'7',
'8',
'9',
'X' };
801 void Hist::book(
string titleIn,
int nBinIn,
double xMinIn,
806 if (nBinIn < 1) nBin = 1;
807 if (nBinIn > NBINMAX) nBin = NBINMAX;
810 dx = (xMax - xMin)/nBin;
826 for (
int ix = 0; ix < nBin; ++ix) res[ix] = 0.;
834 void Hist::fill(
double x,
double w) {
837 int iBin = int(floor((x - xMin)/dx));
838 if (iBin < 0) under += w;
839 else if (iBin >= nBin) over += w;
840 else {inside += w; res[iBin] += w; }
848 ostream& operator<<(ostream& os,
const Hist& h) {
851 if (h.nFill <= 0)
return os;
856 strftime(date,18,
"%Y-%m-%d %H:%M",localtime(&t));
857 os <<
"\n\n " << date <<
" " << h.title <<
"\n\n";
860 int nGroup = 1 + (h.nBin - 1) / Hist::NCOLMAX;
861 int nCol = 1 + (h.nBin - 1) / nGroup;
862 vector<double> resCol(nCol);
863 for (
int iCol = 0; iCol < nCol; ++iCol) {
865 for (
int ix = nGroup * iCol; ix < min( h.nBin, nGroup * (iCol + 1)); ++ix)
866 resCol[iCol] += h.res[ix];
870 double yMin = resCol[0];
871 double yMax = resCol[0];
872 for (
int iCol = 1; iCol < nCol; ++iCol) {
873 if (resCol[iCol] < yMin) yMin = resCol[iCol];
874 if (resCol[iCol] > yMax) yMax = resCol[iCol];
878 if (yMax - yMin > Hist::NLINES * DYAC[0] * 1e-9) {
879 if (yMin > 0. && yMin < Hist::SMALLFRAC * yMax) yMin = 0.;
880 if (yMax < 0. && yMax > Hist::SMALLFRAC * yMin) yMax = 0.;
881 int iPowY = int(floor( log10(yMax - yMin) ));
882 if (yMax - yMin < Hist::NLINES * DYAC[0] * pow(10.,iPowY))
884 if (yMax - yMin > Hist::NLINES * DYAC[9] * pow(10.,iPowY))
886 double nLinePow = Hist::NLINES * pow(10.,iPowY);
887 double delY = DYAC[0];
888 for (
int idel = 0; idel < 9; ++idel)
889 if (yMax - yMin >= nLinePow * DYAC[idel]) delY = DYAC[idel+1];
890 double dy = delY * pow(10.,iPowY);
893 vector<int> row(nCol);
894 vector<int> frac(nCol);
895 for (
int iCol = 0; iCol < nCol ; ++iCol) {
896 double cta = abs(resCol[iCol]) / dy;
897 row[iCol] = int(cta + 0.95);
898 if(resCol[iCol] < 0.) row[iCol] = - row[iCol];
899 frac[iCol] = int(10. * (cta + 1.05 - floor(cta + 0.95)));
901 int rowMin = int(abs(yMin)/dy + 0.95);
902 if ( yMin < 0) rowMin = - rowMin;
903 int rowMax = int(abs(yMax)/dy + 0.95);
904 if ( yMax < 0) rowMax = - rowMax;
907 os << fixed << setprecision(2);
908 for (
int iRow = rowMax; iRow >= rowMin; iRow--)
if (iRow != 0) {
909 os <<
" " << setw(10) << iRow*delY <<
"*10^"
910 << setw(2) << iPowY <<
" ";
911 for (
int iCol = 0; iCol < nCol ; ++iCol) {
912 if (iRow == row[iCol]) os << NUMBER[frac[iCol]];
913 else if (iRow * (row[iCol] - iRow) > 0) os << NUMBER[10];
919 double maxim = log10(max(yMax, -yMin));
920 int iPowBin = int(floor(maxim + 0.0001));
922 for (
int iCol = 0; iCol < nCol ; ++iCol) {
923 if (resCol[iCol] < - pow(10., iPowBin - 4)) os <<
"-";
925 row[iCol] = int(abs(resCol[iCol]) * pow(10., 3 - iPowBin) + 0.5);
927 for (
int iRow = 3; iRow >= 0; iRow--) {
928 os <<
" *10^" << setw(2) << iPowBin + iRow - 3 <<
" ";
929 int mask = int( pow(10., iRow) + 0.5);
930 for (
int iCol = 0; iCol < nCol ; ++iCol) {
931 os << NUMBER[(row[iCol] / mask) % 10];
936 maxim = log10( max( -h.xMin, h.xMax - h.dx));
937 int iPowExp = int(floor(maxim + 0.0001));
939 for (
int iCol = 0; iCol < nCol ; ++iCol) {
940 if (h.xMin + iCol * nGroup * h.dx < - pow(10., iPowExp - 3)) os <<
"-";
942 row[iCol] = int(abs(h.xMin + iCol * nGroup * h.dx)
943 * pow(10., 2 - iPowExp) + 0.5);
945 for (
int iRow = 2; iRow >= 0; iRow--) {
946 os <<
" *10^" << setw(2) << iPowExp + iRow - 2 <<
" ";
947 int mask = int( pow(10., iRow) + 0.5);
948 for (
int iCol = 0; iCol < nCol ; ++iCol)
949 os << NUMBER[(row[iCol] / mask) % 10];
954 }
else os <<
" Histogram not shown since lowest value" << scientific
955 << setprecision(4) << setw(12) << yMin <<
" and highest value"
956 << setw(12) << yMax <<
" are too close \n \n";
962 for (
int ix = 0; ix < h.nBin ; ++ix) {
963 double cta = abs(h.res[ix]);
964 double x = h.xMin + (ix + 0.5) * h.dx;
966 cxSum = cxSum + cta * x;
967 cxxSum = cxxSum + cta * x * x;
969 double xmean = cxSum / max(cSum, Hist::TINY);
970 double rms = sqrtpos( cxxSum / max(cSum, Hist::TINY) - xmean*xmean );
971 os << scientific << setprecision(4)
972 <<
" Entries =" << setw(12) << h.nFill
973 <<
" Mean =" << setw(12) << xmean
974 <<
" Underflow =" << setw(12) << h.under
975 <<
" Low edge =" << setw(12) << h.xMin <<
"\n"
976 <<
" All chan =" << setw(12) << h.inside
977 <<
" Rms =" << setw(12) << rms
978 <<
" Overflow =" << setw(12) << h.over
979 <<
" High edge =" << setw(12) << h.xMax << endl;
987 void Hist::table(ostream& os)
const {
990 os << scientific << setprecision(4);
991 for (
int ix = 0; ix < nBin; ++ix)
992 os << setw(12) << xMin + (ix + 0.5) * dx
993 << setw(12) << res[ix] <<
"\n";
1001 void table(
const Hist& h1,
const Hist& h2, ostream& os) {
1004 if (h1.nBin != h2.nBin || abs(h1.xMin - h2.xMin) > Hist::TOLERANCE * h1.dx
1005 || abs(h1.xMax - h2.xMax) > Hist::TOLERANCE * h1.dx)
return;
1008 os << scientific << setprecision(4);
1009 for (
int ix = 0; ix < h1.nBin; ++ix)
1010 os << setw(12) << h1.xMin + (ix + 0.5) * h1.dx
1011 << setw(12) << h1.res[ix] << setw(12) << h2.res[ix] <<
"\n";
1015 void table(
const Hist& h1,
const Hist& h2,
string fileName) {
1016 ofstream streamName(fileName.c_str());
1017 table( h1, h2, streamName);
1026 double Hist::getBinContent(
int iBin) {
1028 if (iBin > 0 && iBin <= nBin)
return res[iBin - 1];
1029 else if (iBin == 0)
return under;
1030 else if (iBin == nBin + 1)
return over;
1039 bool Hist::sameSize(
const Hist& h)
const {
1041 if (nBin == h.nBin && abs(xMin - h.xMin) < TOLERANCE * dx &&
1042 abs(xMax - h.xMax) < TOLERANCE * dx)
return true;
1051 void Hist::takeLog(
bool tenLog) {
1055 for (
int ix = 0; ix < nBin; ++ix)
1056 if (res[ix] > 1e-20 && res[ix] < yMin ) yMin = res[ix];
1061 for (
int ix = 0; ix < nBin; ++ix)
1062 res[ix] = log10( max( yMin, res[ix]) );
1063 under = log10( max( yMin, under) );
1064 inside = log10( max( yMin, inside) );
1065 over = log10( max( yMin, over) );
1069 for (
int ix = 0; ix < nBin; ++ix)
1070 res[ix] = log( max( yMin, res[ix]) );
1071 under = log( max( yMin, under) );
1072 inside = log( max( yMin, inside) );
1073 over = log( max( yMin, over) );
1082 void Hist::takeSqrt() {
1084 for (
int ix = 0; ix < nBin; ++ix) res[ix] = sqrtpos(res[ix]);
1085 under = sqrtpos(under);
1086 inside = sqrtpos(inside);
1087 over = sqrtpos(over);
1095 Hist& Hist::operator+=(
const Hist& h) {
1096 if (!sameSize(h))
return *
this;
1101 for (
int ix = 0; ix < nBin; ++ix) res[ix] += h.res[ix];
1109 Hist& Hist::operator-=(
const Hist& h) {
1110 if (!sameSize(h))
return *
this;
1115 for (
int ix = 0; ix < nBin; ++ix) res[ix] -= h.res[ix];
1123 Hist& Hist::operator*=(
const Hist& h) {
1124 if (!sameSize(h))
return *
this;
1129 for (
int ix = 0; ix < nBin; ++ix) res[ix] *= h.res[ix];
1137 Hist& Hist::operator/=(
const Hist& h) {
1138 if (!sameSize(h))
return *
this;
1140 under = (abs(h.under) < Hist::TINY) ? 0. : under/h.under;
1141 inside = (abs(h.inside) < Hist::TINY) ? 0. : inside/h.inside;
1142 over = (abs(h.over) < Hist::TINY) ? 0. : over/h.over;
1143 for (
int ix = 0; ix < nBin; ++ix)
1144 res[ix] = (abs(h.res[ix]) < Hist::TINY) ? 0. : res[ix]/h.res[ix];
1152 Hist& Hist::operator+=(
double f) {
1156 for (
int ix = 0; ix < nBin; ++ix) res[ix] += f;
1164 Hist& Hist::operator-=(
double f) {
1168 for (
int ix = 0; ix < nBin; ++ix) res[ix] -= f;
1176 Hist& Hist::operator*=(
double f) {
1180 for (
int ix = 0; ix < nBin; ++ix) res[ix] *= f;
1188 Hist& Hist::operator/=(
double f) {
1192 for (
int ix = 0; ix < nBin; ++ix) res[ix] /= f;
1200 Hist operator+(
double f,
const Hist& h1) {
1201 Hist h = h1;
return h += f;}
1203 Hist operator+(
const Hist& h1,
double f) {
1204 Hist h = h1;
return h += f;}
1206 Hist operator+(
const Hist& h1,
const Hist& h2) {
1207 Hist h = h1;
return h += h2;}
1209 Hist operator-(
double f,
const Hist& h1) {
1211 h.under = f - h1.under;
1212 h.inside = h1.nBin * f - h1.inside;
1213 h.over = f - h1.over;
1214 for (
int ix = 0; ix < h1.nBin; ++ix) h.res[ix] = f - h1.res[ix];
1217 Hist operator-(
const Hist& h1,
double f) {
1218 Hist h = h1;
return h -= f;}
1220 Hist operator-(
const Hist& h1,
const Hist& h2) {
1221 Hist h = h1;
return h -= h2;}
1223 Hist operator*(
double f,
const Hist& h1) {
1224 Hist h = h1;
return h *= f;}
1226 Hist operator*(
const Hist& h1,
double f) {
1227 Hist h = h1;
return h *= f;}
1229 Hist operator*(
const Hist& h1,
const Hist& h2) {
1230 Hist h = h1;
return h *= h2;}
1232 Hist operator/(
double f,
const Hist& h1) {
1234 h.under = (abs(h1.under) < Hist::TINY) ? 0. : f/h1.under;
1235 h.inside = (abs(h1.inside) < Hist::TINY) ? 0. : f/h1.inside;
1236 h.over = (abs(h1.over) < Hist::TINY) ? 0. : f/h1.over;
1237 for (
int ix = 0; ix < h1.nBin; ++ix)
1238 h.res[ix] = (abs(h1.res[ix]) < Hist::TINY) ? 0. : f/h1.res[ix];
1242 Hist operator/(
const Hist& h1,
double f) {
1243 Hist h = h1;
return h /= f;}
1245 Hist operator/(
const Hist& h1,
const Hist& h2) {
1246 Hist h = h1;
return h /= h2;}