CORSIKA#

Support modules for running CORSIKA.

build_options#

Read and validate CORSIKA build variants.

class corsika.build_options.CorsikaBuildVariant(executable, config, atmosphere_geometry, he_hadronic_model, le_hadronic_model, hadronic_transition_energy_default_gev=None)[source]#

One executable variant declared by a CORSIKA build.

classmethod from_mapping(entry)[source]#

Create a variant from a build-options mapping.

Parameters:
entrydict

One entry from the variant list in build_opts.yml.

Returns:
CorsikaBuildVariant

Validated and normalized variant.

Raises:
ValueError

If a required field is missing or invalid.

corsika.build_options.format_corsika_build_variants(variants)[source]#

Format installed CORSIKA build variants as a compact table.

Parameters:
variantsiterable of CorsikaBuildVariant

Available variants.

Returns:
str

Human-readable table.

corsika.build_options.get_corsika_build_report(corsika_path=None)[source]#

Return a report of installed CORSIKA interaction-model variants.

Parameters:
corsika_pathstr or Path, optional

CORSIKA installation directory. If omitted, use SIMTOOLS_CORSIKA_PATH and then the simtools default path.

Returns:
str

Human-readable table of installed variants.

Raises:
FileNotFoundError

If the build manifest is missing.

PermissionError

If a declared executable is not executable.

ValueError

If the manifest is invalid or declares a missing executable.

corsika.build_options.get_installed_corsika_build_variants(corsika_path)[source]#

Return build variants whose declared executables are installed.

Parameters:
corsika_pathstr or Path

CORSIKA installation directory.

Returns:
tuple of CorsikaBuildVariant

Validated installed variants.

Raises:
FileNotFoundError

If the manifest is missing.

ValueError

If the manifest declares a missing executable.

PermissionError

If a declared executable is not executable.

corsika.build_options.read_corsika_build_variants(corsika_path)[source]#

Read CORSIKA executable variants from build_opts.yml.

Parameters:
corsika_pathstr or Path

CORSIKA installation directory.

Returns:
tuple of CorsikaBuildVariant

Installed executable variants.

Raises:
FileNotFoundError

If the build-options file is unavailable.

ValueError

If the file is malformed, contains no variants, or declares duplicates.

corsika.build_options.select_corsika_build_variant(variants, he_model, le_model, geometry)[source]#

Select one CORSIKA build variant.

Parameters:
variantsiterable of CorsikaBuildVariant

Available variants.

he_modelstr

High-energy hadronic interaction model.

le_modelstr

Low-energy hadronic interaction model.

geometrystr

Atmosphere geometry (flat or curved).

Returns:
CorsikaBuildVariant

The unique matching variant.

Raises:
ValueError

If the requested combination is unavailable.

input_writer#

Serialize model parameter values for CORSIKA input cards.

corsika.input_writer.format_parameter(parameter_name, value, unit=None)[source]#

Format a value using the CORSIKA format declared in its parameter schema.

corsika.input_writer.format_value(value, format_name, unit=None)[source]#

Format a value using a schema-declared CORSIKA input format.

corsika_config#

CORSIKA configuration.

class corsika.corsika_config.CorsikaConfig(array_model, run_number, label=None, context=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.

run_numberint

Run number.

labelstr

Instance label.

assert_corsika_configurations_match(model_versions)[source]#

Assert that CORSIKA configurations match across all model versions.

Parameters:
model_versionslist

List of model versions to check.

Raises:
InvalidCorsikaInputError

If CORSIKA parameters are not identical across all model versions.

generate_corsika_input_file(use_multipipe, input_file, output_file)[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.

input_file: Path

Path to the input file to be generated.

output_file: Path

Path to the output file to be generated.

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_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.

is_calibration_run()[source]#

Check if this simulation is a calibration run.

Returns:
bool

True if it is a calibration run, False otherwise.

property primary_particle#

Primary particle.

property simulation_parameters#

Return physical run settings without CORSIKA steering cards.

property use_curved_atmosphere#

Check if zenith angle condition for curved atmosphere usage for CORSIKA is met.

corsika.corsika_config.get_site_config_parameters(site_model, model_directory=None)[source]#

Translate site quantities into CORSIKA7 configuration parameters.

Parameters:
site_modelSiteModel

Resolved site model with atmosphere and geomagnetic field.

model_directorypathlib.Path, optional

Directory containing the atmospheric profile.

Returns:
dict

Native CORSIKA7 site configuration.

primary_particle#

Primary particle definition.

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

Primary particle definition using CORSIKA7, eventio, 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.

classmethod available_particle_names()[source]#

Return sorted primary-particle common names.

property corsika7_id#

CORSIKA7 ID of the primary particle.

property eventio_id#

EventIO ID of the primary particle.

0 (gamma), 1(e-), 2(mu-), 100*A+Z for nucleons and nuclei, negative for antimatter.

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 from a CORSIKA IACT file and fill histograms.

class corsika.corsika_histograms.CorsikaHistograms(input_file, normalization_method='per-telescope', axis_distance=<Quantity 1000. m>)[source]#

Extract Cherenkov photons from a CORSIKA IACT file and fill histograms.

Parameters:
input_file: str or Path

CORSIKA IACT file.

axis_distance: astropy.units.Quantity or float

Distance from the axis to consider when calculating the lateral density profiles along x and y axes. If a float is given, it is assumed to be in meters.

Raises:
FileNotFoundError:

if the input file given does not exist.

fill()[source]#

Fill Cherenkov photons histograms.

get_hist_1d_projection(label, hist)[source]#

Get 1D distributions from event data or weighted histograms.

Parameters:
label: str

Histogram label.

hist: dict

Histogram dictionary.

Returns:
numpy.ndarray

Histogram counts.

numpy.array

Histogram x bin edges.

numpy.ndarray or None

Histogram uncertainties (if available).

get_hist_2d_projection(hist)[source]#

Get 2D distributions.

Parameters:
hist: histogram

Histogram with axes and a weighted or unweighted view.

Returns:
numpy.ndarray

Histogram counts.

numpy.array

Histogram x bin edges.

numpy.array

Histogram y bin edges.

numpy.ndarray or None

Histogram uncertainties (sqrt of variance) if available.