Index: trunk/MagicSoft/Simulation/Detector/Camera/creadparam.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Camera/creadparam.cxx	(revision 2965)
+++ trunk/MagicSoft/Simulation/Detector/Camera/creadparam.cxx	(revision 5072)
@@ -19,7 +19,7 @@
 //=
 //= $RCSfile: creadparam.cxx,v $
-//= $Revision: 1.26 $
-//= $Author: blanch $ 
-//= $Date: 2004-01-30 09:58:39 $
+//= $Revision: 1.27 $
+//= $Author: moralejo $ 
+//= $Date: 2004-09-16 15:16:34 $
 //=
 //=//////////////////////////////////////////////////////////////////////
@@ -54,4 +54,5 @@
 
 #include "creadparam.h"
+#include "camera.h"      // Needed for MAX_NUMBER_OF_CTS
 
 //!@}
@@ -68,5 +69,5 @@
 //!@{
 
-static char Input_filename[100][PATH_MAX_LENGTH];  //@< input filename
+static char **Input_filename;  //@< input filename
 static char Starfield_filename[PATH_MAX_LENGTH]; //@< starfield input filename
 static int Starfield_center[6]={0,0,0,0,0,0}; //@< center of the starfield FOV
@@ -75,7 +76,7 @@
 static char ROOT_filename[PATH_MAX_LENGTH];   //@< data filename
 static char Loop_filename[PATH_MAX_LENGTH];   //@< special data filename
-static int  CT_geometry = 0;                  //@< CT camera geometry
+static char CT_geom_string[256];              //@< Contains geometry ids of CTs  
 static int  CT_number = 1;                    //@< Number of CT
-static char QE_filename[100][PATH_MAX_LENGTH];     //@< name of the qe file
+static char **QE_filename; //@< name of the qe file
 static char NSB_directory[PATH_MAX_LENGTH];   //@< database for NSB
 static char NSB_outer_directory[PATH_MAX_LENGTH];   //@< database for NSB
@@ -83,5 +84,6 @@
 static int ElecNoise = TRUE;                  //@< Will we add ElecNoise?
 static float FADC_pedestal = 10.0;            //@< Value for FADC Pedestal
-static float FADC_Noise = 2.0;                //@< Value for FADC ElecNoise
+static float FADC_Noise_inner = 2.0;         //@< Value for FADC ElecNoise
+static float FADC_Noise_outer = 2.0;         //@< Value for FADC ElecNoise
 static float Digital_Noise = 1.0;            //@< Value for FADC  digital Noise
 static float Trig_Noise = 0.3;                //@< Factor for Trigger ElecNoise
@@ -89,5 +91,5 @@
 static float meanNSB;           //@< NSB mean value (per pixel)
 static int nphe2NSB=0;          //@< Number of phe from shower to do NSB simulation 
-static float qThreshold[100][CAMERA_PIXELS];     //@< Threshold values
+static float **qThreshold; //@< Threshold values
 static int Individual_Thres = FALSE;
 static float RiseDisc = -1.0;
@@ -112,7 +114,7 @@
 static float Trigger_response_ampl = 1.0;
 static float Trigger_response_fwhm = 2.0;
-static float Trigger_threshold[100];
-static int Trigger_multiplicity[100];
-static int Trigger_topology[100];
+static float Trigger_threshold[MAX_NUMBER_OF_CTS];
+static int Trigger_multiplicity[MAX_NUMBER_OF_CTS];
+static int Trigger_topology[MAX_NUMBER_OF_CTS];
 static float Trigger_loop_lthres = 3.0;
 static float Trigger_loop_uthres = 10.0;
@@ -122,20 +124,26 @@
 static int Trigger_loop_ltop = 0;
 static int Trigger_loop_utop = 2;
+static int FADC_shape = 0;
 static float FADC_response_ampl = MFADC_RESPONSE_INTEGRAL;
 static float FADC_response_fwhm = MFADC_RESPONSE_FWHM;
+static int FADC_shape_out = 0;
 static float FADC_resp_ampl_out = MFADC_RESPONSE_INTEGRAL;
 static float FADC_resp_fwhm_out = MFADC_RESPONSE_FWHM;
 static float High_to_Low = 10.0;      //@< Low gain channel respct to High
-static float Source_offset_th=0.;     //@<  Displacement in Theta of the 
-                                      //@< source from the center
-static float Source_offset_ph=0.;     //@<  Displacement in Phi of the 
-                                      //@< source from the center
-
-static float sigma_spot = -1.; // Sigma in x and y for additional 
-                               // gaussian spread of the mirror spot.
+
+static float sigma_x_spot = 0.; // Sigma in x and y (cm) for additional 
+static float sigma_y_spot = 0.; // gaussian spread of the mirror spot.
+                               
+static float misp_x = 0.; // Mispointing in x 
+static float misp_y = 0.; // Mispointing in y
 
 static float trig_delay = 25.;  // Delay in ns between beginning of FADC
                                 // time window and the trigger instant.
 
+static float CTcoor[MAX_NUMBER_OF_CTS][3]; 
+
+static float m_fraction[MAX_NUMBER_OF_CTS];
+
+// Coordinates of CT locations, in centimeters, in the Corsika system.
 
 //!@}
@@ -162,8 +170,25 @@
   char token[ITEM_MAX_LENGTH];   //@< a single token
   int i, j, k;                      //@< dummy counters
-  float aux, aux2;                    //@< auxiliar variable
+  float aux, aux1, aux2;                    //@< auxiliar variable
   int aux3, aux4;                    //@< auxiliar variable
   ifstream ifile;
   char filename_tmp[PATH_MAX_LENGTH];
+
+
+  memset((char*)CT_geom_string, 0, sizeof(CT_geom_string));
+
+  Input_filename = new char *[MAX_NUMBER_OF_CTS];
+  QE_filename = new char *[MAX_NUMBER_OF_CTS];
+  qThreshold = new float *[MAX_NUMBER_OF_CTS];
+
+  for (int i = 0; i < MAX_NUMBER_OF_CTS; i++)
+    {
+      Input_filename[i] = new char[PATH_MAX_LENGTH];
+      QE_filename[i] = new char[PATH_MAX_LENGTH];
+      qThreshold[i] = new float[CAMERA_PIXELS];
+      CTcoor[i][0] = 0.; CTcoor[i][1] = 0.; CTcoor[i][2] = 0.;
+      m_fraction[i] = 1.;
+    }
+
   // use cin or ifile (reading from STDIN or from parameters file?
   if ( filename != NULL )
@@ -259,5 +284,5 @@
       break;
 
-    case ct_num:             //@< name of the telescope file
+    case ct_num:             //@< number of telescopes
           
       // get the name of the ct_file from the line
@@ -269,5 +294,12 @@
           
       // get the name of the ct_file from the line
-      sscanf(line, "%s %i", token, &CT_geometry);
+      sscanf(line, "%s %s", token, CT_geom_string);
+      if ( strlen(CT_geom_string) > MAX_NUMBER_OF_CTS )
+	{
+	  printf("\nError: ct_geom option read from input card wrong:\n");
+	  printf("Number of digits (%d) is larger than maximum number\n",strlen(CT_geom_string) );
+	  printf("of allowed telescopes (%d). Exiting.\n\n", MAX_NUMBER_OF_CTS);
+	  exit(1);
+	}
 
       break;
@@ -285,10 +317,11 @@
       // we will not add electronic noise for FADC and Trigger channels.
       ElecNoise = FALSE;
-      FADC_Noise = 0.0;
+      FADC_Noise_inner = 0.0;
+      FADC_Noise_outer = 0.0;
       Trig_Noise =0.0;
 
       break;
 
-    case fadc_pedestal:              //@< FADC ElecNoise
+    case fadc_pedestal:              //@< FADC pedestal
           
       // value for FADC Pedestal
@@ -311,5 +344,5 @@
       break;
 
-    case high_to_low:              //@< FADC ElecNoise
+    case high_to_low:              //@< High to Low gain ratio
           
       // Value for the Low Gain channel respect to the High gain
@@ -321,5 +354,7 @@
           
       // value for FADC Elec Noise
-      sscanf(line, "%s %f %f", token, &FADC_Noise, &Digital_Noise);
+      sscanf(line, "%s %f %f %f", token, 
+	     &FADC_Noise_inner, &FADC_Noise_outer,
+	     &Digital_Noise);
 
       ElecNoise = TRUE;
@@ -479,5 +514,5 @@
 
       //  Get parameters for the fadc  response for one phe
-      sscanf(line, "%s %f %f", token, &FADC_response_ampl,&FADC_response_fwhm);
+      sscanf(line, "%s %i %f %f", token, &FADC_shape, &FADC_response_ampl,&FADC_response_fwhm);
 
       break;
@@ -486,5 +521,5 @@
 
       //  Get parameters for the fadc  response for one phe
-      sscanf(line, "%s %f %f", token, &FADC_resp_ampl_out,&FADC_resp_fwhm_out);
+      sscanf(line, "%s %i %f %f", token, &FADC_shape_out, &FADC_resp_ampl_out,&FADC_resp_fwhm_out);
 
       break;
@@ -545,11 +580,4 @@
       break;
 
-    case source_offset:
-
-      //  Get offset of source
-	sscanf(line, "%s %f %f", token, &Source_offset_th, &Source_offset_ph);
-
-      break;
-
     case Trigger_Loop_Output_Only_Specialists:
 
@@ -563,13 +591,60 @@
       break;
 
+    case trigger_delay:
+
+      sscanf(line, "%s %f", token, &trig_delay);
+      break;
+
+
     case sigma_xy_cm_spot:
 
-      sscanf(line, "%s %f", token, &sigma_spot);
-      break;
-
-    case trigger_delay:
-
-      sscanf(line, "%s %f", token, &trig_delay);
-      break;
+      sscanf(line, "%s %f", token, &sigma_x_spot);
+      sigma_y_spot=sigma_x_spot;
+      break;
+
+    case sigma_x_cm_spot:
+
+      sscanf(line, "%s %f", token, &sigma_x_spot);
+      break;
+
+    case sigma_y_cm_spot:
+
+      sscanf(line, "%s %f", token, &sigma_y_spot);
+      break;
+
+    case misspoint_deg:
+
+      sscanf(line, "%s %f %f", token, &misp_x, &misp_y);
+      break;
+
+    case telescope_location_cm:
+
+      if ( 5 != sscanf(line, "%s %d %f %f %f", token, &j, &aux, &aux1, &aux2) )
+	{
+	  printf("\nError: wrong number of arguments for command telescope_location_cm.\n");
+	  printf("Usage: telescope_location_cm ct_id x y z\n");
+	  printf("Coordinates must be written in centimeters.");
+	  printf("Exiting.\n\n");
+	  exit(1);
+	}
+
+      if (j >= MAX_NUMBER_OF_CTS)
+	{
+	  printf("\nError: coordinates were supplied for a telescope index (%d)\n", j);
+	  printf("larger than allowed. Valid telescope ids range from 0 to %d. Exiting.\n\n", MAX_NUMBER_OF_CTS-1);
+	  exit(1);
+	}
+      CTcoor[j][0] = aux;
+      CTcoor[j][1] = aux1;
+      CTcoor[j][2] = aux2;
+
+      break;
+
+    case mirror_fraction:
+
+	sscanf(line, "%s %d %f", token, &j, &aux);
+	m_fraction[j] = aux;
+	
+	break;
 
     case end_file:            //@< end of the parameters file
@@ -761,7 +836,11 @@
 //!@{
 int 
-get_ct_geometry(void)
-{
-  return (CT_geometry);
+get_ct_geometry(int ict)
+{
+  char dummy[2];
+  strncpy(dummy, &(CT_geom_string[ict]), 1);
+  dummy[1] = '\0';
+
+  return ((int)atoi(dummy));
 }
 //!@}
@@ -839,7 +918,9 @@
 //!@{
 int
-add_elec_noise(float *fadc, float *digi, float *trig)
-{
-  *fadc = FADC_Noise;
+add_elec_noise(float *fadcinner, float*fadcouter, float *digi, float *trig)
+{
+  *fadcinner = FADC_Noise_inner;
+  *fadcouter = FADC_Noise_outer;
+
   *digi = Digital_Noise;
   *trig = Trig_Noise;
@@ -1174,8 +1255,11 @@
 //!@{
 void
-get_FADC_properties(float *ra, float *rf, float *rao, float *rfo)
-{
+get_FADC_properties(int *shape,float *ra, float *rf,
+		    int *shapeo, float *rao, float *rfo)
+{
+  *shape=FADC_shape;
   *ra=FADC_response_ampl;
   *rf=FADC_response_fwhm;
+  *shapeo=FADC_shape_out;
   *rao=FADC_resp_ampl_out;
   *rfo=FADC_resp_fwhm_out;
@@ -1241,5 +1325,5 @@
 get_Trigger_Single(float **t, int *m, int *g)
 {
-  for(int j=0;j<100;j++){
+  for(int j=0;j<MAX_NUMBER_OF_CTS;j++){
     for(int i=0;i<CAMERA_PIXELS;i++)
       t[j][i]=qThreshold[j][i];
@@ -1251,19 +1335,4 @@
 
 //!-----------------------------------------------------------
-// @name get_source_off
-//                                                
-// @desc give the offset of the source to the center of the camera 
-//
-//------------------------------------------------------------
-// @function 
-
-//!@{
-void get_source_off(float *th, float *p){
-    *th=Source_offset_th;
-    *p=Source_offset_ph;
-}
-//!@}
-
-//!-----------------------------------------------------------
 // @name get_FADC_pedesta
 //                                                
@@ -1300,7 +1369,25 @@
 }
 
-float get_sigma_xy_cm_spot(void){
-
-  return sigma_spot;
+int get_misspointing(float *x, float *y){
+
+  *x=misp_x;
+  *y=misp_y;
+
+  if (misp_x == 0.0 && misp_y==0.0)
+    return 0;
+  else 
+    return 1;
+
+}
+
+float get_sigma_xy_cm_spot(float *x, float *y){
+
+  *x=sigma_x_spot;
+  *y=sigma_y_spot;
+
+  if (sigma_x_spot > 0.0 || sigma_y_spot >0.0)
+    return 1.0;
+  else 
+    return -1.0;
 
 }
@@ -1311,4 +1398,16 @@
 
 }
+
+float get_telescope_location_cm(int j, int icoor){
+
+  return CTcoor[j][icoor];
+
+}
+
+float get_mirror_fraction(int j){
+    return m_fraction[j];
+}
+
+
 
 //!@}
@@ -1319,4 +1418,23 @@
 //
 // $Log: not supported by cvs2svn $
+//
+// Revision 1.27  2004/05/12 A. Moralejo
+//
+// Changed fadc_noise command: now the two first numbers are respectively
+// the analogic electronic noise for inner (small) and outer (big) pixels
+// respectively. Last number is still the FADC digital noise which affects
+// equallly inner and outer pixels (as well as high and low gain).
+//
+// Revision 1.26  2004/01/30 09:58:39  blanch
+// [Changes done mainly by A. Moralejo]
+//
+// Two new commands of the input card have been added:
+//
+// sigma_xy_cm_spot: to enlarge the point spread function.
+// trigger_delay: to center the FADC signal
+//
+// There is also a check that the Pedestal is an integer, otherwise it
+// becames complex to get a reasonable rms for events without electronic noise.
+//
 // Revision 1.25  2003/10/26 19:45:38  blanch
 // The write_all_data input card command has been removed.
