radiasoft / rssynergia

Tools for Synergia
Other
2 stars 4 forks source link

foo.h5 contents for 8-2 IOTA Notebook? #3

Closed sszustkowski closed 6 years ago

sszustkowski commented 7 years ago

I have noticed when I run the 8-2 IOTA example notebook, I see particles_000#.h5 being created in the directory. What is contained in the foo.h5 extension files? Since I would like to create a Poincare section for a macro particle, or even a single particle of n turns as an exercise for myself. -Sebastian

ncook882 commented 7 years ago

Hi Sebastian. The particles files are created using Synergia's native diagnostics. Specifically, a call such as the following can be used to add particle diagnostics to the simulation.

opts.turnsPerDiag = 1 particlediag = synergia.bunch.Diagnostics_particles("particles.h5",0,0,opts.output_dir) bunch_simulator.add_per_turn(particlediag, opts.turnsPerDiag)

After each turn, particle data is dumped into the particles_000#.h5 file as you noted. A helpful exercise may be to open the .h5 file within IPython using tables and to explore the organization. This can be done as follows:

f = tables.open_file(inputfile, 'r')

Generally speaking, the .h5 file is organized heirarchically into a set of groups and datasets. For particles files, the 'root group' provides top level access to datasets and global attributes. In the case of the particles files, there are 7 available datasets, accessible through root:

  1. f.root.particles - dataset containing the array of particle coordinates in the format [x,px,y,py,z,pz,ID#]
  2. f.root.mass - reference particle mass in GeV
  3. `f.root.charge1 - reference particle charge in units of elementary charge
  4. f.root.pz - reference particle momentum in GeV/c
  5. f.root.s_n - s coordinate of the reference particle - ranges from 0 to the lattice length in m
  6. f.root.rep - how many repetitions the particle has travelled through the lattice
  7. f.root.tlen - cumulative tracked length in m (equal to f.root.rep[()]*lattice_length +f.root.s_n[()])

To access the corresponding values for these datasets, you can use either the command f.root.mass.read() to grab all particles or a more generic array indexing f.root.particles[(i)] to get information for the i-th particle.

With regards to constructing your own .h5 files by hand, I would recommend you first check out either the tables documentation or the h5py documentation to familiarize yourself with the two most prominent Python packages for HDF5 manipulation. So long as you construct a .h5 file with the appropriate datasets as documented above, you should have no problem using the rssynergia tools to manipulate the file.

Alternatively, you could use Synergia's bunch constructor to create a bunch that's been matched to a specific lattice (see for example this brief Synergia tutorial).

There are various ways to construct bunch objects in Synergia, so this list is certainly non-exhaustive. Let me know if you have other questions.