CORSIKA add-on package IACT/ATMO:  Version 1.70 (August 2025)
mc_tel.h
Go to the documentation of this file.
1 /* ============================================================================
2 
3  Copyright (C) 1997, 2001, 2009, 2010, 2012, 2016, 2018, 2019, 2020, 2021, 2022, 2023 Konrad Bernloehr
4 
5  This file is part of the eventio/hessio library.
6 
7  The eventio/hessio library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with this library. If not, see <http://www.gnu.org/licenses/>.
19 
20 ============================================================================ */
21 
32 /* ========================================================= */
33 
34 #ifndef _MC_TEL_LOADED
35 
36 #define _MC_TEL_LOADED 2
37 
38 #ifndef _EVENTIO_BASIC_LOADED
39 # include "io_basic.h"
40 #endif
41 
42 #include "mc_atmprof.h"
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /* Data types: */
49 
50 #ifdef DOUBLEPREC
51 typedef double real;
52 #else
53 typedef float real;
54 #endif
55 
56 typedef short INT16;
57 typedef unsigned short UINT16;
58 #ifdef OS_MSDOS
59 typedef long INT32;
60 typedef unsigned long UINT32;
61 #else
62 typedef int INT32;
63 typedef unsigned int UINT32;
64 #endif
65 
66 /* Data structures: */
73 struct bunch
74 {
75  float photons;
76  float x, y;
77  float cx, cy;
78  float ctime;
79  float zem;
80  float lambda;
81 };
82 
95 struct bunch3d
96 {
97  float photons;
98  float x, y, z;
100  float cx, cy, cz;
102  float ctime;
103  float dist;
104  float lambda;
105 };
106 
129 {
130  short photons;
131  short x, y;
132  short cx, cy;
133  short ctime;
134  short log_zem;
135  short lambda;
136 };
137 
141 {
142  int pixel;
143  int lambda;
144  double atime;
145  /* double amplitude; */
146 };
147 
151 {
152  char *text;
153  struct linked_string *next;
154 };
155 
162 {
163  long id;
164  int is_set;
167  double weight;
174  size_t niparam;
175  int *iparam;
177  size_t nfparam;
178  float *fparam;
179 };
181 
182 /* I/O item types: */
183 
184 /* Never change the following numbers after MC data is created: */
185 #define IO_TYPE_MC_BASE 1200
186 #define IO_TYPE_MC_RUNH (IO_TYPE_MC_BASE+0)
187 #define IO_TYPE_MC_TELPOS (IO_TYPE_MC_BASE+1)
188 #define IO_TYPE_MC_EVTH (IO_TYPE_MC_BASE+2)
189 #define IO_TYPE_MC_TELOFF (IO_TYPE_MC_BASE+3)
190 #define IO_TYPE_MC_TELARRAY (IO_TYPE_MC_BASE+4)
191 #define IO_TYPE_MC_PHOTONS (IO_TYPE_MC_BASE+5)
192 #define IO_TYPE_MC_LAYOUT (IO_TYPE_MC_BASE+6)
193 #define IO_TYPE_MC_TRIGTIME (IO_TYPE_MC_BASE+7)
194 #define IO_TYPE_MC_PE (IO_TYPE_MC_BASE+8)
195 #define IO_TYPE_MC_EVTE (IO_TYPE_MC_BASE+9)
196 #define IO_TYPE_MC_RUNE (IO_TYPE_MC_BASE+10)
197 #define IO_TYPE_MC_LONGI (IO_TYPE_MC_BASE+11)
198 #define IO_TYPE_MC_INPUTCFG (IO_TYPE_MC_BASE+12)
199 #define IO_TYPE_MC_TELARRAY_HEAD (IO_TYPE_MC_BASE+13)
200 #define IO_TYPE_MC_TELARRAY_END (IO_TYPE_MC_BASE+14)
201 #define IO_TYPE_MC_EXTRA_PARAM (IO_TYPE_MC_BASE+15)
202 #define IO_TYPE_MC_ATMPROF (IO_TYPE_MC_BASE+16)
203 #define IO_TYPE_MC_PHOTONS3D (IO_TYPE_MC_BASE+17)
204 
205 /* Function prototypes: */
206 
207 /* io_telescope.c */
208 int write_tel_block (IO_BUFFER *iobuf, int type, int num,
209  real *data, int len);
210 int read_tel_block (IO_BUFFER *iobuf, int type, real *data,
211  int maxlen);
212 int print_tel_block (IO_BUFFER *iobuf);
213 
214 int write_input_lines (IO_BUFFER *iobuf,
215  struct linked_string *list);
216 int read_input_lines (IO_BUFFER *iobuf,
217  struct linked_string *list);
218 
219 int write_tel_pos (IO_BUFFER *iobuf, int ntel, double *x,
220  double *y, double *z, double *r);
221 int read_tel_pos (IO_BUFFER *iobuf, int max_tel, int *ntel,
222  double *x, double *y, double *z, double *r);
223 int print_tel_pos (IO_BUFFER *iobuf);
224 
225 int write_tel_offset (IO_BUFFER *iobuf, int narray, double toff,
226  double *xoff, double *yoff);
227 int write_tel_offset_w (IO_BUFFER *iobuf, int narray, double toff,
228  double *xoff, double *yoff, double *weight);
229 int read_tel_offset (IO_BUFFER *iobuf, int max_array, int *narray,
230  double *toff, double *xoff, double *yoff);
231 int read_tel_offset_w (IO_BUFFER *iobuf, int max_array, int *narray,
232  double *toff, double *xoff, double *yoff, double *weight);
233 int print_tel_offset (IO_BUFFER *iobuf);
234 
235 int begin_write_tel_array (IO_BUFFER *iobuf, IO_ITEM_HEADER *ih, int array);
237 int begin_read_tel_array (IO_BUFFER *iobuf, IO_ITEM_HEADER *ih, int *array);
239 
240 int write_tel_array_head (IO_BUFFER *iobuf, IO_ITEM_HEADER *ih, int array);
241 int write_tel_array_end (IO_BUFFER *iobuf, IO_ITEM_HEADER *ih, int array);
242 int read_tel_array_head (IO_BUFFER *iobuf, IO_ITEM_HEADER *ih, int *array);
243 int read_tel_array_end (IO_BUFFER *iobuf, IO_ITEM_HEADER *ih, int *array);
244 
245 int write_tel_photons (IO_BUFFER *iobuf, int array, int tel,
246  double photons, struct bunch *bunches, int nbunches,
247  int ext_bunches, char *ext_fname);
248 int write_tel_compact_photons (IO_BUFFER *iobuf, int array, int tel,
249  double photons, struct compact_bunch *cbunches, int nbunches,
250  int ext_bunches, char *ext_fname);
251 int read_tel_photons (IO_BUFFER *iobuf, int max_bunches, int *array,
252  int *tel, double *photons, struct bunch *bunches, int *nbunches);
253 int print_tel_photons (IO_BUFFER *iobuf);
254 
255 int write_tel_photons3d (IO_BUFFER *iobuf, int array, int tel,
256  double photons, struct bunch3d *bunches3d, int nbunches,
257  int ext_bunches, char *ext_fname);
258 int read_tel_photons3d (IO_BUFFER *iobuf, int max_bunches, int *array,
259  int *tel, double *photons, struct bunch3d *bunches3d, int *nbunches);
260 int print_tel_photons3d (IO_BUFFER *iobuf);
261 
262 int write_shower_longitudinal (IO_BUFFER *iobuf, int event, int type,
263  double *data, int ndim, int np, int nthick, double thickstep);
264 int read_shower_longitudinal (IO_BUFFER *iobuf, int *event,
265  int *type, double *data, int ndim, int *np, int *nthick,
266  double *thickstep, int max_np);
268 
269 int write_camera_layout (IO_BUFFER *iobuf, int itel, int type,
270  int pixels, double *xp, double *yp);
271 int read_camera_layout (IO_BUFFER *iobuf, int max_pixels, int *itel,
272  int *type, int *pixels, double *xp, double *yp);
273 int print_camera_layout (IO_BUFFER *iobuf);
274 
275 int write_photo_electrons (IO_BUFFER *iobuf, int array, int tel,
276  int npe, int pixels, int flags, int *pe_counts, int *tstart,
277  double *t, double *a, int *photon_counts);
278 int read_photo_electrons (IO_BUFFER *iobuf, int max_pixel,
279  int max_pe, int *array, int *tel, int *npe, int *pixels, int *flags,
280  int *pe_counts, int *tstart, double *t, double *a, int *photon_counts);
281 int print_photo_electrons (IO_BUFFER *iobuf);
282 
283 int write_shower_extra_parameters (IO_BUFFER *iobuf, ShowerExtraParam *ep);
284 int read_shower_extra_parameters (IO_BUFFER *iobuf, ShowerExtraParam *ep);
285 int print_shower_extra_parameters (IO_BUFFER *iobuf);
286 int init_shower_extra_parameters(ShowerExtraParam *ep, size_t ni_max, size_t nf_max);
288 ShowerExtraParam *get_shower_extra_parameters(void);
289 
290 void remember_corsika_atm_params(float *hlay, float *aatm, float *batm, float *catm);
291 int get_corsika_atm_params(double *hlay, double *aatm, double *batm, double *catm, double *datm);
292 
293 int write_atmprof (IO_BUFFER *iobuf, AtmProf *atmprof);
294 int read_atmprof (IO_BUFFER *iobuf, AtmProf *atmprof);
295 int print_atmprof (IO_BUFFER *iobuf);
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 
301 #endif
static int ntel
Number of telescopes set up.
Definition: iact.c:352
static size_t max_bunches
The default maximum number of bunches can later be adapted to CORSIKA.
Definition: sim_skeleton.c:63
Basic header file for eventio data format.
A data structure shared between io_simtel.c and atmo.c - which is used by both sim_telarray and the C...
int print_camera_layout(IO_BUFFER *iobuf)
Print the layout (pixel positions) of a camera used for converting from photons to photo-electrons in...
Definition: io_simtel.c:2159
int write_tel_pos(IO_BUFFER *iobuf, int ntel, double *x, double *y, double *z, double *r)
Write positions of telescopes/detectors within a system or array.
Definition: io_simtel.c:484
int read_atmprof(IO_BUFFER *iobuf, AtmProf *atmprof)
Read the atmospheric profile table as used in CORSIKA.
Definition: io_simtel.c:2944
int print_atmprof(IO_BUFFER *iobuf)
Print the atmospheric profile table as used in CORSIKA.
Definition: io_simtel.c:3066
int clear_shower_extra_parameters(ShowerExtraParam *ep)
Similar to init_shower_extra_parameters() but without any attempts to re-allocate or resize buffers.
Definition: io_simtel.c:2822
int write_tel_photons(IO_BUFFER *iobuf, int array, int tel, double photons, struct bunch *bunches, int nbunches, int ext_bunches, char *ext_fname)
Write all the photon bunches for one telescope to an I/O buffer.
Definition: io_simtel.c:1035
int print_shower_longitudinal(IO_BUFFER *iobuf)
Print CORSIKA shower longitudinal distributions.
Definition: io_simtel.c:2003
int write_atmprof(IO_BUFFER *iobuf, AtmProf *atmprof)
Write the atmospheric profile table as used in CORSIKA with ATMEXT option and set up with 'ATMOSPHERE...
Definition: io_simtel.c:2878
int print_tel_offset(IO_BUFFER *iobuf)
Print offsets and weights of randomly scattered arrays with respect to shower core.
Definition: io_simtel.c:773
int read_tel_photons(IO_BUFFER *iobuf, int max_bunches, int *array, int *tel, double *photons, struct bunch *bunches, int *nbunches)
Read bunches of Cherenkov photons for one telescope/detector.
Definition: io_simtel.c:1397
int print_tel_photons(IO_BUFFER *iobuf)
Print bunches of Cherenkov photons for one telescope/detector.
Definition: io_simtel.c:1604
int print_tel_pos(IO_BUFFER *iobuf)
Print positions of telescopes/detectors within a system or array.
Definition: io_simtel.c:577
int read_tel_block(IO_BUFFER *iobuf, int type, real *data, int maxlen)
Read a CORSIKA header/trailer block of given type (see mc_tel.h)
Definition: io_simtel.c:105
int read_tel_pos(IO_BUFFER *iobuf, int max_tel, int *ntel, double *x, double *y, double *z, double *r)
Read positions of telescopes/detectors within a system or array.
Definition: io_simtel.c:521
int write_tel_array_end(IO_BUFFER *iobuf, IO_ITEM_HEADER *ih, int array)
End writing data for one array of telescopes/detectors.
Definition: io_simtel.c:947
int print_tel_block(IO_BUFFER *iobuf)
Print a CORSIKA header/trailer block of any type (see mc_tel.h)
Definition: io_simtel.c:165
int read_input_lines(IO_BUFFER *iobuf, struct linked_string *list)
Read a block with several character strings (normally containing the text of the CORSIKA inputs file)...
Definition: io_simtel.c:423
int begin_read_tel_array(IO_BUFFER *iobuf, IO_ITEM_HEADER *ih, int *array)
Begin reading data for one array of telescopes/detectors.
Definition: io_simtel.c:880
int init_shower_extra_parameters(ShowerExtraParam *ep, size_t ni_max, size_t nf_max)
Initialize, resize, clear shower extra parameters.
Definition: io_simtel.c:2754
int print_photo_electrons(IO_BUFFER *iobuf)
List the the photoelectrons registered in a Cherenkov telescope camera.
Definition: io_simtel.c:2475
int write_camera_layout(IO_BUFFER *iobuf, int itel, int type, int pixels, double *xp, double *yp)
Write the layout (pixel positions) of a camera used for converting from photons to photo-electrons in...
Definition: io_simtel.c:2084
int read_tel_array_end(IO_BUFFER *iobuf, IO_ITEM_HEADER *ih, int *array)
End reading data for one array of telescopes/detectors.
Definition: io_simtel.c:999
int end_read_tel_array(IO_BUFFER *iobuf, IO_ITEM_HEADER *ih)
End reading data for one array of telescopes/detectors.
Definition: io_simtel.c:904
int begin_write_tel_array(IO_BUFFER *iobuf, IO_ITEM_HEADER *ih, int array)
Begin writing data for one array of telescopes/detectors.
Definition: io_simtel.c:838
int read_tel_offset_w(IO_BUFFER *iobuf, int max_array, int *narray, double *toff, double *xoff, double *yoff, double *weight)
Read offsets and weights of randomly scattered arrays with respect to shower core.
Definition: io_simtel.c:710
int read_tel_array_head(IO_BUFFER *iobuf, IO_ITEM_HEADER *ih, int *array)
Begin reading data for one array of telescopes/detectors.
Definition: io_simtel.c:973
int read_shower_longitudinal(IO_BUFFER *iobuf, int *event, int *type, double *data, int ndim, int *np, int *nthick, double *thickstep, int max_np)
Read CORSIKA shower longitudinal distributions.
Definition: io_simtel.c:1942
int end_write_tel_array(IO_BUFFER *iobuf, IO_ITEM_HEADER *ih)
End writing data for one array of telescopes/detectors.
Definition: io_simtel.c:858
int write_input_lines(IO_BUFFER *iobuf, struct linked_string *list)
Write a linked list of character strings (normally containing the text of the CORSIKA inputs file) as...
Definition: io_simtel.c:370
int write_tel_offset_w(IO_BUFFER *iobuf, int narray, double toff, double *xoff, double *yoff, double *weight)
Write offsets and weights of randomly scattered arrays with respect to shower core.
Definition: io_simtel.c:650
int read_tel_offset(IO_BUFFER *iobuf, int max_array, int *narray, double *toff, double *xoff, double *yoff)
Read offsets of randomly scattered arrays with respect to shower core.
Definition: io_simtel.c:689
int read_photo_electrons(IO_BUFFER *iobuf, int max_pixel, int max_pe, int *array, int *tel, int *npe, int *pixels, int *flags, int *pe_counts, int *tstart, double *t, double *a, int *photon_counts)
Read the photoelectrons registered in a Cherenkov telescope camera.
Definition: io_simtel.c:2332
int write_tel_photons3d(IO_BUFFER *iobuf, int array, int tel, double photons, struct bunch3d *bunches3d, int nbunches, int ext_bunches, char *ext_fname)
Write all the photon bunches (3D) for one telescope to an I/O buffer.
Definition: io_simtel.c:1164
int write_tel_block(IO_BUFFER *iobuf, int type, int num, real *data, int len)
Write a CORSIKA block as given type number (see mc_tel.h).
Definition: io_simtel.c:72
int write_photo_electrons(IO_BUFFER *iobuf, int array, int tel, int npe, int pixels, int flags, int *pe_counts, int *tstart, double *t, double *a, int *photon_counts)
Write the photo-electrons registered in a Cherenkov telescope camera.
Definition: io_simtel.c:2226
int print_tel_photons3d(IO_BUFFER *iobuf)
Print 3D bunches of Cherenkov photons for one telescope/detector.
Definition: io_simtel.c:1773
int write_tel_offset(IO_BUFFER *iobuf, int narray, double toff, double *xoff, double *yoff)
Write offsets of randomly scattered arrays with respect to shower core.
Definition: io_simtel.c:621
int write_shower_longitudinal(IO_BUFFER *iobuf, int event, int type, double *data, int ndim, int np, int nthick, double thickstep)
Write CORSIKA shower longitudinal distributions.
Definition: io_simtel.c:1899
int write_tel_compact_photons(IO_BUFFER *iobuf, int array, int tel, double photons, struct compact_bunch *cbunches, int nbunches, int ext_bunches, char *ext_fname)
Write all the photon bunches for one telescope to an I/O buffer.
Definition: io_simtel.c:1297
int read_tel_photons3d(IO_BUFFER *iobuf, int max_bunches, int *array, int *tel, double *photons, struct bunch3d *bunches3d, int *nbunches)
Read bunches of Cherenkov photons for one telescope/detector.
Definition: io_simtel.c:1515
int read_camera_layout(IO_BUFFER *iobuf, int max_pixels, int *itel, int *type, int *pixels, double *xp, double *yp)
Read the layout (pixel positions) of a camera used for converting from photons to photo-electrons in ...
Definition: io_simtel.c:2120
int write_tel_array_head(IO_BUFFER *iobuf, IO_ITEM_HEADER *ih, int array)
Begin writing data for one array of telescopes/detectors.
Definition: io_simtel.c:926
The IO_BUFFER structure contains all data needed the manage the stuff.
Definition: io_basic.h:90
An IO_ITEM_HEADER is to access header info for an I/O block and as a handle to the I/O buffer.
Definition: io_basic.h:75
Atmospheric profile as stored in atmprof*.dat files - the actually used columns only.
Definition: mc_atmprof.h:48
A more complete, alternative bunch structure which can also represent upward-going photon bunches or ...
Definition: mc_tel.h:96
float cz
Direction cosines of photon direction,.
Definition: mc_tel.h:100
float ctime
usually with cz < 0 for downward.
Definition: mc_tel.h:102
float dist
Distance of emission point from arrival position (cm)
Definition: mc_tel.h:103
float photons
Number of photons in bunch.
Definition: mc_tel.h:97
float z
Arrival position relative to telescope (cm),.
Definition: mc_tel.h:98
float lambda
Wavelength in nanometers or 0.
Definition: mc_tel.h:104
Photons collected in bunches of identical direction, position, time, and wavelength.
Definition: mc_tel.h:74
float ctime
Arrival time (ns)
Definition: mc_tel.h:78
float photons
Number of photons in bunch.
Definition: mc_tel.h:75
float lambda
Wavelength in nanometers or 0.
Definition: mc_tel.h:80
float y
Arrival position relative to telescope (cm)
Definition: mc_tel.h:76
float zem
Height of emission point above sea level (cm)
Definition: mc_tel.h:79
float cy
Direction cosines of photon direction.
Definition: mc_tel.h:77
The compact_bunch struct is equivalent to the bunch struct except that we try to use less memory.
Definition: mc_tel.h:129
short cy
cx,cy*30000
Definition: mc_tel.h:132
short photons
ph*100
Definition: mc_tel.h:130
short lambda
(nm) or 0
Definition: mc_tel.h:135
short y
x,y*10 (mm)
Definition: mc_tel.h:131
short ctime
ctime*10 (0.1ns) after subtracting offset
Definition: mc_tel.h:133
short log_zem
log10(zem)*1000
Definition: mc_tel.h:134
The linked_string is mainly used to keep CORSIKA input.
Definition: mc_tel.h:151
A photo-electron produced by a photon hitting a pixel.
Definition: mc_tel.h:141
int lambda
The wavelength of the photon.
Definition: mc_tel.h:143
int pixel
The pixel that was hit.
Definition: mc_tel.h:142
double atime
The time [ns] when the photon hit the pixel.
Definition: mc_tel.h:144
Extra shower parameters of unspecified nature.
Definition: mc_tel.h:162
float * fparam
Space for extra floats, at least of size nfparam.
Definition: mc_tel.h:178
long id
May identify to the user what the parameters should mean.
Definition: mc_tel.h:163
size_t nfparam
Number of extra floating-point parameters.
Definition: mc_tel.h:177
int * iparam
Space for extra integer parameters, at least of size niparam.
Definition: mc_tel.h:175
double weight
To be used if the weight of a shower may change during processing, e.g.
Definition: mc_tel.h:167
size_t niparam
Number of extra integer parameters.
Definition: mc_tel.h:174
int is_set
May be reset after writing the parameter block and must thus be set to 1 for each shower for which th...
Definition: mc_tel.h:164