Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 8149)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 8154)
@@ -94,4 +94,5 @@
 #include "MFTriggerPattern.h"
 #include "MGeomApply.h"
+#include "MPedestalSubtract.h"
 //#include "MMcPedestalCopy.h"
 #include "MPointingPosCalc.h"
@@ -450,4 +451,8 @@
     MContinue conttp(&ftp, "ContTrigPattern");
 
+    // Create the pedestal subtracted raw-data
+    MPedestalSubtract pedsub;
+    pedsub.SetPedestalCam(&pedcamab);
+
     // Do signal and pedestal calculation
     MPedCalcFromLoGain     pedlo1("MPedCalcFundamental");
@@ -471,15 +476,30 @@
         extractor1->SetPedestals(&pedcamab);
 
+        // Setup to use the hi-gain extraction window in the lo-gain
+        // range (the start of the lo-gain range is added automatically
+        // by MPedCalcFromLoGain)
+        //
+        // The window size of the extractor is not yet initialized,
+        // so we have to stick to the extraction range
+        const Int_t f = extractor1->GetHiGainFirst();
+        const Int_t l = extractor1->GetHiGainLast();
+        const Int_t w = (l-f+1)&~1;
+
+        pedlo1.SetExtractWindow(f, w);
+
         if (extractor1->InheritsFrom("MExtractTimeAndCharge"))
         {
             pedlo2.SetExtractor((MExtractTimeAndCharge*)extractor1);
             pedlo3.SetExtractor((MExtractTimeAndCharge*)extractor1);
+            /*
             const Int_t win = ((MExtractTimeAndCharge*)extractor1)->GetWindowSizeHiGain();
             pedlo1.SetExtractWindow(15, win);
-            pedlo2.SetExtractWindow(15, win/*obsolete*/);
-            pedlo3.SetExtractWindow(15, win/*obsolete*/);
+            pedlo2.SetExtractWindow(15, win//obsolete//);
+            pedlo3.SetExtractWindow(15, win//obsolete//);
+            */
         }
         else
         {
+            /*
             // FIXME: How to get the fixed value 15 automatically?
             const Int_t f = (Int_t)(15.5+extractor1->GetHiGainFirst());
@@ -488,4 +508,8 @@
             pedlo2.SetExtractWindow(f, n);
             pedlo3.SetExtractWindow(f, n);
+            */
+            pedlo2.SetExtractWindow(f, w);
+            pedlo3.SetExtractWindow(f, w);
+
         }
     }
@@ -657,4 +681,5 @@
     tlist2.AddToList(&apply);
     tlist2.AddToList(&merge);
+    tlist2.AddToList(&pedsub);
     tlist2.AddToList(&pedlo1);
     tlist2.AddToList(&pedlo2);
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 8149)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 8154)
@@ -154,4 +154,5 @@
 #include "MRawFileRead.h"
 #include "MGeomApply.h"
+#include "MPedestalSubtract.h"
 #include "MTaskEnv.h"
 #include "MBadPixelsMerge.h"
@@ -1907,6 +1908,21 @@
     tlist.AddToList(&apply);
 
-    MPedCalcPedRun           pedcalc;
-    pedcalc.SetExtractWindow(fExtractor->GetHiGainFirst(),TMath::Nint(fExtractor->GetNumHiGainSamples()));
+    // Produce pedestal subtracted raw-data
+    MPedestalSubtract pedsub;
+    pedsub.SetPedestalCam(fExtractor->GetPedestals());
+    tlist.AddToList(&pedsub);
+
+    // Setup to use the hi-gain extraction window in the lo-gain
+    // range (the start of the lo-gain range is added automatically
+    // by MPedCalcFromLoGain)
+    //
+    // The window size of the extractor is not yet initialized,
+    // so we have to stick to the extraction range
+    const Int_t f = fExtractor->GetHiGainFirst();
+    const Int_t l = fExtractor->GetHiGainLast();
+    const Int_t w = (l-f+1)&~1;
+
+    MPedCalcPedRun pedcalc;
+    pedcalc.SetExtractWindow(f, w);
 
     if (IsIntensity())
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 8149)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 8154)
@@ -82,4 +82,5 @@
 #include "MRawEvtData.h"
 #include "MGeomApply.h"
+#include "MPedestalSubtract.h"
 #include "MTriggerPatternDecode.h"
 #include "MBadPixelsMerge.h"
@@ -1064,9 +1065,9 @@
     // 
     if (!fBadPixelsFile.IsNull())
-      {
+    {
         *fLog << inf << "Excluding: " << fBadPixelsFile << endl;
-        ifstream fin(fBadPixelsFile.Data());
-        fBadPixels.AsciiRead((istream&)fin);
-      }
+        ifstream fin(fBadPixelsFile);
+        fBadPixels.AsciiRead(fin);
+    }
 
     MGeomApply geomapl;
@@ -1074,5 +1075,5 @@
 
     MPedCalcPedRun pedcalc;
-    pedcalc.SetPedestalUpdate(kFALSE);
+    //pedcalc.SetPedestalUpdate(kFALSE);
 
     MPedCalcFromLoGain pedlogain;
@@ -1132,4 +1133,12 @@
         tlist.AddToList(&fillpul);
     }
+
+    // produce pedestal subtracted raw-data
+    MPedestalSubtract pedsub;
+    if (fExtractor && fExtractionType!=kFundamental)
+        pedsub.SetPedestalCam(&fPedestalCamIn);
+    else
+        pedsub.SetNamePedestalCam(""); // Only copy hi- and lo-gain together!
+    tlist.AddToList(&pedsub);
 
     // ----------------------------------------------------------------------
@@ -1186,38 +1195,35 @@
     if (fExtractor)
     {
-      fExtractor->SetPedestals(&fPedestalCamIn);
-
-      if (fExtractionType!=kFundamental)
+        fExtractor->SetPedestals(&fPedestalCamIn);
+
+        if (fExtractionType!=kFundamental)
         {
-          pedcalc.SetRandomCalculation(fExtractionType==kWithExtractorRndm);
-          pedlogain.SetRandomCalculation(fExtractionType==kWithExtractorRndm);
-          
-          pedcalc.SetExtractor((MExtractTimeAndCharge*)fExtractor);
-          pedlogain.SetExtractor((MExtractTimeAndCharge*)fExtractor);
+            pedcalc.SetRandomCalculation(fExtractionType==kWithExtractorRndm);
+            pedlogain.SetRandomCalculation(fExtractionType==kWithExtractorRndm);
+
+            pedcalc.SetExtractor((MExtractTimeAndCharge*)fExtractor);
+            pedlogain.SetExtractor((MExtractTimeAndCharge*)fExtractor);
         }
-      
-      if (fExtractor->InheritsFrom("MExtractTimeAndCharge"))
+        else
         {
-
-          const Float_t f = 0.1+fExtractor->GetHiGainFirst();
-          const Int_t win = ((MExtractTimeAndCharge*)fExtractor)->GetWindowSizeHiGain();
-          pedcalc.SetExtractWindow((Int_t)f, win);
-          pedlogain.SetExtractWindow((Int_t)(15+f), win);
-
+            // The window size of the extractor is not yet initialized,
+            // so we have to stick to the extraction range
+            const Int_t f = fExtractor->GetHiGainFirst();
+            const Int_t l = fExtractor->GetHiGainLast();
+            const Int_t w = (l-f+1)&~1;
+
+            // Setup to use the hi-gain extraction window in the lo-gain
+            // range (the start of the lo-gain range is added automatically
+            // by MPedCalcFromLoGain)
+            pedcalc.SetExtractWindow(f, w);
+            pedlogain.SetExtractWindow(f, w);
         }
-      else
+
+        if (!fExtractor->InheritsFrom("MExtractTimeAndCharge") && fExtractionType!=kFundamental)
         {
-          const Float_t f = 0.1+fExtractor->GetHiGainFirst();
-          const Float_t n = 0.1+fExtractor->GetNumHiGainSamples();
-          pedcalc.SetExtractWindow((Int_t)f, (Int_t)n);
-          pedlogain.SetExtractWindow((Int_t)(15+f), (Int_t)n);
-
-          if (fExtractionType!=kFundamental)
-            {
-              *fLog << inf;
-              *fLog << "Signal extractor doesn't inherit from MExtractTimeAndCharge..." << endl;
-              *fLog << " --> falling back to fundamental pedestal extraction." << endl;
-              fExtractionType=kFundamental;
-            }
+            *fLog << inf;
+            *fLog << "Signal extractor doesn't inherit from MExtractTimeAndCharge..." << endl;
+            *fLog << " --> falling back to fundamental pedestal extraction." << endl;
+            fExtractionType=kFundamental;
         }
     }
