Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 5368)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 5373)
@@ -228,54 +228,6 @@
 
   //
-  // Check for saturation in all other slices
-  //
-  while (p<end)
-    {
-
-      fHiGainSignal[count++] = (Float_t)*p;
-
-      if (*p > max)
-        {
-          max    = *p;
-          maxpos =  p-ptr;
-        }
-
-      if (*p++ >= fSaturationLimit)
-        sat++;
-    }
-  
-  if (fHiLoLast != 0)
-    {
-
-      end = logain + fHiLoLast;
-
-      while (logain<end)
-        {
-
-          fHiGainSignal[count++] = (Float_t)*logain;
-          range++;
-
-          if (*logain > max)
-            {
-              max    = *logain;
-              maxpos =  range;
-            }
-          
-          if (*logain++ >= fSaturationLimit)
-            sat++;
-        }
-    }
-  
-  //
-  // allow one saturated slice 
-  //
-  if (sat > 0)
-    return;
-
-  Float_t time_sum  = 0.;
-  Float_t fmax      = 0.;
-  Float_t ftime_max = 0.;
-  Int_t   max_p     = 0;
-  
+  // Preparations for the pedestal subtraction (with AB-noise correction)
+  //
   const Float_t pedes  = ped.GetPedestal();
   const Float_t ABoffs = ped.GetPedestalABoffset();
@@ -286,4 +238,61 @@
 
   //
+  // Check for saturation in all other slices
+  //
+  while (p<end)
+    {
+
+      const Int_t ids      = fHiGainFirst + count ;
+      const Float_t signal = (Float_t)*p - pedmean[(ids+abflag) & 0x1];
+      fHiGainSignal[count] = signal;
+
+      count++;
+
+      if (*p > max)
+        {
+          max    = *p;
+          maxpos =  p-ptr;
+        }
+
+      if (*p++ >= fSaturationLimit)
+        sat++;
+    }
+  
+  if (fHiLoLast != 0)
+    {
+
+      end = logain + fHiLoLast;
+
+      while (logain<end)
+        {
+
+          const Int_t ids      = fHiGainFirst + range ;
+          const Float_t signal = (Float_t)*logain - pedmean[(ids+abflag) & 0x1];
+          fHiGainSignal[range] = signal;
+          range++;
+
+          if (*logain > max)
+            {
+              max    = *logain;
+              maxpos =  range;
+            }
+          
+          if (*logain++ >= fSaturationLimit)
+            sat++;
+        }
+    }
+  
+  //
+  // allow one saturated slice 
+  //
+  if (sat > 0)
+    return;
+
+  Float_t time_sum  = 0.;
+  Float_t fmax      = 0.;
+  Float_t ftime_max = 0.;
+  Int_t   max_p     = 0;
+  
+  //
   // Calculate the sum of the first fWindowSize slices
   //
@@ -300,5 +309,5 @@
       {
         const Int_t   idx = fBinningResolutionHiGain*sample+fBinningResolutionHalfHiGain;
-        const Float_t pex = fHiGainSignal[sample+i]-pedmean[(sample+i+abflag) & 0x1];
+        const Float_t pex = fHiGainSignal[sample+i];
 	sum              += fAmpWeightsHiGain [idx]*pex; 
 	time_sum         += fTimeWeightsHiGain[idx]*pex;
@@ -348,8 +357,8 @@
   {
     const Int_t   idx = fBinningResolutionHiGain*sample + fBinningResolutionHalfHiGain + t_iter;
-    const Int_t   ids = (IsNoiseCalculation()) ? sample : max_p + sample;
+    const Int_t   ids = IsNoiseCalculation() ? sample : max_p + sample;
     
     const Float_t pex = ids < 0 ? 0. : 
-      ( ids > range ? 0. : fHiGainSignal[ids]-pedmean[(ids+abflag) & 0x1]);
+      ( ids > range ? 0. : fHiGainSignal[ids]);
     sum              += fAmpWeightsHiGain [idx]*pex; 
     time_sum         += fTimeWeightsHiGain[idx]*pex;
@@ -376,26 +385,6 @@
 
   //
-  // Check for saturation in all other slices
-  //
-  while (p<end)
-    {
-
-      fLoGainSignal[count++] = (Float_t)*p;
-
-      if (*p > max)
-        {
-          max    = *p;
-          maxpos =  p-ptr;
-        }
-
-      if (*p++ >= fSaturationLimit)
-        sat++;
-    }
-  
-  Float_t time_sum  = 0.;
-  Float_t fmax      = 0.;
-  Float_t ftime_max = 0.;
-  Int_t   max_p     = 0;
-  
+  // Prepare the low-gain pedestal
+  //
   const Float_t pedes  = ped.GetPedestal();
   const Float_t ABoffs = ped.GetPedestalABoffset();
@@ -406,4 +395,31 @@
 
   //
+  // Check for saturation in all other slices
+  //
+  while (p<end)
+    {
+
+      const Int_t ids      = fLoGainFirst + count ;
+      const Float_t signal = (Float_t)*p - pedmean[(ids+abflag) & 0x1];
+      fLoGainSignal[count] = signal;
+
+      count++;
+
+      if (*p > max)
+        {
+          max    = *p;
+          maxpos =  p-ptr;
+        }
+
+      if (*p++ >= fSaturationLimit)
+        sat++;
+    }
+  
+  Float_t time_sum  = 0.;
+  Float_t fmax      = 0.;
+  Float_t ftime_max = 0.;
+  Int_t   max_p     = 0;
+  
+  //
   // Calculate the sum of the first fWindowSize slices
   //
@@ -420,5 +436,5 @@
       {
         const Int_t   idx = fBinningResolutionLoGain*sample+fBinningResolutionHalfLoGain;
-        const Float_t pex = fLoGainSignal[sample+i]-pedmean[(sample+i+abflag) & 0x1];
+        const Float_t pex = fLoGainSignal[sample+i];
 	sum              += fAmpWeightsLoGain [idx]*pex; 
 	time_sum         += fTimeWeightsLoGain[idx]*pex;
@@ -469,5 +485,5 @@
     const Int_t   ids = (IsNoiseCalculation()) ? sample : max_p + sample;;
     const Float_t pex = ids < 0 ? 0. : 
-      ( ids > range ? 0. : fLoGainSignal[ids]-pedmean[(ids+abflag) & 0x1]);
+      ( ids > range ? 0. : fLoGainSignal[ids]);
     sum              += fAmpWeightsLoGain [idx]*pex; 
     time_sum         += fTimeWeightsLoGain[idx]*pex;
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 5368)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 5373)
@@ -353,10 +353,10 @@
   Int_t  count     = 0;
 
-  Float_t pedes        = ped.GetPedestal();
+  const Float_t pedes  = ped.GetPedestal();
   const Float_t ABoffs = ped.GetPedestalABoffset();
 
-  Float_t PedMean[2];
-  PedMean[0] = pedes + ABoffs;
-  PedMean[1] = pedes - ABoffs;
+  Float_t pedmean[2];
+  pedmean[0] = pedes + ABoffs;
+  pedmean[1] = pedes - ABoffs;
 
   fAbMax        = 0.;
@@ -371,5 +371,5 @@
 
       const Int_t ids      = fHiGainFirst + count ;
-      const Float_t signal = (Float_t)*p - PedMean[(ids+abflag) & 0x1];
+      const Float_t signal = (Float_t)*p - pedmean[(ids+abflag) & 0x1];
       fHiGainSignal[count] = signal;
 
@@ -395,5 +395,5 @@
 
           const Int_t ids      = fHiGainFirst + range ;
-          const Float_t signal = (Float_t)*logain - PedMean[(ids+abflag) & 0x1];
+          const Float_t signal = (Float_t)*logain - pedmean[(ids+abflag) & 0x1];
           fHiGainSignal[range] = signal;
           range++;
@@ -683,6 +683,6 @@
       // Now integrate the whole thing!
       // 
-      Int_t startslice = (Int_t)(fAbMaxPos - fRiseTime);
-      Int_t lastslice  = (Int_t)(fAbMaxPos + fFallTime);
+      Int_t startslice = IsNoiseCalculation() ? 0 : (Int_t)(fAbMaxPos - fRiseTime);
+      Int_t lastslice  = IsNoiseCalculation() ? (Int_t)(fRiseTime+fFallTim) : (Int_t)(fAbMaxPos + fFallTime);
       
       if (startslice < 0)
@@ -728,7 +728,7 @@
   const Float_t ABoffs = ped.GetPedestalABoffset();
 
-  Float_t PedMean[2];
-  PedMean[0] = pedes + ABoffs;
-  PedMean[1] = pedes - ABoffs;
+  Float_t pedmean[2];
+  pedmean[0] = pedes + ABoffs;
+  pedmean[1] = pedes - ABoffs;
 
   fAbMax        = 0.;
@@ -743,5 +743,5 @@
 
       const Int_t ids      = fLoGainFirst + count ;
-      const Float_t signal = (Float_t)*p - PedMean[(ids+abflag) & 0x1];
+      const Float_t signal = (Float_t)*p - pedmean[(ids+abflag) & 0x1];
       fLoGainSignal[count] = signal;
 
@@ -1034,6 +1034,6 @@
       // Now integrate the whole thing!
       // 
-      Int_t startslice = (Int_t)(fAbMaxPos - fRiseTime);
-      Int_t lastslice  = (Int_t)(fAbMaxPos + fFallTime + 1);
+      Int_t startslice = IsNoiseCalculation() ? 0 : (Int_t)(fAbMaxPos - fRiseTime);
+      Int_t lastslice  = IsNoiseCalculation() ? (Int_t)(fRiseTime+fFallTim) : (Int_t)(fAbMaxPos + fFallTime + 1);
       
       if (startslice < 0)
