Index: trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 2351)
+++ trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 2352)
@@ -21,7 +21,7 @@
 //
 // $RCSfile: camera.cxx,v $
-// $Revision: 1.59 $
+// $Revision: 1.60 $
 // $Author: blanch $ 
-// $Date: 2003-09-22 11:38:47 $
+// $Date: 2003-09-23 16:50:55 $
 //
 ////////////////////////////////////////////////////////////////////////
@@ -134,65 +134,16 @@
   @"*/
 
+/*!@"
+
+  And this is the information about the whole telescope.
+
+  @"*/
+
 //!@{
-static int   ct_Type;         //@< Type of telescope: 0:CT1, 1:MAGIC
-//!@}
-
-/*!@"
-
-  And this is the information about the whole telescope.
-
-  @"*/
-
-//!@{
 
 // parameters of the CT (from the CT definition file) 
-
-////@: Focal distances [cm]
-//static float *ct_Focal;       
-
-//@: Mean Focal distances [cm]
-static float ct_Focal_mean;   
-
-//@: STDev. Focal distances [cm]
-static float ct_Focal_std;    
-
-//@: Mean Point Spread function [cm]
-static float ct_PSpread_mean; 
-
-//@: STDev. Point Spread function [cm]
-static float ct_PSpread_std;  
-
-//@: STDev. Adjustmente deviation [cm]
-static float ct_Adjustment_std; 
-
-//@: Radius of the Black Spot in mirror [cm]
-static float ct_BlackSpot_rad;
-
-//@: Radius of one mirror [cm]
-static float ct_RMirror;      
-
-//@: Camera width [cm]
-static float ct_CameraWidth;  
-
-//@: Pixel width [cm]
-static float ct_PixelWidth;   
-
-//@: ct_PixelWidth_corner_2_corner = ct_PixelWidth / cos(60)
-static float ct_PixelWidth_corner_2_corner; 
-
-//@: Number of mirrors
-static int ct_NMirrors = 0;   
 
 //@: Number of pixels
 static int ct_NPixels;        
-
-//@: Number of pixels
-static int ct_NCentralPixels;        
-
-//@: Number of pixels
-static int ct_NGapPixels;        
-
-//@: name of the CT definition file to use
-static char ct_filename[256];  
 
 //@: Number of CT
@@ -286,7 +237,4 @@
 
 
-//@: coordinates x,y for each pixel
-static float **pixary;  
-
 //@: contents of the pixels (ph.e.)
 static float *fnpix;    
@@ -331,44 +279,4 @@
 
   @"*/
-
-//!@{
-// Pointer to a table with the following info.:
-
-static float **ct_data;       
-
-/*
- *  TYPE=0  (CT1)
- *      i   s   rho   theta   x   y   z   thetan  phin  xn   yn   zn
- * 
- *       i : number of the mirror
- *       s : arc length [cm]
- *     rho : polar rho of the position of the center of the mirror [cm]
- *   theta : polar angle of the position of the center of the mirror [cm]
- *       x : x coordinate of the center of the mirror [cm]
- *       y : y coordinate of the center of the mirror [cm]
- *       z : z coordinate of the center of the mirror [cm]
- *  thetan : polar theta angle of the direction where the mirror points to
- *    phin : polar phi angle of the direction where the mirror points to
- *      xn : xn coordinate of the normal vector in the center (normalized)
- *      yn : yn coordinate of the normal vector in the center (normalized)
- *      zn : zn coordinate of the normal vector in the center (normalized)
- * 
- *  TYPE=1  (MAGIC)
- *      i  f   sx   sy   x   y   z   thetan  phin 
- * 
- *       i : number of the mirror
- *       f : focal distance of that mirror
- *      sx : curvilinear coordinate of mirror's center in X[cm]
- *      sy : curvilinear coordinate of mirror's center in X[cm]
- *       x : x coordinate of the center of the mirror [cm]
- *       y : y coordinate of the center of the mirror [cm]
- *       z : z coordinate of the center of the mirror [cm]
- *  thetan : polar theta angle of the direction where the mirror points to
- *    phin : polar phi angle of the direction where the mirror points to
- *      xn : xn coordinate of the normal vector in the center (normalized)
- *      yn : yn coordinate of the normal vector in the center (normalized)
- *      zn : zn coordinate of the normal vector in the center (normalized)
- */
-//!@} 
 
 /*!@"
@@ -737,5 +645,4 @@
   strcpy( rootname, get_root_filename() );
   strcpy( rootname_loop, get_loop_filename() );
-  strcpy( ct_filename, get_ct_filename() );
   strcpy( nsbpathname, get_nsb_directory() );
   strcpy( nsbpath_outer, get_nsb_directory_outer() );
@@ -753,59 +660,66 @@
 
     Starfield_rotate = get_starfield_rotate();
-    log(SIGNATURE,
-   	"%s:\n\t%20s:  %s\n",
-    	"Starfield Rotate",
-        "Rotate Starfield",  ONoff(Starfield_rotate)
-    	  );
  
   // log filenames information
-
+  for(Int_t ict=0;ict<ct_Number;ict++){
+
+    log(SIGNATURE,"\t%s : %i\n\t%20s:\t%i\n",
+	"------- TELESCOPE ",ict+1,
+	"Geometry ", GeometryCamera[ict]);
+    strcpy( qe_filename, get_qe_filename(ict));
+
+    log(SIGNATURE,
+	"%s:\n\t%20s:\t%s\n\t%20s:\t%s\n\t%20s\n\t%20s:\t%s\n\t%20s:\t%s\n\t%20s:\t%s\n\t%20s:\t%s\n\t%20s:\t%s\n",
+	"Filenames",
+	"In", inname_CT[ict], 
+	"Stars", starfieldname,
+	"NSB database","(inner pixels)", nsbpathname,
+	"(outer pixels)", nsbpath_outer,
+	"QE", qe_filename, 
+	"Data", datname,
+	"ROOT",  rootname 
+	);
+    
+    // log Trigger information
+    
+    if (Trigger_Loop) {
+      log(SIGNATURE,
+	  "%s:\n\t%20s: from %5.2f to %5.2f by %5.2f step\n\t%20s: %i - %i\n\t%20s: %i - %i\n\t%20s\n",
+	  "Trigger Loop mode",
+	  "Threshold",Trigger_loop_lthres,Trigger_loop_uthres,Trigger_loop_sthres,
+	  "Multiplicity",Trigger_loop_lmult,Trigger_loop_umult,
+	  "Topology",Trigger_loop_ltop,Trigger_loop_utop,
+	  rootname_loop);
+    }
+    else if (Individual_Thres_Pixel == FALSE){
+      log(SIGNATURE,
+	  "%s:\n\t%20s: %f\n\t%20s: %i\n\t%20s: %i\n",
+	  "Single Trigger mode",
+	  "Threshold",qThreshold[ict][0],
+	  "Multiplicity",Trigger_multiplicity[ict],
+	  "Topology",Trigger_topology[ict]);
+    }   
+    else{
+      log(SIGNATURE,
+	  "%s:\n\t%20s: %s\n\t%20s: %i\n\t%20s: %i\n",
+	  "Single Trigger mode",
+	  "Threshold","Different for each pixel",
+	  "Multiplicity",Trigger_multiplicity[ict],
+	  "Topology",Trigger_topology[ict]);
+    }
+    log(SIGNATURE,"\t%s\n",
+	"END TELESCOPE --------");
+  }
+  // log flags information
+  
   log(SIGNATURE,
-      "%s:\n\t%20s:\t%s\n\t%20s:\t%s\n\t%20s:\t%s\n\t%20s:\t%s\n\t%20s:\t%s\n\t%20s:\t%s\n\t%20s:\t%s\n",
-      "Filenames",
-      "In", inname_CT[0], 
-      "Stars", starfieldname,
-      "NSB database (inner pixels)", nsbpathname,
-      "NSB database (outer pixels)", nsbpath_outer,
-      "CT", ct_filename, 
-      "Data", datname,
-      "ROOT",  rootname 
-      );
-
-  // log Trigger information
-
-  if (Trigger_Loop) {
-    log(SIGNATURE,
-	"%s:\n\t%20s: from %5.2f to %5.2f by %5.2f step\n\t%20s: %i - %i\n\t%20s: %i - %i\n\t%20s\n",
-	"Trigger Loop mode",
-	"Threshold",Trigger_loop_lthres,Trigger_loop_uthres,Trigger_loop_sthres,
-	"Multiplicity",Trigger_loop_lmult,Trigger_loop_umult,
-	"Topology",Trigger_loop_ltop,Trigger_loop_utop,
-	rootname_loop);
-  }
-  else if (Individual_Thres_Pixel == FALSE){
-    log(SIGNATURE,
-   	"%s:\n\t%20s: %f\n\t%20s: %i\n\t%20s: %i\n",
-    	"Single Trigger mode",
-    	"Threshold",qThreshold[0][0],
-    	"Multiplicity",Trigger_multiplicity[0],
-    	"Topology",Trigger_topology[0]);
-  }   
-  else{
-    log(SIGNATURE,
-   	"%s:\n\t%20s: %s\n\t%20s: %i\n\t%20s: %i\n",
-    	"Single Trigger mode",
-    	"Threshold","Different for each pixel",
-     	"Multiplicity",Trigger_multiplicity[0],
-    	"Topology",Trigger_topology[0]);
-  }
-  // log flags information
-
-  log(SIGNATURE,
-      "%s:\n\t%20s: %s\n\t%20s: %s\n\t%20s: %s\n",
+      "%s:\n\t%20s: %s\n\t%20s: %s\n\t%20s: %s\n\t%20s: %s\n\t%20s: %3.2f(%s) %3.2f(%s) %s\n",
       "Flags",
       "Data_From_STDIN",   ONoff(Data_From_STDIN),  
       "Write_All_Events",  ONoff(Write_All_Images), 
-      "Write_All_Data",    ONoff(Write_All_Data));
+      "Write_All_Data",    ONoff(Write_All_Data),
+      "Rotate Starfield",  ONoff(Starfield_rotate),
+      "Electronic Noise",  Trigger_noise,"trigger", FADC_noise,"fadc",ONoff(addElecNoise)
+      );
 
   // log flags information
@@ -822,7 +736,9 @@
   
   log(SIGNATURE,
-      "%s:\n\t%20s: %f\n",
+      "%s:\n\t%20s: %f: %s\n\t%20s: %f\n",
       "Parameters",
-      "NSB (phes/pixel)", meanNSB, ONoff(simulateNSB));
+      "NSB (phes/pixel)", meanNSB, ONoff(simulateNSB),
+      "Pedestals = ", get_FADC_pedestal()
+      );
   
   // log selections
@@ -881,5 +797,5 @@
   // read parameters from the ct.def file
 
-  read_ct_file();
+  //read_ct_file();
 
   Int_t Lev0, Lev1; 
@@ -2791,237 +2707,4 @@
 
 //!-----------------------------------------------------------
-// @name read_ct_file           
-//                          
-// @desc read CT definition file
-//
-// @date Sat Jun 27 05:58:56 MET DST 1998
-//------------------------------------------------------------
-// @function  
-
-//!@{
-void
-read_ct_file(void)
-{
-  char line[LINE_MAX_LENGTH];    //@< line to get from the ctin
-  char token[ITEM_MAX_LENGTH];   //@< a single token
-  int i, j;                      //@< dummy counters
-
-  log( "read_ct_file", "start.\n" );
-
-  ifstream ctin ( ct_filename );
-
-  if ( ctin.bad() ) 
-    error( "read_ct_file", 
-           "Cannot open CT def. file: %s\n", ct_filename );
-  
-  // loop till the "end" directive is reached
-
-  while (!ctin.eof()) {          
-
-    // get line from stdin
-
-    ctin.getline(line, LINE_MAX_LENGTH);
-
-    // look for each item at the beginning of the line
-
-    for (i=0; i<=define_mirrors; i++) 
-      if (strstr(line, CT_ITEM_NAMES[i]) == line)
-        break;
-    
-    // if it is not a valid line, just ignore it
-
-    if (i == define_mirrors+1) 
-      continue;
-    
-    // case block for each directive
-
-    switch ( i ) {
-
-    case type:                // <type of telescope> (0:CT1 ¦ 1:MAGIC)
-      
-      // get focal distance
-
-      sscanf(line, "%s %d", token, &ct_Type);
-
-      log( "read_ct_file", "<Type of Telescope>: %s\n", 
-           ((ct_Type==0) ? "CT1" : "MAGIC") );
-
-      break;
-
-    case focal_distance:      // <focal distance> [cm]
-      
-      // get focal distance
-
-      sscanf(line, "%s %f", token, &ct_Focal_mean);
-
-      log( "read_ct_file", "<Focal distance>: %f cm\n", ct_Focal_mean );
-
-      break;
-
-    case focal_std:           // s(focal distance) [cm]
-      
-      // get focal distance
-
-      sscanf(line, "%s %f", token, &ct_Focal_std);
-
-      log( "read_ct_file", "s(Focal distance): %f cm\n", ct_Focal_std );
-
-      break;
-
-    case point_spread:        // <point spread> [cm]
-      
-      // get point spread
-
-      sscanf(line, "%s %f", token, &ct_PSpread_mean);
-
-      log( "read_ct_file", "<Point spread>: %f cm\n", ct_PSpread_mean );
-
-      break;
-
-    case point_std:           // s(point spread) [cm]
-      
-      // get point spread
-
-      sscanf(line, "%s %f", token, &ct_PSpread_std);
-
-      log( "read_ct_file", "s(Point spread): %f cm\n", ct_PSpread_std );
-
-      break;
-
-    case adjustment_dev:      // s(adjustment_dev) [cm]
-      
-      // get point spread
-
-      sscanf(line, "%s %f", token, &ct_Adjustment_std);
-
-      log( "read_ct_file", "s(Adjustment): %f cm\n", ct_Adjustment_std );
-
-      break;
-
-    case black_spot:          // radius of the black spot in the center [cm]
-      
-      // get black spot radius
-
-      sscanf(line, "%s %f", token, &ct_BlackSpot_rad);
-
-      log( "read_ct_file", "Radius of the black spots: %f cm\n", 
-           ct_BlackSpot_rad);
-
-      break;
-
-    case r_mirror:            // radius of the mirrors [cm]
-      
-      // get radius of mirror
-
-      sscanf(line, "%s %f", token, &ct_RMirror);
-
-      log( "read_ct_file", "Radii of the mirrors: %f cm\n", ct_RMirror );
-
-      break;
-
-    case n_mirrors:           // number of mirrors
-      
-      // get the name of the output_file from the line
-
-      sscanf(line, "%s %d", token, &ct_NMirrors);
-
-      log( "read_ct_file", "Number of mirrors: %d\n", ct_NMirrors );
-
-      break;
-
-    case camera_width:        // camera width [cm]
-      
-      // get the name of the ct_file from the line
-
-      sscanf(line, "%s %f", token, &ct_CameraWidth);
-
-      log( "read_ct_file", "Camera width: %f cm\n", ct_CameraWidth );
-
-      break;
-
-    case n_pixels:           // number of pixels
-      
-      // get the name of the output_file from the line
-
-      sscanf(line, "%s %d", token, &ct_NPixels);
-
-      log( "read_ct_file", "Number of pixels: %d\n", ct_NPixels );
-
-      break;
-
-    case n_centralpixels:           // number of central pixels
-      
-      // get the name of the output_file from the line
-
-      sscanf(line, "%s %d", token, &ct_NCentralPixels);
-
-      log( "read_ct_file", "Number of central pixels: %d\n", ct_NCentralPixels );
-
-      break;
-
-    case n_gappixels:           // number of gap pixels
-      
-      // get the name of the output_file from the line
-
-      sscanf(line, "%s %d", token, &ct_NGapPixels);
-
-      log( "read_ct_file", "Number of gap pixels: %d\n", ct_NGapPixels );
-
-      break;
-
-    case pixel_width:         // pixel width [cm]
-      
-      // get the name of the ct_file from the line
-
-      sscanf(line, "%s %f", token, &ct_PixelWidth);
-
-      ct_PixelWidth_corner_2_corner = ct_PixelWidth / cos(RAD(30.0));
-
-      log( "read_ct_file", "Pixel width: %f cm\n", ct_PixelWidth );
-
-      break;
-
-    case define_mirrors:      // read table with the parameters of the mirrors
-
-      log( "read_ct_file", "Table of mirrors data:\n" );
-
-      // check whether the number of mirrors was already set
-
-      if ( ct_NMirrors == 0 )
-        error( "read_ct_file", "NMirrors was not set.\n" );
-      
-      // allocate memory for paths list
-
-      log( "read_ct_file", "Allocating memory for ct_data\n" );
-
-      ct_data = new float*[ct_NMirrors];
-
-      for (i=0; i<ct_NMirrors; i++) 
-        ct_data[i] = new float[CT_NDATA];
-
-      // read data
-
-      log( "read_ct_file", "Reading mirrors data...\n" );
-
-      for (i=0; i<ct_NMirrors; i++)
-        for (j=0; j<CT_NDATA; j++)
-          ctin >> ct_data[i][j];
-
-      break;
-
-    } // switch ( i ) 
-
-  } // end while
-
-  // end
-
-  log( "read_ct_file", "done.\n" );
-
-  return;
-}
-//!@}
-
-
-//!-----------------------------------------------------------
 // @name read_QE  
 //                          
@@ -3209,195 +2892,4 @@
 //!@}
 
-//!-----------------------------------------------------------
-// @name read_pixels  
-//                          
-// @desc read pixels data
-//
-// @date Fri Mar 12 16:33:34 MET 1999
-//------------------------------------------------------------
-// @function
-
-//!@{
-void 
-read_pixels(struct camera *pcam)
-{
-  /*  ifstream qefile;
-  char line[LINE_MAX_LENGTH];
-  int n, i, j, icount;
-  float qe;
-
-  //------------------------------------------------------------
-  // first, pixels' coordinates
-
-  pcam->inumpixels = ct_NPixels;
-  pcam->inumcentralpixels = ct_NCentralPixels;
-  pcam->inumgappixels = ct_NGapPixels;
-  pcam->inumbigpixels = ct_NPixels - ct_NCentralPixels - ct_NGapPixels;
-  pcam->dpixdiameter_cm =  ct_PixelWidth; 
-
-  // initialize pixel numbers
-
-  pixary = new float* [2*ct_NCentralPixels];
-  for ( i=0; i<2*ct_NCentralPixels; ++i ) 
-    pixary[i] = new float[2];
-
-  pixneig = new int* [ct_NCentralPixels];
-  for ( i=0; i<ct_NCentralPixels; ++i ) {
-    pixneig[i] = new int[6];
-    for ( j=0; j<6; ++j ) 
-      pixneig[i][j] = -1;
-  }
-
-  npixneig = new int[ct_NCentralPixels];
-  for ( i=0; i<ct_NCentralPixels; ++i ) 
-    npixneig[i] = 0;
-
-  // generate all coordinates
-
-  igen_pixel_coordinates(pcam);
-
-
-  // calculate tables of neighbours
-  
-#ifdef __DEBUG__
-  for ( n=0 ; n<ct_NPixels ; ++n ) {
-    cout << "Para el pixel " << n << ": ";	
-    for ( i=n+1 ; (i<ct_NPixels)&&(npixneig[n]<6) ; ++i) {
-      if ( pixels_are_neig(n,i) == TRUE ) {
-        pixneig[n][npixneig[n]] = i;
-        pixneig[i][npixneig[i]] = n;
-        cout << i << ' ';
-        ++npixneig[n];
-        ++npixneig[i];
-      }
-    }
-    cout << endl << flush;
-  }
-#else // ! __DEBUG__
-  for ( n=0 ; n<ct_NCentralPixels ; ++n ) 
-    for ( i=n+1 ; (i<ct_NCentralPixels)&&(npixneig[n]<6) ; ++i) 
-      if ( pixels_are_neig(n,i) == TRUE ) {
-        pixneig[n][npixneig[n]] = i;
-        pixneig[i][npixneig[i]] = n;
-        ++npixneig[n];
-        ++npixneig[i];
-      }
-#endif // ! __DEBUG__
-  
-#ifdef __DEBUG__
-  for ( n=0 ; n<ct_NPixels ; ++n ) {
-    cout << n << ':';
-    for ( j=0; j<npixneig[n]; ++j) 
-      cout << ' ' << pixneig[n][j];
-    cout << endl << flush;
-  }
-#endif // __DEBUG__  
-
-  //------------------------------------------------------------
-  // second, pixels' QE
-
-  // try to open the file
-
-  log("read_pixels", "Opening the file \"%s\" . . .\n", QE_FILE);
-  
-  qefile.open( QE_FILE );
-  
-  // if it is wrong or does not exist, exit
-  
-  if ( qefile.bad() )
-    error( "read_pixels", "Cannot open \"%s\". Exiting.\n", QE_FILE );
-  
-  // read file
-
-  log("read_pixels", "Reading data . . .\n");
-
-  i=-1;
-  icount = 0;
-
-  while ( ! qefile.eof() ) {          
-
-    // get line from the file
-
-    qefile.getline(line, LINE_MAX_LENGTH);
-
-    // skip if comment
-
-    if ( *line == '#' )
-      continue;
-
-    // if it is the first valid value, it is the number of QE data points
-
-    if ( i < 0 ) {
-
-      // get the number of datapoints 
-
-      sscanf(line, "%d", &pointsQE);
-      
-      // allocate memory for the table of QEs
-      
-      QE = new float ** [ct_NPixels];
-
-      for ( i=0; i<ct_NPixels; ++i ) {
-        QE[i] = new float * [2];
-        QE[i][0] = new float[pointsQE];
-        QE[i][1] = new float[pointsQE];
-      }
-      
-      QElambda = new float [pointsQE];
-
-      for ( i=0; i<pointsQE; ++i ) {
-        qefile.getline(line, LINE_MAX_LENGTH);
-        sscanf(line, "%f", &QElambda[i]);
-      }
-
-      i=0;
-
-      continue;
-    }
-
-    // get the values (num-pixel, num-datapoint, QE-value)
-    
-    if( sscanf(line, "%d %d %f", &i, &j, &qe) != 3 ) 
-      break;
-
-    if ( ((i-1) < ct_NPixels) && ((i-1) > -1) &&
-         ((j-1) < pointsQE)   && ((j-1) > -1) ) {
-      QE[i-1][0][j-1] = QElambda[j-1];
-      QE[i-1][1][j-1] = qe;
-    }
-
-    if ( i > ct_NPixels) break;
-
-    icount++;
-
-  }
-
-  if(icount/pointsQE < ct_NPixels){
-    error( "read_pixels", "The quantum efficiency file is faulty\n  (found only %d pixels instead of %d).\n",
-	   icount/pointsQE, ct_NPixels );
-  }
-
-  // close file
-
-  qefile.close();
-
-  // test QE
-
-  for(icount=0; icount< ct_NPixels; icount++){
-    for(i=0; i<pointsQE; i++){
-      if( QE[icount][0][i] < 100. || QE[icount][0][i] > 1000. ||
-	  QE[icount][1][i] < 0. || QE[icount][1][i] > 100.){
-	error( "read_pixels", "The quantum efficiency file is faulty\n  pixel %d, point %d  is % f, %f\n",
-	       icount, i, QE[icount][0][i], QE[icount][1][i] );
-      }
-    }
-  }
-
-  // end
-
-  log("read_pixels", "Done.\n");
-  */
-}
-//!@}
 
 //!-----------------------------------------------------------
@@ -3534,29 +3026,4 @@
 }
 
-//!-----------------------------------------------------------
-// @name pixels_are_neig                        
-//                                             
-// @desc check whether two pixels are neighbours
-//
-// @var pix1      Number of the first pixel
-// @var pix2      Number of the second pixel
-// @return        TRUE: both pixels are neighbours; FALSE: oth.
-//
-// @date Wed Sep  9 17:58:37 MET DST 1998
-//------------------------------------------------------------
-// @function  
-
-//!@{
-int
-pixels_are_neig(int pix1, int pix2)
-{ 
-  if ( sqrt(SQR( pixary[pix1][0] - pixary[pix2][0] ) +
-            SQR( pixary[pix1][1] - pixary[pix2][1] ) ) 
-       > ct_PixelWidth_corner_2_corner ) 
-    return ( FALSE );
-  else
-    return ( TRUE );
-}
-//!@}
 
 //!-----------------------------------------------------------
