Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 5293)
+++ trunk/MagicSoft/Mars/Changelog	(revision 5294)
@@ -25,4 +25,10 @@
      - fixed a small bug concerning the way the second derivatives are 
        calculated. The effect is less than 1% on the time resolution
+
+   * msignal/MExtractTimeFastSpline.cc
+     - comment the search for the half maximum and use the maximum again. 
+       The half maximum fails sometimes by 0.5 slices which seems to be 
+       some intrinsic behavior of the calibration pulses. 
+       The maximum seems to be OK, though. 
 
 
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeFastSpline.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeFastSpline.cc	(revision 5293)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeFastSpline.cc	(revision 5294)
@@ -53,5 +53,5 @@
 const Byte_t  MExtractTimeFastSpline::fgLoGainLast   = 14;
 const Float_t MExtractTimeFastSpline::fgResolution   = 0.003;
-const Float_t MExtractTimeFastSpline::fgRiseTime     = 1.5;
+const Float_t MExtractTimeFastSpline::fgRiseTime     = 2.;
 
 // --------------------------------------------------------------------------
@@ -168,5 +168,5 @@
   // Check for saturation in all other slices
   //
-  while (++p<end)
+  while (p<end)
     {
       if (*p > max)
@@ -176,5 +176,5 @@
         }
 
-      if (*p >= fSaturationLimit)
+      if (*p++ >= fSaturationLimit)
         {
           sat++;
@@ -183,9 +183,15 @@
     }
   
-  if (sat)
+  //
+  // allow one saturated slice 
+  //
+  if (sat > 1)
     return;
 
-  if (maxpos < 2)
-    return;
+  if (maxpos < 1)
+    {
+      time = -999.;
+      return;
+    }
   
   Float_t pp;
@@ -200,6 +206,6 @@
       pp = fHiGainSecondDeriv[i-1] + 4.;
       fHiGainSecondDeriv[i] = -1.0/pp;
-      const Double_t deriv = *(p+1) - 2.* *(p) + *(p-1);
-      fHiGainFirstDeriv [i] = (6.0*deriv-fHiGainFirstDeriv[i-1])/pp;
+      fHiGainFirstDeriv [i] = *(p+1) - 2.* *(p) + *(p-1);
+      fHiGainFirstDeriv [i] = (6.0*fHiGainFirstDeriv[i]-fHiGainFirstDeriv[i-1])/pp;
     }
 
@@ -229,11 +235,11 @@
 
   //
-  // Search for the maximum, starting in interval maxpos-1. If no maximum is found, go to 
-  // interval maxpos+1.
-  //
-
+  // Search for the maximum, starting in interval maxpos-1 in steps of 0.2 till maxpos-0.2.
+  // If no maximum is found, go to interval maxpos+1.
+  //
   Float_t higainklo = fHiGainSecondDeriv[klo];
   Float_t higainkhi = fHiGainSecondDeriv[khi];
-  while (x<upper-0.3)
+
+  while ( x < upper - 0.3 )
     {
       
@@ -254,6 +260,8 @@
     }
   
-
- if (time > upper-0.1)
+  //
+  // Search for the absolute maximum from maxpos to maxpos+1 in steps of 0.2
+  //
+  if (time > upper-0.1)
     {
 
@@ -270,4 +278,5 @@
       higainklo = fHiGainSecondDeriv[klo];
       higainkhi = fHiGainSecondDeriv[khi];
+
       while (x<upper-0.3)
         {
@@ -289,18 +298,26 @@
         }
   }
- 
-  const Float_t up = time+step-0.055;
-  const Float_t lo = time-step+0.055;
+
+  //
+  // Now, the time, abmax and khicont and klocont are set correctly within the previous precision.
+  // Try a better precision. 
+  //
+  const Float_t up = time+step-0.035;
+  const Float_t lo = time-step+0.035;
   const Float_t maxpossave = time;
-
+  
   x     = time;
   a     = upper - x;
   b     = x - lower;
 
-  step  = 0.04; // step size of 83 ps 
+  step  = 0.025; // step size of 83 ps 
 
   higainklo = fHiGainSecondDeriv[klo];
   higainkhi = fHiGainSecondDeriv[khi];
-  while (x<up)
+
+  //
+  // First, try from time up to time+0.2 in steps of 83ps.
+  //
+  while ( x < up )
     {
 
@@ -322,5 +339,15 @@
     }
 
-  if (time < klo + 0.02)
+
+  //
+  // Second, try from time down to time-0.2 in steps of 0.04.
+  //
+  x     = maxpossave;
+  //
+  // Test the possibility that the absolute maximum has not been found between
+  // maxpos and maxpos+0.02, then we have to look between maxpos-0.02 and maxpos
+  // which requires new setting of klocont and khicont
+  //
+  if (x < klo + 0.02)
     {
       klo--;
@@ -332,5 +359,4 @@
     }
   
-  x     = maxpossave;
   a     = upper - x;
   b     = x - lower;
@@ -338,5 +364,6 @@
   higainklo = fHiGainSecondDeriv[klo];
   higainkhi = fHiGainSecondDeriv[khi];
-  while (x>lo)
+
+  while ( x > lo )
     {
 
@@ -360,4 +387,5 @@
   const Float_t halfmax = pedes + (abmax - pedes)/2.;
 
+#if 0
   //
   // Now, loop from the maximum bin leftward down in order to find the position of the half maximum.
@@ -381,5 +409,4 @@
   klocont = (Float_t)*(first+klo);
   khicont = (Float_t)*(first+klo+1);
-  time  = x;
 
   step = 0.5;
@@ -415,7 +442,9 @@
       
     }
-
   time  = (Float_t)fHiGainFirst + x;
-  dtime = fResolution;
+
+#endif
+  dtime = 0.035;
+
 }
 
@@ -431,5 +460,5 @@
   const Int_t range = fLoGainLast - fLoGainFirst + 1;
   const Byte_t *end = first + range;
-  Byte_t *p = first;
+  Byte_t       *p   = first;
   Byte_t max    = 0;
   Byte_t maxpos = 0;
@@ -438,5 +467,5 @@
   // Check for saturation in all other slices
   //
-  while (++p<end)
+  while (p<end)
     {
       if (*p > max)
@@ -446,5 +475,5 @@
         }
 
-      if (*p >= fSaturationLimit)
+      if (*p++ >= fSaturationLimit)
         {
           sat++;
@@ -456,5 +485,5 @@
     return;
 
-  if (maxpos < 2)
+  if (maxpos < 1)
     return;
   
