Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 3860)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 3861)
@@ -23,4 +23,13 @@
      - fixed a bug in loop 3 taking the default QE Cam instead of the 
        one filled by MJCalibration 
+
+
+   * msignal/MExtractor.[h,cc]
+     - new base class for signal extractors
+
+   * msignal/MExtractFixedWindow.[h,cc]
+   * msignal/MExtractSlidindWindow.[h,cc]
+   * msignal/MExtractFixedWindowPeakSearch.[h,cc]
+     - replacements for MExtractSignal, MExtractSignal2, MExtractSignal3
 
 
Index: /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.cc	(revision 3861)
+++ /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.cc	(revision 3861)
@@ -0,0 +1,140 @@
+/* ======================================================================== *\
+!
+! *
+! * 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 analysing 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, 04/2004 <mailto:markus@ifae.es>
+!              Thomas Bretz, 01/2004 
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+//  MExtractFixedWindow
+//
+//  Extracts the signal from a fixed window
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MExtractFixedWindow.h"
+#include "MExtractor.h"
+
+#include <fstream>
+
+
+ClassImp(MExtractFixedWindow);
+
+using namespace std;
+
+const Byte_t MExtractFixedWindow::fgHiGainFirst =  3;
+const Byte_t MExtractFixedWindow::fgHiGainLast  =  14;
+const Byte_t MExtractFixedWindow::fgLoGainFirst =  3;
+const Byte_t MExtractFixedWindow::fgLoGainLast  =  14;
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+MExtractFixedWindow::MExtractFixedWindow(const char *name, const char *title)
+{
+  fName  = name  ? name  : "MExtractFixedWindow";
+  fTitle = title ? title : "Signal Extractor for a fixed FADC window";
+
+
+  SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
+
+  fNumHiGainSamples = (Float_t)(fHiGainLast-fHiGainFirst) + 1.;
+  fNumLoGainSamples = (Float_t)(fLoGainLast-fLoGainFirst) + 1.;
+
+  fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
+  fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
+}
+
+
+void MExtractFixedWindow::FindSignalHiGain(Byte_t *ptr, Int_t size, Int_t &sum, Byte_t &sat) const
+{
+
+  Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
+  
+  sum = 0;
+  sat = 0;
+  
+  while (ptr<end)
+    {
+      sum += *ptr;
+      
+      if (*ptr++ >= fSaturationLimit)
+        sat++;
+    }
+}
+
+void MExtractFixedWindow::FindSignalLoGain(Byte_t *ptr, Int_t size, Int_t &sum, Byte_t &sat) const
+{
+
+  Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1;
+  
+  sum = 0;
+  sat = 0;
+  
+  while (ptr<end)
+    {
+      sum += *ptr;
+      
+      if (*ptr++ >= fSaturationLimit)
+        sat++;
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
+void MExtractFixedWindow::StreamPrimitive(ofstream &out) const
+{
+
+  out << "   " << ClassName() << " " << GetUniqueName() << "(\"";
+  out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
+  
+  if (fSaturationLimit!=fgSaturationLimit)
+    {
+      out << "   " << GetUniqueName() << ".SetSaturationLimit(";
+      out << (int)fSaturationLimit << ");" << endl;
+    }
+  
+  const Bool_t arg4 = fNumLoGainSamples+fLoGainFirst-1 != fgLoGainLast;
+  const Bool_t arg3 = arg4 || fLoGainFirst != fgLoGainFirst;
+  const Bool_t arg2 = arg3 || fNumHiGainSamples+fHiGainFirst-1 != fgHiGainLast;
+  const Bool_t arg1 = arg2 || fHiGainFirst != fgHiGainFirst;
+  
+  if (!arg1)
+    return;
+  
+  out << "   " << GetUniqueName() << ".SetRange(";
+  out << (int)fLoGainFirst;
+  if (arg2)
+    {
+      out << ", " << (int)(fNumHiGainSamples+fHiGainFirst-1);
+      if (arg3)
+        {
+          out << ", " << (int)fLoGainFirst;
+          if (arg4)
+            out << ", " << (int)(fNumLoGainSamples+fLoGainFirst-1);
+        }
+    }
+  out << ");" << endl;
+}
Index: /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.h
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.h	(revision 3861)
+++ /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.h	(revision 3861)
@@ -0,0 +1,36 @@
+#ifndef MARS_MExtractFixedWindow
+#define MARS_MExtractFixedWindow
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MExtractFixedWindow                                                          //
+//                                                                         //
+// Integrates the time slices of the all pixels in a fixed window          //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef MARS_MExtractor
+#include "MExtractor.h"
+#endif
+
+class MExtractFixedWindow : public MExtractor
+{
+private:
+  static const Byte_t fgHiGainFirst;     // First FADC slice Hi-Gain (currently set to: 3) 
+  static const Byte_t fgHiGainLast;      // Last FADC slice Hi-Gain (currently set to: 14) 
+  static const Byte_t fgLoGainFirst;     // First FADC slice Lo-Gain (currently set to: 3) 
+  static const Byte_t fgLoGainLast;      // Last FADC slice Lo-Gain (currently set to: 14) 
+
+  void   FindSignalHiGain(Byte_t *ptr, Int_t last, Int_t &sum, Byte_t &sat) const;
+  void   FindSignalLoGain(Byte_t *ptr, Int_t last, Int_t &sum, Byte_t &sat) const;
+
+  void   StreamPrimitive(ofstream &out) const;
+  
+public:
+
+  MExtractFixedWindow(const char *name=NULL, const char *title=NULL);
+
+  ClassDef(MExtractFixedWindow, 0) // Signal Extractor for a fixed extraction window
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.h
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.h	(revision 3861)
+++ /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.h	(revision 3861)
@@ -0,0 +1,42 @@
+#ifndef MARS_MExtractFixedWindowPeakSearch
+#define MARS_MExtractFixedWindowPeakSearch
+
+#ifndef MARS_MExtractor
+#include "MExtractor.h"
+#endif
+
+class MExtractFixedWindowPeakSearch : public MExtractor
+{
+private:
+
+  static const Byte_t fgHiGainFirst;
+  static const Byte_t fgHiGainLast;
+  static const Byte_t fgLoGainFirst;
+  static const Byte_t fgLoGainLast;
+  static const Byte_t fgHiGainWindowSize;     // The extraction window Hi-Gain
+  static const Byte_t fgLoGainWindowSize;     // The extraction window Lo-Gain
+  static const Byte_t fgPeakSearchWindowSize; // The window in which the global peak is searched for
+
+  Byte_t  fPeakSearchWindowSize; // Size of FADC window in the search for the highest peak of all pixels.
+
+  Byte_t  fWindowSizeHiGain;     // Number of Hi Gain slices in window
+  Byte_t  fWindowSizeLoGain;     // Number of Lo Gain slices in window
+
+  void   FindSignalHiGain(Byte_t *ptr, Int_t last, Int_t &sum, Byte_t &sat) const;
+  void   FindSignalLoGain(Byte_t *ptr, Int_t last, Int_t &sum, Byte_t &sat) const;  
+
+  void   FindPeak(Byte_t *ptr, Byte_t window, Byte_t &startslice, Int_t &signal, Int_t &sat) const;
+
+  Int_t  Process();
+
+public:
+
+    MExtractFixedWindowPeakSearch(const char *name=NULL, const char *title=NULL);
+
+    void SetWindows(Byte_t windowh=fgHiGainWindowSize, Byte_t windowl=fgLoGainWindowSize, 
+		    Byte_t peaksearchwindow=fgPeakSearchWindowSize);
+
+    ClassDef(MExtractFixedWindowPeakSearch, 0) // Signal Extractor for fixed size trigger-corrected extraction window 
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.cc	(revision 3861)
+++ /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.cc	(revision 3861)
@@ -0,0 +1,180 @@
+/* ======================================================================== *\
+!
+! *
+! * 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 analysing 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): Thomas Bretz, 02/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!              Hendrik Bartko, 01/2004 <mailto:hbartko@mppmu.mpg.de>
+!              Markus Gaug   , 04/2004 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+//   MExtractSlidingWindow
+//
+//  Extracts the signal from a sliding window of size fHiGainWindowSize and 
+//  fLoGainWindowSize. The signal is the one which maximizes the integral 
+//  contents. 
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MExtractSlidingWindow.h"
+#include "MExtractor.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MExtractSlidingWindow);
+
+using namespace std;
+
+const Byte_t MExtractSlidingWindow::fgHiGainFirst      = 3;
+const Byte_t MExtractSlidingWindow::fgHiGainLast       = 14;
+const Byte_t MExtractSlidingWindow::fgLoGainFirst      = 3;
+const Byte_t MExtractSlidingWindow::fgLoGainLast       = 14;
+const Byte_t MExtractSlidingWindow::fgHiGainWindowSize = 6;
+const Byte_t MExtractSlidingWindow::fgLoGainWindowSize = 6;
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+MExtractSlidingWindow::MExtractSlidingWindow(const char *name, const char *title)
+{
+
+  fName  = name  ? name  : "MExtractSlidingWindow";
+  fTitle = title ? title : "Signal Extractor for a sliding FADC window";
+
+  SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
+  SetWindowSize();
+
+}
+
+void MExtractSlidingWindow::SetWindowSize(Byte_t windowh, Byte_t windowl)
+{
+  
+  fWindowSizeHiGain = windowh & ~1;
+  fWindowSizeLoGain = windowl & ~1;
+
+  if (fWindowSizeHiGain != windowh)
+    *fLog << warn << "MExtractSignal2::SetRange - Hi Gain window size has to be even, set to: " 
+          << int(fWindowSizeHiGain) << " samples " << endl;
+  
+    if (fWindowSizeLoGain != windowl)
+      *fLog << warn << "MExtractSignal2::SetRange - Lo Gain window size has to be even, set to: " 
+            << int(fWindowSizeLoGain) << " samples " << endl;
+    
+    if (fWindowSizeHiGain<2) 
+      {
+        fWindowSizeHiGain = 2;
+      *fLog << warn << "MExtractSignal2::SetRange - Hi Gain window size set to two samples" << endl;
+      }
+    
+    if (fWindowSizeLoGain<2) 
+    {
+      fWindowSizeLoGain = 2;
+      *fLog << warn << "MExtractSignal2::SetRange - Lo Gain window size set to two samples" << endl;
+    }
+    
+    fNumHiGainSamples = (Float_t)fWindowSizeHiGain;
+    fNumLoGainSamples = (Float_t)fWindowSizeLoGain;
+    
+    fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
+    fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
+}
+
+
+
+void MExtractSlidingWindow::FindSignalHiGain(Byte_t *ptr, Int_t size,  Int_t &max, Byte_t &sat) const
+{
+    const Byte_t *end = ptr + size;
+
+    Int_t sum=0;
+
+    //
+    // Calculate the sum of the first fWindowSize slices
+    //
+    sat = 0;
+    Byte_t *p = ptr;
+    while (p<ptr+fWindowSizeHiGain)
+    {
+        sum += *p;
+        if (*p++ >= fSaturationLimit)
+            sat++;
+    }
+
+    //
+    // Check for saturation in all other slices
+    //
+    while (p<end)
+        if (*p++ >= fSaturationLimit)
+            sat++;
+
+    //
+    // Calculate the i-th sum as
+    //    sum_i+1 = sum_i + slice[i+8] - slice[i]
+    // This is fast and accurate (because we are using int's)
+    //
+    max=sum;
+    for (p=ptr; p+fWindowSizeHiGain<end; p++)
+    {
+        sum += *(p+fWindowSizeHiGain) - *p;
+        if (sum>max)
+            max = sum;
+    }
+}
+
+
+void MExtractSlidingWindow::FindSignalLoGain(Byte_t *ptr, Int_t size,  Int_t &max, Byte_t &sat) const
+{
+    const Byte_t *end = ptr + size;
+
+    Int_t sum=0;
+
+    //
+    // Calculate the sum of the first fWindowSize slices
+    //
+    sat = 0;
+    Byte_t *p = ptr;
+    while (p<ptr+fWindowSizeLoGain)
+    {
+        sum += *p;
+        if (*p++ >= fSaturationLimit)
+            sat++;
+    }
+
+    //
+    // Check for saturation in all other slices
+    //
+    while (p<end)
+        if (*p++ >= fSaturationLimit)
+            sat++;
+
+    //
+    // Calculate the i-th sum as
+    //    sum_i+1 = sum_i + slice[i+8] - slice[i]
+    // This is fast and accurate (because we are using int's)
+    //
+    max=sum;
+    for (p=ptr; p+fWindowSizeLoGain<end; p++)
+    {
+        sum += *(p+fWindowSizeLoGain) - *p;
+        if (sum>max)
+            max = sum;
+    }
+}
+
Index: /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.h
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.h	(revision 3861)
+++ /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.h	(revision 3861)
@@ -0,0 +1,34 @@
+#ifndef MARS_MExtractSlidingWindow
+#define MARS_MExtractSlidingWindow
+
+#ifndef MARS_MExtractor
+#include "MExtractor.h"
+#endif
+
+class MExtractSlidingWindow : public MExtractor
+{
+private:
+  
+  static const Byte_t fgHiGainFirst;      // First FADC slice Hi-Gain (currently set to: 3) 
+  static const Byte_t fgHiGainLast;       // Last FADC slice Hi-Gain (currently set to: 14) 
+  static const Byte_t fgLoGainFirst;      // First FADC slice Lo-Gain (currently set to: 3) 
+  static const Byte_t fgLoGainLast;       // Last FADC slice Lo-Gain (currently set to: 14) 
+  static const Byte_t fgHiGainWindowSize; // The extraction window Hi-Gain
+  static const Byte_t fgLoGainWindowSize; // The extraction window Lo-Gain
+
+  Byte_t  fWindowSizeHiGain;             // Number of Hi Gain slices in window
+  Byte_t  fWindowSizeLoGain;             // Number of Lo Gain slices in window  
+  
+  void   FindSignalHiGain(Byte_t *ptr, Int_t last, Int_t &max, Byte_t &sat) const;
+  void   FindSignalLoGain(Byte_t *ptr, Int_t last, Int_t &max, Byte_t &sat) const;  
+
+public:
+  MExtractSlidingWindow(const char *name=NULL, const char *title=NULL);
+
+  void SetWindowSize(Byte_t windowh=fgHiGainWindowSize,
+                     Byte_t windowl=fgLoGainWindowSize);
+
+  ClassDef(MExtractSlidingWindow, 0) // Signal Extractor for sliding extraction window
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/msignal/MExtractor.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 3861)
+++ /trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 3861)
@@ -0,0 +1,199 @@
+/* ======================================================================== *\
+!
+! *
+! * 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 analysing 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, 04/2004 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+//   MExtractor
+//
+//   Base class for the signal extractors, used the function 
+//   FindSignal() to extract the signal and substract the pedestal value    
+//
+//   The following variables have to be set by the derived class and 
+//   do not have defaults:
+//   - fNumHiGainSamples
+//   - fNumLoGainSamples
+//   - fSqrtHiGainSamples
+//   - fSqrtLoGainSamples
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MExtractor.h"
+
+#include <fstream>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+#include "MRawEvtData.h"
+#include "MRawEvtPixelIter.h"
+
+#include "MPedestalCam.h"
+#include "MPedestalPix.h"
+
+#include "MExtractedSignalCam.h"
+#include "MExtractedSignalPix.h"
+
+ClassImp(MExtractor);
+
+using namespace std;
+
+const Byte_t MExtractor::fgSaturationLimit = 254;
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+MExtractor::MExtractor(const char *name, const char *title)
+    : fNumHiGainSamples(0.), fNumLoGainSamples(0.), fSaturationLimit(fgSaturationLimit)
+{
+
+    fName  = name  ? name  : "MExtractor";
+    fTitle = title ? title : "Base class for signal extractors";
+
+    AddToBranchList("MRawEvtData.*");
+
+    SetRange();
+}
+
+void MExtractor::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
+{
+
+    fHiGainFirst = hifirst;
+    fLoGainFirst = lofirst;
+
+    fHiGainLast  = hilast;
+    fLoGainLast  = lolast;
+
+}
+
+// --------------------------------------------------------------------------
+//
+// The PreProcess searches for the following input containers:
+//  - MRawEvtData
+//  - MPedestalCam
+//
+// The following output containers are also searched and created if
+// they were not found:
+//
+//  - MExtractedSignalCam
+//
+Int_t MExtractor::PreProcess(MParList *pList)
+{
+    fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
+    if (!fRawEvt)
+    {
+        *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
+        return kFALSE;
+    }
+
+
+    fSignals = (MExtractedSignalCam*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalCam"));
+    if (!fSignals)
+        return kFALSE;
+
+    fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast, fNumHiGainSamples,
+                                fLoGainFirst, fLoGainLast, fNumLoGainSamples);
+
+    fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
+
+    if (!fPedestals)
+    {
+        *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
+void MExtractor::FindSignalHiGain(Byte_t *ptr, Int_t last, Int_t &sum, Byte_t &sat) const
+{
+  return;
+}
+
+void MExtractor::FindSignalLoGain(Byte_t *ptr, Int_t last, Int_t &sum, Byte_t &sat) const
+{
+  return;
+}
+
+// --------------------------------------------------------------------------
+//
+// Calculate the integral of the FADC time slices and store them as a new
+// pixel in the MExtractedSignalCam container.
+//
+Int_t MExtractor::Process()
+{
+
+  MRawEvtPixelIter pixel(fRawEvt);
+  fSignals->Clear();
+
+  UInt_t  sat=0;
+
+  while (pixel.Next())
+    {
+      Int_t sumhi;
+      Byte_t sathi;
+
+      FindSignalHiGain(pixel.GetHiGainSamples()+fHiGainFirst, fHiGainLast, sumhi, sathi);
+
+      Int_t  sumlo = 0;
+      Byte_t satlo = 0;
+
+      if (pixel.HasLoGain())
+        {
+          FindSignalLoGain(pixel.GetLoGainSamples()+fLoGainFirst, fLoGainLast, sumlo, satlo);
+          
+          if (satlo)
+            sat++;
+        }
+      
+      const Int_t pixid = pixel.GetPixelId();
+      
+      const MPedestalPix  &ped = (*fPedestals)[pixid]; 
+      MExtractedSignalPix &pix = (*fSignals)[pixid];
+      
+      const Float_t pedes  = ped.GetPedestal();
+      const Float_t pedrms = ped.GetPedestalRms();
+      
+      pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
+                             sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
+      
+      pix.SetGainSaturation(sathi, sathi, satlo);
+      
+    } /* while (pixel.Next()) */
+
+    fSignals->SetReadyToSave();
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
+void MExtractor::StreamPrimitive(ofstream &out) const
+{
+}
+
Index: /trunk/MagicSoft/Mars/msignal/MExtractor.h
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractor.h	(revision 3861)
+++ /trunk/MagicSoft/Mars/msignal/MExtractor.h	(revision 3861)
@@ -0,0 +1,63 @@
+#ifndef MARS_MExtractor
+#define MARS_MExtractor
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MExtractor                                                              //
+//                                                                         //
+// Base class for the signal extractors                                    //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MRawEvtData;
+class MRawRunHeader;
+
+class MPedestalCam;
+class MExtractedSignalCam;
+
+class MExtractor : public MTask
+{
+protected:
+    static const Byte_t fgSaturationLimit;
+
+    MPedestalCam        *fPedestals;    // Pedestals of all pixels in the camera
+    MExtractedSignalCam *fSignals;      // Extracted signal of all pixels in the camera
+
+    MRawEvtData         *fRawEvt;       // raw event data (time slices)
+    MRawRunHeader       *fRunHeader;    // RunHeader information
+
+    Byte_t  fHiGainFirst;
+    Byte_t  fLoGainFirst;
+
+    Byte_t  fHiGainLast;
+    Byte_t  fLoGainLast;
+
+    Float_t  fNumHiGainSamples;
+    Float_t  fNumLoGainSamples;
+
+    Float_t  fSqrtHiGainSamples;
+    Float_t  fSqrtLoGainSamples;
+
+    Byte_t  fSaturationLimit;
+
+    virtual void FindSignalHiGain(Byte_t *ptr, Int_t last, Int_t &sum, Byte_t &sat) const;
+    virtual void FindSignalLoGain(Byte_t *ptr, Int_t last, Int_t &sum, Byte_t &sat) const;
+
+    virtual Int_t  PreProcess(MParList *pList);
+    virtual Int_t  Process();
+    virtual void   StreamPrimitive(ofstream &out) const;
+
+public:
+    MExtractor(const char *name=NULL, const char *title=NULL);
+
+    void SetRange(Byte_t hifirst=0, Byte_t hilast=0, Byte_t lofirst=0, Byte_t lolast=0);
+    void SetSaturationLimit(Byte_t lim) { fSaturationLimit = lim; }
+
+    ClassDef(MExtractor, 0) // Signal Extractor Base Class
+};
+
+#endif
