Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 2792)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 2793)
@@ -25,4 +25,8 @@
      - Time fit accepted if ChiSquare less than 30. (instead of 20.)
 
+   * mcalib/MCalibrationPix.[h.cc]
+     - F-Factor corrected and added error
+     - Histograms not fitted if they are empty
+     - rejection criteria of fitted charges now > 5 PedRMS (instead 3)
 
  2004/01/13: Abelardo Moralejo
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationFits.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationFits.h	(revision 2792)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationFits.h	(revision 2793)
@@ -8,4 +8,61 @@
 #define GIMMEABREAK     10000000000.0
 
+inline Double_t gfKto4(Double_t *x, Double_t *par)
+{
+
+  Double_t lambda = par[0];  
+  
+  Double_t sum = 0.;
+  Double_t arg = 0.;
+
+  Double_t mu0 = par[1];
+  Double_t mu1 = par[2];
+
+  if (mu1 < mu0)
+    return GIMMEABREAK;
+
+  Double_t sigma0 = par[3];
+  Double_t sigma1 = par[4];
+
+  if (sigma1 < sigma0)
+    return GIMMEABREAK;
+
+
+  Double_t mu2 = (2.*mu1)-mu0;  
+  Double_t mu3 = (3.*mu1)-(2.*mu0);
+  Double_t mu4 = (4.*mu1)-(3.*mu0);
+
+  Double_t sigma2 = TMath::Sqrt((2.*sigma1*sigma1) - (sigma0*sigma0));  
+  Double_t sigma3 = TMath::Sqrt((3.*sigma1*sigma1) - (2.*sigma0*sigma0));
+  Double_t sigma4 = TMath::Sqrt((4.*sigma1*sigma1) - (3.*sigma0*sigma0));
+
+  Double_t lambda2 = lambda*lambda;
+  Double_t lambda3 = lambda2*lambda;
+  Double_t lambda4 = lambda3*lambda;
+
+  // k=0:
+  arg = (x[0] - mu0)/sigma0;
+  sum = TMath::Exp(-0.5*arg*arg)/sigma0;
+  
+  // k=1:
+  arg = (x[0] - mu1)/sigma1;
+  sum += lambda*TMath::Exp(-0.5*arg*arg)/sigma1;
+  
+  // k=2:
+  arg = (x[0] - mu2)/sigma2;
+  sum += 0.5*lambda2*TMath::Exp(-0.5*arg*arg)/sigma2;
+
+  // k=3:
+  arg = (x[0] - mu3)/sigma3;
+  sum += 0.1666666667*lambda3*TMath::Exp(-0.5*arg*arg)/sigma3;
+
+  // k=4:
+  arg = (x[0] - mu4)/sigma4;
+  sum += 0.041666666666667*lambda4*TMath::Exp(-0.5*arg*arg)/sigma4;
+  
+  return TMath::Exp(-1.*lambda)*par[5]*sum;
+
+};
+
 inline Double_t gfKto5(Double_t *x, Double_t *par)
 {
@@ -68,7 +125,8 @@
   sum += 0.008333333333333*lambda5*TMath::Exp(-0.5*arg*arg)/sigma5;
 
-  return par[5]*sum;
-
-};
+  return TMath::Exp(-1.*lambda)*par[5]*sum;
+
+};
+
 
 inline Double_t gfKto6(Double_t *x, Double_t *par)
@@ -139,5 +197,5 @@
   sum += 0.001388888888889*lambda6*TMath::Exp(-0.5*arg*arg)/sigma6;
   
-  return par[5]*sum;
+  return TMath::Exp(-1.*lambda)*par[5]*sum;
 
 };
@@ -217,5 +275,5 @@
   sum += 0.000198412698413*lambda7*TMath::Exp(-0.5*arg*arg)/sigma7;
   
-  return par[5]*sum;
+  return TMath::Exp(-1.*lambda)*par[5]*sum;
 
 };
@@ -303,5 +361,5 @@
   sum += 0.000024801587315*lambda8*TMath::Exp(-0.5*arg*arg)/sigma7;
   
-  return par[5]*sum;
+  return TMath::Exp(-1.*lambda)*par[5]*sum;
 
 };
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc	(revision 2792)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc	(revision 2793)
@@ -43,5 +43,14 @@
 // --------------------------------------------------------------------------
 //
-// Default Constructor. 
+// Default Constructor: 
+//
+// The following values are initialized to meaningful values:
+//
+// - The Electronic Rms to 1.5 per FADC slice
+// - The uncertainty about the Electronic RMS to 0.3 per slice
+// - The F-Factor is assumed to have been measured in Munich to 1.13 - 1.17. 
+//   We use here the Square of the Munich definition, thus:
+//   Mean F-Factor  = 1.15*1.15 = 1.32
+//   Error F-Factor = 2.*0.02   = 0.04
 //
 MCalibrationPix::MCalibrationPix(const char *name, const char *title)
@@ -61,6 +70,8 @@
       fSigmaTime(-1.),
       fTimeChiSquare(-1.),
-      fFactor(1.3),
+      fFactor(1.32),
+      fFactorError(0.04),
       fPheFFactorMethod(-1.),
+      fPheFFactorMethodError(-1.),
       fConversionFFactorMethod(-1.),
       fConversionBlindPixelMethod(-1.),
@@ -122,4 +133,5 @@
 //
 // 1) Return if the charge distribution is already succesfully fitted  
+//    or if the histogram is empty
 // 2) Set a lower Fit range according to 1.5 Pedestal RMS in order to avoid 
 //    possible remaining cosmics to spoil the fit.
@@ -133,5 +145,5 @@
 // The fits are declared valid (fFitValid = kTRUE), if:
 //
-// 1) Pixel has a fitted charge greater than 3*PedRMS
+// 1) Pixel has a fitted charge greater than 5*PedRMS
 // 2) Pixel has a fit error greater than 0.
 // 3) Pixel has a fit Probability greater than 0.0001 
@@ -141,4 +153,6 @@
 // (this stage is only performed in the times fit)
 //
+// If the histogram is empty, all values are set to -1.
+//
 // The conversion factor after the F-Factor method is declared valid, if:
 //
@@ -152,6 +166,7 @@
   //
   // 1) Return if the charge distribution is already succesfully fitted  
-  //
-  if (fHist->IsFitOK())
+  //    or if the histogram is empty
+  //
+  if (fHist->IsFitOK() || fHist->IsEmpty())
     return kTRUE;
 
@@ -301,5 +316,5 @@
 
       const Float_t rSigmaSquareRelErrSquare = (sigmaSquareErrSquare + pedRmsSquareErrSquare)
-        / (fRSigmaSquare * fRSigmaSquare) ;
+                                               / (fRSigmaSquare * fRSigmaSquare) ;
   
       //
@@ -342,5 +357,5 @@
 // The check return kTRUE if:
 //
-// 1) Pixel has a fitted charge greater than 3*PedRMS
+// 1) Pixel has a fitted charge greater than 5*PedRMS
 // 2) Pixel has a fit error greater than 0.
 // 3) Pixel has a fit Probability greater than 0.0001 
@@ -355,7 +370,7 @@
     equivpedestal /= fConversionHiLo;
       
-  if (fCharge < 3.*equivpedestal)
-    {
-      *fLog << warn << "WARNING: Fitted Charge is smaller than 3 Pedestal RMS in Pixel " << fPixId << endl;
+  if (fCharge < 5.*equivpedestal)
+    {
+      *fLog << warn << "WARNING: Fitted Charge is smaller than 5 Pedestal RMS in Pixel " << fPixId << endl;
       return kFALSE;
     }
