Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
quick_view.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file quick_view.py
1 #!/usr/bin/env python3
2 import numpy as np
3 import matplotlib.pyplot as plt
4 import h5py, sys
5 
6 def help():
7 
8  """
9  This script plots
10  (1) transverse intergated entropy/density as function of rapidity
11  (2) Projection of entropy/density onto x-y (eta=0) plane
12  (3) ............................. onto y-eta (x=0) plane.
13  (4) ............................. onto x-eta (y=0) plane.
14 
15  Usage:
16  {:s} trento3d-hdf5-output [list-of-event-id-to-convert]
17 
18  For example, to view all events:
19  {:s} ic.hdf5
20  To view only events #2 and #3:
21  {:s} ic.hdf5 2 3
22 """
23  print(help.__doc__.format(__file__, __file__, __file__))
24 
25 def plot(dataset):
26  fig, axes = plt.subplots(
27  nrows=2, ncols=2,
28  figsize=(8, 7)
29  )
30  ax = axes[0,0]
31  field = dataset.value
32  Nx, Ny, Neta = field.shape
33  deta = dataset.attrs['deta']
34  dxy = dataset.attrs['dxy']
35  Lx, Ly, Leta = Nx*dxy/2., Ny*dxy/2., (Neta-1)*deta/2.
36  x = np.linspace(-Lx, Lx, Nx)
37  y = np.linspace(-Ly, Ly, Ny)
38  eta = np.linspace(-Leta, Leta, Neta)
39  ax.plot(eta, np.sum(field, axis=(0,1))*dxy*dxy)
40  ax.set_xlabel(r'$\eta$')
41  ax.set_ylabel(r'$dS/d\eta$')
42  ax.set_title('Tranverse integrated entropy')
43  Nxmid, Nymid, Netamid = int((Nx-1)/2), int((Ny-1)/2), int((Neta-1)/2)
44  for ax, projection, ranges, xlabel, ylabel, title in zip(
45  axes.flatten()[1:],
46  [field[:,:,Netamid], field[Nxmid,:,:], field[:,Nymid,:]],
47  [[-Lx, Lx, -Ly, Ly], [-Ly, Ly, -Leta, Leta], [-Lx, Lx, -Leta, Leta]],
48  [r'$y$ [fm]', r'$\eta$', r'$\eta$'],
49  [r'$x$ [fm]', r'$y$ [fm]', r'$x$ [fm]'],
50  [r'$x$-$y$ projection, $\eta=0$',r'$y$-$\eta$ projection, $x=0$',
51  r'$x$-$\eta$ projection, $y=0$']
52  ):
53  ax.contourf(projection, extent=ranges)
54  ax.set_xlabel(xlabel)
55  ax.set_ylabel(ylabel)
56  ax.set_title(title)
57  ax.axis('equal')
58  plt.subplots_adjust(wspace=0.4, hspace=0.4)
59  plt.show()
60 
61 def main():
62  if len(sys.argv) <= 1:
63  help()
64  exit()
65  f = h5py.File(sys.argv[1], 'r')
66  elist = ['event_{}'.format(index) for index in sys.argv[2:]] \
67  if len(sys.argv)>=3 else list(f.keys())
68  for eid in elist:
69  plot(f[eid])
70 
71 if __name__ == '__main__':
72  main()