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

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