Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 5745)
+++ trunk/MagicSoft/Mars/Changelog	(revision 5746)
@@ -44,4 +44,12 @@
    * msignal/MExtractTimeAndChargeDigitalFilter.cc
      - fixed two bugs introduced yesterday by TB.
+
+   * msignal/MExtractTimeAndChargeSpline.cc
+   * msignal/MExtractTimeAndChargeSlidingWindow.cc
+     - adopt part of TB's speed accelerations into these classes
+
+   * msignal/MExtractTimeAndCharge.cc
+     - fix the low-gain extraction window for the case that the high-gain
+       is saturated. Was skipped so far.
 
 
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc	(revision 5745)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc	(revision 5746)
@@ -86,5 +86,4 @@
 
 const Float_t MExtractTimeAndCharge::fgLoGainStartShift = -2.8; 
-
 // --------------------------------------------------------------------------
 //
@@ -157,4 +156,5 @@
                                 fLoGainFirst, fLoGainLast, fNumLoGainSamples);
 
+
   return kTRUE;
 }
@@ -166,13 +166,9 @@
 // Calculate the integral of the FADC time slices and store them as a new
 // pixel in the MExtractedSignalCam container. 
-// The functions FindTimeAndChargeHiGain() and FindTimeAndChargeLoGain are 
+// The functions FindTimeAndChargeHiGain() and FindTimeAndChargeLoGain() are 
 // supposed to extract the signal themselves.
 //
 Int_t MExtractTimeAndCharge::Process()
 {
-    // This cleaning is nor necessary: It is done automatically by
-    // Reset() before each execution of the Tasklist (Process())
-    //  fArrTime->Clear();
-    //  fSignals->Clear();
 
   MRawEvtPixelIter pixel(fRawEvt);
@@ -216,10 +212,11 @@
 
           fLoGainFirstSave = fLoGainFirst;
-          const Byte_t logainstart = (Byte_t)(timehi+fLoGainStartShift);
-          if (!sathi)
-              fLoGainFirst = logainstart > fLoGainFirstSave ? logainstart : fLoGainFirstSave;
-
-          if (fLoGainFirst < fLoGainLast)
-          {
+          const Byte_t logainstart = sathi 
+            ? sathi + (Int_t)fLoGainStartShift
+            : (Byte_t)(timehi + fLoGainStartShift);
+          fLoGainFirst = logainstart > fLoGainFirstSave ? logainstart : fLoGainFirstSave;
+
+          if ( fLoGainFirst < fLoGainLast )
+            {
               const Bool_t logainabflag = (higainabflag + pixel.GetNumHiGainSamples()) & 0x1;
               FindTimeAndChargeLoGain(pixel.GetLoGainSamples()+fLoGainFirst,
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc	(revision 5745)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc	(revision 5746)
@@ -210,26 +210,27 @@
   
   Float_t max = 0;  // highest integral content of all windows
-  Int_t count = 0;  // counter to recognize the AB-flag
+  Int_t count = 0;
+  sat         = 0;
 
   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] = { pedes + ABoffs, pedes - ABoffs };
   //
   // Check for saturation in all other slices
   //
+  Int_t ids = fHiGainFirst;
+
   while (p<first+fWindowSizeHiGain)
     {
-      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];      
       sum                 += signal;
       fHiGainSignal[count] = signal;
       
       if (*p++ >= fSaturationLimit)
-        sat++;
-
+        if (!sat)
+            sat = p-first+fHiGainFirst-1;
+      
       count++;
     }
@@ -240,5 +241,6 @@
   while (p<end)
     if (*p++ >= fSaturationLimit)
-      sat++;
+      if (!sat)
+        sat = p-first+fHiGainFirst-1;
   
   if (IsNoiseCalculation())
@@ -257,6 +259,5 @@
     {
       
-      const Int_t ids      = fHiGainFirst + count + fWindowSizeHiGain;
-      const Float_t signal = (Float_t)*(p+fWindowSizeHiGain) - PedMean[(ids+abflag) & 0x1];      
+      const Float_t signal = (Float_t)*(p+fWindowSizeHiGain) - PedMean[(ids++ + abflag) & 0x1];      
       sum                 += signal - fHiGainSignal[count];
       fHiGainSignal[count + fWindowSizeHiGain] = signal;
@@ -281,11 +282,10 @@
         {
           
-          const Int_t   ids    = fHiGainFirst + count + fWindowSizeHiGain;
-          const Float_t signal = (Float_t)*l - PedMean[(ids+abflag) & 0x1];          
+          const Float_t signal = (Float_t)*l - PedMean[(ids++ + abflag) & 0x1];          
           sum                 += signal - fHiGainSignal[count];
           fHiGainSignal[count + fWindowSizeHiGain] = signal;
-          count++;
           if (*l++ >= fSaturationLimit)
-            sat++;
+            if (!sat)
+              sat = l-logain+fHiGainLast-1;
           
           if (sum>max)
@@ -294,19 +294,20 @@
               idx   = count+1;
             }
+          count++;
           p++;
         }
       
-      if (fHiLoLast > fWindowSizeHiGain)
+      if (fHiLoLast > (Byte_t)fWindowSizeHiGain)
         {
           while (l < logain + fHiLoLast)
             {
-              const Int_t   ids    = fHiGainFirst + count + fWindowSizeHiGain;
-              const Float_t signal = (Float_t)*l - PedMean[(ids+abflag) & 0x1];          
+              const Float_t signal = (Float_t)*l - PedMean[(ids++ + abflag) & 0x1];          
               sum                 += signal - fHiGainSignal[count];
               fHiGainSignal[count+fWindowSizeHiGain] = signal;
-              count++;
-              if (*(l+fWindowSizeHiGain) >= fSaturationLimit)
-                sat++;
-              
+
+              if (*l++ >= fSaturationLimit)
+                if (!sat)
+                  sat = l-logain+fHiGainLast-1;
+
               if (sum>max)
                 {
@@ -314,5 +315,5 @@
                   idx   = count+1;
                 }
-              l++;
+              count++;
             } /* while (l < logain + fHiLoLast) */
         } /* if (fHiLoLast > fWindowSizeHiGain) */
@@ -333,6 +334,6 @@
   sum   = max;
 
-  time  = sum != 0 ? timesignalsum / max  + Float_t(fHiGainFirst) : 1.;
-  dtime = sum != 0 ? ped.GetPedestalRms() / max * sqrt(timesquaredsum - fWindowSizeHiGain*time) : 1.;
+  time  = max > 0.1 ? timesignalsum / max  + Float_t(fHiGainFirst) : 1.;
+  dtime = max > 0.1 ? ped.GetPedestalRms() / max * sqrt(timesquaredsum - fWindowSizeHiGain*time) : 1.;
 
 }
@@ -358,15 +359,13 @@
   const Float_t ABoffs = ped.GetPedestalABoffset();
 
-  Float_t PedMean[2];
-  PedMean[0] = pedes + ABoffs;
-  PedMean[1] = pedes - ABoffs;
-
+  Float_t PedMean[2] = { pedes + ABoffs, pedes - ABoffs };
   //
   // Check for saturation in all other slices
   //
+  Int_t ids = fLoGainFirst;
+
   while (p<first+fWindowSizeLoGain)
     {
-      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];      
       sum                 += signal;
       fLoGainSignal[count] = signal;
@@ -400,6 +399,5 @@
     {
 
-      const Int_t ids      = fLoGainFirst + count + fWindowSizeLoGain;
-      const Float_t signal = (Float_t)*(p+fWindowSizeLoGain) - PedMean[(ids+abflag) & 0x1];      
+      const Float_t signal = (Float_t)*(p+fWindowSizeLoGain) - PedMean[(ids++ + abflag) & 0x1];      
       sum                 += signal - fLoGainSignal[count];
       fLoGainSignal[count + fWindowSizeLoGain] = signal;
@@ -427,6 +425,6 @@
   sum   = max;
 
-  time  = sum != 0 ? timesignalsum / max  + Float_t(fLoGainFirst) : 1.;
-  dtime = sum != 0 ? ped.GetPedestalRms() / max * sqrt(timesquaredsum - fWindowSizeLoGain*time) : 1.;
+  time  = max > 0.1 ? timesignalsum / max  + Float_t(fLoGainFirst) : 1.;
+  dtime = max > 0.1 ? ped.GetPedestalRms() / max * sqrt(timesquaredsum - fWindowSizeLoGain*time) : 1.;
 }
 
