source: trunk/MagicSoft/Simulation/Detector/TimeCam/timecam.h@ 9391

Last change on this file since 9391 was 353, checked in by harald, 25 years ago
this is just the starting point of the further development of the camera project to simulate MonteCarloShower for MAGIC. The TimeCam is using also the information of the arrival time of the cerenkov photons (or the photoelectrons). This is the status of the program as presented on the general MAGIC meeting in Barcelona! Each one is invited to collaborate!!!
File size: 17.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: timecam.h,v $
21//= $Revision: 1.1.1.1 $
22//= $Author: harald $
23//= $Date: 2000-02-08 15:13:44 $
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.h>
43#include <fstream.h>
44#include <stdlib.h>
45#include <stdio.h>
46#include <string.h>
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
54#include "timecam-v.h"
55
56#include "jcmacros.h"
57#include "jcdebug.h"
58
59#include "creadparam.h"
60#include "atm.h"
61
62#include "lagrange.h"
63
64#include "MCEventHeader.hxx"
65#include "MCCphoton.hxx"
66
67// command line options available
68
69#define COMMAND_LINE_OPTIONS "f:h"
70
71/*@'
72
73 This is C++, but RANLIB routines are written in pure ANSI C.
74 In order to read easily these routines, we must include
75 the following directive
76
77*/
78
79extern "C" {
80#include "ranlib.h"
81}
82
83// version of the reflector program that can read
84
85#define REFL_PROGRAM reflector
86#define REFL_VERSION 0.3
87
88const char REFL_SIGNATURE[] = GLUE_postp( REFL_PROGRAM, REFL_VERSION );
89
90//!@}
91
92//=------------------------------------------------------------
93//!@subsection Macro-definitions, and constants.
94
95//!@{
96#define SIN60 0.866025403784439
97#define COS60 0.500000000000000
98
99#define RandomNumber drand48()
100
101#define PIX_ARRAY_SIDE 40
102#define PIX_ARRAY_HALF_SIDE 20
103#define PIXNUM 0
104#define PIXX 1
105#define PIXY 2
106
107#define iMAXNUMPIX 595 // total maximum possible number of pixels in the camera
108
109//@ the trigger threshold up to which the maximum passable threshold is tested
110#define iMAX_THRESHOLD_PHE 50
111
112//@ number of the 1st. pixel of a sector s in a ring r (central pixel: ring=0)
113#define FIRST_PIXEL(r,s) ( ((r)>0) ? (3*(r)*((r)-1) + (r)*(s) + 1) : 0 )
114
115//@ number of the pixels include in a camera of r pixels
116#define NUMBER_PIXELS(r) ( ((r)>0) ? FIRST_PIXEL((r)+1,0) : 1 )
117
118//@ now we define the list CT_ITEM_LIST of possible items in the CT def. file
119#define CT_ITEM_LIST /* LIST OF ITEMS IN THE CT DEFINITION FILE */ \
120T(type), /* type of definition file */ \
121T(focal_distance), /* std(focal distance) */ \
122T(focal_std), /* focal distance */ \
123T(point_spread), /* std(point spread) */ \
124T(point_std), /* point spread */ \
125T(adjustment_dev), /* std of adjustment deviation */ \
126T(black_spot), /* radius of the black spot in center of mirror */ \
127T(n_mirrors), /* number of mirrors */ \
128T(r_mirror), /* radius of one mirror */ \
129T(camera_width), /* camera width */ \
130T(n_pixels), /* total number of pixels in the camera */ \
131T(n_centralpixels), /* number of central pixels in the camera */ \
132T(n_gappixels), /* number of gap pixels in the camera */ \
133T(pixel_width), /* pixel width */ \
134T(define_mirrors) /* this entry is followed by the def. of pixels */
135
136#define T(x) x //@< define T() as the name as it is
137
138enum CT_ITEM_TYPE {
139 CT_ITEM_LIST
140};
141
142#undef T
143
144#define T(x) #x //@< define T() as the string of x
145
146const char *const CT_ITEM_NAMES[] = {
147 CT_ITEM_LIST
148};
149
150#undef T
151
152
153// TYPE=0 (CT1)
154// i s rho theta x y z thetan phin xn yn zn
155//
156// i : number of the mirror
157// s : arc length [cm]
158// rho : polar rho of the position of the center of the mirror [cm]
159// theta : polar angle of the position of the center of the mirror [cm]
160// x : x coordinate of the center of the mirror [cm]
161// y : y coordinate of the center of the mirror [cm]
162// z : z coordinate of the center of the mirror [cm]
163// thetan : polar theta angle of the direction where the mirror points to
164// phin : polar phi angle of the direction where the mirror points to
165// xn : xn coordinate of the normal vector in the center (normalized)
166// yn : yn coordinate of the normal vector in the center (normalized)
167// zn : zn coordinate of the normal vector in the center (normalized)
168//
169// TYPE=1 (MAGIC)
170// i f sx sy x y z thetan phin
171//
172// i : number of the mirror
173// f : focal distance of that mirror
174// sx : curvilinear coordinate of mirror's center in X[cm]
175// sy : curvilinear coordinate of mirror's center in X[cm]
176// x : x coordinate of the center of the mirror [cm]
177// y : y coordinate of the center of the mirror [cm]
178// z : z coordinate of the center of the mirror [cm]
179// thetan : polar theta angle of the direction where the mirror points to
180// phin : polar phi angle of the direction where the mirror points to
181// xn : xn coordinate of the normal vector in the center (normalized)
182// yn : yn coordinate of the normal vector in the center (normalized)
183// zn : zn coordinate of the normal vector in the center (normalized)
184
185#define CT_I 0
186
187#define CT_S 1
188#define CT_RHO 2
189#define CT_THETA 3
190
191#define CT_FOCAL 1
192#define CT_SX 2
193#define CT_SY 3
194
195#define CT_X 4
196#define CT_Y 5
197#define CT_Z 6
198#define CT_THETAN 7
199#define CT_PHIN 8
200#define CT_XN 9
201#define CT_YN 10
202#define CT_ZN 11
203
204#define CT_NDATA 12
205
206//!@}
207
208//=------------------------------------------------------------
209//!@subsection data types
210
211struct camera { /* camera parameters for imaging */
212 int inumpixels;
213 int inumcentralpixels;
214 int inumgappixels;
215 int inumbigpixels;
216 double dpixdiameter_cm; /* diameter of the central and gap pixels in centimeters */
217 double dpixsizefactor[iMAXNUMPIX]; /* size of the pixel relative to dpixdiameter_deg */
218 double dxc[iMAXNUMPIX]; /* Pixel coordinates in camera coordinate system (x points from pixel 1 to 2). */
219 double dyc[iMAXNUMPIX]; /* The numbering of the pixels in these arrays starts at 0! */
220 double dxpointcorr_deg; /* correction of the pixel coordinates; to be added to dxc[] to get correct value */
221 double dypointcorr_deg; /* correction of the pixel coordinates; to be added to dxc[] to get correct value */
222 double di[iMAXNUMPIX]; /* i coordinate in JCs bi-axis hexagonal coordinate system */
223 double dj[iMAXNUMPIX]; /* j coordinate in JCs bi-axis hexagonal coordinate system */
224
225};
226
227
228//=------------------------------------------------------------
229//!@subsection Pre-defined file names.
230
231//!@{
232
233#define QE_FILE "../Data/qe.dat"
234
235//!@}
236
237//=------------------------------------------------------------
238//!@subsection Prototypes of functions.
239
240//!@{
241
242//++
243// prototypes
244//--
245
246#define ONoff(x) ((x==TRUE) ? "[ ON ]" : "[ off]")
247
248// Under Linux, the nint function does not exist, so we have to define it.
249#define nint(x) ((int)floor((x)+0.5))
250
251void present(void);
252void usage(void);
253void clean(void);
254void log(const char *funct, char *fmt, ...);
255void error(const char *funct, char *fmt, ...);
256int isA( char * s1, const char * flag );
257void read_ct_file(void);
258int igen_pixel_coordinates(struct camera *cam);
259void read_pixels(struct camera *cam);
260int pixels_are_neig(int pix1, int pix2);
261int bpoint_is_in_pix(double dx, double dy, int ipixnum, struct camera *pcam);
262float dist_r_P(float a, float b, float c,
263 float l, float m, float n,
264 float x, float y, float z);
265
266//!@}
267
268//=------------------------------------------------------------
269//!@subsection Log of this file.
270
271//!@{
272
273/*
274 *$Log: not supported by cvs2svn $
275 *Revision 1.3 1999/11/11 20:29:29 harald
276 *Small changes to run the new version on a linux machine.
277 *
278 *Revision 1.2 1999/11/10 07:42:41 harald
279 *Small change to read the right data files in.
280 *
281 *Revision 1.1.1.1 1999/11/05 11:59:31 harald
282 *This the starting point for CVS controlled further developments of the
283 *camera program. The program was originally written by Jose Carlos.
284 *But here you can find a "rootified" version to the program. This means
285 *that there is no hbook stuff in it now. Also the output of the
286 *program changed to the MagicRawDataFormat.
287 *
288 *The "rootification" was done by Dirk Petry and Harald Kornmayer.
289 *
290 *In the following you can see the README file of that version:
291 *
292 *==================================================
293 *
294 *Fri Oct 22 1999 D.P.
295 *
296 *The MAGIC Monte Carlo System
297 *
298 *Camera Simulation Programme
299 *---------------------------
300 *
301 *1) Description
302 *
303 *This version is the result of the fusion of H.K.'s
304 *root_camera which is described below (section 2)
305 *and another version by D.P. which had a few additional
306 *useful features.
307 *
308 *The version compiles under Linux with ROOT 2.22 installed
309 *(variable ROOTSYS has to be set).
310 *
311 *Compile as before simply using "make" in the root_camera
312 *directory.
313 *
314 *All features of H.K.'s root_camera were retained.
315 *
316 *Additional features of this version are:
317 *
318 * a) HBOOK is no longer used and all references are removed.
319 *
320 * b) Instead of HBOOK, the user is given now the possibility of
321 * having Diagnostic data in ROOT format as a complement
322 * to the ROOT Raw data.
323 *
324 * This data is written to the file which is determined by
325 * the new input parameter "diag_file" in the camera parameter
326 * file.
327 *
328 * All source code file belonging to this part have filenames
329 * starting with "MDiag".
330 *
331 * The user can read the output file using the following commands
332 * in an interactive ROOT session:
333 *
334 * root [0] .L MDiag.so
335 * root [1] new TFile("diag.root");
336 * root [2] new TTreeViewer("T");
337 *
338 * This brings up a viewer from which all variables of the
339 * TTree can be accessed and histogrammed. This example
340 * assumes that you have named the file "diag.root", that
341 * you are using ROOT version 2.22 or later and that you have
342 * the shared object library "MDiag.so" which is produced
343 * by the Makefile along with the executable "camera".
344 *
345 * ! The contents of the so-called diag file is not yet fixed.
346 * ! At the moment it is what J.C.G. used to put into the HBOOK
347 * ! ntuple. In future versions the moments calculation can be
348 * ! removed and the parameter list be modified correspondingly.
349 *
350 * c) Now concatenated reflector files can be read. This is useful
351 * if you have run the reflector with different parameters but
352 * you want to continue the analysis with all reflector data
353 * going into ONE ROOT outputfile.
354 *
355 * The previous camera version contained a bug which made reading
356 * of two or more concatenated reflector files impossible.
357 *
358 * d) The reflector output format was changed. It is now version
359 * 0.4 .
360 * The change solely consists in a shortening of the flag
361 * definition in the file
362 *
363 * include-MC/MCCphoton.hxx
364 *
365 * ! IF YOU WANT TO READ REFLECTOR FORMAT 0.3, you can easily
366 * ! do so by recompiling camera with the previous version of
367 * ! include-MC/MCCphoton.hxx.
368 *
369 * The change was necessary for saving space and better
370 * debugging. From now on, this format can be frozen.
371 *
372 * ! For producing reflector output in the new format, you
373 * ! of course have to recompile your reflector with the
374 * ! new include-MC/MCCphoton.hxx .
375 *
376 * e) A first version of the pixelization with the larger
377 * outer pixels is implemented. THIS IS NOT YET FULLY
378 * TESTED, but first rough tests show that it works
379 * at least to a good approximation.
380 *
381 * The present version implements the camera outline
382 * with 18 "gap-pixels" and 595 pixels in total as
383 * shown in
384 *
385 * http://sarastro.ifae.es/internal/home/hardware/camera/numbering.ps
386 *
387 * This change involved
388 *
389 * (i) The file pixels.dat is no longer needed. Instead
390 * the coordinates are generated by the program itself
391 * (takes maybe 1 second). In the file
392 *
393 * pixel-coords.txt
394 *
395 * in the same directory as this README, you find a list
396 * of the coordinates generated by this new routine. It
397 * has the format
398 *
399 * number i j x y size-factor
400 *
401 * where i and j are J.C.G.'s so called biaxis hexagonal
402 * coordinates (for internal use) and x and y are the
403 * coordinates of the pixel centers in the standard camera
404 * coordinate system in units of centimeters. The value
405 * of "size-factor" determines the linear size of the pixel
406 * relative to the central pixels.
407 *
408 * (ii) The magic.def file has two additional parameters
409 * which give the number of central pixels and the
410 * number of gap pixels
411 *
412 * (iii) In camera.h and camera.cxx several changes were
413 * necessary, among them the introduction of several
414 * new functions
415 *
416 * The newly suggested outline with asymmetric Winston cones
417 * will be implemented in a later version.
418 *
419 * f) phe files can no longer be read since this contradicts
420 * our philosophy that the analysis should be done with other
421 * programs like e.g. EVITA and not with "camera" itself.
422 * This possibility was removed.
423 *
424 * g) ROOT is no longer invoked with an interactive interface.
425 * In this way, camera can better be run as a batch program and
426 * it uses less memory.
427 *
428 * h) small changes concerning the variable "t_chan" were necessary in
429 * order to avoid segmentation faults: The variable is used as an
430 * index and it went sometimes outside the limits when camera
431 * was reading proton data. This is because the reflector files
432 * don't contain the photons in a chronological order and also
433 * the timespread can be considerably longer that the foreseen
434 * digitisation timespan. Please see the source code of camera.cxx
435 * round about line 1090.
436 *
437 * j) several unused variables were removed, a few warning messages
438 * occur when you compile camera.cxx but these can be ignored at
439 * the moment.
440 *
441 *In general the program is of course not finished. It still needs
442 *debugging, proper trigger simulation, simulation of the asymmetric
443 *version of the outer pixels, proper NSB simulation, adaption of
444 *the diag "ntuple" contents to our need and others small improvements.
445 *
446 *In the directory rfl-files there is now a file in reflector format 0.4
447 *containing a single event produced by the starfiled adder. It has
448 *a duration of 30 ns and represents the region around the Crab Nebula.
449 *Using the enclosed input parameter file, camera should process this
450 *file without problems.
451 *
452 *2) The README for the previous version of root_camera
453 *
454 *README for a preliminary version of the
455 *root_camera program.
456 *
457 *root_camera is based on the program "camera"of Jose Carlos
458 *Gonzalez. It was changed in the way that only the pixelisation
459 *and the distibution of the phe to the FADCs works in a
460 *first version.
461 *
462 *Using the #undef command most possibilities of the orignal
463 *program are switched of.
464 *
465 *The new parts are signed by
466 *
467 *- ROOT or __ROOT__
468 * nearly all important codelines for ROOT output are enclosed
469 * in structures like
470 * #ifdef __ROOT__
471 *
472 * code
473 *
474 * #endif __ROOT__
475 *
476 * In same case the new lines are signed by a comment with the word
477 * ROOT in it.
478 *
479 * For timing of the pulse some variable names are changed.
480 * (t0, t1, t --> t_ini, t_fin, t_1st, t_chan,...)
481 * Look also for this changes.
482 *
483 * For the new root-file is also a change in readparm-files
484 *
485 *
486 *- __DETAIL_TRIGGER__
487 *
488 * This is for the implementation of the current work on trigger
489 * studies. Because the class MTrigger is not well documented it
490 * isn´t a part of this tar file. Only a dummy File exists.
491 *
492 *
493 *
494 *With all files in the archive, the root_camera program should run.
495 *
496 *A reflector file is in the directory rfl-files
497 *
498 *==================================================
499 *
500 *From now on, use CVS for development!!!!
501 *
502 *
503 *
504 *Revision 1.3 1999/10/22 15:32:56 petry
505 *tidied-up version, really sent to H.K. and N.M., 22-10-99
506 *
507 *Revision 1.2 1999/10/22 15:01:28 petry
508 *version sent to H.K. and N.M. on Fri Oct 22 1999
509 *
510 *Revision 1.1.1.1 1999/10/21 16:35:10 petry
511 *first synthesised version
512 *
513 * Revision 1.8 1999/03/15 14:59:06 gonzalez
514 * camera-1_1
515 *
516 * Revision 1.7 1999/03/02 09:56:11 gonzalez
517 * *** empty log message ***
518 *
519 * Revision 1.6 1999/01/14 17:32:40 gonzalez
520 * Added to camera the STDIN input option (data_from_input)
521 *
522 */
523
524//!@}
525//=EOF
526
Note: See TracBrowser for help on using the repository browser.