smiet.corsika package

class smiet.corsika.OriginLibraryGenerator(sim_primary: str = 'proton', sim_energy: float = 1e+17, atm_model: int = 17, site: str = 'lofar')

Bases: object

corsika_exec_hadr_label : dict = {'qgsjetII': 'QGSII', 'sibyll': 'SIBYLL'}

Class to generate the origin shower library using CORSIKA simulations.

generate_single_shower(sim_zenith: float, sim_xmax: float, n_nodes: int = 2, n_cores_per_node: int = 76, vxvxB: bool = True, sim_dir='./', sim_nr: int = 999999) str

Generate a single origin shower simulation. This is useful for testing and debugging purposes.

Parameters:
sim_zenith : float

Zenith angle in degrees.

sim_xmax : float

Xmax value in g/cm^2. n_nodes : int

Number of nodes to use for each simulation (default is 2).

n_cores_per_node : int

Number of cores per node (default is 76).

vxvxB : bool

Whether to only generate showers on the vxvxB axis or not. Default is True. Otherwise, a rotate starshape is used.

sim_dir : str

Directory where the simulation will be set up.

sim_nr : int, default=999999

Simulation number to use for the shower.

generate_submit_files(zenith_angles: tuple = (0, 63, 3), xmax_values: tuple = (600, 1300, 100), n_sims: int = 3, n_nodes: int = 2, n_cores_per_node: int = 76, vxvxB: bool = True) list

Generate steering files for CORSIKA simulations.

Parameters:
zenith_angles : tuple

Tuple specifying (min, max, step) for zenith angles in degrees. NOte that max should be less than 60 degrees, and include the step.

xmax_values : tuple

Tuple specifying (min, max, step) for Xmax values in g/cm^2. NOte that max should include the step.

n_sims : int, default=3

The number of times to repeat each simulation (default is 3). This is to ensure that we have enough statistics.

n_nodes : int

Number of nodes to use for each simulation (default is 2).

n_cores_per_node : int

Number of cores per node (default is 76).

vxvxB : bool

Whether to only generate showers on the vxvxB axis or not. Default is True. Otherwise, a rotated starshape is used.

Returns:

List of directories where simulations are set up.

Return type:

list

modify_input_file(inp_file: list, direct: str) list

Modify the input file to include direct and datdir commands.

Parameters:
inp_file : list

List of strings representing the lines of the input file.

Returns:

Modified list of strings for the input file.

Return type:

list

setup_paths(corsika_runner_path: str, run_dir: str, cluster_type: str = 'horeka', hadr_model: str = 'sibyll') None

Configure the paths for CORSIKA runner and run directory.

Parameters:
corsika_runner_path : str

Path to the CORSIKA runner executable.

run_dir : str

Directory where the CORSIKA simulations will be run and saved.

cluster_type : str, default="horeka"

Type of cluster that the jobs are submitted into.

The submit scripts should be placed in the submit_templates directory, with the naming scheme submit_{cluster_type}.sh.

Currently only “horeka” is supported.

hadr_model : str, default="sibyll"

Hadronic interaction model used for the fitting functions. Currently only “sibyll” and “qgsjetII” are supported.

submit_jobs(sim_rundirs: list) None

Submit the generated jobs to the SLURM scheduler.

Parameters:
sim_rundirs : list

List of directories where simulations are set up.

smiet.corsika.generate_simulation(sim_nr, sim_primary, sim_cores, sim_zenith=None, sim_azimuth=None, sim_energy=None, sim_xmax=None, slice_gram=5.0, magnetic_field='lofar', thinning=1e-07, atmosphere=17, core=None, radii=None, nr_of_arms=1, cherenkov=False, rotate: bool = False)

Prepare the contents for the INP, LIST and REAS files for a sliced MPI simulation, with a star shape pattern for the antenna layout.

One can choose to project the antennas along the shower axis or along the viewing angle by setting the cherenkov option. If this is set to True, the radii parameter will be interpreted as a list of viewing angles expressed as multiples of the slice Cherenkov angle. Otherwise, the radii parameter should be the list of radii to use in the star shape (use this option to generate origin showers).

The magnetic field vector can be taken from the radiotools.helper module, by passing a string as the magnetic_field parameter. This variable is passed on to the radiotools.helper.get_magnetic_field_vector function. But to be consistent with the CORSIKA definition where the magnetic field has no East-West component, the vector x-component is set to zero. This ensures the simulated antennas are indeed on the (vx)vxB axis.

The primary particle can be specified as a string, which will be converted to the corresponding CORSIKA particle code. As of June 2025, only proton, helium, carbon, silicon and iron primaries are supported (this is limited by the CORSIKA_PARTICLE_CODES dictionary).

Parameters:
sim_nr : int

The number of the simulation.

sim_primary : {'proton', 'helium', 'carbon', 'silicon', 'iron'}

The primary particle to inject

sim_cores : int

The number of cores the simulation will be run on

sim_zenith : float, optional

The zenith angle in degrees. If not provided, the angle will be drawn from sample_zenith_angle.

sim_azimuth : float, optional

The azimuth angle in degrees. If not provided, the angle will be drawn from sample_azimuth_angle.

sim_energy : float, optional

The energy of the simulation in GeV. If not provided, the energy will be drawn from sample_primary_energy.

sim_xmax : float, optional

The depth of shower maximum in g/cm^2. If provided, this value (along with sim_energy and sim_zenith) will be used to compute the first interaction height of the shower, using the parameterisation from CONEX. This value will be passed in the FIXHEI parameter in the CORSIKA input file.

core : list of float, default=[0, 0, 0] * units.m

The core to use in the simulation

slice_gram : float, default=5.0

The thickness of the atmospheric slices. NB: DO NOT put in internal units. We default the units to be g/cm^2.

radii : list of float, default=None

The radii of the starshape, passed to smiet.corsika.generate_list_file

nr_of_arms : int, default=1

The number of arms in the star shape pattern. This is passed to smiet.corsika.generate_list_file.

cherenkov : bool, default=False

If True, interpret radii as multiples of slice Cherenkov radius, and calculate antenna radii per slice

magnetic_field : np.ndarray or str, default='lofar'

If a string, the name of the site from which to take the magnetic field vector (using radiotools.helper). Otherwise, this is interpreted as the magnetic field vector (in internal units).

thinning : float, default=1e-7

The thinning level to use

atmosphere : int or str, default=17

The CORSIKA atmosphere identifier. If a string, the path to the GDAS atmosphere file.

rotate : bool, default=False

Whether to rotate the antenna positions in the LIST file by 22.5 degrees so that the do not align with the vxB axis, which we know fails with template synthesis.

smiet.corsika.generate_simulation_from_hdf5(base_sim_file: str, sim_nr: int, sim_cores: int, sim_primary: str | int | None = None, sim_energy: float | None = None, slice_gram: float = 5.0, atm_file: str | None = None)

Generate simulation files for an origin shower from an existing coreas simulation.

The geometry, primary particle type and energy are taken from the base_sim_file simulation, as well as the observation level, magnetic field and thinning level. If there is no GDAS atmosphere file provided, the atmosphere model number is also taken from the base_sim_file.

Parameters:
base_sim_file : str

Path to the HDF5 simulation file on which we base the new simulation.

sim_nr : int

The number of the new simulation.

sim_cores : int

The number of cores the simulation will be run on

sim_primary : str or int, default=None

If provided, the primary particle type to use in the new simulation. If a string, the type is converted to the CORSIKA identification code using CORSIKA_PARTICLE_CODES dictionary. In this case the particle needs to be supported (see the documentation of generate_simulation()). Can also be an integer, in which case it is used as the CORSIKA particle code directly. If None, the primary particle type will be taken from the base_sim_file.

sim_energy : float, default=None

If provided, the primary energy to use in the new simulation. Otherwise, the energy will be taken from the base_sim_file.

slice_gram : float, default=5.0

The thickness of the atmospheric slices in g/cm^2. NB: DO NOT put in internal units. We default the units to be g/cm^2.

atm_file : str, default=None

The path to the GDAS atmosphere file. If None, the atmosphere model number from the base_sim_file will be used instead, and an atmosphere file will not be used.

smiet.corsika.sample_azimuth_angle(range=(0, 360), size=1)

Sample the azimuth angle within the given range, from a uniform distribution.

Parameters:
range : tuple, default=(0, 360)

The lower and upper azimuth angle in degrees

size : int, default=1

The number of angles to samples

Returns:

azimuth_angle – Sampled azimuth angles (in internal units), as an array of length size

Return type:

list of float

smiet.corsika.sample_primary_energy(exp_range=(8, 10), size=1)

Sample a single primary energy from log-uniform distribution, between the exponents given by exp_range. For example, using the default settings, calling this function will generate a value between \(10^{8}\) and \(10^{10}\) GeV.

Parameters:
exp_range : tuple, default=(8, 10)

The lower and upper exponent of the energy range in GeV to sample from

size : int, default=1

The number of energies to retrieve

Returns:

primary_energy – Primary energy (in internal units), as an array of length size

Return type:

list of float

smiet.corsika.sample_zenith_angle(range=(0, 90), size=1, uniformity='sin2')

Sample the zenith angle from some distribution normalised with the solid angle. The names of the distributions refer to the variable in which they are uniform.

Parameters:
range : tuple, default=(0, 90)

The lower and upper zenith angle in degrees (endpoints exclude

size : int, default=1

The number of angles to samples

uniformity : {'sin2', 'sin', 'cos'}

The distribution to use to sample the zenith angle

Returns:

zenith_angle – Sampled zenith angles (in internal units), as an array of length size

Return type:

list of float

Notes

The names of the distributions refer to the variable in which they are uniform, in the sense that if you sampled using ‘sin2’ (the default), the zenith angle distribution will look uniform if binned in \(sin^2(\theta)\).

smiet.corsika.write_simulation_to_file(inp_file, list_file, reas_file, sim_directory='./', reset=False)

Write the provided contents of the INP, LIST and REAS files for a single simulation to the files in a directory named after the simulation number.

The directory will be created in the sim_directory path, and will be named SIMXXXXXX, where the last six digits are the simulation number. This is retrieved from the INP file contents, as the first line of the file. The function will fail if the directory already exists, unless reset is set to True, in which case the directory will be removed and re-created.

Parameters:
inp_file : list

The contents of the INP file

list_file : list

The contents of the LIST file

reas_file : list

The contents of the REAS file

sim_directory : str, default='./'

The path to the directory where the simulation directory will be made, in which all files are written

reset : bool, default=False

whether to delete the simulation directory or not

Submodules