Index: /trunk/MagicSoft/Mars/NEWS
===================================================================
--- /trunk/MagicSoft/Mars/NEWS	(revision 4339)
+++ /trunk/MagicSoft/Mars/NEWS	(revision 4340)
@@ -1,4 +1,7 @@
                                                                -*-*- END -*-*-
  *** Version <cvs>
+ 
+   - new Signal Extractors: MExtractFixedWindowSpline 
+                         nd MExtractAmplitudeSpline
 
    - implementes interleave in merpp to be able to merpp parts of a file
@@ -9,5 +12,4 @@
 
    - star display to 'mirror' stars to the camera (MAstroCamera)
-
 
 
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeCam.cc	(revision 4339)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeCam.cc	(revision 4340)
@@ -1105,4 +1105,5 @@
   leg->SetBit(kCanDelete);
   leg->AddEntry(green1,"1 Led GREEN","l");
+  leg->AddEntry(green5,"5 Leds GREEN","l");
   leg->AddEntry(blue1,"1 Led BLUE","l");
   leg->AddEntry(blue5,"5 Leds BLUE","l");
Index: /trunk/MagicSoft/Mars/msignal/MExtractAmplitudeSpline.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractAmplitudeSpline.cc	(revision 4340)
+++ /trunk/MagicSoft/Mars/msignal/MExtractAmplitudeSpline.cc	(revision 4340)
@@ -0,0 +1,645 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analyzing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!   Author(s): Markus Gaug       05/2004 <mailto:markus@ifae.es> 
+!
+!   Copyright: MAGIC Software Development, 2002-2004
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+//   MExtractTimeAndChargeSpline
+//
+//   Fast Spline extractor using a cubic spline algorithm of Numerical Recipes. 
+//   It returns the integral below the interpolating spline. 
+// 
+//   Call: SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast) 
+//         to modify the ranges. Ranges have to be an even number. In case of odd 
+//         ranges, the last slice will be reduced by one.
+//
+//  Defaults are: 
+// 
+//   fHiGainFirst =  fgHiGainFirst =  3 
+//   fHiGainLast  =  fgHiGainLast  =  14
+//   fLoGainFirst =  fgLoGainFirst =  3 
+//   fLoGainLast  =  fgLoGainLast  =  14
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MExtractAmplitudeSpline.h"
+
+#include "MExtractedSignalCam.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MExtractAmplitudeSpline);
+
+using namespace std;
+
+const Byte_t  MExtractAmplitudeSpline::fgHiGainFirst  = 2;
+const Byte_t  MExtractAmplitudeSpline::fgHiGainLast   = 14;
+const Byte_t  MExtractAmplitudeSpline::fgLoGainFirst  = 3;
+const Byte_t  MExtractAmplitudeSpline::fgLoGainLast   = 14;
+const Float_t MExtractAmplitudeSpline::fgResolution   = 0.003;
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+// Calls: 
+// - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
+// 
+MExtractAmplitudeSpline::MExtractAmplitudeSpline(const char *name, const char *title) 
+    : fHiGainSignal(NULL), fLoGainSignal(NULL),
+      fHiGainFirstDeriv(NULL), fLoGainFirstDeriv(NULL),
+      fHiGainSecondDeriv(NULL), fLoGainSecondDeriv(NULL)
+{
+
+  fName  = name  ? name  : "MExtractAmplitudeSpline";
+  fTitle = title ? title : "Signal Extractor for a fixed FADC window using a fast spline";
+
+  SetResolution();
+  SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
+}
+
+MExtractAmplitudeSpline::~MExtractAmplitudeSpline()
+{
+  
+  if (fHiGainSignal)
+    delete fHiGainSignal;
+  if (fLoGainSignal)
+    delete fLoGainSignal;
+  if (fHiGainFirstDeriv)
+    delete fHiGainFirstDeriv;
+  if (fLoGainFirstDeriv)
+    delete fLoGainFirstDeriv;
+  if (fHiGainSecondDeriv)
+    delete fHiGainSecondDeriv;
+  if (fLoGainSecondDeriv)
+    delete fLoGainSecondDeriv;
+  
+}
+
+// --------------------------------------------------------------------------
+//
+// SetRange: 
+//
+// Checks: 
+// - if the window defined by (fHiGainLast-fHiGainFirst-1) are odd, subtract one
+// - if the window defined by (fLoGainLast-fLoGainFirst-1) are odd, subtract one
+// - if the Hi Gain window is smaller than 2, set fHiGainLast to fHiGainFirst+1
+// - if the Lo Gain window is smaller than 2, set fLoGainLast to fLoGainFirst+1
+// 
+// Calls:
+// - MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
+// 
+// Sets:
+// - fNumHiGainSamples to: (Float_t)(fHiGainLast-fHiGainFirst+1)
+// - fNumLoGainSamples to: (Float_t)(fLoGainLast-fLoGainFirst+1)
+// - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples)
+// - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples)  
+//  
+void MExtractAmplitudeSpline::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
+{
+
+
+  MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
+
+  fNumHiGainSamples = 1.;
+  fNumLoGainSamples = 1.;
+
+  fSqrtHiGainSamples = 1.;
+  fSqrtLoGainSamples = 1.;
+
+  fHiLoLast  = 0;
+  
+}
+
+// --------------------------------------------------------------------------
+//
+// ReInit
+//
+// Calls:
+// - MExtractor::ReInit(pList);
+// - fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
+//                                fLoGainFirst, fLoGainLast, fNumLoGainSamples);
+// 
+// Deletes all arrays, if not NULL
+// Creates new arrays according to the extraction range
+//
+Bool_t MExtractAmplitudeSpline::ReInit(MParList *pList)
+{
+
+  if (!MExtractor::ReInit(pList))
+    return kFALSE;
+
+  fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
+                              fLoGainFirst, fLoGainLast, fNumLoGainSamples);
+
+  if (fHiGainSignal)
+    delete fHiGainSignal;
+  if (fLoGainSignal)
+    delete fLoGainSignal;
+  if (fHiGainFirstDeriv)
+    delete fHiGainFirstDeriv;
+  if (fLoGainFirstDeriv)
+    delete fLoGainFirstDeriv;
+  if (fHiGainSecondDeriv)
+    delete fHiGainSecondDeriv;
+  if (fLoGainSecondDeriv)
+    delete fLoGainSecondDeriv;
+  
+  Int_t range = fHiGainLast - fHiGainFirst + 1 + fHiLoLast;
+
+  fHiGainSignal = new Float_t[range];
+  memset(fHiGainSignal,0,range*sizeof(Float_t));
+  fHiGainFirstDeriv  = new Float_t[range];
+  memset(fHiGainFirstDeriv,0,range*sizeof(Float_t));
+  fHiGainSecondDeriv = new Float_t[range];
+  memset(fHiGainSecondDeriv,0,range*sizeof(Float_t));
+
+  *fLog << endl;
+  *fLog << inf << GetDescriptor() << ": Using for High-Gain Extraction " << range
+        << " FADC samples from " 
+        << Form("%s%2i%s"," High Gain slice ",(Int_t)fHiGainFirst," to (including) ")
+        << Form("%s%2i",fHiLoLast ? "Low Gain slice " : " High Gain slice ",
+                fHiLoLast ?  (Int_t)fHiLoLast : (Int_t)fHiGainLast ) 
+        << endl;
+
+  range = fLoGainLast - fLoGainFirst + 1;
+
+  fLoGainSignal = new Float_t[range];
+  memset(fLoGainSignal,0,range*sizeof(Float_t));
+  fLoGainFirstDeriv  = new Float_t[range];
+  memset(fLoGainFirstDeriv,0,range*sizeof(Float_t));
+  fLoGainSecondDeriv = new Float_t[range];
+  memset(fLoGainSecondDeriv,0,range*sizeof(Float_t));
+
+  *fLog << endl;
+  *fLog << inf << GetDescriptor() << ": Using for Low-Gain Extraction " << range
+        << " FADC samples from " 
+        << Form("%s%2i%s%2i"," Low Gain slice ",(Int_t)fLoGainFirst,
+                " to (including) ",(Int_t)fLoGainLast) << endl;
+
+  return kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// FindSignalHiGain:
+//
+// - Loop from ptr to (ptr+fHiGainLast-fHiGainFirst)
+// - Sum up contents of *ptr
+// - If *ptr is greater than fSaturationLimit, raise sat by 1
+// 
+// - If fHiLoLast is not 0, loop also from logain to (logain+fHiLoLast)
+// - Sum up contents of logain
+// - If *logain is greater than fSaturationLimit, raise sat by 1
+//
+void MExtractAmplitudeSpline::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) const
+{
+  
+  Int_t count   = 0;
+  Float_t abmaxpos = 0.;
+  Byte_t max    = 0;
+  Byte_t maxpos = 0;
+  
+  Int_t range = fHiGainLast - fHiGainFirst + 1;
+  Byte_t *end = ptr + range;
+  Byte_t *p     = ptr;
+  //
+  // Check for saturation in all other slices
+  //
+  while (++p<end)
+    {
+      
+      fHiGainSignal[count] = (Float_t)*p;
+      
+      if (*p > max)
+        {
+          max    = *p;
+          maxpos =  count;
+        }
+      
+      range++;
+      count++;
+      
+      if (*p >= fSaturationLimit)
+        {
+          sat++;
+              break;
+        }
+    }
+  
+  if (fHiLoLast != 0)
+    {
+      
+      p    = logain;
+      end  = logain + fHiLoLast + 1;
+      
+      while (p<end)
+        {
+          
+          fHiGainSignal[count] = (Float_t)*p;
+
+          if (*p > max)
+            {
+              max    = *p;
+              maxpos =  count;
+            }
+          
+          range++;
+          count++;
+
+          if (*p++ >= fSaturationLimit)
+            {
+              sat++;
+              break;
+            }
+        }
+    }
+
+  //
+  // allow one saturated slice 
+  //
+  if (sat > 1)
+    return;
+
+  //
+  // Don't start if the maxpos is too close to the left limit.
+  //
+  if (maxpos < 2)
+    return;
+
+  Float_t pp;
+  fHiGainSecondDeriv[0] = 0.;
+  fHiGainFirstDeriv[0]  = 0.;
+
+  for (Int_t i=1;i<range-1;i++)
+    {
+      pp = fHiGainSecondDeriv[i-1] + 4.;
+      fHiGainSecondDeriv[i] = -1.0/pp;
+      fHiGainFirstDeriv [i] = fHiGainSignal[i+1] - fHiGainSignal[i] - fHiGainSignal[i] + fHiGainSignal[i-1];
+      fHiGainFirstDeriv [i] = (6.0*fHiGainFirstDeriv[i]-fHiGainFirstDeriv[i-1])/pp;
+      p++;
+    }
+
+  fHiGainSecondDeriv[range-1] = 0.;
+  for (Int_t k=range-2;k>=0;k--)
+    fHiGainSecondDeriv[k] = (fHiGainSecondDeriv[k]*fHiGainSecondDeriv[k+1] + fHiGainFirstDeriv[k])/6.;
+  
+  //
+  // Now find the maximum  
+  //
+  Float_t step  = 0.2; // start with step size of 1ns and loop again with the smaller one
+  Float_t lower = (Float_t)maxpos-1.;
+  Float_t upper = (Float_t)maxpos;
+  Float_t x     = lower;
+  Float_t y     = 0.;
+  Float_t a     = 1.;
+  Float_t b     = 0.;
+  Int_t   klo = maxpos-1;
+  Int_t   khi = maxpos;
+  Float_t klocont = fHiGainSignal[klo];
+  Float_t khicont = fHiGainSignal[khi];
+  sum       = khicont;
+  abmaxpos  = lower;
+
+  //
+  // Search for the maximum, starting in interval maxpos-1. If no maximum is found, go to 
+  // interval maxpos+1.
+  //
+  while (x<upper-0.3)
+    {
+
+      x += step;
+      a -= step;
+      b += step;
+
+      y = a*klocont
+        + b*khicont
+        + (a*a*a-a)*fHiGainSecondDeriv[klo] 
+        + (b*b*b-b)*fHiGainSecondDeriv[khi];
+
+      if (y > sum)
+        {
+          sum      = y;
+          abmaxpos = x;
+        }
+    }
+
+  if (abmaxpos > upper-0.1)
+    {
+      
+      upper = (Float_t)maxpos+1;
+      lower = (Float_t)maxpos;
+      x     = lower;
+      a     = 1.;
+      b     = 0.;
+      khi   = maxpos+1;
+      klo   = maxpos;
+      klocont = fHiGainSignal[klo];
+      khicont = fHiGainSignal[khi];
+
+      while (x<upper-0.3)
+        {
+
+          x += step;
+          a -= step;
+          b += step;
+          
+          y = a* klocont
+            + b* khicont
+            + (a*a*a-a)*fHiGainSecondDeriv[klo] 
+            + (b*b*b-b)*fHiGainSecondDeriv[khi];
+          
+          if (y > sum)
+            {
+              sum    = y;
+              abmaxpos = x;
+            }
+        }
+    }
+
+ const Float_t up = abmaxpos+step-0.055;
+ const Float_t lo = abmaxpos-step+0.055;
+ const Float_t maxpossave = abmaxpos;
+ 
+ x     = abmaxpos;
+ a     = upper - x;
+ b     = x - lower;
+
+  step  = 0.04; // step size of 83 ps 
+
+  while (x<up)
+    {
+
+      x += step;
+      a -= step;
+      b += step;
+      
+      y = a* klocont
+        + b* khicont
+        + (a*a*a-a)*fHiGainSecondDeriv[klo] 
+        + (b*b*b-b)*fHiGainSecondDeriv[khi];
+      
+      if (y > sum)
+        {
+          sum    = y;
+          abmaxpos = x;
+        }
+    }
+
+ if (abmaxpos < klo + 0.02)
+    {
+      klo--;
+      khi--;
+      klocont = fHiGainSignal[klo];
+      khicont = fHiGainSignal[khi];
+      upper--;
+      lower--;
+    }
+ 
+  x     = maxpossave;
+  a     = upper - x;
+  b     = x - lower;
+
+  while (x>lo)
+    {
+
+      x -= step;
+      a += step;
+      b -= step;
+      
+      y = a* klocont
+        + b* khicont
+        + (a*a*a-a)*fHiGainSecondDeriv[klo] 
+        + (b*b*b-b)*fHiGainSecondDeriv[khi];
+      
+      if (y > sum)
+        sum      = y;
+    }
+}
+
+
+// --------------------------------------------------------------------------
+//
+// FindSignalLoGain:
+//
+// - Loop from ptr to (ptr+fLoGainLast-fLoGainFirst)
+// - Sum up contents of *ptr
+// - If *ptr is greater than fSaturationLimit, raise sat by 1
+// 
+void MExtractAmplitudeSpline::FindSignalLoGain(Byte_t *ptr, Float_t &sum, Byte_t &sat) const
+{
+  
+  Int_t count   = 0;
+  Float_t abmaxpos = 0.;
+  Byte_t max    = 0;
+  Byte_t maxpos = 0;
+  
+  Int_t range = fLoGainLast - fLoGainFirst + 1;
+  Byte_t *end = ptr + range;
+  Byte_t *p   = ptr;
+  //
+  // Check for saturation in all other slices
+  //
+  while (++p<end)
+    {
+      
+      fLoGainSignal[count] = (Float_t)*p;
+      
+      if (*p > max)
+        {
+          max    = *p;
+          maxpos =  count;
+        }
+      
+      range++;
+      count++;
+      
+      if (*p >= fSaturationLimit)
+        {
+          sat++;
+              break;
+        }
+    }
+  
+
+  //
+  // allow one saturated slice 
+  //
+  if (sat > 1)
+    return;
+
+  //
+  // Don't start if the maxpos is too close to the left limit.
+  //
+  if (maxpos < 2)
+    return;
+
+  Float_t pp;
+  fLoGainSecondDeriv[0] = 0.;
+  fLoGainFirstDeriv[0]  = 0.;
+
+  for (Int_t i=1;i<range-1;i++)
+    {
+      pp = fLoGainSecondDeriv[i-1] + 4.;
+      fLoGainSecondDeriv[i] = -1.0/pp;
+      fLoGainFirstDeriv [i] = fLoGainSignal[i+1] - fLoGainSignal[i] - fLoGainSignal[i] + fLoGainSignal[i-1];
+      fLoGainFirstDeriv [i] = (6.0*fLoGainFirstDeriv[i]-fLoGainFirstDeriv[i-1])/pp;
+      p++;
+    }
+
+  fLoGainSecondDeriv[range-1] = 0.;
+  for (Int_t k=range-2;k>=0;k--)
+    fLoGainSecondDeriv[k] = (fLoGainSecondDeriv[k]*fLoGainSecondDeriv[k+1] + fLoGainFirstDeriv[k])/6.;
+  
+  //
+  // Now find the maximum  
+  //
+  Float_t step  = 0.2; // start with step size of 1ns and loop again with the smaller one
+  Float_t lower = (Float_t)maxpos-1.;
+  Float_t upper = (Float_t)maxpos;
+  Float_t x     = lower;
+  Float_t y     = 0.;
+  Float_t a     = 1.;
+  Float_t b     = 0.;
+  Int_t   klo = maxpos-1;
+  Int_t   khi = maxpos;
+  Float_t klocont = fLoGainSignal[klo];
+  Float_t khicont = fLoGainSignal[khi];
+  sum       = khicont;
+  abmaxpos  = lower;
+
+  //
+  // Search for the maximum, starting in interval maxpos-1. If no maximum is found, go to 
+  // interval maxpos+1.
+  //
+  while (x<upper-0.3)
+    {
+
+      x += step;
+      a -= step;
+      b += step;
+
+      y = a*klocont
+        + b*khicont
+        + (a*a*a-a)*fLoGainSecondDeriv[klo] 
+        + (b*b*b-b)*fLoGainSecondDeriv[khi];
+
+      if (y > sum)
+        {
+          sum      = y;
+          abmaxpos = x;
+        }
+    }
+
+  if (abmaxpos > upper-0.1)
+    {
+      
+      upper = (Float_t)maxpos+1;
+      lower = (Float_t)maxpos;
+      x     = lower;
+      a     = 1.;
+      b     = 0.;
+      khi   = maxpos+1;
+      klo   = maxpos;
+      klocont = fLoGainSignal[klo];
+      khicont = fLoGainSignal[khi];
+
+      while (x<upper-0.3)
+        {
+
+          x += step;
+          a -= step;
+          b += step;
+          
+          y = a* klocont
+            + b* khicont
+            + (a*a*a-a)*fLoGainSecondDeriv[klo] 
+            + (b*b*b-b)*fLoGainSecondDeriv[khi];
+          
+          if (y > sum)
+            {
+              sum    = y;
+              abmaxpos = x;
+            }
+        }
+    }
+
+ const Float_t up = abmaxpos+step-0.055;
+ const Float_t lo = abmaxpos-step+0.055;
+ const Float_t maxpossave = abmaxpos;
+ 
+ x     = abmaxpos;
+ a     = upper - x;
+ b     = x - lower;
+
+  step  = 0.04; // step size of 83 ps 
+
+  while (x<up)
+    {
+
+      x += step;
+      a -= step;
+      b += step;
+      
+      y = a* klocont
+        + b* khicont
+        + (a*a*a-a)*fLoGainSecondDeriv[klo] 
+        + (b*b*b-b)*fLoGainSecondDeriv[khi];
+      
+      if (y > sum)
+        {
+          sum    = y;
+          abmaxpos = x;
+        }
+    }
+
+ if (abmaxpos < klo + 0.02)
+    {
+      klo--;
+      khi--;
+      klocont = fLoGainSignal[klo];
+      khicont = fLoGainSignal[khi];
+      upper--;
+      lower--;
+    }
+ 
+  x     = maxpossave;
+  a     = upper - x;
+  b     = x - lower;
+
+  while (x>lo)
+    {
+
+      x -= step;
+      a += step;
+      b -= step;
+      
+      y = a* klocont
+        + b* khicont
+        + (a*a*a-a)*fLoGainSecondDeriv[klo] 
+        + (b*b*b-b)*fLoGainSecondDeriv[khi];
+      
+      if (y > sum)
+        sum      = y;
+    }
+}
+
Index: /trunk/MagicSoft/Mars/msignal/MExtractAmplitudeSpline.h
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractAmplitudeSpline.h	(revision 4340)
+++ /trunk/MagicSoft/Mars/msignal/MExtractAmplitudeSpline.h	(revision 4340)
@@ -0,0 +1,47 @@
+#ifndef MARS_MExtractAmplitudeSpline
+#define MARS_MExtractAmplitudeSpline
+
+#ifndef MARS_MExtractor
+#include "MExtractor.h"
+#endif
+
+class MExtractAmplitudeSpline : public MExtractor
+{
+
+private:
+  
+  static const Byte_t  fgHiGainFirst;    // Default for fHiGainFirst  (now set to: 2)
+  static const Byte_t  fgHiGainLast;     // Default for fHiGainLast   (now set to: 14)
+  static const Byte_t  fgLoGainFirst;    // Default for fLOGainFirst  (now set to: 3)
+  static const Byte_t  fgLoGainLast;     // Default for fLoGainLast   (now set to: 14)
+  static const Float_t fgResolution;     // Default for fResolution   (now set to: 0.003)
+
+  Float_t *fHiGainSignal;                     // Need fast access to the signals in a float way
+  Float_t *fLoGainSignal;                     // Need fast access to the signals in a float way  
+  Float_t *fHiGainFirstDeriv;
+  Float_t *fLoGainFirstDeriv;  
+  Float_t *fHiGainSecondDeriv;
+  Float_t *fLoGainSecondDeriv;  
+
+  Float_t fResolution;                        // The time resolution in FADC units
+  
+  Bool_t ReInit    (MParList *pList);
+  
+  void   FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) const;
+  void   FindSignalLoGain(Byte_t *ptr, Float_t &sum, Byte_t &sat) const;
+
+public:
+
+  MExtractAmplitudeSpline(const char *name=NULL, const char *title=NULL);
+  ~MExtractAmplitudeSpline();
+  
+  void SetRange(Byte_t hifirst=0, Byte_t hilast=0, Byte_t lofirst=0, Byte_t lolast=0);
+  void SetResolution(Float_t f=fgResolution)     { fResolution = f;  }
+  
+  ClassDef(MExtractAmplitudeSpline, 0)   // Task to Extract the Amplitude using a Fast Spline
+};
+
+#endif
+
+
+
Index: /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.cc	(revision 4339)
+++ /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.cc	(revision 4340)
@@ -186,6 +186,8 @@
 // - If *logain is greater than fSaturationLimit, raise sat by 1
 //
-void MExtractFixedWindow::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Int_t &sum, Byte_t &sat) const
-{
+void MExtractFixedWindow::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) const
+{
+
+  Int_t summ = 0;
 
   Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
@@ -193,20 +195,21 @@
   while (ptr<end)
     {
-      sum += *ptr;
+      summ += *ptr;
       if (*ptr++ >= fSaturationLimit)
         sat++;
     }
 
-  if (fHiLoLast == 0)
-    return;
-  
+  Byte_t *p = logain;
   end = logain + fHiLoLast;
-  while (logain<end)
-    {
-      sum += *logain;
-      
-      if (*logain++ >= fSaturationLimit)
+  while (p<end)
+    {
+      summ += *p;
+      if (*p++ >= fSaturationLimit)
         sat++;
     }
+
+  sum = (Float_t)summ;
+
+  return;
 }
 
@@ -221,6 +224,8 @@
 // - Add contents of *logain to sum
 // 
-void MExtractFixedWindow::FindSignalLoGain(Byte_t *ptr, Int_t &sum, Byte_t &sat) const
-{
+void MExtractFixedWindow::FindSignalLoGain(Byte_t *ptr, Float_t &sum, Byte_t &sat) const
+{
+
+  Int_t summ = 0;
 
   Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1;
@@ -228,9 +233,11 @@
   while (ptr<end)
     {
-      sum += *ptr;
+      summ += *ptr;
       
       if (*ptr++ >= fSaturationLimit)
         sat++;
     }
+
+  sum = (Float_t)summ;
 }
 
Index: /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.h
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.h	(revision 4339)
+++ /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.h	(revision 4340)
@@ -22,6 +22,6 @@
   static const Byte_t fgLoGainLast;      // Last FADC slice Lo-Gain (currently set to: 14) 
 
-  void   FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Int_t &sum, Byte_t &sat) const;
-  void   FindSignalLoGain(Byte_t *ptr, Int_t &sum, Byte_t &sat) const;
+  void   FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) const;
+  void   FindSignalLoGain(Byte_t *ptr, Float_t &sum, Byte_t &sat) const;
   void   StreamPrimitive(ofstream &out) const;
   
Index: /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.cc	(revision 4339)
+++ /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.cc	(revision 4340)
@@ -299,9 +299,10 @@
 // - If *ptr is greater than fSaturationLimit, raise sat by 1
 // 
-void MExtractFixedWindowPeakSearch::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Int_t &sum, Byte_t &sat) const
+void MExtractFixedWindowPeakSearch::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) const
 {
 
   Byte_t *end = ptr + fWindowSizeHiGain-fHiLoLast;
 
+  Int_t summ = 0;
   //
   // Calculate the sum of the "window" slices starting in ptr
@@ -309,5 +310,5 @@
   while (ptr<end)
     {
-      sum += *ptr;
+      summ += *ptr;
       if (*ptr++ >= fSaturationLimit)
 	sat++;
@@ -323,9 +324,10 @@
     {
   
-      sum += *p;
+      summ += *p;
       if (*p++ >= fSaturationLimit)
         sat++;
     }
 
+  sum = (Float_t)summ;
   return;
 }
@@ -339,5 +341,5 @@
 // - If *ptr is greater than fSaturationLimit, raise sat by 1
 // 
-void MExtractFixedWindowPeakSearch::FindSignalLoGain(Byte_t *ptr, Int_t &sum, Byte_t &sat) const
+void MExtractFixedWindowPeakSearch::FindSignalLoGain(Byte_t *ptr, Float_t &sum, Byte_t &sat) const
 {
   //
@@ -345,12 +347,14 @@
   //
   Byte_t *p = ptr;
+  Int_t summ = 0;
 
   while (p<ptr+fWindowSizeLoGain)
     {
-      sum += *p;
+      summ += *p;
       if (*p++ >= fSaturationLimit)
 	sat++;
     }
 
+  sum = (Float_t)summ;
   return;
 }
@@ -417,10 +421,10 @@
       // Find signal in hi- and lo-gain
       //
-      Int_t sumhi=0;
+      Float_t sumhi=0.;
       Byte_t sathi=0;
 
       FindSignalHiGain(pixel.GetHiGainSamples()+hiGainFirst, pixel.GetLoGainSamples(), sumhi, sathi);
 
-      Int_t sumlo=0;
+      Float_t sumlo=0.;
       Byte_t satlo=0;
       if (pixel.HasLoGain())
@@ -449,4 +453,8 @@
 
       pix.SetGainSaturation(sathi, sathi, satlo);
+
+      //      pix.SetNumHiGainSlices(fNumHiGainSamples);
+      //      pix.SetNumLoGainSlices(fNumLoGainSamples);      
+      
     } /* while (pixel.Next()) */
 
Index: /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.h
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.h	(revision 4339)
+++ /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.h	(revision 4340)
@@ -26,6 +26,6 @@
   Byte_t  fLowGainPeakShift;     // Shift of the low gain pulse with respect to the high gain pulse, in slices: it is 0 if the low gain is delayed with respect to HG by 15 slices.
 
-  void   FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Int_t &sum, Byte_t &sat) const;
-  void   FindSignalLoGain(Byte_t *ptr, Int_t &sum, Byte_t &sat) const;  
+  void   FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) const;
+  void   FindSignalLoGain(Byte_t *ptr, Float_t &sum, Byte_t &sat) const;  
 
   void   FindPeak(Byte_t *ptr, Byte_t window, Byte_t &startslice, Int_t &signal, Int_t &sat) const;
Index: /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowSpline.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowSpline.cc	(revision 4339)
+++ /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowSpline.cc	(revision 4340)
@@ -224,5 +224,5 @@
 // - If *logain is greater than fSaturationLimit, raise sat by 1
 //
-void MExtractFixedWindowSpline::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Int_t &sum, Byte_t &sat) const
+void MExtractFixedWindowSpline::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) const
 {
   
@@ -236,5 +236,6 @@
   fHiGainFirstDeriv[0]  = 0.;
 
-  Float_t sumf = *ptr++/2.;
+  Int_t summ = 0;
+  sum = (Float_t)*ptr++/2.;
   //
   // Check for saturation in all other slices
@@ -243,5 +244,5 @@
     {
 
-      sumf += *ptr;
+      summ += *ptr;
       i++;
 
@@ -260,5 +261,5 @@
   if (fHiLoLast == 0)
     {
-      sumf += *ptr/2.;
+      sum += (Float_t)*ptr/2.;
       fHiGainSecondDeriv[++i] = 0.;      
 
@@ -266,5 +267,5 @@
   else
     {
-      sumf += *ptr;
+      summ += *ptr;
       i++;
 
@@ -279,5 +280,5 @@
         {
 
-          sumf += *logain;
+          summ += *logain;
           i++;
           
@@ -291,5 +292,5 @@
           
         }
-      sumf += *logain/2;
+      sum += (Float_t)*logain/2;
       fHiGainSecondDeriv[++i] = 0.;
     }
@@ -298,8 +299,8 @@
     {
       fHiGainSecondDeriv[k] = fHiGainSecondDeriv[k]*fHiGainSecondDeriv[k+1] + fHiGainFirstDeriv[k];
-      sumf += 0.25*fHiGainSecondDeriv[k];
-    }
-  
-  sum = (Int_t)sumf;
+      sum += 0.25*fHiGainSecondDeriv[k];
+    }
+  
+  sum += (Float_t)summ;
 }
 
@@ -312,5 +313,5 @@
 // - If *ptr is greater than fSaturationLimit, raise sat by 1
 // 
-void MExtractFixedWindowSpline::FindSignalLoGain(Byte_t *ptr, Int_t &sum, Byte_t &sat) const
+void MExtractFixedWindowSpline::FindSignalLoGain(Byte_t *ptr, Float_t &sum, Byte_t &sat) const
 {
   
@@ -324,5 +325,6 @@
   fLoGainFirstDeriv[0]  = 0.;
 
-  Float_t sumf = *ptr++/2.;
+  Int_t summ = 0;
+  sum = (Float_t)*ptr++/2.;
   //
   // Check for saturation in all other slices
@@ -331,5 +333,5 @@
     {
 
-      sumf += *ptr;
+      summ += *ptr;
       i++;
 
@@ -346,5 +348,5 @@
     sat++;
 
-  sumf += *ptr/2.;
+  sum += (Float_t)*ptr/2.;
   fLoGainSecondDeriv[++i] = 0.;      
   
@@ -352,8 +354,8 @@
     {
       fLoGainSecondDeriv[k] = fLoGainSecondDeriv[k]*fLoGainSecondDeriv[k+1] + fLoGainFirstDeriv[k];
-      sumf += 0.25*fLoGainSecondDeriv[k];
-    }
-  
-  sum = (Int_t)sumf;
-}
-
+      sum += 0.25*fLoGainSecondDeriv[k];
+    }
+  
+  sum += (Float_t)summ;
+}
+
Index: /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowSpline.h
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowSpline.h	(revision 4339)
+++ /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowSpline.h	(revision 4340)
@@ -23,6 +23,6 @@
   Bool_t ReInit    (MParList *pList);
   
-  void   FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Int_t &sum, Byte_t &sat) const;
-  void   FindSignalLoGain(Byte_t *ptr, Int_t &sum, Byte_t &sat) const;
+  void   FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Byte_t &sat) const;
+  void   FindSignalLoGain(Byte_t *ptr, Float_t &sum, Byte_t &sat) const;
 
 public:
Index: /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.cc	(revision 4339)
+++ /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.cc	(revision 4340)
@@ -215,9 +215,10 @@
 // - Check if the sum has become bigger and store it in case yes.
 // 
-void MExtractSlidingWindow::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Int_t &max, Byte_t &sat) const
+void MExtractSlidingWindow::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &max, Byte_t &sat) const
 {
     const Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
 
     Int_t sum=0;
+    Int_t sumtot =0;
 
     //
@@ -259,10 +260,10 @@
     // This is fast and accurate (because we are using int's)
     //
-    max=sum;
+    sumtot=sum;
     for (p=ptr; p+fWindowSizeHiGain-fHiLoLast<end; p++)
     {
         sum += *(p+fWindowSizeHiGain-fHiLoLast) - *p;
-        if (sum>max)
-            max = sum;
+        if (sum>sumtot)
+            sumtot = sum;
     }
 
@@ -270,8 +271,8 @@
     {
         sum += *l - *p++;
-        if (sum>max)
-            max = sum;
-    }
-
+        if (sum>sumtot)
+            sumtot = sum;
+    }
+    max = (Float_t)sumtot;
 }
 
@@ -288,10 +289,10 @@
 // - Check if the sum has become bigger and store it in case yes.
 // 
-void MExtractSlidingWindow::FindSignalLoGain(Byte_t *ptr, Int_t &max, Byte_t &sat) const
+void MExtractSlidingWindow::FindSignalLoGain(Byte_t *ptr, Float_t &max, Byte_t &sat) const
 {
     const Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1;
 
     Int_t sum=0;
-
+    Int_t sumtot=0;
     //
     // Calculate the sum of the first fWindowSize slices
@@ -318,11 +319,13 @@
     // This is fast and accurate (because we are using int's)
     //
-    max=sum;
+    sumtot=sum;
     for (p=ptr; p+fWindowSizeLoGain<end; p++)
     {
         sum += *(p+fWindowSizeLoGain) - *p;
-        if (sum>max)
-            max = sum;
-    }
-}
-
+        if (sum>sumtot)
+            sumtot = sum;
+    }
+    max = (Float_t)sumtot;
+}
+
+
Index: /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.h
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.h	(revision 4339)
+++ /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.h	(revision 4340)
@@ -20,6 +20,6 @@
   Byte_t  fWindowSizeLoGain;             // Number of Lo Gain slices in window  
   
-  void   FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Int_t &max, Byte_t &sat) const;
-  void   FindSignalLoGain(Byte_t *ptr, Int_t &max, Byte_t &sat) const;  
+  void   FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Float_t &max, Byte_t &sat) const;
+  void   FindSignalLoGain(Byte_t *ptr, Float_t &max, Byte_t &sat) const;  
 
   Bool_t  ReInit(MParList *pList);
Index: /trunk/MagicSoft/Mars/msignal/MExtractor.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 4339)
+++ /trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 4340)
@@ -228,10 +228,10 @@
 
 
-void MExtractor::FindSignalHiGain(Byte_t *firstused, Byte_t *logain, Int_t &sum, Byte_t &sat) const
+void MExtractor::FindSignalHiGain(Byte_t *firstused, Byte_t *logain, Float_t &sum, Byte_t &sat) const
 {
   return;
 }
 
-void MExtractor::FindSignalLoGain(Byte_t *firstused, Int_t &sum, Byte_t &sat) const
+void MExtractor::FindSignalLoGain(Byte_t *firstused, Float_t &sum, Byte_t &sat) const
 {
   return;
@@ -251,10 +251,10 @@
   while (pixel.Next())
     {
-      Int_t sumhi  = 0;
+      Float_t sumhi = 0.;
       Byte_t sathi = 0;
 
       FindSignalHiGain(pixel.GetHiGainSamples()+fHiGainFirst, pixel.GetLoGainSamples(), sumhi, sathi);
 
-      Int_t  sumlo = 0;
+      Float_t sumlo = 0.;
       Byte_t satlo = 0;
 
@@ -269,5 +269,5 @@
       const Float_t pedes  = ped.GetPedestal();
       const Float_t pedrms = ped.GetPedestalRms();
-      
+
       pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
                              sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
Index: /trunk/MagicSoft/Mars/msignal/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/msignal/Makefile	(revision 4339)
+++ /trunk/MagicSoft/Mars/msignal/Makefile	(revision 4340)
@@ -37,4 +37,5 @@
            MExtractFixedWindowPeakSearch.cc \
            MExtractFixedWindowSpline.cc \
+           MExtractAmplitudeSpline.cc \
            MExtractSignal.cc \
            MExtractSignal2.cc \
Index: /trunk/MagicSoft/Mars/msignal/SignalLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/msignal/SignalLinkDef.h	(revision 4339)
+++ /trunk/MagicSoft/Mars/msignal/SignalLinkDef.h	(revision 4340)
@@ -19,4 +19,5 @@
 #pragma link C++ class MExtractFixedWindowPeakSearch+;
 #pragma link C++ class MExtractFixedWindowSpline+;
+#pragma link C++ class MExtractAmplitudeSpline+;
 #pragma link C++ class MExtractPINDiode++;
 #pragma link C++ class MExtractBlindPixel++;
