Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
s95p.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file s95p.cpp
1 #include <cmath>
2 #include <iostream>
3 #include <fstream>
4 #include <cstdlib>
5 
6 extern int glauberVariable;
7 
8 namespace s95p {
9 using namespace std;
10 
11 int NX, NY; // N*N table
12 double** e, xmin, xmax, ymin, ymax;
13 
14 double s95p_s(double e) {
15  double val;
16  if (e < 0.1270769021427449)
17  val = 12.2304 * pow(e, 1.16849);
18  else if (e < 0.4467079524674040)
19  val = 11.9279 * pow(e, 1.15635);
20  else if (e < 1.9402832534193788)
21  val = 0.0580578 + 11.833 * pow(e, 1.16187);
22  else if (e < 3.7292474570977285)
23  val =
24  18.202 * e - 62.021814 - 4.85479 * exp(-2.72407e-11 * pow(e, 4.54886)) +
25  65.1272 * pow(e, -0.128012) * exp(-0.00369624 * pow(e, 1.18735)) -
26  4.75253 * pow(e, -1.18423);
27  else
28  val = 18.202 * e - 63.0218 - 4.85479 * exp(-2.72407e-11 * pow(e, 4.54886)) +
29  65.1272 * pow(e, -0.128012) * exp(-0.00369624 * pow(e, 1.18735));
30  return pow(val, 3. / 4.);
31 }
32 
33 double s95p_e(double s) {
34  double e = pow(s, 4. / 3.) / 18.2, e0;
35  do {
36  e0 = e;
37  e = e0 - (s95p_s(e0) - s) / (6.608681233 * pow(e0, -0.25));
38  } while (fabs(e - e0) > 1e-10);
39  return e;
40 }
41 
42 void loadSongIC(char* filename, double factor) {
43  ifstream fin(filename);
44  if (!fin) {
45  cout << "cannot open " << filename << endl;
46  exit(1);
47  }
48  fin >> NX >> NY;
49  double* x = new double[NX];
50  double* y = new double[NY];
51  e = new double* [NX];
52  for (int ix = 0; ix < NX; ix++) e[ix] = new double[NY];
53 
54  for (int ix = 0; ix < NX; ix++)
55  for (int iy = 0; iy < NY; iy++) {
56  fin >> x[ix] >> y[iy] >> e[ix][iy];
57  if (glauberVariable == 1)
58  e[ix][iy] = s95p_e(factor * e[ix][iy]);
59  else
60  e[ix][iy] = factor * e[ix][iy];
61  }
62  xmin = x[0];
63  xmax = x[NX - 1];
64  ymin = y[0];
65  ymax = y[NY - 1];
66  delete[] x;
67  delete[] y;
68 }
69 
70 double getSongEps(double x, double y) {
71  // linear interpolation in 2D is used
72  const double dx = (xmax - xmin) / (NX - 1);
73  const double dy = (ymax - ymin) / (NY - 1);
74  const int ix = (int)((x - xmin) / dx);
75  const int iy = (int)((y - ymin) / dy);
76  if (ix < 0 || ix > NX - 2 || iy < 0 || iy > NY - 2) return 0.0;
77  const double sx = x - xmin - ix * dx;
78  const double sy = y - ymin - iy * dy;
79  double wx[2] = {(1. - sx / dx), sx / dx};
80  double wy[2] = {(1. - sy / dy), sy / dy};
81  double result = 0;
82  for (int jx = 0; jx < 2; jx++)
83  for (int jy = 0; jy < 2; jy++) {
84  result += wx[jx] * wy[jy] * e[ix + jx][iy + jy];
85  }
86  return result;
87 }
88 
89 } // end s95p