Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 5607)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 5608)
@@ -613,12 +613,13 @@
       // First, find the right FADC slice:
       // 
-      klo  = maxpos - 1;
+      klo  = maxpos;
       while (klo >= 0)
         {
+          klo--;
           if (fHiGainSignal[klo] < fHalfMax)
             break;
-          klo--;
-        }
-      
+        }
+      
+      khi = klo+1;
       //
       // Loop from the beginning of the slice upwards to reach the fHalfMax:
@@ -632,5 +633,5 @@
       Bool_t back = kFALSE;
       
-      Int_t maxcnt = 50;
+      Int_t maxcnt = 20;
       Int_t cnt    = 0;
 
@@ -985,12 +986,13 @@
       // First, find the right FADC slice:
       // 
-      klo  = maxpos - 1;
-      while (klo >= 0)
-        {
+      klo  = maxpos;
+      while (klo > 0)
+        {
+          klo--;
           if (fLoGainSignal[klo] < fHalfMax)
             break;
-          klo--;
-        }
-      
+        }
+      
+      khi = klo+1;
       //
       // Loop from the beginning of the slice upwards to reach the fHalfMax:
@@ -1004,5 +1006,5 @@
       Bool_t back = kFALSE;
       
-      Int_t maxcnt = 50;
+      Int_t maxcnt = 20;
       Int_t cnt    = 0;
 
@@ -1034,13 +1036,10 @@
 
           if (++cnt > maxcnt)
-            {
-              //              *fLog << inf << x << "  " << y << " " << fHalfMax << endl;
-              break;
-            }
+            break;
           
           step /= 2.;
         }
 
-      time  = x + (Int_t)fLoGainFirst;
+      time  = x + (Float_t)fLoGainFirst;
       dtime = fResolution;
     }
@@ -1151,4 +1150,6 @@
   Float_t b = start-lo;
 
+  Int_t cnt = 0;
+
   while (1)
     {
@@ -1171,4 +1172,6 @@
             + (a*a*a-a)*fHiGainSecondDeriv[klo] 
             + (b*b*b-b)*fHiGainSecondDeriv[khi];
+          
+          cnt++;
         }
 
