Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 7843)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 7844)
@@ -41,4 +41,31 @@
      - allow to setup different password for differend users and different
        users for different databases in sql.rc
+
+   * mcalib/MCalibrateRelTimes.cc:
+     - implemented a workaround to mark pixels bad for extraction of
+       hi- and lo-gain failed. (Before MCalibrateData just assigned
+       a weird value)
+
+   * msignal/MArrivalTimePix.h:
+     - added some member functions
+
+   * msignal/MExtractTimeAndCharge.cc:
+     - added some comments which contain future code
+     - invalidate hi- and lo-gain if both could not be extracted properly
+       (FIXME: We need a cut on the number of unsuitable pixels per event)
+     - changed handling of sathi to make the detection of hi-gain
+       saturation work properly
+
+   * msignal/MExtractTimeAndChargeDigitalFilter.cc:
+     - changed fgLoGainOffset from 1.05 to 0.95 (comming out of the
+       latest plots)
+     - fixed assignment of sat in hi-gain extraction to make sure
+       the the satuartion information can be returned properly
+
+   * msignal/MExtractTimeAndChargeSpline.cc:
+     - changed fgLoGainStartShift according to BCN cvs to -2.4 (FIXME
+       this should be checked!)
+     - adapted handling of sat in hi-gain extraction to changes
+       above
 
 
Index: /trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc	(revision 7843)
+++ /trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc	(revision 7844)
@@ -179,5 +179,52 @@
 
   while (pixel.Next())
-    {
+  {
+      // COPY HERE PRODUCING ARRAY WITH SAMPLES
+
+      /*
+       const MPedestalPix  &ped = (*fPedestals)[pixidx];
+
+       const Float_t pedes  = ped.GetPedestal();
+       const Float_t ABoffs = ped.GetPedestalABoffset();
+
+       const Float_t pedmean[2] = { pedes + ABoffs, pedes - ABoffs };
+
+       const Int_t num = pixel.GetNumHiGainSamples()+pixel.GetNumLoGainSamples();
+
+       MArrayF sample(num);
+
+       const Int_t abflag = pixel.HasABFlag() ? 1 : 0;
+       const Int_t ids0 = fHiGainFirst + abflag;
+
+       Int_t ids  = ids0;
+
+       Float_t  null   = 0;      // Starting value for maxpos
+       Float_t *maxpos = &null;  // Position of maximum
+       Float_t *sat1   = 0;      // First saturating slice
+       Float_t *sat2   = 0;      // Last saturating slice
+
+       const Float_t *beg = sample.GetArray();
+       const Float_t *end = beg + num;
+
+       Float_t *ptr = beg;
+       while (ptr<end)
+       {
+          *sample++ = (Float_t)*ptr - pedmean[ids++&0x1];
+
+          // This extraction must be done independant for lo- and hi-gain
+          // if (*ptr > *maxpos)
+          //     maxpos = ptr;
+          //
+          // if (*ptr >= fSaturationLimit)
+          // {
+          //    sat2 = ptr;
+          //    if (!sat1)
+          //       sat1 = ptr;
+          // }
+          //
+          // ptr++;
+        }
+       */
+
       //
       // Find signal in hi- and lo-gain
@@ -210,5 +257,16 @@
       // Adapt the low-gain extraction range from the obtained high-gain time
       //
-      if (pixel.HasLoGain() && (fMaxBinContent > fLoGainSwitch) )
+
+      // IN THIS CASE THE PIXEL SHOULD BE MARKED BAD!!!!
+      // MEANS: Hi gain has saturated, but it is too early to extract
+      // the lo-gain properly
+      // THIS produces pulse positions ~= -1
+      // The signal might be handled in MCalibrateData, but hwat's about
+      // the arrival times in MCalibrateRelTime
+      if (sathi && fMaxBinContent<=fLoGainSwitch)
+          deltasumlo=deltasumhi=deltatimelo=deltatimehi=-1;
+
+      // FIXME: What to do with the pixel if it saturates too early???
+      if (pixel.HasLoGain() && (fMaxBinContent > fLoGainSwitch /*|| sathi>0*/) )
       {
           deltasumlo  = 0; // make logain of MExtractedSignalPix valid
@@ -217,5 +275,9 @@
           fLoGainFirstSave = fLoGainFirst;
 
-          const Float_t pos = sathi==0 ? timehi : sathi;
+          // sathi is the number (not index!) of the first saturating slice
+          // 0 indicates that no saturation was found
+          // FIMXME: Is 3 an accurate value?
+
+          const Float_t pos = sathi==0 ? timehi : (int)(sathi)-3;
 
           if (pos>-fLoGainStartShift)
@@ -225,5 +287,5 @@
               fLoGainFirst = fLoGainFirstSave;
 
-          if ( fLoGainFirst <= fLoGainLast-fWindowSizeLoGain)
+          if (fLoGainFirst <= fLoGainLast-fWindowSizeLoGain)
           {
               const Bool_t logainabflag = (higainabflag + pixel.GetNumHiGainSamples()) & 0x1;
Index: /trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 7843)
+++ /trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 7844)
@@ -24,4 +24,5 @@
 !
 \* ======================================================================== */
+
 //////////////////////////////////////////////////////////////////////////////
 //
@@ -88,5 +89,5 @@
 const Int_t  MExtractTimeAndChargeDigitalFilter::fgSignalStartBinHiGain    =  4;
 const Int_t  MExtractTimeAndChargeDigitalFilter::fgSignalStartBinLoGain    =  4;
-const Float_t MExtractTimeAndChargeDigitalFilter::fgOffsetLoGain           =  1.05;
+const Float_t MExtractTimeAndChargeDigitalFilter::fgOffsetLoGain           =  0.95;
 const Float_t MExtractTimeAndChargeDigitalFilter::fgLoGainStartShift       = -1.8;
 
@@ -329,5 +330,4 @@
   const Byte_t *end = ptr + range;
   Byte_t *p     = ptr;
-  Byte_t maxpos = 0;
 
   //
@@ -352,5 +352,7 @@
       if (*p > fMaxBinContent)
 	{
-	  maxpos = p-ptr;
+          Byte_t maxpos = p-ptr;
+
+          // range-fWindowSizeHiGain+1 == fHiLoLast isn't it?
 	  if (maxpos > 1 && maxpos < (range - fWindowSizeHiGain + 1))
 	    fMaxBinContent = *p;
@@ -359,5 +361,5 @@
       if (*p++ >= fSaturationLimit)
         if (!sat)
-          sat = ids-3;
+          sat = ids-fHiGainFirst;
     }
 
@@ -391,5 +393,5 @@
           if (*logain++ >= fSaturationLimit)
             if (!sat)
-              sat = ids-3;
+              sat = ids-fHiGainFirst;
         }
     }
Index: /trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 7843)
+++ /trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 7844)
@@ -160,5 +160,5 @@
 const Float_t MExtractTimeAndChargeSpline::fgLoGainStretch    = 1.5;
 const Float_t MExtractTimeAndChargeSpline::fgOffsetLoGain     = 1.39;  // 5 ns
-const Float_t MExtractTimeAndChargeSpline::fgLoGainStartShift = -1.8;  
+const Float_t MExtractTimeAndChargeSpline::fgLoGainStartShift = -2.4;
 
 // --------------------------------------------------------------------------
@@ -404,5 +404,5 @@
       if (*p++ >= fSaturationLimit)
         if (!sat)
-          sat = ids-3;
+          sat = ids-fHiGainFirst;
       
     }
@@ -426,5 +426,5 @@
           if (*logain++ >= fSaturationLimit)
             if (!sat)
-              sat = ids-3;
+              sat = ids-fHiGainFirst;
 
           range++;
