Index: trunk/MagicSoft/Mars/msignal/MExtractor.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 8362)
+++ trunk/MagicSoft/Mars/msignal/MExtractor.cc	(revision 8364)
@@ -17,6 +17,7 @@
 !
 !   Author(s): Markus Gaug, 04/2004 <mailto:markus@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Author(s): Thomas Bretz <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2007
 !
 !
@@ -74,4 +75,9 @@
 //  - Byte_t fHiLoLast;                // Number of slices in fLoGainSamples counted for the High-Gain signal
 //
+// Class Version 8:
+// ----------------
+//  - Byte_t fSaturationLimit;
+//  + Uint_t fSaturationLimit;
+//
 //
 // Input Containers:
@@ -108,5 +114,5 @@
 using namespace std;
 
-const Byte_t  MExtractor::fgSaturationLimit = 245;
+const UInt_t  MExtractor::fgSaturationLimit = 245;
 const TString MExtractor::fgNamePedestalCam = "MPedestalCam";
 const TString MExtractor::fgNameSignalCam   = "MExtractedSignalCam";
@@ -255,8 +261,13 @@
     if (numl==0)
     {
-        *fLog << inf << "No lo-gains... resetting lo-gain range and saturation limit." << endl;
+        *fLog << inf << "No lo-gains... resetting lo-gain range";
         fLoGainFirst=0;
         fLoGainLast =0;
-        fSaturationLimit=0xff;
+        if (fSaturationLimit>0xff)
+        {
+            *fLog << " and saturation limit";
+            fSaturationLimit=0xff;
+        }
+        *fLog << "." << endl;
     }
 
@@ -443,5 +454,5 @@
     if (IsEnvDefined(env, prefix, "SaturationLimit", print))
     {
-        SetSaturationLimit(GetEnvValue(env, prefix, "SaturationLimit", fSaturationLimit));
+        SetSaturationLimit(GetEnvValue(env, prefix, "SaturationLimit", (Int_t)fSaturationLimit));
         rc = kTRUE;
     }
Index: trunk/MagicSoft/Mars/msignal/MExtractor.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractor.h	(revision 8362)
+++ trunk/MagicSoft/Mars/msignal/MExtractor.h	(revision 8364)
@@ -32,5 +32,5 @@
   
 protected:
-  static const Byte_t  fgSaturationLimit;  //! Default for fSaturationLimit (now set to: 254)
+  static const UInt_t  fgSaturationLimit;  //! Default for fSaturationLimit (now set to: 254)
   static const TString fgNamePedestalCam;  //! "MPedestalCam"
   static const TString fgNameSignalCam;    //! "MExtractedSignalCam"
@@ -59,5 +59,5 @@
   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
+  UInt_t   fSaturationLimit;               // Highest FADC slice value until being declared saturated
 
   TString  fNamePedestalCam;               // Name of the 'MPedestalCam' container
@@ -94,5 +94,5 @@
   Float_t GetResolutionPerPheHiGain() const { return fResolutionPerPheHiGain; }
   Float_t GetResolutionPerPheLoGain() const { return fResolutionPerPheLoGain; }
-  Byte_t  GetSaturationLimit() const { return fSaturationLimit; }
+  UInt_t  GetSaturationLimit() const { return fSaturationLimit; }
 
   Bool_t  HasLoGain() const { return fLoGainFirst>0 || fLoGainLast>0; }
@@ -106,5 +106,5 @@
 
   void SetOffsetLoGain    ( const Float_t  f=fgOffsetLoGain          ) { fOffsetLoGain     = f;    }
-  void SetSaturationLimit ( const Byte_t lim=fgSaturationLimit       ) { fSaturationLimit  = lim;  }
+  void SetSaturationLimit ( const UInt_t lim=fgSaturationLimit       ) { fSaturationLimit  = lim;  }
   void SetNamePedestalCam ( const char *name=fgNamePedestalCam.Data()) { fNamePedestalCam  = name; }
   void SetNameSignalCam   ( const char *name=fgNameSignalCam.Data()  ) { fNameSignalCam    = name; }
@@ -122,5 +122,5 @@
   void Print(Option_t *o="") const; //*MENU*
 
-  ClassDef(MExtractor, 7) // Signal Extractor Base Class
+  ClassDef(MExtractor, 8) // Signal Extractor Base Class
 };
 
Index: trunk/MagicSoft/Mars/msignal/MSignalCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MSignalCalc.cc	(revision 8362)
+++ trunk/MagicSoft/Mars/msignal/MSignalCalc.cc	(revision 8364)
@@ -46,9 +46,9 @@
 
 #include "MRawRunHeader.h"
-#include "MRawEvtData.h"       // MRawEvtData::GetNumPixels
 #include "MSignalCam.h"
 #include "MPedestalPix.h"
 #include "MPedestalCam.h"
 #include "MRawEvtPixelIter.h"
+#include "MPedestalSubtractedEvt.h"
 
 ClassImp(MSignalCalc);
@@ -66,9 +66,4 @@
     fName  = name  ? name  : "MSignalCalc";
     fTitle = title ? title : "Task to calculate Cerenkov photons from raw data";
-
-    AddToBranchList("MRawEvtData.fHiGainPixId");
-    AddToBranchList("MRawEvtData.fLoGainPixId");
-    AddToBranchList("MRawEvtData.fHiGainFadcSamples");
-    AddToBranchList("MRawEvtData.fLoGainFadcSamples");
 }
 
@@ -95,8 +90,8 @@
     }
 
-    fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
+    fRawEvt = (MPedestalSubtractedEvt*)pList->FindObject("MPedestalSubtractedEvt");
     if (!fRawEvt)
     {
-        *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
+        *fLog << dbginf << "MPedestalSubtractedEvt not found... aborting." << endl;
         return kFALSE;
     }
@@ -130,13 +125,18 @@
 // pixel in the MSignalCam container.
 //
+#include <TSystem.h>
 Int_t MSignalCalc::Process()
 {
-    MRawEvtPixelIter pixel(fRawEvt);
-
-    while (pixel.Next())
+    const Int_t npix = fRawEvt->GetNumPixels();
+    const Int_t nhi  = fRunHeader->GetNumSamplesHiGain();
+    const Int_t nlo  = fRunHeader->GetNumSamplesLoGain();
+
+    for (int i=0; i<npix; i++)
     {
-        Byte_t *ptr   = pixel.GetHiGainSamples();
-        Byte_t *max   = ptr+pixel.GetIdxMaxHiGainSample();
-	Byte_t *end   = ptr+fRunHeader->GetNumSamplesHiGain();
+        Byte_t *raw = fRawEvt->GetSamplesRaw(i);
+
+        Byte_t *ptr   = raw;
+        Byte_t *max   = ptr+fRawEvt->GetMax(i, 0, nhi);
+	Byte_t *end   = ptr+nhi;
         Byte_t *first = max-fBefore;
         Byte_t *last  = max+fAfter;
@@ -144,5 +144,5 @@
         ULong_t sumb  = 0;   // sum background
         ULong_t sqb   = 0;   // sum sqares background
-        ULong_t sumsb = 0;   // sum signal+background
+        //ULong_t sumsb = 0;   // sum signal+background
         ULong_t sqsb  = 0;   // sum sqares signal+background
 
@@ -168,5 +168,5 @@
             else
             {
-                sumsb += *ptr;
+                //sumsb += *ptr;
                 sqsb  += *ptr* *ptr;
                 nsb++;
@@ -175,9 +175,9 @@
         }
 
-        if (sat==0 && ishi)
+        if (nlo>0 && sat==0 && ishi)
         {
             // Area: x9
-            ptr = pixel.GetLoGainSamples();
-            end = ptr+fRunHeader->GetNumSamplesLoGain();
+            ptr = raw+nhi;
+            end = ptr+nlo;
 
             sumb = 0;   // sum background
@@ -187,5 +187,5 @@
             while (ptr<end)
             {
-                // Background already calced from hi-gains!
+                // Background already caced from hi-gains!
                 sumb += *ptr;
                 sqb  += *ptr* *ptr;
@@ -195,9 +195,9 @@
         }
 
-        if (sat>1 && !ishi)
+        if (nlo>0 && sat>1 && !ishi)
         {
             // Area: x9
-            ptr = pixel.GetLoGainSamples();
-            max = ptr+pixel.GetIdxMaxLoGainSample();
+            ptr = raw+nhi;
+            max = ptr+fRawEvt->GetMax(i, nhi, nhi+nlo);
 
             if (*max>250)
@@ -207,11 +207,11 @@
             }
 
-            end   = ptr+fRunHeader->GetNumSamplesLoGain();
+            end   = ptr+nlo;
             first = max-fBefore;
             last  = max+fAfter;
 
-            sumsb = 0;   // sum signal+background
-            sqsb  = 0;   // sum sqares signal+background
-            //sumb  = 0;   // sum background
+            //sumsb = 0;   // sum signal+background
+            //sqsb  = 0;   // sum sqares signal+background
+            sumb  = 0;   // sum background
             //sqb   = 0;   // sum sqares background
 
@@ -230,5 +230,5 @@
                 else
                 {
-                    sumsb += *ptr;
+                    //sumsb += *ptr;
                     sqsb  += *ptr* *ptr;
                     nsb++;
@@ -238,8 +238,8 @@
         }
 
-        Float_t b  = (float)sumb/nb;       // background
-        Float_t sb = (float)sumsb/nsb;     // signal+background
-
-        Float_t msb  = (float)sqb/nb;      // mean square background
+        Float_t b  = nb==0 ? 0 : (float)sumb/nb;       // background
+        //Float_t sb = (float)sumsb/nsb;     // signal+background
+
+        Float_t msb  = nb==0 ? 0 : (float)sqb/nb;      // mean square background
         //Float_t mssb = (float)sqsb/nsb;    // mean square signal+background
 
@@ -247,5 +247,5 @@
         //Float_t sigsb = sqrt(mssb-sb*sb);  // sigma signal+background
 
-        Float_t s   = sb-b;                // signal
+        //Float_t s   = sb-b;                // signal
         //Float_t sqs = sqsb-nsb*b;          // sum squares signal
 
@@ -253,8 +253,7 @@
         //Float_t sigs = sqrt(mss-s*s);      // sigma signal
 
-        if (sat>1)
-            s *= 11.3;
-
-        Int_t idx = pixel.GetPixelId();
+        //if (sat>1)
+        //    s *= 11.3;
+
         //fCerPhotEvt->AddPixel(idx, s, sigs);
 
@@ -262,5 +261,5 @@
         // MMcPedestalCopy and MMcPedestalNSBAdd
         if (fPedestals)
-            (*fPedestals)[idx].Set(b, sigb);
+            (*fPedestals)[i].Set(b, sigb);
     }
 
Index: trunk/MagicSoft/Mars/msignal/MSignalCalc.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MSignalCalc.h	(revision 8362)
+++ trunk/MagicSoft/Mars/msignal/MSignalCalc.h	(revision 8364)
@@ -6,16 +6,16 @@
 #endif
 
-class MRawEvtData;
 class MPedestalCam;
 class MSignalCam;
 class MRawRunHeader;
+class MPedestalSubtractedEvt;
 
 class MSignalCalc : public MTask
 {
 private:
-    MPedestalCam  *fPedestals;  // Pedestals of all pixels in the camera
-    MRawEvtData   *fRawEvt;     // raw event data (time slices)
-    MSignalCam    *fCerPhotEvt; // Cerenkov Photon Event used for calculation
-    MRawRunHeader *fRunHeader;  // RunHeader information
+    MRawRunHeader          *fRunHeader;  // RunHeader information
+    MPedestalSubtractedEvt *fRawEvt;     // raw event data (time slices)
+    MSignalCam             *fCerPhotEvt; // Cerenkov Photon Event used for calculation
+    MPedestalCam           *fPedestals;  // Pedestals of all pixels in the camera
 
     Byte_t fBefore;
