Index: trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.cxx	(revision 635)
+++ trunk/MagicSoft/Simulation/Detector/include-MFadc/MFadc.cxx	(revision 637)
@@ -74,4 +74,12 @@
 
   //
+  //  set all pedestals to 0
+  //
+  
+  for ( i =0 ; i <CAMERA_PIXELS ; i++ ) { 
+    pedestal[i] = 0 ; 
+  }
+
+  //
   //  set tha values of FADC slices that would be read after trigger to zero
   //
@@ -105,5 +113,4 @@
   }
 }
-
 
 void MFadc::Fill( Int_t iPix, Float_t time, Float_t amplitude ) { 
@@ -171,4 +178,60 @@
 }
 
+void MFadc::Set( Int_t iPix, Float_t resp[(Int_t) SLICES_MFADC]) { 
+  
+  //
+  // Sets the information about fadc reponse from a given array
+  //
+  // parameter is the number of the pixel and the values to be set
+  //
+  //
+
+  Int_t i ; 
+  
+  //
+  //   first we have to check if the pixel iPix is used or not until now
+  //   if this is the first use, reset all signal for that pixels
+  // 
+  if ( iPix > CAMERA_PIXELS ) {
+    cout << " WARNING:  MFadc::Fill() :  iPix greater than CAMERA_PIXELS"
+	 << endl ;
+    exit(987) ; 
+  }
+
+  if ( used[iPix] == FALSE ) {
+    used [iPix] = TRUE ; 
+    
+    for (i=0; i < SLICES_MFADC; i++ ) {
+      sig[iPix][i] = 0. ; 
+    }
+  }
+  for ( i = 0 ; i<SLICES_MFADC; i++ ) {
+    sig[iPix][i] = resp[i] ; 
+  }
+
+}
+
+void MFadc::SetPedestals( Int_t ped) { 
+  //  It sets pedestal for each pixel flat randomly dstributed between 0 and ped
+  //  It uses the instance of TRandom GenElec.
+
+  Int_t i;
+
+  for(i=0;i<CAMERA_PIXELS;i++){
+    pedestal[i]= (UChar_t)(ped* GenElec->Rndm());
+  }
+}
+
+void MFadc::SetPedestals(  UChar_t ped[CAMERA_PIXELS]) { 
+  //  It sets pedestal for each pixel from ped array
+
+  Int_t i;
+
+  for(i=0;i<CAMERA_PIXELS;i++){
+    pedestal[i]= ped[i];
+  }
+}
+  
+
 void MFadc::Baseline(){
   //  
@@ -188,4 +251,18 @@
     }
   }
+}
+
+void MFadc::Pedestals(){
+  // 
+  //  It shifts the FADC contents their pedestal values
+  //  It shifts the values in the analog signal, 
+  //  therefore it has to be done before getting FADC output
+  //
+
+  Int_t i, j;
+
+  for(i=0;i<CAMERA_PIXELS;i++)
+    for(j=0;j<SLICES_MFADC;j++)
+      sig[i][j]+=pedestal[i];
 }
 
@@ -368,5 +445,5 @@
       i=0;
       for ( Int_t is=iFirstSlice ; is < (iFirstSlice+FADC_SLICES) ; is++ ) {
-	if (is< SLICES_MFADC)
+	if (is< SLICES_MFADC && sig[ip][is]>0.0)
 	  output[ip][i++]=(UChar_t) sig[ip][is];
 	else 
@@ -451,5 +528,5 @@
 }
 
-Float_t MFadc::GetFadcSignal(Int_t pixel, Int_t slice){
+UChar_t MFadc::GetFadcSignal(Int_t pixel, Int_t slice){
 
   //  It returns the analog signal for a given pixel and a given FADC
