Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
global-time-converter.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file global-time-converter.py
1 #!/usr/bin/env python3
2 import numpy as np, h5py, math
3 import sys, os, warnings
4 import matplotlib.pyplot as plt
5 
6 def help():
7  """
8  This script transforms the initial condition from
9  (tau, x, y, eta) frame to (t, x, y, z) frame. This
10  conversion assumes longitudinal Bjorken expansion
11  and transverse still.
12 
13  The entropy density in longitudinal-local frame at
14  constant proper time tau0 is:
15  s(tau0, x, y, eta) = s0(x,y,eta)/tau0
16  = ns0(x,y,eta) <-- trento3d
17 
18  Assuming Bjorken expansion for a short proper time,
19  s(tau, x, y, eta) = 1/tau*s0(x,y,eta)
20  = tau0/tau*ns0(x,y,eta) -- (1)
21 
22  Expression (1) is transformed into (t, x, y, z) via,
23  s'(t0, x, y, z) = 1/tau*ns0(x, y, eta)
24  tau = sqrt(t0^2 - z^2)
25  eta = 1/2*ln[(t0+z)/(t0-z)]
26  where tau0 is absorbed into normalization of ns0
27  (see --normalization option of the trento3d model).
28 
29  Usage:
30  {:s} trento3d-hdf5-output t0 [list-of-event-id-to-convert]
31 
32  For example, to convert all events to t0=1fm/c:
33  {:s} ic.hdf5 1.0
34  To convert only events #2 and #3 to t0=1fm/c:
35  {:s} ic.hdf5 1.0 2 3
36 """
37  print(help.__doc__.format(__file__, __file__, __file__))
38 
39 tiny = 1e-9
40 
41 def convert(dataset, t0):
42  field = dataset.value
43  Nx, Ny, Neta = field.shape
44  deta = dataset.attrs['deta']
45  dxy = dataset.attrs['dxy']
46  Lx, Ly, Leta = Nx*dxy/2., Ny*dxy/2., (Neta-1)*deta/2.
47  x = np.linspace(-Lx, Lx, Nx)
48  y = np.linspace(-Ly, Ly, Ny)
49  eta = np.linspace(-Leta, Leta, Neta)
50  # set maximum z-range, about +/- 6-unit of rapidity
51  z_max = t0*math.tanh(6.)
52  zarray = np.linspace(-z_max, z_max, Neta)
53 
54  new_field = np.zeros_like(field)
55 
56  for iz, z in enumerate(zarray):
57  eta = 0.5*np.log((t0+z)/(t0-z))
58  if np.abs(eta) > Leta:
59  continue
60  residue, index = math.modf((eta+Leta)/deta)
61  index = int(index)
62  new_field[:,:,iz] = ( field[:,:,index] *(1.-residue) \
63  + field[:,:,index+1]*residue) \
64  / np.sqrt(t0**2-z**2)
65  return x, y, zarray, new_field
66 
67 def plot(x, y, z, s):
68  dx = x[1]-x[0]
69  dy = y[1]-y[0]
70  fig, ax = plt.subplots(1, 1)
71  ax.plot(z, np.sum(s, axis=(0,1))*dx*dy, 'ro-')
72  ax.set_xlabel(r'$z$ [fm]', size=15)
73  ax.set_title(r'Local-rest-frame entropy in $t-z$ coordinates', size=15)
74  ax.set_ylabel(r'$ds/dV$ [Arb. units.]', size=15)
75  plt.subplots_adjust(wspace=0.15, bottom=0.2)
76  plt.semilogy()
77  plt.show()
78 
79 def main():
80  if len(sys.argv) <= 2:
81  help()
82  exit()
83  f = h5py.File(sys.argv[1], 'r')
84  t0 = float(sys.argv[2])
85  elist = ['event_{}'.format(index) for index in sys.argv[3:]] \
86  if len(sys.argv)>=4 else list(f.keys())
87  for eid in elist:
88  x, y, z, s = convert(f[eid], t0)
89  plot(x, y, z, s)
90 if __name__ == "__main__":
91  main()