CORSIKA add-on package IACT/ATMO:  Version 1.63 (November 2020)
Data Structures | Macros | Typedefs | Functions | Variables
iact.c File Reference

CORSIKA interface for Imaging Atmospheric Cherenkov Telescopes etc. More...

#include "initial.h"
#include "io_basic.h"
#include "mc_tel.h"
#include <assert.h>
#include "fileopen.h"
#include "atmo.h"
#include "sampling.h"
#include "straux.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
Include dependency graph for iact.c:

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]
 

Detailed Description

Author
Konrad Bernloehr
Date
CVS $Date: 2020/11/24 11:27:19 $ 
CVS $Revision: 1.133 $ 

Version 1.2.49 (for IACT/ATMO package version 1.63)


This file implements a CORSIKA interface for the simulation of (3-D) arrays of Cherenkov telescopes. A whole array may be simulated in multiple instances with random offsets of each instance. For full use of this software additional files are required which are available now on request from Konrad Bernloehr (e-mail: Konra.nosp@m.d.Be.nosp@m.rnloe.nosp@m.hr@m.nosp@m.pi-hd.nosp@m..mpg.nosp@m..de). These additional files should be included in the same add-on package to CORSIKA which includes this file. A fallback mechanism is included to use the normal CORSIKA output of Cherenkov photon bunches instead of the dedicated output functions from the unavailable files. However, this fallback mechanism has important drawbacks: information about positions of telescopes are completely lost and no photon bunches are collected in memory because the collected bunches would never be written out. For those reasons you are adviced to obtain and use the additional software.

General comments on this file:

Routines provided in this file interface to recent versions of the CORSIKA air shower simulation program (the FORTRAN implementation only for now, not CORSIKA 8). Modifications to CORSIKA have been kept as simple as possible and the existing routines for production of Cherenkov light have been largely maintained. Setup of the telescope systems to be simulated is via the usual CORSIKA input file (the syntax of which has been extended by a few additional keywords). These telescope systems can be randomly scattered several times within a given area. All treatment whether a bunch of photons hits a telescope is done by the routines in this file. Photon bunches are kept in main memory until the end of the event. This might be a limitation when simulating large showers / many telescopes / many systems of telescopes on a computer with little memory. An option to store photon bunches in a temporary file has, therefore, been included. After the end of an event in CORSIKA all photon bunches (sorted by system and telescope) are written to a data file in the 'eventio' portable data format also used for CRT and HEGRA CT data. All CORSIKA run/event header/trailer blocks are also written to this file.

This version comes with sections for conditional compilation like EXTENDED_TELOUT CORSIKA is compiled with extended interface (IACTEXT option). Information about particles on ground is stored. IACTEXT For all practical purposes a synonym to EXTENDED_TELOUT. STORE_EMITTER Store information about all particles emitting light after the photon bunch. This duplicated the amount of data. Requires the IACTEXT option to be activated. MARK_DIRECT_LIGHT The Cherenkov photons bunches from the primary particle and its leading/major fragments are marked up with a non-zero wavelength (1: direct, 2, 3: major fragments). Requires the IACTEXT option to be activated. See the ALL_WL_RANDOM configuration parameter to sim_telarray. CORSIKA_SAVES_PHOTONS CORSIKA should save photons in its own format. IACT_NO_GRID For optimization of finding detector hits in normal simulations a detector is assigned to each grid cell onto which the detector throws a 'shadow', reducing the detector intersection checks a lot. In special shower simulations (example: a 10000 m high string of telescopes) or in technical simulations (e.g. using the IACT interface for artificial light sources, without CORSIKA) this may fail and explicit intersection of each photon bunch with each detector sphere needs to be checked. NO_EXTERNAL_ATMOSPHERES CORSIKA was compiled without the ATMEXT option and we do not handle tables of atmospheric density etc. Note that these extensions may not have been tested in a long time. Use with care.