Index: trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.cc	(revision 7034)
+++ trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.cc	(revision 7043)
@@ -150,5 +150,40 @@
   fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
   fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);  
-  
+
+  const Int_t wshigain = fHiGainLast-fHiGainFirst+1;
+  const Int_t wslogain = fLoGainLast-fLoGainFirst+1;
+
+  switch (wshigain)
+    {
+    case 2:
+      SetResolutionPerPheHiGain(0.021);
+      break;
+    case 4:
+    case 6:
+    case 8:
+    case 10:
+    case 12:
+    case 14:
+      SetResolutionPerPheHiGain(0.011);      
+      break;
+    default:
+        *fLog << warn << GetDescriptor() << ": Could not set the hi-gain extractor resolution/phe for window size " << wshigain << endl;
+    }
+  
+  switch (wslogain)
+    {
+    case 4:
+      SetResolutionPerPheLoGain(0.063);
+      break;
+    case 6:
+      SetResolutionPerPheLoGain(0.017);
+      break;
+    case 8:
+    case 10:
+      SetResolutionPerPheLoGain(0.011);      
+      break;
+    default:
+      *fLog << warn << GetDescriptor() << ": Could not set the lo-gain extractor resolution/phe for window size " << wslogain << endl;
+    }
 }
 
Index: trunk/MagicSoft/Mars/msignal/MExtractPINDiode.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractPINDiode.cc	(revision 7034)
+++ trunk/MagicSoft/Mars/msignal/MExtractPINDiode.cc	(revision 7043)
@@ -25,17 +25,36 @@
 //////////////////////////////////////////////////////////////////////////////
 //
-//   MExtractPINDiode
+//  MExtractPINDiode
 //
 //  Extracts the signal from a fixed window in a given range.
 //
 //  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.
+//  to modify the ranges.
+//
 //  Defaults are: 
 // 
-//   fHiGainFirst =  fgHiGainFirst =  3 
-//   fHiGainLast  =  fgHiGainLast  =  14
-//   fLoGainFirst =  fgLoGainFirst =  3 
-//   fLoGainLast  =  fgLoGainLast  =  14
+//   fHiGainFirst =  fgHiGainFirst =  0 
+//   fHiGainLast  =  fgHiGainLast  =  29
+//   fLoGainFirst =  fgLoGainFirst =  0
+//   fLoGainLast  =  fgLoGainLast  =  0
+//
+//  The FADC slices are fit by a Gaussian around the pulse maximum. 
+//  The following figures show two typical (high-intensity and low-intensity) 
+//  pulses together with the applied fit:
+//
+//Begin_Html
+/*
+<img src="images/PINDiode_pulse_high.gif">
+<img src="images/PINDiode_pulse_low.gif">
+*/
+//End_Html
+//
+// The fit ranges can be modified with the functions:
+// - SetLowerFitLimit() 
+// - SetUpperFitLimit()
+//
+// Defaults are:
+//   - fLowerFitLimit: 2
+//   - fUpperFitLimit: 5
 //
 //////////////////////////////////////////////////////////////////////////////
@@ -44,4 +63,8 @@
 #include <fstream>
 
+#include <TF1.h>
+#include <TH1.h>
+#include <TPad.h>
+
 #include "MLog.h"
 #include "MLogManip.h"
@@ -61,9 +84,12 @@
 using namespace std;
 
-const UInt_t MExtractPINDiode::fgPINDiodeIdx     = 100;
-const Byte_t MExtractPINDiode::fgHiGainFirst =  0;
-const Byte_t MExtractPINDiode::fgHiGainLast  =  14;
-const Byte_t MExtractPINDiode::fgLoGainFirst =  0;
-const Byte_t MExtractPINDiode::fgLoGainLast  =  14;
+const UInt_t MExtractPINDiode::fgPINDiodeIdx   =  3;
+const Byte_t MExtractPINDiode::fgHiGainFirst   =  0;
+const Byte_t MExtractPINDiode::fgHiGainLast    = 29;
+const Byte_t MExtractPINDiode::fgLoGainFirst   =  0;
+const Byte_t MExtractPINDiode::fgLoGainLast    =  0;
+const Byte_t MExtractPINDiode::fgLowerFitLimit =  2;
+const Byte_t MExtractPINDiode::fgUpperFitLimit =  5;
+
 // --------------------------------------------------------------------------
 //
@@ -72,9 +98,13 @@
 // Calls: 
 // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
-// - SetPINDiodeIdx()
+//
+// - Set fPINDiodeIdx   to fgPINDiodeIdx
+// - Set fLowerFitLimit to fgLowerFitLimit
+// - Set fUpperFitLimit to fgUpperFitLimit
 //
 MExtractPINDiode::MExtractPINDiode(const char *name, const char *title)
-{
-  
+    : fSlices(NULL)
+{
+
   fName  = name  ? name  : "MExtractPINDiode";
   fTitle = title ? title : "Task to extract the signal from the FADC slices";
@@ -82,4 +112,19 @@
   SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
   SetPINDiodeIdx();
+
+  SetLowerFitLimit();
+  SetUpperFitLimit();  
+
+  fPedMean.Set(2);
+}
+
+// --------------------------------------------------------------------------
+//
+// - delete the histogram fSlices, if it exists
+//
+MExtractPINDiode::~MExtractPINDiode()
+{
+  if (fSlices)
+    delete fSlices;
 }
 
@@ -89,8 +134,5 @@
 //
 // 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
+// - if the Hi Gain window is smaller than 4, set fHiGainLast to fHiGainFirst+3
 // 
 // Calls:
@@ -99,43 +141,31 @@
 // Sets:
 // - fNumHiGainSamples to: (Float_t)(fHiGainLast-fHiGainFirst+1)
-// - fNumLoGainSamples to: (Float_t)(fLoGainLast-fLoGainFirst+1)
+// - fNumLoGainSamples to: 0.
 // - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples)
-// - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples)  
+// - fSqrtLoGainSamples to: 0.
 //  
 void MExtractPINDiode::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
 {
 
-  const Byte_t window = hilast-hifirst+1+lolast-lofirst+1;
-  const Byte_t weven  = window & ~1;
-
-  if (weven != window)
+  lofirst = 0;
+  lolast  = 0;
+
+  const Byte_t window = hilast-hifirst+1;
+
+  if (window<4) 
     {
       *fLog << warn << GetDescriptor() 
-            << Form("%s%2i%s%2i",": Total window size has to be even, set last slice from "
-                    ,(int)lolast," to ",(int)(lolast-1)) << endl;
-      lolast -= 1;
-    }
-  
-  if (window<2) 
-    {
-      *fLog << warn << GetDescriptor() 
-            << Form("%s%2i%s%2i",": Total window is smaller than 2 FADC sampes, set last slice from" 
-                    ,(int)lolast," to ",(int)(lofirst+1)) << endl;
-      hilast = hifirst+1;
-    }
-  
+            << Form("%s%2i%s%2i",": Total window is smaller than 4 FADC sampes, set last slice from" 
+                    ,(int)lolast," to ",(int)(lofirst+3)) << endl;
+      hilast = hifirst+3;
+    }
 
   MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
 
   fNumHiGainSamples = (Float_t)(fHiGainLast-fHiGainFirst+1);
-  fNumLoGainSamples = (fLoGainLast == 0) ? 0. : (Float_t)(fLoGainLast-fLoGainFirst+1);  
+  fNumLoGainSamples = 0.;
 
   fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
-  fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);  
-  
-  fNumSamples = (fLoGainLast == 0) 
-    ? fHiGainLast-fHiGainFirst+1 
-    : fHiGainLast-fHiGainFirst+1+fLoGainLast-fLoGainFirst+1;
-  fSqrtSamples = TMath::Sqrt((Float_t)fNumSamples);
+  fSqrtLoGainSamples = 0.;
   
 }
@@ -149,5 +179,12 @@
 // they were not found:
 //
+//  - MRawEvtData2
 //  - MExtractedPINDiode
+//
+// Initializes fPedMean to:
+// - fPedMean[0]: pedestal + AB-offset
+// - fPedMean[1]: pedestal - AB-offset
+//
+// Initializes TH1F fSlices to [fHiGainFirst-0.5,fHiGainLast+0.5]
 //
 Int_t MExtractPINDiode::PreProcess(MParList *pList)
@@ -157,23 +194,40 @@
     return kFALSE;
   
+  fRawEvt = NULL;
+  fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData2"));
+  if (!fRawEvt)
+    {
+      *fLog << err << AddSerialNumber("MRawEvtData2") << " not found... aborting." << endl;
+      return kFALSE;
+    }
+
   fPINDiode = (MExtractedSignalPINDiode*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalPINDiode"));
   if (!fPINDiode)
     return kFALSE;
 
+  fPedMean.Reset();
+
   const MPedestalPix &ped   = (*fPedestals)[fPINDiodeIdx]; 
 
-    if (&ped)
-      {
-        fPedestal = ped.GetPedestal();
-        fPedRms   = ped.GetPedestalRms();
-      }
-    else
-      {
-        *fLog << err << " Cannot find MPedestalPix of the PIN Diode (idx=" 
-              << fPINDiodeIdx << ")" << endl;
+  if (&ped)
+    {
+      fPedMean[0] = ped.GetPedestal() + ped.GetPedestalABoffset();
+      fPedMean[1] = ped.GetPedestal() - ped.GetPedestalABoffset();      
+    }
+  else
+    {
+      *fLog << err << " Cannot find MPedestalPix of the PIN Diode (idx=" 
+            << fPINDiodeIdx << ")" << endl;
         return kFALSE;
-      }
-
-    return kTRUE;
+    }
+  
+  if (fSlices)
+    delete fSlices;
+
+  fSlices = new TH1F("PINDiode","PIN Diode fitted slices",(Int_t)(fHiGainLast-fHiGainFirst+1),
+                     fHiGainFirst-0.5,fHiGainLast+0.5);
+  fSlices->SetDirectory(NULL);
+
+  return kTRUE;
 }
 
@@ -190,91 +244,137 @@
   
   fPINDiode->SetUsedFADCSlices(fHiGainFirst, fLoGainLast);
-  
+
+  *fLog << endl;
+  *fLog << inf << "Taking " << fNumHiGainSamples
+        << " HiGain samples from slice " << (Int_t)fHiGainFirst
+        << " to " << (Int_t)(fHiGainLast+fHiLoLast) << " incl" << endl;
+
   return kTRUE;
-  
-}
-
-
-
-void MExtractPINDiode::FindSignalandVarianceHiGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const
-{
-
-  Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
-
+}
+
+
+
+
+// ----------------------------------------------------------------------------------
+//
+// Extracts the (pedestal-subtracted) FADC slices between fHiGainFirst and fHiGainLast 
+// and fills them into the histogram fSlices. Memorizes the position of maximum at 
+// maxpos.
+//
+// Checks for saturation
+// 
+// Fits fSlices to a Gaussian in the ranges: maxpos-fLowerFitLimit, maxpos+fUpperFitLimit
+//
+// Writes fit results into MExtractedSignalPINDiode
+//
+Int_t MExtractPINDiode::Process()
+{
+
+
+  MRawEvtPixelIter pixel(fRawEvt);
+  
+  fPINDiode->Clear();
+  fSlices->Reset();
+  
+  pixel.Jump(fPINDiodeIdx);
+  
+  Byte_t sat  = 0;
+
+  Int_t higainsamples = pixel.GetNumHiGainSamples();
+  Int_t logainsamples = pixel.GetNumLoGainSamples();
+  
+  const Bool_t higainabflag = pixel.HasABFlag();
+  Byte_t *ptr = pixel.GetHiGainSamples()+fHiGainFirst;
+  Byte_t *end = ptr+higainsamples;
+  
+  Int_t cnt=0;
+
+  Float_t max = 0.;
+  Int_t maxpos = 0;
+  
   while (ptr<end)
     {
-      sum  += *ptr;
-      sum2 += *ptr * *ptr;
-
-      if (*ptr++ >= fSaturationLimit)
-        sat++;
-    }
-}
-
-void MExtractPINDiode::FindSignalandVarianceLoGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const
-{
-
-  Byte_t *end = ptr +  fLoGainLast - fLoGainFirst  + 1;
-
-  while (ptr<end)
-    {
-      sum  += *ptr;
-      sum2 += *ptr * *ptr;
       
-      if (*ptr++ >= fSaturationLimit)
-        sat++;
-    }
-}
-
-
-
-// --------------------------------------------------------------------------
-//
-// Calculate the integral of the FADC time slices and store them as a new
-// pixel in the MExtractedPINDiode container.
-//
-Int_t MExtractPINDiode::Process()
-{
-
-
-  MRawEvtPixelIter pixel(fRawEvt);
-  
-  fPINDiode->Clear();
-  
-  pixel.Jump(fPINDiodeIdx);
-  
-  Int_t sum   = 0;
-  Int_t sum2  = 0;
-  Byte_t sat  = 0;
-  Int_t max   = 0;
-  
-  // 
-  // Calculate first the time:
-  //
-  const Int_t maxhi = pixel.GetIdxMaxHiGainSample();
-  const Int_t maxlo = pixel.GetIdxMaxLoGainSample();
-  
-  if (maxhi > maxlo)
-    max = maxhi;
-  else
-    max = maxlo + pixel.GetNumHiGainSamples();
-  
-  FindSignalandVarianceHiGain(pixel.GetHiGainSamples()+fHiGainFirst,sum,sum2,sat);
-  if (pixel.HasLoGain())
-    FindSignalandVarianceLoGain(pixel.GetLoGainSamples()+fLoGainFirst,sum,sum2,sat);
-
-  const Float_t var = ((Float_t)sum2 - (Float_t)sum*sum/fNumSamples)/(fNumSamples-1);
-  const Float_t rms = TMath::Sqrt(var);
-  
-  // 
-  // FIXME: The following formulae have to be revised!!
-  //
-  fPINDiode->SetExtractedSignal(sum - fPedestal*fNumSamples, fPedRms*fSqrtSamples);
-  fPINDiode->SetExtractedRms   (rms, rms/2./fSqrtSamples);
-  fPINDiode->SetExtractedTime  (max, rms/fSqrtSamples);
-  fPINDiode->SetSaturation(sat);
+      if (*ptr >= fSaturationLimit)
+        {
+          sat++;
+          break;
+        }
+
+      const Float_t cont = (Float_t)*ptr - fPedMean[(cnt + higainabflag) & 0x1];
+      fSlices->Fill(cnt,cont);
+
+      if (cont > max)
+      {
+        max = cont;
+        maxpos = cnt;
+      }
+
+      ptr++;
+      cnt++;
+    }
+  
+  cnt = 0;
+  
+  if (pixel.HasLoGain() && !sat)
+    {
+      
+      ptr = pixel.GetLoGainSamples();
+      end = ptr+logainsamples;
+      
+      const Bool_t logainabflag = (higainabflag + pixel.GetNumHiGainSamples()) & 0x1;
+      
+      while (ptr<end)
+        {
+          
+          if (*ptr >= fSaturationLimit)
+            {
+              sat++;
+              break;
+            }
+
+          const Float_t cont = (Float_t)*ptr - fPedMean[(cnt + logainabflag) & 0x1];
+          
+          fSlices->Fill(cnt+ higainsamples,cont);
+          
+          if (cont > max) 
+            {
+              max    = cont;
+              maxpos = cnt+higainsamples;
+            }
+          ptr++;
+          cnt++;
+        }
+    }
+          
+  if (sat)
+    {
+      fPINDiode->SetSaturation(1);
+      return kTRUE;
+    }
+
+  fSlices->Fit("gaus", "RQ", "", maxpos-fLowerFitLimit,maxpos+fUpperFitLimit);
+  
+  TF1 *gausfunc = fSlices->GetFunction("gaus");
+
+  fPINDiode->SetExtractedSignal(gausfunc->GetParameter(0), gausfunc->GetParError(0));
+  fPINDiode->SetExtractedTime  (gausfunc->GetParameter(1), gausfunc->GetParError(1));
+  fPINDiode->SetExtractedSigma (gausfunc->GetParameter(2), gausfunc->GetParError(2));
+  fPINDiode->SetExtractedChi2  (gausfunc->GetChisquare());
   fPINDiode->SetReadyToSave();
-  
+
   return kTRUE;
 }
 
+// ----------------------------------------------------------------------------------
+//
+// deletes fSlices and sets pointer to NULL
+//
+Int_t MExtractPINDiode::PostProcess()
+{
+  
+  delete fSlices;
+  fSlices = NULL;
+  
+  return kTRUE;
+}
Index: trunk/MagicSoft/Mars/msignal/MExtractPINDiode.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractPINDiode.h	(revision 7034)
+++ trunk/MagicSoft/Mars/msignal/MExtractPINDiode.h	(revision 7043)
@@ -15,5 +15,11 @@
 #endif
 
+#ifndef MARS_MArrayF
+#include "MArrayF.h"
+#endif
+
+class TH1F;
 class MExtractedSignalPINDiode;
+
 class MExtractPINDiode : public MExtractor
 {
@@ -21,33 +27,39 @@
 
   static const UInt_t fgPINDiodeIdx;  
-  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 fgHiGainFirst;     // First FADC slice Hi-Gain (now set to: 3) 
+  static const Byte_t fgHiGainLast;      // Last  FADC slice Hi-Gain (now set to: 14) 
+  static const Byte_t fgLoGainFirst;     // First FADC slice Lo-Gain (now set to: 3) 
+  static const Byte_t fgLoGainLast;      // Last  FADC slice Lo-Gain (now set to: 14) 
 
-  MExtractedSignalPINDiode  *fPINDiode;     // Extracted signal of the PIN Diode
+  static const Byte_t fgLowerFitLimit;   // Default for fLowerFitLimit (now set to: 2)
+  static const Byte_t fgUpperFitLimit;   // Default for fUpperFitLimit (now set to: 5)
 
-  UInt_t  fPINDiodeIdx;
-  Float_t fPedestal;
-  Float_t fPedRms;
-  Int_t   fNumSamples;
-  Float_t fSqrtSamples;
+  Byte_t fLowerFitLimit;                 // Number of FADC slices before maximum to start fit
+  Byte_t fUpperFitLimit;                 // Number of FADC slices after maximum to end fit
   
-  void   FindSignalandVarianceHiGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const;
-  void   FindSignalandVarianceLoGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const;
-
-  Int_t  PreProcess(MParList *pList);
-  Bool_t ReInit(MParList *pList);  
-  Int_t  Process();
+  MExtractedSignalPINDiode  *fPINDiode;  // Extracted signal of the PIN Diode
+  TH1F                      *fSlices;    // Histogram to fit the slices
+  
+  UInt_t  fPINDiodeIdx;                  // PIN Diode pixel ID
+  
+  MArrayF fPedMean;                      // The used pedestals (0: ped+AB, 1: ped-AB)
+  
+  Int_t  PreProcess( MParList *pList );
+  Bool_t ReInit    ( MParList *pList );  
+  Int_t  Process    ();
+  Int_t  PostProcess();
   
 public:
 
   MExtractPINDiode(const char *name=NULL, const char *title=NULL);
+  ~MExtractPINDiode();  
 
   // Setters
   void SetRange(Byte_t hifirst=0, Byte_t hilast=0, Byte_t lofirst=0, Byte_t lolast=0);
-  void SetPINDiodeIdx(    const UInt_t idx=fgPINDiodeIdx    ) { fPINDiodeIdx     = idx; }   
+  void SetPINDiodeIdx  ( const UInt_t idx=fgPINDiodeIdx    ) { fPINDiodeIdx   = idx; }
+  void SetLowerFitLimit( const Byte_t lim=fgLowerFitLimit  ) { fLowerFitLimit = lim; }
+  void SetUpperFitLimit( const Byte_t lim=fgUpperFitLimit  ) { fUpperFitLimit = lim; }     
 
-  ClassDef(MExtractPINDiode, 0) // Signal Extractor for the PIN Diode
+  ClassDef(MExtractPINDiode, 1) // Signal Extractor for the PIN Diode
 };
 
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 7034)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 7043)
@@ -78,7 +78,7 @@
 const Int_t  MExtractTimeAndChargeDigitalFilter::fgSignalStartBinHiGain    =  4;
 const Int_t  MExtractTimeAndChargeDigitalFilter::fgSignalStartBinLoGain    =  4;
-const TString MExtractTimeAndChargeDigitalFilter::fgNameWeightsFile        = "msignal/cosmics_weights46.dat";
+const TString MExtractTimeAndChargeDigitalFilter::fgNameWeightsFile        = "msignal/cosmics_weights.dat";
 const Float_t MExtractTimeAndChargeDigitalFilter::fgOffsetLoGain           =  1.7; // 5 ns
-const Float_t MExtractTimeAndChargeDigitalFilter::fgLoGainStartShift       = -2.8;
+const Float_t MExtractTimeAndChargeDigitalFilter::fgLoGainStartShift       = -1.8;
 
 // --------------------------------------------------------------------------
@@ -753,4 +753,30 @@
 
     CalcBinningResArrays();
+
+    switch (fWindowSizeHiGain)
+      {
+      case 4:
+	SetResolutionPerPheHiGain(0.036);
+	break;
+      case 6:
+	SetResolutionPerPheHiGain(0.021);
+	break;
+      default:
+	*fLog << warn << "Could not set the high-gain extractor resolution per phe for window size " 
+	      << fWindowSizeHiGain << endl;
+      }
+
+    switch (fWindowSizeLoGain)
+      {
+      case 4:
+	SetResolutionPerPheLoGain(0.005);
+	break;
+      case 6:
+	SetResolutionPerPheLoGain(0.004);
+	break;
+      default:
+	*fLog << warn << "Could not set the low-gain extractor resolution per phe for window size " 
+	      << fWindowSizeLoGain << endl;
+      }
 
     fWeightsSet = kTRUE;
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc	(revision 7034)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc	(revision 7043)
@@ -76,4 +76,5 @@
 const Byte_t  MExtractTimeAndChargeSlidingWindow::fgHiGainWindowSize = 6;
 const Byte_t  MExtractTimeAndChargeSlidingWindow::fgLoGainWindowSize = 6;
+
 // --------------------------------------------------------------------------
 //
@@ -176,4 +177,43 @@
   fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
 
+  switch (fWindowSizeHiGain)
+    {
+    case 2:
+      SetResolutionPerPheHiGain(0.050);
+      break;
+    case 4:
+      SetResolutionPerPheHiGain(0.039);
+      break;
+    case 6:
+    case 8:
+      SetResolutionPerPheHiGain(0.011);
+      break;
+    case 14:
+      SetResolutionPerPheHiGain(0.009);
+      break;
+    default:
+      *fLog << warn << GetDescriptor() << ": Could not set the high-gain extractor resolution per phe for window size " 
+            << fWindowSizeHiGain << endl;
+    }
+  
+  switch (fWindowSizeLoGain)
+    {
+    case 2:
+      SetResolutionPerPheLoGain(0.028);
+      break;
+    case 4:
+      SetResolutionPerPheLoGain(0.013);
+      break;
+    case 6:
+      SetResolutionPerPheLoGain(0.008);
+      break;
+    case 8:
+    case 10:
+      SetResolutionPerPheLoGain(0.005);
+      break;
+    default:
+      *fLog << warn << GetDescriptor() << ": Could not set the low-gain extractor resolution per phe for window size " 
+            << fWindowSizeLoGain << endl;
+    }
 }
 
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.h	(revision 7034)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.h	(revision 7043)
@@ -11,9 +11,8 @@
 
 class MPedestalPix;
+
 class MExtractTimeAndChargeSlidingWindow : public MExtractTimeAndCharge
 {
-
 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)
@@ -49,5 +48,5 @@
                                Byte_t &sat, const MPedestalPix &ped, const Bool_t abflag);
 
-  ClassDef(MExtractTimeAndChargeSlidingWindow, 0)   // Task to Extract Times and Charges using a Sliding Window
+  ClassDef(MExtractTimeAndChargeSlidingWindow, 1)   // Task to Extract Times and Charges using a Sliding Window
 };
 
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 7034)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 7043)
@@ -233,4 +233,7 @@
       fWindowSizeLoGain  = 1;
       fRiseTimeHiGain    = 0.5;
+
+      SetResolutionPerPheHiGain(0.053);
+      SetResolutionPerPheLoGain(0.016);
       
       return;
@@ -242,12 +245,58 @@
       fNumHiGainSamples  = fRiseTimeHiGain + fFallTimeHiGain;
       fNumLoGainSamples  = fLoGainLast ? fRiseTimeLoGain + fFallTimeLoGain : 0.;
-      //      fNumLoGainSamples  *= 0.75;      
 
       fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
       fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
-      fWindowSizeHiGain  = (Int_t)(fRiseTimeHiGain + fFallTimeHiGain);
-      fWindowSizeLoGain  = (Int_t)((fRiseTimeLoGain + fFallTimeLoGain)*fLoGainStretch);
-      //      fNumLoGainSamples  *= 0.75;      
-    }
+      fWindowSizeHiGain  = TMath::Nint(fRiseTimeHiGain + fFallTimeHiGain);
+      // to ensure that for the case: 1.5, the window size becomes: 2 (at any compiler)
+      fWindowSizeLoGain  = TMath::Nint(TMath::Ceil((fRiseTimeLoGain + fFallTimeLoGain)*fLoGainStretch));
+    }
+
+    switch (fWindowSizeHiGain)
+    {
+    case 1:
+      SetResolutionPerPheHiGain(0.041);
+      break;
+    case 2:
+      SetResolutionPerPheHiGain(0.064);
+      break;
+    case 3:
+    case 4:
+      SetResolutionPerPheHiGain(0.050);
+      break;
+    case 5:
+    case 6:
+      SetResolutionPerPheHiGain(0.030);
+      break;
+    default:
+	*fLog << warn << GetDescriptor() << ": Could not set the high-gain extractor resolution per phe for window size " 
+	      << fWindowSizeHiGain << endl;
+	break;
+    }
+
+    switch (fWindowSizeLoGain)
+    {
+    case 1:
+    case 2:
+      SetResolutionPerPheLoGain(0.005);
+      break;
+    case 3:
+    case 4:
+      SetResolutionPerPheLoGain(0.017);
+      break;
+    case 5:
+    case 6:
+    case 7:
+      SetResolutionPerPheLoGain(0.005);
+      break;
+    case 8:
+    case 9:
+      SetResolutionPerPheLoGain(0.005);
+      break;
+    default:
+	*fLog << warn << "Could not set the low-gain extractor resolution per phe for window size " 
+	      << fWindowSizeLoGain << endl;
+	break;
+     }
 }
 
Index: trunk/MagicSoft/Mars/msignal/MExtractedSignalPINDiode.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractedSignalPINDiode.cc	(revision 7034)
+++ trunk/MagicSoft/Mars/msignal/MExtractedSignalPINDiode.cc	(revision 7043)
@@ -39,7 +39,4 @@
 
 using namespace std;
-
-static const Float_t gkSignalInitializer = 99999.9;
-
 // ------------------------------------------------------------------------
 //
@@ -49,5 +46,5 @@
 // Additionally, the number of saturated Slices are stored. 
 // 
-// Default values for the extracted signals are: 99999.9 
+// Default values for the extracted signals are: -1. 
 //
 MExtractedSignalPINDiode::MExtractedSignalPINDiode(const char* name, const char* title)
@@ -62,16 +59,19 @@
 // ------------------------------------------------------------------------
 //
-// Invalidate values
+// Invalidate values to -1.
 //
 void MExtractedSignalPINDiode::Clear(Option_t *o)
 {
-  fExtractedSignal          = gkSignalInitializer;
-  fExtractedSignalErr       = gkSignalInitializer;
-  fExtractedTime            = gkSignalInitializer;
-  fExtractedTimeErr         = gkSignalInitializer; 
-  fExtractedRms             = gkSignalInitializer; 
-  fExtractedRmsErr          = gkSignalInitializer; 
 
-  fNumSaturated       = 0;
+  fExtractedSignal          = -1.;
+  fExtractedSignalErr       = -1.;
+  fExtractedTime            = -1.;
+  fExtractedTimeErr         = -1.; 
+  fExtractedSigma           = -1.; 
+  fExtractedSigmaErr        = -1.; 
+  fExtractedChi2            = -1.; 
+
+  fSaturated  = kFALSE;
+  
 }
 
@@ -85,36 +85,35 @@
 void MExtractedSignalPINDiode::SetExtractedSignal(const Float_t sig, const Float_t sigerr)   
 {
-  fExtractedSignal      = sig; 
+  fExtractedSignal    = sig; 
   fExtractedSignalErr = sigerr;
 }
 
-void MExtractedSignalPINDiode::SetExtractedRms(const Float_t sig, const Float_t sigerr)   
+void MExtractedSignalPINDiode::SetExtractedSigma(const Float_t sig, const Float_t sigerr)   
 {
-  fExtractedRms      = sig; 
-  fExtractedRmsErr = sigerr;
+  fExtractedSigma    = sig; 
+  fExtractedSigmaErr = sigerr;
 }
 
 void MExtractedSignalPINDiode::SetExtractedTime(const Float_t sig, const Float_t sigerr)   
 {
-  fExtractedTime      = sig; 
+  fExtractedTime    = sig; 
   fExtractedTimeErr = sigerr;
 }
 
-
 Bool_t MExtractedSignalPINDiode::IsValid() const
 {
-    return fExtractedSignal >= 0. || fExtractedSignalErr >= 0.;
-}
-
-void MExtractedSignalPINDiode::SetSaturation(const Byte_t numsat)
-{
-  fNumSaturated = numsat; 
+  if (fSaturated)
+    return kFALSE;
+  
+  return fExtractedSignal >= 0. || fExtractedSignalErr >= 0.;
 }
 
 void MExtractedSignalPINDiode::Print(Option_t *o) const
 {
-  *fLog << " Signal: " << fExtractedSignal
-        << " +- " << fExtractedSignalErr
-        << " Nr. Saturation: " <<  fNumSaturated
+  *fLog << Form(" Signal: %4.2f+-%4.2f",fExtractedSignal,fExtractedSignalErr) 
+        << Form(" Arr.Time: %4.2f+-%4.2f",fExtractedTime,fExtractedTimeErr) 
+        << Form(" Sigma: %4.2f+-%4.2f",fExtractedSigma,fExtractedSigmaErr) 
+        << Form(" Chi2: %5.2f",fExtractedChi2) 
+        << Form(" Saturation: %s",fSaturated ? "yes" : "no")
         << endl;
 }
Index: trunk/MagicSoft/Mars/msignal/MExtractedSignalPINDiode.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractedSignalPINDiode.h	(revision 7034)
+++ trunk/MagicSoft/Mars/msignal/MExtractedSignalPINDiode.h	(revision 7043)
@@ -10,42 +10,47 @@
 private:
 
-  Float_t fExtractedSignal;    // mean value of the extracted signal
-  Float_t fExtractedSignalErr; // error of the mean value of the extracted signal
-  Float_t fExtractedTime; 
-  Float_t fExtractedTimeErr; 
-  Float_t fExtractedRms; 
-  Float_t fExtractedRmsErr; 
-
-  Byte_t fFirst;
-  Byte_t fNumFADCSamples;
-  Byte_t fNumSaturated;
+  Float_t fExtractedSignal;    // Extracted signal amplitude
+  Float_t fExtractedSignalErr; // Error extracted signal amplitude
+  Float_t fExtractedTime;      // Position of signal amplitude
+  Float_t fExtractedTimeErr;   // Error position of signal amplitude
+  Float_t fExtractedSigma;     // Width Gauss fit 
+  Float_t fExtractedSigmaErr;  // Error of width
+  Float_t fExtractedChi2;      // Chi2 Gauss fit   
+ 
+  Byte_t fNumFADCSamples;      // Number of used FADC slices
+  Byte_t fFirst;               // First FADC slice to start extraction
+  
+  Bool_t fSaturated;           // FADC saturation occurrance flag
 
 public:
-    MExtractedSignalPINDiode(const char* name=NULL, const char* title=NULL);
 
-    void Clear(Option_t *o="");
-    void Print(Option_t *o="") const;
+  MExtractedSignalPINDiode(const char* name=NULL, const char* title=NULL);
+  
+  void Clear(Option_t *o="");
+  
+  // Getter
+  Float_t GetExtractedSignal()    const { return fExtractedSignal;       }
+  Float_t GetExtractedSignalErr() const { return fExtractedSignalErr;    }
+  Float_t GetExtractedTime()      const { return fExtractedTime;         }
+  Float_t GetExtractedTimeErr()   const { return fExtractedTimeErr;      }
+  Float_t GetExtractedSigma()     const { return fExtractedSigma;        }
+  Float_t GetExtractedSigmaErr()  const { return fExtractedSigmaErr;     }
+  Float_t GetExtractedChi2()      const { return fExtractedChi2;         }  
+  Byte_t  GetNumFADCSamples()     const { return fNumFADCSamples;        }
+  
+  Bool_t  IsValid()    const;   
+  
+  // Print
+  void Print(Option_t *o="") const;
 
-    // Setter
-    void SetExtractedSignal(const Float_t sig, const Float_t sigerr);
-    void SetExtractedRms(  const Float_t sig, const Float_t sigerr);
-    void SetExtractedTime(  const Float_t sig, const Float_t sigerr);
-    void SetSaturation(   const Byte_t numsat);
-    void SetUsedFADCSlices( const Byte_t first, const Byte_t num);
-    
-    // Getter
-    Float_t GetExtractedSignal()    const { return fExtractedSignal;       }
-    Float_t GetExtractedSignalErr() const { return fExtractedSignalErr;    }
-    Float_t GetExtractedTime()      const { return fExtractedTime;         }
-    Float_t GetExtractedTimeErr()   const { return fExtractedTimeErr;      }
-    Float_t GetExtractedRms()       const { return fExtractedRms;          }
-    Float_t GetExtractedRmsErr()    const { return fExtractedRmsErr;       }
-    Byte_t  GetNumFADCSamples()     const { return fNumFADCSamples;        }
-    Byte_t  GetFirstUsedSlice()     const { return fFirst;                 }
-    Byte_t  GetLastUsedSlice()      const { return fFirst+fNumFADCSamples; }    
-    
-    Bool_t IsValid() const;   
+  // Setter
+  void SetExtractedSignal(const Float_t sig, const Float_t sigerr);
+  void SetExtractedSigma(  const Float_t sig, const Float_t sigerr);
+  void SetExtractedTime(  const Float_t sig, const Float_t sigerr);
+  void SetExtractedChi2(  const Float_t chi ) { fExtractedChi2 = chi; }
+  void SetSaturation  (   const Bool_t b=kTRUE) { fSaturated = b;  }
+  void SetUsedFADCSlices( const Byte_t first, const Byte_t num);
 
-    ClassDef(MExtractedSignalPINDiode, 1)	// Storage Container for Extracted Signal information of one pixel
+  ClassDef(MExtractedSignalPINDiode, 2)	// Storage Container for Extracted Signal information of one pixel
 };
 
Index: trunk/MagicSoft/Mars/msignal/MExtractor.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 7034)
+++ trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 7043)
@@ -64,4 +64,9 @@
 //End_Html
 //
+// Class Version 6:
+//  +Float_t fResolutionPerPheHiGain; // Extractor-dependent charge resolution per phe for high-gain (see TDAS-0502).
+//  +Float_t fResolutionPerPheLoGain; // Extractor-dependent charge resolution per phe for low-gain  (see TDAS-0502).
+//
+//
 // Input Containers:
 //   MRawEvtData
@@ -100,4 +105,5 @@
 const TString MExtractor::fgNameSignalCam   = "MExtractedSignalCam";
 const Float_t MExtractor::fgOffsetLoGain    = 1.51;   // 5 ns
+
 // --------------------------------------------------------------------------
 //
@@ -116,6 +122,7 @@
 //
 MExtractor::MExtractor(const char *name, const char *title)
-    : fPedestals(NULL), fSignals(NULL), fRawEvt(NULL), fRunHeader(NULL),
-      fHiLoLast(0), fNumHiGainSamples(0.), fNumLoGainSamples(0.)
+    : fResolutionPerPheHiGain(0), fResolutionPerPheLoGain(0),
+      fPedestals(NULL), fSignals(NULL), fRawEvt(NULL), fRunHeader(NULL),
+      fHiLoLast(0), fNumHiGainSamples(0), fNumLoGainSamples(0)
 {
     fName  = name  ? name  : "MExtractor";
Index: trunk/MagicSoft/Mars/msignal/MExtractor.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractor.h	(revision 7034)
+++ trunk/MagicSoft/Mars/msignal/MExtractor.h	(revision 7043)
@@ -23,11 +23,12 @@
 {
 private:
-
   static const Float_t fgOffsetLoGain;     //! Default for fOffsetLoGain (now set to 1.51 (= 5ns)
   
   Bool_t  fNoiseCalculation;               //! Flag if extractor determines noise contribution from pedestal file.
+
+  Float_t fResolutionPerPheHiGain;         // Extractor-dependent charge resolution per phe for high-gain (see TDAS-0502).
+  Float_t fResolutionPerPheLoGain;         // Extractor-dependent charge resolution per phe for low-gain  (see TDAS-0502).
   
 protected:
-
   static const Byte_t  fgSaturationLimit;  //! Default for fSaturationLimit (now set to: 254)
   static const TString fgNamePedestalCam;  //! "MPedestalCam"
@@ -54,13 +55,20 @@
   Float_t  fSqrtHiGainSamples;             // Sqrt. nr. High Gain FADC slices used to extract the signal
   Float_t  fSqrtLoGainSamples;             // Sqrt. nr. Low  Gain FADC slices used to extract the signal
-                                           
+
   Byte_t   fSaturationLimit;               // Highest FADC slice value until being declared saturated
+
   TString  fNamePedestalCam;               // Name of the 'MPedestalCam' container
   TString  fNameSignalCam;                 // Name of the 'MExtractedSignalCam' container
 
+  // MExtractor
   virtual void FindSignalHiGain(Byte_t *firstused, Byte_t *lowgain, Float_t &sum, Byte_t &sat) const { }
   virtual void FindSignalLoGain(Byte_t *firstused, Float_t &sum, Byte_t &sat) const { }
-  
+
+  void SetResolutionPerPheHiGain(Float_t f) { fResolutionPerPheHiGain=f; }
+  void SetResolutionPerPheLoGain(Float_t f) { fResolutionPerPheLoGain=f; }
+
   Int_t   PreProcessStd(MParList *pList);
+
+  // MTask
   Int_t   PreProcess( MParList *pList );
   Bool_t  ReInit    ( MParList *pList );
@@ -69,12 +77,9 @@
   Int_t   ReadEnv(const TEnv &env, TString prefix, Bool_t print);
 
+
 public:
   MExtractor(const char *name=NULL, const char *title=NULL);
   
-  void Clear(Option_t *o="") 
-    {
-      fHiGainFirst = fHiGainLast = fLoGainFirst = fLoGainLast = fHiLoLast = 0;
-    }
-
+  // getter
   Byte_t  GetHiGainFirst()      const { return fHiGainFirst;      }
   Byte_t  GetHiGainLast ()      const { return fHiGainLast ;      }
@@ -86,5 +91,9 @@
 
   Bool_t  IsNoiseCalculation () const { return fNoiseCalculation; }
-  
+
+  // Setter
+  Float_t SetResolutionPerPheHiGain() const { return fResolutionPerPheHiGain; }
+  Float_t SetResolutionPerPheLoGain() const { return fResolutionPerPheLoGain; }
+
   virtual void SetRange(Byte_t hifirst=0, Byte_t hilast=0, Byte_t lofirst=0, Byte_t lolast=0);
 
@@ -97,7 +106,13 @@
   void SetPedestals (MPedestalCam *pedcam)   { fPedestals = pedcam; }
 
+  // TObject
+  void Clear(Option_t *o="") 
+    {
+      fHiGainFirst = fHiGainLast = fLoGainFirst = fLoGainLast = fHiLoLast = 0;
+    }
+
   void Print(Option_t *o="") const;
 
-  ClassDef(MExtractor, 5) // Signal Extractor Base Class
+  ClassDef(MExtractor, 6) // Signal Extractor Base Class
 };
 
