Production Configuration

Contents

Production Configuration#

Modules provide functionality to configure a simulation production. This includes the derivation of energy, viewcone radius, and core scatter ranges and the calculation of the number of events to be simulated given a pre-determined metric.

calculate_statistical_errors_grid_point#

Evaluate statistical uncertainties from DL2 MC event files.

class production_configuration.calculate_statistical_errors_grid_point.StatisticalErrorEvaluator(file_path: str, metrics: dict[str, float], grid_point: tuple[float, float, float, float, float] | None = None)[source]#

Evaluates statistical uncertainties from a DL2 MC event file.

Parameters:
file_pathstr

Path to the DL2 MC event file.

metricsdict, optional

Dictionary of metrics to evaluate. Default is None.

grid_pointtuple, optional

Tuple specifying the grid point (energy, azimuth, zenith, NSB, offset).

calculate_energy_estimate()[source]#

Calculate the uncertainties in energy estimation.

Returns:
float

The calculated uncertainty for energy estimation.

calculate_energy_threshold(requested_eff_area_fraction=0.1)[source]#

Calculate the energy threshold where the effective area exceeds 10% of its maximum value.

Returns:
float

Energy threshold value.

calculate_max_error_for_effective_area()[source]#

Calculate the maximum relative error for effective area.

Returns:
max_errorfloat

Maximum relative error.

calculate_metrics()[source]#

Calculate all defined metrics as specified in self.metrics and store results.

calculate_overall_metric(metric='average')[source]#

Calculate an overall metric for the statistical uncertainties.

Parameters:
metricstr

The metric to calculate (‘average’, ‘maximum’).

Returns:
dict

Dictionary with overall maximum errors for each metric.

calculate_uncertainty_effective_area()[source]#

Calculate the uncertainties on the effective collection area.

Returns:
errorsdict

Dictionary with uncertainties for the file.

compute_efficiency_and_errors(reconstructed_event_counts, simulated_event_counts)[source]#

Compute reconstructed event efficiency and its uncertainty assuming binomial distribution.

Parameters:
reconstructed_event_countsarray with units

Histogram counts of reconstructed events.

simulated_event_countsarray with units

Histogram counts of simulated events.

Returns:
efficienciesarray

Array of calculated efficiencies.

relative_errorsarray

Array of relative uncertainties.

compute_reconstructed_event_histogram(event_energies_reco, bin_edges)[source]#

Compute histogram of events as function of reconstructed energy.

Parameters:
event_energies_recoarray

Array of reconstructed energy per event.

bin_edgesarray

Array of energy bin edges.

Returns:
reconstructed_event_histogramarray

Histogram of reconstructed events.

create_bin_edges()[source]#

Create unique energy bin edges.

Returns:
bin_edgesarray

Array of unique energy bin edges.

load_data_from_file(file_path)[source]#

Load data from the DL2 MC event file and return dictionaries with units.

Returns:
dict

Dictionary containing data from the DL2 MC event file with units.

derive_corsika_limits#

Calculate CORSIKA thresholds for energy, radial distance, and viewcone.

class production_configuration.derive_corsika_limits.LimitCalculator(event_data_file, telescope_list=None)[source]#

Compute thresholds for CORSIKA configuration for energy, radial distance, and viewcone.

Event data is read from the reduced MC event data file.

Parameters:
event_data_filestr

Path to the HDF5 file containing the event data.

telescope_listlist, optional

List of telescope IDs to filter the events (default is None).

compute_lower_energy_limit(loss_fraction)[source]#

Compute the lower energy limit in TeV based on the event loss fraction.

Parameters:
loss_fractionfloat

Fraction of events to be lost.

Returns:
astropy.units.Quantity

Lower energy limit.

compute_upper_radial_distance(loss_fraction)[source]#

Compute the upper radial distance based on the event loss fraction.

Parameters:
loss_fractionfloat

Fraction of events to be lost.

Returns:
astropy.units.Quantity

Upper radial distance in m.

compute_viewcone(loss_fraction)[source]#

Compute the viewcone based on the event loss fraction.

The shower IDs of triggered events are used to create a mask for the azimuth and altitude of the triggered events. A mapping is created between the triggered events and the simulated events using the shower IDs.

Parameters:
loss_fractionfloat

Fraction of events to be lost.

Returns:
astropy.units.Quantity

Viewcone radius in degrees.

property core_distance_bins#

Return bins for the core distance histogram.

property energy_bins#

Return bins for the energy histogram.

plot_data(lower_energy_limit, upper_radial_distance, viewcone, output_path=None)[source]#

Plot the core distances and energies of triggered events.

Parameters:
lower_energy_limit: astropy.units.Quantity

Lower energy limit to display on plots.

upper_radial_distance: astropy.units.Quantity

Upper radial distance limit to display on plots.

viewcone: astropy.units.Quantity

Viewcone radius to display on plots.

output_path: Path or str, optional

Directory to save plots. If None, plots will be displayed.

property view_cone_bins#

Return bins for the viewcone histogram.

derive_production_statistics#

Calculate the event production statistics based on metrics.

Module for calculating the production event statistics based on statistical error metrics. Contains the ProductionStatisticsDerivator class, which derives the number of events for both the entire dataset and specific grid points. Event statistic is calculated using error metrics and the evaluator’s results.

class production_configuration.derive_production_statistics.ProductionStatisticsDerivator(evaluator, metrics: dict)[source]#

Derives the production statistics based on statistical error metrics.

Supports deriving statistics for both the entire dataset and specific grid points like energy values.

calculate_production_statistics_at_grid_point(grid_point: tuple) Quantity[source]#

Derive the production statistics for a specific energy grid point.

Parameters:
grid_pointtuple

The grid point specifying energy, azimuth, zenith, NSB, and offset.

Returns:
float

The derived production statistics at the specified grid point (energy).

derive_statistics(return_sum: bool = True) Quantity[source]#

Derive the production statistics based on statistical error metrics.

Parameters:
return_sumbool, optional

If True, returns the sum of production statistics for the entire set of MC events. If False, returns the production statistics for each grid point along the energy axis. Default is True.

Returns:
u.Quantity

If ‘return_sum’ is True, returns the total derived production statistics as a u.Quantity. If ‘return_sum’ is False, returns an array of production statistics along the energy axis as a u.Quantity.

derive_production_statistics_handler#

Module to run the StatisticalErrorEvaluator and interpolate results.

This module provides the ProductionStatisticsHandler class, which manages the workflow for derivation of required number of events for a simulation production using pre-defined metrics.

The module includes functionality to: - Initialize evaluators for statistical error calculations based on input parameters. - Perform interpolation using the initialized evaluators to estimate production statistics at a query point. - Write the results of the interpolation to an output file.

class production_configuration.derive_production_statistics_handler.ProductionStatisticsHandler(args_dict)[source]#

Handles the workflow for deriving production statistics.

This class manages the evaluation of statistical uncertainties from DL2 MC event files and performs interpolation to estimate the required number of events for a simulation production at a specified query point.

initialize_evaluators()[source]#

Initialize StatisticalErrorEvaluator instances for the given zeniths and offsets.

perform_interpolation()[source]#

Perform interpolation for the query point.

run()[source]#

Run the scaling and interpolation workflow.

write_output(production_statistics)[source]#

Write the derived event statistics to a file.

generate_production_grid#

Module defines the GridGeneration class.

Used to generate a grid of simulation points based on flexible axes definitions such azimuth, zenith angle, night-sky background, and camera offset. The module handles axis binning, scaling and interpolation of energy thresholds, viewcone, and radius limits from a lookup table. Additionally, it allows for converting between Altitude/Azimuth and Right Ascension Declination coordinates. The resulting grid points are saved to a file.

class production_configuration.generate_production_grid.GridGeneration(axes: dict, coordinate_system: str = 'zenith_azimuth', observing_location=None, observing_time=None, lookup_table: str | None = None, telescope_ids: list | None = None)[source]#

Defines and generates a grid of simulation points based on flexible axes definitions.

This class generates a grid of points for a simulation based on parameters such as azimuth, zenith angle, night-sky background, and camera offset, taking into account axis definitions, scaling, and units and interpolating values for simulations from a lookup table.

convert_altaz_to_radec(alt, az)[source]#

Convert Altitude/Azimuth (AltAz) coordinates to Right Ascension/Declination (RA/Dec).

Parameters:
altfloat

Altitude angle in degrees.

azfloat

Azimuth angle in degrees.

Returns:
SkyCoord

SkyCoord object containing the RA/Dec coordinates.

Raises:
ValueError

If observing_time is not set.

convert_coordinates(grid_points: list[dict]) list[dict][source]#

Convert the grid points to RA/Dec coordinates if necessary.

Parameters:
grid_pointslist of dict
List of grid points, each represented as a dictionary with axis

names as keys and values.

Returns:
list of dict

The grid points with converted RA/Dec coordinates.

create_circular_binning(azimuth_range, num_bins)[source]#

Create bin centers for azimuth angles, handling circular wraparound (0 deg to 360 deg).

Parameters:
azimuth_rangetuple

(min_azimuth, max_azimuth), can wrap around 0 deg.

num_binsint

Number of bins.

Returns:
np.ndarray

Array of bin centers.

generate_grid() list[dict][source]#

Generate the grid based on the required axes and include interpolated limits.

Takes energy threshold, viewcone, and radius from the interpolated lookup table.

Returns:
list of dict

A list of grid points, each represented as a dictionary with axis names as keys and axis values as values. Axis values may include units where defined.

serialize_grid_points(grid_points, output_file=None)[source]#

Serialize the grid output and save to a file or print to the console.

serialize_quantity(value)[source]#

Serialize Quantity.

generate_simulation_config#

Derives simulation configuration parameters for a grid point based on several metrics.

class production_configuration.generate_simulation_config.SimulationConfig(grid_point: dict[str, float], file_path: str, metrics: dict[str, float] | None = None)[source]#

Configures simulation parameters for a specific grid point.

Parameters:
grid_pointdict

Dictionary representing a grid point with azimuth, elevation, and night sky background.

file_pathstr

Path to the DL2 MC event file for statistical uncertainty evaluation.

metricsdict, optional

Dictionary of metrics to evaluate.

calculate_required_events() int[source]#

Calculate the required number of simulated events based on statistical error metrics.

Uses the ProductionStatisticsDerivator to scale the events.

Returns:
int

The number of simulated events required.

configure_simulation() dict[str, float][source]#

Configure the simulation parameters for the grid point.

Returns:
dict
A dictionary with simulation parameters such as core scatter area,

viewcone, and number of simulated events.

interpolation_handler#

Handle interpolation between multiple StatisticalErrorEvaluator instances.

class production_configuration.interpolation_handler.InterpolationHandler(evaluators, metrics: dict)[source]#

Handle interpolation between multiple StatisticalErrorEvaluator instances.

interpolate(query_points: ndarray) ndarray[source]#

Interpolate the number of simulated events given query points.

Parameters:
query_pointsnp.ndarray

Array of query points with shape (n, 5), where n is the number of points, and 5 represents (energy, azimuth, zenith, nsb, offset).

Returns:
np.ndarray

Interpolated values at the query points.

interpolate_energy_threshold(query_point: ndarray) float[source]#

Interpolate the energy threshold for a given grid point.

Parameters:
query_pointnp.ndarray

Array specifying the grid point (energy, azimuth, zenith, NSB, offset).

Returns:
float

Interpolated energy threshold.

plot_comparison(evaluator)[source]#

Plot a comparison between the simulated, derived, and reconstructed events.

Parameters:
evaluatorStatisticalErrorEvaluator

The evaluator for which to plot the comparison.