Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 5742)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 5760)
@@ -180,5 +180,5 @@
 }
 
-Bool_t MJCalibrateSignal::ProcessFile(MPedestalCam &pedcamab, MPedestalCam &pedcam)
+Bool_t MJCalibrateSignal::ProcessFile(MPedestalCam &pedcamab, MPedestalCam &pedcam2/*, MPedestalCam &pedcam*/)
 {
     if (!fSequence.IsValid())
@@ -276,5 +276,4 @@
     plist.AddToList(this); // take care of fDisplay!
     plist.AddToList(&badcam);
-    plist.AddToList(&pedcam);
     plist.AddToList(&calibcont);
 
@@ -323,11 +322,28 @@
     MBadPixelsMerge        merge(&badpix);
 
-    MPedCalcFromLoGain     pedlo1("MPedCalcMeanFromLoGain");
+    // Make sure that pedcamab has the correct name
+    pedcamab.SetName("MPedestalFundamental");
+    //pedcam.SetName("MPedestalFromExtractorRndm");
+    pedcam2.SetName("MPedestalFromExtractor");
+    //plist.AddToList(&pedcam);
+    plist.AddToList(&pedcam2);
+    plist.AddToList(&pedcamab);
+
+    MPedCalcFromLoGain     pedlo1("MPedCalcFundamental");
     pedlo1.SetPedestalUpdate(kTRUE);
-    pedlo1.SetPedestalsOut(&pedcamab);
-
-    MPedCalcFromLoGain     pedlo2("MPedCalcRmsFromLoGain");
-    pedlo2.SetPedestalUpdate(kTRUE);
-    pedlo2.SetPedestalsIn(&pedcamab);
+    pedlo1.SetNamePedestalCamOut("MPedestalFundamental");
+    /*
+     MPedCalcFromLoGain     pedlo2("MPedCalcWithExtractorRndm");
+     pedlo2.SetPedestalUpdate(kTRUE);
+     pedlo2.SetRandomCalculation(kTRUE);
+     pedlo2.SetNamePedestalCamIn("MPedestalFundamental");
+     pedlo2.SetNamePedestalCamOut("MPedestalFromExtractorRndm");
+     */
+
+    MPedCalcFromLoGain     pedlo3("MPedCalcWithExtractor");
+    pedlo3.SetPedestalUpdate(kTRUE);
+    pedlo3.SetRandomCalculation(kFALSE);
+    pedlo3.SetNamePedestalCamIn("MPedestalFundamental");
+    pedlo3.SetNamePedestalCamOut("MPedestalFromExtractor");
 
     if (extractor1)
@@ -336,9 +352,11 @@
         const Float_t win = extractor1->GetNumHiGainSamples();
         pedlo1.SetExtractWindow(15, (UShort_t)TMath::Nint(win));
-        pedlo2.SetExtractWindow(15, (UShort_t)TMath::Nint(win));
+        //pedlo2.SetExtractWindow(15, (UShort_t)TMath::Nint(win));
+        pedlo3.SetExtractWindow(15, (UShort_t)TMath::Nint(win));
 
         if (extractor1->InheritsFrom("MExtractTimeAndCharge"))
         {
-            pedlo2.SetExtractor((MExtractTimeAndCharge*)extractor1);
+            //pedlo2.SetExtractor((MExtractTimeAndCharge*)extractor1);
+            pedlo3.SetExtractor((MExtractTimeAndCharge*)extractor1);
             extractor1->SetPedestals(&pedcamab);
         }
@@ -355,9 +373,14 @@
         calib.SetCalibrationMode(MCalibrateData::kFfactor);
         calib.SetPedestalFlag(MCalibrateData::kRun);
+        // FIXME: What to do for MC files???
+        calib.AddPedestal("MPedestalCam", "MPedPhotFundamental");
+        calib.AddPedestal("MPedestalCam", "MPedPhotFromExtractor");
+        //calib.AddPedestal("MPedestalCam", "MPedPhotFromExtractorRndm");
     }
     else
     {
-        calib.AddPedestal("MPedestalCam", "MPedPhotFromExtractorRndm");
         calib.AddPedestal("Fundamental");
+        calib.AddPedestal("FromExtractor");
+        //calib.AddPedestal("FromExtractorRndm");
         calib.SetPedestalFlag(MCalibrateData::kEvent);
     }
@@ -366,4 +389,10 @@
     MBadPixelsCalc         bpcal;
     MBadPixelsTreat        treat;
+
+    bpcal.SetNamePedPhotCam("MPedPhotFromExtractor");
+    treat.AddNamePedPhotCam("MPedPhotFundamental");
+    treat.AddNamePedPhotCam("MPedPhotFromExtractor");
+    //treat.AddNamePedPhotCam("MPedPhotFromExtractorRndm");
+
 
     MHCamEvent evt0(0, "PedFLG",      "Pedestal from Lo Gain;;P [fadc/sl]");
@@ -383,56 +412,57 @@
     evt7.EnableVariance();
 
-    MFillH fill0(&evt0, &pedcamab,             "FillPedFLG");
-    MFillH fill1(&evt1, "MPedestalCam",        "FillPedRmsFLG");
-    MFillH fill2(&evt2, "MExtractedSignalCam", "FillExtracted");
-    MFillH fill3(&evt3, "MPedPhotCam",         "FillPedPhot");
-    MFillH fill4(&evt4, "MPedPhotFromExtractorRndm", "FillPedRMS");
-    MFillH fill5(&evt5, "MCerPhotEvt",         "FillInterpolated");
-    MFillH fill6(&evt6, "MBadPixelsCam",       "FillUnsuitable");
-    MFillH fill7(&evt7, "MArrivalTime",        "FillTimes");
+    MFillH fill0(&evt0, "MPedestalFundamental",   "FillPedFLG");
+    MFillH fill1(&evt1, "MPedestalFromExtractor", "FillPedRmsFLG");
+    MFillH fill2(&evt2, "MExtractedSignalCam",    "FillExtracted");
+    MFillH fill3(&evt3, "MPedPhotFundamental",    "FillPedPhot");
+    MFillH fill4(&evt4, "MPedPhotFromExtractor",  "FillPedRMS");
+    MFillH fill5(&evt5, "MCerPhotEvt",            "FillInterpolated");
+    MFillH fill6(&evt6, "MBadPixelsCam",          "FillUnsuitable");
+    MFillH fill7(&evt7, "MArrivalTime",           "FillTimes");
 
     // The second rule is for the case reading raw-files!
     MWriteRootFile write(2, Form("%s{s/_D_/_Y_}{s/.raw$/.root}", fPathOut.Data()), fOverwrite);
     // Run Header
-    write.AddContainer("MRawRunHeader",       "RunHeaders");
-    write.AddContainer("MBadPixelsCam",       "RunHeaders");
-    write.AddContainer("MGeomCam",            "RunHeaders");
+    write.AddContainer("MRawRunHeader",             "RunHeaders");
+    write.AddContainer("MBadPixelsCam",             "RunHeaders");
+    write.AddContainer("MGeomCam",                  "RunHeaders");
     // Monte Carlo Headers
-    write.AddContainer("MMcTrigHeader",       "RunHeaders", kFALSE);
-    write.AddContainer("MMcConfigRunHeader",  "RunHeaders", kFALSE);
-    write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
+    write.AddContainer("MMcTrigHeader",             "RunHeaders", kFALSE);
+    write.AddContainer("MMcConfigRunHeader",        "RunHeaders", kFALSE);
+    write.AddContainer("MMcCorsikaRunHeader",       "RunHeaders", kFALSE);
     // Monte Carlo
-    write.AddContainer("MMcEvt",              "Events", kFALSE);
-    write.AddContainer("MMcTrig",             "Events", kFALSE);
+    write.AddContainer("MMcEvt",                    "Events",     kFALSE);
+    write.AddContainer("MMcTrig",                   "Events",     kFALSE);
     // Data
-    write.AddContainer("MCerPhotEvt",         "Events");
-    write.AddContainer("MPedPhotCam",         "Events");
-    write.AddContainer("MPedPhotFromExtractorRndm", "Events");
-    write.AddContainer("MTime",               "Events", kFALSE);
-    write.AddContainer("MRawEvtHeader",       "Events");
-    write.AddContainer("MArrivalTime",        "Events");
+    write.AddContainer("MCerPhotEvt",               "Events");
+    write.AddContainer("MPedPhotFundamental",       "Events");
+    write.AddContainer("MPedPhotFromExtractor",     "Events");
+    //write.AddContainer("MPedPhotFromExtractorRndm", "Events");
+    write.AddContainer("MTime",                     "Events",     kFALSE);
+    write.AddContainer("MRawEvtHeader",             "Events");
+    write.AddContainer("MArrivalTime",              "Events");
     // Slow-Control: Current
-    write.AddContainer("MTimeCurrents",       "Currents", kFALSE);
-    write.AddContainer("MCameraDC",           "Currents", kFALSE);
-    write.AddContainer("MReportCurrents",     "Currents", kFALSE);
+    write.AddContainer("MTimeCurrents",             "Currents",   kFALSE);
+    write.AddContainer("MCameraDC",                 "Currents",   kFALSE);
+    write.AddContainer("MReportCurrents",           "Currents",   kFALSE);
     // Slow-Control: Camera
-    write.AddContainer("MReportCamera",       "Camera", kFALSE);
-    write.AddContainer("MTimeCamera",         "Camera", kFALSE);
-    write.AddContainer("MCameraAUX",          "Camera", kFALSE);
-    write.AddContainer("MCameraCalibration",  "Camera", kFALSE);
-    write.AddContainer("MCameraCooling",      "Camera", kFALSE);
-    write.AddContainer("MCameraHV",           "Camera", kFALSE);
-    write.AddContainer("MCameraLV",           "Camera", kFALSE);
-    write.AddContainer("MCameraLids",         "Camera", kFALSE);
+    write.AddContainer("MReportCamera",             "Camera",     kFALSE);
+    write.AddContainer("MTimeCamera",               "Camera",     kFALSE);
+    write.AddContainer("MCameraAUX",                "Camera",     kFALSE);
+    write.AddContainer("MCameraCalibration",        "Camera",     kFALSE);
+    write.AddContainer("MCameraCooling",            "Camera",     kFALSE);
+    write.AddContainer("MCameraHV",                 "Camera",     kFALSE);
+    write.AddContainer("MCameraLV",                 "Camera",     kFALSE);
+    write.AddContainer("MCameraLids",               "Camera",     kFALSE);
     // Slow-Control: Trigger
-    write.AddContainer("MReportTrigger",      "Trigger", kFALSE);
-    write.AddContainer("MTimeTrigger",        "Trigger", kFALSE);
+    write.AddContainer("MReportTrigger",            "Trigger",    kFALSE);
+    write.AddContainer("MTimeTrigger",              "Trigger",    kFALSE);
     // Slow-Control: Drive
-    write.AddContainer("MPointingPos",        "Drive", kFALSE);
-    write.AddContainer("MReportDrive",        "Drive", kFALSE);
-    write.AddContainer("MTimeDrive",          "Drive", kFALSE);
+    write.AddContainer("MPointingPos",              "Drive",      kFALSE);
+    write.AddContainer("MReportDrive",              "Drive",      kFALSE);
+    write.AddContainer("MTimeDrive",                "Drive",      kFALSE);
     // Slow-Control: Central Control
-    write.AddContainer("MReportCC",           "CC", kFALSE);
-    write.AddContainer("MTimeCC",             "CC", kFALSE);
+    write.AddContainer("MReportCC",                 "CC",         kFALSE);
+    write.AddContainer("MTimeCC",                   "CC",         kFALSE);
 
     // Now setup tasklist for events
@@ -445,5 +475,6 @@
     {
         tlist2.AddToList(&pedlo1);
-        tlist2.AddToList(&pedlo2);
+        //tlist2.AddToList(&pedlo2);
+        tlist2.AddToList(&pedlo3);
     }
     tlist2.AddToList(&fill0);
Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.h	(revision 5742)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.h	(revision 5760)
@@ -34,5 +34,5 @@
     MJCalibrateSignal(const char *name=NULL, const char *title=NULL);
 
-    Bool_t ProcessFile(MPedestalCam &camab, MPedestalCam &cam);
+    Bool_t ProcessFile(MPedestalCam &camab, MPedestalCam &cam2/*, MPedestalCam &cam2*/);
 
     ClassDef(MJCalibrateSignal, 0) // Tool to create a pedestal file (MPedestalCam)
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 5742)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 5760)
@@ -1563,4 +1563,5 @@
     // Input containers
     //
+    pedcam.SetName("MPedestalCam");
     plist.AddToList(&pedcam);
     plist.AddToList(&fBadPixels);
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 5742)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 5760)
@@ -113,5 +113,5 @@
 MJPedestal::MJPedestal(const char *name, const char *title) 
     : fRuns(0), fExtractor(NULL), fDisplayType(kNormalDisplay),
-      fDataCheck(kFALSE), fExtractType(kUsePedRun)
+      fDataCheck(kFALSE), fExtractType(kUsePedRun), fExtractionType(kFundamental)
 {
     fName  = name  ? name  : "MJPedestal";
@@ -121,5 +121,4 @@
     SetUsePedRun();
     SetPathIn("");
-    SetExtractorResolution(kFALSE);
 }
 
@@ -298,5 +297,5 @@
       }
     
-    if (fExtractorResolution)
+    if (fExtractionType!=kFundamental/*fExtractorResolution*/)
       {
         for (UInt_t i=0;i<geomcam.GetNumPixels();i++)
@@ -338,5 +337,5 @@
     // Display data
     //
-    if (fDisplayType != kDataCheckDisplay && fExtractType != kUseHists && !fExtractorResolution)
+    if (fDisplayType != kDataCheckDisplay && fExtractType != kUseHists && fExtractionType==kFundamental/*fExtractorResolution*/)
       {
         TCanvas &c3 = fDisplay->AddTab("Pedestals");
@@ -381,5 +380,5 @@
       {
 
-        TCanvas &c3 = fDisplay->AddTab(fExtractorResolution ? "PedExtrd" : "Ped");
+        TCanvas &c3 = fDisplay->AddTab(fExtractionType!=kFundamental/*fExtractorResolution*/ ? "PedExtrd" : "Ped");
         c3.Divide(2,3);
         
@@ -391,5 +390,5 @@
         // for the datacheck, fix the ranges!!
         //
-        if (!fExtractorResolution)
+        if (fExtractionType==kFundamental/*!fExtractorResolution*/)
           {
             obj1->SetMinimum(fgPedestalMin);
@@ -535,5 +534,5 @@
       }
     
-    if (fExtractorResolution)
+    if (fExtractionType!=kFundamental/*fExtractorResolution*/)
       {
             
@@ -674,7 +673,12 @@
 void MJPedestal::SetExtractor(MExtractor* ext)
 {
-    if (fExtractor)
-        delete fExtractor;
-    fExtractor = ext ? (MExtractor*)ext->Clone(ext->GetName()) : NULL;
+    if (ext)
+    {
+        if (fExtractor)
+            delete fExtractor;
+        fExtractor = ext ? (MExtractor*)ext->Clone(ext->GetName()) : NULL;
+    }
+    else
+        fExtractor = 0;
 }
 
@@ -709,5 +713,5 @@
             fExtractType = kUseHists;
 
-    SetExtractorResolution(GetEnv("ExtractorResolution", fExtractorResolution));
+    //fExtractorResolution = GetEnv("ExtractionType", fExtractorResolution);
 
     SetNoStorage(GetEnv("DisableOutput", IsNoStorage()));
@@ -784,9 +788,10 @@
         return kTRUE;
 
-    if (!fExtractorResolution || !fExtractor->InheritsFrom("MExtractTimeAndCharge"))
+    if (fExtractionType==kFundamental || !fExtractor->InheritsFrom("MExtractTimeAndCharge"))
         return kFALSE;
 
     extped.SetPedestalsIn(&fPedestalCamIn);
     extped.SetExtractor((MExtractTimeAndCharge*)fExtractor);
+    extped.SetRandomCalculation(fExtractionType==kWithExtractorRndm);
 
     return kTRUE;
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.h	(revision 5742)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.h	(revision 5760)
@@ -59,5 +59,6 @@
     Extract_t fExtractType;                              // Chosen extractor type
 
-    Bool_t fExtractorResolution;                         // Flag if the extractor is used to calculate the pedestals
+    enum Extraction { kFundamental, kWithExtractorRndm, kWithExtractor };
+    Int_t fExtractionType;                         // Flag if the extractor is used to calculate the pedestals
 
     MExtractor *ReadCalibration() const;
@@ -102,5 +103,8 @@
     void SetDataCheckDisplay()                  { fDisplayType = kDataCheckDisplay; }
     void SetNormalDisplay()                     { fDisplayType = kNormalDisplay;    }
-    void SetExtractorResolution(const Bool_t b=kTRUE) { fExtractorResolution = b;  }
+
+    void SetExtractionFundamental()       { fExtractionType=kFundamental; }
+    void SetExtractionWithExtractorRndm() { fExtractionType=kWithExtractorRndm; }
+    void SetExtractionWithExtractor()     { fExtractionType=kWithExtractor; }
 
     MExtractor *GetExtractor() const { return fExtractor; }
Index: trunk/MagicSoft/Mars/mjobs/MJStar.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJStar.cc	(revision 5742)
+++ trunk/MagicSoft/Mars/mjobs/MJStar.cc	(revision 5760)
@@ -185,5 +185,7 @@
  */
     //MBadPixelsMerge        merge(&badpix);
-    MImgCleanStd           clean; 
+    MImgCleanStd           clean;
+    clean.SetNamePedPhotCam("MPedPhotFromExtractor");
+
     MHillasCalc            hcalc;
 
