Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 5562)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 5570)
@@ -180,5 +180,5 @@
 }
 
-Bool_t MJCalibrateSignal::ProcessFile(MPedestalCam &pedcam)
+Bool_t MJCalibrateSignal::ProcessFile(MPedestalCam &pedcamab, MPedestalCam &pedcam)
 {
     if (!fSequence.IsValid())
@@ -269,12 +269,4 @@
         *fLog << inf << "No Camera geometry found using default <MGeomCamMagic>" << endl;
 
-    //
-    // Switch off noise calculation
-    //
-    if (extractor1)
-        extractor1->SetNoiseCalculation(kFALSE);
-    if (extractor2)
-        extractor2->SetNoiseCalculation(kFALSE);
-
     // This is necessary for the case in which it is not in the files
     MBadPixelsCam badcam;
@@ -328,6 +320,11 @@
     MBadPixelsMerge        merge(&badpix);
 
-    MPedCalcFromLoGain     pedlo;
-    pedlo.SetPedestalUpdate(kTRUE);
+    MPedCalcFromLoGain     pedlo1("MPedCalcFromLoGainAB");
+    pedlo1.SetPedestalUpdate(kTRUE);
+    pedlo1.SetPedestalsOut(&pedcamab);
+
+    MPedCalcFromLoGain     pedlo2;
+    pedlo2.SetPedestalUpdate(kTRUE);
+    pedlo2.SetPedestalsIn(&pedcamab);
 
     if (extractor1)
@@ -335,5 +332,9 @@
         // FIXME: How to get the fixed value 15 automatically?
         const Float_t win = extractor1->GetNumHiGainSamples();
-        pedlo.SetExtractWindow(15, (UShort_t)TMath::Nint(win));
+        pedlo1.SetExtractWindow(15, (UShort_t)TMath::Nint(win));
+        pedlo2.SetExtractWindow(15, (UShort_t)TMath::Nint(win));
+
+        if (extractor1->InheritsFrom("MExtractTimeAndCharge"))
+            pedlo2.SetExtractor((MExtractTimeAndCharge*)extractor1);
     }
 
@@ -345,16 +346,26 @@
     MCalibrateData         calib;
     if (filetype==3)
+    {
         calib.SetCalibrationMode(MCalibrateData::kFfactor);
+        calib.SetPedestalFlag(MCalibrateData::kRun);
+    }
+    else
+    {
+        calib.SetPedestalCamMean(&pedcamab);
+        calib.SetPedestalFlag(MCalibrateData::kEvent);
+    }
+
     MCalibrateRelTimes     caltm;
     MBadPixelsCalc         bpcal;
     MBadPixelsTreat        treat;
 
-    MHCamEvent evt0(0, "PedestalFLG", "Pedestal from Lo Gain;;P [fadc/sl]");
-    MHCamEvent evt1(0, "Extra'd",     "Extracted Signal;;S [fadc/sl]");
-    MHCamEvent evt2(0, "PedPhot",     "Calibrated Pedestal;;P [\\gamma]");
-    MHCamEvent evt3(1, "PedRMS",      "Calibrated Pedestal RMS;;\\sigma_{p} [\\gamma]");
-    MHCamEvent evt4(0, "Interp'd",    "Interpolated Signal;;S [\\gamma]");
-    MHCamEvent evt5(2, "Unsuitable",  "Unsuitable event ratio;;%");
-    MHCamEvent evt6(0, "Times",       "Arrival Time;;T [slice]");
+    MHCamEvent evt0(0, "PedFLG",      "Pedestal from Lo Gain;;P [fadc/sl]");
+    MHCamEvent evt1(2, "PedRmsFLG",   "Pedestal RMS from Lo Gain;;\\sigma_{p} [fadc/sl]");
+    MHCamEvent evt2(0, "Extra'd",     "Extracted Signal;;S [fadc/sl]");
+    MHCamEvent evt3(0, "PedPhot",     "Calibrated Pedestal;;P [\\gamma]");
+    MHCamEvent evt4(1, "PedRMS",      "Calibrated Pedestal RMS;;\\sigma_{p} [\\gamma]");
+    MHCamEvent evt5(0, "Interp'd",    "Interpolated Signal;;S [\\gamma]");
+    MHCamEvent evt6(2, "Unsuitable",  "Unsuitable event ratio;;%");
+    MHCamEvent evt7(0, "Times",       "Arrival Time;;T [slice]");
     evt0.EnableVariance();
     evt1.EnableVariance();
@@ -362,13 +373,15 @@
     evt3.EnableVariance();
     evt4.EnableVariance();
-    evt6.EnableVariance();
-
-    MFillH fill0(&evt0, "MPedestalCam",        "FillPedestalFLG");
-    MFillH fill1(&evt1, "MExtractedSignalCam", "FillExtracted");
-    MFillH fill2(&evt2, "MPedPhotCam",         "FillPedPhot");
-    MFillH fill3(&evt3, "MPedPhotCam",         "FillPedRMS");
-    MFillH fill4(&evt4, "MCerPhotEvt",         "FillInterpolated");
-    MFillH fill5(&evt5, "MBadPixelsCam",       "FillUnsuitable");
-    MFillH fill6(&evt6, "MArrivalTime",        "FillTimes");
+    evt5.EnableVariance();
+    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, "MPedPhotCam",         "FillPedRMS");
+    MFillH fill5(&evt5, "MCerPhotEvt",         "FillInterpolated");
+    MFillH fill6(&evt6, "MBadPixelsCam",       "FillUnsuitable");
+    MFillH fill7(&evt7, "MArrivalTime",        "FillTimes");
 
     MWriteRootFile write(2, Form("%s{s/_D_/_Y_}", fPathOut.Data()), fOverwrite);
@@ -418,20 +431,27 @@
     tlist2.AddToList(&apply);
     tlist2.AddToList(&merge);
-    tlist2.AddToList(filetype==3 ? (MTask*)&pcopy : (MTask*)&pedlo);
+    if (filetype==3)
+        tlist2.AddToList(&pcopy);
+    else
+    {
+        tlist2.AddToList(&pedlo1);
+        tlist2.AddToList(&pedlo2);
+    }
     tlist2.AddToList(&fill0);
+    tlist2.AddToList(&fill1);
     if (extractor1)
         tlist2.AddToList(&taskenv1);
     if (extractor2)
         tlist2.AddToList(&taskenv2);
-    tlist2.AddToList(&fill1);
+    tlist2.AddToList(&fill2);
     tlist2.AddToList(&calib);
     tlist2.AddToList(&caltm);
-    tlist2.AddToList(&fill2);
+    tlist2.AddToList(&fill3);
     tlist2.AddToList(&bpcal);
     tlist2.AddToList(&treat);
-    tlist2.AddToList(&fill3);
     tlist2.AddToList(&fill4);
     tlist2.AddToList(&fill5);
     tlist2.AddToList(&fill6);
+    tlist2.AddToList(&fill7);
 
     // Setup List for Drive-tree
Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.h	(revision 5562)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.h	(revision 5570)
@@ -34,5 +34,5 @@
     MJCalibrateSignal(const char *name=NULL, const char *title=NULL);
 
-    Bool_t ProcessFile(MPedestalCam &cam);
+    Bool_t ProcessFile(MPedestalCam &camab, MPedestalCam &cam);
 
     ClassDef(MJCalibrateSignal, 0) // Tool to create a pedestal file (MPedestalCam)
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 5562)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 5570)
@@ -213,11 +213,11 @@
   SetUsePINDiode();
   
-  SetRelTimeCalibration( kFALSE );
-  SetDataCheck         ( kFALSE );
-  SetDebug             ( kFALSE );
-  SetIntensity         ( kFALSE );
-
-  SetNoStorage         ( kFALSE );
-  SetHistsStorage      ( kFALSE );
+  SetRelTimeCalibration();
+  SetDataCheck(kFALSE);
+  SetDebug(kFALSE);
+  SetIntensity(kFALSE);
+
+  SetNoStorage(kFALSE);
+  SetHistsStorage(kFALSE);
 }
 
@@ -1685,10 +1685,4 @@
 
     //
-    // Switch off noise calculation
-    //
-    fExtractor->SetNoiseCalculation(kFALSE);
-    fTimeExtractor->SetNoiseCalculation(kFALSE);
-
-    //
     // Setup more tasks and tasklist
     //
@@ -1718,5 +1712,5 @@
     
         if (IsRelTimes())
-          tlist.AddToList(&taskenv2);
+            tlist.AddToList(&taskenv2);
     }
     
@@ -1766,5 +1760,5 @@
 
     if (!WriteTasks(taskenv.GetTask(), taskenv2.GetTask()))
-      return kFALSE;
+        return kFALSE;
 
     // Execute first analysis
@@ -1908,35 +1902,44 @@
 Bool_t MJCalibration::WriteTasks(MTask *t1, MTask *t2) const
 {
-
-  if (IsNoStorage())
+    if (IsNoStorage())
+        return kTRUE;
+
+    if (fPathOut.IsNull())
+        return kTRUE;
+
+    const TString oname(GetOutputFile());
+
+    *fLog << inf << "Writing to file: " << oname << endl;
+
+    TFile file(oname, fOverwrite?"RECREATE":"NEW", "File created by MJCalibration", 9);
+    if (!file.IsOpen())
+    {
+        *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
+        return kFALSE;
+    }
+
+    if (t1)
+    {
+        *fLog << inf << " - Writing Task " << t1->GetName() << " [" << t1->ClassName() << "]..." << flush;
+        if (t1->Write()<=0)
+        {
+            *fLog << err << "Unable to write " << t1->GetName() << " to " << oname << endl;
+            return kFALSE;
+        }
+        *fLog << "ok." << endl;
+    }
+
+    if (t2)
+    {
+        *fLog << inf << " - Writing Task " << t2->GetName() << " [" << t2->ClassName() << "]..." << flush;
+        if (t2->Write()<=0)
+        {
+            *fLog << err << "Unable to write " << t2->GetName() << " to " << oname << endl;
+            return kFALSE;
+        }
+        *fLog << "ok." << endl;
+    }
+
     return kTRUE;
-
-  if (fPathOut.IsNull())
-    return kTRUE;
-  
-  const TString oname(GetOutputFile());
-
-  *fLog << inf << "Writing to file: " << oname << endl;
-  
-  TFile file(oname, fOverwrite?"RECREATE":"NEW", "File created by MJCalibration", 9);
-  if (!file.IsOpen())
-    {
-      *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
-      return kFALSE;
-    }
-  
-  if (t1 && t1->Write()<=0)
-    {
-      *fLog << err << "Unable to write " << t1->GetName() << " to " << oname << endl;
-      return kFALSE;
-    }
-  
-  if (t2 && t2->Write()<=0)
-    {
-      *fLog << err << "Unable to write " << t2->GetName() << " to " << oname << endl;
-      return kFALSE;
-    }
-  
-  return kTRUE;
 }
 
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 5562)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 5570)
@@ -151,16 +151,7 @@
 Bool_t MJPedestal::ReadPedestalCam()
 {
-    if (IsNoStorage())
-        return kFALSE;
-
     const TString fname = GetOutputFile();
 
-    if (gSystem->AccessPathName(fname, kFileExists))
-    {
-        *fLog << warn << "Input file " << fname << " doesn't exist, will create it." << endl;
-        return kFALSE;
-    }
-
-    *fLog << inf << "Reading from file: " << fname << endl;
+    *fLog << inf << "Reading pedestals from file: " << fname << endl;
 
     TFile file(fname, "READ");
@@ -198,5 +189,5 @@
     const TString fname = Form("%s/calib%06d.root",fPathIn.Data(), fSequence.GetSequence());
 
-    *fLog << inf << "Reading from file: " << fname << endl;
+    *fLog << inf << "Reading extractor from file: " << fname << endl;
 
     TFile file(fname, "READ");
@@ -213,5 +204,6 @@
         return NULL;
     }
-    return o ? (MExtractor*)o->Clone() : NULL;
+
+    return o ? (MExtractor*)o->Clone("ExtractSignal") : NULL;
 }
 
@@ -684,5 +676,5 @@
     if (fExtractor)
         delete fExtractor;
-    fExtractor = ext ? (MExtractor*)ext->Clone() : NULL;
+    fExtractor = ext ? (MExtractor*)ext->Clone(ext->GetName()) : NULL;
 }
 
@@ -721,5 +713,5 @@
     SetNoStorage(GetEnv("DisableOutput", IsNoStorage()));
 
-    MTaskEnv tenv;
+    MTaskEnv tenv("ExtractSignal");
     tenv.SetDefault(fExtractor);
 
@@ -737,4 +729,5 @@
 
     SetExtractor((MExtractor*)tenv.GetTask());
+
     return kTRUE;
 }
@@ -816,8 +809,6 @@
     }
 
-    //if (!CheckEnv())
-    //    return kFALSE;
-
-    CheckEnv();
+    if (!CheckEnv())
+        return kFALSE;
 
     // --------------------------------------------------------------------------------
@@ -944,4 +935,5 @@
     }
 
+    /*
     if (!fPathIn.IsNull())
     {
@@ -949,12 +941,5 @@
         fExtractor = 0;
     }
-
-    //
-    // Check that the extractor has the bit Noise Calculation() set which 
-    // means that the each "sliding" of the sliding window is not applied
-    //
-    if (fExtractor)
-        fExtractor->SetNoiseCalculation(fExtractorResolution);
-
+    */
     //
     // Execute the eventloop
