Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 3861)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 3862)
@@ -28,4 +28,6 @@
      - new base class for signal extractors
 
+   * msignal/Makefile	
+   * msignal/SignalLinkDef.h	
    * msignal/MExtractFixedWindow.[h,cc]
    * msignal/MExtractSlidindWindow.[h,cc]
Index: /trunk/MagicSoft/Mars/macros/bootcampstandardanalysis.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/bootcampstandardanalysis.C	(revision 3861)
+++ /trunk/MagicSoft/Mars/macros/bootcampstandardanalysis.C	(revision 3862)
@@ -60,4 +60,6 @@
 {
 
+  MExtractSlidingWindow extractor;
+
   MRunIter pruns;
   MRunIter cruns;
@@ -118,8 +120,5 @@
   MJCalibration     calloop;
   calloop.SetInput(&cruns);
-  //
-  // Use as signal extractor MExtractSignal:
-  //
-  calloop.SetExtractorLevel(1);
+  calloop.SetExtractor(&extractor);
   //
   // Set the corr. cams:
@@ -186,5 +185,4 @@
   static_cast<MRead&>(read3).AddFiles(pruns);  
 
-  MExtractSignal   extsig;
   MCalibrate       photcalc;
   photcalc.SetCalibrationMode(MCalibrate::kFfactor);
@@ -193,5 +191,5 @@
   tlist3.AddToList(&read3);
   tlist3.AddToList(&geomapl);
-  tlist3.AddToList(&extsig);
+  tlist3.AddToList(&extractor);
   tlist3.AddToList(&photcalc);
   //    tlist3.AddToList(&photrmscalc);
@@ -252,5 +250,5 @@
   tlist4.AddToList(&read4);
   tlist4.AddToList(&geomapl);
-  tlist4.AddToList(&extsig);
+  tlist4.AddToList(&extractor);
   tlist4.AddToList(&timecalc);
   tlist4.AddToList(&photcalc);
@@ -264,5 +262,4 @@
 
   if (!evtloop4.PreProcess())
-
     return;
   
Index: /trunk/MagicSoft/Mars/macros/calibration.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/calibration.C	(revision 3861)
+++ /trunk/MagicSoft/Mars/macros/calibration.C	(revision 3862)
@@ -63,4 +63,5 @@
 {
 
+  MExtractFixedWindowPeakSearch extractor;
   
   MRunIter pruns;
@@ -120,4 +121,5 @@
   //
   //  calloop.SetRelTimeCalibration();
+  calloop.SetExtractor(&extractor);
   calloop.SetInput(&cruns);
   calloop.SetDisplay(display);
@@ -134,4 +136,5 @@
   MJExtractCalibTest testloop;
 
+  testloop.SetExtractor(&extractor);
   testloop.SetInput(&cruns);
   testloop.SetDisplay(display);
Index: /trunk/MagicSoft/Mars/macros/pedphotcalc.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/pedphotcalc.C	(revision 3861)
+++ /trunk/MagicSoft/Mars/macros/pedphotcalc.C	(revision 3862)
@@ -65,5 +65,6 @@
 #include "MCalibrationQEPix.h"
 #include "MExtractedSignalCam.h"
-#include "MExtractSignal.h" 
+#include "MExtractSlidingWindow.h" 
+#include "MExtractFixedWindow.h" 
 #include "MCerPhotEvt.h"
 #include "MCalibrate.h"
@@ -210,4 +211,6 @@
                  )
 {
+
+  MExtractFixedWindow extractor;
   
   MRunIter pruns;
@@ -266,5 +269,5 @@
   // Use as signal extractor MExtractSignal:
   //
-  calloop.SetExtractorLevel(1);
+  calloop.SetExtractor(&extractor);
   //
   // The next two commands are for the display:
@@ -313,5 +316,4 @@
   static_cast<MRead&>(read3).AddFiles(pruns);  
 
-  MExtractSignal  sigcalc;
   MCalibrate      photcalc;
   photcalc.SetCalibrationMode(MCalibrate::kFfactor);
@@ -320,5 +322,5 @@
   tlist3.AddToList(&read3);
   tlist3.AddToList(&geomapl);
-  tlist3.AddToList(&sigcalc);
+  tlist3.AddToList(&extractor);
   tlist3.AddToList(&photcalc);
   tlist3.AddToList(&pedphotcalc);
Index: /trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 3861)
+++ /trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 3862)
@@ -38,9 +38,6 @@
 //End_Html
 //
-// Different signal extractors can be chosen via the command SetExtractorLevel(UInt_t i)
-// Up to now, the following extractors are available:
-// i=1: Use MExtractSignal  (fixed window)
-// i=2: Use MExtractSignal2 (sliding window: default)
-// i=3: Use MExtractSignal3 (coherent sliding window for all pixels)
+// Different signal extractors can be set with the command SetExtractor()
+// Only extractor deriving from MExtractor can be set, default is MExtractSlidingWindow
 //
 // At the end of the eventloop, plots and results are displayed, depending on 
@@ -119,9 +116,8 @@
 #include "MBadPixelsMerge.h"
 #include "MBadPixelsCam.h"
-#include "MExtractSignal.h"
+#include "MExtractor.h"
 #include "MExtractPINDiode.h"
 #include "MExtractBlindPixel.h"
-#include "MExtractSignal2.h"
-#include "MExtractSignal3.h"
+#include "MExtractSlidingWindow.h"
 #include "MFCosmics.h"
 #include "MContinue.h"
@@ -143,10 +139,10 @@
 // Default constructor. 
 //
-// Sets fRuns to 0, fColor to kNONE, fDisplay to kNormalDisplay, 
+// Sets fRuns to 0, fExtractor to NULL, fColor to kNONE, fDisplay to kNormalDisplay, 
 // fRelTime to kFALSE, fExtractorLevel to 2, fArrivalTimeLevel to 2
 //
 MJCalibration::MJCalibration(const char *name, const char *title) 
-    : fRuns(0), fColor(MCalibrationCam::kNONE), fDisplayType(kNormalDisplay),
-      fRelTimes(kFALSE), fDataCheck(kFALSE), fExtractorLevel(2), fArrivalTimeLevel(2)
+    : fRuns(0), fExtractor(NULL), fColor(MCalibrationCam::kNONE), fDisplayType(kNormalDisplay),
+      fRelTimes(kFALSE), fDataCheck(kFALSE), fArrivalTimeLevel(2)
 {
   fName  = name  ? name  : "MJCalibration";
@@ -765,5 +761,5 @@
 //   2)  MBadPixelsMerge
 //   3)  MGeomApply
-//   4)  MExtractSignal, MExtractSignal2 or MExtractSignal3, depending on fExtractorLevel
+//   4)  MExtractor
 //   5)  MExtractPINDiode
 //   6)  MExtractBlindPixel
@@ -839,7 +835,5 @@
   MExtractPINDiode         pinext;
   MExtractBlindPixel       blindext;
-  MExtractSignal           extract1; 
-  MExtractSignal2          extract2;
-  MExtractSignal3          extract3;
+  MExtractSlidingWindow    extract2;
   MArrivalTimeCalc         tmecalc1;
   MArrivalTimeCalc2        tmecalc2;
@@ -872,16 +866,11 @@
   tlist.AddToList(&apply);
 
-  if (fExtractorLevel <= 1)
-    tlist.AddToList(&extract1);
-  else if (fExtractorLevel == 2) 
-    tlist.AddToList(&extract2);
-  else if (fExtractorLevel == 3) 
-    tlist.AddToList(&extract3);
+  if (fExtractor)
+    tlist.AddToList(fExtractor);
   else
     {
-      *fLog << err << GetDescriptor() 
-            << ": No valid Signal extractor has been chosen, have only: " << fExtractorLevel 
-            << " aborting..." << endl;
-      return kFALSE;
+      *fLog << warn << GetDescriptor() 
+            << ": No extractor has been chosen, take default MExtractSlidingWindow " << endl;
+      tlist.AddToList(&extract2);
     }
   
Index: /trunk/MagicSoft/Mars/mjobs/MJCalibration.h
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJCalibration.h	(revision 3861)
+++ /trunk/MagicSoft/Mars/mjobs/MJCalibration.h	(revision 3862)
@@ -21,4 +21,5 @@
 class MParList;
 class MPedestalCam;
+class MExtractor;
 class MJCalibration : public MParContainer, public MGCamDisplays
 {
@@ -29,5 +30,6 @@
   TString fOutputPath;                                     // Path to the output files
   
-  MRunIter *fRuns;                                         // Calibration files
+  MRunIter   *fRuns;                                       // Calibration files
+  MExtractor *fExtractor;                                  // Signal extractor
   
   MBadPixelsCam          fBadPixels;                       // Bad Pixels cam, can be set from previous runs
@@ -44,5 +46,4 @@
   Bool_t fRelTimes;                                        // Flag if relative times have to be calibrated
   Bool_t fDataCheck;                                       // Flag if the data check is run on raw data
-  UInt_t fExtractorLevel;                                  // Level signal extractor (e.g. MExtractSignal2) 
   UInt_t fArrivalTimeLevel;                                // Level arr. time extractor (e.g. MArrivalTimeCalc2)
   
@@ -67,5 +68,6 @@
   const MBadPixelsCam    &GetBadPixels() const    { return fBadPixels;      }
   
-  void SetBadPixels(const MBadPixelsCam &bad)    { bad.Copy(fBadPixels);   }
+  void SetBadPixels(const MBadPixelsCam &bad)     { bad.Copy(fBadPixels);   }
+  void SetExtractor(MExtractor* ext)              { fExtractor = ext; }
   void SetQECam    (const MCalibrationQECam &qe) { qe.Copy(fQECam);        }    
   void SetColor    (const MCalibrationCam::PulserColor_t color) { fColor = color; }
@@ -83,7 +85,5 @@
 
   // Extractors
-  void SetExtractorLevel    (const UInt_t i=1    ) { fExtractorLevel   = i; }
   void SetArrivalTimeLevel  (const UInt_t i=1    ) { fArrivalTimeLevel = i; }  
-      
   
   Bool_t ReadCalibrationCam();
Index: /trunk/MagicSoft/Mars/mjobs/MJExtractCalibTest.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJExtractCalibTest.cc	(revision 3861)
+++ /trunk/MagicSoft/Mars/mjobs/MJExtractCalibTest.cc	(revision 3862)
@@ -54,5 +54,6 @@
 #include "MReadMarsFile.h"
 #include "MGeomApply.h"
-#include "MExtractSignal.h"
+#include "MExtractSlidingWindow.h"
+#include "MExtractor.h"
 #include "MFillH.h"
 #include "MCalibrate.h"
@@ -65,6 +66,12 @@
 
 using namespace std;
-
-MJExtractCalibTest::MJExtractCalibTest(const char *name, const char *title) : fRuns(0)
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+// Sets fRuns to 0, fExtractor to NULL
+//
+MJExtractCalibTest::MJExtractCalibTest(const char *name, const char *title) 
+    : fRuns(NULL), fExtractor(NULL)
 {
     fName  = name  ? name  : "MJExtractCalibTest";
@@ -93,8 +100,8 @@
   
   // Create histograms to display
-  MHCamera disp1 (geomcam, "Cal;Photons",           "Mean of calibrated Photons");
-  MHCamera disp2 (geomcam, "Cal;SigmaPhotons",      "Sigma of calibrated photons");
-  MHCamera disp3 (geomcam, "Cal;PhotonsPerArea",    "Mean Photons per Area");
-  MHCamera disp4 (geomcam, "Cal;SigmaPhotPerArea",  "Sigma Photons per Area");
+  MHCamera disp1 (geomcam, "Test;Photons",           "Mean of calibrated Photons");
+  MHCamera disp2 (geomcam, "Test;SigmaPhotons",      "Sigma of calibrated photons");
+  MHCamera disp3 (geomcam, "Test;PhotonsPerArea",    "Equiv. Cherenkov Photons per Area");
+  MHCamera disp4 (geomcam, "Test;SigmaPhotPerArea",  "Sigma equiv. Cher. Photons per Area");
 
   // Fitted charge means and sigmas
@@ -199,7 +206,7 @@
   static_cast<MRead&>(read).AddFiles(*fRuns);
   
-  MGeomApply      apply; // Only necessary to craete geometry
-  MExtractSignal  extract;
-  MCalibrate      photcalc;
+  MGeomApply            apply; // Only necessary to craete geometry
+  MExtractSlidingWindow extract2;
+  MCalibrate            photcalc;
   photcalc.SetCalibrationMode(MCalibrate::kFfactor);
 
@@ -223,5 +230,14 @@
   tlist.AddToList(&read);
   tlist.AddToList(&apply);
-  tlist.AddToList(&extract);
+
+  if (fExtractor)
+    tlist.AddToList(fExtractor);
+    else
+    {
+      *fLog << warn << GetDescriptor() 
+            << ": No extractor has been chosen, take default MExtractSlidingWindow " << endl;
+      tlist.AddToList(&extract2);
+    }
+
   if (TestBit(kEnableGraphicalOutput))
     tlist.AddToList(&fill);
@@ -328,8 +344,8 @@
     plist.AddToList(&tlist);
 
-    MGeomApply      apply; // Only necessary to craete geometry
-    MExtractSignal  extract;
-    MCalibrate      calib;
-    MPedPhotCalc    calc;
+    MGeomApply            apply; // Only necessary to craete geometry
+    MExtractSlidingWindow extract2;
+    MCalibrate            calib;
+    MPedPhotCalc          calc;
 
     MHCamEvent evt1("ExtOffset");
@@ -342,5 +358,14 @@
     tlist.AddToList(&read);
     tlist.AddToList(&apply);
-    tlist.AddToList(&extract);
+
+    if (fExtractor)
+      tlist.AddToList(fExtractor);
+    else
+      {
+      *fLog << warn << GetDescriptor() 
+            << ": No extractor has been chosen, take default MExtractSlidingWindow " << endl;
+      tlist.AddToList(&extract2);
+    }
+
     if (TestBit(kEnableGraphicalOutput))
         tlist.AddToList(&fill1);
Index: /trunk/MagicSoft/Mars/mjobs/MJExtractCalibTest.h
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJExtractCalibTest.h	(revision 3861)
+++ /trunk/MagicSoft/Mars/mjobs/MJExtractCalibTest.h	(revision 3862)
@@ -20,6 +20,5 @@
 class MCalibrationChargeCam;
 class MCalibrationQECam;
-class MPedPhotCam;
-class MHCalibrationTestCam;
+class MExtractor;
 class MJExtractCalibTest : public MParContainer, public MGCamDisplays
 {
@@ -28,5 +27,6 @@
   TString fOutputPath;
 
-  MRunIter *fRuns;
+  MRunIter   *fRuns;                                       // Data files
+  MExtractor *fExtractor;                                  // Signal extractor
   
   MBadPixelsCam        fBadPixels;
@@ -54,4 +54,5 @@
   const MBadPixelsCam &GetBadPixels()  const { return fBadPixels; }
   
+  void SetExtractor(MExtractor* ext)              { fExtractor = ext; }
   void SetBadPixels(const MBadPixelsCam &bad) { bad.Copy(fBadPixels); }
   
Index: /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.cc	(revision 3862)
+++ /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.cc	(revision 3862)
@@ -0,0 +1,332 @@
+/* ======================================================================== *\
+   !
+   ! *
+   ! * 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): Abelardo Moralejo, 4/2004 <mailto:moralejo@pd.infn.it>
+   !              Markus Gaug      , 4/2004 <mailto:markus@ifae.es>
+   !   Copyright: MAGIC Software Development, 2000-2004
+   !
+   !
+   \* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+//   MExtractFixedWindowPeakSearch
+//
+//  Calculate the signal integrating fWindowSize time slices, the same for 
+//  all pixels. The integrated slices change from event to event, since the
+//  pulse positions in the FADC jump between events, but apparently in a 
+//  "coherent" fashion. We first loop over all pixels and find the one 
+//  which has the highest sum of fPeakSearchWindowSize (default: 4) consecutive 
+//  non-saturated high gain slices. The position of the peak in this pixel 
+//  determines the integration window position for all pixels of this event. 
+//  For the moment we neglect time delays between pixels (which are in most 
+//  cases small). The class is based on MExtractSignal2.
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MExtractFixedWindowPeakSearch.h"
+#include "MExtractor.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MRawEvtPixelIter.h"
+
+#include "MExtractedSignalCam.h"
+#include "MExtractedSignalPix.h"
+
+#include "MPedestalCam.h"
+#include "MPedestalPix.h"
+
+ClassImp(MExtractFixedWindowPeakSearch);
+
+using namespace std;
+
+const Byte_t MExtractFixedWindowPeakSearch::fgHiGainWindowSize     = 6;
+const Byte_t MExtractFixedWindowPeakSearch::fgLoGainWindowSize     = 6;
+const Byte_t MExtractFixedWindowPeakSearch::fgPeakSearchWindowSize = 4;
+const Byte_t MExtractFixedWindowPeakSearch::fgHiGainFirst          = 0;
+const Byte_t MExtractFixedWindowPeakSearch::fgHiGainLast           = 14;
+const Byte_t MExtractFixedWindowPeakSearch::fgLoGainFirst          = 0;
+const Byte_t MExtractFixedWindowPeakSearch::fgLoGainLast           = 14;
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+MExtractFixedWindowPeakSearch::MExtractFixedWindowPeakSearch(const char *name, const char *title)
+{
+
+  fName  = name  ? name  : "MExtractFixedWindowPeakSearch";
+  fTitle = title ? title : "Task to extract the signal from the FADC slices";
+
+  SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
+  SetWindows();
+}
+
+void MExtractFixedWindowPeakSearch::SetWindows(Byte_t windowh, Byte_t windowl, Byte_t peaksearchwindow)
+{
+  //
+  // Set windows to even number of slices due to clock noise (odd/even slice effect).
+  //
+  fWindowSizeHiGain = windowh & ~1;
+  fWindowSizeLoGain = windowl & ~1;
+  fPeakSearchWindowSize = peaksearchwindow & ~1;
+
+
+  if (fWindowSizeHiGain != windowh)
+    *fLog << endl << warn << 
+      "MExtractFixedWindowPeakSearch::SetWindows - Hi Gain window size has to be even, set to: " 
+	  << int(fWindowSizeHiGain) << " samples " << endl;
+    
+  if (fWindowSizeLoGain != windowl)
+    *fLog << endl << warn << 
+      "MExtractFixedWindowPeakSearch::SetWindows - Lo Gain window size has to be even, set to: " 
+	  << int(fWindowSizeLoGain) << " samples " << endl;
+
+  if (fPeakSearchWindowSize != peaksearchwindow)
+    *fLog << endl << warn << 
+      "MExtractFixedWindowPeakSearch::SetWindows - Peak Search window size has to be even, set to: " 
+	  << int(fPeakSearchWindowSize) << " samples " << endl;
+
+
+  if (fWindowSizeHiGain<2) 
+    {
+      fWindowSizeHiGain = 2;
+      *fLog << warn 
+            << "MExtractFixedWindowPeakSearch::SetWindows - Hi Gain window size set to two samples" << endl;
+    }
+
+  if (fWindowSizeLoGain<2) 
+    {
+      fWindowSizeLoGain = 2;
+      *fLog << warn 
+            << "MExtractFixedWindowPeakSearch::SetWindows - Lo Gain window size set to two samples" << endl;
+    }
+
+  if (fPeakSearchWindowSize<2) 
+    {
+      fPeakSearchWindowSize = 2;
+      *fLog << warn 
+            << "MExtractFixedWindowPeakSearch::SetWindows - Peak Search window size set to two samples" << endl;
+    }
+
+
+  fNumHiGainSamples = (Float_t)fWindowSizeHiGain;
+  fNumLoGainSamples = (Float_t)fWindowSizeLoGain;
+
+  fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
+  fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
+}
+
+// --------------------------------------------------------------------------
+//
+// FindPeak
+// Finds highest sum of "window" consecutive FADC slices in a pixel, and store
+// in "startslice" the first slice of the group which yields the maximum sum.
+// In "max" the value of the maximum sum is stored, in "sat" the number of 
+// saturated slices.
+//
+void MExtractFixedWindowPeakSearch::FindPeak(Byte_t *ptr, Byte_t window, Byte_t &startslice, 
+			       Int_t &max, Int_t &sat) const
+{
+  const Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
+
+  Int_t sum=0;
+
+  //
+  // Calculate the sum of the first "window" slices
+  //
+  sat = 0;
+  Byte_t *p = ptr;
+
+  while (p<ptr+window)
+    {
+      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 of n as
+  //    sum_i+1 = sum_i + slice[i+window] - slice[i]
+  // This is fast and accurate (because we are using int's)
+  //
+  max=sum;
+  for (p=ptr; p+window<end; p++)
+    {
+      sum += *(p+window) - *p;
+      if (sum > max)
+	{
+	  max = sum;
+	  startslice = p-ptr;
+	}
+    }
+
+  return;
+}
+
+// --------------------------------------------------------------------------
+//
+// FindSignal
+// Adds up "window" slices starting in slice to which "ptr" points. The result 
+// is stored in "sum", and the number of saturated  slices in "sat".
+//
+void MExtractFixedWindowPeakSearch::FindSignalHiGain(Byte_t *ptr, Int_t size, Int_t &sum, Byte_t &sat) const
+{
+  //
+  // Calculate the sum of the "window" slices starting in ptr
+  //
+  sum = 0;
+  sat = 0;
+  Byte_t *p = ptr;
+
+  while (p<ptr+fWindowSizeHiGain)
+    {
+      sum += *p;
+      if (*p++ >= fSaturationLimit)
+	sat++;
+    }
+
+  return;
+}
+
+// --------------------------------------------------------------------------
+//
+// FindSignal
+// Adds up "window" slices starting in slice to which "ptr" points. The result 
+// is stored in "sum", and the number of saturated  slices in "sat".
+//
+void MExtractFixedWindowPeakSearch::FindSignalLoGain(Byte_t *ptr, Int_t size, Int_t &sum, Byte_t &sat) const
+{
+  //
+  // Calculate the sum of the "window" slices starting in ptr
+  //
+  sum = 0;
+  sat = 0;
+  Byte_t *p = ptr;
+
+  while (p<ptr+fWindowSizeLoGain)
+    {
+      sum += *p;
+      if (*p++ >= fSaturationLimit)
+	sat++;
+    }
+
+  return;
+}
+
+// --------------------------------------------------------------------------
+//
+// Process
+// First find the pixel with highest sum of fPeakSearchWindowSize slices (default:4)
+// "startslice" will mark the slice at which the highest sum begins for that pixel.
+// Then define the beginning of the integration window for ALL pixels as the slice
+// before that: startslice-1 (this is somehow arbitrary), unless of course startslice=0,
+// in which case we start at 0. We will also check that the integration window does not 
+// go beyond the FADC limits.
+//
+Int_t MExtractFixedWindowPeakSearch::Process()
+{
+
+  MRawEvtPixelIter pixel(fRawEvt);
+
+  Int_t sat;
+  Int_t maxsumhi = 0;
+  Byte_t startslice;
+  Byte_t hiGainFirst = 0;
+  Byte_t loGainFirst = 0;
+
+  while (pixel.Next())
+    {
+      Int_t sumhi;
+      sat = 0;
+
+      FindPeak(pixel.GetHiGainSamples(), fPeakSearchWindowSize, startslice, sumhi, sat);
+      if (sumhi > maxsumhi && sat == 0 )
+	{
+	  maxsumhi = sumhi;
+	  if (startslice > 0)
+	    hiGainFirst = startslice-1;
+	  else
+	    hiGainFirst = 0;
+	}
+    }
+
+
+  loGainFirst = hiGainFirst;
+
+  // Make sure we will not integrate beyond the hi gain limit:
+  if (hiGainFirst+fWindowSizeHiGain > pixel.GetNumHiGainSamples())
+    hiGainFirst = pixel.GetNumHiGainSamples()-fWindowSizeHiGain;
+
+  // Make sure we will not integrate beyond the lo gain limit:
+  if (loGainFirst+fWindowSizeLoGain > pixel.GetNumLoGainSamples())
+    loGainFirst = pixel.GetNumLoGainSamples()-fWindowSizeLoGain;
+
+  pixel.Reset();
+  fSignals->Clear();
+
+  sat = 0;
+  while (pixel.Next())
+    {
+      //
+      // Find signal in hi- and lo-gain
+      //
+      Int_t sumhi;
+      Byte_t sathi;
+
+      FindSignalHiGain(pixel.GetHiGainSamples()+hiGainFirst, fWindowSizeHiGain, sumhi, sathi);
+
+      Int_t sumlo=0;
+      Byte_t satlo=0;
+      if (pixel.HasLoGain())
+        {
+	  FindSignalLoGain(pixel.GetLoGainSamples()+loGainFirst, fWindowSizeLoGain, sumlo, satlo);
+	  if (satlo)
+	    sat++;
+        }
+
+      //
+      // Take corresponding pedestal
+      //
+      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();
+
+      //
+      // Set extracted signal with pedestal substracted
+      //
+      pix.SetExtractedSignal(sumhi - pedes*fNumHiGainSamples, pedrms*fSqrtHiGainSamples,
+                             sumlo - pedes*fNumLoGainSamples, pedrms*fSqrtLoGainSamples);
+
+      pix.SetGainSaturation(sathi, sathi, satlo);
+    } /* while (pixel.Next()) */
+
+  fSignals->SetReadyToSave();
+
+  return kTRUE;
+}
Index: /trunk/MagicSoft/Mars/msignal/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/msignal/Makefile	(revision 3861)
+++ /trunk/MagicSoft/Mars/msignal/Makefile	(revision 3862)
@@ -37,4 +37,8 @@
 SRCFILES = MExtractedSignalCam.cc \
            MExtractedSignalPix.cc \
+           MExtractor.cc \
+           MExtractFixedWindow.cc \
+           MExtractSlidingWindow.cc \
+           MExtractFixedWindowPeakSearch.cc \
            MExtractSignal.cc \
            MExtractSignal2.cc \
Index: /trunk/MagicSoft/Mars/msignal/SignalLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/msignal/SignalLinkDef.h	(revision 3861)
+++ /trunk/MagicSoft/Mars/msignal/SignalLinkDef.h	(revision 3862)
@@ -10,4 +10,10 @@
 #pragma link C++ class MExtractSignal2+;
 #pragma link C++ class MExtractSignal3+;
+
+#pragma link C++ class MExtractor+;
+#pragma link C++ class MExtractFixedWindow+;
+#pragma link C++ class MExtractSlidingWindow+;
+#pragma link C++ class MExtractFixedWindowPeakSearch+;
+   
 
 #pragma link C++ class MExtractPINDiode++;
