CORSIKA Reader

Read CORSIKA data files.

This provides functionality to read CORSIKA output files with Python. It provides the following main classes:

  • CorsikaFile: The file class provides a generator over all events in the file.
  • CorsikaEvent: The event class that provides a generator over all particles at ground.

and the following classes that correspond to the sub-blocks defined in the CORSIKA manual:

Additionally version for thinned showers are available:

Issues

This module does not handle platform dependent issues such as byte ordering (endianness) and field size. This was the result of an afternoon hack and has only been tested with files generated using 32 bit CORSIKA files on a linux system compiled with gfortran.

  • Field Size: According to the CORSIKA user manual section 10.2 all quantities are written as single precision real numbers independently of 32-bit or 64-bit, so each field in the file should be 4 bytes long.
  • Endianness: There is no check for byte ordering. It can be added using Python’s struct module.
  • Special Particles: This module currently ignores all special (book-keeping) particles like for muon additional information and history.

More Info

For short information on fortran unformatted binary files, take a look at http://paulbourke.net/dataformats/reading/

For detailed information on the CORSIKA format, check the ‘Outputs’ chapter in the CORSIKA user manual. In particular, check the ‘Normal Particle Output’ section.

Authors

class sapphire.corsika.reader.CorsikaEvent(raw_file, header_index, end_index)

CorsikaEvent constructor

The user never calls this. The CorsikaFile does.

Parameters:
  • raw_fileCorsikaFile object.
  • header_index – index where the event header starts.
  • end_index – index where the event end starts.
get_header()

Get the Event Header

Returns:an instance of EventHeader
get_end()

Get the Event end sub-block

Returns:an instance of EventEnd
get_particles()

Generator over particles in the event.

Note

This generator filters out additional muon information and all particles at observation levels other than 1.

Use like this:

for particle in event.get_particles():
    pass
Yield:each particle in the event
class sapphire.corsika.reader.CorsikaFile(filename)

CORSIKA output file handler

This class will probide an interface for CORSIKA output files. Allowing you go get at the events and particles in the file. This class is meant for unthinned simulations.

CorsikaFile constructor

Param:the filemame of the CORSIKA data file
finish()

Close the opened CORSIKA data file

check()

Check DAT file format

Some basic sanity checks.

Fortran unformatted files are written in ‘blocks’. Each block has a header and end. They both contain the same information: the number of bytes in the block.

This function only checks if there is an integer number of blocks in the file and if the header and end are equal.

Here would be the place to dynamically check for endiannes and field size.

get_sub_blocks()

Get the sub-blocks in the file.

Normally one would not need this function but it is here because I have used it.

get_header()

Get the Run header

Returns:an instance of RunHeader
get_end()

Get the Run end

Returns:an instance of RunEnd
get_events()

Generator over the Events in the file

This method is a generator over the events in the file. Use it like this:

for event in my_file.get_events():
    pass
class sapphire.corsika.reader.CorsikaFileThin(filename)

CORSIKA thinned output file handler

Same as the unthinned output handler, but with support for the different format, particles also have the weight property. This class is meant for thinned simulations.

CorsikaFileThin constructor

It takes a filename as argument