Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 4319)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 4320)
@@ -186,4 +186,5 @@
 #include <TSystem.h>
 #include <TH1.h>
+#include <TF1.h>
 
 #include "MLog.h"
@@ -197,4 +198,5 @@
 #include "MGeomCam.h"
 #include "MGeomPix.h"
+#include "MHCamera.h"
 
 #include "MPedestalCam.h"
@@ -229,5 +231,5 @@
 const Float_t MCalibrationChargeCalc::fgLambdaCheckLimit       = 0.5;
 const Float_t MCalibrationChargeCalc::fgPheErrLimit            = 3.5;
-const Float_t MCalibrationChargeCalc::fgFFactorErrLimit        = 3.5;
+const Float_t MCalibrationChargeCalc::fgFFactorErrLimit        = 4.5;
 // --------------------------------------------------------------------------
 //
@@ -701,4 +703,6 @@
   PrintUncalibrated(MBadPixelsPix::kDeviatingNumPhes,    
                     "Pixels with deviating number of phes:             ");
+  PrintUncalibrated(MBadPixelsPix::kDeviatingFFactor,    
+                    "Pixels with deviating F-Factor:                   ");
 
   *fLog << inf << endl;
@@ -923,4 +927,6 @@
   //             The loop is only to recognize later pixels with very deviating numbers
   //
+  MHCamera camphes(*fGeom,"Camphes","Phes in Camera");
+
   for (UInt_t i=0; i<npixels; i++)
     {
@@ -944,4 +950,7 @@
       const Float_t nvar  = pix.GetPheFFactorMethod()*pix.GetPheFFactorMethod();
       const Int_t   aidx  = (*fGeom)[i].GetAidx();
+
+      camphes.Fill(i,nphe);
+      camphes.SetUsed(i);
 
       areaphes    [aidx] += nphe;
@@ -973,4 +982,47 @@
       lowlim  [i] = areaphes[i] - fPheErrLimit*TMath::Sqrt(areavars[i]);
       upplim  [i] = areaphes[i] + fPheErrLimit*TMath::Sqrt(areavars[i]);
+
+      TArrayI area(1);
+      area[0] = i;
+
+      TH1D *hist = camphes.ProjectionS(TArrayI(),area);
+      hist->Fit("gaus","Q");
+      const Float_t mean  = hist->GetFunction("gaus")->GetParameter(1);
+      const Float_t sigma = hist->GetFunction("gaus")->GetParameter(2);
+      const Int_t   ndf   = hist->GetFunction("gaus")->GetNDF();
+
+      if (ndf < 2)
+        {
+          *fLog << warn << GetDescriptor() << ": Cannot use a Gauss fit to the number of photo-electrons " 
+                << "in the camera with area index: " << i << endl;
+          *fLog << warn << GetDescriptor() << ": Number of dof.: " << ndf << " is smaller than 2 " << endl;
+          *fLog << warn << GetDescriptor() << ": Will use the simple mean and rms " << endl;
+          delete hist;
+          continue;
+        }
+      
+      const Double_t prob = hist->GetFunction("gaus")->GetProb();
+
+      if (prob < 0.001)
+        {
+          *fLog << warn << GetDescriptor() << ": Cannot use a Gauss fit to the number of photo-electrons " 
+                << "in the camera with area index: " << i << endl;
+          *fLog << warn << GetDescriptor() << ": Fit probability " << prob 
+                << " is smaller than 0.001 " << endl;
+          *fLog << warn << GetDescriptor() << ": Will use the simple mean and rms " << endl;
+          delete hist;
+          continue;
+        }
+      
+      *fLog << inf << endl;
+      *fLog << inf << GetDescriptor() << ": Mean Number of photo-electrons " 
+            << "in the camera with area index: " << i << ": " 
+            << Form("%4.2f%s%4.2f",mean,"+-",sigma) << endl;
+      *fLog << inf << endl;
+
+      lowlim  [i] = mean  - fPheErrLimit*sigma;
+      upplim  [i] = mean  + fPheErrLimit*sigma;
+
+      delete hist;
     }
 
@@ -1289,4 +1341,6 @@
   const UInt_t npixels  = fGeom->GetNumPixels();
 
+  MHCamera camffactor(*fGeom,"Camffactor","F-Factor in Camera");
+
   for (UInt_t i=0; i<npixels; i++)
     {
@@ -1306,5 +1360,4 @@
           (*fBadPixels)[i].SetUncalibrated( MBadPixelsPix::kDeviatingNumPhes );
           continue;
-          
         }
 
@@ -1320,6 +1373,10 @@
 
       const Int_t aidx = (*fGeom)[i].GetAidx();
-
-      avffactorphotons[aidx] += pix.GetMeanFFactorFADC2Phot();
+      const Float_t ffactor = pix.GetMeanFFactorFADC2Phot();
+
+      camffactor.Fill(i,ffactor);
+      camffactor.SetUsed(i);
+
+      avffactorphotons[aidx] += ffactor;
       avffactorphotvar[aidx] += pix.GetMeanFFactorFADC2PhotVar();
       numffactor[aidx]++;
@@ -1330,6 +1387,50 @@
       avffactorphotons[i] /= numffactor[i];
       avffactorphotvar[i] /= numffactor[i];
-      lowlim  [i] = 1.1;
+
+      lowlim  [i] = 1.1;   // Lowest known F-Factor of a PMT
       upplim  [i] = avffactorphotons[i] + fFFactorErrLimit*TMath::Sqrt(avffactorphotvar[i]);
+
+      TArrayI area(1);
+      area[0] = i;
+
+      TH1D *hist = camffactor.ProjectionS(TArrayI(),area);
+      hist->Fit("gaus","Q");
+      const Float_t mean  = hist->GetFunction("gaus")->GetParameter(1);
+      const Float_t sigma = hist->GetFunction("gaus")->GetParameter(2);
+      const Int_t   ndf   = hist->GetFunction("gaus")->GetNDF();
+
+      if (ndf < 2)
+        {
+          *fLog << warn << GetDescriptor() << ": Cannot use a Gauss fit to the F-Factor " 
+                << "in the camera with area index: " << i << endl;
+          *fLog << warn << GetDescriptor() << ": Number of dof.: " << ndf << " is smaller than 2 " << endl;
+          *fLog << warn << GetDescriptor() << ": Will use the simple mean and rms " << endl;
+          delete hist;
+          continue;
+        }
+      
+      const Double_t prob = hist->GetFunction("gaus")->GetProb();
+
+      if (prob < 0.001)
+        {
+          *fLog << warn << GetDescriptor() << ": Cannot use a Gauss fit to the F-Factor " 
+                << "in the camera with area index: " << i << endl;
+          *fLog << warn << GetDescriptor() << ": Fit probability " << prob 
+                << " is smaller than 0.001 " << endl;
+          *fLog << warn << GetDescriptor() << ": Will use the simple mean and rms " << endl;
+          delete hist;
+          continue;
+        }
+
+      *fLog << inf << endl;
+      *fLog << inf << GetDescriptor() << ": Mean F-Factor " 
+            << "in the camera with area index: " << i << ": " 
+            << Form("%4.2f%s%4.2f",mean,"+-",sigma) << endl;
+      *fLog << inf << endl;
+
+      lowlim  [i] = mean  - fFFactorErrLimit*sigma;
+      upplim  [i] = mean  + fFFactorErrLimit*sigma;
+
+      delete hist;
     }
   
