Index: trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 5318)
+++ trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 5320)
@@ -21,7 +21,7 @@
 //
 // $RCSfile: camera.cxx,v $
-// $Revision: 1.79 $
+// $Revision: 1.80 $
 // $Author: moralejo $ 
-// $Date: 2004-10-26 14:02:32 $
+// $Date: 2004-10-26 19:21:05 $
 //
 ////////////////////////////////////////////////////////////////////////
@@ -995,4 +995,8 @@
   }
 
+  float *fadc_jitter = new float[ct_Number];
+  for (int i=0; i<ct_Number;i++)
+    fadc_jitter[i] = 0.;
+
   MFadc **Fadc_CT;
   Fadc_CT = new MFadc *[ct_Number];
@@ -1686,4 +1690,10 @@
 				      ((MGeomCam*)(camgeom.UncheckedAt(ict)))
 				      ->GetNumPixels());
+
+    //
+    // Fill also the flag indicating whether the PMT gain fluctuations 
+    // were simulated or not:
+    //
+    HeaderFadc[ict]->SetGainFluctuations(Trigger_CT[ict]->GetGainFluctuations());
   }
 
@@ -1944,6 +1954,14 @@
 	  inumphe_CT[ict]=0;
 
+
+	  // Obtain the FADC jitter of 1 FADC slice. This is a time to be added to the 
+	  // time of all photons in an event, before digitalization of the signal. It is
+	  // therefore the same time shift for all pixels in a CT. 
+
+	  fadc_jitter[ict] = 
+	    (1./Fadc_CT[ict]->GetFadcSlicesPerNanosec()) * RandomNumber; //ns
+
 	  // read the photons and produce the photoelectrons
-	  
+
 	  k = produce_phes( inputfile[ict],
 			    ((MGeomCam*)(camgeom.UncheckedAt(ict))),
@@ -1958,5 +1976,6 @@
 			    &arrtmax_ns, // will be changed by the function!
 			    ict,
-			    mirror_frac[ict]);
+			    mirror_frac[ict],
+			    fadc_jitter[ict]);
 
 	  inumphe=(inumphe<inumphe_CT[ict])?inumphe_CT[ict]:inumphe;
@@ -2324,5 +2343,6 @@
 				  -1.0,
 				  -1.0,
-				  -1.0);
+				  -1.0,
+				  fadc_jitter[0]);
 		}
 		else{
@@ -2363,5 +2383,6 @@
 				 mcevth_2[0].get_ElecFraction(),
 				 mcevth_2[0].get_MuonFraction(),
-				 mcevth_2[0].get_OtherFraction());
+				 mcevth_2[0].get_OtherFraction(),
+				 fadc_jitter[0]);
 		}
 	      }
@@ -2538,5 +2559,5 @@
 	  } // end CT loop
 
-	  // If there is trigger in some telecope or we store all showers
+	  // If there is trigger in some telescope or we store all showers
 	  if(btrigger){  
 	    if (Write_McEvt){
@@ -2581,5 +2602,6 @@
 				  -1.0,
 				  -1.0,
-				  -1.0);
+				  -1.0,
+				   fadc_jitter[ict]);
 		}
 		else{
@@ -2618,5 +2640,6 @@
 				  mcevth_2[ict].get_ElecFraction(),
 				  mcevth_2[ict].get_MuonFraction(),
-				  mcevth_2[ict].get_OtherFraction());
+				  mcevth_2[ict].get_OtherFraction(),
+				  fadc_jitter[ict]);
 		}
 	      }
@@ -4004,5 +4027,7 @@
 		  float *tmax_ns,    // maximum arrival time of all phes
 		  int ict,      // Telescope that is being analised to get the right QE.
-		  float mirror_fraction // Fraction of total mirror really present
+		  float mirror_fraction, // Fraction of total mirror really present
+		  float fadc_jitter     // Random shift (max 1 slice) of pulses in 
+			                // FADC, to simulate FADC clock noise.
                    ){
 
@@ -4034,12 +4059,4 @@
 
   float C1, C2, C3, rho;
-
-  // A. Moralejo, October 2004
-  // Introduced the FADC jitter of 1 FADC slice. This is a time to be added to the 
-  // time of all photons in an event, before digitalization of the signal. We use 
-  // a positive value between 0 and 1 slice for technical reasons, but it is 
-  // totally equivalent to having made  +- 1 FADC slice
-
-  float fadc_jitter = (1./fadc->GetFadcSlicesPerNanosec()) * random.Uniform(0., 1.); //ns
 
   //- - - - - - - - - - - - - - - - - - - - - - - - - 
@@ -4404,5 +4421,5 @@
 	    fsetpos( infile, &fileposition);
 
-	    // produce photoelectrons
+	    // produce photoelectrons (photons from starfield)
 
 	    k = produce_phes( infile,
@@ -4418,5 +4435,7 @@
 			      &tmax_ns,
 			      0,
-			      mirror_fraction); // photons from starfield
+			      mirror_fraction,
+			      0.); 
+
 
 	    if( k != 0 ){ // non-zero returnvalue means error
@@ -4653,10 +4672,10 @@
 
 	  McEvt[ict]->Fill( 0, 0, 0., -1.0, -1.0, -1.0, 0., 0., 0., 0., 0.,
-			    0., 0., 0., pulsetime[ict], 0., 0., 0., 0.,
+			    0., 0., 0., 0., 0., 0., 0., 0.,
 			    0., 0., 0., 0., 0, 0, 0,
 			    (UInt_t) ntotphot[ict], 
 			    (UInt_t) ntotphe[ict],
 			    (UInt_t) nphe_from_nsb[ict]+ ntotphe[ict],
-			    0., 0., 0.);
+			    0., 0., 0., pulsetime[ict]);
 
 	  //
@@ -4910,4 +4929,8 @@
 //
 // $Log: not supported by cvs2svn $
+// Revision 1.79  2004/10/26 14:02:32  moralejo
+//
+// Added option to switch off gain fluctuations (gain_fluctuations_off)
+//
 // Revision 1.78  2004/10/21 17:44:07  moralejo
 //
@@ -5057,5 +5080,5 @@
 // - The screen output information has been improved to prevent some
 // non-desired running conditions just looking at the output screen.
-// - One MMcEvt for each Telscope is stored in the output file.
+// - One MMcEvt for each Telsecope is stored in the output file.
 // - 500 empty events are simualted to get a more precise estimation of the
 // pedestal Sigma for each pixel.
