Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 3713)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 3714)
@@ -26,15 +26,38 @@
 // MCalibrationChargeCam                                               
 //                                                               
-// Storage container for charge calibration results of the whole camera.
+// Storage container for charge calibration results from the signal distribution 
+// fits (see MHCalibrationChargeCam and MHCalibrationChargePix), the calculation 
+// of reduced sigmas and number of photo-electrons (this class) and conversion 
+// factors sum FADC slices to photo-electrons (see MCalibrationChargeCalc)
 //
 // Individual pixels have to be cast when retrieved e.g.:
 // MCalibrationChargePix &avpix = (MCalibrationChargePix&)(*fChargeCam)[i]
 // 
-// The following calibration constants can be retrieved from each pixel:
+// Averaged values over one whole area index (e.g. inner or outer pixels for 
+// the MAGIC camera), can be retrieved via: 
+// MCalibrationChargePix &avpix = (MCalibrationChargePix&)fChargeCam->GetAverageArea(i)
+//
+// Averaged values over one whole camera sector can be retrieved via: 
+// MCalibrationChargePix &avpix = (MCalibrationChargePix&)fChargeCam->GetAverageSector(i)
+//
+// Note the averageing has been done on an event-by-event basis. Resulting 
+// Sigma's of the Gauss fit have been multiplied with the square root of the number 
+// of involved pixels in order to make a direct comparison possible with the mean of 
+// sigmas. 
+//
+// The following "calibration" constants are used for the calibration of each pixel 
+// (see MCalibrate and MCalibrateData):
+//
+// - MCalibrationQEPix::GetMeanConvFADC2Phe(): The mean conversion factor from the 
+//   summed FADC slices to the number of photo-electrons (in first order independent 
+//   on colour and intensity)
+// - MCalibrationQEPix::GetMeanFFactorFADC2Phot(): The mean F-Factor of the total  
+//   readout chain dividing the signal to noise of the incoming number of photons 
+//   (= sqrt(number photons)) by the signal to noise of the outgoing summed FADC slices 
+//   signal (= MCalibrationPix::GetMean() / MCalibrationChargePix::GetRSigma() )
+//
+// The following calibration constants can be retrieved directly from this class:
 //
 // - GetConversionFactorFFactor    ( Int_t idx, Float_t &mean, Float_t &err, Float_t &sigma );
-// - GetConversionFactorBlindPixel ( Int_t idx, Float_t &mean, Float_t &err, Float_t &sigma );
-// - GetConversionFactorPINDiode   ( Int_t idx, Float_t &mean, Float_t &err, Float_t &sigma );
-// - GetConversionFactorCombined   ( Int_t idx, Float_t &mean, Float_t &err, Float_t &sigma );
 //
 // where: 
@@ -48,84 +71,7 @@
 // Note, Conversion is ALWAYS (included the F-Factor method!) from summed FADC slices to PHOTONS.
 //
-// Averaged values over one whole area index (e.g. inner or outer pixels for 
-// the MAGIC camera), can be retrieved via: 
-// MCalibrationChargePix &avpix = (MCalibrationChargePix&)fChargeCam->GetAverageArea(i)
-//
-// Averaged values over one whole camera sector can be retrieved via: 
-// MCalibrationChargePix &avpix = (MCalibrationChargePix&)fChargeCam->GetAverageSector(i)
-//
-// Note the averageing has been done on an event-by-event basis. Resulting 
-// Sigma's of the Gauss fit have been multiplied with the square root of the number 
-// of involved pixels in order to make a direct comparison possible with the mean of 
-// sigmas. 
-//
-// See also: MCalibrationChargePix, MCalibrationChargeCalc
+// See also: MCalibrationChargePix, MCalibrationChargeCalc, MCalibrationQECam
 //           MHCalibrationChargePix, MHCalibrationChargeCam              
-//
-// The types of GetPixelContent() are as follows:
-// 
-// Fitted values:
-// ============== 
-//
-// 0: Fitted Charge                              (see MCalibrationPix::GetMean())
-// 1: Error of fitted Charge                     (see MCalibrationPix::GetMeanErr())
-// 2: Sigma of fitted Charge                     (see MCalibrationPix::GetSigma())
-// 3: Error of Sigma of fitted Charge            (see MCalibrationPix::GetSigmaErr())
-//
-// Useful variables derived from the fit results:
-// =============================================
-//
-// 4: Probability Gauss fit Charge distribution  (see MCalibrationPix::GetProb())
-// 5: Reduced Sigma of fitted Charge             (see MCalibrationChargePix::GetRSigma())
-// 6: Error Reduced Sigma of fitted Charge       (see MCalibrationChargePix::GetRSigmaErr())
-// 7: Reduced Sigma per Charge                 
-// 8: Error of Reduced Sigma per Charge 
-//
-// Results of the different calibration methods:
-// =============================================
-//
-//  9: Nr. Photo-electrons from F-Factor Method   (see MCalibrationChargePix::GetPheFFactorMethod())
-// 10: Error Nr. Photo-el. from F-Factor Method   (see MCalibrationChargePix::GetPheFFactorMethodErr())
-// 11: Conversion factor   from F-Factor Method   (see MCalibrationChargePix::GetMeanConversionFFactorMethod())
-// 12: Error conv. factor  from F-Factor Method   (see MCalibrationChargePix::GetConversionFFactorMethodErr())
-// 13: Overall F-Factor    from F-Factor Method   (see MCalibrationChargePix::GetTotalFFactorFFactorMethod())
-// 14: Error F-Factor      from F-Factor Method   (see MCalibrationChargePix::GetTotalFFactorFFactorMethodErr())
-// 15: Pixels valid calibration F-Factor-Method   (see MCalibrationChargePix::IsFFactorMethodValid())           
-// 16: Conversion factor   from BlindPixel Method (see MCalibrationChargePix::GetMeanConversionBlindPixelMethod()) 
-// 17: Error conv. factor  from BlindPixel Method (see MCalibrationChargePix::GetConversionBlindPixelMethodErr())  
-// 18: Overall F-Factor    from BlindPixel Method (see MCalibrationChargePix::GetTotalFFactorBlindPixelMethod())   
-// 19: Error F-Factor      from BlindPixel Method (see MCalibrationChargePix::GetTotalFFactorBlindPixelMethodErr())
-// 20: Pixels valid calibration BlindPixel-Method (see MCalibrationChargePix::IsBlindPixelMethodValid())           
-// 21: Conversion factor   from PINDiode Method   (see MCalibrationChargePix::GetMeanConversionPINDiodeMethod()) 
-// 22: Error conv. factor  from PINDiode Method   (see MCalibrationChargePix::GetConversionPINDiodeMethodErr())  
-// 23: Overall F-Factor    from PINDiode Method   (see MCalibrationChargePix::GetTotalFFactorPINDiodeMethod())   
-// 24: Error F-Factor      from PINDiode Method   (see MCalibrationChargePix::GetTotalFFactorPINDiodeMethodErr())
-// 25: Pixels valid calibration PINDiode-Method   (see MCalibrationChargePix::IsPINDiodeMethodValid())           
-//                                                
-// Localized defects:                             
-// ==================
-//
-// 26: Excluded Pixels
-// 27: Number of pickup events in the Hi Gain     (see MCalibrationPix::GetHiGainNumPickup())
-// 28: Number of pickup events in the Lo Gain     (see MCalibrationPix::GetLoGainNumPickup())
-//
-// Other classifications of pixels:
-// ================================
-//
-// 29: Pixels with saturated Hi-Gain              (see MCalibrationPix::IsHighGainSaturation())
-//
-// Used Pedestals:
-// ===============
-//
-// 30: Pedestal for entire signal extr. range     (see MCalibrationChargePix::Ped())
-// 31: Error Pedestal entire signal extr. range   (see MCalibrationChargePix::PedErr())
-// 32: Ped. RMS entire signal extraction range    (see MCalibrationChargePix::PedRms())
-// 33: Error Ped. RMS entire signal extr. range   (see MCalibrationChargePix::PedRmsErr())
-//
-// Calculated absolute arrival times (very low precision!):
-// ========================================================
-//
-// 34: Absolute Arrival time of the signal        (see MCalibrationChargePix::GetAbsTimeMean())
-// 35: RMS Ab.  Arrival time of the signal        (see MCalibrationChargePix::GetAbsTimeRms())
+//           MCalibrationChargeBlindPix, MCalibrationChargePINDiode
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -133,6 +79,4 @@
 #include "MCalibrationCam.h"
 
-#include <TH2.h>
-#include <TCanvas.h>
 #include <TClonesArray.h>
 
@@ -175,7 +119,4 @@
 //
 MCalibrationChargeCam::MCalibrationChargeCam(const char *name, const char *title)
-    : fOffsets(NULL),
-      fSlopes(NULL),
-      fOffvsSlope(NULL)
 {
   fName  = name  ? name  : "MCalibrationChargeCam";
@@ -187,19 +128,4 @@
   
   Clear();
-}
-
-// --------------------------------------------------------------------------
-//
-// Deletes the histograms if they exist
-//
-MCalibrationChargeCam::~MCalibrationChargeCam()
-{
-
-  if (fOffsets)
-    delete fOffsets;
-  if (fSlopes)
-    delete fSlopes;
-  if (fOffvsSlope)
-    delete fOffvsSlope;
 }
 
@@ -341,53 +267,53 @@
 // 5: Reduced Sigma of fitted Charge             (see MCalibrationChargePix::GetRSigma())
 // 6: Error Reduced Sigma of fitted Charge       (see MCalibrationChargePix::GetRSigmaErr())
-// 7: Reduced Sigma per Charge                 
-// 8: Error of Reduced Sigma per Charge 
-//
-// Results of the different calibration methods:
-// =============================================
-//
-//  9: Nr. Photo-electrons from F-Factor Method   (see MCalibrationChargePix::GetPheFFactorMethod())
-// 10: Error Nr. Photo-el. from F-Factor Method   (see MCalibrationChargePix::GetPheFFactorMethodErr())
-// 11: Conversion factor   from F-Factor Method   (see MCalibrationChargePix::GetMeanConversionFFactorMethod())
-// 12: Error conv. factor  from F-Factor Method   (see MCalibrationChargePix::GetConversionFFactorMethodErr())
-// 13: Overall F-Factor    from F-Factor Method   (see MCalibrationChargePix::GetTotalFFactorFFactorMethod())
-// 14: Error F-Factor      from F-Factor Method   (see MCalibrationChargePix::GetTotalFFactorFFactorMethodErr())
-// 15: Pixels valid calibration F-Factor-Method   (see MCalibrationChargePix::IsFFactorMethodValid())           
-// 16: Conversion factor   from BlindPixel Method (see MCalibrationChargePix::GetMeanConversionBlindPixelMethod()) 
-// 17: Error conv. factor  from BlindPixel Method (see MCalibrationChargePix::GetConversionBlindPixelMethodErr())  
-// 18: Overall F-Factor    from BlindPixel Method (see MCalibrationChargePix::GetTotalFFactorBlindPixelMethod())   
-// 19: Error F-Factor      from BlindPixel Method (see MCalibrationChargePix::GetTotalFFactorBlindPixelMethodErr())
-// 20: Pixels valid calibration BlindPixel-Method (see MCalibrationChargePix::IsBlindPixelMethodValid())           
-// 21: Conversion factor   from PINDiode Method   (see MCalibrationChargePix::GetMeanConversionPINDiodeMethod()) 
-// 22: Error conv. factor  from PINDiode Method   (see MCalibrationChargePix::GetConversionPINDiodeMethodErr())  
-// 23: Overall F-Factor    from PINDiode Method   (see MCalibrationChargePix::GetTotalFFactorPINDiodeMethod())   
-// 24: Error F-Factor      from PINDiode Method   (see MCalibrationChargePix::GetTotalFFactorPINDiodeMethodErr())
-// 25: Pixels valid calibration PINDiode-Method   (see MCalibrationChargePix::IsPINDiodeMethodValid())           
+// 7: Reduced Sigma per Charge                   (see MCalibrationChargePix::GetRSigmaPerCharge())
+// 8: Error of Reduced Sigma per Charge          (see MCalibrationChargePix::GetRSigmaPerChargeErr())
+//
+// Results of the F-Factor calibration Method:
+// ===========================================
+//
+//  9: Nr. Photo-electrons from F-Factor Method  (see MCalibrationChargePix::GetPheFFactorMethod())
+// 10: Error Nr. Photo-el. from F-Factor Method  (see MCalibrationChargePix::GetPheFFactorMethodErr())
+// 11: Conversion factor   from F-Factor Method  (see MCalibrationChargePix::GetMeanConversionFFactorMethod())
+// 12: Error conv. factor  from F-Factor Method  (see MCalibrationChargePix::GetConversionFFactorMethodErr())
+// 13: Overall F-Factor    from F-Factor Method  (see MCalibrationChargePix::GetTotalFFactorFFactorMethod())
+// 14: Error F-Factor      from F-Factor Method  (see MCalibrationChargePix::GetTotalFFactorFFactorMethodErr())
+// 15: Pixels valid calibration F-Factor-Method  (see MCalibrationChargePix::IsFFactorMethodValid())           
+//
+// Results of the Low-Gain vs. High-Gain Conversion:
+// =================================================
+//
+// 16: Mean Signal Hi-Gain / Mean Signal Lo-Gain (see MCalibrationPix::GetHiLoMeansDivided())
+// 17: Error Signal High-Gain / Signal Low Gain  (see MCalibrationPix::GetHiLoMeansDividedErr())
+// 18: Sigma High-Gain / Sigma Low Gain          (see MCalibrationPix::GetHiLoSigmasDivided())
+// 19: Error Sigma High-Gain / Sigma Low Gain    (see MCalibrationPix::GetHiLoSigmasDividedErr())
 //                                                
 // Localized defects:                             
 // ==================
 //
-// 26: Excluded Pixels
-// 27: Number of pickup events in the Hi Gain     (see MCalibrationPix::GetHiGainNumPickup())
-// 28: Number of pickup events in the Lo Gain     (see MCalibrationPix::GetLoGainNumPickup())
+// 20: Excluded Pixels
+// 21: Number of pickup   events in the Hi Gain  (see MCalibrationPix::GetHiGainNumPickup())
+// 22: Number of pickup   events in the Lo Gain  (see MCalibrationPix::GetLoGainNumPickup())
+// 23: Number of blackout events in the Hi Gain  (see MCalibrationPix::GetHiGainNumBlackout())
+// 24: Number of blackout events in the Lo Gain  (see MCalibrationPix::GetLoGainNumBlackout())
 //
 // Other classifications of pixels:
 // ================================
 //
-// 29: Pixels with saturated Hi-Gain              (see MCalibrationPix::IsHighGainSaturation())
+// 25: Pixels with saturated High-Gain           (see MCalibrationPix::IsHiGainSaturation())
+//
+// Calculated absolute arrival times (very low precision!):
+// ========================================================
+//
+// 26: Absolute Arrival time of the signal       (see MCalibrationChargePix::GetAbsTimeMean())
+// 27: RMS Ab.  Arrival time of the signal       (see MCalibrationChargePix::GetAbsTimeRms())
 //
 // Used Pedestals:
 // ===============
 //
-// 30: Pedestal for entire signal extr. range     (see MCalibrationChargePix::Ped())
-// 31: Error Pedestal entire signal extr. range   (see MCalibrationChargePix::PedErr())
-// 32: Ped. RMS entire signal extraction range    (see MCalibrationChargePix::PedRms())
-// 33: Error Ped. RMS entire signal extr. range   (see MCalibrationChargePix::PedRmsErr())
-//
-// Calculated absolute arrival times (very low precision!):
-// ========================================================
-//
-// 34: Absolute Arrival time of the signal        (see MCalibrationChargePix::GetAbsTimeMean())
-// 35: RMS Ab.  Arrival time of the signal        (see MCalibrationChargePix::GetAbsTimeRms())
+// 28: Pedestal for entire signal extr. range    (see MCalibrationChargePix::Ped())
+// 29: Error Pedestal entire signal extr. range  (see MCalibrationChargePix::PedErr())
+// 30: Ped. RMS entire signal extraction range   (see MCalibrationChargePix::PedRms())
+// 31: Error Ped. RMS entire signal extr. range  (see MCalibrationChargePix::PedRmsErr())
 //
 Bool_t MCalibrationChargeCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
@@ -448,24 +374,10 @@
       if (pix.IsExcluded())
         return kFALSE;
-      if (pix.GetRSigma() == -1.)
-        return kFALSE;
-      if (pix.GetMean() == 0.)
-        return kFALSE;
-      val = pix.GetRSigma() / pix.GetMean();
+      val = pix.GetRSigmaPerCharge();
       break;
     case 8:
       if (pix.IsExcluded())
         return kFALSE;
-      if (pix.GetRSigmaRelVar() <= 0.)
-        return kFALSE;
-      if (pix.GetMeanRelVar() <= 0.)
-        return kFALSE;
-      // relative error Rsigma square
-      val =  pix.GetRSigmaRelVar() + pix.GetMeanRelVar();
-      //a calculate relative error out of squares
-      if (val < 0)
-        val = -1.;
-      else
-        val  =   TMath::Sqrt(val) * pix.GetRSigma() / pix.GetMean();
+      val =  pix.GetRSigmaPerChargeErr();
       break;
     case 9:
@@ -508,34 +420,24 @@
       break;
     case 16:
-      return kFALSE;
+      if (pix.IsExcluded())
+        return kFALSE;
+      val = pix.GetHiLoMeansDivided();
       break;
     case 17:
-      return kFALSE;
+      if (pix.IsExcluded())
+        return kFALSE;
+      val = pix.GetHiLoMeansDividedErr();
       break;
     case 18:
-      return kFALSE;
+      if (pix.IsExcluded())
+        return kFALSE;
+      val = pix.GetHiLoSigmasDivided();
       break;
     case 19:
-      return kFALSE;
+      if (pix.IsExcluded())
+        return kFALSE;
+      val = pix.GetHiLoSigmasDividedErr();
       break;
     case 20:
-      return kFALSE;
-      break;
-    case 21:
-      return kFALSE;
-      break;
-    case 22:
-      return kFALSE;
-      break;
-    case 23:
-      return kFALSE;
-      break;
-    case 24:
-      return kFALSE;
-      break;
-    case 25:
-      return kFALSE;
-      break;
-    case 26:
       if (pix.IsExcluded())
         val = 1.;
@@ -543,48 +445,58 @@
         return kFALSE;
       break;
+    case 21:
+      if (pix.IsExcluded())
+        return kFALSE;
+      val = pix.GetHiGainNumPickup();
+      break;
+    case 22:
+      if (pix.IsExcluded())
+        return kFALSE;
+      val = pix.GetLoGainNumPickup();
+      break;
+    case 23:
+      if (pix.IsExcluded())
+        return kFALSE;
+      val = pix.GetHiGainNumBlackout();
+      break;
+    case 24:
+      if (pix.IsExcluded())
+        return kFALSE;
+      val = pix.GetLoGainNumBlackout();
+      break;
+    case 25:
+      if (pix.IsExcluded())
+        return kFALSE;
+      val = pix.IsHiGainSaturation();
+      break;
+    case 26:
+      if (pix.IsExcluded())
+        return kFALSE;
+      val = pix.GetAbsTimeMean();
+      break;
     case 27:
       if (pix.IsExcluded())
         return kFALSE;
-      val = pix.GetHiGainNumPickup();
+      val = pix.GetAbsTimeRms();
       break;
     case 28:
       if (pix.IsExcluded())
         return kFALSE;
-      val = pix.GetLoGainNumPickup();
+      val = pix.GetPed();
       break;
     case 29:
       if (pix.IsExcluded())
         return kFALSE;
-      val = pix.IsHiGainSaturation();
+      val = pix.GetPedErr();
       break;
     case 30:
       if (pix.IsExcluded())
         return kFALSE;
-      val = pix.GetPed();
+      val = pix.GetPedRms();
       break;
     case 31:
       if (pix.IsExcluded())
         return kFALSE;
-      val = pix.GetPedErr();
-      break;
-    case 32:
-      if (pix.IsExcluded())
-        return kFALSE;
-      val = pix.GetPedRms();
-      break;
-    case 33:
-      if (pix.IsExcluded())
-        return kFALSE;
       val = pix.GetPedErr()/2.;
-      break;
-    case 34:
-      if (pix.IsExcluded())
-        return kFALSE;
-      val = pix.GetAbsTimeMean();
-      break;
-    case 35:
-      if (pix.IsExcluded())
-        return kFALSE;
-      val = pix.GetAbsTimeRms();
       break;
     default:
@@ -593,5 +505,4 @@
 
   return val!=-1.;
-
 }
 
@@ -626,45 +537,2 @@
 
 
-/*
-void MCalibrationChargeCam::DrawHiLoFits()
-{
-
-  if (!fOffsets)
-    fOffsets = new TH1D("pp","Offsets of the HiGain LoGain Fit",100,-600.,400.);
-  if (!fSlopes)
-    fSlopes  = new TH1D("mm","Slopes of the HiGain LoGain Fit",100,-2.,2.);
-  if (!fOffvsSlope)
-    fOffvsSlope = new TH2D("aa","Slopes vs Offsets of the HiGain LoGain Fit",100,-600.,400.,100,-2.,2.);
-
-  TIter Next(fPixels);
-  MCalibrationPix *pix;
-  MHCalibrationPixel *hist;
-  while ((pix=(MCalibrationPix*)Next()))
-    {
-      hist = pix->GetHist();
-      hist->FitHiGainvsLoGain();
-      fOffsets->Fill(hist->GetOffset(),1.);
-      fSlopes->Fill(hist->GetSlope(),1.);
-      fOffvsSlope->Fill(hist->GetOffset(),hist->GetSlope(),1.);
-    }
-
-   TCanvas *c1 = new TCanvas();
-
-   c1->Divide(1,3);
-   c1->cd(1);
-   fOffsets->Draw();
-   gPad->Modified();
-   gPad->Update();
-
-   c1->cd(2);
-  fSlopes->Draw();
-  gPad->Modified();
-  gPad->Update();
-
-  c1->cd(3);
-  fOffvsSlope->Draw("col1");
-  gPad->Modified();
-  gPad->Update();
-}
-
-*/
