Warning, /JETSCAPE/external_packages/trento/doc/examples.rst is written in an unsupported language. File is not indexed.
0001 Examples
0002 ========
0003 Run a thousand lead-lead events using default settings and save the event data to file::
0004
0005 trento Pb Pb 1000 > PbPb.dat
0006
0007 Run proton-lead events with a larger cross section (for the higher beam energy) and also compress the output::
0008
0009 trento p Pb 1000 --cross-section 7.1 | gzip > pPb.dat.gz
0010
0011 Suppress printing to stdout and save events to HDF5::
0012
0013 trento p Pb 1000 --cross-section 7.1 --quiet --output events.hdf
0014
0015 Uranium-uranium events at RHIC (smaller cross section) using short options::
0016
0017 trento U U 1000 -x 4.2
0018
0019 Deformed gold-gold with an explicit nucleon width::
0020
0021 trento Au2 Au2 1000 -x 4.2 -w 0.6
0022
0023 Simple sorting and selection (e.g. by centrality) can be achieved by combining standard Unix tools.
0024 For example, this sorts by centrality (multiplicity) and selects the top 10%::
0025
0026 trento Pb Pb 1000 | sort -rgk 4 | head -n 100
0027
0028 Working with Python
0029 -------------------
0030 The `scientific Python stack <https://www.scipy.org>`_ is ideal for analyzing T\ :sub:`R`\ ENTo data.
0031
0032 One way to load event properties into Python is to save them to a text file and then read it with ``np.loadtxt``.
0033 Here's a nice trick to avoid the temporary file:
0034
0035 .. code:: python
0036
0037 import subprocess
0038 import numpy as np
0039
0040 with subprocess.Popen('trento Pb Pb 1000'.split(), stdout=subprocess.PIPE) as proc:
0041 data = np.array([l.split() for l in proc.stdout], dtype=float)
0042
0043 Now the ``data`` array contains the event properties.
0044 It can be sorted and selected using numpy indexing, for example to sort by centrality as before:
0045
0046 .. code:: python
0047
0048 data_sorted = data[data[:, 3].argsort()[::-1]]
0049 central = data_sorted[:100]
0050
0051 Text files are easily read by ``np.loadtxt``.
0052 The header will be ignored by default, so this is all it takes to read and plot a profile:
0053
0054 .. code:: python
0055
0056 import matplotlib.pyplot as plt
0057
0058 profile = np.loadtxt('events/0.dat')
0059 plt.imshow(profile, interpolation='none', cmap=plt.cm.Blues)
0060
0061 Reading HDF5 files requires `h5py <http://www.h5py.org>`_.
0062 ``h5py`` file objects have a dictionary-like interface where the keys are the event names (``event_0``, ``event_1``, ...) and the values are HDF5 datasets.
0063 Datasets can implicitly or explicitly convert to numpy arrays, and the ``attrs`` object provides access to the event properties.
0064 Simple example:
0065
0066 .. code:: python
0067
0068 import h5py
0069
0070 # open an HDF5 file for reading
0071 with h5py.File('events.hdf', 'r') as f:
0072 # get the first event from the file
0073 ev = f['event_0']
0074
0075 # plot the profile
0076 plt.imshow(ev, interpolation='none', cmap=plt.cm.Blues)
0077
0078 # extract the profile as a numpy array
0079 profile = np.array(ev)
0080
0081 # read event properties
0082 mult = ev.attrs['mult']
0083 e2 = ev.attrs['e2']
0084
0085 # sort by centrality
0086 sorted_events = sorted(f.values(), key=lambda x: x.attrs['mult'], reverse=True)