CORSIKA add-on package IACT/ATMO:  Version 1.63 (November 2020)
Data Structures | Macros | Typedefs | Functions | Variables
The CORSIKA iact/atmo interface

Data Structures

struct  detstruct
 A structure describing a detector and linking its photons bunches to it. More...
 
struct  gridstruct
 

Macros

#define EXTERNAL_STORAGE   1
 Enable external temporary bunch storage.
 
#define EXTRA_MEM   0
 
#define EXTRA_MEM_1   EXTRA_MEM
 
#define EXTRA_MEM_10   EXTRA_MEM
 
#define EXTRA_MEM_11   EXTRA_MEM
 
#define EXTRA_MEM_12   EXTRA_MEM
 
#define EXTRA_MEM_2   EXTRA_MEM
 
#define EXTRA_MEM_3   EXTRA_MEM
 
#define EXTRA_MEM_4   EXTRA_MEM
 
#define EXTRA_MEM_5   EXTRA_MEM
 
#define EXTRA_MEM_6   EXTRA_MEM
 
#define EXTRA_MEM_7   EXTRA_MEM
 
#define EXTRA_MEM_8   EXTRA_MEM
 
#define EXTRA_MEM_9   EXTRA_MEM
 
#define GRID_SIZE   1000
 unit: cm
 
#define HAVE_EVENTIO_FUNCTIONS   1
 
#define IACT_ATMO_VERSION   "1.63 (2020-11-23)"
 
#define INTERNAL_LIMIT   100000
 Start external storage after so many bunches.
 
#define M_PI   3.14159265358979323846 /* pi */
 
#define max(a, b)   ((a)>(b)?(a):(b))
 
#define MAX_ARRAY_SIZE   1000 /* Use the same limit as in CORSIKA itself. */
 Maximum number of telescopes (or other detectors) per array.
 
#define MAX_BUNCHES   5000000
 
#define MAX_CLASS   1
 
#define MAX_IO_BUFFER   200000000
 
#define min(a, b)   ((a)<(b)?(a):(b))
 
#define NBUNCH   5000
 Memory allocation step size for bunches.
 
#define PIPE_OUTPUT   1
 
#define PRMPAR_SIZE   17
 
#define square(x)   ((x)*(x))
 
#define UNKNOWN_LONG_DIST   1
 

Typedefs

typedef float cors_real_t
 Type for CORSIKA floating point numbers remaining REAL*4.
 

Functions

static int compact_photon_hit (struct detstruct *det, double x, double y, double cx, double cy, double sx, double sy, double photons, double ctime, double zem, double lambda)
 Store a photon bunch for a given telescope in compact format. More...
 
static void cross_prod (double *v1, double *v2, double *v3)
 Cross (outer) product of two 3-D vectors v1, v2 into 3-D vector v3.
 
static int expand_env (char *fname, size_t maxlen)
 Expanding environment variables ourselves rather than passing that on a shell later, so that we can still check characters after expansion.
 
void extprim_setup (const char *text1)
 Function for activating and setting up user-defined (external to CORSIKA) control over types, energy spectra, and angular distribution of primaries. More...
 
void extprm5_ (cors_dbl_t *type, cors_dbl_t *eprim, double *thetap, double *phip, double *ar)
 Alternate call for extprm_() with explicit array rotation angle passed in function call. More...
 
void extprm_ (cors_dbl_t *type, cors_dbl_t *eprim, double *thetap, double *phip)
 Function for external shower-by-shower setting of primary type, energy, and direction. More...
 
void get_iact_stats (long *sb, double *ab, double *ap)
 
void get_impact_offset (cors_real_t evth[273], cors_dbl_t prmpar[PRMPAR_SIZE])
 Approximate impact offset of primary due to geomagnetic field. More...
 
static void get_mass_charge (int type, double *mass, double *charge)
 
double heigh_ (double *thickness)
 The CORSIKA built-in function for the height as a function of overburden. More...
 
static void iact_param (const char *text0)
 Processing of IACT module specific parameters in Corsika input. More...
 
double iact_rndm (int dummy)
 Use a more unique function name if we want to use the same random generator from CORSIKA (sequence 4) also in other parts linked with the IACT module. More...
 
static int in_detector (struct detstruct *det, double x, double y, double sx, double sy)
 Check if a photon bunch hits a particular telescope volume. More...
 
static void ioerrorcheck ()
 
static int is_off (char *word)
 
static int is_on (char *word)
 
static int Nint_f (double x)
 Nearest integer function. More...
 
static double norm3 (double *v)
 Norm of a 3-D vector.
 
static void norm_vec (double *v)
 Normalize a 3-D vector.
 
static int photon_hit (struct detstruct *det, double x, double y, double cx, double cy, double sx, double sy, double photons, double ctime, double zem, double lambda)
 Store a photon bunch for a given telescope in long format. More...
 
double refidx_ (double *height)
 Index of refraction as a function of altitude [cm]. More...
 
double rhof_ (double *height)
 The CORSIKA built-in density lookup function. More...
 
void rmmard_ (double *, int *, int *)
 
static double rndm (int dummy)
 Random number interface using sequence 4 of CORSIKA. More...
 
void sample_offset (const char *sampling_fname, double core_range, double theta, double phi, double thetaref, double phiref, double offax, double E, int primary, double *xoff, double *yoff, double *sampling_area)
 Get uniformly sampled or importance sampled offset of array with respect to core, in the plane perpendicular to the shower axis. More...
 
static int set_random_systems (double theta, double phi, double thetaref, double phiref, double offax, double E, int primary, int volflag)
 Randomly scatter each array of detectors in given area. More...
 
void set_system_displacement (double dx, double dy)
 Report displaced core positions in event header. More...
 
void telasu_ (int *n, cors_dbl_t *dx, cors_dbl_t *dy)
 Setup how many times each shower is used. More...
 
void telend_ (cors_real_t evte[273])
 End of event. More...
 
void televt_ (cors_real_t evth[273], cors_dbl_t prmpar[PRMPAR_SIZE])
 Start of new event. More...
 
void telfil_ (const char *name0)
 Define the output file for photon bunches hitting the telescopes. More...
 
void telinf_ (int *itel, double *x, double *y, double *z, double *r, int *exists)
 Return information about configured telescopes back to CORSIKA. More...
 
void tellng_ (int *type, double *data, int *ndim, int *np, int *nthick, double *thickstep)
 Write CORSIKA 'longitudinal' (vertical) distributions. More...
 
void tellni_ (const char *line, int *llength)
 Keep a record of CORSIKA input lines. More...
 
int telout_ (cors_dbl_t *bsize, cors_dbl_t *wt, cors_dbl_t *px, cors_dbl_t *py, cors_dbl_t *pu, cors_dbl_t *pv, cors_dbl_t *ctime, cors_dbl_t *zem, cors_dbl_t *lambda)
 Check if a photon bunch hits one or more simulated detector volumes. More...
 
void telrne_ (cors_real_t rune[273])
 Write run end block to the output file. More...
 
void telrnh_ (cors_real_t runh[273])
 Save aparameters from CORSIKA run header. More...
 
void telset_ (cors_dbl_t *x, cors_dbl_t *y, cors_dbl_t *z, cors_dbl_t *r)
 Add another telescope to the system (array) of telescopes. More...
 
void telshw_ ()
 Show what telescopes have actually been set up. More...
 
void telsmp_ (const char *name)
 

Variables

static double airlightspeed = 29.9792458/1.0002256
 Speed of light used to correct for the delay between observation level. More...
 
static double all_bunches
 
static double all_bunches_run
 
static double all_photons
 
static double all_photons_run
 
static double arr_cosang = 1.0
 
static double arr_sinang = 0.0
 
static double arrang = 0.
 Array rotation angle (in radians, like ARRANR in corsika.F)
 
static int arrang_known = 0
 
static double atmo_top
 Height of top of atmosphere [cm].
 
static double Bfield [3]
 Magnetic field vector in detector coordinate system (with Bz positive if upwards)
 
static double bxplane [3]
 
static double byplane [3]
 Spanning vectors of shower plane such that projection of B field is in bxplane direction.
 
static double core_range
 The maximum core offset of array centres in circular distribution. More...
 
static double core_range1
 The maximum core offsets in x,y for rectangular distribution. More...
 
static double core_range2
 
int cors_4dig_def = 6900
 
double cors_ver_def = 6.900
 
static struct linked_string corsika_inputs = { corsika_inputs_head, NULL }
 
static char corsika_inputs_head [80]
 
int corsika_version = (CORSIKA_VERSION)
 The CORSIKA version actually running. More...
 
static int count_print_evt = 0
 
static int count_print_tel = 0
 The number of events for which full output is 'printed' can be limited. More...
 
static int det_in_class [MAX_CLASS]
 
static struct detstruct ** detector
 
static double dmax = 0.
 Max. More...
 
static int do_print
 
static double energy
 
static int event_number
 
static double event_weight
 Event weight (default: 1.0). More...
 
FILE * extprim_file = NULL
 
char * extprim_fname = NULL
 
static double first_int
 
static struct gridstructgrid
 
static int grid_elements
 
static int grid_nx
 
static int grid_ny
 
static double grid_x_high
 
static double grid_x_low
 
static double grid_y_high
 
static double grid_y_low
 
static int impact_correction = 1
 Correct impact position if non-zero. More...
 
static double impact_offset [2]
 Offset of impact position of charged primaries.
 
static IO_BUFFERiobuf
 
static double lambda1
 
static double lambda2
 
static long max_bunches = MAX_BUNCHES
 
static int max_internal_bunches = INTERNAL_LIMIT
 The largest number of photon bunches kept in main memory before attempting to flush them to temporary files on disk. More...
 
static size_t max_io_buffer = MAX_IO_BUFFER
 The largest block size in the output data, which must hold all photons bunches of one array. More...
 
static int max_print_evt = 100
 
static int max_print_tel = 10
 
static size_t missing_evth = 0
 Count events where there is no event header preceding event end. More...
 
static int narray
 
static int * ndet
 
static int nevents
 
static int nrun
 
static int nsys = 1
 Number of arrays.
 
static int ntel = 0
 Number of telescopes set up.
 
static double obs_dx
 
static double obs_dy
 
static double obs_height
 
static double off_axis
 
static char * output_fname = NULL
 The name of the output file for eventio format data. More...
 
static char * output_options = NULL
 
static double phi_central
 
static double phi_prim
 
static double pprim [3]
 Momentum vector of primary particle.
 
static int primary
 
static double raise_tel
 Non-zero if any telescope has negative z.
 
static double rmax = 0.
 Max. More...
 
static double rtel [MAX_ARRAY_SIZE]
 
static char * sampling_fname
 The name of the file providing parameters for importance sampling. More...
 
static int skip_off2 = 1
 
static int skip_print = 1
 
static int skip_print2 = 100
 
static long stored_bunches
 
static int tel_individual = 0
 
static size_t tel_split_threshold = 10000000
 Bunches in the whole array for auto-splitting. More...
 
static int televt_done
 
static double theta_central
 The central value of the allowed ranges in theta and phi. More...
 
static double theta_prim
 
static double toffset
 
static int use_compact_format = 1
 
static double ush
 
static double ushc
 
static double vsh
 
static double vshc
 
static double * weight
 
int with_extprim = 0
 
static double wsh
 
static double wshc
 
static double xdisplaced = 0.
 Extra reported core offset displacement (not used with CORSIKA)
 
static double * xoffset
 
static double xtel [MAX_ARRAY_SIZE]
 Position and size definition of fiducial spheres. More...
 
static double ydisplaced = 0.
 
static double * yoffset
 
static double ytel [MAX_ARRAY_SIZE]
 
static double ztel [MAX_ARRAY_SIZE]
 
int atmosphere
 The atmospheric profile number, 0 for built-in. More...
 
static char * atmprof_name = NULL
 File name for atmospheric profile table. More...
 
static int num_prof
 Number of levels in original table. More...
 
static double p_alt [MAX_PROFILE]
 Altitude levels in given table (converted to [cm], upward order). More...
 
static double p_alt_rev [MAX_PROFILE]
 Altitude levels in given table (converted to [cm], reversed order). More...
 
static double p_rho [MAX_PROFILE]
 Density at given levels [g/cm^3] (upward height order)
 
static double p_rho_rev [MAX_PROFILE]
 Density at given levels [g/cm^3], reversed order.
 
static double p_thick [MAX_PROFILE]
 Atmospheric thickness at given levels [g/cm^2].
 
static double p_log_rho [MAX_PROFILE]
 Log of density at given levels (for better interpolation)
 
static double p_log_thick [MAX_PROFILE]
 Log of atmospheric thickness at given levels (upward height order)
 
static double p_log_thick_rev [MAX_PROFILE]
 Log of atmospheric thickness at given levels (reversed order)
 
static double p_log_n1 [MAX_PROFILE]
 Log of (index of refraction minus 1.0) at given levels. More...
 
static double p_bend_ray_hori_a [MAX_PROFILE]
 Coefficient for horizontal displacement refraction effect (reversed order)
 
static double p_bend_ray_time_a [MAX_PROFILE]
 Coefficient for arrival time effect by refraction, density dependence (reversed order)
 
static double p_bend_ray_time0 [MAX_PROFILE]
 Coefficient for arrival time effect by refraction, altitude dependence.
 
static CsplineParcs_alt_log_rho
 Cubic spline parameters for log(density) versus altitude interpolation.
 
static CsplineParcs_alt_log_thick
 Cubic spline parameters for log(thickness) versus altitude interpolation.
 
static CsplineParcs_alt_log_n1
 Cubic spline parameters for log(n-1) versus altitude interpolation.
 
static CsplineParcs_log_thick_alt
 Cubic spline parameters for altitude versus log(thickness) reverse interpolation.
 
static CsplineParcs_bend_rho_hori_a
 Cubic spline parameters for horizontal displacement refraction effect.
 
static CsplineParcs_bend_rho_time_a
 Cubic spline parameters for arrival time effect by refraction, density dependence.
 
static CsplineParcs_bend_alt_time0
 Cubic spline parameters for arrival time effect by refraction, altitude dependence.
 
static double top_of_atmosphere = 112.83e5
 Height of top of atmosphere [cm], = p_alt[num_prof-1].
 
static double top_of_atm_table
 The heighest entry in the atmospheric profile table. More...
 
static double bottom_of_atmosphere = 0.
 Bottom is normally at sea level but table could differ, = p_alt[0].
 
static double bottom_log_thickness
 Thickness at bottom, depending on profile, = p_log_thick[0].
 
static double top_log_thickness
 Thickness at top is zero, thus using an extrapolation from the second last value. More...
 
static double top_layer_2nd_altitude
 Second highest altitude tabulated, using exponential density profile above that. More...
 
static double top_layer_rho0
 Sea-level altitude matching profile in top layer, without scaling for thickness. More...
 
static double top_layer_cfac
 Scaling factor needed to match thickness at second last level. More...
 
static double top_layer_hscale
 Height scale of exponention density profile in top layer. More...
 
static double top_layer_hscale_rho0_cfac
 top_layer_rho0 * top_layer_cfac * top_layer_hscale
 
static double top_layer_hscale_rho0_cfac_inv
 1. More...
 
static double top_layer_exp_top
 exp(-top_of_atmosphere/top_layer_hscale)
 
static double * fast_p_alt
 Equidistant steps in altitude.
 
static double * fast_p_log_rho
 Log(rho) at fast_p_alt steps.
 
static double * fast_p_log_thick
 Log(thick) at fast_p_alt steps.
 
static double * fast_p_log_n1
 Log(n-1) at fast_p_alt steps.
 
static double fast_h_fac
 Inverse of height difference per step.
 
static double * fast_p_thick
 Direct interpolation of thickness at fast_p_alt steps.
 
static double * fast_p_rho
 Direct interpolation of density at fast_p_alt steps.
 
static double * fast_p_n1
 Direct interpolation of n-1 at fast_p_alt steps.
 
static double * fast_p_eq_log_thick
 Equidistant steps in log(thick)
 
static double * fast_p_heigh_rev
 Altitude at given log(thick) steps.
 
static double fast_log_thick_fac
 Inverse of log(thickness) difference per step.
 
static double * fast_p_bend_ray_hori_a
 Coefficient for horizontal displacement refraction effect.
 
static double * fast_p_bend_ray_time_a
 Coefficient for arrival time effect by refraction, density dependence.
 
static double * fast_p_bend_ray_time0
 Coefficient for arrival time effect by refraction, altitude dependence.
 
static double * fast_p_rho_rev
 Density steps used in fast interpolation, in order of incr. More...
 
static double fast_rho_fac
 
static double etadsn = 0.000283 * 994186.38 / 1222.656
 
static double observation_level
 Altitude [cm] of observation level.
 
static double obs_level_refidx
 
static double obs_level_thick
 
static void init_refraction_tables ()
 Initialize tables needed for atmospheric refraction. More...
 
static void init_fast_interpolation ()
 An alternate interpolation method (which requires that the table is sufficiently fine-grained and equidistant) has to be initialized first.
 
static void init_corsika_atmosphere ()
 Take the atmospheric profile from CORSIKA built-in functions. More...
 
static void init_atmosphere_from_text_file ()
 Initialize atmospheric profiles. More...
 
static void init_atmosphere_from_atmprof (void)
 
static double sum_log_dev_sq (double a, double b, double c, int np, double *h, double *t, double *rho)
 
static double atm_exp_fit (double h1, double h2, double *ap, double *bp, double *cp, double *s0, int *npp)
 Fit one atmosphere layer by an expontential density model.
 
void free_atmo_csplines (void)
 
static void trace_ray_planar (double emlev, double olev, double za, double step, double *xo, double *to, double *so)
 Trace a downward light ray in a planar atmosphere. More...
 
static void init_common_atmosphere (void)
 Second-stage part of atmospheric profile initialization is common to CORSIKA default profile and tabulated profiles.
 
void atmset_ (int *iatmo, double *obslev)
 Set number of atmospheric model profile to be used. More...
 
void atmnam_ (const char *aname, double *obslev)
 Instead of setting the atmospheric profile by number, it gets set by name, also indicated by setting profile number to 99. More...
 
void atm_init (AtmProf *aprof)
 This variant is not usable from the FORTRAN code side, thus no underscore at the end of the function name. More...
 
double rhofx_ (double *height)
 Density of the atmosphere as a function of altitude. More...
 
double thickx_ (double *height)
 Atmospheric thickness [g/cm**2] as a function of altitude. More...
 
double refim1x_ (double *height)
 Index of refraction minus 1 as a function of altitude [cm]. More...
 
double heighx_ (double *thick)
 Altitude [cm] as a function of atmospheric thickness [g/cm**2]. More...
 
void raybnd_ (double *zem, cors_dbl_t *u, cors_dbl_t *v, double *w, cors_dbl_t *dx, cors_dbl_t *dy, cors_dbl_t *dt)
 Calculate the bending of light due to atmospheric refraction. More...
 
static double sum_log_dev_sq (double a, double b, double c, int np, double *h, double *t, double *UNUSED(rho))
 Measure of deviation of model layers from tables.
 
static double fn_thick (double h, int nl, double *hl, double *a, double *b, double *c)
 Corresponding to CORSIKA built-in function THICK; only used to show fit results. More...
 
static double fn_rhof (double h, int nl, double *hl, double *UNUSED(a), double *b, double *c)
 Corresponding to CORSIKA built-in function RHOF; only used to show fit results. More...
 
void atmfit_ (int *nlp, double *hlay, double *aatm, double *batm, double *catm)
 Fit the tabulated density profile for CORSIKA EGS part. More...
 
void show_atmo_macros (void)
 
#define M_PI   (3.14159265358979323846264338327950288)
 /
 
#define WITH_RPOLATOR_CSPLINE   1 /* Take advantage of cubic splines if we have them available */
 
#define FAST_INTERPOLATION   always
 
#define FAST_INTERPOLATION2   always
 
#define FAST_INTERPOLATION3   always
 
#define WITH_THICKX_DIRECT
 
#define UNUSED(x)   UNUSED_ ## x
 
#define MAX_PROFILE   120
 
#define MAX_FAST_PROFILE   40000
 
#define _XSTR_(s)   _STR_(s)
 Expand a macro first and then enclose in string.
 
#define _STR_(s)   #s
 Enclose in string without macro expansion. More...
 
#define SHOW_MACRO(s)
 The following shows the same output after a "#define XYZ" and a "#define XYZ 1" (or compiled with "-DXYZ") More...
 
typedef double cors_dbl_t
 
void raybnd_vec_ (double *zem, cors_dbl_t *u, cors_dbl_t *v, double *w, cors_dbl_t *dx, cors_dbl_t *dy, cors_dbl_t *dt)
 
double thick_ (double *height)
 The CORSIKA built-in function for vertical atmospheric thickness (overburden). More...
 
#define CORSIKA_VERSION   6900
 /
 
#define VECTOR_SIZE   4
 
typedef float cors_real_t
 Type for CORSIKA floating point numbers remaining REAL*4.
 
typedef double cors_dbl_t
 Type for CORSIKA numbers which are currently REAL*8.
 
void get_impact_offset (cors_real_t evth[273], cors_dbl_t prmpar[17])
 
void televt_ (cors_real_t evth[273], cors_dbl_t prmpar[17])
 
int iact_check_track_ (double *x1, double *y1, double *z1, double *t1, double *e1, double *eta1, double *x2, double *y2, double *z2, double *t2, double *e2, double *eta2, double *amass, double *charge, double *wtthin)
 
#define PRMPAR_SIZE   17
 /
 

Detailed Description

Macro Definition Documentation

◆ _STR_

#define _STR_ (   s)    #s

◆ SHOW_MACRO

#define SHOW_MACRO (   s)
Value:
if ( strcmp(#s,_XSTR_(s)) != 0 ) \
{ if ( strcmp("", _XSTR_(s)) != 0 && strcmp("1", _XSTR_(s)) != 0 ) \
printf( " " #s "=" _XSTR_(s) "\n" ); else printf( " " #s "\n" ); }
#define _XSTR_(s)
Expand a macro first and then enclose in string.
Definition: atmo.c:3035

Other non-empty, not "1" assigned values are shown explicitly. Undefined macros are not shown. Neither are any assigned to itself.

Function Documentation

◆ atm_init()

void atm_init ( AtmProf aprof)

It is there for doing the atmophere initialization like in the other cases but already passing the pre-filled AtmProf (struct mc_atmprof) along, for example after reading CORSIKA data written by IACT/atmo package version 1.60 and up.

Parameters
aprofPointer to atmospheric profile table structure.
Returns
(none)

References atmosphere, atmospheric_profile::atmprof_fname, atmospheric_profile::atmprof_id, atmprof_name, observation_level, and atmospheric_profile::obslev.

◆ atmfit_()

void atmfit_ ( int *  nlp,
double *  hlay,
double *  aatm,
double *  batm,
double *  catm 
)

Fitting of the tabulated atmospheric density profile by piecewise exponential parts as used in CORSIKA. The fits are constrained by fixing the atmospheric thicknesses at the boundaries to the values obtained from the table. Note that not every atmospheric profile can be fitted well by the CORSIKA piecewise models (4*exponential + 1*constant density). In particular, the tropical model is known to be a problem. Setting the boundary heights manually might help. The user is advised to check at least once that the fitted layers represent the tabulated atmosphere sufficiently well, at least at the altitudes most critical for the observations (usually at observation level and near shower maximum but depending on the user's emphasis, this may vary).

Fit all layers (except the uppermost) by exponentials and (if *nlp > 0) try to improve fits by adjusting layer boundaries. The uppermost layer has constant density up to the 'edge' of the atmosphere.

This function may be called from CORSIKA.

Parameters (all pointers since function is called from Fortran):

Parameters
nlpNumber of layers (5, or negative of that if boundaries set manually)
hlayVector of layer (lower) boundaries.
aatm,batm,catmParameters as used in CORSIKA.

◆ atmnam_()

void atmnam_ ( const char *  aname,
double *  obslev 
)

It does not actually initialize the atmosphere - this still should be done with atmset, using profile number 99 for that purpose. You need to call atmnam_ before atmset to make use of this feature.

◆ atmset_()

void atmset_ ( int *  iatmo,
double *  obslev 
)

The atmospheric model is initialized first before the interpolating functions can be used. For efficiency reasons, the functions rhofx_(), thickx_(), ... don't check if the initialisation was done.

This function is called if the 'ATMOSPHERE' keyword is present in the CORSIKA input file.

The function may be called from CORSIKA to initialize the atmospheric model via 'CALL ATMSET(IATMO,OBSLEV)' or such.

Parameters
iatmo(pointer to) atmospheric profile number; negative for CORSIKA built-in profiles.
obslev(pointer to) altitude of observation level [cm]
Returns
(none)

◆ compact_photon_hit()

static int compact_photon_hit ( struct detstruct det,
double  x,
double  y,
double  cx,
double  cy,
double  sx,
double  sy,
double  photons,
double  ctime,
double  zem,
double  lambda 
)
static

Store a photon bunch in the bunch list for a given telescope. This bunch list is dynamically created and extended as required. This routine is using a more compact format than photon_hit(). This compact format is not appropriate when core distances of telescopes times sine of zenith angle exceed 1000 m.

Parameters
detpointer to data structure of the detector hit.
xX position in CORSIKA detection plane [cm]
yY position in CORSIKA detection plane [cm]
cxDirection projection onto X axis
cyDirection projection onto Y axis
sxSlope with respect to X axis (atan(sx) = acos(cx))
sySlope with respect to Y axis (atan(sy) = acos(cy))
photonsBunch size (sizes above 327 cannot be represented)
ctimeArrival time of bunch in CORSIKA detection plane.
zemAltitude of emission above sea level [cm]
lambdaWavelength (0: undetermined, -1: converted to photo-electron)
Returns
0 (O.K.), -1 (failed to save photon bunch)

References fileclose(), fileopen(), INTERNAL_LIMIT, NBUNCH, and compact_bunch::photons.

◆ extprim_setup()

void extprim_setup ( const char *  text1)
Parameters
textCORSIKA input card text following the 'IACT EXTPRIM' keywords. Could be parameter values or a file name. Unless the parameter starts with a further keyword plus colon to indicate other formats (not yet supported), it is assumed as a filename, as in 'text:filename' to indicate that the file is read as an (ASCII) text file line by line with the following four values each: particle-code total-energy-in-GeV zenith-angle-in-deg azimuth-deg [ azimuth-flag ] where the optional azimuth-flag field can be set to 1 to indicate that the azimuth is to be counted in the astronomical sense (zero for a particle coming from geographical North, increasing clockwise) rather than the CORSIKA way (zero for a particle moving towards geomagnetic North, increasing counter-clockwise).

◆ extprm5_()

void extprm5_ ( cors_dbl_t type,
cors_dbl_t eprim,
double *  thetap,
double *  phip,
double *  ar 
)

May not work as intended. Use with care.

Parameters
typeThe type number of the primary to be used in CORSIKA (output).
eprimThe total energy [GeV] to be used for the primary (output).
thetapThe zenith angle [rad] of the primary (output).
phipThe azimuth angle [rad] of the primary in the CORSIKA way (direction of movement from magnetic North counter-clockwise) (output).
arArray rotation angle w.r.t. magnetic North (input) [radians].

References M_PI.

◆ extprm_()

void extprm_ ( cors_dbl_t type,
cors_dbl_t eprim,
double *  thetap,
double *  phip 
)

If primaries are to be generated following some special (non-power-law) spectrum, with a mixed composition, or with an angular distribution not achieved by built-in methods, a user-defined implementation of this function can be used to generate a mixture of primaries of any spectrum, composition, and angular distribution.

Be aware that this function would be called before televt_ and thus (at least for the first shower) before those run parameters not fitting into the run header are known.

Parameters
typeThe type number of the primary to be used in CORSIKA (output).
eprimThe total energy [GeV] to be used for the primary (output).
thetapThe zenith angle [rad] of the primary (output).
phipThe azimuth angle [rad] of the primary in the CORSIKA way (direction of movement from magnetic North counter-clockwise) (output).

◆ fn_rhof()

static double fn_rhof ( double  h,
int  nl,
double *  hl,
double *  UNUSEDa,
double *  b,
double *  c 
)
static

◆ fn_thick()

static double fn_thick ( double  h,
int  nl,
double *  hl,
double *  a,
double *  b,
double *  c 
)
static

References top_of_atmosphere.

◆ get_impact_offset()

void get_impact_offset ( cors_real_t  evth[273],
cors_dbl_t  prmpar[PRMPAR_SIZE] 
)

Get the approximate impact offset of the primary particle due to deflection in the geomagnetic field. The approximation that the curvature radius is large compared to the distance travelled is used. The method is also not very accurate at large zenith angles where curvature of the atmosphere gets important. Therefore a zenith angle cut is applied and showers very close to the horizon are skipped. Only the offset at the lowest detection level is evaluated.

Parameters
evthCORSIKA event header block
prmparCORSIKA primary particle block. We need it to get the particle's relativistic gamma factor (prmpar[2] or prmpar[1], depending on the CORSIKA version).
Returns
(none)

◆ heigh_()

double heigh_ ( double *  thickness)

References heighx_().

◆ heighx_()

double heighx_ ( double *  thick)

This function can be called from Fortran code as HEIGHX(THICK).

Parameters
thick(pointer to) atmospheric thickness [g/cm**2]
Returns
altitude [cm]

References bottom_log_thickness, bottom_of_atmosphere, fast_log_thick_fac, num_prof, p_thick, top_layer_2nd_altitude, top_layer_exp_top, top_layer_hscale, top_layer_hscale_rho0_cfac_inv, top_layer_rho0, top_log_thickness, and top_of_atmosphere.

Here is the caller graph for this function:

◆ iact_param()

static void iact_param ( const char *  text0)
static
Parameters
textText following the IACT keyword on the input line.

References getword(), and telfil_().

◆ iact_rndm()

double iact_rndm ( int  dummy)

References rndm().

◆ in_detector()

static int in_detector ( struct detstruct det,
double  x,
double  y,
double  sx,
double  sy 
)
static

Check if a photon bunch (or, similarly, a particle) hits a particular simulated telescope/detector.

Parameters
xX position of photon position in CORSIKA detection level [cm]
yY position of photon position in CORSIKA detection level [cm]
sxSlope of photon direction in X/Z plane.
sySlope of photon direction in Y/Z plane.
Returns
0 (does not hit), 1 (does hit)

◆ init_atmosphere_from_text_file()

static void init_atmosphere_from_text_file ( )
static

Internal function for initialising both external and CORSIKA built-in atmospheric profiles. If any CORSIKA built-in profile should be used, it simply calls init_corsika_atmosphere().

Otherwise, atmospheric models are read in from text-format tables. The supplied models 1-6 are based on output of the MODTRAN program. For the interpolation of relevant parameters (density, thickness, index of refraction, ...) all parameters are transformed such that linear interpolation can be easily used.

◆ init_corsika_atmosphere()

static void init_corsika_atmosphere ( )
static

For use of the refraction bending corrections together with the CORSIKA built-in atmospheres, the atmosphere tables are constructed from the CORSIKA RHOF and THICK functions. Note that the refraction index in this case is without taking the effect of wator vapour into account.

References atmosphere, heigh_(), num_prof, and top_of_atmosphere.

◆ init_refraction_tables()

static void init_refraction_tables ( )
static

Initialize the correction tables used for the refraction bending of the light paths. It is called once after the atmospheric profile has been defined.

◆ Nint_f()

static int Nint_f ( double  x)
static

◆ photon_hit()

static int photon_hit ( struct detstruct det,
double  x,
double  y,
double  cx,
double  cy,
double  sx,
double  sy,
double  photons,
double  ctime,
double  zem,
double  lambda 
)
static

Store a photon bunch in the bunch list for a given telescope. It is kept in memory or temporary disk storage until the end of the event. This way, photon bunches or sorted by telescope. This bunch list is dynamically created and extended as required.

Parameters
detpointer to data structure of the detector hit.
xX position in CORSIKA detection plane [cm]
yY position in CORSIKA detection plane [cm]
cxDirection projection onto X axis
cyDirection projection onto Y axis
sxSlope with respect to X axis (atan(sx) = acos(cx))
sySlope with respect to Y axis (atan(sy) = acos(cy))
photonsBunch size
ctimeArrival time of bunch in CORSIKA detection plane.
zemAltitude of emission above sea level [cm]
lambdaWavelength (0: undetermined, -1: converted to photo-electron)
Returns
0 (O.K.), -1 (failed to save photon bunch)

Note: With the EXTENDED_TELOUT every second call would have data of the emitting particle: the mass in cx, the charge in cy, the energy in photons, the time of emission in zem, and 9999 in lambda.

◆ raybnd_()

void raybnd_ ( double *  zem,
cors_dbl_t u,
cors_dbl_t v,
double *  w,
cors_dbl_t dx,
cors_dbl_t dy,
cors_dbl_t dt 
)

Path of light through the atmosphere including the bending by refraction. This function assumes a plane-parallel atmosphere. Coefficients for corrections from straight-line propagation to refraction-bent path are numerically evaluated when the atmospheric model is defined. Note that while the former mix of double/float data types may appear odd, it was determined by the variables present in older CORSIKA to save conversions. With CORSIKA 6.0 all parameters are of double type.

This function may be called from FORTRAN as CALL RAYBND(ZEM,U,V,W,DX,DY,DT)

Parameters
zemAltitude of emission above sea level [cm]
uInitial/Final direction cosine along X axis (updated)
vInitial/Final direction cosine along Y axis (updated)
wInitial/Final direction cosine along Z axis, positive is downwards (updated)
dxPosition in CORSIKA detection plane [cm] (updated)
dyPosition in CORSIKA detection plane [cm] (updated)
dtTime of photon [ns]. Input: emission time. Output: time of arrival in CORSIKA detection plane.

References observation_level, and rhofx_().

◆ refidx_()

double refidx_ ( double *  height)

This function can be called from Fortran code as REFIDX(HEIGHT).

Parameters
height(pointer to) altitude [cm]
Returns
index of refraction

◆ refim1x_()

double refim1x_ ( double *  height)

This function can be called from Fortran code as REFIM1X(HEIGHT). This part has been split off from refidx_ in order to be able to access values small compared to 1.0 without big (relative) rounding errors.

Parameters
height(pointer to) altitude [cm]
Returns
index of refraction minus one

References bottom_of_atmosphere, fast_p_alt, fast_p_n1, p_log_n1, rpol_cspline(), and top_of_atmosphere.

Here is the caller graph for this function:

◆ rhof_()

double rhof_ ( double *  height)

◆ rhofx_()

double rhofx_ ( double *  height)

This function can be called from Fortran code as RHOFX(HEIGHT).

Parameters
height(pointer to) altitude [cm]
Returns
density [g/cm**3]

References bottom_of_atmosphere, fast_p_alt, fast_p_rho, p_rho, rpol_cspline(), and top_of_atmosphere.

Here is the caller graph for this function:

◆ rndm()

static double rndm ( int  dummy)
static

◆ sample_offset()

void sample_offset ( const char *  sampling_fname,
double  core_range,
double  theta,
double  phi,
double  thetaref,
double  phiref,
double  offax,
double  E,
int  primary,
double *  xoff,
double *  yoff,
double *  sampling_area 
)
Parameters
sampling_fnameName of file with parameters, to be read on first call.
core_rangeMaximum core distance as used in data format check [cm]. If not obeying this maximum distance, make sure to switch on the long data format manually.
thetaZenith angle [radians]
phiShower azimuth angle in CORSIKA angle convention [radians].
thetarefReference zenith angle (e.g. of VIEWCONE centre) [radians].
phirefReference azimuth angle (e.g. of VIEWCONE centre) [radians].
offaxAngle between central direction (typically VIEWCONE centre) and the direction of the current primary [radians].
EEnergy of primary particle [GeV]
primaryPrimary particle ID.
xoffX offset [cm] to be generated.
yoffY offset [cm] to be generated.
sampling_areaArea weight of the generated sample (normalized to Pi*core_range^2) [cm^2].

◆ set_random_systems()

static int set_random_systems ( double  theta,
double  phi,
double  thetaref,
double  phiref,
double  offax,
double  E,
int  primary,
int  volflag 
)
static

The area containing the detectors is sub-divided into a rectangular grid and each detector with a (potential) intersection with a grid element is marked for that grid element. A detector can be marked for several grid elements unless completely inside one element. Checks which detector(s) is/are hit by a photon bunch (or, similarly, by a particle) is thus reduced to check only the detectors marked for the grid element which is hit by the photon bunch (or particle). The grid should be sufficiently fine-grained that there are usually not much more than one detector per element but finer graining than the detector sizes makes no sense.

Parameters
thetaZenith angle of the shower following [radians].
phiShower azimuth angle in CORSIKA angle convention [radians].
thetarefReference zenith angle (e.g. of VIEWCONE centre) [radians].
phirefReference azimuth angle (e.g. of VIEWCONE centre) [radians].
offaxAngle between central direction (typically VIEWCONE centre) and the direction of the current primary [radians].
EPrimary particle energy in GeV (may be used in importance sampling).
primaryPrimary particle ID (may be used in importance sampling).
volflagSet to 1 if CORSIKA was compiled with VOLUMEDET option, 0 otherwise.
Returns
0 (O.K.), -1 (error)

◆ set_system_displacement()

void set_system_displacement ( double  dx,
double  dy 
)

The given displacement is added on top of generated core offsets. This function is not used with CORSIKA.

References xdisplaced.

◆ telasu_()

void telasu_ ( int *  n,
cors_dbl_t dx,
cors_dbl_t dy 
)

Set up how many times the telescope system should be randomly scattered within a given area. Thus each telescope system (array) will see the same shower but at random offsets. Each shower is thus effectively used several times. This function is called according to the CSCAT keyword in the CORSIKA input file.

Parameters
nThe number of telescope systems
dxCore range radius (if dy==0) or core x range
dyCore y range (non-zero for ractangular, 0 for circular)
Returns
(none)

References core_range, and core_range1.

◆ telend_()

void telend_ ( cors_real_t  evte[273])

Write out all recorded photon bunches.

End of an event: write all stored photon bunches to the output data file, and the CORSIKA event end block as well.

Parameters
evteCORSIKA event end block
Returns
(none)

◆ televt_()

void televt_ ( cors_real_t  evth[273],
cors_dbl_t  prmpar[PRMPAR_SIZE] 
)

Save event parameters.

Start of new event: get parameters from CORSIKA event header block, create randomly scattered telescope systems in given area, and write their positions as well as the CORSIKA block to the data file.

Parameters
evthCORSIKA event header block
prmparCORSIKA primary particle block
Returns
(none)

◆ telfil_()

void telfil_ ( const char *  name0)

This function is called when the 'TELFIL' keyword is present in the CORSIKA input file.

* The 'file name' parsed is actually decoded further:
*    Apart from the leading '+' or '|' or '+|' the TELFIL argument
*    may contain further bells ans whistles:
*    If the supplied file name contains colons, they are assumed to 
*    separate appended numbers with the following meaning:
*      #1:  number of events for which the photons per telescope are shown
*      #2:  number of events for which energy, direction etc. are shown
*      #3:  every so often an event is shown (e.g. 10 -> every tenth event).
*      #4:  every so often the event number is shown even if #1 and #2 ran out.
*      #5:  offset for #4 (#4=100, #5=1: show events 1, 101, 201, ...)
*      #6:  the maximum number of photon bunches before using external storage
*      #7:  the maximum size of the output buffer in Megabytes.
*    Example: name = "iact.dat:5:15:10"
*       name becomes "iact.dat"
*       5 events are fully shown
*       15 events have energy etc. shown
*       Every tenth event is shown, i.e. 10,20,30,40,50 are fully shown
*       and events number 60,...,150 have their energies etc. shown.
*       After that every shower with event number divideable by 1000 is shown.
*    Note: No spaces inbetween! CORSIKA input processing truncates at blanks.
*
*    Instead of adding these numbers to the TELFIL parameter you can use
*    separate IACT input parameters - which may be less confusing:
*       TELFIL +iact.dat:5:15:10:1000:1:100000:200
*    is equivalent to
*       TELFIL +iact.dat
*       IACT print_events 5 15 10 1000 1
*       IACT internal_bunches 100000
*       IACT io_buffer 200MB
* 
Parameters
nameOutput file name. Note: A leading '+' means: use non-compact format A leading '|' (perhaps after '+') means that the name will not be interpreted as the name of a data file but of a program to which the 'eventio' data stream will be piped (i.e. that program should read the data from its standard input. Any command-line options to that program can be defined via an 'IACT telopt' line.
Returns
(none)
Here is the caller graph for this function:

◆ telinf_()

void telinf_ ( int *  itel,
double *  x,
double *  y,
double *  z,
double *  r,
int *  exists 
)
Parameters
itelnumber of telescope in question
x,y,ztelescope position [cm]
rradius of fiducial volume [cm]
existstelescope exists

References ntel, and xtel.

◆ tellng_()

void tellng_ ( int *  type,
double *  data,
int *  ndim,
int *  np,
int *  nthick,
double *  thickstep 
)

Write several kinds of vertical distributions to the output. These or kinds of histograms as a function of atmospheric depth. In CORSIKA, these are generally referred to as 'longitudinal' distributions.

*  There are three types of distributions:
*       type 1: particle distributions for
*               gammas, positrons, electrons, mu+, mu-,
*               hadrons, all charged, nuclei, Cherenkov photons.
*       type 2: energy distributions (with energies in GeV) for
*               gammas, positrons, electrons, mu+, mu-,
*               hadrons, all charged, nuclei, sum of all.
*       type 3: energy deposits (in GeV) for
*               gammas, e.m. ionisation, cut of e.m.  particles,
*               muon ionisation, muon cut, hadron ionisation,
*               hadron cut, neutrinos, sum of all.
*               ('cut' accounting for low-energy particles dropped)
*  

Note: Corsika can be built with three options concerning the vertical profile of Cherenkov light: default = emission profile, INTCLONG = integrated light profile, NOCLONG = no Cherenkov profiles at all. If you know which kind you are using, you are best off by defining it for compilation of this file (either -DINTEGRATED_LONG_DIST, -DEMISSION_LONG_DIST, or -DNO_LONG_DIST). By default, a run-time detection is attempted which should work well with some 99.99% of all air showers but may fail in some cases like non-interacting muons as primary particles etc.

If eventio functionality is disabled this function does nothing.

Parameters
typesee above
dataset of (usually 9) distributions
ndimmaximum number of entries per distribution
npnumber of distributions (usually 9)
nthicknumber of entries actually filled per distribution (is 1 if called without LONGI being enabled).
thickstepstep size in g/cm**2
Returns
(none)

◆ tellni_()

void tellni_ ( const char *  line,
int *  llength 
)

Add a CORSIKA input line to a linked list of strings which will be written to the output file in eventio format right after the run header.

Parameters
lineinput line (not terminated)
llengthmaximum length of input lines (132 usually)

◆ telout_()

int telout_ ( cors_dbl_t bsize,
cors_dbl_t wt,
cors_dbl_t px,
cors_dbl_t py,
cors_dbl_t pu,
cors_dbl_t pv,
cors_dbl_t ctime,
cors_dbl_t zem,
cors_dbl_t lambda 
)

A bunch of photons from CORSIKA is checked if they hit a a telescope and in this case it is stored (in memory). This routine can alternatively trigger that the photon bunch is written by CORSIKA in its usual photons file.

Note that this function should only be called for downward photons as there is no parameter that could indicate upwards photons.

The interface to this function can be modified by defining EXTENDED_TELOUT. Doing so requires to have a CORSIKA version with support for the IACTEXT option, and to actually activate that option. That could be useful when adding your own code to create some nice graphs or statistics that requires to know the emitting particle and its energy but would be of little help for normal use. Inconsistent usage of EXTENDED_TELOUT here and IACTEXT in CORSIKA will most likely lead to a crash.

Parameters
bsizeNumber of photons (can be fraction of one)
wtWeight (if thinning option is active)
pxx position in detection level plane
pyy position in detection level plane
pux direction cosine
pvy direction cosine
ctimearrival time in plane after first interaction
zemheight of emission above sea level
lambda0. (if wavelength undetermined) or wavelength [nm]. If lambda < 0, photons are already converted to photo-electrons (p.e.), i.e. we have p.e. bunches.
temisTime of photon emission (only if CORSIKA extracted with IACTEXT option and this code compiled with EXTENDED_TELOUT defined).
penergyEnergy of emitting particle (under conditions as temis).
amassMass of emitting particle (under conditions as temis).
chargeCharge of emitting particle (under conditions as temis).
Returns
0 (no output to old-style CORSIKA file needed) 2 (detector hit but no eventio interface available or output should go to CORSIKA file anyway)

References impact_offset, compact_bunch::lambda, and compact_bunch::y.

◆ telrne_()

void telrne_ ( cors_real_t  rune[273])
Parameters
runeCORSIKA run end block

◆ telrnh_()

void telrnh_ ( cors_real_t  runh[273])

Get relevant parameters from CORSIKA run header block and write run header block to the data output file.

Parameters
runhCORSIKA run header block
Returns
(none)

◆ telset_()

void telset_ ( cors_dbl_t x,
cors_dbl_t y,
cors_dbl_t z,
cors_dbl_t r 
)

Set up another telescope for the simulated telescope system. No details of a telescope need to be known except for a fiducial sphere enclosing the relevant optics. Actually, the detector could as well be a non-imaging device.

This function is called for each TELESCOPE keyword in the CORSIKA input file.

Parameters
xX position [cm]
yY position [cm]
zZ position [cm]
rradius [cm] within which the telescope is fully contained
Returns
(none)

References MAX_ARRAY_SIZE, ntel, and xtel.

◆ telshw_()

void telshw_ ( void  )

This function is called by CORSIKA after the input file is read.

References output_fname.

◆ telsmp_()

void telsmp_ ( const char *  name)
@short Set the file name with parameters for importance sampling.

Note that the TELSAMPLE parameter is not processed by CORSIKA itself
and thus has to be specified through configuration lines like
IACT TELSAMPLE filename
*(IACT) TELSAMPLE filename

where the first form requires a CORSIKA patch and the second would work without that patch (but then only with uppercase file names).

References sampling_fname.

◆ thick_()

double thick_ ( double *  height)

References thickx_().

◆ thickx_()

double thickx_ ( double *  height)

This function can be called from Fortran code as THICKX(HEIGHT).

Parameters
height(pointer to) altitude [cm]
Returns
thickness [g/cm**2]

References bottom_of_atmosphere, fast_p_alt, fast_p_thick, num_prof, p_alt, p_thick, rpol_cspline(), top_layer_2nd_altitude, top_layer_exp_top, top_layer_hscale, top_layer_hscale_rho0_cfac, top_layer_rho0, and top_of_atmosphere.

Here is the caller graph for this function:

◆ trace_ray_planar()

static void trace_ray_planar ( double  emlev,
double  olev,
double  za,
double  step,
double *  xo,
double *  to,
double *  so 
)
static
Parameters
emlevEmission level altitude [cm]
olevObservation level altitude [cm] (below emlev)
zaZenith angle (positive downwards)
stepStep length [cm]
xoArrival position at observation level [cm] (returned only), positive value expected for downward bending.
toTravel time to observation level [ns] (returned only).
soPath length travelled [cm] (returned only).

References refidx_().

Variable Documentation

◆ airlightspeed

double airlightspeed = 29.9792458/1.0002256
static

and the actual telescope elevation. Adapted to observation level after run start. [cm/ns] at H=2200 m

◆ atmosphere

int atmosphere

◆ atmprof_name

char* atmprof_name = NULL
static

◆ core_range

double core_range
static

◆ core_range1

double core_range1
static

◆ corsika_version

int corsika_version = (CORSIKA_VERSION)

◆ count_print_tel

int count_print_tel = 0
static

You can control that with the TELFIL option for the output file. Defaults correspond to 'TELFIL iact.dat:10:100:1'

◆ dmax

double dmax = 0.
static

distance of telescopes in (x,y)

◆ event_weight

double event_weight
static

Might be filled with external primaries.

◆ fast_p_rho_rev

double* fast_p_rho_rev
static

density

◆ impact_correction

int impact_correction = 1
static

◆ max_internal_bunches

int max_internal_bunches = INTERNAL_LIMIT
static

◆ max_io_buffer

size_t max_io_buffer = MAX_IO_BUFFER
static

◆ missing_evth

size_t missing_evth = 0
static

That may happen with very-low-energy electrons/positrons bent away in the geomagnetic field before any interaction.

◆ num_prof

int num_prof
static

◆ output_fname

char* output_fname = NULL
static

◆ p_alt

double p_alt[MAX_PROFILE]
static

◆ p_alt_rev

double p_alt_rev[MAX_PROFILE]
static

◆ p_log_n1

double p_log_n1[MAX_PROFILE]
static

◆ rmax

double rmax = 0.
static

radius of telescopes

◆ sampling_fname

char* sampling_fname
static

◆ tel_split_threshold

size_t tel_split_threshold = 10000000
static

◆ theta_central

double theta_central
static

◆ top_layer_2nd_altitude

double top_layer_2nd_altitude
static

◆ top_layer_cfac

double top_layer_cfac
static

◆ top_layer_hscale

double top_layer_hscale
static

◆ top_layer_hscale_rho0_cfac_inv

double top_layer_hscale_rho0_cfac_inv
static

/(top_layer_rho0 * top_layer_cfac * top_layer_hscale)

◆ top_layer_rho0

double top_layer_rho0
static

◆ top_log_thickness

double top_log_thickness
static

for fast interpolation in reverse direction (thickness to height).

◆ top_of_atm_table

double top_of_atm_table
static

◆ xtel

double xtel[MAX_ARRAY_SIZE]
static