Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 8518)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 8519)
@@ -42,4 +42,19 @@
      - removed automatic writing of fDisplay from WriteContainer
      - added a new function WriteDisplay
+
+   * mhcalib/MHCalibrationChargeCam.cc, mpedestal/MExtractPedestal.cc,
+     msignal/MExtractBlindPixel.cc, msignal/MSignalCalc.cc:
+     - replaced GetMax by GetMaxPos
+
+   * mhcalib/MHCalibrationPulseTimeCam.cc:
+     - use new GetMax returning position and height at once
+
+   * mpedestal/MPedestalSubtractedEvt.[h,cc]:
+     - devided the old function GetMax into GetMax and GetRawMax
+
+   * msignal/MExtractTimeAndCharge.cc:
+     - GetSaturationTime now uses the real maximum as reference not 
+       the maximum of the raw-date
+     - adapted the use of GetMax
 
 
Index: /trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeCam.cc	(revision 8518)
+++ /trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeCam.cc	(revision 8519)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MHCalibrationChargeCam.cc,v 1.58 2007-04-27 10:04:47 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MHCalibrationChargeCam.cc,v 1.59 2007-05-16 13:56:17 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -751,5 +751,5 @@
          continue;
 
-      const Float_t timehi = fRawEvt->GetMax(pixid, hifirst, hilast)+hifirst;
+      const Float_t timehi = fRawEvt->GetMaxPos(pixid, hifirst, hilast)+hifirst;
       histhi.FillAbsTime(timehi);
 
@@ -764,5 +764,5 @@
           MHCalibrationChargePix &histlo = (MHCalibrationChargePix&)(*this)(pixid);
 
-          const Float_t timelo = fRawEvt->GetMax(pixid, nhi+lofirst, nhi+lolast)+lofirst;
+          const Float_t timelo = fRawEvt->GetMaxPos(pixid, nhi+lofirst, nhi+lolast)+lofirst;
           histlo.FillAbsTime(timelo);
 
Index: /trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.cc	(revision 8518)
+++ /trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.cc	(revision 8519)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MHCalibrationPulseTimeCam.cc,v 1.38 2007-04-25 14:39:43 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MHCalibrationPulseTimeCam.cc,v 1.39 2007-05-16 13:56:17 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -390,6 +390,6 @@
 
         // Get position of maximum
-        const Int_t   pos = evt->GetMax(idx);
-        const Float_t max = evt->GetSamples(idx)[pos];
+        Float_t max;
+        const Int_t pos = evt->GetMax(idx, max);
 
         // check if maximum is high enough
Index: /trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc
===================================================================
--- /trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc	(revision 8518)
+++ /trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc	(revision 8519)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MExtractPedestal.cc,v 1.30 2007-05-11 15:47:18 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MExtractPedestal.cc,v 1.31 2007-05-16 13:56:17 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -648,5 +648,5 @@
 
     // Do some handling if maxpos is last slice?
-    const Int_t maxposhi = fSignal->GetMax(idx, start, start+range-1);
+    const Int_t maxposhi = fSignal->GetMaxPos(idx, start, start+range-1);
 
     const Float_t *sig = fSignal->GetSamples(idx);
Index: /trunk/MagicSoft/Mars/mpedestal/MPedestalSubtractedEvt.cc
===================================================================
--- /trunk/MagicSoft/Mars/mpedestal/MPedestalSubtractedEvt.cc	(revision 8518)
+++ /trunk/MagicSoft/Mars/mpedestal/MPedestalSubtractedEvt.cc	(revision 8519)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MPedestalSubtractedEvt.cc,v 1.3 2007-03-04 12:01:37 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MPedestalSubtractedEvt.cc,v 1.4 2007-05-16 13:56:17 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -130,43 +130,57 @@
 // --------------------------------------------------------------------------
 //
-// Get the maximum of the slices [first,last] of pixel index.
+// Get the maximum of the pedestal subtracted slices [first,last] of
+// pixel with index idx.
 //
 // The position returned is the index of the position of the pedestal
 // subtracted maximum w.r.t. to first.
-// The value returned is the maximum of the raw-data.
+// The value returned is the maximum corresponding to this index.
 //
 // Warning: No range checks and no sanity checks are done!
 //
-Int_t MPedestalSubtractedEvt::GetMax(const Int_t idx, const Int_t first, const Int_t last, UInt_t &val) const
+Int_t MPedestalSubtractedEvt::GetMax(const Int_t idx, const Int_t first, const Int_t last, Float_t &val) const
 {
     // Get pointer to first slice to be considered
-    Byte_t  const *samb = GetSamplesRaw(idx);
-    Float_t const *samf = GetSamples(idx);
-
-    Byte_t  const *ptrb = samb+first;
-    Float_t const *ptrf = samf+first;
+    Float_t const *sam = GetSamples(idx);
+
+    Float_t const *beg = sam+first;
 
     // The best information so far: the first slice is the maximum
-    const Byte_t  *maxb = ptrb;
-    const Float_t *maxf = ptrf;
-
-    // Store the pointer to the first slice
-//    const Byte_t  *begb = ptrb;
-    const Float_t *begf = ptrf;
-
-    // Calculate the last slice to be considered
-    const Byte_t  *endb = samb+last;
-
-    while (ptrb<endb)
-    {
-        // Pre-increment: check the second slice first
-        if (*++ptrb>*maxb)
-            maxb = ptrb;
-        if (*++ptrf>*maxf)
-            maxf = ptrf;
-    }
-
-    val = *maxb;
-    return maxf-begf;
+    const Float_t *max = beg;
+
+    for (const Float_t *ptr=beg+1; ptr<=sam+last; ptr++)
+        if (*++ptr>*max)
+            max = ptr;
+
+    val = *max;
+    return max-beg;
+}
+
+// --------------------------------------------------------------------------
+//
+// Get the maximum of the raw slices [first,last] of pixel with index idx.
+//
+// The position returned is the index of the position of the raw-data
+// w.r.t. to first.
+// The value returned is the maximum corresponding to this index.
+//
+// Warning: No range checks and no sanity checks are done!
+//
+Int_t MPedestalSubtractedEvt::GetRawMax(const Int_t idx, const Int_t first, const Int_t last, UInt_t &val) const
+{
+    // Get pointer to first slice to be considered
+    Byte_t const *sam = GetSamplesRaw(idx);
+
+    Byte_t const *beg = sam+first;
+
+    // The best information so far: the first slice is the maximum
+    const Byte_t *max = beg;
+
+    for (const Byte_t *ptr=beg+1; ptr<=sam+last; ptr++)
+        if (*++ptr>*max)
+            max = ptr;
+
+    val = *max;
+    return max-beg;
 }
 
Index: /trunk/MagicSoft/Mars/mpedestal/MPedestalSubtractedEvt.h
===================================================================
--- /trunk/MagicSoft/Mars/mpedestal/MPedestalSubtractedEvt.h	(revision 8518)
+++ /trunk/MagicSoft/Mars/mpedestal/MPedestalSubtractedEvt.h	(revision 8519)
@@ -41,20 +41,55 @@
     Int_t GetSaturation(const Int_t idx, Int_t limit, Int_t &first, Int_t &last) const;
     //void  InterpolateSaturation(const Int_t idx, Int_t limit, Int_t first, Int_t last) const;
-    Int_t GetMax(const Int_t pixidx, const Int_t first, const Int_t last, UInt_t &val) const;
-    Int_t GetMax(const Int_t pixidx, const Int_t first, const Int_t last) const
+
+    Int_t GetMax(const Int_t pixidx, const Int_t first, const Int_t last, Float_t &val) const;
+    Int_t GetMax(const Int_t pixidx, Float_t &val) const
     {
-        UInt_t val;
+        return GetMax(pixidx, 0, fNumSamples-1, val);
+    }
+    Int_t GetMaxPos(const Int_t pixidx, const Int_t first, const Int_t last) const
+    {
+        Float_t val;
         return GetMax(pixidx, first, last, val);
     }
-    Int_t GetMax(const Int_t pixidx, UInt_t &val) const
+    Int_t GetMaxPos(const Int_t pixidx, Float_t &val) const
     {
         return GetMax(pixidx, 0, fNumSamples-1, val);
     }
 
-    Int_t GetMax(const Int_t pixidx) const
+    Int_t GetMaxPos(const Int_t pixidx) const
+    {
+        Float_t val;
+        return GetMax(pixidx, 0, fNumSamples-1, val);
+    }
+
+    Int_t GetRawMax(const Int_t idx, const Int_t first, const Int_t last, UInt_t &val) const;
+    Int_t GetRawMax(const Int_t pixidx, UInt_t &val) const
+    {
+        return GetRawMax(pixidx, 0, fNumSamples-1, val);
+    }
+    Int_t GetRawMaxPos(const Int_t pixidx, const Int_t first, const Int_t last) const
     {
         UInt_t val;
-        return GetMax(pixidx, 0, fNumSamples-1, val);
+        return GetRawMax(pixidx, first, last, val);
     }
+    Int_t GetRawMaxPos(const Int_t pixidx, UInt_t &val) const
+    {
+        return GetRawMax(pixidx, 0, fNumSamples-1, val);
+    }
+
+    Int_t GetRawMaxPos(const Int_t pixidx) const
+    {
+        UInt_t val;
+        return GetRawMax(pixidx, 0, fNumSamples-1, val);
+    }
+
+    UInt_t GetRawMaxVal(const Int_t idx, const Int_t first, const Int_t last) const
+    {
+        UInt_t val;
+        GetRawMax(idx, first, last, val);
+        return val;
+    }
+
+
     Int_t GetSaturation(const Int_t pixidx, Int_t limit) const
     {
Index: /trunk/MagicSoft/Mars/msignal/MExtractBlindPixel.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractBlindPixel.cc	(revision 8518)
+++ /trunk/MagicSoft/Mars/msignal/MExtractBlindPixel.cc	(revision 8519)
@@ -362,6 +362,5 @@
     Int_t sat1 = fHiGainLast;  // Last  slice to extract and last saturating slice
 
-    UInt_t maxcont;
-    Int_t maxpos = fSignal->GetMax(idx, sat0, sat1, maxcont);
+    Int_t maxpos = fSignal->GetMaxPos(idx, sat0, sat1);
 
 //    numsat = fSignal->GetSaturation(idx, fSaturationLimit, sat0, sat1);
Index: /trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc	(revision 8518)
+++ /trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc	(revision 8519)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MExtractTimeAndCharge.cc,v 1.64 2007-03-04 13:25:07 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MExtractTimeAndCharge.cc,v 1.65 2007-05-16 13:56:17 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -189,9 +189,11 @@
 // order polynomial interpolation.
 //
-Double_t MExtractTimeAndCharge::GetSaturationTime(Int_t sat0, const Float_t *sig, Int_t maxcont) const
+Double_t MExtractTimeAndCharge::GetSaturationTime(Int_t sat0, const Float_t *sig, Int_t maxpos) const
 {
     const Int_t p = sat0>1 ? sat0-2 : sat0-1;
     if (sat0<=0)
         return 0;
+
+    const Float_t &maxcont = sig[maxpos];
     if (sat0==1)
         return sig[0]>maxcont/2 ? 0 : 0.5;
@@ -228,10 +230,10 @@
         const Float_t *sig = fSignal->GetSamples(pixidx);
 
-        Int_t sathi0 = fHiGainFirst;  // First slice to extract and first saturating slice
-        Int_t sathi1 = fHiGainLast;   // Last  slice to extract and last saturating slice
-
-        UInt_t maxcont;
-        Int_t maxposhi = fSignal->GetMax(pixidx, sathi0, sathi1, maxcont);
+        const UInt_t maxcont  = fSignal->GetRawMaxVal(pixidx, fHiGainFirst, fHiGainLast);
+        const  Int_t maxposhi = fSignal->GetMaxPos(pixidx, fHiGainFirst, fHiGainLast);
+
         // Would it be better to take lastsat-firstsat?
+        Int_t sathi0   = fHiGainFirst;  // First slice to extract and first saturating slice
+        Int_t sathi1   = fHiGainLast;   // Last  slice to extract and last saturating slice
         Int_t numsathi = fSignal->GetSaturation(pixidx, fSaturationLimit, sathi0, sathi1);
 
@@ -253,5 +255,5 @@
         if (numsathi>1)
         {
-            timehi = GetSaturationTime(sathi0, sig, maxcont)-fHiGainFirst;
+            timehi = GetSaturationTime(sathi0, sig, fHiGainFirst+maxposhi)-fHiGainFirst;
             deltatimehi = 0;
         }
@@ -335,10 +337,9 @@
                 first = numh+fLoGainFirst;
              */
+            // Would it be better to take lastsat-firstsat?
+            const Int_t maxposlo = fSignal->GetMaxPos(pixidx, first, last);
+
             Int_t satlo0 = first;   // First slice to extract and first saturating slice
             Int_t satlo1 = last;    // Last  slice to extract and last saturating slice
-
-            // Would it be better to take lastsat-firstsat?
-            UInt_t maxlo;
-            Int_t maxposlo = fSignal->GetMax(pixidx, satlo0, satlo1, maxlo);
             numsatlo = fSignal->GetSaturation(pixidx, fSaturationLimit, satlo0, satlo1);
 
@@ -359,5 +360,5 @@
             if (numsatlo>1)
             {
-                timelo = GetSaturationTime(satlo0, sig, maxlo)-numh-first;
+                timelo = GetSaturationTime(satlo0, sig, first+maxposlo)-numh-first;
                 deltatimelo = 0;
             }
Index: /trunk/MagicSoft/Mars/msignal/MSignalCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MSignalCalc.cc	(revision 8518)
+++ /trunk/MagicSoft/Mars/msignal/MSignalCalc.cc	(revision 8519)
@@ -137,5 +137,5 @@
 
         Byte_t *ptr   = raw;
-        Byte_t *max   = ptr+fRawEvt->GetMax(i, 0, nhi);
+        Byte_t *max   = ptr+fRawEvt->GetMaxPos(i, 0, nhi);
 	Byte_t *end   = ptr+nhi;
         Byte_t *first = max-fBefore;
@@ -199,5 +199,5 @@
             // Area: x9
             ptr = raw+nhi;
-            max = ptr+fRawEvt->GetMax(i, nhi, nhi+nlo);
+            max = ptr+fRawEvt->GetMaxPos(i, nhi, nhi+nlo);
 
             if (*max>250)
