Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 3510)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 3511)
@@ -42,4 +42,7 @@
      of sigmas to calculation of variances which saves all the useless 
      square rooting.
+
+   - took out pointers to MCalibraitonChargeBlindPix and 
+     MCalibrationChargePINDiode in MCalibrationChargeCam.
 
 
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 3510)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 3511)
@@ -279,7 +279,4 @@
         return kFALSE;
 
-    fCam->SetPINDiode(fPINDiode);
-    fCam->SetBlindPixel(fBlindPixel);
-
     fEvtTime = (MTime*)pList->FindObject("MTime");
 
@@ -558,5 +555,5 @@
       {
 	  fCam->SetBlindPixelMethodValid(kTRUE);
-	  fCam->ApplyBlindPixelCalibration(*fGeom,*fBadPixels);
+	  fCam->ApplyBlindPixelCalibration(*fGeom,*fBadPixels, *fBlindPixel);
       }
   }
@@ -582,5 +579,5 @@
       {
 	  fCam->SetPINDiodeMethodValid(kTRUE);
-	  fCam->ApplyPINDiodeCalibration(*fGeom,*fBadPixels);
+	  fCam->ApplyPINDiodeCalibration(*fGeom,*fBadPixels, *fPINDiode);
       }
   }
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 3510)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 3511)
@@ -141,6 +141,6 @@
 const Float_t MCalibrationChargeCam::gkAverageQE                = 0.18;     
 const Float_t MCalibrationChargeCam::gkAverageQEErr             = 0.02;  
-const Float_t MCalibrationChargeCam::fgConvFFactorRelErrLimit   = 0.25;
-const Float_t MCalibrationChargeCam::fgPheFFactorRelLimit       = 7.;
+const Float_t MCalibrationChargeCam::fgConvFFactorRelErrLimit   = 0.35;
+const Float_t MCalibrationChargeCam::fgPheFFactorRelErrLimit    = 5.;
 // --------------------------------------------------------------------------
 //
@@ -170,5 +170,5 @@
     SetAverageQE();
     SetConvFFactorRelErrLimit();
-    SetPheFFactorRelLimit();
+    SetPheFFactorRelErrLimit();
 }
 
@@ -263,7 +263,7 @@
   fNumExcludedPixels            = 0;
   fMeanFluxPhesInnerPixel       = 0.;
-  fMeanFluxPhesInnerPixelErr    = 0.;
+  fMeanFluxPhesInnerPixelVar    = 0.;
   fMeanFluxPhesOuterPixel       = 0.;
-  fMeanFluxPhesOuterPixelErr    = 0.;
+  fMeanFluxPhesOuterPixelVar    = 0.;
 
   CLRBIT(fFlags,kBlindPixelMethodValid);
@@ -287,4 +287,32 @@
 {
     b ? SETBIT(fFlags, kPINDiodeMethodValid) : CLRBIT(fFlags, kPINDiodeMethodValid); 
+}
+
+Float_t MCalibrationChargeCam::GetMeanFluxPhesInnerPixelErr()   const
+{
+  if (fMeanFluxPhesInnerPixelVar <= 0.)
+    return -1.;
+  return TMath::Sqrt(fMeanFluxPhesInnerPixelVar);
+}
+
+Float_t MCalibrationChargeCam::GetMeanFluxPhesOuterPixelErr()   const
+{
+  if (fMeanFluxPhesOuterPixelVar <= 0.)
+    return -1.;
+  return TMath::Sqrt(fMeanFluxPhesOuterPixelVar);
+}
+
+Float_t MCalibrationChargeCam::GetMeanFluxPhotonsInnerPixelErr()   const
+{
+  if (fMeanFluxPhotonsInnerPixelVar <= 0.)
+    return -1.;
+  return TMath::Sqrt(fMeanFluxPhotonsInnerPixelVar);
+}
+
+Float_t MCalibrationChargeCam::GetMeanFluxPhotonsOuterPixelErr()   const
+{
+  if (fMeanFluxPhotonsOuterPixelVar <= 0.)
+    return -1.;
+  return TMath::Sqrt(fMeanFluxPhotonsOuterPixelVar);
 }
 
@@ -506,12 +534,20 @@
         return kFALSE;
       if ((*this)[idx].GetRSigmaCharge() == -1.)
+        return kFALSE;
+      if ((*this)[idx].GetMeanCharge() == 0.)
+        return kFALSE;
+      val = (*this)[idx].GetRSigmaCharge() / (*this)[idx].GetMeanCharge();
+      break;
+    case 8:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if ((*this)[idx].GetRSigmaCharge() <= 0.)
 	  return kFALSE;
-      val = (*this)[idx].GetRSigmaCharge() / (*this)[idx].GetMeanCharge();
-      break;
-    case 8:
-      if ((*this)[idx].IsExcluded())
-        return kFALSE;
-      if ((*this)[idx].GetRSigmaCharge() == -1.)
+      if ((*this)[idx].GetMeanCharge() <= 0.)
+        return kFALSE;
+      if ((*this)[idx].GetRSigmaChargeErr() <= 0.)
 	  return kFALSE;
+      if ((*this)[idx].GetMeanChargeErr() <= 0.)
+        return kFALSE;
       // relative error RsigmaCharge square
       val =    (*this)[idx].GetRSigmaChargeErr()* (*this)[idx].GetRSigmaChargeErr() 
@@ -553,15 +589,17 @@
       if ((*this)[idx].IsExcluded() || !(*this)[idx].IsFFactorMethodValid())
         return kFALSE;
-      val = (*this)[idx].GetTotalFFactorErrFFactorMethod();
+      val = (*this)[idx].GetTotalFFactorFFactorMethodErr();
       break;
     case 15:
       if ((*this)[idx].IsExcluded() || !(*this)[idx].IsBlindPixelMethodValid())
         return kFALSE;
-      val = fBlindPixel->GetMeanFluxInsidePlexiglass()*area;
+      //      val = fBlindPixel->GetMeanFluxInsidePlexiglass()*area;
+      val = 1.;
       break;
     case 16:
       if ((*this)[idx].IsExcluded() || !(*this)[idx].IsBlindPixelMethodValid())
         return kFALSE;
-      val = fBlindPixel->GetMeanFluxErrInsidePlexiglass()*area;
+      //      val = fBlindPixel->GetMeanFluxErrInsidePlexiglass()*area;
+      val = 1.;
       break;
     case 17:
@@ -583,15 +621,17 @@
       if ((*this)[idx].IsExcluded() || !(*this)[idx].IsBlindPixelMethodValid())
         return kFALSE;
-      val = (*this)[idx].GetTotalFFactorErrBlindPixelMethod();
+      val = (*this)[idx].GetTotalFFactorBlindPixelMethodErr();
       break;
     case 21:
       if ((*this)[idx].IsExcluded() || !(*this)[idx].IsPINDiodeMethodValid())
         return kFALSE;
-      val = fPINDiode->GetMeanFluxOutsidePlexiglass()*area;
+      //      val = fPINDiode->GetMeanFluxOutsidePlexiglass()*area;
+      val = 1.;
       break;
     case 22:
       if ((*this)[idx].IsExcluded() || !(*this)[idx].IsPINDiodeMethodValid())
         return kFALSE;
-      val = fPINDiode->GetMeanFluxErrOutsidePlexiglass()*area;
+      //      val = fPINDiode->GetMeanFluxErrOutsidePlexiglass()*area;
+      val = 1.;
       break;
     case 23:
@@ -613,5 +653,5 @@
       if ((*this)[idx].IsExcluded() || !(*this)[idx].IsPINDiodeMethodValid())
         return kFALSE;
-      val = (*this)[idx].GetTotalFFactorErrPINDiodeMethod();
+      val = (*this)[idx].GetTotalFFactorPINDiodeMethodErr();
       break;
     case 27:
@@ -725,9 +765,8 @@
 // which are fPheFFactorRelLimit sigmas from the mean.
 //
-Bool_t MCalibrationChargeCam::CalcMeanFluxPhotonsFFactorMethod(const MGeomCam &geom, const MBadPixelsCam &bad)
-{
-
-  const Float_t avQERelErrSquare             = fAverageQEErr * fAverageQEErr
-                                            / (fAverageQE    * fAverageQE ); 
+Bool_t MCalibrationChargeCam::CalcMeanFluxPhotonsFFactorMethod(const MGeomCam &geom, MBadPixelsCam &bad)
+{
+
+  const Float_t avQERelVar = fAverageQEVar / (fAverageQE * fAverageQE ); 
 
   Float_t sumweightsinner = 0.;
@@ -757,4 +796,5 @@
       if (npheerr > 0.)
         {
+          const Float_t weight = nphe*nphe/npheerr/npheerr;
           // 
           // first the inner pixels:
@@ -762,5 +802,4 @@
           if (ratio == 1.)
             {
-              const Float_t weight = 1./npheerr/npheerr;
               sumweightsinner += weight;
               sumphesinner    += weight*nphe;
@@ -772,5 +811,4 @@
               // now the outers
               //
-              const Float_t weight = 1./npheerr/npheerr;
               sumweightsouter += weight;
               sumphesouter    += weight*nphe;
@@ -790,6 +828,5 @@
     {
       fMeanFluxPhesInnerPixel    = sumphesinner/sumweightsinner;
-      fMeanFluxPhesInnerPixelErr = TMath::Sqrt(1./sumweightsinner);
-
+      fMeanFluxPhesInnerPixelVar = (1./sumweightsinner)*fMeanFluxPhesInnerPixel*fMeanFluxPhesInnerPixel;
     }
 
@@ -802,22 +839,51 @@
     {
       fMeanFluxPhesOuterPixel    = sumphesouter/sumweightsouter;
-      fMeanFluxPhesOuterPixelErr = TMath::Sqrt(1./sumweightsouter);
-    }
-
-  Float_t meanFluxPhotonsRelErrSquare = fMeanFluxPhesInnerPixelErr * fMeanFluxPhesInnerPixelErr 
-                                     / (fMeanFluxPhesInnerPixel    * fMeanFluxPhesInnerPixel);
+      fMeanFluxPhesOuterPixelVar = (1./sumweightsouter)*fMeanFluxPhesOuterPixel*fMeanFluxPhesOuterPixel;
+    }
+
+  Float_t meanFluxPhotonsRelVar  = fMeanFluxPhesInnerPixelVar
+                                / (fMeanFluxPhesInnerPixel * fMeanFluxPhesInnerPixel);
 
   fMeanFluxPhotonsInnerPixel    =  fMeanFluxPhesInnerPixel/fAverageQE;
-  fMeanFluxPhotonsInnerPixelErr =  TMath::Sqrt(meanFluxPhotonsRelErrSquare + avQERelErrSquare)
-                                             * fMeanFluxPhotonsInnerPixel;
-
-  fMeanFluxPhotonsOuterPixel    = 4.*fMeanFluxPhotonsInnerPixel;
-  fMeanFluxPhotonsOuterPixelErr = 4.*fMeanFluxPhotonsInnerPixelErr;  
+  fMeanFluxPhotonsInnerPixelVar =  (meanFluxPhotonsRelVar + avQERelVar)
+                                 * fMeanFluxPhotonsInnerPixel * fMeanFluxPhotonsInnerPixel;
+
+  fMeanFluxPhotonsOuterPixel    = 4. *fMeanFluxPhotonsInnerPixel;
+  fMeanFluxPhotonsOuterPixelVar = 16.*fMeanFluxPhotonsInnerPixelVar;  
   
+  *fLog << inf << " Mean number of photo-electrons from inner pixels (F-Factor Method): "
+        << fMeanFluxPhesInnerPixel << " +- " << GetMeanFluxPhesInnerPixelErr() << endl;
+
+  *fLog << inf << " Mean number of photons from inner pixels (F-Factor Method): "
+        << fMeanFluxPhotonsInnerPixel << " +- " << GetMeanFluxPhotonsInnerPixelErr() << endl;
+
   //
   // Here starts the second loop discarting pixels out of the range:
   //
-  const Float_t innererr = TMath::Sqrt((Float_t)validinner)*fPheFFactorRelLimit*fMeanFluxPhesInnerPixelErr;
-  const Float_t outererr = TMath::Sqrt((Float_t)validouter)*fPheFFactorRelLimit*fMeanFluxPhesOuterPixelErr;
+  const Float_t innervar = (Float_t)validinner*fPheFFactorRelVarLimit*fMeanFluxPhesInnerPixelVar;
+  const Float_t outervar = (Float_t)validouter*fPheFFactorRelVarLimit*fMeanFluxPhesOuterPixelVar;
+  
+  Float_t innererr;
+  Float_t outererr;
+
+  if (innervar > 0.)
+    innererr = TMath::Sqrt(innervar);
+  else
+    {
+      *fLog << warn << GetDescriptor() << ": Variance of mean number of photo-electrons for inner pixels "
+            << " is smaller than 0. " << endl;
+      SetFFactorMethodValid(kFALSE);
+      return kFALSE;
+    }
+  
+  if (outervar > 0.)
+    outererr = TMath::Sqrt(outervar);
+  else
+    {
+      *fLog << warn << GetDescriptor() << ": Variance of mean number of photo-electrons for outer pixels "
+            << " is smaller than 0. " << endl;
+      SetFFactorMethodValid(kFALSE);
+      return kFALSE;
+    }
 
   const Float_t lowerpheinnerlimit = fMeanFluxPhesInnerPixel - innererr;
@@ -851,4 +917,5 @@
       if (npheerr > 0.)
         {
+          const Float_t weight = nphe*nphe/npheerr/npheerr;
           // 
           // first the inner pixels:
@@ -859,9 +926,8 @@
               if (nphe < lowerpheinnerlimit || nphe > upperpheinnerlimit)
                 {
-                  pix2->SetFFactorMethodValid(kFALSE);
+                  bad[idx].SetUnsuitable(MBadPixelsPix::kUnreliableRun);
                   continue;
                 }
 
-              const Float_t weight = 1./npheerr/npheerr;
               sumweightsinner += weight;
               sumphesinner    += weight*nphe;
@@ -874,9 +940,8 @@
               if (nphe < lowerpheouterlimit || nphe > upperpheouterlimit)
                 {
-                  pix2->SetFFactorMethodValid(kFALSE);
+                  bad[idx].SetUnsuitable(MBadPixelsPix::kUnreliableRun);
                   continue;
                 }
 
-              const Float_t weight = 1./npheerr/npheerr;
               sumweightsouter += weight;
               sumphesouter    += weight*nphe;
@@ -895,5 +960,5 @@
     {
       fMeanFluxPhesInnerPixel    = sumphesinner/sumweightsinner;
-      fMeanFluxPhesInnerPixelErr = TMath::Sqrt(1./sumweightsinner);
+      fMeanFluxPhesInnerPixelVar = (1./sumweightsinner)*fMeanFluxPhesInnerPixel*fMeanFluxPhesInnerPixel;
 
     }
@@ -907,22 +972,22 @@
     {
       fMeanFluxPhesOuterPixel    = sumphesouter/sumweightsouter;
-      fMeanFluxPhesOuterPixelErr = TMath::Sqrt(1./sumweightsouter);
-    }
-
-  meanFluxPhotonsRelErrSquare = fMeanFluxPhesInnerPixelErr * fMeanFluxPhesInnerPixelErr 
-                             / (fMeanFluxPhesInnerPixel    * fMeanFluxPhesInnerPixel);
+      fMeanFluxPhesOuterPixelVar = (1./sumweightsouter)*fMeanFluxPhesOuterPixel*fMeanFluxPhesOuterPixel;
+    }
+
+  meanFluxPhotonsRelVar = fMeanFluxPhesInnerPixelVar
+                       / (fMeanFluxPhesInnerPixel    * fMeanFluxPhesInnerPixel);
 
   fMeanFluxPhotonsInnerPixel    =  fMeanFluxPhesInnerPixel/fAverageQE;
-  fMeanFluxPhotonsInnerPixelErr =  TMath::Sqrt(meanFluxPhotonsRelErrSquare + avQERelErrSquare)
-                                 * fMeanFluxPhotonsInnerPixel;
-
-  fMeanFluxPhotonsOuterPixel    = 4.*fMeanFluxPhotonsInnerPixel;
-  fMeanFluxPhotonsOuterPixelErr = 4.*fMeanFluxPhotonsInnerPixelErr;  
+  fMeanFluxPhotonsInnerPixelVar =  (meanFluxPhotonsRelVar + avQERelVar)
+                                 * fMeanFluxPhotonsInnerPixel * fMeanFluxPhotonsInnerPixel;
+
+  fMeanFluxPhotonsOuterPixel    = 4. *fMeanFluxPhotonsInnerPixel;
+  fMeanFluxPhotonsOuterPixelVar = 16.*fMeanFluxPhotonsInnerPixelVar;  
 
   *fLog << inf << " Mean number of photo-electrons from inner pixels (F-Factor Method): "
-        << fMeanFluxPhesInnerPixel << " +- " << fMeanFluxPhesInnerPixelErr << endl;
+        << fMeanFluxPhesInnerPixel << " +- " << GetMeanFluxPhesInnerPixelErr() << endl;
 
   *fLog << inf << " Mean number of photons from inner pixels (F-Factor Method): "
-        << fMeanFluxPhotonsInnerPixel << " +- " << fMeanFluxPhotonsInnerPixelErr << endl;
+        << fMeanFluxPhotonsInnerPixel << " +- " << GetMeanFluxPhotonsInnerPixelErr() << endl;
 
   return kTRUE;
@@ -932,6 +997,6 @@
 {
 
-  const Float_t meanphotRelErrSquare        = fMeanFluxPhotonsInnerPixelErr * fMeanFluxPhotonsInnerPixelErr
-                                           /( fMeanFluxPhotonsInnerPixel    * fMeanFluxPhotonsInnerPixel );
+  const Float_t meanphotRelVar  = fMeanFluxPhotonsInnerPixelVar
+                               /( fMeanFluxPhotonsInnerPixel    * fMeanFluxPhotonsInnerPixel );
 
   TIter Next(fPixels);
@@ -971,15 +1036,15 @@
         }
       
-      const Float_t chargeRelErrSquare       =   pix->GetMeanChargeErr() * pix->GetMeanChargeErr()
-                                             / ( pix->GetMeanCharge()    * pix->GetMeanCharge());
-      const Float_t rsigmaChargeRelErrSquare =   pix->GetRSigmaChargeErr() *  pix->GetRSigmaChargeErr()
-  	                                      / (pix->GetRSigmaCharge()    * pix->GetRSigmaCharge()) ;
-
-      const Float_t convrelerr = TMath::Sqrt(meanphotRelErrSquare + chargeRelErrSquare);
-
-      if (convrelerr > fConvFFactorRelErrLimit)
+      const Float_t chargeRelVar       =   pix->GetMeanChargeErr() * pix->GetMeanChargeErr()
+                                       / ( pix->GetMeanCharge()    * pix->GetMeanCharge());
+      const Float_t rsigmaChargeRelVar =   pix->GetRSigmaChargeErr() *  pix->GetRSigmaChargeErr()
+                                        / (pix->GetRSigmaCharge()    * pix->GetRSigmaCharge()) ;
+
+      const Float_t convrelvar = meanphotRelVar + chargeRelVar;
+
+      if (convrelvar > fConvFFactorRelVarLimit)
         {
-          *fLog << warn << GetDescriptor() << ": Conversion Factor F-Factor Method Rel. Error: " 
-                << convrelerr << " above limit of: " << fConvFFactorRelErrLimit 
+          *fLog << warn << GetDescriptor() << ": Conversion Factor F-Factor Method Rel. Variance: " 
+                << convrelvar << " above limit of: " << fConvFFactorRelVarLimit 
                 << " in pixel: " << idx << endl;
           pix->SetFFactorMethodValid(kFALSE);
@@ -996,14 +1061,16 @@
       // Calculate the error of the Total F-Factor of the camera ( in photons )
       //
-      const Float_t totalFFactorErr = TMath::Sqrt(  rsigmaChargeRelErrSquare
-                                    + chargeRelErrSquare
-                                    + meanphotRelErrSquare );
-
-      pix->SetConversionFFactorMethod(conv,
-                                      convrelerr*conv,
-                                      totalFFactor*TMath::Sqrt(conv));
+      const Float_t totalFFactorVar = rsigmaChargeRelVar + chargeRelVar + meanphotRelVar;
+
+      if (convrelvar > 0. && conv > 0.)
+        pix->SetConversionFFactorMethod(conv,
+                                        TMath::Sqrt(convrelvar)*conv,
+                                        totalFFactor*TMath::Sqrt(conv));
 
       pix->SetTotalFFactorFFactorMethod(   totalFFactor   );
-      pix->SetTotalFFactorErrFFactorMethod(totalFFactorErr);      
+
+      if (totalFFactorVar > 0.)
+        pix->SetTotalFFactorFFactorMethodErr(TMath::Sqrt(totalFFactorVar));      
+
       pix->SetFFactorMethodValid();
     }
@@ -1012,9 +1079,9 @@
 
 
-void MCalibrationChargeCam::ApplyBlindPixelCalibration(const MGeomCam &geom, const MBadPixelsCam &bad)
-{
-
-  Float_t flux    = fBlindPixel->GetMeanFluxInsidePlexiglass();
-  Float_t fluxerr = fBlindPixel->GetMeanFluxErrInsidePlexiglass();
+void MCalibrationChargeCam::ApplyBlindPixelCalibration(const MGeomCam &geom, const MBadPixelsCam &bad, const MCalibrationChargeBlindPix &blindpix)
+{
+
+  Float_t flux    = blindpix.GetMeanFluxInsidePlexiglass();
+  Float_t fluxerr = blindpix.GetMeanFluxErrInsidePlexiglass();
 
   TIter Next(fPixels);
@@ -1056,9 +1123,9 @@
 }
 
-void MCalibrationChargeCam::ApplyPINDiodeCalibration(const MGeomCam &geom, const MBadPixelsCam &bad)
-{
-
-  Float_t flux    = fPINDiode->GetMeanFluxOutsidePlexiglass();
-  Float_t fluxerr = fPINDiode->GetMeanFluxErrOutsidePlexiglass();
+void MCalibrationChargeCam::ApplyPINDiodeCalibration(const MGeomCam &geom, const MBadPixelsCam &bad, const MCalibrationChargePINDiode &pindiode)
+{
+
+  Float_t flux    = pindiode.GetMeanFluxOutsidePlexiglass();
+  Float_t fluxerr = pindiode.GetMeanFluxErrOutsidePlexiglass();
 
   TIter Next(fPixels);
@@ -1137,6 +1204,4 @@
 // and the number of photons reaching the plexiglass for one Inner Pixel 
 //
-// FIXME: The PINDiode is still not working and so is the code 
-//
 Bool_t MCalibrationChargeCam::GetConversionFactorPINDiode(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
 {
@@ -1157,6 +1222,4 @@
 // and the number of photons reaching one Inner Pixel. 
 // The procedure is not yet defined.
-//
-// FIXME: The PINDiode is still not working and so is the code 
 //
 Bool_t MCalibrationChargeCam::GetConversionFactorCombined(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h	(revision 3510)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h	(revision 3511)
@@ -26,11 +26,11 @@
   
   static const Float_t fgConvFFactorRelErrLimit; // The limit for acceptance of the rel. error of the conversion factor with the FFactor method
-  static const Float_t fgPheFFactorRelLimit;     // The rel. limit for acceptance of a calculated number of phe's w.r.t the mean number (in sigma of the error)
+  static const Float_t fgPheFFactorRelErrLimit;  // The rel. limit for acceptance of a calculated number of phe's w.r.t the mean number (in sigma of the error)
   
   Float_t fAverageQE;                // The average quantum efficieny (see Class description)
-  Float_t fAverageQEErr;             // The error of the average quantum efficieny (see Class description)
+  Float_t fAverageQEVar;             // The error of the average quantum efficieny (see Class description)
   
-  Float_t fConvFFactorRelErrLimit;   // The limit for acceptance of the rel. error of the conversion factor with the FFactor method
-  Float_t fPheFFactorRelLimit;       // The rel. limit for acceptance of a calculated number of phe's w.r.t the mean number (in sigma of the error).
+  Float_t fConvFFactorRelVarLimit;   // The limit for acceptance of the rel. error of the conversion factor with the FFactor method
+  Float_t fPheFFactorRelVarLimit;    // The rel. limit for acceptance of a calculated number of phe's w.r.t the mean number (in variances of the error).
   
   Int_t fNumPixels;
@@ -43,7 +43,4 @@
   MBadPixelsPix         *fAverageOuterBadPix;    //-> Average Pixel of all events
   
-  const MCalibrationChargeBlindPix *fBlindPixel; //! Pointer to the Blind Pixel with fit results
-  const MCalibrationChargePINDiode *fPINDiode;   //! Pointer to the PIN Diode with fit results
-
   TH1D* fOffsets;                                //! 
   TH1D* fSlopes;                                 //! 
@@ -58,12 +55,12 @@
 
   Float_t fMeanFluxPhesInnerPixel;        //  The mean number of photo-electrons in an INNER PIXEL
-  Float_t fMeanFluxPhesInnerPixelErr;     //  The uncertainty about the number of photo-electrons INNER PIXEL  
+  Float_t fMeanFluxPhesInnerPixelVar;     //  The variance of the number of photo-electrons INNER PIXEL  
   Float_t fMeanFluxPhesOuterPixel;        //  The mean number of photo-electrons in an INNER PIXEL
-  Float_t fMeanFluxPhesOuterPixelErr;     //  The uncertainty about the number of photo-electrons INNER PIXEL  
+  Float_t fMeanFluxPhesOuterPixelVar;     //  The variance of the number of photo-electrons INNER PIXEL  
 
   Float_t fMeanFluxPhotonsInnerPixel;        //  The mean number of photo-electrons in an INNER PIXEL
-  Float_t fMeanFluxPhotonsInnerPixelErr;     //  The uncertainty about the number of photo-electrons INNER PIXEL  
+  Float_t fMeanFluxPhotonsInnerPixelVar;     //  The variance of the number of photo-electrons INNER PIXEL  
   Float_t fMeanFluxPhotonsOuterPixel;        //  The mean number of photo-electrons in an INNER PIXEL
-  Float_t fMeanFluxPhotonsOuterPixelErr;     //  The uncertainty about the number of photo-electrons INNER PIXEL  
+  Float_t fMeanFluxPhotonsOuterPixelVar;     //  The variance of the number of photo-electrons INNER PIXEL  
   
 public:
@@ -78,11 +75,8 @@
   void SetAverageQE(          const Float_t qe= gkAverageQE, 
 			      const Float_t err=gkAverageQEErr)         { fAverageQE    = qe;           
-			                                                  fAverageQEErr = err;         }
+			                                                  fAverageQEVar = err*err; }
   void SetNumPixelsExcluded(  const UInt_t n )            {  fNumExcludedPixels = n; }
-  void SetConvFFactorRelErrLimit( const Float_t f=fgConvFFactorRelErrLimit ) { fConvFFactorRelErrLimit = f; }
-  void SetPheFFactorRelLimit (  const Float_t f=fgPheFFactorRelLimit )     { fPheFFactorRelLimit = f;    }  
-
-  void SetPINDiode  ( const MCalibrationChargePINDiode *d ) {  fPINDiode   = d;      }
-  void SetBlindPixel( const MCalibrationChargeBlindPix *b ) {  fBlindPixel = b;      }
+  void SetConvFFactorRelErrLimit( const Float_t f=fgConvFFactorRelErrLimit ) { fConvFFactorRelVarLimit = f*f; }
+  void SetPheFFactorRelErrLimit (  const Float_t f=fgPheFFactorRelErrLimit )     { fPheFFactorRelVarLimit = f*f;    }  
 
   void SetFFactorMethodValid(    const Bool_t b = kTRUE );
@@ -100,12 +94,12 @@
 
   Float_t GetMeanFluxPhesInnerPixel()     const { return fMeanFluxPhesInnerPixel;     }
-  Float_t GetMeanFluxPhesInnerPixelErr()  const { return fMeanFluxPhesInnerPixelErr;  }
+  Float_t GetMeanFluxPhesInnerPixelErr()  const;
   Float_t GetMeanFluxPhesOuterPixel()     const { return fMeanFluxPhesOuterPixel;     }
-  Float_t GetMeanFluxPhesOuterPixelErr()  const { return fMeanFluxPhesOuterPixelErr;  }
+  Float_t GetMeanFluxPhesOuterPixelErr()  const;
 
   Float_t GetMeanFluxPhotonsInnerPixel()     const { return fMeanFluxPhotonsInnerPixel;     }
-  Float_t GetMeanFluxPhotonsInnerPixelErr()  const { return fMeanFluxPhotonsInnerPixelErr;  }
+  Float_t GetMeanFluxPhotonsInnerPixelErr()  const;
   Float_t GetMeanFluxPhotonsOuterPixel()     const { return fMeanFluxPhotonsOuterPixel;     }
-  Float_t GetMeanFluxPhotonsOuterPixelErr()  const { return fMeanFluxPhotonsOuterPixelErr;  }
+  Float_t GetMeanFluxPhotonsOuterPixelErr()  const;
 
   Bool_t IsBlindPixelMethodValid()   const;
@@ -138,8 +132,12 @@
   Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
 
-  Bool_t CalcMeanFluxPhotonsFFactorMethod(const MGeomCam &geom, const MBadPixelsCam &bad);  
+  Bool_t CalcMeanFluxPhotonsFFactorMethod(const MGeomCam &geom, MBadPixelsCam &bad);  
 
-  void   ApplyPINDiodeCalibration(const MGeomCam &geom, const MBadPixelsCam &bad);
-  void   ApplyBlindPixelCalibration(const MGeomCam &geom, const MBadPixelsCam &bad);
+  void   ApplyPINDiodeCalibration(const MGeomCam &geom,
+                                  const MBadPixelsCam &bad,
+                                  const MCalibrationChargePINDiode &pindiode);
+  void   ApplyBlindPixelCalibration(const MGeomCam &geom,
+                                    const MBadPixelsCam &bad,
+                                    const MCalibrationChargeBlindPix &blindpix);
   void   ApplyFFactorCalibration(const MGeomCam &geom, const MBadPixelsCam &bad);
 
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.cc	(revision 3510)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.cc	(revision 3511)
@@ -83,4 +83,7 @@
 //  since we might be applying it to PMTs in the totally wrong direction.
 // 
+//
+//  Error of all variables are calculated by error-propagation. Note that internally, 
+//  all error variables contain Variances in order to save the CPU-intensive square rooting 
 // 
 /////////////////////////////////////////////////////////////////////////////
@@ -109,4 +112,5 @@
 const Float_t MCalibrationChargePix::fgTimeLimit                = 1.5;
 const Float_t MCalibrationChargePix::fgTimeErrLimit             = 3.;
+const Float_t MCalibrationChargePix::fgPheFFactorMethodLimit    = 5.;
 // --------------------------------------------------------------------------
 //
@@ -136,4 +140,6 @@
   SetTimeLimit();
   SetTimeErrLimit();
+  SetPheFFactorMethodLimit();
+  
 }
 
@@ -156,17 +162,17 @@
 
   fHiGainMeanCharge                 =  -1.;
-  fHiGainMeanChargeErr              =  -1.;
+  fHiGainMeanChargeVar              =  -1.;
   fHiGainSigmaCharge                =  -1.;
-  fHiGainSigmaChargeErr             =  -1.;
+  fHiGainSigmaChargeVar             =  -1.;
   fHiGainChargeProb                 =  -1.;
 
   fLoGainMeanCharge                 =  -1.;
-  fLoGainMeanChargeErr              =  -1.;
+  fLoGainMeanChargeVar              =  -1.;
   fLoGainSigmaCharge                =  -1.;
-  fLoGainSigmaChargeErr             =  -1.;
+  fLoGainSigmaChargeVar             =  -1.;
   fLoGainChargeProb                 =  -1.;
 
   fRSigmaCharge                     =  -1.;
-  fRSigmaChargeErr                  =  -1.;
+  fRSigmaChargeVar                  =  -1.;
   
   fHiGainNumPickup                  =  -1;
@@ -177,8 +183,8 @@
   fPed                              =  -1.;
   fPedRms                           =  -1.;
-  fPedErr                           =  -1.;
+  fPedVar                           =  -1.;
 
   fLoGainPedRms                     =  -1.;
-  fLoGainPedRmsErr                  =  -1.;
+  fLoGainPedRmsVar                  =  -1.;
 
   fTimeFirstHiGain                  =   0 ;
@@ -191,5 +197,5 @@
 
   fPheFFactorMethod                 =  -1.;
-  fPheFFactorMethodErr              =  -1.;
+  fPheFFactorMethodVar              =  -1.;
 
   fMeanConversionFFactorMethod      =  -1.;
@@ -198,8 +204,8 @@
   fMeanConversionCombinedMethod     =  -1.;
 
-  fConversionFFactorMethodErr       =  -1.;
-  fConversionBlindPixelMethodErr    =  -1.;
-  fConversionPINDiodeMethodErr      =  -1.;
-  fConversionCombinedMethodErr      =  -1.;
+  fConversionFFactorMethodVar       =  -1.;
+  fConversionBlindPixelMethodVar    =  -1.;
+  fConversionPINDiodeMethodVar      =  -1.;
+  fConversionCombinedMethodVar      =  -1.;
 
   fSigmaConversionFFactorMethod     =  -1.;
@@ -231,5 +237,5 @@
   fPed       = ped;    
   fPedRms    = pedrms;
-  fPedErr    = pederr;
+  fPedVar    = pederr*pederr;
 }
   
@@ -246,7 +252,7 @@
 {
     if (IsHiGainSaturation())
-	fLoGainMeanChargeErr = f;
+	fLoGainMeanChargeVar = f*f;
     else
-	fHiGainMeanChargeErr = f;
+	fHiGainMeanChargeVar = f*f;
 
 }
@@ -264,11 +270,9 @@
 {
     if (IsHiGainSaturation())
-	fLoGainSigmaChargeErr = f;
+	fLoGainSigmaChargeVar = f*f;
     else
-	fHiGainSigmaChargeErr = f;
-
-}
-
-
+	fHiGainSigmaChargeVar = f*f;
+
+}
 
 // --------------------------------------------------------------------------
@@ -279,5 +283,5 @@
 {
   fMeanConversionFFactorMethod  = c;
-  fConversionFFactorMethodErr   = err;
+  fConversionFFactorMethodVar   = err*err;
   fSigmaConversionFFactorMethod = sig;
 }
@@ -290,5 +294,5 @@
 {
   fMeanConversionCombinedMethod  = c;
-  fConversionCombinedMethodErr   = err;
+  fConversionCombinedMethodVar   = err*err;
   fSigmaConversionCombinedMethod = sig;
 }
@@ -302,5 +306,5 @@
 {
   fMeanConversionBlindPixelMethod  = c;
-  fConversionBlindPixelMethodErr   = err;
+  fConversionBlindPixelMethodVar   = err*err;
   fSigmaConversionBlindPixelMethod = sig;
 }
@@ -313,5 +317,5 @@
 {
   fMeanConversionPINDiodeMethod  = c ;
-  fConversionPINDiodeMethodErr   = err;
+  fConversionPINDiodeMethodVar   = err*err;
   fSigmaConversionPINDiodeMethod = sig;
 }
@@ -408,8 +412,6 @@
 void MCalibrationChargePix::SetAbsTimeBordersLoGain(const Byte_t f, const Byte_t l)
 {
-
   fTimeFirstLoGain = f;
   fTimeLastLoGain  = l;
-  
 }
 
@@ -421,15 +423,20 @@
 Float_t  MCalibrationChargePix::GetPedRmsErr()  const
 {
-  return IsHiGainSaturation() ? fLoGainPedRmsErr : fPedErr/2.;
+  return IsHiGainSaturation() ? TMath::Sqrt(fLoGainPedRmsVar) : TMath::Sqrt(fPedVar)/2.;
+}
+
+Float_t  MCalibrationChargePix::GetPedErr()  const
+{
+  return  TMath::Sqrt(fPedVar);
 }
 
 Float_t  MCalibrationChargePix::GetMeanCharge()   const 
 {
-    return IsHiGainSaturation() ? fLoGainMeanCharge : fHiGainMeanCharge ;
+    return IsHiGainSaturation() ? GetLoGainMeanCharge() : GetHiGainMeanCharge() ;
 }
 
 Float_t  MCalibrationChargePix::GetMeanChargeErr()   const 
 {
-    return IsHiGainSaturation() ? fLoGainMeanChargeErr : fHiGainMeanChargeErr ;
+    return IsHiGainSaturation() ? GetLoGainMeanChargeErr() : GetHiGainMeanChargeErr() ;
 }
 
@@ -441,10 +448,144 @@
 Float_t  MCalibrationChargePix::GetSigmaCharge()   const 
 {
-    return IsHiGainSaturation() ? fLoGainSigmaCharge : fHiGainSigmaCharge ;
+    return IsHiGainSaturation() ? GetLoGainSigmaCharge() : GetHiGainSigmaCharge() ;
 }
 
 Float_t  MCalibrationChargePix::GetSigmaChargeErr()   const 
 {
-    return IsHiGainSaturation() ? fLoGainSigmaChargeErr : fHiGainSigmaChargeErr ;
+    return IsHiGainSaturation() ? GetLoGainSigmaChargeErr() : GetHiGainSigmaChargeErr() ;
+}
+
+Float_t MCalibrationChargePix::GetHiGainMeanChargeErr()  const
+{
+  return TMath::Sqrt(fHiGainMeanChargeVar);
+}
+
+Float_t MCalibrationChargePix::GetLoGainMeanCharge()  const 
+{
+  return fLoGainMeanCharge * fConversionHiLo;
+}
+
+Float_t MCalibrationChargePix::GetLoGainMeanChargeErr()  const
+{
+
+  const Float_t chargeRelVar     =  fLoGainMeanChargeVar
+                                 /( fLoGainMeanCharge * fLoGainMeanCharge );
+
+  const Float_t conversionRelVar =  fConversionHiLoVar
+                                 /( fConversionHiLo   * fConversionHiLo   );
+
+  return TMath::Sqrt(chargeRelVar+conversionRelVar) * GetLoGainMeanCharge();
+}
+
+Float_t MCalibrationChargePix::GetLoGainSigmaCharge()  const 
+{
+  return fLoGainSigmaCharge * fConversionHiLo;
+}
+
+Float_t MCalibrationChargePix::GetLoGainSigmaChargeErr()  const
+{
+
+  const Float_t sigmaRelVar     =  fLoGainSigmaChargeVar
+                                /( fLoGainSigmaCharge * fLoGainSigmaCharge );
+
+  const Float_t conversionRelVar =  fConversionHiLoVar
+                                 /( fConversionHiLo   * fConversionHiLo   );
+
+  return TMath::Sqrt(sigmaRelVar+conversionRelVar) * GetLoGainSigmaCharge();
+}
+
+Float_t MCalibrationChargePix::GetHiGainSigmaChargeErr()  const
+{
+  return TMath::Sqrt(fHiGainSigmaChargeVar);
+}
+
+Float_t MCalibrationChargePix::GetRSigmaCharge()  const
+{
+  return IsHiGainSaturation() ? fRSigmaCharge*fConversionHiLo : fRSigmaCharge ;
+} 
+
+Float_t MCalibrationChargePix::GetRSigmaChargeErr()  const
+{
+ if (IsHiGainSaturation())
+    {
+      const Float_t rsigmaRelVar     =  fRSigmaChargeVar
+                                    /( fRSigmaCharge * fRSigmaCharge );
+      const Float_t conversionRelVar =  fConversionHiLoVar
+                                     /( fConversionHiLo   * fConversionHiLo   );
+      return TMath::Sqrt(rsigmaRelVar+conversionRelVar) * GetRSigmaCharge();
+    }
+ else
+   return TMath::Sqrt(fRSigmaChargeVar);
+
+}
+
+Float_t MCalibrationChargePix::GetConversionHiLoErr()  const
+{
+  if (fConversionHiLoVar < 0.)
+    return -1.;
+  return TMath::Sqrt(fConversionHiLoVar);
+}
+
+Float_t MCalibrationChargePix::GetPheFFactorMethodErr()  const
+{
+  if (fPheFFactorMethodVar < 0.)
+    return -1.;
+  return TMath::Sqrt(fPheFFactorMethodVar);
+}
+
+Float_t MCalibrationChargePix::GetConversionCombinedMethodErr()  const
+{
+  if (fConversionCombinedMethodVar < 0.)
+    return -1.;
+  return TMath::Sqrt(fConversionCombinedMethodVar);
+}
+
+Float_t MCalibrationChargePix::GetConversionPINDiodeMethodErr()  const
+{
+  if (fConversionPINDiodeMethodVar < 0.)
+    return -1.;
+  return TMath::Sqrt(fConversionPINDiodeMethodVar);
+}
+
+Float_t MCalibrationChargePix::GetConversionBlindPixelMethodErr()  const
+{
+  if (fConversionBlindPixelMethodVar < 0.)
+    return -1.;
+  return TMath::Sqrt(fConversionBlindPixelMethodVar);
+}
+
+Float_t MCalibrationChargePix::GetConversionFFactorMethodErr()  const
+{
+  if (fConversionFFactorMethodVar < 0.)
+    return -1.;
+  return TMath::Sqrt(fConversionFFactorMethodVar);
+}
+
+Float_t MCalibrationChargePix::GetTotalFFactorCombinedMethodErr()  const
+{
+  if (fTotalFFactorCombinedMethodVar < 0.)
+    return -1.;
+  return TMath::Sqrt(fTotalFFactorCombinedMethodVar);
+}
+
+Float_t MCalibrationChargePix::GetTotalFFactorPINDiodeMethodErr()  const
+{
+  if (fTotalFFactorPINDiodeMethodVar < 0.)
+    return -1.;
+  return TMath::Sqrt(fTotalFFactorPINDiodeMethodVar);
+}
+
+Float_t MCalibrationChargePix::GetTotalFFactorBlindPixelMethodErr()  const
+{
+  if (fTotalFFactorBlindPixelMethodVar < 0.)
+    return -1.;
+  return TMath::Sqrt(fTotalFFactorBlindPixelMethodVar);
+}
+
+Float_t MCalibrationChargePix::GetTotalFFactorFFactorMethodErr()  const
+{
+  if (fTotalFFactorFFactorMethodVar < 0.)
+    return -1.;
+  return TMath::Sqrt(fTotalFFactorFFactorMethodVar);
 }
 
@@ -454,5 +595,4 @@
 }
 
-
 Bool_t MCalibrationChargePix::IsExcluded()     const
 { 
@@ -505,6 +645,6 @@
 //
 // 1) Pixel has a fitted charge greater than fChargeLimit*PedRMS
-// 2) Pixel has a fit error greater than fChargeErrLimit
-// 3) Pixel has a fitted charge greater its fChargeRelErrLimit times its charge error
+// 2) Pixel has a fit error greater than fChargeVarLimit
+// 3) Pixel has a fitted charge greater its fChargeRelVarLimit times its charge error
 // 4) Pixel has a charge sigma bigger than its Pedestal RMS
 // 
@@ -520,16 +660,18 @@
     }
   
-  if (GetMeanChargeErr() < fChargeErrLimit) 
-    {
-      *fLog << warn << "WARNING: Error of Fitted Charge is smaller than "
-            << fChargeErrLimit << " in Pixel  " << fPixId << endl;
+  const Float_t meanchargevar = IsHiGainSaturation() ? fLoGainMeanChargeVar : fHiGainMeanChargeVar;
+  
+  if (meanchargevar < fChargeVarLimit) 
+    {
+      *fLog << warn << "WARNING: Variance of Fitted Charge is smaller than "
+            << meanchargevar << " in Pixel  " << fPixId << endl;
       bad->SetChargeErrNotValid();
       bad->SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
     }
       
-   if (GetMeanCharge() < fChargeRelErrLimit*GetMeanChargeErr()) 
+   if (GetMeanCharge()*GetMeanCharge() < fChargeRelVarLimit*meanchargevar) 
     {
       *fLog << warn << "WARNING: Fitted Charge is smaller than "
-            << fChargeRelErrLimit << "* its error in Pixel  " << fPixId << endl;
+            << TMath::Sqrt(fChargeRelVarLimit) << "* its error in Pixel  " << fPixId << endl;
       bad->SetChargeRelErrNotValid();
       bad->SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
@@ -577,7 +719,6 @@
 {
 
-    Float_t pedRmsSquare          = fPedRms * fPedRms;
-    Float_t pedRmsSquareErrSquare = fPedErr * fPedErr * pedRmsSquare; // fPedRmsErr = fPedErr/2.
-    Float_t pedRmsSquareErr;
+    Float_t pedRmsSquare      = fPedRms * fPedRms;
+    Float_t pedRmsSquareVar   = fPedVar * pedRmsSquare; // fPedRmsErr = fPedErr/2.
     
     //
@@ -587,13 +728,13 @@
     // We extract the pure NSB contribution:
     //
-    const Float_t elecRmsSquare          =    fElectronicPedRms    * fElectronicPedRms;
-    const Float_t elecRmsSquareErrSquare = 4.*fElectronicPedRmsErr * fElectronicPedRmsErr * elecRmsSquare;
+    const Float_t elecRmsSquare    =    fElectronicPedRms    * fElectronicPedRms;
+    const Float_t elecRmsSquareVar = 4.*fElectronicPedRmsVar * elecRmsSquare;
     
-    Float_t nsbSquare             =  pedRmsSquare          - elecRmsSquare;
-    Float_t nsbSquareRelErrSquare = (pedRmsSquareErrSquare + elecRmsSquareErrSquare)
+    Float_t nsbSquare             =  pedRmsSquare    - elecRmsSquare;
+    Float_t nsbSquareRelVar       = (pedRmsSquareVar + elecRmsSquareVar)
                                 	/ (nsbSquare * nsbSquare) ;
     
     if (nsbSquare < 0.)
-        nsbSquare = 0.;
+      nsbSquare = 0.;
     
     //
@@ -601,40 +742,41 @@
     // add it quadratically to the electronic noise
     //
-    const Float_t conversionSquare             =    fConversionHiLo    * fConversionHiLo;
-    const Float_t conversionSquareRelErrSquare = 4.*fConversionHiLoErr * fConversionHiLoErr / conversionSquare;
+    const Float_t conversionSquare        =    fConversionHiLo    * fConversionHiLo;
+    const Float_t convertedNsbSquare      =    nsbSquare       / conversionSquare;
+    const Float_t convertedNsbSquareVar   =    nsbSquareRelVar
+                                    	    * convertedNsbSquare * convertedNsbSquare;
     
-    const Float_t convertedNsbSquare          =  nsbSquare             / conversionSquare;
-    const Float_t convertedNsbSquareErrSquare = (nsbSquareRelErrSquare + conversionSquareRelErrSquare)
-                                        	* convertedNsbSquare * convertedNsbSquare;
+    pedRmsSquare     = convertedNsbSquare    + elecRmsSquare;
+    pedRmsSquareVar  = convertedNsbSquareVar + elecRmsSquareVar;
     
-    pedRmsSquare     = convertedNsbSquare           + elecRmsSquare;
-    pedRmsSquareErr  = TMath::Sqrt( convertedNsbSquareErrSquare  + elecRmsSquareErrSquare );
-    
-    //
-    // Correct also for the conversion to Hi-Gain:
-    //
-    fLoGainPedRms    = TMath::Sqrt(pedRmsSquare)               * fConversionHiLo;
-    fLoGainPedRmsErr = 0.5 * pedRmsSquareErr /  fLoGainPedRms  * fConversionHiLo;
-}
-
+    fLoGainPedRms    = TMath::Sqrt(pedRmsSquare);
+    fLoGainPedRmsVar = 0.25 * pedRmsSquareVar /  pedRmsSquare;
+
+}
+
+//
+// 
+//
 Bool_t MCalibrationChargePix::CalcReducedSigma()
 {
 
-  const Float_t sigmaSquare               =    GetSigmaCharge()   * GetSigmaCharge();
-  const Float_t sigmaSquareErrSquare      = 4.*GetSigmaChargeErr()* GetSigmaChargeErr() * sigmaSquare;
-
-  Float_t pedRmsSquare;         
-  Float_t pedRmsSquareErrSquare;
+  const Float_t sigmacharge    = IsHiGainSaturation() ? fLoGainSigmaCharge    : fHiGainSigmaCharge   ;
+  const Float_t sigmachargevar = IsHiGainSaturation() ? fLoGainSigmaChargeVar : fHiGainSigmaChargeVar;
+
+  const Float_t sigmaSquare     =      sigmacharge     * sigmacharge;
+  const Float_t sigmaSquareVar  = 4.*  sigmachargevar  * sigmaSquare;
+
+  Float_t pedRmsSquare ;         
+  Float_t pedRmsSquareVar;
   
   if (IsHiGainSaturation())
-  {
-      pedRmsSquare             =      fLoGainPedRms    * fLoGainPedRms;
-      pedRmsSquareErrSquare    =  4.* fLoGainPedRmsErr * fLoGainPedRmsErr * pedRmsSquare;
+    {
+      pedRmsSquare     =      fLoGainPedRms    * fLoGainPedRms;
+      pedRmsSquareVar  =  4.* fLoGainPedRmsVar * pedRmsSquare;
     }
   else
   {
-
-      pedRmsSquare           =       fPedRms * fPedRms;                                          
-      pedRmsSquareErrSquare  =       fPedErr * fPedErr * pedRmsSquare; // fPedRmsErr = fPedErr/2.
+      pedRmsSquare       =  fPedRms * fPedRms;                                          
+      pedRmsSquareVar    =  fPedVar * pedRmsSquare; // fPedRmsErr = fPedErr/2.
   }
   //
@@ -642,5 +784,4 @@
   //
   const Float_t rsigmachargesquare = sigmaSquare - pedRmsSquare;
-
   if (rsigmachargesquare <= 0.)
     {
@@ -651,6 +792,7 @@
     }
   
+
   fRSigmaCharge    = TMath::Sqrt(rsigmachargesquare);
-  fRSigmaChargeErr = TMath::Sqrt(sigmaSquareErrSquare + pedRmsSquareErrSquare) / 2. / fRSigmaCharge;
+  fRSigmaChargeVar = 0.25 * (sigmaSquareVar + pedRmsSquareVar) / rsigmachargesquare;
 
   return kTRUE;
@@ -670,4 +812,7 @@
     }
   
+  const Float_t charge    = IsHiGainSaturation() ? fLoGainMeanCharge    : fHiGainMeanCharge   ;
+  const Float_t chargevar = IsHiGainSaturation() ? fLoGainMeanChargeVar : fHiGainMeanChargeVar;
+
   //
   // Square all variables in order to avoid applications of square root
@@ -675,14 +820,12 @@
   // First the relative error squares
   //
-  const Float_t chargeSquare              =     GetMeanCharge()    * GetMeanCharge();
-  const Float_t chargeSquareRelErrSquare  = 4.* GetMeanChargeErr() * GetMeanChargeErr() / chargeSquare;
-
-  const Float_t ffactorsquare             =    gkFFactor    * gkFFactor;
-  const Float_t ffactorsquareRelErrSquare = 4.*gkFFactorErr * gkFFactorErr / ffactorsquare;
-
-
-  const Float_t rsigmaSquare              =     fRSigmaCharge    * fRSigmaCharge;
-  const Float_t rsigmaSquareRelErrSquare  = 4.* fRSigmaChargeErr * fRSigmaChargeErr / rsigmaSquare;
-
+  const Float_t chargeSquare        =     charge * charge;
+  const Float_t chargeSquareRelVar  = 4.* chargevar/ chargeSquare;
+
+  const Float_t ffactorsquare       =    gkFFactor    * gkFFactor;
+  const Float_t ffactorsquareRelVar = 4.*gkFFactorErr * gkFFactorErr / ffactorsquare;
+
+  const Float_t rsigmaSquare        =     fRSigmaCharge    * fRSigmaCharge;
+  const Float_t rsigmaSquareRelVar  = 4.* fRSigmaChargeVar / rsigmaSquare;
 
   //
@@ -692,5 +835,5 @@
   fPheFFactorMethod = ffactorsquare * chargeSquare / rsigmaSquare;
 
-  if (fPheFFactorMethod < 0.)
+  if (fPheFFactorMethod < fPheFFactorMethodLimit)
     {
       SetFFactorMethodValid(kFALSE);
@@ -701,11 +844,8 @@
   // Calculate the Error of Nphe
   //
-  const Float_t pheFFactorRelErrSquare =  ffactorsquareRelErrSquare
-                                         + chargeSquareRelErrSquare
-                                         + rsigmaSquareRelErrSquare;
-  fPheFFactorMethodErr                 =  TMath::Sqrt(pheFFactorRelErrSquare) * fPheFFactorMethod;
+  fPheFFactorMethodVar =  (ffactorsquareRelVar + chargeSquareRelVar + rsigmaSquareRelVar) 
+                         * fPheFFactorMethod * fPheFFactorMethod;
 
   SetFFactorMethodValid(kTRUE);
-
   return kTRUE;
 }
@@ -715,23 +855,9 @@
 {
   
-  const Float_t chargeRelErrSquare     =    fLoGainMeanChargeErr * fLoGainMeanChargeErr
-                                         /( fLoGainMeanCharge    * fLoGainMeanCharge  );
-  const Float_t sigmaRelErrSquare      =    fLoGainSigmaChargeErr * fLoGainSigmaChargeErr
-                                         /( fLoGainSigmaCharge    * fLoGainSigmaCharge );
-  const Float_t conversionRelErrSquare =    fConversionHiLoErr * fConversionHiLoErr 
-                                         /( fConversionHiLo    * fConversionHiLo  );
-  
-  fLoGainMeanCharge         *= fConversionHiLo;
-  fLoGainMeanChargeErr       = TMath::Sqrt(chargeRelErrSquare + conversionRelErrSquare) * fLoGainMeanCharge;
-  
-  fLoGainSigmaCharge        *= fConversionHiLo;
-  fLoGainSigmaChargeErr      =  TMath::Sqrt(sigmaRelErrSquare + conversionRelErrSquare) * fLoGainSigmaCharge;
-  
-  fElectronicPedRms     = gkElectronicPedRms    * TMath::Sqrt(fNumLoGainSamples);
-  fElectronicPedRmsErr  = gkElectronicPedRmsErr * TMath::Sqrt(fNumLoGainSamples);
+  fElectronicPedRms       = gkElectronicPedRms    * TMath::Sqrt(fNumLoGainSamples);
+  fElectronicPedRmsVar    = gkElectronicPedRmsErr * gkElectronicPedRmsErr * fNumLoGainSamples;
   
   CalcLoGainPed();
-
-}
-
-
+}
+
+
