Index: trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h	(revision 7188)
@@ -19,8 +19,10 @@
 #pragma link C++ class MCalibrationIntensityCam+;
 #pragma link C++ class MCalibrationIntensityChargeCam+;
+#pragma link C++ class MCalibrationIntensityConstCam+;
 #pragma link C++ class MCalibrationIntensityBlindCam+;
 #pragma link C++ class MCalibrationIntensityQECam+;
 #pragma link C++ class MCalibrationIntensityRelTimeCam+;
 #pragma link C++ class MCalibrationIntensityTestCam+;
+
 #pragma link C++ class MCalibrationCam+;
 #pragma link C++ class MCalibrationPix+;
Index: trunk/MagicSoft/Mars/mcalib/MCalibConstCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibConstCam.cc	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/MCalibConstCam.cc	(revision 7188)
@@ -85,30 +85,33 @@
 // --------------------------------------------------------------------------
 //
-// Set the size of the camera
-//
-void MCalibConstCam::InitSize(const UInt_t i)
-{
-    fArray->ExpandCreate(i);
-}
-
-// -------------------------------------------------------------------
-//
-// Calls TClonesArray::ExpandCreate() for:
-// - fAverageAreas
-//
-void MCalibConstCam::InitAverageAreas(const UInt_t i)
-{
-  fAverageAreas->ExpandCreate(i);
-}
-
-// -------------------------------------------------------------------
-//
-// Calls TClonesArray::ExpandCreate() for:
-// - fAverageSectors
-//
-void MCalibConstCam::InitAverageSectors(const UInt_t i)
-{
-  fAverageSectors->ExpandCreate(i);
-}
+// Copy 'constructor'
+//
+void MCalibConstCam::Copy(TObject &obj) const
+{
+
+  MParContainer::Copy(obj);
+
+  MCalibConstCam &cam = (MCalibConstCam&)obj;
+  
+  Int_t n = GetSize();
+  
+  if (n==0)
+    return;
+  
+  cam.InitSize(n);
+  for (int i=0; i<n; i++)
+    (*this)[i].Copy(cam[i]);
+
+  n = GetNumAverageArea();
+  cam.InitAverageAreas(n);
+  for (int i=0; i<n; i++)
+    GetAverageArea(i).Copy(cam.GetAverageArea(i));
+
+  n = GetNumAverageSector();
+  cam.InitAverageSectors(n);
+  for (int i=0; i<n; i++)
+    GetAverageSector(i).Copy(cam.GetAverageSector(i));
+}
+
 
 // -------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/mcalib/MCalibConstCam.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibConstCam.h	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/MCalibConstCam.h	(revision 7188)
@@ -9,5 +9,8 @@
 #endif
 
-class TClonesArray;
+#ifndef ROOT_TClonesArray
+#include <TClonesArray.h>
+#endif
+
 
 class MGeomCam;
@@ -21,4 +24,6 @@
   TClonesArray *fAverageSectors;  //-> Array of MCalibConstPix, one per camera sector
 
+  Int_t fRunNumber;               // Run number
+  
 public:
 
@@ -27,28 +32,32 @@
   
   void Clear(Option_t *o="");
+  void Copy(TObject &object) const;
   
   // Getters 
-        MCalibConstPix &GetAverageArea   ( UInt_t i );
-  const MCalibConstPix &GetAverageArea   ( UInt_t i )            const;
-  const Int_t           GetNumAverageArea()                      const;
-        MCalibConstPix &GetAverageSector ( UInt_t i );
-  const MCalibConstPix &GetAverageSector ( UInt_t i )            const;
-  const Int_t           GetNumAverageSector()                    const;
-  Int_t                 GetSize          ()                      const;
+        MCalibConstPix &GetAverageArea     ( UInt_t i );
+  const MCalibConstPix &GetAverageArea     ( UInt_t i )  const;
+  const Int_t           GetNumAverageArea  ()            const;
+        MCalibConstPix &GetAverageSector   ( UInt_t i );
+  const MCalibConstPix &GetAverageSector   ( UInt_t i )  const;
+  const Int_t           GetNumAverageSector()            const;
+  Int_t                 GetSize            ()            const;
 
-        MCalibConstPix &operator[]     ( Int_t i             );
-  const MCalibConstPix &operator[]     ( Int_t i             ) const;
+        MCalibConstPix &operator[]         ( Int_t i  );
+  const MCalibConstPix &operator[]         ( Int_t i  )  const;
 
   void  Init                           ( const MGeomCam &geom);
-  void  InitSize                       ( const UInt_t i      );
-  void  InitAverageAreas               ( const UInt_t i      );
-  void  InitAverageSectors             ( const UInt_t i      );
+  void  InitSize                       ( const UInt_t i ) { fArray->ExpandCreate(i);          }
+  void  InitAverageAreas               ( const UInt_t i ) { fAverageAreas->ExpandCreate(i);   }
+  void  InitAverageSectors             ( const UInt_t i ) { fAverageSectors->ExpandCreate(i); }
 
   void Print(Option_t *o="") const;
+
+  // Setters
+  void SetRunNumber( const Int_t n )   {  fRunNumber = n; }
   
-  Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
-  void  DrawPixelContent(Int_t idx) const;
+  Bool_t GetPixelContent (Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
+  void   DrawPixelContent(Int_t idx) const;
 
-  ClassDef(MCalibConstCam, 0)	// Temporary Storage for calibration constants
+  ClassDef(MCalibConstCam, 1)	// Temporary Storage for calibration constants
 };
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibConstPix.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibConstPix.h	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/MCalibConstPix.h	(revision 7188)
@@ -9,18 +9,24 @@
 {
 private:
-
     Float_t fCalibConst;        // conversion factor (modified after each interlaced cal. update)
     Float_t fCalibFFactor;      // global F-Factor   (modified after each interlaced cal. update)
 
 public:
- 
     MCalibConstPix();
-    
+
+    // TObject
     void Clear(Option_t *o="")
-      {
-	fCalibConst   = -1.;
-	fCalibFFactor = -1.;
-      }
-    
+    {
+        fCalibConst   = -1.;
+        fCalibFFactor = -1.;
+    }
+
+    void Copy(TObject &object) const
+    {
+        MCalibConstPix &pix =  (MCalibConstPix&)object;
+        pix.fCalibConst   = fCalibConst;
+        pix.fCalibFFactor = fCalibFFactor;
+    }
+
     // Getters
     Float_t GetCalibConst()   const { return fCalibConst;   }
@@ -31,5 +37,5 @@
     void SetCalibFFactor( const Float_t f )  { fCalibFFactor = f; }
 
-    ClassDef(MCalibConstPix, 0) // Temporay Storage Calibraion Constant of one pixel
+    ClassDef(MCalibConstPix, 1) // Temporay Storage Calibraion Constant of one pixel
 };
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationBlindCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationBlindCam.cc	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationBlindCam.cc	(revision 7188)
@@ -71,28 +71,4 @@
 
 }
-
-// --------------------------------------------------------------------------
-//
-// Copy 'constructor'
-//
-void MCalibrationBlindCam::Copy(TObject& object) const
-{
-  
-  MCalibrationBlindCam &calib = (MCalibrationBlindCam&)object;
-  
-  MCalibrationCam::Copy(calib);
-
-  /*  
-  const UInt_t n = GetSize();
-  if (n != 0)
-    {
-      calib.InitSize(n);
-      for (UInt_t i=0; i<n; i++)
-        (*this)[i].Copy(calib[i]);
-    }
-  */
-}
-
-
 
 // --------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationBlindCam.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationBlindCam.h	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationBlindCam.h	(revision 7188)
@@ -13,12 +13,10 @@
 
 public:
-
   MCalibrationBlindCam(Int_t nblind=1,const char *name=NULL, const char *title=NULL);
   
-  void Copy(TObject& object) const;
-
   // Inits
   void  Init ( const MGeomCam &geom ) {}
 
+  // Getter
   Bool_t IsFluxInsidePlexiglassAvailable () const;
 
@@ -27,4 +25,5 @@
   Float_t GetFluxInsidePlexiglassRelVar() const;
 
+  // Setter
   void  SetPulserColor( const MCalibrationCam::PulserColor_t col );
   
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.cc	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.cc	(revision 7188)
@@ -73,4 +73,17 @@
 //  + fNumSaturated
 //
+// Class Version 4:
+//  +  Float_t fConversionHiLoSigma;             // Sigma of conversion factor betw. Hi and Lo Gain
+//  -  Float_t fMeanConvFADC2PheVar;             // Variance conversion factor (F-factor method)
+//  +  Float_t fMeanConvFADC2PheStatVar;         // Variance conversion factor, only stat. error
+//  +  Float_t fMeanConvFADC2PheSystVar;         // Variance conversion factor, only syst. error
+//  -  Float_t fMeanFFactorFADC2PhotVar;         // Variance mean F-Factor photons (F-factor method)
+//  +  Float_t fMeanFFactorFADC2PhotVar;         // Variance mean F-Factor photons, only stat. error
+//  -  Float_t fPheFFactorMethod;                // Number Phe's calculated (F-factor method)
+//  -  Float_t fPheFFactorMethodVar;             // Variance number of Phe's (F-factor method)
+//  +  Float_t fPheFFactorMethod;                // Number Phe's calculated  with F-factor method)
+//  +  Float_t fPheFFactorMethodStatVar;         // Variance number of Phe's, only stat. error
+//  +  Float_t fPheFFactorMethodSystVar;         // Variance number of Phe's, only syst. error
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MCalibrationChargePix.h"
@@ -90,8 +103,9 @@
 const Float_t MCalibrationChargePix::gkFFactorErr          = 0.02;
 
-const Float_t MCalibrationChargePix::fgConversionHiLo           = 10.;
-const Float_t MCalibrationChargePix::fgConversionHiLoErr        = 2.5;
-const Float_t MCalibrationChargePix::fgPheFFactorMethodLimit    = 1.;
-const Float_t MCalibrationChargePix::fgConvFFactorRelErrLimit   = 0.85;
+const Float_t MCalibrationChargePix::fgConversionHiLo         = 10.;
+const Float_t MCalibrationChargePix::fgConversionHiLoErr      = 0.05;
+const Float_t MCalibrationChargePix::fgConversionHiLoSigma    = 2.5;
+const Float_t MCalibrationChargePix::fgPheFFactorMethodLimit  = 1.;
+const Float_t MCalibrationChargePix::fgConvFFactorRelErrLimit = 0.85;
 
 // --------------------------------------------------------------------------
@@ -157,8 +171,10 @@
 
   fPheFFactorMethod                 =  -1.;
-  fPheFFactorMethodVar              =  -1.;
+  fPheFFactorMethodStatVar          =  -1.;
+  fPheFFactorMethodSystVar          =  -1.;
 
   fMeanConvFADC2Phe                 =  -1.;
-  fMeanConvFADC2PheVar              =  -1.;
+  fMeanConvFADC2PheStatVar          =  -1.;
+  fMeanConvFADC2PheSystVar          =  -1.;
   fMeanFFactorFADC2Phot             =  -1.;
   fMeanFFactorFADC2PhotVar          =  -1.;  
@@ -168,4 +184,42 @@
   MCalibrationPix::Clear();
 }
+
+// -----------------------------------------------------
+//
+void MCalibrationChargePix::Copy(TObject& object) const
+{
+  MCalibrationChargePix &pix = (MCalibrationChargePix&)object;
+  
+  MCalibrationPix::Copy(pix);
+
+  //
+  // Copy the data members
+  //
+  pix.fAbsTimeMean                = fAbsTimeMean              ;
+  pix.fAbsTimeRms                 = fAbsTimeRms               ;
+  pix.fCalibFlags                 = fCalibFlags               ;
+  pix.fConversionHiLo             = fConversionHiLo           ;
+  pix.fConversionHiLoVar          = fConversionHiLoVar        ;
+  pix.fConversionHiLoSigma        = fConversionHiLoSigma      ;
+  pix.fConvFFactorRelVarLimit     = fConvFFactorRelVarLimit   ;
+  pix.fLoGainPedRmsSquare         = fLoGainPedRmsSquare       ;
+  pix.fLoGainPedRmsSquareVar      = fLoGainPedRmsSquareVar    ;
+  pix.fMeanConvFADC2Phe           = fMeanConvFADC2Phe         ;
+  pix.fMeanConvFADC2PheStatVar    = fMeanConvFADC2PheStatVar  ;
+  pix.fMeanConvFADC2PheSystVar    = fMeanConvFADC2PheSystVar  ;
+  pix.fMeanFFactorFADC2Phot       = fMeanFFactorFADC2Phot     ;
+  pix.fMeanFFactorFADC2PhotVar    = fMeanFFactorFADC2PhotVar  ;
+  pix.fPed                        = fPed                      ;
+  pix.fPedVar                     = fPedVar                   ;
+  pix.fPedRms                     = fPedRms                     ;
+  pix.fPedRmsVar                  = fPedRmsVar                  ;
+  pix.fPheFFactorMethod           = fPheFFactorMethod           ;
+  pix.fPheFFactorMethodStatVar    = fPheFFactorMethodStatVar    ;
+  pix.fPheFFactorMethodSystVar    = fPheFFactorMethodSystVar    ;
+  pix.fPheFFactorMethodLimit      = fPheFFactorMethodLimit      ;
+  pix.fRSigmaSquare               = fRSigmaSquare               ;
+  pix.fRSigmaSquareVar            = fRSigmaSquareVar            ;
+  pix.fNumSaturated               = fNumSaturated               ;
+}                                  
 
 
@@ -185,5 +239,4 @@
 void MCalibrationChargePix::SetPedestal(const Float_t ped, const Float_t pedrms, const Float_t pederr)
 {
-
   fPed       = ped;    
   fPedRms    = pedrms;
@@ -197,5 +250,4 @@
 void MCalibrationChargePix::SetPed(const Float_t ped, const Float_t pederr)
 {
-
   fPed       = ped;    
   fPedVar    = pederr*pederr;
@@ -208,23 +260,77 @@
 void MCalibrationChargePix::SetPedRMS( const Float_t pedrms, const Float_t pedrmserr)
 {
-  
   fPedRms    = pedrms;
   fPedRmsVar = pedrmserr*pedrmserr;
-  
-}
-
-
-// -------------------------------------------------------------------------------
-//
-// Get the conversion Error Hi-Gain to Low-Gain:
-// - If fConversionHiLoVar is smaller than 0 (i.e. has not yet been set), return -1.
+}
+
+
+// Inline Functions:
+// -----------------
+//
+// GetConversionHiLoErr:
+//   Get the conversion Error Hi-Gain to Low-Gain:
+//   If fConversionHiLoVar is smaller than 0 (i.e. has not yet
+//   been set), return -1.
 //  
-Float_t MCalibrationChargePix::GetConversionHiLoErr()  const
-{
-  if (fConversionHiLoVar < 0.)
-    return -1.;
-
-  return TMath::Sqrt(fConversionHiLoVar);
-}
+// GetPedRms(): Get the pedestals RMS: Test bit kHiGainSaturation:
+//  If yes, return square root of fLoGainPedRmsSquare (if greater than 0,
+//  otherwise -1.), If no,  return fPedRms
+//
+// GetConvertedMean(): Get the Low Gain Mean Charge converted to High Gain
+//  amplification: Returns fLoGainMean multiplied with fConversionHiLo if
+//  IsHiGainSaturation(), else return fHiGainMean
+//
+// GetConvertedMeanErr(): Get the Error of the converted Low Gain Mean:
+//  Returns -1 if the variable fLoGainMean or fLoGainMeanVar are smaller than 0.
+//  Returns the square root of the quadratic sum of the relative variances of
+//  the fLoGainMean and fConversionHiLo, mulitplied with GetConvertedMean()
+//  in case of HiGain Saturation,
+//  else return GetMeanErr()
+//
+// GetConvertedSigma(): Get the Low Gain Sigma converted to High Gain
+//  amplification: Returns fLoGainSigma multiplied with fConversionHiLo
+//  if IsHiGainSaturation() else return fHiGainSigma
+//
+// GetConvertedSigmaErr(): Get the Error of the converted Sigma:
+//  Returns -1 if the variable fLoGainSigma or fLoGainSigmaVar are smaller than 0.
+//  if IsHiGainSaturatio()
+//  returns the square root of the quadratic sum of the relative variances of
+//  the fLoGainSigma and fConversionHiLo, mulitplied with GetConvertedSigma()
+//  else returns GetSigmaErr()
+//
+// GetConvertedRSigma(): Get the converted reduced Sigma:
+//  If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
+//  Test bit kHiGainSaturation:
+//  If yes, return square root of fRSigmaSquare, multiplied with fConversionHiLo,
+//  If no , return square root of fRSigmaSquare
+//
+// GetRSigma(): Get the reduced Sigma:
+//  If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
+//
+// GetConvertedRSigmaSquare(): Get the reduced Sigma Square:
+//  If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
+//  Test bit kHiGainSaturation:
+//  If yes, return fRSigmaSquare, multiplied with fConversionHiLo^2,
+//  If no , return fRSigmaSquare
+//
+// GetPheFFactorMethodErr(): Get the error on the number of photo-electrons
+//  (F-Factor Method): If fPheFFactorMethodVar is smaller than 0 (i.e. has
+//  not yet been set), return -1. Else returns the square root of
+//  fPheFFactorMethodVar
+//
+// GetMeanFFactorFADC2PhotErr(): Get the error on the mean total F-Factor
+//  of the signal readout (F-Factor Method): If fMeanFFactorFADC2PhotVar
+//  is smaller than 0 (i.e. has not yet been set), return -1. Else returns
+//  the square root of fMeanFFactorFADC2PhotVar
+//
+// GetPheFFactorMethodRelVar(): Get the relative variance on the number of
+//  photo-electrons (F-Factor Method): If fPheFFactorMethodVar is smaller
+//  than 0 (i.e. has not yet been set), return -1. If fPheFFactorMethod
+//  is 0, return -1. Else returns fPheFFactorMethodVar / fPheFFactorMethod^2
+//
+// GetMeanConvFADC2PheErr(): Get the error on the mean conversion factor
+//  (FFactor  Method): If fMeanConvFADC2PheVar is smaller than 0 (i.e. has
+//  not yet been set), return -1. Else returns the square root of
+//  fMeanConvFADC2PheVar
 
 // --------------------------------------------------------------------------
@@ -278,22 +384,4 @@
  
 
-// --------------------------------------------------------------------------
-//
-// Get the pedestals RMS: 
-// - Test bit kHiGainSaturation: 
-//   If yes, return square root of fLoGainPedRmsSquare (if greater than 0, otherwise -1.), 
-//   If no,  return fPedRms
-//
-Float_t  MCalibrationChargePix::GetPedRms()  const
-{
-
-  if (IsHiGainSaturation())
-    if (fLoGainPedRmsSquare < 0.)
-      return -1.;
-    else
-      return TMath::Sqrt(fLoGainPedRmsSquare);
-  
-  return fPedRms;
-}
 
 // --------------------------------------------------------------------------
@@ -321,113 +409,4 @@
 // --------------------------------------------------------------------------
 //
-// Get the Low Gain Mean Charge converted to High Gain amplification: 
-// Returns fLoGainMean multiplied with fConversionHiLo if IsHiGainSaturation(), 
-//         else return fHiGainMean
-//
-Float_t MCalibrationChargePix::GetConvertedMean()  const 
-{
-
-  if (IsHiGainSaturation())
-    return fLoGainMean * fConversionHiLo;
-
-  return fHiGainMean;
-}
-
-// --------------------------------------------------------------------------
-//
-// Get the Error of the converted Low Gain Mean: 
-//
-// Returns -1 if the variable fLoGainMean or fLoGainMeanVar are smaller than 0.
-//
-// Returns the square root of the quadratic sum of the relative variances of 
-// the fLoGainMean and fConversionHiLo, mulitplied with GetConvertedMean()
-// in case of HiGain Saturation, 
-// else return GetMeanErr()
-//
-Float_t MCalibrationChargePix::GetConvertedMeanErr()  const
-{
-
-  if (IsHiGainSaturation())
-    {
-      const Float_t logainrelvar = GetLoGainMeanRelVar();
-      
-      if (logainrelvar < 0.)
-        return -1.;
-
-      return TMath::Sqrt(logainrelvar + GetConversionHiLoRelVar()) * GetConvertedMean();
-    }
-  else
-    return GetMeanErr();
-
-}
-
-// --------------------------------------------------------------------------
-//
-// Get the Low Gain Sigma converted to High Gain amplification: 
-// Returns fLoGainSigma multiplied with fConversionHiLo if IsHiGainSaturation()
-// else return fHiGainSigma
-//
-Float_t MCalibrationChargePix::GetConvertedSigma()  const 
-{
-  
-  if (IsHiGainSaturation())
-    return fLoGainSigma * fConversionHiLo;
-  else
-    return fHiGainSigma;
-}
-
-// --------------------------------------------------------------------------
-//
-// Get the Error of the converted Sigma: 
-//
-// Returns -1 if the variable fLoGainSigma or fLoGainSigmaVar are smaller than 0.
-//
-// if IsHiGainSaturatio()
-// returns the square root of the quadratic sum of the relative variances of 
-// the fLoGainSigma and fConversionHiLo, mulitplied with GetConvertedSigma()
-// else returns GetSigmaErr()
-//
-Float_t MCalibrationChargePix::GetConvertedSigmaErr()  const
-{
-
-  if (IsHiGainSaturation())
-    {
-      if (fLoGainSigmaVar < 0.)
-        return -1.;
-      
-      if (fLoGainSigma < 0.)
-        return -1.;
-      
-      const Float_t sigmaRelVar =  fLoGainSigmaVar
-                                /( fLoGainSigma * fLoGainSigma );
-
-      return TMath::Sqrt(sigmaRelVar+GetConversionHiLoRelVar()) * GetConvertedSigma();
-    }
-  else
-    return GetSigmaErr();
-
-
-}
-
-// --------------------------------------------------------------------------
-//
-// Get the converted reduced Sigma: 
-// - If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
-// - Test bit kHiGainSaturation: 
-//   If yes, return square root of fRSigmaSquare, multiplied with fConversionHiLo, 
-//   If no , return square root of fRSigmaSquare
-//
-Float_t MCalibrationChargePix::GetConvertedRSigma()  const
-{
-  if (fRSigmaSquare < 0)
-    return -1;
-
-  const Float_t rsigma = TMath::Sqrt(fRSigmaSquare);
-  
-  return IsHiGainSaturation() ? rsigma*fConversionHiLo : rsigma ;
-} 
-
-// --------------------------------------------------------------------------
-//
 // Get the error of the converted reduced Sigma: 
 // - If fRSigmaSquareVar is smaller than 0 (i.e. has not yet been set), return -1.
@@ -460,18 +439,4 @@
 // --------------------------------------------------------------------------
 //
-// Get the reduced Sigma: 
-// - If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
-//
-Float_t MCalibrationChargePix::GetRSigma()  const
-{
-  if (fRSigmaSquare < 0)
-    return -1;
-
-  return TMath::Sqrt(fRSigmaSquare);
-  
-} 
-
-// --------------------------------------------------------------------------
-//
 // Get the error of the reduced Sigma: 
 // - If fRSigmaSquareVar is smaller than 0 (i.e. has not yet been set), return -1.
@@ -540,20 +505,4 @@
   
   return TMath::Sqrt(rsigmarelvar + meanrelvar) * GetRSigmaPerCharge();
-} 
-
-// --------------------------------------------------------------------------
-//
-// Get the reduced Sigma Square: 
-// - If fRSigmaSquare is smaller than 0 (i.e. has not yet been set), return -1.
-// - Test bit kHiGainSaturation: 
-//   If yes, return fRSigmaSquare, multiplied with fConversionHiLo^2, 
-//   If no , return fRSigmaSquare
-//
-Float_t MCalibrationChargePix::GetConvertedRSigmaSquare()  const
-{
-  if (fRSigmaSquare < 0)
-    return -1;
-
-  return IsHiGainSaturation() ? fRSigmaSquare*fConversionHiLo*fConversionHiLo : fRSigmaSquare ;
 } 
 
@@ -582,60 +531,5 @@
 }
 
-// --------------------------------------------------------------------------
-//
-// Get the error on the number of photo-electrons (F-Factor Method):
-// - If fPheFFactorMethodVar is smaller than 0 (i.e. has not yet been set), return -1.
-// - Else returns the square root of fPheFFactorMethodVar
-//
-Float_t MCalibrationChargePix::GetPheFFactorMethodErr()  const
-{
-  if (fPheFFactorMethodVar < 0.)
-    return -1.;
-  return TMath::Sqrt(fPheFFactorMethodVar);
-}
-
-// --------------------------------------------------------------------------
-//
-// Get the error on the mean total F-Factor of the signal readout (F-Factor Method):
-// - If fMeanFFactorFADC2PhotVar is smaller than 0 (i.e. has not yet been set), return -1.
-// - Else returns the square root of fMeanFFactorFADC2PhotVar
-//
-Float_t MCalibrationChargePix::GetMeanFFactorFADC2PhotErr()  const
-{
-  if (fMeanFFactorFADC2PhotVar < 0.)
-    return -1.;
-  return TMath::Sqrt(fMeanFFactorFADC2PhotVar);
-}
-
-// --------------------------------------------------------------------------
-//
-// Get the relative variance on the number of photo-electrons (F-Factor Method):
-// - If fPheFFactorMethodVar is smaller than 0 (i.e. has not yet been set), return -1.
-// - If fPheFFactorMethod    is 0, return -1.
-// - Else returns fPheFFactorMethodVar / fPheFFactorMethod^2
-//
-Float_t MCalibrationChargePix::GetPheFFactorMethodRelVar()  const
-{
-  if (fPheFFactorMethodVar < 0.)
-    return -1.;
-  if (fPheFFactorMethod  == 0.)
-    return -1.;
-
-  return fPheFFactorMethodVar / (fPheFFactorMethod * fPheFFactorMethod);
-}
-
-
-// --------------------------------------------------------------------------
-//
-// Get the error on the mean conversion factor (FFactor  Method):
-// - If fMeanConvFADC2PheVar is smaller than 0 (i.e. has not yet been set), return -1.
-// - Else returns the square root of fMeanConvFADC2PheVar
-//
-Float_t MCalibrationChargePix::GetMeanConvFADC2PheErr()  const
-{
-  if (fMeanConvFADC2PheVar < 0.)
-    return -1.;
-  return TMath::Sqrt(fMeanConvFADC2PheVar);
-}
+
 
 // --------------------------------------------------------------------------
@@ -803,6 +697,7 @@
   // Calculate the Error of Nphe
   //
-  const Float_t pheRelVar = ffactorsquareRelVar + meanSquareRelVar + rsigmaSquareRelVar;
-  fPheFFactorMethodVar    = pheRelVar * fPheFFactorMethod * fPheFFactorMethod;
+  const Float_t pheRelVar  = meanSquareRelVar + rsigmaSquareRelVar;
+  fPheFFactorMethodStatVar = pheRelVar * fPheFFactorMethod * fPheFFactorMethod;
+  fPheFFactorMethodSystVar = ffactorsquareRelVar * fPheFFactorMethod * fPheFFactorMethod;
 
   if (IsDebug())
@@ -816,5 +711,5 @@
     }
 
-  if (fPheFFactorMethodVar < 0. )
+  if (fPheFFactorMethodStatVar < 0. )
     return kFALSE;
 
@@ -879,5 +774,8 @@
   // the errors, but have to take account of this cancellation:
   // 
-  Float_t convrelvar = ffactorsquareRelVar + GetMeanRelVar() + rsigmaSquareRelVar;
+  Float_t convrelvar = GetMeanRelVar() + rsigmaSquareRelVar;
+  if (IsHiGainSaturation())
+      convrelvar += GetConversionHiLoRelVar();
+
   const Float_t limit = IsHiGainSaturation() ? fConvFFactorRelVarLimit * 4. : fConvFFactorRelVarLimit;
 
@@ -906,5 +804,6 @@
     }
   
-  fMeanConvFADC2PheVar =  convrelvar * fMeanConvFADC2Phe * fMeanConvFADC2Phe;
+  fMeanConvFADC2PheStatVar = convrelvar * fMeanConvFADC2Phe  * fMeanConvFADC2Phe;
+  fMeanConvFADC2PheSystVar = ffactorsquareRelVar * fMeanConvFADC2Phe * fMeanConvFADC2Phe;
   
   SetFFactorMethodValid(kTRUE);
@@ -967,5 +866,5 @@
                               + 0.25 * nphotonsrelvar;
   
-  fMeanFFactorFADC2PhotVar    = ffactorrelvar * fMeanFFactorFADC2Phot * fMeanFFactorFADC2Phot;
+  fMeanFFactorFADC2PhotVar = ffactorrelvar * fMeanFFactorFADC2Phot * fMeanFFactorFADC2Phot;
 
   if (IsDebug())
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.h	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.h	(revision 7188)
@@ -17,4 +17,5 @@
   static const Float_t fgConversionHiLo;         //! Default fConversionHiLo          (now set to: 10.)
   static const Float_t fgConversionHiLoErr;      //! Default fConversionHiLoVar       (now set to: 2.5)
+  static const Float_t fgConversionHiLoSigma;    //! Default fConversionHiLoSigma     (now set to: 2.5)
   static const Float_t fgPheFFactorMethodLimit;  //! Default fPheFFactorMethodLimit   (now set to: 5.)
   static const Float_t fgConvFFactorRelErrLimit; //! Default fConvFFactorRelErrLimit  (now set to: 0.35)  
@@ -25,17 +26,20 @@
   Float_t fConversionHiLo;                  // Conversion factor betw. Hi Gain and Lo Gain  
   Float_t fConversionHiLoVar;               // Variance Conversion factor betw. Hi and Lo Gain
+  Float_t fConversionHiLoSigma;             // Sigma of conversion factor betw. Hi and Lo Gain
   Float_t fConvFFactorRelVarLimit;          // Limit for acceptance rel. variance Conversion FADC2Phe
   Float_t fLoGainPedRmsSquare;              // Pedestal RMS square of Low Gain
   Float_t fLoGainPedRmsSquareVar;           // Pedestal RMS square Variance of Low Gain
   Float_t fMeanConvFADC2Phe;                // Conversion factor (F-factor method)
-  Float_t fMeanConvFADC2PheVar;             // Variance conversion factor (F-factor method)
+  Float_t fMeanConvFADC2PheStatVar;         // Variance conversion factor, only stat. error
+  Float_t fMeanConvFADC2PheSystVar;         // Variance conversion factor, only syst. error
   Float_t fMeanFFactorFADC2Phot;            // Total mean F-Factor to photons (F-factor method)
-  Float_t fMeanFFactorFADC2PhotVar;         // Variance mean F-Factor photons (F-factor method)  
+  Float_t fMeanFFactorFADC2PhotVar;         // Variance mean F-Factor photons, only stat. error
   Float_t fPed;                             // Pedestal (from MPedestalPix) times number FADC slices
   Float_t fPedVar;                          // Variance of pedestal 
   Float_t fPedRms;                          // Pedestal RMS (from MPedestalPix) times sqrt nr. FADC slices
   Float_t fPedRmsVar;                       // Pedestal RMS (from MPedestalPix) times sqrt nr. FADC slices
-  Float_t fPheFFactorMethod;                // Number Phe's calculated (F-factor method)
-  Float_t fPheFFactorMethodVar;             // Variance number of Phe's (F-factor method)
+  Float_t fPheFFactorMethod;                // Number Phe's calculated  with F-factor method)
+  Float_t fPheFFactorMethodStatVar;         // Variance number of Phe's, only stat. error
+  Float_t fPheFFactorMethodSystVar;         // Variance number of Phe's, only syst. error
   Float_t fPheFFactorMethodLimit;           // Min. number Photo-electrons for pix to be accepted.
   Float_t fRSigmaSquare;                    // Square of Reduced sigma
@@ -51,61 +55,129 @@
   
 public:
+  MCalibrationChargePix(const char *name=NULL, const char *title=NULL);
 
-  MCalibrationChargePix(const char *name=NULL, const char *title=NULL);
-  
+  // TObject
   void Clear(Option_t *o="");
+  void Copy(TObject& object) const;
 
   // Setter
-  void SetAbsTimeMean ( const Float_t f ) { fAbsTimeMean = f; }
-  void SetAbsTimeRms  ( const Float_t f ) { fAbsTimeRms  = f; }
-  void SetConversionHiLo    ( const Float_t c=fgConversionHiLo    )        { fConversionHiLo    = c;       }
-  void SetConversionHiLoErr ( const Float_t e=fgConversionHiLoErr )        { fConversionHiLoVar = e*e;     }
+  /*
   void SetConvFFactorRelErrLimit   ( const Float_t f=fgConvFFactorRelErrLimit) { fConvFFactorRelVarLimit = f*f;}
-  void SetFFactorMethodValid   ( const Bool_t b = kTRUE );
   void SetMeanConvFADC2Phe      ( const Float_t f)                          { fMeanConvFADC2Phe       = f; }
   void SetMeanConvFADC2PheVar   ( const Float_t f)                          { fMeanConvFADC2PheVar    = f; }
   void SetMeanFFactorFADC2Phot  ( const Float_t f)                          { fMeanFFactorFADC2Phot   = f; }
-  void SetPedestal              ( const Float_t ped, const Float_t pedrms, const Float_t pederr);
-  void SetPed                   ( const Float_t ped, const Float_t pederr);  
-  void SetPedRMS              ( const Float_t pedrms, const Float_t pedrmserr);  
   void SetPheFFactorMethod      ( const Float_t f)                          { fPheFFactorMethod       = f; }
   void SetPheFFactorMethodVar   ( const Float_t f)                          { fPheFFactorMethodVar    = f; }  
   void SetPheFFactorMethodLimit ( const Float_t f=fgPheFFactorMethodLimit ) { fPheFFactorMethodLimit  = f; }
   void SetNumSaturated          ( const Int_t   i)                          { fNumSaturated           = i; }
+  */
+  void SetFFactorMethodValid     (const Bool_t b = kTRUE );
+  void SetPedestal               (const Float_t ped, const Float_t pedrms, const Float_t pederr);
+  void SetPed                   ( const Float_t ped, const Float_t pederr);  
+  void SetPedRMS              ( const Float_t pedrms, const Float_t pedrmserr);  
+
+  void SetAbsTimeMean            (const Float_t f)                          { fAbsTimeMean            = f; }
+  void SetAbsTimeRms             (const Float_t f)                          { fAbsTimeRms             = f; }
+  void SetConversionHiLo         (const Float_t c=fgConversionHiLo        ) { fConversionHiLo         = c; }
+  void SetConversionHiLoErr      (const Float_t e=fgConversionHiLoErr     ) { fConversionHiLoVar      = e*e;}
+  void SetConversionHiLoSigma    (const Float_t s=fgConversionHiLoSigma   ) { fConversionHiLoSigma    = s; }
+  void SetConvFFactorRelErrLimit (const Float_t f=fgConvFFactorRelErrLimit) { fConvFFactorRelVarLimit = f*f;}
+  void SetMeanConvFADC2Phe       (const Float_t f)                          { fMeanConvFADC2Phe       = f; }
+  void SetMeanConvFADC2PheVar    (const Float_t f)                          { fMeanConvFADC2PheStatVar= f; }
+  void SetMeanConvFADC2PheSystVar(const Float_t f)                          { fMeanConvFADC2PheSystVar= f; }
+  void SetMeanFFactorFADC2Phot   (const Float_t f)                          { fMeanFFactorFADC2Phot   = f; }
+  void SetNumSaturated           (const Int_t   i)                          { fNumSaturated           = i; }
+  void SetPheFFactorMethod       (const Float_t f)                          { fPheFFactorMethod       = f; }
+  void SetPheFFactorMethodVar    (const Float_t f)                          { fPheFFactorMethodStatVar= f; }
+  void SetPheFFactorMethodSystVar(const Float_t f)                          { fPheFFactorMethodSystVar= f; }
+  void SetPheFFactorMethodLimit  (const Float_t f=fgPheFFactorMethodLimit ) { fPheFFactorMethodLimit  = f; }
   
   // Getters
-  Float_t GetAbsTimeMean             () const { return fAbsTimeMean;             }
-  Float_t GetAbsTimeRms              () const { return fAbsTimeRms;              }
-  Float_t GetConversionHiLo          () const { return fConversionHiLo;          }
-  Float_t GetConversionHiLoErr       () const;
-  Float_t GetConvertedMean           () const;
-  Float_t GetConvertedMeanErr        () const;
-  Float_t GetConvertedSigma          () const;
-  Float_t GetConvertedSigmaErr       () const;
-  Float_t GetConvertedRSigma         () const;
-  Float_t GetConvertedRSigmaErr      () const;
-  Float_t GetConvertedRSigmaSquare   () const;  
-  Float_t GetMeanConvFADC2Phe        () const { return fMeanConvFADC2Phe;        } 
-  Float_t GetMeanConvFADC2PheErr     () const;
-  Float_t GetMeanConvFADC2PheVar     () const { return fMeanConvFADC2PheVar;     }
-  Float_t GetMeanFFactorFADC2Phot    () const { return fMeanFFactorFADC2Phot;    }
-  Float_t GetMeanFFactorFADC2PhotErr () const;
-  Float_t GetMeanFFactorFADC2PhotVar () const { return fMeanFFactorFADC2PhotVar; }    
-  Int_t   GetNumSaturated            () const { return fNumSaturated;            }
-  Float_t GetPed                     () const { return fPed;                     }
-  Float_t GetPedErr                  () const { return TMath::Sqrt(fPedVar);     }
-  Float_t GetPedRms                  () const;
-  Float_t GetPedRmsErr               () const;
-  Float_t GetPheFFactorMethod        () const { return fPheFFactorMethod;        }    
-  Float_t GetPheFFactorMethodErr     () const;
-  Float_t GetPheFFactorMethodVar     () const { return fPheFFactorMethodVar;     }
-  Float_t GetPheFFactorMethodRelVar  () const;
-  Float_t GetRSigma                  () const;
-  Float_t GetRSigmaErr               () const;
-  Float_t GetRSigmaRelVar            () const;
-  Float_t GetRSigmaPerCharge         () const;
-  Float_t GetRSigmaPerChargeErr      () const;
+  Float_t GetAbsTimeMean        () const { return fAbsTimeMean;    }
+  Float_t GetAbsTimeRms         () const { return fAbsTimeRms;     }
+  Float_t GetConversionHiLo     () const { return fConversionHiLo; }
+  Float_t GetConversionHiLoErr  () const { return fConversionHiLoVar<0 ? -1 : TMath::Sqrt(fConversionHiLoVar);  }
+  Float_t GetConversionHiLoSigma() const { return fConversionHiLoSigma; }
+  Float_t GetConvertedMean      () const { return IsHiGainSaturation() ? fLoGainMean * fConversionHiLo : fHiGainMean; }
+  Float_t GetConvertedMeanErr   () const
+  {
+      if (!IsHiGainSaturation())
+          return GetMeanErr();
+      const Float_t logainrelvar = GetLoGainMeanRelVar();
+      return logainrelvar<0 ? -1 : TMath::Sqrt(logainrelvar + GetConversionHiLoRelVar()) * GetConvertedMean();
+  }
+  Float_t GetConvertedSigma() const { return IsHiGainSaturation() ? fLoGainSigma * fConversionHiLo : fHiGainSigma; }
+  Float_t GetConvertedSigmaErr() const
+  {
+    if (!IsHiGainSaturation())
+        return GetSigmaErr();
 
-  Bool_t IsFFactorMethodValid        () const;
+    if (fLoGainSigmaVar<0 || fLoGainSigma<0)
+        return -1.;
+
+    const Float_t sigmaRelVar = fLoGainSigmaVar/(fLoGainSigma*fLoGainSigma);
+    return TMath::Sqrt(sigmaRelVar+GetConversionHiLoRelVar()) * GetConvertedSigma();
+  }
+  Float_t GetConvertedRSigma() const
+  {
+      if (fRSigmaSquare < 0)
+          return -1;
+      const Float_t rsigma = TMath::Sqrt(fRSigmaSquare);
+      return IsHiGainSaturation() ? rsigma*fConversionHiLo : rsigma ;
+  }
+  Float_t GetConvertedRSigmaErr() const;
+  Float_t GetConvertedRSigmaSquare() const
+  {
+      if (fRSigmaSquare < 0)
+          return -1;
+      return IsHiGainSaturation() ? fRSigmaSquare*fConversionHiLo*fConversionHiLo : fRSigmaSquare ;
+  }
+  Float_t GetMeanConvFADC2Phe() const { return fMeanConvFADC2Phe; }
+  Float_t GetMeanConvFADC2PheErr  () const { return fMeanConvFADC2PheStatVar<0 ? -1 : TMath::Sqrt(fMeanConvFADC2PheStatVar); }
+  Float_t GetMeanConvFADC2PheSystErr() const { return fMeanConvFADC2PheSystVar<0 ? -1 : TMath::Sqrt(fMeanConvFADC2PheSystVar); }
+  Float_t GetMeanConvFADC2PheTotErr() const
+  {
+      if (fMeanConvFADC2PheSystVar<0 || fMeanConvFADC2PheStatVar<0)
+          return -1.;
+      return TMath::Sqrt(fMeanConvFADC2PheSystVar+fMeanConvFADC2PheStatVar);
+  }
+  Float_t GetFFactorFADC2Phe        () const { return gkFFactor;   }
+  Float_t GetMeanConvFADC2PheVar    () const { return fMeanConvFADC2PheStatVar; }
+  Float_t GetMeanConvFADC2PheSystVar() const { return fMeanConvFADC2PheSystVar; }
+
+  Float_t GetMeanFFactorFADC2Phot   () const { return fMeanFFactorFADC2Phot;    }
+  Float_t GetMeanFFactorFADC2PhotErr() const { return fMeanFFactorFADC2PhotVar<0 ? -1. : TMath::Sqrt(fMeanFFactorFADC2PhotVar); }
+  Float_t GetMeanFFactorFADC2PhotVar() const { return fMeanFFactorFADC2PhotVar; }
+  Int_t   GetNumSaturated           () const { return fNumSaturated;            }    
+  Float_t GetPed                    () const { return fPed;                     }
+  Float_t GetPedErr                 () const { return TMath::Sqrt(fPedVar);     }
+  Float_t GetPedRms                 () const
+  {
+    if (!IsHiGainSaturation())
+        return fPedRms;
+    return fLoGainPedRmsSquare<0 ? -1 : TMath::Sqrt(fLoGainPedRmsSquare);
+  }
+  Float_t GetPedRmsErr              () const;
+  Float_t GetPheFFactorMethod       () const { return fPheFFactorMethod; }
+  Float_t GetPheFFactorMethodErr    () const { return fPheFFactorMethodStatVar<0 ? -1 : TMath::Sqrt(fPheFFactorMethodStatVar); }
+  Float_t GetPheFFactorMethodSystErr() const { return fPheFFactorMethodSystVar<0 ? -1 : TMath::Sqrt(fPheFFactorMethodSystVar); }
+  Float_t GetPheFFactorMethodTotErr () const
+  {
+      if (fPheFFactorMethodStatVar<0 || fPheFFactorMethodSystVar<0)
+          return -1.;
+      return TMath::Sqrt(fPheFFactorMethodStatVar+fPheFFactorMethodSystVar);
+  }
+  Float_t GetPheFFactorMethodVar    () const { return fPheFFactorMethodStatVar; }
+  Float_t GetPheFFactorMethodSystVar() const { return fPheFFactorMethodSystVar; }
+  Float_t GetPheFFactorMethodRelVar () const { return fPheFFactorMethodStatVar<=0 ? -1 : fPheFFactorMethodStatVar / (fPheFFactorMethod * fPheFFactorMethod); }
+  Float_t GetPheFFactorMethodRelSystVar() const { return fPheFFactorMethodSystVar<=0 ? -1. : fPheFFactorMethodSystVar / (fPheFFactorMethod * fPheFFactorMethod); }
+  Float_t GetRSigma                 () const { return fRSigmaSquare<0 ? -1 : TMath::Sqrt(fRSigmaSquare); }
+
+  Float_t GetRSigmaErr         () const;
+  Float_t GetRSigmaRelVar      () const;
+  Float_t GetRSigmaPerCharge   () const;
+  Float_t GetRSigmaPerChargeErr() const;
+
+  Bool_t IsFFactorMethodValid() const;
 
   // Calculations
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationHiLoPix.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationHiLoPix.cc	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationHiLoPix.cc	(revision 7188)
@@ -18,20 +18,25 @@
 !   Author(s): Markus Gaug   02/2004 <mailto:markus@ifae.es>
 !
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Copyright: MAGIC Software Development, 2000-2005
 !
 \* ======================================================================== */
 /////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MCalibrationHiLoPix                                                     //
-//                                                                         //
-// Storage container for high-gain vs. low-gain charge calibration results // 
-// of one Pixel (PMT).                                                     //
-// The following "calibration" constants can be retrieved:                 //
+//
+// MCalibrationHiLoPix
+//
+// Storage container for high-gain vs. low-gain charge calibration results
+// of one Pixel (PMT).
+// The following "calibration" constants can be retrieved:
 // - GetHiLoRatio(): The mean conversion High-gain vs. Low-gain
 //   with which the low-gain result has to be multiplied
-// - GetHiLoSigma(): The Gauss sigma of histogrammed High-gain vs. Low-gain ratios
+// - GetHiLoSigma(): The Gauss sigma of histogrammed High-gain vs.
+//   Low-gain ratios
 //
-// See also: MHCalibrationHiLoPix, MHCalibrationHiLoCam              //
-//                                                                         //
+// See also: MHCalibrationHiLoPix, MHCalibrationHiLoCam
+//
+// Class Version 2:
+//  + Float_t fOffsetPerSlice;  // Offset from fit (per FADC slice)
+//  + Float_t fGainRatio;       // Ratio of gains from fit
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MCalibrationHiLoPix.h"
@@ -46,4 +51,5 @@
 //
 MCalibrationHiLoPix::MCalibrationHiLoPix(const char *name, const char *title)
+  : fOffsetPerSlice(-9999.), fGainRatio(-1.)
 {
 
@@ -52,3 +58,2 @@
 
 }
-
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationHiLoPix.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationHiLoPix.h	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationHiLoPix.h	(revision 7188)
@@ -9,10 +9,15 @@
 {
 private:
+    Float_t fOffsetPerSlice;            // Offset from fit (per FADC slice)
+    Float_t fGainRatio;                 // Ratio of gains from fit
 
 public:
+  MCalibrationHiLoPix(const char *name=NULL, const char *title=NULL);
 
-  MCalibrationHiLoPix(const char *name=NULL, const char *title=NULL);
-  ~MCalibrationHiLoPix() {}
-  
+  // Setter
+  void SetGainRatio     (const Float_t f) { fGainRatio      = f; }
+  void SetOffsetPerSlice(const Float_t f) { fOffsetPerSlice = f; }
+
+  // Getter
   Float_t GetHiLoChargeRatio()         const { return GetHiGainMean();     }
   Float_t GetHiLoChargeRatioErr()      const { return GetHiGainMeanErr();  }
@@ -26,6 +31,8 @@
   Float_t GetHiLoTimeDiffSigmaErr()    const { return GetLoGainSigmaErr(); }
   Float_t GetHiLoTimeDiffProb()        const { return GetLoGainProb();     }
+  Float_t GetGainRatio     ()          const { return fGainRatio;          }
+  Float_t GetOffsetPerSlice()          const { return fOffsetPerSlice;     }
 
-  ClassDef(MCalibrationHiLoPix, 1)	// Container HiLo conversion Calibration Results Pixel
+  ClassDef(MCalibrationHiLoPix, 2)	// Container HiLo conversion Calibration Results Pixel
 };
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityChargeCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityChargeCam.cc	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityChargeCam.cc	(revision 7188)
@@ -594,9 +594,14 @@
           varerr[i] = pix.GetRSigmaErr();
         }
-      if (option.Contains("abstime"))
+      if (option.Contains("abstimemean"))
         {
           var   [i] = pix.GetAbsTimeMean();
           varerr[i] = pix.GetAbsTimeRms();
         }
+      if (option.Contains("abstimerms"))
+        {
+          var   [i] = pix.GetAbsTimeRms();
+          varerr[i] = pix.GetAbsTimeRms()/2.;
+        }
       if (option.Contains("blackout"))
         {
@@ -663,4 +668,14 @@
           var   [i] = pix.GetRSigmaPerCharge();
           varerr[i] = pix.GetRSigmaPerChargeErr();
+        }
+      if (option.Contains("conversionfactor"))
+        {
+          const MCalibrationChargePix &apix = (MCalibrationChargePix&)cam->GetAverageArea(0);
+          const Float_t mean = pix.GetConvertedMean();
+          const Float_t phe  = apix.GetPheFFactorMethod();
+
+          var[i]    = phe/mean;
+          varerr[i] = TMath::Sqrt(apix.GetPheFFactorMethodErr()*apix.GetPheFFactorMethodErr()/mean/mean
+                                  + phe*phe/mean/mean/mean/mean*pix.GetConvertedMeanErr()*pix.GetConvertedMeanErr());
         }
   }
@@ -735,7 +750,328 @@
           
           if (option.Contains("rsigma"))
+              pvar = pix.GetRSigma();
+          if (option.Contains("abstimemean"))
+              pvar = pix.GetAbsTimeMean();
+          if (option.Contains("abstimerms"))
+              pvar = pix.GetAbsTimeRms();
+          if (option.Contains("conversionhilo"))
+              pvar = pix.GetConversionHiLo();
+          if (option.Contains("convertedmean"))
+              pvar = pix.GetConvertedMean();
+          if (option.Contains("convertedsigma"))
+              pvar = pix.GetConvertedSigma();
+          if (option.Contains("convertedrsigma"))
+              pvar = pix.GetConvertedRSigma();
+          if (option.Contains("meanconvfadc2phe"))
+              pvar = pix.GetMeanConvFADC2Phe();
+          if (option.Contains("meanffactorfadc2phot"))
+              pvar = pix.GetMeanFFactorFADC2Phot();
+          if (option.Contains("ped"))
+              pvar = pix.GetPed();
+          if (option.Contains("pedrms"))
+              pvar = pix.GetPedRms();
+          if (option.Contains("pheffactormethod"))
+              pvar = pix.GetPheFFactorMethod();
+          if (option.Contains("rsigmapercharge"))
+              pvar = pix.GetRSigmaPerCharge();
+          if (option.Contains("conversionfactor"))
+          {
+              const MCalibrationChargePix &apix = (MCalibrationChargePix&)cam->GetAverageArea(aidx);
+              pvar = apix.GetPheFFactorMethod()/pix.GetConvertedMean();
+          }
+
+
+          variab  += pvar;
+          variab2 += pvar*pvar;
+          num++;
+          
+          camcharge.Fill(j,pvar);
+          camcharge.SetUsed(j);
+        }
+      
+      if (num > 1)
+        {
+          variab  /= num;
+          variance = (variab2 - variab*variab*num) / (num-1);
+
+          vararea[i]    = variab;
+          varareaerr[i] = variance>0 ? TMath::Sqrt(variance/num) : 999999999.;
+
+          //
+          // Make also a Gauss-fit to the distributions. The RMS can be determined by 
+          // outlier, thus we look at the sigma and the RMS and take the smaller one, afterwards.
+          // 
+          h = camcharge.ProjectionS(TArrayI(),TArrayI(1,&aidx),"_py",750);
+          h->SetDirectory(NULL);
+          h->Fit("gaus","QL");
+          TF1 *fit = h->GetFunction("gaus");
+
+          Float_t ci2   = fit->GetChisquare();
+          Float_t sigma = fit->GetParameter(2);
+
+          if (ci2 > 500. || sigma > varareaerr[i])
+            {
+              h->Fit("gaus","QLM");
+              fit = h->GetFunction("gaus");
+
+              ci2   = fit->GetChisquare();
+              sigma = fit->GetParameter(2);
+            }
+          
+          const Float_t mean  = fit->GetParameter(1);
+          const Float_t ndf   = fit->GetNDF();
+          
+          *fLog << inf << "Camera Nr: " << i << endl;
+          *fLog << inf << option.Data() << " area idx: " << aidx << " Results: " << endl;
+          *fLog << inf << "Mean: " << Form("%4.3f",mean) 
+                << "+-" << Form("%4.3f",fit->GetParError(1))
+                << "  Sigma: " << Form("%4.3f",sigma) << "+-" << Form("%4.3f",fit->GetParError(2)) 
+                << "  Chisquare: " << Form("%4.3f",ci2) << "  NDF  : " << ndf << endl;
+          delete h;
+          gROOT->GetListOfFunctions()->Remove(fit);
+
+          if (sigma<varareaerr[i] && ndf>2 && ci2<500.)
+            {
+              vararea   [i] = mean;
+              varareaerr[i] = sigma/TMath::Sqrt((Float_t)num);
+            }
+        }
+      else
+        {
+          vararea[i]    = -1.;
+          varareaerr[i] = 0.;
+        }
+
+      nr[i] = i;
+      nrerr[i] = 0.;
+    }
+  
+  TGraphErrors *gr = new TGraphErrors(size,
+                                     nr.GetArray(),vararea.GetArray(),
+                                     nrerr.GetArray(),varareaerr.GetArray());
+  gr->SetTitle(Form("%s Area %3i Average",option.Data(),aidx));
+  gr->GetXaxis()->SetTitle("Camera Nr.");
+  //  gr->GetYaxis()->SetTitle("<Q> [1]");      
+  return gr;
+}
+
+
+// -------------------------------------------------------------------
+//
+// Returns a TGraphErrors with the mean effective number of photon
+// vs. the calibration camera number. With the string 'method', different
+// calibration methods can be called.
+//
+TGraphErrors *MCalibrationIntensityChargeCam::GetPhotVsTime( const Option_t *method )
+{
+  
+  const Int_t size = GetSize();
+  
+  if (size == 0)
+    return NULL;
+
+  TString option(method);
+
+  TArrayF photarr(size);
+  TArrayF photarrerr(size);
+  TArrayF nr(size);
+  TArrayF nrerr(size);
+  
+  for (Int_t i=0;i<GetSize();i++)
+    {
+      //
+      // Get the calibration cam from the intensity cam
+      //
+      MCalibrationChargeCam *cam = (MCalibrationChargeCam*)GetCam(i);
+
+      //
+      // Get the calibration pix from the calibration cam
+      //
+      Float_t phot    = 0.;
+      Float_t photerr = 0.;
+
+      if (option.Contains("BlindPixel"))
+        {
+          phot    = cam->GetNumPhotonsBlindPixelMethod();
+          photerr = cam->GetNumPhotonsBlindPixelMethodErr();
+        }
+      if (option.Contains("FFactor"))
+        {
+          phot    = cam->GetNumPhotonsFFactorMethod();
+          photerr = cam->GetNumPhotonsFFactorMethodErr();
+        }
+      if (option.Contains("PINDiode"))
+        {
+          phot    = cam->GetNumPhotonsPINDiodeMethod();
+          photerr = cam->GetNumPhotonsPINDiodeMethodErr();
+        }
+
+      photarr[i]       = phot;
+      photarrerr[i]    = photerr;
+
+      nr[i] = i;
+      nrerr[i] = 0.;
+    }
+  
+  TGraphErrors *gr = new TGraphErrors(size,
+                                     nr.GetArray(),photarr.GetArray(),
+                                     nrerr.GetArray(),photarrerr.GetArray());
+  gr->SetTitle("Photons Average");
+  gr->GetXaxis()->SetTitle("Camera Nr.");
+  gr->GetYaxis()->SetTitle("<N_{phot}> [1]");
+  return gr;
+}
+
+// -------------------------------------------------------------------
+//
+// Returns a TGraphErrors with the mean effective number of photo-electrons per 
+// area index 'aidx' vs. the calibration camera number 
+//
+TGraphErrors *MCalibrationIntensityChargeCam::GetPhePerAreaVsTime( const Int_t aidx, const MGeomCam &geom)
+{
+  
+  const Int_t size = GetSize();
+  
+  if (size == 0)
+    return NULL;
+  
+  TArrayF phearea(size);
+  TArrayF pheareaerr(size);
+  TArrayF time(size);
+  TArrayF timeerr(size);
+  
+  for (Int_t i=0;i<GetSize();i++)
+    {
+      //
+      // Get the calibration cam from the intensity cam
+      //
+      MCalibrationChargeCam *cam = (MCalibrationChargeCam*)GetCam(i);
+
+      //
+      // Get the calibration pix from the calibration cam
+      //
+      const MCalibrationChargePix &apix = (MCalibrationChargePix&)cam->GetAverageArea(aidx);
+      const Float_t phe          = apix.GetPheFFactorMethod();
+      const Float_t pheerr       = apix.GetPheFFactorMethodErr();
+
+      phearea[i]       = phe;
+      pheareaerr[i]    = pheerr;
+
+      time[i] = i;
+      timeerr[i] = 0.;
+    }
+  
+  TGraphErrors *gr = new TGraphErrors(size,
+                                     time.GetArray(),phearea.GetArray(),
+                                     timeerr.GetArray(),pheareaerr.GetArray());
+  gr->SetTitle(Form("Phes Area %d Average",aidx));
+  gr->GetXaxis()->SetTitle("Camera Nr.");
+  gr->GetYaxis()->SetTitle("<N_{phe}> [1]");
+  return gr;
+}
+
+// -------------------------------------------------------------------
+//
+// Returns a TGraphErrors with the event-by-event averaged charge per 
+// area index 'aidx' vs. the calibration camera number 
+//
+TGraphErrors *MCalibrationIntensityChargeCam::GetChargePerAreaVsTime( const Int_t aidx, const MGeomCam &geom)
+{
+  
+  const Int_t size = GetSize();
+  
+  if (size == 0)
+    return NULL;
+  
+  TArrayF chargearea(size);
+  TArrayF chargeareaerr(size);
+  TArrayF nr(size);
+  TArrayF nrerr(size);
+  
+  for (Int_t i=0;i<GetSize();i++)
+    {
+      //
+      // Get the calibration cam from the intensity cam
+      //
+      MCalibrationChargeCam *cam = (MCalibrationChargeCam*)GetCam(i);
+
+      //
+      // Get the calibration pix from the calibration cam
+      //
+      const MCalibrationChargePix &apix = (MCalibrationChargePix&)cam->GetAverageArea(aidx);
+      const Float_t charge          = apix.GetConvertedMean();
+      const Float_t chargeerr       = apix.GetConvertedSigma();
+
+      chargearea[i]       = charge;
+      chargeareaerr[i]    = chargeerr;
+
+      nr[i]    = i;
+      nrerr[i] = 0.;
+    }
+  
+  TGraphErrors *gr = new TGraphErrors(size,
+                                     nr.GetArray(),chargearea.GetArray(),
+                                     nrerr.GetArray(),chargeareaerr.GetArray());
+  gr->SetTitle(Form("Averaged Charges Area Idx %d",aidx));
+  gr->GetXaxis()->SetTitle("Camera Nr.");
+  gr->GetYaxis()->SetTitle("<Q> [FADC cnts]");      
+  return gr;
+}
+
+TH1F *MCalibrationIntensityChargeCam::GetVarFluctuations( const Int_t aidx, const MGeomCam &geom, const Option_t *varname )
+{
+  
+  const Int_t size = GetSize();
+  
+  if (size == 0)
+    return NULL;
+  
+  TString option(varname);
+  option.ToLower();
+  
+  TH1F *hist = new TH1F("hist",Form("%s - Rel. Fluctuations %s Pixel",option.Data(),aidx ? "Outer" : "Inner"),
+                        200,0.,100.);
+  hist->SetXTitle("Relative Fluctuation [%]");
+  hist->SetYTitle("Nr. channels [1]");  
+  hist->SetFillColor(kRed+aidx);
+
+  MCalibrationChargeCam *cam = (MCalibrationChargeCam*)GetCam();
+
+  //
+  // Loop over pixels
+  //
+  for (Int_t npix=0;npix<cam->GetSize();npix++)
+    {
+      if (geom[npix].GetAidx() != aidx)
+        continue;
+
+      Double_t variab   = 0.;
+      Double_t variab2  = 0.;
+      Double_t variance = 0.;
+      Int_t    num      = 0;
+      Float_t  pvar     = 0.;
+      Float_t  relrms   = 99.9;
+      //
+      // Loop over the Cams for each pixel
+      //
+      for (Int_t i=0; i<GetSize(); i++)
+        {
+          MCalibrationChargeCam *cam = (MCalibrationChargeCam*)GetCam(i);
+          //
+          // Get the calibration pix from the calibration cam
+          //
+          MCalibrationChargePix &pix = (MCalibrationChargePix&)(*cam)[npix];
+          //
+          // Don't use bad pixels
+          //
+          if (!pix.IsFFactorMethodValid())
+            continue;
+
+          if (option.Contains("rsigma"))
             pvar = pix.GetRSigma();
-          if (option.Contains("abstime"))
+          if (option.Contains("abstimemean"))
             pvar = pix.GetAbsTimeMean();
+          if (option.Contains("abstimerms"))
+            pvar = pix.GetAbsTimeRms();
           if (option.Contains("conversionhilo"))
             pvar = pix.GetConversionHiLo();
@@ -758,321 +1094,14 @@
           if (option.Contains("rsigmapercharge"))
             pvar = pix.GetRSigmaPerCharge();
+          if (option.Contains("conversionfactor"))
+          {
+              const MCalibrationChargePix &apix = (MCalibrationChargePix&)cam->GetAverageArea(0);
+              pvar = apix.GetPheFFactorMethod()/pix.GetConvertedMean();
+          }
+
 
           variab  += pvar;
           variab2 += pvar*pvar;
           num++;
-          
-          camcharge.Fill(j,pvar);
-          camcharge.SetUsed(j);
-        }
-      
-      if (num > 1)
-        {
-          variab  /= num;
-          variance = (variab2 - variab*variab*num) / (num-1);
-
-          vararea[i] = variab;
-          if (variance > 0.)
-            varareaerr[i] = TMath::Sqrt(variance);
-          else
-            varareaerr[i] = 999999999.;
-
-          //
-          // Make also a Gauss-fit to the distributions. The RMS can be determined by 
-          // outlier, thus we look at the sigma and the RMS and take the smaller one, afterwards.
-          // 
-          h = camcharge.ProjectionS(TArrayI(),TArrayI(1,&aidx),"_py",750);
-          h->SetDirectory(NULL);
-          h->Fit("gaus","QL");
-          TF1 *fit = h->GetFunction("gaus");
-
-          Float_t ci2   = fit->GetChisquare();
-          Float_t sigma = fit->GetParameter(2);
-
-          if (ci2 > 500. || sigma > varareaerr[i])
-            {
-              h->Fit("gaus","QLM");
-              fit = h->GetFunction("gaus");
-
-              ci2   = fit->GetChisquare();
-              sigma = fit->GetParameter(2);
-            }
-          
-          const Float_t mean  = fit->GetParameter(1);
-          const Float_t ndf   = fit->GetNDF();
-          
-          *fLog << inf << "Camera Nr: " << i << endl;
-          *fLog << inf << option.Data() << " area idx: " << aidx << " Results: " << endl;
-          *fLog << inf << "Mean: " << Form("%4.3f",mean) 
-                << "+-" << Form("%4.3f",fit->GetParError(1))
-                << "  Sigma: " << Form("%4.3f",sigma) << "+-" << Form("%4.3f",fit->GetParError(2)) 
-                << "  Chisquare: " << Form("%4.3f",fit->GetChisquare()) << "  NDF  : " << ndf << endl;          
-          delete h;
-          gROOT->GetListOfFunctions()->Remove(fit);
-
-          if (sigma < varareaerr[i] && ndf > 2)
-            {
-              vararea   [i] = mean;
-              varareaerr[i] = sigma;
-            }
-        }
-      else
-        {
-          vararea[i]    = -1.;
-          varareaerr[i] = 0.;
-        }
-
-      nr[i] = i;
-      nrerr[i] = 0.;
-    }
-  
-  TGraphErrors *gr = new TGraphErrors(size,
-                                     nr.GetArray(),vararea.GetArray(),
-                                     nrerr.GetArray(),varareaerr.GetArray());
-  gr->SetTitle(Form("%s Area %3i Average",option.Data(),aidx));
-  gr->GetXaxis()->SetTitle("Camera Nr.");
-  //  gr->GetYaxis()->SetTitle("<Q> [1]");      
-  return gr;
-}
-
-
-// -------------------------------------------------------------------
-//
-// Returns a TGraphErrors with the mean effective number of photon
-// vs. the calibration camera number. With the string 'method', different
-// calibration methods can be called.
-//
-TGraphErrors *MCalibrationIntensityChargeCam::GetPhotVsTime( const Option_t *method )
-{
-  
-  const Int_t size = GetSize();
-  
-  if (size == 0)
-    return NULL;
-
-  TString option(method);
-
-  TArrayF photarr(size);
-  TArrayF photarrerr(size);
-  TArrayF nr(size);
-  TArrayF nrerr(size);
-  
-  for (Int_t i=0;i<GetSize();i++)
-    {
-      //
-      // Get the calibration cam from the intensity cam
-      //
-      MCalibrationChargeCam *cam = (MCalibrationChargeCam*)GetCam(i);
-
-      //
-      // Get the calibration pix from the calibration cam
-      //
-      Float_t phot    = 0.;
-      Float_t photerr = 0.;
-
-      if (option.Contains("BlindPixel"))
-        {
-          phot    = cam->GetNumPhotonsBlindPixelMethod();
-          photerr = cam->GetNumPhotonsBlindPixelMethodErr();
-        }
-      if (option.Contains("FFactor"))
-        {
-          phot    = cam->GetNumPhotonsFFactorMethod();
-          photerr = cam->GetNumPhotonsFFactorMethodErr();
-        }
-      if (option.Contains("PINDiode"))
-        {
-          phot    = cam->GetNumPhotonsPINDiodeMethod();
-          photerr = cam->GetNumPhotonsPINDiodeMethodErr();
-        }
-
-      photarr[i]       = phot;
-      photarrerr[i]    = photerr;
-
-      nr[i] = i;
-      nrerr[i] = 0.;
-    }
-  
-  TGraphErrors *gr = new TGraphErrors(size,
-                                     nr.GetArray(),photarr.GetArray(),
-                                     nrerr.GetArray(),photarrerr.GetArray());
-  gr->SetTitle("Photons Average");
-  gr->GetXaxis()->SetTitle("Camera Nr.");
-  gr->GetYaxis()->SetTitle("<N_phot> [1]");      
-  return gr;
-}
-
-// -------------------------------------------------------------------
-//
-// Returns a TGraphErrors with the mean effective number of photo-electrons per 
-// area index 'aidx' vs. the calibration camera number 
-//
-TGraphErrors *MCalibrationIntensityChargeCam::GetPhePerAreaVsTime( const Int_t aidx, const MGeomCam &geom)
-{
-  
-  const Int_t size = GetSize();
-  
-  if (size == 0)
-    return NULL;
-  
-  TArrayF phearea(size);
-  TArrayF pheareaerr(size);
-  TArrayF time(size);
-  TArrayF timeerr(size);
-  
-  for (Int_t i=0;i<GetSize();i++)
-    {
-      //
-      // Get the calibration cam from the intensity cam
-      //
-      MCalibrationChargeCam *cam = (MCalibrationChargeCam*)GetCam(i);
-
-      //
-      // Get the calibration pix from the calibration cam
-      //
-      const MCalibrationChargePix &apix = (MCalibrationChargePix&)cam->GetAverageArea(aidx);
-      const Float_t phe          = apix.GetPheFFactorMethod();
-      const Float_t pheerr       = apix.GetPheFFactorMethodErr();
-
-      phearea[i]       = phe;
-      pheareaerr[i]    = pheerr;
-
-      time[i] = i;
-      timeerr[i] = 0.;
-    }
-  
-  TGraphErrors *gr = new TGraphErrors(size,
-                                     time.GetArray(),phearea.GetArray(),
-                                     timeerr.GetArray(),pheareaerr.GetArray());
-  gr->SetTitle(Form("Phes Area %d Average",aidx));
-  gr->GetXaxis()->SetTitle("Camera Nr.");
-  gr->GetYaxis()->SetTitle("<N_phes> [1]");      
-  return gr;
-}
-
-// -------------------------------------------------------------------
-//
-// Returns a TGraphErrors with the event-by-event averaged charge per 
-// area index 'aidx' vs. the calibration camera number 
-//
-TGraphErrors *MCalibrationIntensityChargeCam::GetChargePerAreaVsTime( const Int_t aidx, const MGeomCam &geom)
-{
-  
-  const Int_t size = GetSize();
-  
-  if (size == 0)
-    return NULL;
-  
-  TArrayF chargearea(size);
-  TArrayF chargeareaerr(size);
-  TArrayF nr(size);
-  TArrayF nrerr(size);
-  
-  for (Int_t i=0;i<GetSize();i++)
-    {
-      //
-      // Get the calibration cam from the intensity cam
-      //
-      MCalibrationChargeCam *cam = (MCalibrationChargeCam*)GetCam(i);
-
-      //
-      // Get the calibration pix from the calibration cam
-      //
-      const MCalibrationChargePix &apix = (MCalibrationChargePix&)cam->GetAverageArea(aidx);
-      const Float_t charge          = apix.GetConvertedMean();
-      const Float_t chargeerr       = apix.GetConvertedSigma();
-
-      chargearea[i]       = charge;
-      chargeareaerr[i]    = chargeerr;
-
-      nr[i]    = i;
-      nrerr[i] = 0.;
-    }
-  
-  TGraphErrors *gr = new TGraphErrors(size,
-                                     nr.GetArray(),chargearea.GetArray(),
-                                     nrerr.GetArray(),chargeareaerr.GetArray());
-  gr->SetTitle(Form("Averaged Charges Area Idx %d",aidx));
-  gr->GetXaxis()->SetTitle("Camera Nr.");
-  gr->GetYaxis()->SetTitle("<Q> [FADC cnts]");      
-  return gr;
-}
-
-TH1F *MCalibrationIntensityChargeCam::GetVarFluctuations( const Int_t aidx, const MGeomCam &geom, const Option_t *varname )
-{
-  
-  const Int_t size = GetSize();
-  
-  if (size == 0)
-    return NULL;
-  
-  TString option(varname);
-  
-  TH1F *hist = new TH1F("hist",Form("%s - Rel. Fluctuations %s Pixel",option.Data(),aidx ? "Outer" : "Inner"),
-                        200,0.,100.);
-  hist->SetXTitle("Relative Fluctuation [%]");
-  hist->SetYTitle("Nr. channels [1]");  
-  hist->SetFillColor(kRed+aidx);
-
-  MCalibrationChargeCam *cam = (MCalibrationChargeCam*)GetCam();
-
-  //
-  // Loop over pixels
-  //
-  for (Int_t npix=0;npix<cam->GetSize();npix++)
-    {
-      if (geom[npix].GetAidx() != aidx)
-        continue;
-
-      Double_t variab   = 0.;
-      Double_t variab2  = 0.;
-      Double_t variance = 0.;
-      Int_t    num      = 0;
-      Float_t  pvar     = 0.;
-      Float_t  relrms   = 99.9;
-      //
-      // Loop over the Cams for each pixel
-      //
-      for (Int_t i=0; i<GetSize(); i++)
-        {
-          MCalibrationChargeCam *cam = (MCalibrationChargeCam*)GetCam(i);
-          //
-          // Get the calibration pix from the calibration cam
-          //
-          MCalibrationChargePix &pix = (MCalibrationChargePix&)(*cam)[npix];
-          //
-          // Don't use bad pixels
-          //
-          if (!pix.IsFFactorMethodValid())
-            continue;
-
-          if (option.Contains("RSigma"))
-            pvar = pix.GetRSigma();
-          if (option.Contains("AbsTime"))
-            pvar = pix.GetAbsTimeMean();
-          if (option.Contains("ConversionHiLo"))
-            pvar = pix.GetConversionHiLo();
-          if (option.Contains("ConvertedMean"))
-            pvar = pix.GetConvertedMean();
-          if (option.Contains("ConvertedSigma"))
-            pvar = pix.GetConvertedSigma();
-          if (option.Contains("ConvertedRSigma"))
-            pvar = pix.GetConvertedRSigma();
-          if (option.Contains("MeanConvFADC2Phe"))
-            pvar = pix.GetMeanConvFADC2Phe();
-          if (option.Contains("MeanFFactorFADC2Phot"))
-            pvar = pix.GetMeanFFactorFADC2Phot();
-          if (option.Contains("Ped"))
-            pvar = pix.GetPed();
-          if (option.Contains("PedRms"))
-            pvar = pix.GetPedRms();
-          if (option.Contains("PheFFactorMethod"))
-            pvar = pix.GetPheFFactorMethod();
-          if (option.Contains("RSigmaPerCharge"))
-            pvar = pix.GetRSigmaPerCharge();
-
-          variab  += pvar;
-          variab2 += pvar*pvar;
-          num++;
         }
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc	(revision 7188)
@@ -40,4 +40,8 @@
 //                  - FinalizeBadPixels()
 //
+// Class Version 2:
+//  + Byte_t fCheckFlags; // Bit-field to hold the possible check flags
+//
+//
 //  Input Containers:
 //   MCalibrationRelTimeCam
@@ -71,5 +75,4 @@
 #include "MBadPixelsPix.h"
 
-
 ClassImp(MCalibrationRelTimeCalc);
 
@@ -77,4 +80,5 @@
 
 const Float_t MCalibrationRelTimeCalc::fgRelTimeResolutionLimit = 1.0;
+
 // --------------------------------------------------------------------------
 //
@@ -97,11 +101,16 @@
   fName  = name  ? name  : "MCalibrationRelTimeCalc";
   fTitle = title ? title : "Task to finalize the relative time calibration";
-  
+
+  SetCheckFitResults       ( kFALSE );
+  SetCheckDeviatingBehavior( kFALSE );
+  SetCheckHistOverflow     ( kFALSE );
+  SetCheckOscillations     ( kFALSE );
+
   SetRelTimeResolutionLimit();
   SetOutputPath();
   SetOutputFile("");
- 
+
   Clear();
-  
+
 }
 
@@ -268,5 +277,5 @@
 
   PrintUncalibrated(MBadPixelsPix::kDeviatingTimeResolution,    
-                    Form("%s%2.1f%s","Time resolution less than ",fRelTimeResolutionLimit," FADC slices from Mean:   "));
+                    Form("%s%2.1f%s","Time resol. less than ",fRelTimeResolutionLimit," FADC sl. from Mean:     "));
   PrintUncalibrated(MBadPixelsPix::kRelTimeOscillating,   
                     "Pixels with changing Rel. Times over time:             ");
@@ -437,17 +446,20 @@
       MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*relcam)[i];
 
-      if (bad.IsUncalibrated( MBadPixelsPix::kDeviatingTimeResolution))
-        bad.SetUnsuitable(   MBadPixelsPix::kUnreliableRun   );
- 
-      if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeNotFitted))
-        bad.SetUnsuitable(   MBadPixelsPix::kUnreliableRun   );
- 
-      if (bad.IsUncalibrated( MBadPixelsPix::kRelTimeOscillating))
-        bad.SetUnsuitable(   MBadPixelsPix::kUnreliableRun   );
- 
-      if (bad.IsUnsuitable(   MBadPixelsPix::kUnsuitableRun    ))
-        pix.SetExcluded();
-
-    }
+      if (IsCheckDeviatingBehavior())
+          if (bad.IsUncalibrated(MBadPixelsPix::kDeviatingTimeResolution))
+              bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
+
+      if (IsCheckFitResults())
+          if (bad.IsUncalibrated(MBadPixelsPix::kRelTimeNotFitted))
+              bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
+
+      if (IsCheckOscillations())
+          if (bad.IsUncalibrated(MBadPixelsPix::kRelTimeOscillating))
+              bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
+
+      if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
+          pix.SetExcluded();
+    }
+
 }
 
@@ -488,6 +500,6 @@
 
   if (fGeom->InheritsFrom("MGeomCamMagic"))
-    *fLog << " " << setw(7) << "Uncalibrated Pixels:            " 
-          << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
+    *fLog << " " << setw(7) << "Uncalibrated Pixels:            Inner: "
+          << Form("%3i",counts[0]) << " Outer: " << Form("%3i",counts[1]) << endl;
 
   counts.Reset();
@@ -506,6 +518,6 @@
     relcam->SetNumUnreliable(counts[aidx], aidx);
 
-  *fLog << " " << setw(7) << "Unreliable Pixels:              "
-        << Form("%s%3i%s%3i","Inner: ",counts[0]," Outer: ",counts[1]) << endl;
+  *fLog << " " << setw(7) << "Unreliable Pixels:              Inner: "
+        << Form("%3i",counts[0]) << " Outer: " << Form("%3i",counts[1]) << endl;
 
 }
@@ -545,7 +557,7 @@
 void MCalibrationRelTimeCalc::SetOutputPath(TString path)
 {
-  fOutputPath = path;
-  if (fOutputPath.EndsWith("/"))
-    fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
+    fOutputPath = path;
+    if (fOutputPath.EndsWith("/"))
+        fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
 }
 
@@ -556,4 +568,41 @@
 const char* MCalibrationRelTimeCalc::GetOutputFile()
 {
-  return Form("%s/%s", (const char*)fOutputPath, (const char*)fOutputFile);
-}
+    return Form("%s/%s", (const char*)fOutputPath, (const char*)fOutputFile);
+}
+
+
+// --------------------------------------------------------------------------
+//
+// MCalibrationRelTimeCam.CheckFitResults: Yes
+// MCalibrationRelTimeCam.CheckDeviatingBehavior: Yes
+// MCalibrationRelTimeCam.CheckHistOverflow: Yes
+// MCalibrationRelTimeCam.CheckOscillations: Yes
+// 
+Int_t MCalibrationRelTimeCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Bool_t rc = kFALSE;
+
+    if (IsEnvDefined(env, prefix, "CheckFitResults", print))
+    {
+        SetCheckFitResults(GetEnvValue(env, prefix, "CheckFitResults", IsCheckFitResults()));
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "CheckDeviatingBehavior", print))
+    {
+        SetCheckDeviatingBehavior(GetEnvValue(env, prefix, "CheckDeviatingBehavior", IsCheckDeviatingBehavior()));
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "CheckHistOverflow", print))
+    {
+        SetCheckHistOverflow(GetEnvValue(env, prefix, "CheckHistOverflow", IsCheckHistOverflow()));
+        rc = kTRUE;
+    }
+
+    if (IsEnvDefined(env, prefix, "CheckOscillations", print))
+    {
+        SetCheckOscillations(GetEnvValue(env, prefix, "CheckOscillations", IsCheckOscillations()));
+        rc = kTRUE;
+    }
+
+    return rc;
+}
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.h	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.h	(revision 7188)
@@ -43,4 +43,15 @@
   MGeomCam                   *fGeom;             //! Camera geometry
 
+  // enums
+  enum  Check_t
+  {
+      kCheckHistOverflow,
+      kCheckDeviatingBehavior,
+      kCheckOscillations,
+      kCheckFitResults
+  };                                             // Possible Checks
+
+  Byte_t fCheckFlags;                            // Bit-field to hold the possible check flags
+
   enum  { kDebug };                              //  Possible flags
 
@@ -56,24 +67,43 @@
   void   PrintUncalibrated( MBadPixelsPix::UncalibratedType_t typ, const char *text) const;
 
+  // Query checks
+  Bool_t IsCheckDeviatingBehavior() const { return TESTBIT(fCheckFlags,kCheckDeviatingBehavior); }
+  Bool_t IsCheckHistOverflow     () const { return TESTBIT(fCheckFlags,kCheckHistOverflow);      }
+  Bool_t IsCheckOscillations     () const { return TESTBIT(fCheckFlags,kCheckOscillations);      }
+  Bool_t IsCheckFitResults       () const { return TESTBIT(fCheckFlags,kCheckFitResults);        }
+
+  // MTask
   Bool_t ReInit     (MParList *pList); 
   Int_t  Process    () { return kTRUE; }
   Int_t  PostProcess();
 
+  // MParContainer
+  Int_t  ReadEnv(const TEnv &env, TString prefix, Bool_t print);
+
 public:
-
   MCalibrationRelTimeCalc(const char *name=NULL, const char *title=NULL);
 
+  // TObject
   void Clear(const Option_t *o="");
-  
+
+  // MCalibrationRelTimeCalc
   Int_t Finalize();
   
+  // Getter
   Bool_t IsDebug() const  {  return TESTBIT(fFlags,kDebug); }
 
-  void SetDebug                 ( const Bool_t  b=kTRUE ) { b ? SETBIT(fFlags,kDebug) : CLRBIT(fFlags,kDebug); }   
+  // Setter
   void SetOutputPath            ( TString path="."                         );
   void SetOutputFile            ( TString file="TimeCalibStat.txt"         ) { fOutputFile          = file; }
   void SetRelTimeResolutionLimit( const Float_t f=fgRelTimeResolutionLimit ) { fRelTimeResolutionLimit = f; }
 
-  ClassDef(MCalibrationRelTimeCalc, 1)   // Task finalizing the relative time Calibration 
+  // Checks
+  void SetCheckFitResults(const Bool_t b=kTRUE)        { b ? SETBIT(fCheckFlags,kCheckFitResults) : CLRBIT(fCheckFlags,kCheckFitResults); }
+  void SetCheckDeviatingBehavior(const Bool_t b=kTRUE) { b ? SETBIT(fCheckFlags,kCheckDeviatingBehavior) : CLRBIT(fCheckFlags,kCheckDeviatingBehavior); }
+  void SetCheckHistOverflow(const Bool_t b=kTRUE)      { b ? SETBIT(fCheckFlags,kCheckHistOverflow) : CLRBIT(fCheckFlags,kCheckHistOverflow); }
+  void SetCheckOscillations(const Bool_t b=kTRUE)      { b ? SETBIT(fCheckFlags,kCheckOscillations) : CLRBIT(fCheckFlags,kCheckOscillations); }
+  void SetDebug(const Bool_t b=kTRUE)                  { b ? SETBIT(fFlags, kDebug) : CLRBIT(fFlags, kDebug); }
+
+  ClassDef(MCalibrationRelTimeCalc, 2)   // Task finalizing the relative time Calibration
 };
 
Index: trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.cc	(revision 7188)
@@ -71,16 +71,14 @@
 using namespace std;
 
-MMcCalibrationCalc::MMcCalibrationCalc(const char *name, const char *title)
+// --------------------------------------------------------------------------
+//
+// Constructor. Default value for fMinSize is 1000 ADC counts. This must be
+// set in general by the user (SetMinSize), since it depends among other things
+// on the signal extractor used.
+//
+MMcCalibrationCalc::MMcCalibrationCalc(const char *name, const char *title): fMinSize(1000)
 {
     fName  = name  ? name  : "MMcCalibrationCalc";
     fTitle = title ? title : "Calculate and write conversion factors into MCalibrationChargeCam and MCalibrationQECam containers";
-
-    fHistADC2PhotEl = new TH1F(AddSerialNumber("ADC2PhotEl"), "log10(fPhotElfromShower/fSize)", 1500, -3., 3.);
-    fHistADC2PhotEl->SetXTitle("log_{10}(fPhotElfromShower / fSize) [photel/ADC count]");
-
-
-    fHistPhot2PhotEl = new TH1F(AddSerialNumber("Phot2PhotEl"), "Photon conversion efficiency", 1000, 0., 1.);
-    fHistPhot2PhotEl->SetXTitle("Overall photon conversion efficiency [photoelectron/photon]");
-
 }
 
@@ -93,9 +91,10 @@
 Bool_t MMcCalibrationCalc::CheckRunType(MParList *pList) const
 {
-    const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
+    const MRawRunHeader *run = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
     if (!run)
     {
-        *fLog << warn << "Warning - cannot check file type, MRawRunHeader not found." << endl;
-        return kTRUE;
+      *fLog << warn << "Warning - cannot check file type, " << AddSerialNumber("MRawRunHeader") 
+	    << " not found." << endl;
+      return kTRUE;
     }
 
@@ -105,11 +104,8 @@
 // --------------------------------------------------------------------------
 //
-// Make sure, that there is an MCalibrationCam Object in the Parameter List.
+// Look for all necessary containers and create histograms
 //
 Int_t MMcCalibrationCalc::PreProcess(MParList *pList)
 {
-    fHistADC2PhotEl->Reset();
-    fHistPhot2PhotEl->Reset();
-
     fADC2PhotEl = 0;
     fPhot2PhotEl = 0;
@@ -156,4 +152,16 @@
         return kFALSE;
     }
+
+    //
+    // Create histograms:
+    //
+
+    fHistADC2PhotEl = new TH1F(AddSerialNumber("ADC2PhotEl"), "log10(fPhotElfromShower/fSize)", 1500, -3., 3.);
+    fHistADC2PhotEl->SetXTitle("log_{10}(fPhotElfromShower / fSize) [photel/ADC count]");
+
+
+    fHistPhot2PhotEl = new TH1F(AddSerialNumber("Phot2PhotEl"), "Photon conversion efficiency", 1000, 0., 1.);
+    fHistPhot2PhotEl->SetXTitle("Overall photon conversion efficiency [photoelectron/photon]");
+
 
     return kTRUE;
@@ -210,12 +218,8 @@
   // perpendicular to the camera plane.
   //
-  // FIXME! We should look for AddSerialNumber("MMcConfigRunHeader") but
-  // for the moment the stereo version of camera does not write one such
-  // header per telescope (it should!)
-  //
-  MMcConfigRunHeader* mcconfig = (MMcConfigRunHeader*) pList->FindObject("MMcConfigRunHeader");
+  MMcConfigRunHeader* mcconfig = (MMcConfigRunHeader*) pList->FindObject(AddSerialNumber("MMcConfigRunHeader"));
   if (!mcconfig)
     {
-      *fLog << err << "MMcConfigRunHeader" << " not found... aborting." << endl;
+      *fLog << err << AddSerialNumber("MMcConfigRunHeader") << " not found... aborting." << endl;
       return kFALSE;
     }
@@ -253,9 +257,7 @@
     //
     // Exclude events with low Size (larger fluctuations)
-    // FIXME? The present cut (1000 "inner-pixel-counts") is somehow
-    // arbitrary. Might it be optimized?
     //   
 
-    if (size < 1000)
+    if (size < fMinSize)
         return kTRUE;
 
@@ -288,5 +290,12 @@
     }
 
-    fPhot2PhotEl = fHistPhot2PhotEl->GetMean();   // Average quantum efficiency
+    fPhot2PhotEl = fHistPhot2PhotEl->GetMean();   
+    // Average quantum efficiency. For now we will set this value for all pixels, although
+    // even in MC there may be differences from pixel to pixel, if the .dat file containing 
+    // QE vs lambda, input of the camera simulation, has different QE curves for different
+    // pixels. FIXME?
+
+    MCalibrationQEPix &avqepix = (MCalibrationQEPix&)(fQECam->GetAverageArea(0));
+    avqepix.SetAverageQE(fPhot2PhotEl); // Needed by MCalibrateData!
 
     //
@@ -335,5 +344,5 @@
 	// FIXME: we are now assuming that all inner pixels have the same gain, and all 
 	// outer pixels have the same gain (different from inner ones though). This can 
-        // only be like this in camera 0.7, but may change in future versions of camera.
+        // only be like this in camera 0.7, but might change in future versions of camera.
 	//
 
@@ -347,4 +356,5 @@
     }
 
+
     return kTRUE;
 }
Index: trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h	(revision 7188)
@@ -35,4 +35,8 @@
                                          // outer pixels w.r.t inner ones
 
+    Float_t fMinSize; 
+    // Minimum SIZE (before calibration, ADC counts) an event must have to be considered in the
+    // calculation of the calibration constants.
+
     TH1F*   fHistADC2PhotEl;
     TH1F*   fHistPhot2PhotEl; // Histograms for monitoring the calibration.
@@ -50,4 +54,6 @@
     TH1F*   GetHistPhot2PhotEl() { return fHistPhot2PhotEl; }
 
+    void SetMinSize(Float_t x) { fMinSize = x; }
+
     ClassDef(MMcCalibrationCalc, 0)   // Task which obtains, for MC files, the calibration factor from ADC counts to photons. 
 };
Index: trunk/MagicSoft/Mars/mcalib/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mcalib/Makefile	(revision 7147)
+++ trunk/MagicSoft/Mars/mcalib/Makefile	(revision 7188)
@@ -40,4 +40,5 @@
 	   MCalibrateRelTimes.cc \
            MCalibrationIntensityCam.cc \
+           MCalibrationIntensityConstCam.cc \
            MCalibrationIntensityChargeCam.cc \
            MCalibrationIntensityBlindCam.cc \
