Index: trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc	(revision 8563)
+++ trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc	(revision 8564)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MExtractPedestal.cc,v 1.31 2007-05-16 13:56:17 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MExtractPedestal.cc,v 1.32 2007-06-16 21:59:19 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -179,7 +179,8 @@
 const TString  MExtractPedestal::fgNameRawEvtData  = "MRawEvtData";
 
-const UShort_t MExtractPedestal::fgCheckWinFirst   =  0;
-const UShort_t MExtractPedestal::fgCheckWinLast    = 29;
-const UShort_t MExtractPedestal::fgMaxSignalVar    = 40;
+const UShort_t MExtractPedestal::fgCheckWinFirst   =   0;
+const UShort_t MExtractPedestal::fgCheckWinLast    =  29;
+const UShort_t MExtractPedestal::fgMaxSignalVar    =  40;
+const UShort_t MExtractPedestal::fgMaxSignalAbs    = 250;
 
 // --------------------------------------------------------------------------
@@ -210,4 +211,5 @@
     SetCheckRange(fgCheckWinFirst, fgCheckWinLast);
     SetMaxSignalVar(fgMaxSignalVar);
+    SetMaxSignalAbs(fgMaxSignalAbs);
 
     Clear();
@@ -598,17 +600,17 @@
 //
 // Check whether the signal variation between fCheckWinFirst and fCheckWinLast
-// exceeds fMaxSignalVar or the signal is greater than 250
+// exceeds fMaxSignalVar or the signal is greater than fMaxSignalAbs
 //
 Bool_t MExtractPedestal::CheckVariation(UInt_t idx) const
 {
     // This is the fast workaround to put hi- and lo-gains together
-    Byte_t *slices = fSignal->GetSamplesRaw(idx);
+    USample_t *slices = fSignal->GetSamplesRaw(idx);
 
     // Start 'real' work
-    UInt_t max = 0;
-    UInt_t min = (UInt_t)-1;
+    USample_t max = 0;
+    USample_t min = (USample_t)-1;
 
     // Find the maximum and minimum signal per slice in the high gain window
-    for (Byte_t *slice=slices+fCheckWinFirst; slice<=slices+fCheckWinLast; slice++)
+    for (USample_t *slice=slices+fCheckWinFirst; slice<=slices+fCheckWinLast; slice++)
     {
         if (*slice > max)
@@ -620,5 +622,5 @@
     // If the maximum in the high gain window is smaller than
     // FIXME: Precompiled value!
-    return max-min<fMaxSignalVar && max<250;
+    return max-min<fMaxSignalVar && max<fMaxSignalAbs;
 }
 
@@ -648,5 +650,5 @@
 
     // Do some handling if maxpos is last slice?
-    const Int_t maxposhi = fSignal->GetMaxPos(idx, start, start+range-1);
+    const Int_t maxposhi = fRandomCalculation ? 0 : fSignal->GetMaxPos(idx, start, start+range-1);
 
     const Float_t *sig = fSignal->GetSamples(idx);
@@ -659,4 +661,5 @@
                                          dummy[0], dummy[1], dummy[2],
                                          0, maxposhi);
+
     return sum;
 }
@@ -672,6 +675,6 @@
     const Int_t first = fExtractWinFirst+offset;
 
-    Byte_t *ptr = fSignal->GetSamplesRaw(pixel.GetPixelId())+first;
-    Byte_t *end = ptr + fExtractWinSize;
+    USample_t *ptr = fSignal->GetSamplesRaw(pixel.GetPixelId())+first;
+    USample_t *end = ptr + fExtractWinSize;
 
     Int_t abflag = pixel.HasABFlag() + first;
@@ -786,6 +789,12 @@
     // multiplies by this number
 
+    // scale to 256
+    const UInt_t scale = fExtractor ? 1 : fRunHeader->GetScale();
+
+    ped    /= scale;
+    abOffs /= scale;
+
     // 5. Calculate the RMS from the Variance:
-    const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
+    const Double_t rms = var<0 ? 0 : TMath::Sqrt(var)/scale;
 
     // abOffs contains only half of the signal as ped.
@@ -834,11 +843,13 @@
     // multiplies by this number
 
+    // scale to 256
+    const UInt_t scale = fExtractor ? 1 : fRunHeader->GetScale();
+
     // 5. Scale the mean, variance and AB-noise to the number of pixels:
-    ped    /= napix;
-    var    /= napix;
-    abOffs /= napix;
+    ped    /= napix*scale;
+    abOffs /= napix*scale;
 
     // 6. Calculate the RMS from the Variance:
-    const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
+    const Double_t rms = var<0 ? 0 : TMath::Sqrt(var)/scale;
 
     // abOffs contains only half of the signal as ped.
@@ -887,11 +898,13 @@
     // multiplies by this number
 
+    // scale to 256
+    const UInt_t scale = fExtractor ? 1 : fRunHeader->GetScale();
+
     // 5. Scale the mean, variance and AB-noise to the number of pixels:
-    ped    /= nspix;
-    var    /= nspix;
-    abOffs /= nspix;
+    ped    /= nspix*scale;
+    abOffs /= nspix*scale;
 
     // 6. Calculate the RMS from the Variance:
-    const Double_t rms = var<0 ? 0 : TMath::Sqrt(var);
+    const Double_t rms = var<0 ? 0 : TMath::Sqrt(var)/scale;
 
     // abOffs contains only half of the signal as ped.
@@ -947,4 +960,5 @@
     *fLog << "CheckWindow from slice " << fCheckWinFirst   << " to " << fCheckWinLast << " incl." << endl;
     *fLog << "Max.allowed signal variation: " << fMaxSignalVar << endl;
+    *fLog << "Max.allowed signal absolute:  " << fMaxSignalAbs << endl;
 }
 
@@ -1020,4 +1034,11 @@
     }
 
+    if (IsEnvDefined(env, prefix, "MaxSignalAbs", print))
+    {
+        SetMaxSignalAbs(GetEnvValue(env, prefix, "MaxSignalAbs", fMaxSignalAbs));
+        rc = kTRUE;
+    }
+
+    // find resource for MPedestalCam
     if (IsEnvDefined(env, prefix, "NamePedestalCamInter", print))
     {
@@ -1034,3 +1055,2 @@
     return rc;
 }
-
Index: trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.h
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.h	(revision 8563)
+++ trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.h	(revision 8564)
@@ -24,4 +24,7 @@
 class MRawEvtPixelIter;
 
+//typedef UShort_t USample_t;
+typedef Byte_t USample_t;
+
 class MExtractPedestal : public MTask
 {
@@ -33,4 +36,5 @@
   static const UShort_t fgCheckWinLast;     //! Last FADC slice to check for signal  (currently set to: 29)
   static const UShort_t fgMaxSignalVar;     //! The maximum difference between the highest and lowest slice
+  static const UShort_t fgMaxSignalAbs;     //! The maximum absolte slice
 
   TString fNamePedestalCamOut;       // Name of the outgoing 'MPedestalCam' container
@@ -64,4 +68,5 @@
 
   UShort_t fMaxSignalVar;
+  UShort_t fMaxSignalAbs;
 
   Bool_t  fUseSpecialPixels;         // Flag if the special pixels shall be treated
@@ -125,5 +130,6 @@
   virtual Bool_t SetRangeFromExtractor(const MExtractor &ext) = 0;
 
-  void SetMaxSignalVar(UShort_t maxvar=40)  { fMaxSignalVar = maxvar;    }
+  void SetMaxSignalVar(UShort_t maxvar=40)   { fMaxSignalVar = maxvar; }
+  void SetMaxSignalAbs(UShort_t maxabs=250)  { fMaxSignalAbs = maxabs; }
 
   // names
