Index: trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 2201)
+++ trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 2286)
@@ -21,7 +21,7 @@
 //
 // $RCSfile: camera.cxx,v $
-// $Revision: 1.56 $
+// $Revision: 1.57 $
 // $Author: blanch $ 
-// $Date: 2003-06-18 17:13:35 $
+// $Date: 2003-07-17 18:02:46 $
 //
 ////////////////////////////////////////////////////////////////////////
@@ -240,4 +240,6 @@
 static float FADC_response_ampl = MFADC_RESPONSE_AMPLITUDE;
 static float FADC_response_fwhm = MFADC_RESPONSE_FWHM;
+static float FADC_resp_ampl_out = MFADC_RESPONSE_AMPLITUDE;
+static float FADC_resp_fwhm_out = MFADC_RESPONSE_FWHM;
 static float FADC_noise = 2.0;
 
@@ -398,4 +400,5 @@
   char inname[256];           //@< input file name
   char starfieldname[256];    //@< starfield input file name
+  char qe_filename[256];       //@< qe input file name
 
   char datname[256];          //@< data (ASCII) output file name
@@ -407,7 +410,8 @@
 
   char nsbpathname[256];      //@< directory with the dataabse for th NSB
+  char nsbpath_outer[256];    //@< directory with the dataabse for outer pixels
 
   char flag[SIZE_OF_FLAGS + 1];  //@< flags in the .rfl file
-  char flag_new[4];              //@< New flag for the run header in the .rfl file
+  char flag_new[SIZE_OF_FLAGS + 1];              //@< New flag for the run header in the .rfl file
 
   int reflector_file_version;  //@< vrsion of he reflector file
@@ -480,6 +484,4 @@
   int flagstoring = 0;
 
-  float fCorrection;          //@< Factor to apply to pixel values (def. 1.)
-
   int ntrigger = 0;           //@< number of triggers in the whole file
   int btrigger = 0;           //@< trigger flag
@@ -493,7 +495,6 @@
   float fpixelthres[CAMERA_PIXELS];         //@< Threshold values
 
-  TArrayC *fadcValues;  //@< the analog Fadc signal for pixels
-
-  float degTriggerZone;       //@< trigger area in the camera (radius, in deg.)
+  TArrayC *fadcValues;     //@< the analog Fadc High gain signal for pixels
+  TArrayC *fadcValuesLow;  //@< the analog Fadc Low gain signal for pixels
 
   int still_in_loop = FALSE;
@@ -524,6 +525,4 @@
 
   ct_NPixels=camgeom.GetNumPixels();
-  read_QE();
-  read_WC();
 
   //!@' @#### Definition of variables for |getopt()|.
@@ -598,4 +597,11 @@
   Data_From_STDIN = get_data_from_stdin();
 
+  // read WC and QE files
+
+  strcpy( qe_filename, get_qe_filename());
+
+  read_QE(qe_filename);
+  read_WC();
+
   // write all images, even those without trigger?
 
@@ -618,5 +624,6 @@
   get_secure_threhold(&riseDiskThres,&secureDiskThres);
 
-  get_FADC_properties( &FADC_response_ampl, &FADC_response_fwhm);
+  get_FADC_properties( &FADC_response_ampl, &FADC_response_fwhm,
+		       &FADC_resp_ampl_out, &FADC_resp_fwhm_out);
 
   get_Trigger_properties( &Trigger_gate_length, &Trigger_overlaping_time, &Trigger_response_ampl, &Trigger_response_fwhm);
@@ -639,4 +646,5 @@
 
   strcpy( inname, get_input_filename() );
+
   strcpy( starfieldname, get_starfield_filename() );
   strcpy( datname, get_data_filename() );
@@ -645,4 +653,5 @@
   strcpy( ct_filename, get_ct_filename() );
   strcpy( nsbpathname, get_nsb_directory() );
+  strcpy( nsbpath_outer, get_nsb_directory_outer() );
 
   // get different parameters of the simulation
@@ -657,5 +666,4 @@
   //Parameters for starfield rotation
 
-    get_teles_axis(&zenith, &azimutal); 
     Starfield_rotate = get_starfield_rotate();
     log(SIGNATURE,
@@ -668,9 +676,10 @@
 
   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",
+      "%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, 
       "Stars", starfieldname,
-      "NSB database", nsbpathname,
+      "NSB database (inner pixels)", nsbpathname,
+      "NSB database (outer pixels)", nsbpath_outer,
       "CT", ct_filename, 
       "Data", datname,
@@ -790,5 +799,6 @@
   Int_t Lev0, Lev1; 
   
-  fadcValues =  new TArrayC(FADC_SLICES);
+  fadcValues    =  new TArrayC(FADC_SLICES);
+  fadcValuesLow =  new TArrayC(FADC_SLICES);
 
   // number of pixels for parameters
@@ -813,7 +823,8 @@
 		    Trigger_response_fwhm);  //@< A instance of the Class MTrigger 
 
+  // Generate databse for trigger electronic noise
+  Trigger.SetElecNoise(Trigger_noise) ;
+
   // Set Right Discriminator threshold, taking into account trigger pixels
-
-
   Trigger.CheckThreshold(&qThreshold[0]);
 
@@ -857,5 +868,6 @@
   }
 
-  MFadc fadc(FADC_response_ampl,FADC_response_fwhm) ; //@< A instance of the Class MFadc
+  MFadc fadc(FADC_response_ampl,FADC_response_fwhm,
+	     FADC_resp_ampl_out,FADC_resp_fwhm_out) ; //@< A instance of the Class MFadc
 
   //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -874,7 +886,11 @@
 
   for(i=0;i<CAMERA_PIXELS;i++)
-    input_pedestals[i]=10.5;
-  
+    input_pedestals[i]=get_FADC_pedestal();
+
   fadc.SetPedestals(input_pedestals);
+
+  // Generate databse for the Fadc electronic noise
+  
+  fadc.SetElecNoise(FADC_noise);
 
   // Prepare the raw data output
@@ -987,5 +1003,5 @@
 
   //  Fill branches for MMcTrigHeader
-  
+
   if(!Trigger_Loop && Write_McTrig){
 
@@ -1134,11 +1150,4 @@
   }
   
-  // set trigger area (deg)
-
-  if ( ! get_trigger_radius( &degTriggerZone ) )
-    degTriggerZone = ( ct_Type == 0 ) ? (5.0) : (5.0);
-
-  if ( ! get_correction( &fCorrection ) )
-    fCorrection = 1.0;
 
   // prepare the NSB simulation
@@ -1146,7 +1155,13 @@
   //  Instance of the Mlons class
   MLons lons(Trigger_response_ampl, Trigger_response_fwhm,
-	     MFADC_RESPONSE_AMPLITUDE, MFADC_RESPONSE_FWHM);
+	     FADC_response_ampl,FADC_response_fwhm);
 
   lons.SetPath(nsbpathname);
+
+  //  Instance of the Mlons class
+  MLons lons_outer(Trigger_response_ampl, Trigger_response_fwhm,
+		   FADC_resp_ampl_out,FADC_resp_fwhm_out);
+
+  lons_outer.SetPath(nsbpath_outer);
 
   if( simulateNSB ){
@@ -1226,4 +1241,5 @@
   
   strcpy( flag, "                                        \0" );
+  strcpy( flag_new, "    \0" );
 
   // allocate space for PMTs numbers of pixels
@@ -1264,5 +1280,5 @@
 
 	//  We break the main loop
-	cout<<"Warning: Expected start of run header flag, but found:"<<flag<<endl;
+	cout<<"Warning: Expected start of run header flag, but found:"<<flag_new<<endl;
 	cout<<"         We break the main loop"<<endl;
 	break;      
@@ -1277,5 +1293,4 @@
 
       fread( flag, SIZE_OF_FLAGS, 1, inputfile );
-
       while( isA( flag, FLAG_START_OF_EVENT   )){ // while there is a next event
 	fread( flag_new, 4, 1, inputfile );
@@ -1284,5 +1299,5 @@
 
 	//  We break while events loop
-	  cout<<"Warning: Expected start of event header flag, but found:"<<flag<<endl;
+	  cout<<"Warning: Expected start of event header flag, but found:"<<flag_new<<endl;
 	  cout<<"         We break the while events loop"<<endl;
 	  break;      
@@ -1512,6 +1527,12 @@
 	  for(UInt_t ui=0;ui<camgeom.GetNumPixels();ui++)
 	    if(nsb_phepns_rotated[ui]>0.0){
-	      k=lons.GetResponse(nsb_phepns_rotated[ui],0.1,
-	      			 & nsb_trigresp[0],& nsb_fadcresp[0]);
+	      if(camgeom[ui].GetR()>camgeom[0].GetR()){
+		k=lons_outer.GetResponse(nsb_phepns_rotated[ui],0.1,
+				   & nsb_trigresp[0],& nsb_fadcresp[0]);
+	      }
+	      else{
+		k=lons.GetResponse(nsb_phepns_rotated[ui],0.1,
+				   & nsb_trigresp[0],& nsb_fadcresp[0]);
+	      }
 	      if(k==0){
 		cout << "Exiting.\n";
@@ -1528,4 +1549,5 @@
 	}
 
+	ntcph+=ncph;
 	if ((nshow+ntshow)%100 == 1){
 	  log(SIGNATURE, "End of this event: %d cphs(+%d). . .\n",
@@ -1535,5 +1557,4 @@
 	  cout<<inumphensb<<endl;
 	}
-	ntcph += ncph;
 
 	// skip it ?
@@ -1567,15 +1588,4 @@
 	// TRIGGER HERE
 
-	//
-	//   now the noise of the electronic 
-	//   (preamps, optical transmission,..)  is introduced. 
-	//   This is done inside the class MTrigger by the method ElecNoise. 
-	//   
-	if (addElecNoise){	
-	    Trigger.ElecNoise(Trigger_noise) ;
-	    
-	    fadc.ElecNoise(FADC_noise) ;
-	}
-
 	//  We should simulate the AC coupling behaviour:
         //  For the FADC it is only done for the NSB while producinr
@@ -1583,4 +1593,16 @@
 	//  For the trigger is done in the Trigger.Diskriminate(), which
 	//  is called later (it should be seperated to speed up the program
+	//
+
+	//   now the noise of the electronic 
+	//   (preamps, optical transmission,..)  is introduced. 
+	//   This is done inside the class MTrigger by the method ElecNoise. 
+	//   
+
+	if (addElecNoise && nphe2NSB<=inumphe){	
+	  Trigger.ElecNoise(Trigger_noise) ;
+	    
+	  fadc.ElecNoise(FADC_noise) ;
+	}
 
 	//  now a shift in the fadc signal due to the pedestlas is 
@@ -1693,6 +1715,8 @@
 			  for (j=0;j<FADC_SLICES;j++){
 			    fadcValues->AddAt(fadc.GetFadcSignal(i,j),j);
+			    fadcValuesLow->AddAt(fadc.GetFadcLowGainSignal(i,j),j);
 			  }
 			  EvtData[iconcount]->AddPixel(i,fadcValues,0);
+			  EvtData[iconcount]->AddPixel(i,fadcValuesLow,kTRUE);
 			}
 		      }
@@ -1725,5 +1749,5 @@
 	      if (reflector_file_version<6){
 		mcevth.get_times(&ftime, &ltime);
-		McEvt->Fill( -1.0, 
+		McEvt->Fill( 0, 
 			     (UShort_t) mcevth.get_primary() , 
 			     mcevth.get_energy(),
@@ -1750,5 +1774,5 @@
 			     (UInt_t)mcevth.get_CORSIKA(), 
 			     (UInt_t)mcevth.get_AtmAbs(), 
-			     (UInt_t)mcevth.get_MirrAbs()+mcevth.get_OutOfMirr()+mcevth.get_BlackSpot(), 
+			     (UInt_t)(mcevth.get_MirrAbs()+mcevth.get_OutOfMirr()+mcevth.get_BlackSpot()), 
 			     (UInt_t) ncph, 
 			     (UInt_t) inumphe,
@@ -1762,5 +1786,5 @@
 		mcevth_2.get_times(&ftime, &ltime);
 		chi2=mcevth_2.get_NKGfit(&Nmax, &t0, &tmax, &a, &b, &c);
-		McEvt->Fill( mcevth_2.get_evt_number(),
+		McEvt->Fill((UInt_t) mcevth_2.get_evt_number(),
 			    (UShort_t) mcevth_2.get_primary() , 
 			     mcevth_2.get_energy(),
@@ -1787,5 +1811,5 @@
 			     (UInt_t)mcevth_2.get_CORSIKA(), 
 			     (UInt_t)mcevth_2.get_AtmAbs(), 
-			     (UInt_t)mcevth_2.get_MirrAbs()+mcevth_2.get_OutOfMirr()+mcevth_2.get_BlackSpot(), 
+			     (UInt_t)(mcevth_2.get_MirrAbs()+mcevth_2.get_OutOfMirr()+mcevth_2.get_BlackSpot()), 
 			     (UInt_t) ncph, 
 			     (UInt_t) inumphe,
@@ -1898,6 +1922,8 @@
 		  for (j=0;j<FADC_SLICES;j++){
 		    fadcValues->AddAt(fadc.GetFadcSignal(i,j),j);
+		    fadcValuesLow->AddAt(fadc.GetFadcLowGainSignal(i,j),j);
 		  }
 		  EvtData[0]->AddPixel(i,fadcValues,0);
+		  EvtData[0]->AddPixel(i,fadcValuesLow,kTRUE);
 		}
 	      }
@@ -1911,5 +1937,5 @@
 	      if (reflector_file_version<6){
 		mcevth.get_times(&ftime, &ltime);
-		McEvt->Fill( -1.0, 
+		McEvt->Fill( 0, 
 			     (UShort_t) mcevth.get_primary() , 
 			     mcevth.get_energy(),
@@ -1936,5 +1962,5 @@
 			     (UInt_t)mcevth.get_CORSIKA(), 
 			     (UInt_t)mcevth.get_AtmAbs(), 
-			     (UInt_t)mcevth.get_MirrAbs()+mcevth.get_OutOfMirr()+mcevth.get_BlackSpot(), 
+			     (UInt_t)(mcevth.get_MirrAbs()+mcevth.get_OutOfMirr()+mcevth.get_BlackSpot()), 
 			     (UInt_t) ncph, 
 			     (UInt_t) inumphe,
@@ -1948,5 +1974,5 @@
 		mcevth_2.get_times(&ftime, &ltime);
 		chi2=mcevth_2.get_NKGfit(&Nmax, &t0, &tmax, &a, &b, &c);
-		McEvt->Fill( mcevth_2.get_evt_number(),
+		McEvt->Fill( (UInt_t) mcevth_2.get_evt_number(),
 			     (UShort_t) mcevth_2.get_primary() , 
 			     mcevth_2.get_energy(),
@@ -1973,5 +1999,5 @@
 			     (UInt_t)mcevth_2.get_CORSIKA(), 
 			     (UInt_t)mcevth_2.get_AtmAbs(), 
-			     (UInt_t)mcevth_2.get_MirrAbs()+mcevth_2.get_OutOfMirr()+mcevth_2.get_BlackSpot(), 
+			     (UInt_t) (mcevth_2.get_MirrAbs()+mcevth_2.get_OutOfMirr()+mcevth_2.get_BlackSpot()), 
 			     (UInt_t) ncph, 
 			     (UInt_t) inumphe,
@@ -2088,5 +2114,5 @@
 	} // end if found end of file
       } // end if found end of run
-
+      
     } // end if else found start of run
   } // end big while loop
@@ -2101,5 +2127,6 @@
   get_starfield_center(&sfRaH,&sfRaM,&sfRaS,&sfDeD,&sfDeM,&sfDeS);
   if (reflector_file_version<6){
-    get_teles_axis(&telestheta,&telesphi);
+    telestheta=-10.0;
+    telesphi=-10.0;
     mcevth.get_theta_range(&shthetamin, &shthetamax);
     mcevth.get_phi_range(&shphimin,&shphimax);
@@ -2713,5 +2740,5 @@
 //!@{
 void 
-read_QE(void){
+read_QE(char fname[256]){
   ifstream qefile;
   char line[LINE_MAX_LENGTH];
@@ -2724,12 +2751,12 @@
   // try to open the file
 
-  log("read_QE", "Opening the file \"%s\" . . .\n", QE_FILE);
-  
-  qefile.open( QE_FILE );
+  log("read_QE", "Opening the file \"%s\" . . .\n", fname);
+  
+  qefile.open( fname );
   
   // if it is wrong or does not exist, exit
   
   if ( qefile.bad() )
-    error( "read_QE", "Cannot open \"%s\". Exiting.\n", QE_FILE );
+    error( "read_QE", "Cannot open \"%s\". Exiting.\n", fname );
   
   // read file
@@ -2846,5 +2873,5 @@
   // try to open the file
 
-  log("read_QE", "Opening the file \"%s\" . . .\n", WC_FILE);
+  log("read_WC", "Opening the file \"%s\" . . .\n", WC_FILE);
   
   wcfile.open( WC_FILE );
@@ -3894,5 +3921,7 @@
     // store the new photoelectron
 
-    fadc->Fill(ipixnum,(t-*tmin_ns) , trigger->FillShow(ipixnum,t-*tmin_ns));
+    fadc->Fill(ipixnum,(t-*tmin_ns) , 
+	       trigger->FillShow(ipixnum,t-*tmin_ns),
+	       !((*camgeom)[ipixnum].GetR()>(*camgeom)[0].GetR()));
     
     *itotnphe += 1;
