Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 8307)
+++ trunk/MagicSoft/Mars/Changelog	(revision 8308)
@@ -24,4 +24,8 @@
      - included check for monitoring flag
 
+   * mextralgo/MExtralgoSpline.[h,cc]:
+     - implemented the possibility to determine the pulse width at
+       maxheight/2
+
 
 
Index: trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.cc
===================================================================
--- trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.cc	(revision 8307)
+++ trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.cc	(revision 8308)
@@ -126,5 +126,5 @@
         x = x3;
 
-    return x<0 ? -1 : x+i;
+    return x<0 ? -2 : x+i;
 }
 
@@ -132,5 +132,5 @@
 //
 // Search analytically downward for the value y of the spline, starting
-// at x, until x==0. If y is not found -1 is returned.
+// at x, until x==0. If y is not found -2 is returned.
 //
 Double_t MExtralgoSpline::SearchY(Float_t x, Float_t y) const
@@ -142,4 +142,17 @@
     Double_t rc = FindY(i, y, 0, x-i);
     while (--i>=0 && rc<0)
+        rc = FindY(i, y);
+
+    return rc;
+}
+
+Double_t MExtralgoSpline::SearchYup(Float_t x, Float_t y) const
+{
+    if (x<0)
+        x = 0.0001;
+
+    Int_t i = TMath::FloorNint(x);
+    Double_t rc = FindY(i, y, x-i, 1.);
+    while (i++<fNum-1 && rc<0)
         rc = FindY(i, y);
 
@@ -227,10 +240,12 @@
 }
 
-void MExtralgoSpline::Extract(Byte_t sat, Int_t maxbin)
+void MExtralgoSpline::Extract(Byte_t sat, Int_t maxbin, Bool_t width)
 {
     fSignal    =  0;
     fTime      =  0;
+    fWidth     =  0;
     fSignalDev = -1;
     fTimeDev   = -1;
+    fWidthDev  = -1;
 
     if (fNum<2)
@@ -381,7 +396,7 @@
     }*/
 
-    Float_t maxpos, maxval;
+    Float_t maxpos;
     // FIXME: Check the default if no maximum found!!!
-    GetMaxAroundI(maxbin, maxpos, maxval);
+    GetMaxAroundI(maxbin, maxpos, fHeight);
 
     // --- End NEW ---
@@ -391,15 +406,20 @@
         fTime      = maxpos;
         fTimeDev   = 0;
-        fSignal    = maxval;
+        fSignal    = fHeight;
         fSignalDev = 0;  // means: is valid
         return;
     }
 
-    // Search downwards for maxval/2
+    const Float_t h = fExtractionType==kIntegralAbs ? fHeightTm : fHeight*fHeightTm;
+
+    // Search downwards for fHeight/2
     // By doing also a search upwards we could extract the pulse width
-    const Double_t x1 = SearchY(maxpos, maxval/2);
-
-    fTime      = x1;
+    fTime      = SearchY(maxpos, h);
     fTimeDev   = 0;
+    if (width)
+    {
+        fWidth    = SearchYup(maxpos, h)-fTime;
+        fWidthDev = 0;
+    }
     fSignal    = CalcIntegral(maxpos);
     fSignalDev = 0;  // means: is valid
Index: trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h
===================================================================
--- trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h	(revision 8307)
+++ trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h	(revision 8308)
@@ -12,5 +12,5 @@
 {
 public:  
-    enum ExtractionType_t { kAmplitude, kIntegral };    //! Possible time and charge extraction types
+    enum ExtractionType_t { kAmplitude, kIntegralRel, kIntegralAbs };    //! Possible time and charge extraction types
 
 private:
@@ -30,4 +30,6 @@
     Float_t fFallTime;
 
+    Float_t fHeightTm;
+
 //    Float_t fResolution;
 
@@ -35,6 +37,9 @@
     Float_t fTime;
     Float_t fTimeDev;
+    Float_t fWidth;
+    Float_t fWidthDev;
     Float_t fSignal;
     Float_t fSignalDev;
+    Float_t fHeight;
 
     Double_t ReMul(const TComplex &c1, const TComplex &th) const;
@@ -89,4 +94,5 @@
     Double_t FindY(Int_t i, Double_t y=0, Double_t min=0, Double_t max=1) const;
     Double_t SearchY(Float_t maxpos, Float_t y) const;
+    Double_t SearchYup(Float_t maxpos, Float_t y) const;
 /*
     // Evaluate first solution for a possible maximum (x|first deriv==0)
@@ -230,5 +236,5 @@
             rc1 = kTRUE;
         }
-        if (i>fNum-2)
+        if (i>=fNum-1)
         {
             xmax2 = fNum-1;
@@ -440,5 +446,5 @@
 public:
     MExtralgoSpline(const Float_t *val, Int_t n, Float_t *der1, Float_t *der2)
-        : fExtractionType(kIntegral), fVal(val), fNum(n), fDer1(der1), fDer2(der2), fTime(0), fTimeDev(-1), fSignal(0), fSignalDev(-1)
+        : fExtractionType(kIntegralRel), fVal(val), fNum(n), fDer1(der1), fDer2(der2), fHeightTm(0.5), fTime(0), fTimeDev(-1), fSignal(0), fSignalDev(-1)
     {
         InitDerivatives();
@@ -447,17 +453,22 @@
     void SetRiseFallTime(Float_t rise, Float_t fall) { fRiseTime=rise; fFallTime=fall; }
     void SetExtractionType(ExtractionType_t typ)     { fExtractionType = typ; }
-//    void SetResolution(Float_t res)                  { fResolution=res; }
+    void SetHeightTm(Float_t h)                      { fHeightTm = h; }
+        //    void SetResolution(Float_t res)                  { fResolution=res; }
 
     Float_t GetTime() const      { return fTime; }
+    Float_t GetWidth() const     { return fWidth; }
     Float_t GetSignal() const    { return fSignal; }
+    Float_t GetHeight() const    { return fHeight; }
 
     Float_t GetTimeDev() const   { return fTimeDev; }
+    Float_t GetWidthDev() const  { return fWidthDev; }
     Float_t GetSignalDev() const { return fSignalDev; }
 
     void GetSignal(Float_t &sig, Float_t &dsig) const { sig=fSignal; dsig=fSignalDev; }
+    void GetWidth(Float_t &sig, Float_t &dsig) const  { sig=fWidth; dsig=fWidthDev; }
     void GetTime(Float_t &sig, Float_t &dsig) const   { sig=fTime; dsig=fTimeDev; }
 
     Float_t ExtractNoise(/*Int_t iter*/);
-    void Extract(Byte_t sat, Int_t maxpos);
+    void Extract(Byte_t sat, Int_t maxpos, Bool_t width=kFALSE);
 };
 
