Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 3722)
+++ trunk/MagicSoft/Mars/Changelog	(revision 3723)
@@ -36,4 +36,5 @@
 
    * mjobs/MJPedestals.cc
+   * mjobs/MJCalibration.cc
      - replaced MBadPixelsMerge by MParList.AddToList(fBadPixels) until 
        bug in MBadPixelsMerge is resolved (see bugtracker).
@@ -49,4 +50,7 @@
      - pointer to fSig is not stored, somehow, when running MJCalibration
        Don't know why. Removed and stored some variables instead
+
+   * mjobs/MJCalibration.cc
+     - updated documentation, updated QE Cam
 
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationQEPix.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationQEPix.h	(revision 3722)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationQEPix.h	(revision 3723)
@@ -122,8 +122,8 @@
 
   // Setters 
-  void SetAverageQEBlindPixelAvailable   ( const Bool_t b );
-  void SetAverageQECombinedAvailable     ( const Bool_t b );
-  void SetAverageQEFFactorAvailable      ( const Bool_t b );
-  void SetAverageQEPINDiodeAvailable     ( const Bool_t b );
+  void SetAverageQEBlindPixelAvailable   ( const Bool_t b=kTRUE );
+  void SetAverageQECombinedAvailable     ( const Bool_t b=kTRUE );
+  void SetAverageQEFFactorAvailable      ( const Bool_t b=kTRUE );
+  void SetAverageQEPINDiodeAvailable     ( const Bool_t b=kTRUE );
   void SetBlindPixelMethodValid          ( const Bool_t b, const MCalibrationCam::PulserColor_t col);
   void SetCombinedMethodValid            ( const Bool_t b, const MCalibrationCam::PulserColor_t col);
Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationCam.cc	(revision 3722)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationCam.cc	(revision 3723)
@@ -400,4 +400,5 @@
   if (!fBadPixels)
     {
+
       fBadPixels = (MBadPixelsCam*)pList->FindCreateObj(AddSerialNumber("MBadPixelsCam"));
       if (!fBadPixels)
@@ -547,5 +548,5 @@
   if (bad.IsBad())
     hist.SetExcluded();
-
+  
   hist.InitBins();
   hist.ChangeHistId(i);
Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.cc	(revision 3722)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.cc	(revision 3723)
@@ -424,4 +424,6 @@
   fBlindPix->SetOscillating  ( !IsFourierSpectrumOK() );
 
+  fBlindPix->SetValid(kTRUE);
+
   fMeanPedestal     = fSignal->GetPed();
   fMeanPedestalErr  = fSignal->GetPedErr();
@@ -437,7 +439,9 @@
 
   FitPedestal();
-  
+
   if (FitSinglePhe())
-      fBlindPix->SetSinglePheFitOK();
+    fBlindPix->SetSinglePheFitOK();
+  else
+    fBlindPix->SetValid(kFALSE);
 
   fBlindPix->SetLambda      (    fLambda               );
Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationChargePINDiode.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationChargePINDiode.cc	(revision 3722)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationChargePINDiode.cc	(revision 3723)
@@ -284,4 +284,6 @@
   fPINDiode->SetRmsChargeSigmaErr( GetRmsChargeSigmaErr()    );
 
+  fPINDiode->SetValid(kTRUE);
+
   const Byte_t  loweredge  = fSigPIN->GetFirstUsedSlice();
   const Byte_t  upperedge  = fSigPIN->GetLastUsedSlice();
@@ -291,16 +293,18 @@
   if (GetAbsTimeMean() < lowerlimit)
     {
-      *fLog << warn << GetDescriptor() << ": Mean ArrivalTime in first " << fTimeLowerLimit 
-            << " extraction bin in PIN Diode " << endl;
-      *fLog << GetAbsTimeMean() << "   " << lowerlimit << endl;
-      return kFALSE;
+      *fLog << warn << GetDescriptor() 
+            << Form("%s%3.1f%s%2.1f%s",": Mean ArrivalTime: ",GetAbsTimeMean()," smaller than ",
+                    lowerlimit," FADC slices from lower edge in PIN Diode") << endl;
+      *fLog << warn << GetDescriptor() << ": No PIN Diode calibration!! " << endl;
+      fPINDiode->SetValid(kFALSE);
     }
   
   if ( GetAbsTimeMean() > upperlimit )
     {
-      *fLog << warn << GetDescriptor() << ": Mean ArrivalTime in last " << fTimeUpperLimit 
-            << " two extraction bins in PIN Diode " << endl;
-      *fLog << GetAbsTimeMean() << "   " << upperlimit << endl;
-      return kFALSE;
+      *fLog << warn << GetDescriptor() 
+            << Form("%s%3.1f%s%2.1f%s",": Mean ArrivalTime: ",GetAbsTimeMean()," bigger than ",
+                    upperlimit," FADC slices from upper edge in PIN Diode") << endl;
+      *fLog << warn << GetDescriptor() << ": No PIN Diode calibration!! " << endl;
+      fPINDiode->SetValid(kFALSE);
     }
 
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 3722)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 3723)
@@ -23,8 +23,12 @@
 !
 \* ======================================================================== */
-
 /////////////////////////////////////////////////////////////////////////////
 //
 //  MJCalibration
+//
+//  Do one calibration loop over serious of runs with the same pulser 
+//  colour and the same intensity. The following containers (rectangular) and 
+//  tasks (ellipses) are called to produce an MCalibrationChargeCam and to 
+//  update the MCalibrationQECam: (MCalibrate is not called from this class)
 //
 //Begin_Html
@@ -33,4 +37,10 @@
 */
 //End_Html
+//
+// See also: MHCalibrationChargePix, MHCalibrationChargeCam, MHGausEvents
+//           MHCalibrationChargeBlindPix, MHCalibrationChargePINDiode
+//           MCalibrationChargePix, MCalibrationChargeCam, MCalibrationChargeCalc
+//           MCalibrationChargeBlindPix, MCalibrationChargePINDiode,
+//           MCalibrationQECam, MBadPixelsPix, MBadPixelsCam
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -56,4 +66,5 @@
 
 #include "MPedestalCam.h"
+#include "MCalibrationQECam.h"
 #include "MCalibrationChargeCam.h"
 #include "MCalibrationChargePINDiode.h"
@@ -80,4 +91,10 @@
 using namespace std;
 
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+// Sets fRuns to 0
+//
 MJCalibration::MJCalibration(const char *name, const char *title) : fRuns(0)
 {
@@ -86,4 +103,333 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Draw the MHCamera into the MStatusDisplay: 
+// 
+// 1) Draw it as histogram (MHCamera::DrawCopy("hist")
+// 2) Draw it as a camera, with MHCamera::SetPrettyPalette() set. 
+// 3) If "rad" is not zero, draw its values vs. the radius from the camera center. 
+//    (DrawRadialProfile())
+// 4) Depending on the variable "fit", draw the values projection on the y-axis
+//    (DrawProjection()):
+//    0: don't draw
+//    1: Draw fit to Single Gauss (for distributions flat-fielded over the whole camera)
+//    2: Draw and fit to Double Gauss (for distributions different for inner and outer pixels)
+//    3: Draw and fit to Triple Gauss (for distributions with inner, outer pixels and outliers)
+//    4: Draw and fit to Polynomial grade 0: (for the probability distributions)
+//    >4: Draw and don;t fit.
+//
+void MJCalibration::CamDraw(TCanvas &c, const Int_t x, const Int_t y, const MHCamera &cam1, 
+                            const Int_t fit, const Int_t rad)
+{
+    c.cd(x);
+    gPad->SetBorderMode(0);
+    gPad->SetTicks();
+    MHCamera *obj1=(MHCamera*)cam1.DrawCopy("hist");
+    obj1->SetDirectory(NULL);
+
+    c.cd(x+y);
+    gPad->SetBorderMode(0);
+    obj1->SetPrettyPalette();
+    obj1->AddNotify(&fCalibrationCam);
+    obj1->Draw();
+
+    if (rad)
+      {
+        c.cd(x+2*y);
+        gPad->SetBorderMode(0);
+        gPad->SetTicks();
+        DrawRadialProfile(obj1);
+      }
+    
+
+    if (!fit)
+        return;
+
+    c.cd(rad ? x+3*y : x+2*y);
+    gPad->SetBorderMode(0);
+    gPad->SetTicks();
+    DrawProjection(obj1, fit);
+}
+
+// --------------------------------------------------------------------------
+//
+// Display the results in MStatusDisplay: 
+//
+// - Add "Calibration" to the MStatusDisplay title
+// - Retrieve the MGeomCam from MParList
+// - Initialize the following MHCamera's:
+//   1)  MCalibrationPix::GetMean()
+//   2)  MCalibrationPix::Sigma()
+//   3)  MCalibrationChargePix::GetRSigma()
+//   4)  MCalibrationChargePix::GetRSigmaPerCharge()
+//   5)  MCalibrationChargePix::GetPheFFactorMethod()
+//   6)  MCalibrationChargePix::GetMeanConvFADC2Phe()
+//   7)  MCalibrationChargePix::GetMeanFFactorFADC2Phot()
+//   8)  MCalibrationQEPix::GetQECascadesFFactor()
+//   9)  MCalibrationQEPix::GetQECascadesBlindPixel()
+//   10) MCalibrationQEPix::GetQECascadesPINDiode()
+//   11) MCalibrationQEPix::GetQECascadesCombined()
+//   12) MCalibrationQEPix::IsAverageQEFFactorAvailable()
+//   13) MCalibrationQEPix::IsAverageQEBlindPixelAvailable()
+//   14) MCalibrationQEPix::IsAverageQEPINDiodeAvailable()
+//   15) MCalibrationQEPix::IsAverageQECombinedAvailable()
+//   16) MCalibrationChargePix::IsHiGainSaturation()
+//   17) MCalibrationPix::GetHiLoMeansDivided()
+//   18) MCalibrationPix::GetHiLoSigmasDivided()
+//   19) MCalibrationChargePix::GetHiGainPickup()
+//   20) MCalibrationChargePix::GetLoGainPickup()
+//   21) MCalibrationChargePix::GetHiGainBlackout()
+//   22) MCalibrationChargePix::GetLoGainBlackout()
+//   23) MCalibrationPix::IsExcluded()
+//   24) MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableRun)
+//   25) MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnreliableRun)
+//   26) MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOscillating)
+//   27) MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOscillating)
+//   28) MCalibrationChargePix::GetAbsTimeMean()
+//   29) MCalibrationChargePix::GetAbsTimeRms()
+//
+void MJCalibration::DisplayResult(MParList &plist)
+{
+    if (!fDisplay)
+        return;
+
+    //
+    // Update display
+    //
+    TString title = fDisplay->GetTitle();
+    title += "--  Calibration ";
+    title += fRuns->GetRunsAsString();
+    title += "  --";
+    fDisplay->SetTitle(title);
+
+    //
+    // Get container from list
+    //
+    MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
+
+    // Create histograms to display
+    MHCamera disp1 (geomcam, "Cal;Charge",            "Fitted Mean Charges");
+    MHCamera disp2 (geomcam, "Cal;SigmaCharge",       "Sigma of Fitted Charges");
+    MHCamera disp3 (geomcam, "Cal;RSigma",            "Reduced Sigmas");
+    MHCamera disp4 (geomcam, "Cal;RSigma/Charge",     "Reduced Sigma per Charge");
+    MHCamera disp5 (geomcam, "Cal;FFactorPhe",        "Nr. of Phe's (F-Factor Method)");
+    MHCamera disp6 (geomcam, "Cal;FFactorConv",       "Conversion Factor (F-Factor Method)");
+    MHCamera disp7 (geomcam, "Cal;FFactorFFactor",    "Total F-Factor (F-Factor Method)");
+    MHCamera disp8 (geomcam, "Cal;CascadesQEFFactor", "Cascades QE (F-Factor Method)");
+    MHCamera disp9 (geomcam, "Cal;CascadesQEBlindPix","Cascades QE (Blind Pixel Method)");
+    MHCamera disp10(geomcam, "Cal;CascadesQEPINDiode","Cascades QE (PIN Diode Method)");
+    MHCamera disp11(geomcam, "Cal;CascadesQECombined","Cascades QE (Combined Method)");
+    MHCamera disp12(geomcam, "Cal;FFactorValid",      "Pixels with valid F-Factor calibration");
+    MHCamera disp13(geomcam, "Cal;BlindPixelValid",   "Pixels with valid BlindPixel calibration");
+    MHCamera disp14(geomcam, "Cal;PINdiodeValid",     "Pixels with valid PINDiode calibration");
+    MHCamera disp15(geomcam, "Cal;CombinedValid",     "Pixels with valid Combined calibration");
+    MHCamera disp16(geomcam, "Cal;Saturation",        "Pixels with saturated Hi Gain");
+    MHCamera disp17(geomcam, "Cal;ConversionMeans",   "Conversion HiGain.vs.LoGain Means");
+    MHCamera disp18(geomcam, "Cal;ConversionSigmas",  "Conversion HiGain.vs.LoGain Sigmas");
+    MHCamera disp19(geomcam, "Cal;HiGainPickup",      "Number Pickup events Hi Gain");
+    MHCamera disp20(geomcam, "Cal;LoGainPickup",      "Number Pickup events Lo Gain");
+    MHCamera disp21(geomcam, "Cal;HiGainBlackout",    "Number Blackout events Hi Gain");
+    MHCamera disp22(geomcam, "Cal;LoGainBlackout",    "Number Blackout events Lo Gain");
+    MHCamera disp23(geomcam, "Cal;Excluded",          "Pixels previously excluded");
+    MHCamera disp24(geomcam, "Bad;UnSuitable",        "Pixels not suited for further analysis");
+    MHCamera disp25(geomcam, "Bad;UnReliable",        "Pixels not reliable for further analysis");
+    MHCamera disp26(geomcam, "Bad;HiGainOscillating", "Oscillating Pixels High Gain");
+    MHCamera disp27(geomcam, "Bad;LoGainOscillating", "Oscillating Pixels Low Gain");
+    MHCamera disp28(geomcam, "Cal;AbsTimeMean",       "Abs. Arrival Times");
+    MHCamera disp29(geomcam, "Cal;AbsTimeRms",        "RMS of Arrival Times");
+
+    // Fitted charge means and sigmas
+    disp1.SetCamContent(fCalibrationCam,  0);
+    disp1.SetCamError(  fCalibrationCam,  1);
+    disp2.SetCamContent(fCalibrationCam,  2);
+    disp2.SetCamError(  fCalibrationCam,  3);
+
+    // Reduced Sigmas and reduced sigmas per charge
+    disp3.SetCamContent(fCalibrationCam,  5);
+    disp3.SetCamError(  fCalibrationCam,  6);
+    disp4.SetCamContent(fCalibrationCam,  7);
+    disp4.SetCamError(  fCalibrationCam,  8);
+
+    // F-Factor Method
+    disp5.SetCamContent(fCalibrationCam,  9);
+    disp5.SetCamError(  fCalibrationCam, 10);
+    disp6.SetCamContent(fCalibrationCam, 11);
+    disp6.SetCamError(  fCalibrationCam, 12);
+    disp7.SetCamContent(fCalibrationCam, 13);
+    disp7.SetCamError(  fCalibrationCam, 14);
+
+    // Quantum Efficiencies
+    disp8.SetCamContent (fQECam, 0 );
+    disp8.SetCamError   (fQECam, 1 );
+    disp9.SetCamContent (fQECam, 2 );
+    disp9.SetCamError   (fQECam, 3 );
+    disp10.SetCamContent(fQECam, 4 );
+    disp10.SetCamError  (fQECam, 5 );
+    disp11.SetCamContent(fQECam, 6 );
+    disp11.SetCamError  (fQECam, 7 );
+
+    // Valid flags
+    disp12.SetCamContent(fQECam, 8 );
+    disp13.SetCamContent(fQECam, 9 );
+    disp14.SetCamContent(fQECam, 10);
+    disp15.SetCamContent(fQECam, 11);
+
+    // Conversion Hi-Lo
+    disp16.SetCamContent(fCalibrationCam, 25);
+    disp17.SetCamContent(fCalibrationCam, 16);
+    disp17.SetCamError  (fCalibrationCam, 17);
+    disp18.SetCamContent(fCalibrationCam, 18);
+    disp18.SetCamError  (fCalibrationCam, 19);
+
+    // Pickup and Blackout
+    disp19.SetCamContent(fCalibrationCam, 21);
+    disp20.SetCamContent(fCalibrationCam, 22);
+    disp21.SetCamContent(fCalibrationCam, 23);
+    disp22.SetCamContent(fCalibrationCam, 24);
+
+    // Pixels with defects
+    disp23.SetCamContent(fCalibrationCam, 20);
+    disp24.SetCamContent(fBadPixels, 1);
+    disp25.SetCamContent(fBadPixels, 3);
+
+    // Oscillations
+    disp26.SetCamContent(fBadPixels, 10);
+    disp27.SetCamContent(fBadPixels, 11);
+
+    // Arrival Times
+    disp28.SetCamContent(fCalibrationCam, 26);
+    disp28.SetCamError(  fCalibrationCam, 27);
+    disp29.SetCamContent(fCalibrationCam, 27);
+
+    disp1.SetYTitle("Q [FADC counts]");
+    disp2.SetYTitle("\\sigma_{Q} [FADC counts]");
+
+    disp3.SetYTitle("\\sqrt{\\sigma^{2}_{Q} - RMS^{2}_{Ped}} [FADC Counts]");
+    disp4.SetYTitle("Red.Sigma/<Q> [1]");
+
+    disp5.SetYTitle("Nr. Phe's [1]");
+    disp6.SetYTitle("Conv.Factor [PhE/FADC counts]");
+    disp7.SetYTitle("Total F-Factor [1]");
+
+    disp8.SetYTitle("QE [1]");
+    disp9.SetYTitle("QE [1]");
+    disp10.SetYTitle("QE [1]");
+    disp11.SetYTitle("QE [1]");
+
+    disp12.SetYTitle("[1]");
+    disp13.SetYTitle("[1]");
+    disp14.SetYTitle("[1]");
+    disp15.SetYTitle("[1]");
+    disp16.SetYTitle("[1]");
+
+    disp17.SetYTitle("<Q>(High)/<Q>(Low) [1]");
+    disp18.SetYTitle("\\sigma_{Q}(High)/\\sigma_{Q}(Low) [1]");
+
+    disp19.SetYTitle("[1]");
+    disp20.SetYTitle("[1]");
+    disp21.SetYTitle("[1]");
+    disp22.SetYTitle("[1]");
+    disp23.SetYTitle("[1]");
+    disp24.SetYTitle("[1]");
+    disp25.SetYTitle("[1]");
+    disp26.SetYTitle("[1]");
+    disp27.SetYTitle("[1]");
+
+    disp28.SetYTitle("Mean Abs. Time [FADC slice]");
+    disp29.SetYTitle("RMS Abs. Time [FADC slices]");
+
+    gStyle->SetOptStat(1111);
+    gStyle->SetOptFit();
+
+    // Charges
+    TCanvas &c1 = fDisplay->AddTab("Fit.Charge");
+    c1.Divide(2, 4);
+
+    CamDraw(c1, 1, 2, disp1, 2, 1);
+    CamDraw(c1, 2, 2, disp2, 2, 1);
+
+    // Reduced Sigmas
+    TCanvas &c3 = fDisplay->AddTab("Red.Sigma");
+    c3.Divide(2,4);
+
+    CamDraw(c3, 1, 2, disp3, 2, 1);
+    CamDraw(c3, 2, 2, disp4, 2, 1);
+
+    //  F-Factor
+    TCanvas &c4 = fDisplay->AddTab("Phe's");
+    c4.Divide(3,4);
+
+    CamDraw(c4, 1, 3, disp5, 2, 1);
+    CamDraw(c4, 2, 3, disp6, 2, 1);
+    CamDraw(c4, 3, 3, disp7, 2, 1);
+
+    // QE's
+    TCanvas &c5 = fDisplay->AddTab("QE's");
+    c5.Divide(4,4);
+
+    CamDraw(c5, 1, 4, disp8,  2, 1);
+    CamDraw(c5, 2, 4, disp9,  2, 1);
+    CamDraw(c5, 3, 4, disp10, 2, 1);
+    CamDraw(c5, 4, 4, disp11, 2, 1);
+
+    // Validity
+    TCanvas &c6 = fDisplay->AddTab("Valid");
+    c6.Divide(4,2);
+
+    CamDraw(c6, 1, 4, disp12, 0);
+    CamDraw(c6, 2, 4, disp13, 0);
+    CamDraw(c6, 3, 4, disp14, 0);
+    CamDraw(c6, 4, 4, disp15, 0);
+
+    // Other info
+    TCanvas &c7 = fDisplay->AddTab("HiLoGain");
+    c7.Divide(3,3);
+
+    CamDraw(c7, 1, 3, disp16, 0);
+    CamDraw(c7, 2, 3, disp17, 1);
+    CamDraw(c7, 3, 3, disp18, 1);
+
+    // Pickup
+    TCanvas &c8 = fDisplay->AddTab("Pickup");
+    c8.Divide(4,2);
+
+    CamDraw(c8, 1, 4, disp19, 0);
+    CamDraw(c8, 2, 4, disp20, 0);
+    CamDraw(c8, 3, 4, disp21, 0);
+    CamDraw(c8, 4, 4, disp22, 0);
+
+    // Defects
+    TCanvas &c9 = fDisplay->AddTab("Defect");
+    c9.Divide(5,2);
+
+    CamDraw(c9, 1, 5, disp23, 0);
+    CamDraw(c9, 2, 5, disp24, 0);
+    CamDraw(c9, 3, 5, disp25, 0);
+    CamDraw(c9, 4, 5, disp26, 0);
+    CamDraw(c9, 5, 5, disp27, 0);
+
+    // Abs. Times
+    TCanvas &c10 = fDisplay->AddTab("Abs. Times");
+    c10.Divide(2,3);
+    
+    CamDraw(c10, 1, 2, disp28, 2);
+    CamDraw(c10, 2, 2, disp29, 1);
+
+}
+
+// --------------------------------------------------------------------------
+//
+// Draw a projection of MHCamera onto the y-axis values. Depending on the 
+// variable fit, the following fits are performed:
+//
+// 1: Single Gauss (for distributions flat-fielded over the whole camera)
+// 2: Double Gauss (for distributions different for inner and outer pixels)
+// 3: Triple Gauss (for distributions with inner, outer pixels and outliers)
+// 4: flat         (for the probability distributions)
+//
+// Moreover, sectors 6,1 and 2 of the camera and sectors 3,4 and 5 are 
+// drawn separately, for inner and outer pixels.
+//
 void MJCalibration::DrawProjection(MHCamera *obj, Int_t fit) const
 {
@@ -215,4 +561,11 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Draw a projection of MHCamera vs. the radius from the central pixel. 
+//
+// The inner and outer pixels are drawn separately, both fitted by a polynomial
+// of grade 1.
+//
 void MJCalibration::DrawRadialProfile(MHCamera *obj) const
 {
@@ -262,247 +615,21 @@
 
 
-void MJCalibration::CamDraw(TCanvas &c, const Int_t x, const Int_t y, const MHCamera &cam1, 
-                            const Int_t fit, const Int_t rad)
-{
-    c.cd(x);
-    gPad->SetBorderMode(0);
-    gPad->SetTicks();
-    MHCamera *obj1=(MHCamera*)cam1.DrawCopy("hist");
-    obj1->SetDirectory(NULL);
-
-    c.cd(x+y);
-    gPad->SetBorderMode(0);
-    obj1->SetPrettyPalette();
-    obj1->AddNotify(&fCalibrationCam);
-    obj1->Draw();
-
-    if (rad)
-      {
-        c.cd(x+2*y);
-        gPad->SetBorderMode(0);
-        gPad->SetTicks();
-        DrawRadialProfile(obj1);
-      }
-    
-
-    if (!fit)
-        return;
-
-    c.cd(rad ? x+3*y : x+2*y);
-    gPad->SetBorderMode(0);
-    gPad->SetTicks();
-    DrawProjection(obj1, fit);
-}
-
-
-void MJCalibration::DisplayResult(MParList &plist)
-{
-    if (!fDisplay)
-        return;
-
-    //
-    // Update display
-    //
-    TString title = fDisplay->GetTitle();
-    title += "--  Calibration ";
-    title += fRuns->GetRunsAsString();
-    title += "  --";
-    fDisplay->SetTitle(title);
-
-    //
-    // Get container from list
-    //
-    MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
-
-    // Create histograms to display
-    MHCamera disp1 (geomcam, "Cal;Charge",         "Fitted Mean Charges");
-    MHCamera disp2 (geomcam, "Cal;SigmaCharge",    "Sigma of Fitted Charges");
-    MHCamera disp3 (geomcam, "Cal;RSigma",         "Reduced Sigmas");
-    MHCamera disp4 (geomcam, "Cal;RSigma/Charge",  "Reduced Sigma per Charge");
-    MHCamera disp5 (geomcam, "Cal;FFactorPhe",     "Nr. of Phe's (F-Factor Method)");
-    MHCamera disp6 (geomcam, "Cal;FFactorConv",    "Conversion Factor (F-Factor Method)");
-    MHCamera disp7 (geomcam, "Cal;BlindPixConv",   "Conversion Factor (Blind Pixel Method)");
-    MHCamera disp8 (geomcam, "Cal;PINDiodeConv",   "Conversion Factor (PIN Diode Method)");
-    MHCamera disp9 (geomcam, "Cal;FFactorValid",   "Pixels with valid F-Factor calibration");
-    MHCamera disp10(geomcam, "Cal;BlindPixelValid","Pixels with valid BlindPixel calibration");
-    MHCamera disp11(geomcam, "Cal;PINdiodeValid",  "Pixels with valid PINDiode calibration");
-    MHCamera disp12(geomcam, "Cal;Excluded",       "Pixels previously excluded");
-    MHCamera disp13(geomcam, "Cal;Saturation",     "Pixels with saturated Hi Gain");
-    MHCamera disp14(geomcam, "Cal;HiGainPickup",   "Number Pickup events Hi Gain");
-    MHCamera disp15(geomcam, "Cal;LoGainPickup",   "Number Pickup events Lo Gain");
-    MHCamera disp16(geomcam, "Bad;UnSuitable",     "Pixels not suited for further analysis");
-    MHCamera disp17(geomcam, "Bad;UnReliable",     "Pixels not reliable for further analysis");
-    MHCamera disp18(geomcam, "Bad;Oscillation",    "Oscillating Pixels");
-    MHCamera disp19(geomcam, "Cal;AbsTimeMean",    "Abs. Arrival Times");
-    MHCamera disp20(geomcam, "Cal;AbsTimeRms",     "RMS of Arrival Times");
-
-    // Fitted charge means and sigmas
-    disp1.SetCamContent(fCalibrationCam,  0);
-    disp1.SetCamError(  fCalibrationCam,  1);
-    disp2.SetCamContent(fCalibrationCam,  2);
-    disp2.SetCamError(  fCalibrationCam,  3);
-
-    // Reduced Sigmas and reduced sigmas per charge
-    disp3.SetCamContent(fCalibrationCam,  5);
-    disp3.SetCamError(  fCalibrationCam,  6);
-    disp4.SetCamContent(fCalibrationCam,  7);
-    disp4.SetCamError(  fCalibrationCam,  8);
-
-    // Conversion Factors, Methods
-    disp5.SetCamContent(fCalibrationCam,  9);
-    disp5.SetCamError(  fCalibrationCam, 10);
-    disp6.SetCamContent(fCalibrationCam, 11);
-    disp6.SetCamError(  fCalibrationCam, 12);
-    disp7.SetCamContent(fCalibrationCam, 13);
-    disp7.SetCamError(  fCalibrationCam, 14);
-    disp8.SetCamContent(fCalibrationCam, 16);
-    disp8.SetCamError(  fCalibrationCam, 17);
-
-    // Valid flags
-    disp9.SetCamContent (fCalibrationCam, 15);
-    disp10.SetCamContent(fCalibrationCam, 20);
-    disp11.SetCamContent(fCalibrationCam, 25);
-
-    // Pixels behavior
-    disp12.SetCamContent(fCalibrationCam, 26);
-    disp13.SetCamContent(fCalibrationCam, 29);
-    disp14.SetCamContent(fCalibrationCam, 27);
-    disp15.SetCamContent(fCalibrationCam, 28);
-
-    // Pixels with defects
-    disp16.SetCamContent(fBadPixels, 1);
-    disp17.SetCamContent(fBadPixels, 3);
-    disp18.SetCamContent(fBadPixels, 8);
-
-    // Arrival Times
-    disp19.SetCamContent(fCalibrationCam, 34);
-    disp19.SetCamError(  fCalibrationCam, 35);
-    disp20.SetCamContent(fCalibrationCam, 35);
-
-    disp1.SetYTitle("Q [FADC units]");
-    disp2.SetYTitle("\\sigma_{Q} [FADC units]");
-
-    disp3.SetYTitle("\\sqrt{\\sigma^{2}_{Q} - RMS^{2}_{Ped}} [FADC Counts]");
-    disp4.SetYTitle("Red.Sigma/<Q> [1]");
-
-    disp5.SetYTitle("PhE [#]");
-    disp6.SetYTitle("Conv.Factor [PhE/FADC units]");
-
-    disp7.SetYTitle("Conv.Factor [Phot/FADC Count]");
-    disp8.SetYTitle("Conv.Factor [Phot/FADC Count]");
-
-    disp9.SetYTitle("[1]");
-    disp10.SetYTitle("[1]");
-    disp11.SetYTitle("[1]");
-    disp12.SetYTitle("[1]");
-    disp13.SetYTitle("[1]");
-    disp14.SetYTitle("[1]");
-    disp15.SetYTitle("[1]");
-    disp16.SetYTitle("[1]");
-    disp17.SetYTitle("[1]");
-    disp18.SetYTitle("[1]");
-    disp19.SetYTitle("Mean Abs. Time [FADC slice]");
-    disp20.SetYTitle("RMS Abs. Time [FADC slices]");
-
-    gStyle->SetOptStat(1111);
-    gStyle->SetOptFit();
-
-    // Charges
-    TCanvas &c1 = fDisplay->AddTab("Fit.Charge");
-    c1.Divide(2, 4);
-
-    CamDraw(c1, 1, 2, disp1, 2, 1);
-    CamDraw(c1, 2, 2, disp2, 2, 1);
-
-    // Reduced Sigmas
-    TCanvas &c3 = fDisplay->AddTab("Red.Sigma");
-    c3.Divide(2,4);
-
-    CamDraw(c3, 1, 2, disp3, 2, 1);
-    CamDraw(c3, 2, 2, disp4, 2, 1);
-
-    //  Methods
-    TCanvas &c4 = fDisplay->AddTab("Methods");
-    c4.Divide(4,4);
-
-    CamDraw(c4, 1, 4, disp5, 2, 1);
-    CamDraw(c4, 2, 4, disp6, 2, 1);
-    CamDraw(c4, 3, 4, disp7, 2, 1);
-    CamDraw(c4, 4, 4, disp8, 2, 1);
-
-    // Validity
-    TCanvas &c5 = fDisplay->AddTab("Validity");
-    c5.Divide(3,2);
-
-    CamDraw(c5, 1, 3, disp9 , 0);
-    CamDraw(c5, 2, 3, disp10, 0);
-    CamDraw(c5, 3, 3, disp11, 0);
-
-    // Other info
-    TCanvas &c6 = fDisplay->AddTab("Behavior");
-    c6.Divide(4,2);
-
-    CamDraw(c6, 1, 4, disp12, 0);
-    CamDraw(c6, 2, 4, disp13, 0);
-    CamDraw(c6, 3, 4, disp14, 0);
-    CamDraw(c6, 4, 4, disp15, 0);
-
-    // Defects
-    TCanvas &c7 = fDisplay->AddTab("Defects");
-    c7.Divide(3,2);
-
-    CamDraw(c7, 1, 3, disp16, 0);
-    CamDraw(c7, 2, 3, disp17, 0);
-    CamDraw(c7, 3, 3, disp18, 0);
-
-    // Abs. Times
-    TCanvas &c8 = fDisplay->AddTab("Abs. Times");
-    c8.Divide(2,3);
-    
-    CamDraw(c8, 1, 2, disp19, 2);
-    CamDraw(c8, 2, 2, disp20, 1);
-
-}
-
-Bool_t MJCalibration::WriteResult()
-{
-    if (fOutputPath.IsNull())
-        return kTRUE;
-
-    const TString oname(GetOutputFile());
-
-    *fLog << inf << "Writing to file: " << oname << endl;
-
-    TFile file(oname, "UPDATE");
-
-    if (fDisplay && fDisplay->Write()<=0)
-    {
-        *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
-        return kFALSE;
-    }
-
-    if (fCalibrationCam.Write()<=0)
-    {
-        *fLog << err << "Unable to write MCalibrationCam to " << oname << endl;
-        return kFALSE;
-    }
-
-    if (fBadPixels.Write()<=0)
-    {
-        *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
-        return kFALSE;
-    }
-
-    return kTRUE;
-
-}
-
-void MJCalibration::SetOutputPath(const char *path)
-{
-    fOutputPath = path;
-    if (fOutputPath.EndsWith("/"))
-        fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
-}
-
+// --------------------------------------------------------------------------
+//
+// Retrieve the output file written by WriteResult()
+// 
+TString MJCalibration::GetOutputFile() const
+{
+    if (!fRuns)
+        return "";
+
+    return Form("%s/%s-F1.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Call the ProcessFile(MPedestalCam)
+// 
 Bool_t MJCalibration::Process(MPedestalCam &pedcam)
 {
@@ -513,56 +640,42 @@
 }
 
-TString MJCalibration::GetOutputFile() const
+// --------------------------------------------------------------------------
+//
+// Execute the task list and the eventloop:
+//
+// - Check if there are fRuns, otherwise return
+// - Check for consistency between run numbers and number of files
+// - Add fRuns to MReadMarsFile
+// - Put into MParList:
+//   1) MPedestalCam          (pedcam)
+//   2) MCalibrationQECam     (fQECam)
+//   3) MCalibrationChargeCam (fCalibrationCam)
+//   4) MBadPixelsCam         (fBadPixels)
+//   5) MCalibrationChargePINDiode
+//   6) MCalibrationChargeBlindPix
+// - Put into the MTaskList:
+//   1)  MReadMarsFile
+//   2)  MBadPixelsMerge
+//   3)  MGeomApply
+//   4)  MExtractSignal2
+//   5)  MExtractPINDiode
+//   6)  MExtractBlindPixel
+//   7)  MContinue(MFCosmics)
+//   8)  MFillH("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode")
+//   9)  MFillH("MHCalibrationChargeBlindPix", "MExtractedSignalBlindPixel")
+//   10) MFillH("MHCalibrationChargeCam",      "MExtractedSignalCam")
+//   11) MCalibrationChargeCalc
+// - Execute MEvtLoop
+// - DisplayResult()
+// - WriteResult()
+//
+Bool_t MJCalibration::ProcessFile(MPedestalCam &pedcam)
 {
     if (!fRuns)
-        return "";
-
-    return Form("%s/%s-F1.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
-}
-
-Bool_t MJCalibration::ReadCalibrationCam()
-{
-    const TString fname = GetOutputFile();
-
-    if (gSystem->AccessPathName(fname, kFileExists))
-    {
-        *fLog << err << "Input file " << fname << " doesn't exist." << endl;
-        return kFALSE;
-    }
-
-    *fLog << inf << "Reading from file: " << fname << endl;
-
-    TFile file(fname, "READ");
-    if (fCalibrationCam.Read()<=0)
-    {
-        *fLog << err << "Unable to read MCalibrationCam from " << fname << endl;
-        return kFALSE;
-    }
-
-    if (file.FindKey("MBadPixelsCam"))
-    {
-        MBadPixelsCam bad;
-        if (bad.Read()<=0)
-        {
-            *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
-            return kFALSE;
-        }
-        fBadPixels.Merge(bad);
-    }
-
-    if (fDisplay /*&& !fDisplay->GetCanvas("Pedestals")*/) // FIXME!
-        fDisplay->Read();
-
-    return kTRUE;
-}
-
-
-Bool_t MJCalibration::ProcessFile(MPedestalCam &pedcam)
-{
-    if (!fRuns)
     {
         *fLog << err << "No Runs choosen... abort." << endl;
         return kFALSE;
     }
+
     if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
     {
@@ -590,6 +703,7 @@
     MParList plist;
     plist.AddToList(&pedcam);
+    plist.AddToList(&fBadPixels);
+    plist.AddToList(&fQECam);
     plist.AddToList(&fCalibrationCam);
-    plist.AddToList(&fBadPixels);
     plist.AddToList(&pindiode);
     plist.AddToList(&blindpix);
@@ -599,5 +713,5 @@
 
     MGeomApply               apply;
-    MBadPixelsMerge          merge(&fBadPixels);
+    //    MBadPixelsMerge          merge(&fBadPixels);
     MExtractPINDiode         pinext;
     MExtractBlindPixel       blindext;
@@ -622,8 +736,6 @@
     MContinue cont(&cosmics);
 
-    //calcalc.SkipBlindPixelFit();
-
     tlist.AddToList(&read);
-    tlist.AddToList(&merge);
+    //    tlist.AddToList(&merge);
     tlist.AddToList(&apply);
     tlist.AddToList(&extract);
@@ -660,2 +772,114 @@
     return kTRUE;
 }
+
+// --------------------------------------------------------------------------
+//
+// Read the following containers from GetOutputFile()
+// - MCalibrationChargeCam
+// - MCalibrationQECam
+// - MBadPixelsCam
+//
+Bool_t MJCalibration::ReadCalibrationCam()
+{
+    const TString fname = GetOutputFile();
+
+    if (gSystem->AccessPathName(fname, kFileExists))
+    {
+        *fLog << err << "Input file " << fname << " doesn't exist." << endl;
+        return kFALSE;
+    }
+
+    *fLog << inf << "Reading from file: " << fname << endl;
+
+    TFile file(fname, "READ");
+    if (fCalibrationCam.Read()<=0)
+    {
+        *fLog << err << "Unable to read MCalibrationChargeCam from " << fname << endl;
+        return kFALSE;
+    }
+
+    if (fQECam.Read()<=0)
+    {
+        *fLog << err << "Unable to read MCalibrationQECam from " << fname << endl;
+        return kFALSE;
+    }
+
+    if (file.FindKey("MBadPixelsCam"))
+    {
+        MBadPixelsCam bad;
+        if (bad.Read()<=0)
+        {
+            *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
+            return kFALSE;
+        }
+        fBadPixels.Merge(bad);
+    }
+
+    if (fDisplay /*&& !fDisplay->GetCanvas("Pedestals")*/) // FIXME!
+        fDisplay->Read();
+
+    return kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Set the path for output files, written by WriteResult()
+// 
+void MJCalibration::SetOutputPath(const char *path)
+{
+    fOutputPath = path;
+    if (fOutputPath.EndsWith("/"))
+        fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Write the result into the output file GetOutputFile(), if fOutputPath exists.
+// 
+// The following containers are written:
+// - MStatusDisplay
+// - MCalibrationChargeCam
+// - MCalibrationQECam
+// - MBadPixelsCam
+//
+Bool_t MJCalibration::WriteResult()
+{
+    if (fOutputPath.IsNull())
+        return kTRUE;
+
+    const TString oname(GetOutputFile());
+
+    *fLog << inf << "Writing to file: " << oname << endl;
+
+    TFile file(oname, "UPDATE");
+
+    if (fDisplay && fDisplay->Write()<=0)
+    {
+        *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
+        return kFALSE;
+    }
+
+    if (fCalibrationCam.Write()<=0)
+    {
+        *fLog << err << "Unable to write MCalibrationChargeCam to " << oname << endl;
+        return kFALSE;
+    }
+
+    if (fQECam.Write()<=0)
+    {
+        *fLog << err << "Unable to write MCalibrationQECam to " << oname << endl;
+        return kFALSE;
+    }
+
+    if (fBadPixels.Write()<=0)
+    {
+        *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+
+}
+
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.h	(revision 3722)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.h	(revision 3723)
@@ -58,5 +58,5 @@
   Bool_t Process    ( MPedestalCam &pedcam );
   
-  ClassDef(MJCalibration, 0) // Tool to create a calibration file (MCalibrationCam)
+  ClassDef(MJCalibration, 0) // Tool to run a calibration per pulser colour and intensity
 };
 
