Index: trunk/MagicSoft/Simulation/Detector/Camera/camera.h
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Camera/camera.h	(revision 365)
+++ trunk/MagicSoft/Simulation/Detector/Camera/camera.h	(revision 366)
@@ -19,7 +19,7 @@
 //=
 //= $RCSfile: camera.h,v $
-//= $Revision: 1.3 $
-//= $Author: harald $ 
-//= $Date: 1999-11-11 20:29:29 $
+//= $Revision: 1.4 $
+//= $Author: petry $ 
+//= $Date: 2000-02-18 17:42:39 $
 //=
 //=//////////////////////////////////////////////////////////////////////
@@ -61,8 +61,7 @@
 #include "moments.h"
 
-#include "lagrange.h"
-
 #include "MCEventHeader.hxx"
 #include "MCCphoton.hxx"
+#include "MTrigger.hxx"
 
 // command line options available
@@ -96,7 +95,9 @@
 //!@{
 
-#define SLICES            100
+#define SLICES            19
 #define WIDTH_TIMESLICE   3.3
  
+#define NOTIME 999999999
+
 #define SIN60   0.866025403784439
 #define COS60   0.500000000000000
@@ -104,20 +105,28 @@
 #define RandomNumber  drand48()
 
-#define PIX_ARRAY_SIDE       40
-#define PIX_ARRAY_HALF_SIDE  20
-#define PIXNUM               0
-#define PIXX                 1
-#define PIXY                 2
-
 #define iMAXNUMPIX  595 // total maximum possible number of pixels in the camera
 
-//@ the trigger threshold up to which the maximum passable threshold is tested 
-#define iMAX_THRESHOLD_PHE   50 
-
-//@ number of the 1st. pixel of a sector s in a ring r (central pixel: ring=0)
-#define FIRST_PIXEL(r,s)   ( ((r)>0) ? (3*(r)*((r)-1) + (r)*(s) + 1) : 0 )
-
-//@ number of the pixels include in a camera of r pixels
-#define NUMBER_PIXELS(r)   ( ((r)>0) ? FIRST_PIXEL((r)+1,0) : 1 )
+#define iMAXNUMPHE 50000 // maximum total number of photoelectrons in one event
+
+#define iNUMNSBPRODCALLS 1  // in order to average over the QE simulation, call the
+                            // phe production function for the NSB iNUMNSBPRODCALLS times
+
+#define iNUMWAVEBANDS 5  // number of wavebands for the NSB simulation
+
+#define WAVEBANDBOUND1 290. // iNUMWAVEBANDS+1 boundaries for waveband definitions (nm)
+#define WAVEBANDBOUND2 310. // for the NSB generation
+#define WAVEBANDBOUND3 400.
+#define WAVEBANDBOUND4 500.
+#define WAVEBANDBOUND5 600.
+#define WAVEBANDBOUND6 800.
+
+#define EXTWAVEBAND1 3.715  // iNUMWAVEBANDS extinction values in magnitudes per airmass
+#define EXTWAVEBAND2 0.642  // - these values were taken from D.L. King, Isaac Newton Group
+#define EXTWAVEBAND3 0.209  // Tech Note No. 31, they are for a clear night at the ORM,
+#define EXTWAVEBAND4 0.107  // La Palma. The values were averaged in the given wavebands
+#define EXTWAVEBAND5 0.053
+
+#define SIMTIMEOFFSET_NS 5  // determines how many ns before the first and after the last
+                            // shower photoelectron, there should be NSB photoelectrons 
 
 //@ now we define the list CT_ITEM_LIST of possible items in the CT def. file
@@ -225,7 +234,14 @@
   double dxpointcorr_deg; /* correction of the pixel coordinates; to be added to dxc[] to get correct value */
   double dypointcorr_deg; /* correction of the pixel coordinates; to be added to dxc[] to get correct value */
-  double di[iMAXNUMPIX]; /* i coordinate in JCs bi-axis hexagonal coordinate system */
-  double dj[iMAXNUMPIX]; /* j coordinate in JCs bi-axis hexagonal coordinate system */
  
+};
+
+class Photoelectron{
+ public:
+  int iarrtime_ns; // arrival time taken from the corresponding photon
+  int ipixnum;     // pixel in which the phe was evoked (starts at 0)
+  
+  Photoelectron(); // constructor (code in camera.cxx)
+
 };
 
@@ -268,5 +284,36 @@
                 float l, float m, float n,
                 float x, float y, float z);
-     
+int check_reflector_file(FILE *infile);
+float lin_interpol(float x1, float y1, float x2, float y2, float x);
+int produce_phes( FILE *sp, // the input file
+		  struct camera *cam, // the camera layout
+		  float minwl_nm, // the minimum accepted wavelength
+		  float maxwl_nm, // the maximum accepted wavelength
+		  class Photoelectron phe[iMAXNUMPHE], // the generated phes
+		  int *itotnphe, // total number of produced photoelectrons
+		  float *nphe, // number of photoelectrons in each pixel
+		  int *incph,    // total number of cph read
+		  float *tmin_ns,   // minimum arrival time of all phes
+		  float *tmax_ns    // maximum arrival time of all phes
+		  );
+
+int produce_nsbrates( char *inname,
+		      struct camera *cam,
+		      class Photoelectron phe[iMAXNUMPHE],
+		      float nsbrate[][iNUMWAVEBANDS]
+		      );
+
+int produce_nsb_phes( float *atmin_ns,
+		      float *atmax_ns,
+		      float theta_rad,
+		      struct camera *cam,
+		      float nsbr_phepns[iMAXNUMPIX][iNUMWAVEBANDS],
+		      float dnsb_phepns[iMAXNUMPIX],
+		      float extinction[iNUMWAVEBANDS],
+		      float fnpx[iMAXNUMPIX],
+		      Photoelectron photo[iMAXNUMPHE],
+		      int *inphe,
+		      float base_mv[iMAXNUMPIX]); 
+
 //!@}
 
@@ -278,4 +325,7 @@
 /*
  *$Log: not supported by cvs2svn $
+ *Revision 1.3  1999/11/11 20:29:29  harald
+ *Small changes to run the new version on a linux machine.
+ *
  *Revision 1.2  1999/11/10 07:42:41  harald
  *Small change to read the right data files in.
@@ -290,218 +340,4 @@
  *The "rootification" was done by Dirk Petry and Harald Kornmayer. 
  *
- *In the following you can see the README file of that version:
- *
- *==================================================
- *
- *Fri Oct 22  1999   D.P.
- *
- *The MAGIC Monte Carlo System
- *
- *Camera Simulation Programme
- *---------------------------
- *
- *1) Description
- *
- *This version is the result of the fusion of H.K.'s
- *root_camera which is described below (section 2)
- *and another version by D.P. which had a few additional
- *useful features.
- *
- *The version compiles under Linux with ROOT 2.22 installed
- *(variable ROOTSYS has to be set).
- *
- *Compile as before simply using "make" in the root_camera
- *directory.
- *
- *All features of H.K.'s root_camera were retained.
- *
- *Additional features of this version are:
- *
- *  a) HBOOK is no longer used and all references are removed.
- *
- *  b) Instead of HBOOK, the user is given now the possibility of 
- *     having Diagnostic data in ROOT format as a complement
- *     to the ROOT Raw data.
- *
- *     This data is written to the file which is determined by
- *     the new input parameter "diag_file" in the camera parameter
- *     file.
- *
- *     All source code file belonging to this part have filenames
- *     starting with "MDiag".
- *
- *     The user can read the output file using the following commands
- *     in an interactive ROOT session:
- *
- *       	root [0] .L MDiag.so
- *	root [1] new TFile("diag.root");
- *	root [2] new TTreeViewer("T");
- *	
- *     This brings up a viewer from which all variables of the
- *     TTree can be accessed and histogrammed. This example
- *     assumes that you have named the file "diag.root", that
- *     you are using ROOT version 2.22 or later and that you have
- *     the shared object library "MDiag.so" which is produced
- *     by the Makefile along with the executable "camera".
- *       
- * !   The contents of the so-called diag file is not yet fixed.
- * !   At the moment it is what J.C.G. used to put into the HBOOK
- * !   ntuple. In future versions the moments calculation can be
- * !   removed and the parameter list be modified correspondingly.
- *
- *  c) Now concatenated reflector files can be read. This is useful
- *     if you have run the reflector with different parameters but
- *     you want to continue the analysis with all reflector data
- *     going into ONE ROOT outputfile.
- *
- *     The previous camera version contained a bug which made reading 
- *     of two or more concatenated reflector files impossible.
- *
- *  d) The reflector output format was changed. It is now version
- *     0.4 .
- *     The change solely consists in a shortening of the flag
- *     definition in the file 
- *
- *           include-MC/MCCphoton.hxx  
- *
- * !   IF YOU WANT TO READ REFLECTOR FORMAT 0.3, you can easily
- * !   do so by recompiling camera with the previous version of
- * !   include-MC/MCCphoton.hxx.
- *
- *     The change was necessary for saving space and better
- *     debugging. From now on, this format can be frozen.
- *
- * !   For producing reflector output in the new format, you
- * !   of course have to recompile your reflector with the
- * !   new include-MC/MCCphoton.hxx .
- *
- *  e) A first version of the pixelization with the larger
- *     outer pixels is implemented. THIS IS NOT YET FULLY
- *     TESTED, but first rough tests show that it works
- *     at least to a good approximation.
- *
- *     The present version implements the camera outline
- *     with 18 "gap-pixels" and 595 pixels in total as
- *     shown in 
- *
- *        http://sarastro.ifae.es/internal/home/hardware/camera/numbering.ps
- *
- *     This change involved 
- *
- *	(i) The file pixels.dat is no longer needed. Instead
- *          the coordinates are generated by the program itself
- *          (takes maybe 1 second). In the file 
- *
- *		pixel-coords.txt
- *
- *	  in the same directory as this README, you find a list
- *          of the coordinates generated by this new routine. It
- *          has the format
- *
- *              number   i   j   x  y  size-factor
- *
- *          where i and j are J.C.G.'s so called biaxis hexagonal
- *          coordinates (for internal use) and x and y are the
- *          coordinates of the pixel centers in the standard camera
- *          coordinate system in units of centimeters. The value
- *          of "size-factor" determines the linear size of the pixel
- *          relative to the central pixels. 
- *
- *        (ii) The magic.def file has two additional parameters
- *          which give the number of central pixels and the
- *          number of gap pixels
- *
- *        (iii) In camera.h and camera.cxx several changes were 
- *          necessary, among them the introduction of several
- *          new functions 
- *
- *     The newly suggested outline with asymmetric Winston cones
- *     will be implemented in a later version.
- *
- *  f) phe files can no longer be read since this contradicts
- *     our philosophy that the analysis should be done with other
- *     programs like e.g. EVITA and not with "camera" itself.
- *     This possibility was removed. 
- *
- *  g) ROOT is no longer invoked with an interactive interface.
- *     In this way, camera can better be run as a batch program and
- *     it uses less memory.
- *
- *  h) small changes concerning the variable "t_chan" were necessary in
- *     order to avoid segmentation faults: The variable is used as an
- *     index and it went sometimes outside the limits when camera
- *     was reading proton data. This is because the reflector files
- *     don't contain the photons in a chronological order and also
- *     the timespread can be considerably longer that the foreseen
- *     digitisation timespan. Please see the source code of camera.cxx
- *     round about line 1090.
- *
- *  j) several unused variables were removed, a few warning messages
- *     occur when you compile camera.cxx but these can be ignored at
- *     the moment.
- *
- *In general the program is of course not finished. It still needs
- *debugging, proper trigger simulation, simulation of the asymmetric
- *version of the outer pixels, proper NSB simulation, adaption of
- *the diag "ntuple" contents to our need and others small improvements.
- *
- *In the directory rfl-files there is now a file in reflector format 0.4
- *containing a single event produced by the starfiled adder. It has
- *a duration of 30 ns and represents the region around the Crab Nebula.
- *Using the enclosed input parameter file, camera should process this
- *file without problems.
- *
- *2) The README for the previous version of root_camera
- *
- *README for a preliminary version of the 
- *root_camera program. 
- *
- *root_camera is based on the program "camera"of Jose Carlos
- *Gonzalez. It was changed in the way that only the pixelisation 
- *and the distibution of the phe to the FADCs works in a 
- *first version. 
- *
- *Using the #undef command most possibilities of the orignal 
- *program are switched of. 
- *
- *The new parts are signed by 
- *
- *- ROOT or __ROOT__ 
- *  nearly all  important codelines for ROOT output are enclosed 
- *  in structures like 
- *  #ifdef __ROOT__ 
- *  
- *    code 
- *
- *  #endif __ROOT__ 
- *
- *  In same case the new lines are signed by a comment with the word 
- *  ROOT in it. 
- *
- *  For timing of the pulse some variable names are changed. 
- *  (t0, t1, t  -->  t_ini, t_fin, t_1st, t_chan,...) 
- *  Look also for this changes. 
- *
- *  For the new root-file is also a change in readparm-files
- *
- *
- *- __DETAIL_TRIGGER__
- *
- *  This is for the implementation of the current work on trigger 
- *  studies. Because the class MTrigger is not well documented it 
- *  isn´t a part of this tar file. Only a dummy File exists. 
- *
- *
- *
- *With all files in the archive, the root_camera program should run. 
- *
- *A reflector file is in the directory rfl-files
- *
- *==================================================
- *
- *From now on, use CVS for development!!!!
- *
- *
- *
  *Revision 1.3  1999/10/22 15:32:56  petry
  *tidied-up version, really sent to H.K. and N.M., 22-10-99
