source: trunk/MagicSoft/Simulation/Detector/Camera/camera.h@ 5274

Last change on this file since 5274 was 5269, checked in by moralejo, 20 years ago
*** empty log message ***
File size: 15.0 KB
Line 
1//=//////////////////////////////////////////////////////////////////////
2//=
3//= camera
4//=
5//= @file camera.h
6//= @desc Header file
7//= @author J C Gonzalez
8//= @email gonzalez@mppmu.mpg.de
9//= @date Thu May 7 16:24:22 1998
10//=
11//=----------------------------------------------------------------------
12//=
13//= Created: Thu May 7 16:24:22 1998
14//= Author: Jose Carlos Gonzalez
15//= Purpose: Program for reflector simulation
16//= Notes: See files README for details
17//=
18//=----------------------------------------------------------------------
19//=
20//= $RCSfile: camera.h,v $
21//= $Revision: 1.23 $
22//= $Author: moralejo $
23//= $Date: 2004-10-13 17:05:05 $
24//=
25//=//////////////////////////////////////////////////////////////////////
26
27// @T \newpage
28
29//!@section Source code of |camera.h|.
30
31/*!@"
32
33 This section shows the include file |camera.h|
34
35 @"*/
36
37//=-----------------------------------------------------------
38//!@subsection Include files.
39
40//!@{
41
42#include <iostream>
43#include <fstream>
44#include <stdlib.h>
45#include <stdio.h>
46#include <string>
47#include <stdarg.h>
48#include <math.h>
49#include <sys/types.h>
50#include <dirent.h>
51#include <unistd.h>
52#include <libgen.h>
53#include <time.h>
54
55#include "camera-v.h"
56
57#include "jcmacros.h"
58#include "jcdebug.h"
59
60#include "creadparam.h"
61#include "moments.h"
62
63#include "MCRunHeader.hxx"
64#include "MCEventHeader.hxx"
65#include "MCEventHeader_2.hxx"
66#include "MMcConfigRunHeader.h"
67#include "MCCphoton.hxx"
68#include "MTrigger.hxx"
69
70#include "MParContainer.h"
71#include "MArray.h"
72
73
74// command line options available
75
76#define COMMAND_LINE_OPTIONS "f:h"
77
78/*@'
79
80 This is C++, but RANLIB routines are written in pure ANSI C.
81 In order to read easily these routines, we must include
82 the following directive
83
84*/
85
86extern "C" {
87#include "ranlib.h"
88}
89
90// version of the reflector program that can read
91
92#define REFL_PROGRAM reflector
93#define REFL_VERSION_A 0.4
94#define REFL_VERSION_B 0.5
95#define REFL_VERSION_C 0.6
96
97const char REFL_SIGNATURE_A[] = GLUE_postp( REFL_PROGRAM, REFL_VERSION_A );
98const char REFL_SIGNATURE_B[] = GLUE_postp( REFL_PROGRAM, REFL_VERSION_B );
99const char REFL_SIGNATURE_C[] = GLUE_postp( REFL_PROGRAM, REFL_VERSION_C );
100
101//!@}
102
103//=------------------------------------------------------------
104//!@subsection Macro-definitions, and constants.
105
106//!@{
107
108#define EMI_NSB 0.78
109#define EMICOAT_NSB 1.0
110#define HPD_NSB 2.70
111
112#define SLICES 19
113#define WIDTH_TIMESLICE 3.3
114
115#define NOTIME 9e+10
116
117#define SIN60 0.866025403784439
118#define COS60 0.500000000000000
119
120#define RandomNumber drand48()
121
122#define iMAXNUMPIX 3500 // total maximum possible number of pixels in the camera
123
124#define iMAXNUMPHE 50000 // maximum total number of photoelectrons in one event
125
126#define iNUMNSBPRODCALLS 1 // in order to average over the QE simulation, call the
127 // phe production function for the NSB iNUMNSBPRODCALLS times
128
129#define iNUMWAVEBANDS 5 // number of wavebands for the NSB simulation
130
131#define WAVEBANDBOUND1 290. // iNUMWAVEBANDS+1 boundaries for waveband definitions (nm)
132#define WAVEBANDBOUND2 310. // for the NSB generation
133#define WAVEBANDBOUND3 400.
134#define WAVEBANDBOUND4 500.
135#define WAVEBANDBOUND5 600.
136#define WAVEBANDBOUND6 800.
137
138#define EXTWAVEBAND1 3.715 // iNUMWAVEBANDS extinction values in magnitudes per airmass
139#define EXTWAVEBAND2 0.642 // - these values were taken from D.L. King, Isaac Newton Group
140#define EXTWAVEBAND3 0.209 // Tech Note No. 31, they are for a clear night at the ORM,
141#define EXTWAVEBAND4 0.107 // La Palma. The values were averaged in the given wavebands
142#define EXTWAVEBAND5 0.053
143
144#define SIMTIMEOFFSET_NS 5 // determines how many ns before the first and after the last
145 // shower photoelectron, there should be NSB photoelectrons
146
147#define MAX_NUMBER_OF_CTS 20 // Maximum number of CTs allowed for running
148 // on multitelescope systems. If this maximum
149 // is set too large, program may crash!
150
151
152//@ now we define the list CT_ITEM_LIST of possible items in the CT def. file
153#define CT_ITEM_LIST /* LIST OF ITEMS IN THE CT DEFINITION FILE */ \
154T(type), /* type of definition file */ \
155T(focal_distance), /* std(focal distance) */ \
156T(focal_std), /* focal distance */ \
157T(point_spread), /* std(point spread) */ \
158T(point_std), /* point spread */ \
159T(adjustment_dev), /* std of adjustment deviation */ \
160T(black_spot), /* radius of the black spot in center of mirror */ \
161T(n_mirrors), /* number of mirrors */ \
162T(r_mirror), /* radius of one mirror */ \
163T(camera_width), /* camera width */ \
164T(n_pixels), /* total number of pixels in the camera */ \
165T(n_centralpixels), /* number of central pixels in the camera */ \
166T(n_gappixels), /* number of gap pixels in the camera */ \
167T(pixel_width), /* pixel width */ \
168T(define_mirrors) /* this entry is followed by the def. of pixels */
169
170#define T(x) x //@< define T() as the name as it is
171
172enum CT_ITEM_TYPE {
173 CT_ITEM_LIST
174};
175
176#undef T
177
178#define T(x) #x //@< define T() as the string of x
179
180const char *const CT_ITEM_NAMES[] = {
181 CT_ITEM_LIST
182};
183
184#undef T
185
186
187// TYPE=0 (CT1)
188// i s rho theta x y z thetan phin xn yn zn
189//
190// i : number of the mirror
191// s : arc length [cm]
192// rho : polar rho of the position of the center of the mirror [cm]
193// theta : polar angle of the position of the center of the mirror [cm]
194// x : x coordinate of the center of the mirror [cm]
195// y : y coordinate of the center of the mirror [cm]
196// z : z coordinate of the center of the mirror [cm]
197// thetan : polar theta angle of the direction where the mirror points to
198// phin : polar phi angle of the direction where the mirror points to
199// xn : xn coordinate of the normal vector in the center (normalized)
200// yn : yn coordinate of the normal vector in the center (normalized)
201// zn : zn coordinate of the normal vector in the center (normalized)
202//
203// TYPE=1 (MAGIC)
204// i f sx sy x y z thetan phin
205//
206// i : number of the mirror
207// f : focal distance of that mirror
208// sx : curvilinear coordinate of mirror's center in X[cm]
209// sy : curvilinear coordinate of mirror's center in X[cm]
210// x : x coordinate of the center of the mirror [cm]
211// y : y coordinate of the center of the mirror [cm]
212// z : z coordinate of the center of the mirror [cm]
213// thetan : polar theta angle of the direction where the mirror points to
214// phin : polar phi angle of the direction where the mirror points to
215// xn : xn coordinate of the normal vector in the center (normalized)
216// yn : yn coordinate of the normal vector in the center (normalized)
217// zn : zn coordinate of the normal vector in the center (normalized)
218
219#define CT_I 0
220
221#define CT_S 1
222#define CT_RHO 2
223#define CT_THETA 3
224
225#define CT_FOCAL 1
226#define CT_SX 2
227#define CT_SY 3
228
229#define CT_X 4
230#define CT_Y 5
231#define CT_Z 6
232#define CT_THETAN 7
233#define CT_PHIN 8
234#define CT_XN 9
235#define CT_YN 10
236#define CT_ZN 11
237
238#define CT_NDATA 12
239
240//!@}
241
242//=------------------------------------------------------------
243//!@subsection data types
244
245struct camera { /* camera parameters for imaging */
246 int inumpixels;
247 int inumcentralpixels;
248 int inumgappixels;
249 int inumbigpixels;
250 double dpixdiameter_cm; /* diameter of the central and gap pixels in centimeters */
251 double dpixsizefactor[iMAXNUMPIX]; /* size of the pixel relative to dpixdiameter_deg */
252 double dxc[iMAXNUMPIX]; /* Pixel coordinates in camera coordinate system (x points from pixel 1 to 2). */
253 double dyc[iMAXNUMPIX]; /* The numbering of the pixels in these arrays starts at 0! */
254 double dxpointcorr_deg; /* correction of the pixel coordinates; to be added to dxc[] to get correct value */
255 double dypointcorr_deg; /* correction of the pixel coordinates; to be added to dxc[] to get correct value */
256
257};
258
259//=------------------------------------------------------------
260//!@subsection Pre-defined file names.
261
262//!@{
263
264#define QE_FILE "../Data/qe.dat"
265#define WC_FILE "../Data/LightCollection.dat"
266
267//!@}
268
269//=------------------------------------------------------------
270//!@subsection Prototypes of functions.
271
272//!@{
273
274//++
275// prototypes
276//--
277
278#define ONoff(x) ((x==TRUE) ? "[ ON ]" : "[ off]")
279
280// Under Linux, the nint function does not exist, so we have to define it.
281#define nint(x) ((int)floor((x)+0.5))
282
283void present(void);
284void usage(void);
285void clean(void);
286void log(const char *funct, char *fmt, ...);
287void error(const char *funct, char *fmt, ...);
288int isA( char * s1, const char * flag );
289void read_ct_file(void);
290int igen_pixel_coordinates(struct camera *cam);
291void read_pixels(struct camera *cam);
292void read_QE(char fname[256], int ict);
293void read_WC(void);
294void read_ascii( FILE *sp, // the input file
295 MMcConfigRunHeader *config
296 );
297int pixels_are_neig(int pix1, int pix2);
298int bpoint_is_in_pix(double dx, double dy, int ipixnum,
299 MGeomCam *pcamgeom);
300float dist_r_P(float a, float b, float c,
301 float l, float m, float n,
302 float x, float y, float z);
303int check_reflector_file(FILE *infile);
304float lin_interpol(float x1, float y1, float x2, float y2, float x);
305int produce_phes( FILE *sp, // the input file
306 class MGeomCam *camgeom, // the camera layout
307 float minwl_nm, // the minimum accepted wavelength
308 float maxwl_nm, // the maximum accepted wavelength
309 class MTrigger *trigger,
310 class MFadc *fadc,
311 int *itotnphe, // total number of produced photoelectrons
312 float *nphe, // number of photoelectrons in each pixel
313 int *incph, // total number of cph read
314 float *tmin_ns, // minimum arrival time of all phes
315 float *tmax_ns, // maximum arrival time of all phes
316 int telescope, // Telescope that is being analised to get the right QE.
317 float mirror_fraction // Fraction of working mirror
318 );
319
320int produce_nsbrates( char *inname,
321 MGeomCam *camgeom,
322 float **nsbrate,
323 int ict,
324 float mirror_fraction
325 );
326
327int produce_nsb_phes( float *atmin_ns,
328 float *atmax_ns,
329 float theta_rad,
330 struct camera *cam,
331 float **nsbr_phepns,
332 float dnsb_phepns[iMAXNUMPIX],
333 float extinction[iNUMWAVEBANDS],
334 float fnpx[iMAXNUMPIX],
335 class MTrigger *trigger,
336 class MFadc *fadc,
337 int *inphe,
338 float base_mv[iMAXNUMPIX]);
339
340int size_rotated ( float *rotated,
341 float nsb[iMAXNUMPIX],
342 float ro);
343
344
345int DoCalibration( class MFadc **Fadc_CT, class MTrigger **Trigger_CT,
346 class TObjArray camgeom,
347 float* nsb_trigresp, float *nsb_fadcresp,
348 class MLons *lons, class MLons *lons_outer,
349 float **diffnsb_phepns, int addElecNoise,
350 class TTree *EvtTree, class MRawEvtHeader **EvtHeader,
351 class MMcEvt **McEvt, class MRawEvtData **EvtData);
352
353
354int produce_calib_phes( class MGeomCam *camgeom, class MTrigger *trigger,
355 class MFadc *fadc, int *itotnphe, float *nphe,
356 int *nphot, int ict, float lambda, float sigma_lambda,
357 float phot_per_pix, float sigma_time, int selected_pixel);
358
359
360//!@}
361
362//=------------------------------------------------------------
363//!@subsection Log of this file.
364
365//!@{
366
367/*
368 *$Log: not supported by cvs2svn $
369 *Revision 1.22 2004/09/17 14:48:21 moralejo
370 *
371 *Changes to adapt headers to c++ style.
372 *
373 *Revision 1.21 2004/09/16 15:24:53 moralejo
374 *Updated on CVS after long time...
375 *
376 *
377 *Revision 1.19 2003/10/17 19:39:30 blanch
378 *Factor used for the NSB scaling for several qe files is defined.
379 *
380 *Revision 1.18 2003/09/15 10:06:47 blanch
381 *Header file for camera 1.58
382 *Number of CT is passed in some subroutines.
383 *MGeomCam is passed instead of MGeomCam magic to allow diferent camera
384 *geometries.
385 *
386 *Revision 1.17 2003/07/17 18:03:03 blanch
387 *Header file for camera 1.57
388 *
389 *Revision 1.15 2003/01/07 16:34:09 blanch
390 *Header file for camera.cxx version 1.50.
391 *
392 *Revision 1.14 2002/12/12 17:41:13 blanch
393 **** empty log message ***
394 *
395 *Revision 1.13 2002/12/10 17:20:32 blanch
396 **** empty log message ***
397 *
398 *Revision 1.12 2002/10/29 17:16:28 blanch
399 *Header file for camera.cxx version 1.45
400 *
401 *Revision 1.11 2002/10/18 16:53:30 blanch
402 *Modification to read several reflector version files.
403 *
404 *Revision 1.10 2002/09/09 16:01:12 blanch
405 *Header file of camera.cxx 1.42.
406 *
407 *Revision 1.9 2002/09/04 09:59:07 blanch
408 *Modifications to use MGeomCam from MARS.
409 *
410 *Revision 1.8 2002/07/16 16:20:23 blanch
411 *Modifications done for the camera.cxx version, where a first implementation
412 *of the Star Field Rotation has been introduced.
413 *
414 *Revision 1.7 2002/03/15 16:06:53 blanch
415 *Library time.h has been added.
416 *
417 *Revision 1.6 2001/04/09 14:39:47 magicsol
418 *Flag that indicates version of reflector format to read: REFL_VERSION has
419 *changed from 0.3 to 0.4.
420 *
421 *Revision 1.5 2000/05/11 13:58:42 blanch
422 *This version of camera.h owns to the version 1.8 of camera.cxx.
423 *
424 *Revision 1.4 2000/02/18 17:42:39 petry
425 *This version includes drastic changes and belongs to camera.cxx 1.5.
426 *It is not yet finished and not immediately useful because the
427 *trigger simulation is not yet re-implemented. I had to take it
428 *out together with some other stuff in order to tidy the whole
429 *program up. This is not meant as an insult to anyone. I needed
430 *to do this in order to be able to work on it.
431 *
432 *This version has been put in the repository in order to be
433 *able to share the further development with others.
434 *
435 *If you need something working, wait or take an earlier one.
436 *See file README.
437 *
438 *Revision 1.3 1999/11/11 20:29:29 harald
439 *Small changes to run the new version on a linux machine.
440 *
441 *Revision 1.2 1999/11/10 07:42:41 harald
442 *Small change to read the right data files in.
443 *
444 *Revision 1.1.1.1 1999/11/05 11:59:31 harald
445 *This the starting point for CVS controlled further developments of the
446 *camera program. The program was originally written by Jose Carlos.
447 *But here you can find a "rootified" version to the program. This means
448 *that there is no hbook stuff in it now. Also the output of the
449 *program changed to the MagicRawDataFormat.
450 *
451 *The "rootification" was done by Dirk Petry and Harald Kornmayer.
452 *
453 *Revision 1.3 1999/10/22 15:32:56 petry
454 *tidied-up version, really sent to H.K. and N.M., 22-10-99
455 *
456 *Revision 1.2 1999/10/22 15:01:28 petry
457 *version sent to H.K. and N.M. on Fri Oct 22 1999
458 *
459 *Revision 1.1.1.1 1999/10/21 16:35:10 petry
460 *first synthesised version
461 *
462 * Revision 1.8 1999/03/15 14:59:06 gonzalez
463 * camera-1_1
464 *
465 * Revision 1.7 1999/03/02 09:56:11 gonzalez
466 * *** empty log message ***
467 *
468 * Revision 1.6 1999/01/14 17:32:40 gonzalez
469 * Added to camera the STDIN input option (data_from_input)
470 *
471 */
472
473//!@}
474//=EOF
Note: See TracBrowser for help on using the repository browser.