CORSIKA

Contents

CORSIKA#

Support modules for running CORSIKA.

corsika_config#

CORSIKA configuration.

class corsika.corsika_config.CorsikaConfig(array_model, args_dict, db_config=None, label=None)[source]#

Configuration for the CORSIKA air shower simulation software.

Follows closely the CORSIKA definitions and output format (see CORSIKA manual).

The configuration is set as a dict corresponding to the command line configuration groups (especially simulation_software, simulation configuration, simulation parameters).

Parameters:
array_modelArrayModel

Array model.

args_dictdict

Configuration dictionary.

db_configdict

MongoDB configuration.

labelstr

Instance label.

fill_corsika_configuration(args_dict, db_config=None)[source]#

Fill CORSIKA configuration.

Dictionary keys are CORSIKA parameter names. Values are converted to CORSIKA-consistent units.

Parameters:
args_dictdict

Configuration dictionary.

db_config: dict

Database configuration.

Returns:
dict

Dictionary with CORSIKA parameters.

generate_corsika_input_file(use_multipipe=False, use_test_seeds=False)[source]#

Generate a CORSIKA input file.

Parameters:
use_multipipe: bool

Whether to set the CORSIKA Inputs file to pipe the output directly to sim_telarray.

get_config_parameter(par_name)[source]#

Get value of CORSIKA configuration parameter.

Parameters:
par_name: str

Name of the parameter as used in the CORSIKA input file (e.g. PRMPAR, THETAP …).

Returns:
list

Value(s) of the parameter.

Raises:
KeyError

When par_name is not a valid parameter name.

get_corsika_config_file_name(file_type, run_number=None)[source]#

Get a CORSIKA config style file name for various configuration file types.

Parameters:
file_type: str

The type of file (determines the file suffix). Choices are config_tmp, config or output_generic.

run_number: int

Run number.

Returns:
str
for file_type=”config_tmp”:

Return CORSIKA input file name for one specific run. This is the input file after being pre-processed by sim_telarray (pfp).

for file_type=”config”:

Return generic CORSIKA config input file name.

for file_type=”output_generic”

Return generic file name for the TELFIL option in the CORSIKA inputs file.

for file_type=”multipipe”

Return multipipe “file name” for the TELFIL option in the CORSIKA inputs file.

Raises:
ValueError

If file_type is unknown or if the run number is not given for file_type==config_tmp.

get_corsika_telescope_list()[source]#

List of telescope positions in the format required for the CORSIKA input file.

Returns:
str

Piece of text to be added to the CORSIKA input file.

property primary#

Primary particle name.

property primary_particle#

Primary particle.

print_config_parameter()[source]#

Print CORSIKA config parameters for inspection.

property run_number#

Set run number.

set_output_file_and_directory(use_multipipe=False)[source]#

Set output file names and directories.

Parameters:
use_multipipe: bool

Whether to set the CORSIKA Inputs file to pipe the output directly to sim_telarray. Defines directory names.

Returns:
str

Output file name.

validate_run_number(run_number)[source]#

Validate run number and return it.

Return run number from configuration if None.

Parameters:
run_number: int

Run number.

Returns:
int

Run number.

Raises:
ValueError

If run_number is not a valid value (e.g., < 1).

exception corsika.corsika_config.InvalidCorsikaInputError[source]#

Exception for invalid corsika input.

primary_particle#

Primary particle definition.

class corsika.primary_particle.PrimaryParticle(particle_id_type=None, particle_id=None)[source]#

Primary particle definition using CORSIKA7 or PDG ID.

Uses a dictionary to map particle common names to CORSIKA7 IDs. Particles not found in the dictionary are searched in the PDG particle database.

Parameters:
particle_id_typestr

Type of the primary particle ID (‘corsika7_id’, ‘common_name’, or ‘pdg_id’).

particle_idint or str

The actual ID of the primary particle.

property corsika7_id#

CORSIKA7 ID of the primary particle.

property name#

Common name of the primary particle.

static particle_names()[source]#

Primary particles including common names, CORSIKA7 IDs, and PDG IDs.

Returns:
dict

Dictionary of particle names, CORSIKA7 IDs, and PDG IDs.

property pdg_id#

PDG ID of the primary particle.

property pdg_name#

PDG name of the primary particle.

corsika_histograms#

Extract Cherenkov photons information from a CORSIKA IACT file.

class corsika.corsika_histograms.CorsikaHistograms(input_file, label=None, output_path=None, hdf5_file_name=None)[source]#

Extracts the Cherenkov photons information from a CORSIKA IACT file.

Parameters:
input_file: str or Path

CORSIKA IACT file provided by the CORSIKA simulation.

label: str

Instance label.

output_path: str

Path where to save the output of the class methods.

hdf5_file_name: str

HDF5 file name for histogram storage.

Raises:
FileNotFoundError:

if the input file given does not exist.

property corsika_version#

Get the version of the CORSIKA IACT file.

Returns:
float:

The version of CORSIKA used to produce the CORSIKA IACT file given by self.input_file.

property dict_1d_distributions#

Dictionary to label the 1D distributions according to the class methods.

Returns:
dict:

The dictionary with information about the 1D distributions.

property dict_2d_distributions#

Dictionary to label the 2D distributions according to the class methods.

Returns:
dict:

The dictionary with information about the 2D distributions.

event_1d_histogram(key, bins=50, hist_range=None)[source]#

Create a histogram for the all events using key as parameter.

Valid keys are stored in self.all_event_keys (CORSIKA defined).

Parameters:
key: str

The information from which to build the histogram, e.g. total_energy, zenith or first_interaction_height.

bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

Edges of the histogram.

Raises:
KeyError:

If key is not valid.

event_2d_histogram(key_1, key_2, bins=50, hist_range=None)[source]#

Create a 2D histogram for the all events using key_1 and key_2 as parameters.

Valid keys are stored in self.all_event_keys (CORSIKA defined).

Parameters:
key_1: str

The information from which to build the histogram, e.g. total_energy, zenith or first_interaction_height.

key_2: str

The information from which to build the histogram, e.g. total_energy, zenith or first_interaction_height.

bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

x Edges of the histogram.

numpy.array

y Edges of the histogram.

Raises:
KeyError:

If at least one of the keys is not valid.

property event_azimuth_angles#

Get the azimuth angles of the simulated events in astropy units of degrees.

Returns:
astropy.Quantity

The azimuth angles for each event, usually in degrees.

property event_energies#

Get the energy of the simulated events in astropy units of TeV.

Returns:
astropy.Quantity

The total energies of the incoming particles for each event, usually in TeV.

property event_first_interaction_heights#

Get the height of the first interaction in astropy units of km.

If negative, tracking starts at margin of atmosphere, see TSTART in the CORSIKA 7 user guide.

Returns:
astropy.Quantity

The first interaction height for each event, usually in km.

property event_zenith_angles#

Get the zenith angles of the simulated events in astropy units of degrees.

Returns:
astropy.Quantity

The zenith angles for each event.

export_event_header_1d_histogram(event_header_element, bins=50, hist_range=None, overwrite=False)[source]#

Export ‘event_header_element’ from CORSIKA to hd5 for a 1D histogram.

Parameters:
event_header_element: str

The key to the CORSIKA event header element. Possible choices are stored in ‘self.all_event_keys’.

bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

overwrite: bool

If True overwrites the histograms already saved in the hdf5 file.

export_event_header_2d_histogram(event_header_element_1, event_header_element_2, bins=50, hist_range=None, overwrite=False)[source]#

Export event_header of a 2D histogram to a hdf5 file.

Searches the 2D histogram for the key ‘event_header_element_1’ and ‘event_header_element_2’from the CORSIKA event header.

Parameters:
event_header_element_1: str

The key to the CORSIKA event header element.

event_header_element_2: str

The key to the CORSIKA event header element. Possible choices for ‘event_header_element_1’ and ‘event_header_element_2’ are stored in ‘self.all_event_keys’.

bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

overwrite: bool

If True overwrites the histograms already saved in the hdf5 file.

export_histograms(overwrite=False)[source]#

Export the histograms to hdf5 files.

Parameters:
overwrite: bool

If True overwrites the histograms already saved in the hdf5 file.

get_2d_num_photons_distr()[source]#

Get the distribution of Cherenkov photons per event per telescope.

It returns the 2D array accounting for the events from the telescopes given by self.telescope_indices.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

An array that counts the telescopes in self.telescope_indices

numpy.array

Number of photons per event per telescope in self.telescope_indices.

get_2d_photon_density_distr()[source]#

Get 2D histograms of position of the Cherenkov photons on the ground.

It returns the photon density per square meter.

Returns:
numpy.ndarray

The values of the histogram, usually in $m^{-2}$

numpy.array

The x bin edges of the density/count histograms in x, usually in meters.

numpy.array

The y bin edges of the density/count histograms in y, usually in meters.

get_2d_photon_direction_distr()[source]#

Get 2D histograms of incoming direction of the Cherenkov photons on the ground.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

The x bin edges of the direction histograms in cos(x).

numpy.array

The y bin edges of the direction histograms in cos(y)

get_2d_photon_position_distr()[source]#

Get 2D histograms of position of the Cherenkov photons on the ground.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

The x bin edges of the count histograms in x, usually in meters.

numpy.array

The y bin edges of the count histograms in y, usually in meters.

get_2d_photon_time_altitude_distr()[source]#

Get 2D histograms of the time and altitude of the photon production.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

The x bin edges of the time_altitude histograms, usually in ns.

numpy.array

The y bin edges of the time_altitude histograms, usually in km.

get_event_parameter_info(parameter)[source]#

Get specific information (i.e. any parameter) of the events.

The parameter is passed through the key word parameter. Available options are to be found under self.all_event_keys. The unit of the parameter, if any, is given according to the CORSIKA version (please see user guide in this case).

Parameters:
parameter: str

The parameter of interest. Available options are to be found under self.all_event_keys.

Returns:
astropy.Quantity

The array with the event information as required by the parameter.

Raises:
KeyError:

If parameter is not valid.

get_num_photons_per_event_distr(bins=50, hist_range=None)[source]#

Get the distribution of photons per event.

Parameters:
bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

Number of photons per event.

get_num_photons_per_telescope_distr(bins=50, hist_range=None)[source]#

Get the distribution of photons per telescope.

Parameters:
bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

Number of photons per telescope.

get_photon_altitude_distr()[source]#

Get the emission altitude of the Cherenkov photons.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

The bin edges of the photon altitude histograms in km.

get_photon_density_distr(bins=None, max_dist=None)[source]#

Get the photon density distribution on the ground in relation to the center of the array.

Parameters:
bins: float

Number of bins of the radial distribution.

max_dist: float

Maximum distance to consider in the 1D histogram (in meters).

Returns:
np.array

The density distribution of the 1D histogram with size = int(max_dist/bin_size), usually in $m^{-2}$.

np.array

The bin edges of the 1D histogram in meters with size = int(max_dist/bin_size) + 1, usually in meter.

get_photon_radial_distr(bins=None, max_dist=None)[source]#

Get the phton radial distribution on the ground in relation to the center of the array.

Parameters:
bins: float

Number of bins of the radial distribution.

max_dist: float

Maximum distance to consider in the 1D histogram (in meters).

Returns:
np.array

The counts of the 1D histogram with size = int(max_dist/bin_size).

np.array

The bin edges of the 1D histogram in meters with size = int(max_dist/bin_size) + 1, usually in meter.

get_photon_time_of_emission_distr()[source]#

Get the distribution of the emitted time of the Cherenkov photons.

The clock starts when the particle crosses the top of the atmosphere (CORSIKA-defined) if self.event_first_interaction_heights is positive or at first interaction if otherwise.

Returns:
numpy.ndarray

The counts of the histogram.

numpy.array

The bin edges of the time histograms in ns.

get_photon_wavelength_distr()[source]#

Get histograms with the wavelengths of the photon bunches.

Returns:
np.array

The counts of the wavelength histogram.

np.array

The bin edges of the wavelength histogram in nanometers.

get_run_info(parameter)[source]#

Get specific information (i.e. any parameter) of the run.

The parameter is passed through the key word parameter. Available options are to be found under self.all_run_keys. The unit of the parameter, if any, is given according to the CORSIKA version (please see user guide in this case).

Parameters:
parameter: str

The parameter of interest. Available options are to be found under self.all_run_keys.

Raises:
KeyError:

If parameter is not valid.

property hdf5_file_name#

Property for the hdf5 file name.

The idea of this property is to allow setting (or changing) the name of the hdf5 file even after creating the class instance.

property header#

Get the run header.

Returns:
dict:

The run header.

property hist_config#

The configuration of the histograms.

Returns:
dict:

the dictionary with the histogram configuration.

hist_config_to_yaml(file_name=None)[source]#

Save the histogram configuration dictionary to a yaml file.

Parameters:
file_name: str

Name of the output file, in which to save the histogram configuration.

property individual_telescopes#

Return the individual telescopes as property.

property magnetic_field#

Get the Earth magnetic field from the events header in astropy units of microT.

A tuple with Earth’s magnetic field in the x and z directions are returned.

Returns:
astropy.Quantity

The Earth magnetic field in the x direction used for each event.

astropy.Quantity

The Earth magnetic field in the z direction used for each event.

property num_photons_per_event#

Get the the number of photons per events.

Includes the telescopes indicated by self.telescope_indices.

Returns:
numpy.array

Number of photons per event.

property num_photons_per_event_per_telescope#

The number of photons per event per telescope.

property num_photons_per_telescope#

The number of photons per event, considering the telescopes given by self.telescope_indices.

Returns:
numpy.array

Number of photons per telescope.

read_event_information()[source]#

Read the information about the events from their headers and save as a class instance.

The main information can also be fetched individually through the functions below. For the remaining information (such as px, py, pz), use this function.

set_histograms(telescope_indices=None, individual_telescopes=None, hist_config=None)[source]#

Create and fill Cherenkov photons histograms using information from the CORSIKA IACT file.

Parameters:
telescope_indices: int or list of int

The indices of the specific telescopes to be inspected.

individual_telescopes: bool

if False, the histograms are supposed to be filled for all telescopes. Default is False. if True, one histogram is set for each telescope separately.

hist_config:

yaml file with the configuration parameters to create the histograms. For the correct format, please look at the docstring of _create_histogram_default_config. Alternatively, it can be a dictionary with the configuration parameters to create the histograms.

Returns:
list: list of boost_histogram.Histogram instances.
Raises:
AttributeError:

if event has not photon saved.

property telescope_indices#

The telescope index (or indices), which are considered for the production of the histograms.

Returns:
list:

The indices of the telescopes of interest.

property telescope_positions#

The telescope positions found in the CORSIKA output file.

It does not depend on the telescope_indices attribute.

Returns:
numpy.ndarray

x, y and z positions of the telescopes and their radius according to the CORSIKA spherical representation of the telescopes.

property total_num_photons#

The total number of photons.

Returns:
float

Total number photons.

exception corsika.corsika_histograms.HistogramNotCreatedError[source]#

Exception for histogram not created.

corsika_histograms_visualize#

Visualize Cherenkov photon distributions from CORSIKA.

corsika.corsika_histograms_visualize.plot_1d_event_header_distribution(histograms_instance, event_header_element, log_y=True, bins=50, hist_range=None)[source]#

Plot the distribution of the quantity given by .

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

event_header_element: str

The key to the CORSIKA event header element.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_2d_counts(histograms_instance, log_z=True)[source]#

Plot the 2D histogram of the photon positions on the ground.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_z: bool

if True, the intensity of the color bar is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_2d_density(histograms_instance, log_z=True)[source]#

Plot the 2D histogram of the photon density distribution on the ground.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_z: bool

if True, the intensity of the color bar is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_2d_direction(histograms_instance, log_z=True)[source]#

Plot the 2D histogram of the incoming direction of photons.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_z: bool

if True, the intensity of the color bar is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_2d_event_header_distribution(histograms_instance, event_header_element_1, event_header_element_2, log_z=True, bins=50, hist_range=None)[source]#

Plot the distribution of the quantity given by CorsikaHistograms.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

event_header_element_1: str

The first key to the CORSIKA event header element

event_header_element_2: str

The second key to the CORSIKA event header element.

log_z: bool

if True, the intensity of the Y axis is given in logarithmic scale.

bins: float

Number of bins for the histogram.

hist_range: 2-tuple

Tuple to define the range of the histogram.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_2d_num_photons_per_telescope(histograms_instance, log_z=True)[source]#

Plot the 2D histogram of the number of photons per event and per telescope.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_z: bool

if True, the intensity of the color bar is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_2d_time_altitude(histograms_instance, log_z=True)[source]#

Plot the 2D histogram of the time and altitude where the photon was produced.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_z: bool

if True, the intensity of the color bar is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_altitude_distr(histograms_instance, log_y=True)[source]#

Plot the distribution of altitude in which the photons were generated in km.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_counts_distr(histograms_instance, log_y=True)[source]#

Plot the 1D distribution, i.e. the radial distribution, of the photons on the ground.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_density_distr(histograms_instance, log_y=True)[source]#

Plot the photon density distribution on the ground.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_photon_per_event_distr(histograms_instance, log_y=True)[source]#

Plot the distribution of the number of Cherenkov photons per event.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_photon_per_telescope_distr(histograms_instance, log_y=True)[source]#

Plot the distribution of the number of Cherenkov photons per telescope.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_time_distr(histograms_instance, log_y=True)[source]#

Plot the distribution times in which the photons were generated in ns.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.plot_wavelength_distr(histograms_instance, log_y=True)[source]#

Plot the 1D distribution of the photon wavelengths.

Parameters:
histograms_instance: corsika.corsika_histograms.CorsikaHistograms

instance of corsika.corsika_histograms.CorsikaHistograms.

log_y: bool

if True, the intensity of the Y axis is given in logarithmic scale.

Returns:
list

List of figures for the given telescopes.

corsika.corsika_histograms_visualize.save_figs_to_pdf(figs, pdf_file_name)[source]#

Save figures from corsika histograms to an output pdf file.

Parameters:
figs: list or numpy.array

List with the figures output by corsika_output_visualize.py.

pdf_file_name: str or Path

Name of the pdf file.