Index: trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 2453)
+++ trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 2962)
@@ -1,3 +1,3 @@
-//!/////////////////////////////////////////////////////////////////////
+////!/////////////////////////////////////////////////////////////////////
 //
 // camera                
@@ -21,7 +21,7 @@
 //
 // $RCSfile: camera.cxx,v $
-// $Revision: 1.66 $
+// $Revision: 1.67 $
 // $Author: blanch $ 
-// $Date: 2003-11-03 12:58:40 $
+// $Date: 2004-01-30 09:51:18 $
 //
 ////////////////////////////////////////////////////////////////////////
@@ -199,7 +199,7 @@
 
 //@: Properties of the FADC
-static float FADC_response_ampl = MFADC_RESPONSE_AMPLITUDE;
+static float FADC_response_ampl = MFADC_RESPONSE_INTEGRAL;
 static float FADC_response_fwhm = MFADC_RESPONSE_FWHM;
-static float FADC_resp_ampl_out = MFADC_RESPONSE_AMPLITUDE;
+static float FADC_resp_ampl_out = MFADC_RESPONSE_INTEGRAL;
 static float FADC_resp_fwhm_out = MFADC_RESPONSE_FWHM;
 static float FADC_noise = 2.0;
@@ -330,5 +330,5 @@
   char GeometryName[100][50];            //@< Name of MGeomCam for each CT
   int GeometryCamera[100];           //@< Identification of MGeomCam for each CT
-  int TriggerPixels[100];           //@< Numeber of pixels in the trigger region for each CT
+  int TriggerPixels[100];           //@< Number of pixels in the trigger region for each CT
 
   int reflector_file_version=0;  //@< vrsion of he reflector file
@@ -682,9 +682,9 @@
 
     // Look to factor for NSB respect to emi_coat PMTs
-    if(!strcmp(qe_filename,"../Data/qe-emi-coat.RFL.dat"))
+    if(strstr(qe_filename,"qe-emi-coat.RFL.dat") != 0)
       factorqe_NSB[ict]=EMICOAT_NSB;
-    else if(!strcmp(qe_filename,"../Data/qe-emi.RFL.dat"))
+    else if(strstr(qe_filename,"qe-emi.RFL.dat") != 0)
       factorqe_NSB[ict]=EMI_NSB;
-    else if(!strcmp(qe_filename, "../Data/qe-intevac_hpd.RFL.dat"))
+    else if(strstr(qe_filename, "qe-intevac_hpd.RFL.dat") != 0)
       factorqe_NSB[ict]=HPD_NSB;
     else{
@@ -852,5 +852,5 @@
 
   for (int ict=0; ict<ct_Number;ict++){
-  // Generate databse for trigger electronic noise
+  // Generate database for trigger electronic noise
     if (addElecNoise)    
       Trigger_CT[ict]->SetElecNoise(Trigger_noise) ;
@@ -912,5 +912,7 @@
       new  MFadc(((MGeomCam*)(camgeom.UncheckedAt(i)))->GetNumPixels(),
 		 FADC_response_ampl,FADC_response_fwhm,
-		 FADC_resp_ampl_out,FADC_resp_fwhm_out) ; //@< A instance of the Class MFadc
+		 FADC_resp_ampl_out,FADC_resp_fwhm_out,
+		 get_trig_delay()
+	  ) ; //@< A instance of the Class MFadc
 
 
@@ -936,5 +938,5 @@
     Fadc_CT[ict]->SetHigh2LowGain(FADC_high2low);
     
-    // Generate databse for the Fadc electronic noise
+    // Generate database for the Fadc electronic noise
     if (addElecNoise){        
       Fadc_CT[ict]->SetElecNoise(FADC_noise);
@@ -1589,5 +1591,5 @@
 	
 	++nshow;
-	if((nshow+ntshow)%100 == 1)
+	if((nshow+ntshow+1)%100 == 1)
 	  log(SIGNATURE, "Event %d(+%d)\n", nshow, ntshow);
 	
@@ -1804,5 +1806,5 @@
 	    rho = rho*180/3.14159;
 
-	    // Rottion of the NSB
+	    // Rotation of the NSB
 	    // FIXME --- We should rotate for all cameras. Is it always the same rho? 	
 	    for(int ict=0;ict<ct_Number;ict++){      
@@ -1847,5 +1849,5 @@
 	  }
 	  ntcph[ict]+=ncph[ict];
-	  if ((nshow+ntshow)%100 == 1){
+	  if ((nshow+ntshow+1)%100 == 1){
 	    log(SIGNATURE, "End of this event: %d cphs(+%d). . .\n",
 		ncph[ict], ntcph[ict]);
@@ -2025,5 +2027,10 @@
 			    i<((MGeomCam*)(camgeom.UncheckedAt(0)))
 			      ->GetNumPixels();i++){
-			  if(!Fadc_CT[0]->IsPixelUsed(i)) continue;
+//
+// AM 15 01 2004: commented out "continue" statement, so that also pixels 
+// with no C-photons will be written to the output in case the camera
+// is run with no noise.		    
+//  			  if(!Fadc_CT[0]->IsPixelUsed(i)) continue;
+//
 			  for (j=0;j<FADC_SLICES;j++){
 			    fadcValues->AddAt(Fadc_CT[0]->GetFadcSignal(i,j),j);
@@ -2264,5 +2271,10 @@
 		      i<((MGeomCam*)(camgeom.UncheckedAt(ict)))->GetNumPixels();
 		      i++){
-		    if(!Fadc_CT[ict]->IsPixelUsed(i)) continue;
+//
+// AM 15 01 2004 Commented out "continue" statement, so that also pixels
+// containing no C-photons will be written to the output in case of running
+// camera with no noise added to the signal.	      
+// 		    if(!Fadc_CT[ict]->IsPixelUsed(i)) continue;
+//
 		    for (j=0;j<FADC_SLICES;j++){
 		      fadcValues->AddAt(Fadc_CT[ict]->GetFadcSignal(i,j),j);
@@ -2457,4 +2469,12 @@
 	  for(int ict=0;ict<ct_Number;ict++){
 	    read_ascii(inputfile[ict], McConfigRunHeader[ict]);
+
+	    if (get_sigma_xy_cm_spot() > 0.)
+	    {
+		Float_t spotsigma = McConfigRunHeader[ict]->GetPointSpread();
+		Float_t newsigma = sqrt(spotsigma * spotsigma + 
+		    get_sigma_xy_cm_spot() * get_sigma_xy_cm_spot());
+		McConfigRunHeader[ict]->SetPointSpread(newsigma);
+	    }
 	  }
 	  if ((! Data_From_STDIN) && ( !feof(inputfile[0]) )){
@@ -3077,8 +3097,5 @@
   Float_t radius = -1.0;
   Float_t focal = -1.0;
-  Float_t stdfocal = -1.0;
   Float_t point = -1.0;
-  Float_t stdpoint = -1.0;
-  Float_t adjust = -1.0;
   Float_t spot = -1.0;
   Float_t camwidth = -1.0;
@@ -3097,15 +3114,30 @@
     if((flag=fgetc(sp))==EOF)
       break;
+    if (flag == '\n')    // skip empty lines
+      continue;
+
     fgets(&line[1],500,sp);
     line[0]=flag;
-    if (line[0]== '#' && line[2]=='n' && line[3]=='u' && line[4]=='m' &&
-	line[5]== 'b' && line[12]=='d' && line[13]=='a' && line[14]=='t'){
+
+    if ( strstr(line, "# reflectivity file") == line ) {
+      while (strstr(line, "# number of datapoints") != line)
+	fgets(line,500,sp);
+
       fgets(line,500,sp);
       sscanf(line,"%i",&numref);
+
       TArrayF wavarray(numref);
       TArrayF refarray(numref);
-      fgets(line,500,sp);
+
+      while (strstr(line, "# datapoints") != line)
+	fgets(line,500,sp);
+
       for(int i=0; i<numref;i++){
 	fgets(line,500,sp);
+	if (line[0] == '#')
+	  {
+	    i--;
+	    continue;
+	  }
 	sscanf(line,"%f %f",&wav,&ref);
 	wavarray[i]=wav;
@@ -3113,4 +3145,5 @@
       }
       for (int j=0; j<nummir;j++){
+
 	MGeomMirror &mirror = config->GetMirror(j);
 	mirror.SetArraySize(numref);
@@ -3127,20 +3160,8 @@
       continue;
     }
-    if (strstr(line, "focal_std") == line){
-      sscanf(line,"%s %f",token,&stdfocal);
-      continue;
-    }
     if (strstr(line, "point_spread") == line){
       sscanf(line,"%s %f",token,&point);
       continue;
     }
-    if (strstr(line, "point_std") == line){
-      sscanf(line,"%s %f",token,&stdpoint);
-      continue;
-    }
-    if (strstr(line, "adjustment_dev") == line){
-      sscanf(line,"%s %f",token,&adjust);
-      continue;
-    }
     if (strstr(line, "black_spot") == line){
       sscanf(line,"%s %f",token,&spot);
@@ -3151,4 +3172,7 @@
       continue;
     }
+    //
+    // Skip obsolete magic.def entries:
+    //
     if (strstr(line, "n_pixels") == line)
       continue;
@@ -3159,4 +3183,5 @@
     if (strstr(line, "n_gappixels") == line)
       continue;
+
     if (strstr(line, "n_mirrors") == line){
       sscanf(line,"%s %i",token,&nummir);
@@ -3178,10 +3203,15 @@
       }
       fgets(line,500,sp);
-      while(line[2]!='w' || line[3]!='i' || line[4]!='t' || line[5]!='h'){
+
+      while ( ! strstr(line, "axis deviation"))
 	fgets(line,500,sp);
-      }
-      fgets(line,500,sp);
+
       for(int i=0;i<nummir;i++){
-      fgets(line,500,sp);
+	fgets(line,500,sp);
+	if (line[0] == '#')
+	  {
+	    i--;
+	    continue;
+	  }
 	sscanf(line,"%f %f",&dx,&dy);
 	MGeomMirror &mirror = config->GetMirror(i);
@@ -3191,6 +3221,5 @@
     }
   }
-  config->SetMagicDef(radius, focal, stdfocal, point,
-		      stdpoint, adjust, spot, camwidth);
+  config->SetMagicDef(radius, focal, point, spot, camwidth);
 }
 
@@ -3708,5 +3737,5 @@
 		  int *itotnphe, // total number of produced photoelectrons
 		  float nphe[iMAXNUMPIX], // number of photoelectrons in each pixel
-		  int *incph,    // total number of cph read
+		  int *incph,       // total number of cph within camera
 		  float *tmin_ns,   // minimum arrival time of all phes
 		  float *tmax_ns,    // maximum arrival time of all phes
@@ -3735,4 +3764,8 @@
   radius_mm = camgeom->GetMaxRadius();
 
+  TRandom random;
+  random.SetSeed((Int_t)(get_seeds(0)*get_seeds(1)));
+
+  float spotsigma = get_sigma_xy_cm_spot();
 
   //- - - - - - - - - - - - - - - - - - - - - - - - - 
@@ -3761,9 +3794,5 @@
 	  
 
-    // increase number of photons
-	  
-    (*incph)++;
-
-    //  Chceck if photon is inside trigger time range
+    //  Check if photon is inside trigger time range
 
     t = photon.get_t() ; 
@@ -3780,4 +3809,11 @@
     cy = photon.get_y(); 
 
+
+    if (spotsigma > 0.)
+    {
+	cx += random.Gaus(0.,spotsigma);
+	cy += random.Gaus(0.,spotsigma);
+    }
+
     // get wavelength
 	  
@@ -3800,4 +3836,10 @@
         continue;
     }
+
+    // AM changed meaning of incph: before it was all photons read from 
+    // reflector file, now only those within a valid pixel:
+    //
+    // increase number of photons
+    (*incph)++;
 
     //+++
@@ -4230,5 +4272,5 @@
 // The seeds in the input card are used to initilize the random numbers.
 // The Amplitud stored in the MMcFadcHeader is the amplitud of the sphe reponse.
-// The Pedestal rms is simualted in a artificail empty event.
+// The Pedestal rms is simulated in an artificial empty event.
 //
 // Revision 1.62  2003/09/26 11:25:07  blanch
