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

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