Index: trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc	(revision 3029)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc	(revision 3059)
@@ -35,6 +35,4 @@
 // 3) It initializes a pointer to an MCalibrationPINDiode container
 //
-// 4)  
-// 
 /////////////////////////////////////////////////////////////////////////////
 #include "MCalibrationCam.h"
@@ -48,4 +46,5 @@
 
 #include "MGeomCam.h"
+#include "MGeomPix.h"
 
 #include "MCalibrationPix.h"
@@ -62,5 +61,4 @@
 const Int_t   MCalibrationCam::gkBlindPixelId   =  559;
 const Int_t   MCalibrationCam::gkPINDiodeId     = 9999;
-const Float_t MCalibrationCam::gkTimeSliceWidth = 3.3;
 
 // --------------------------------------------------------------------------
@@ -383,98 +381,289 @@
     return kFALSE;
 
-  if ( (!(*this)[idx].IsChargeFitValid()) || (*this)[idx].IsExcluded())
-    return kFALSE;
-  
-  if (idx == gkBlindPixelId)
-    return kFALSE;
-
-  if (idx == gkPINDiodeId)
-    return kFALSE;
-
   switch (type)
     {
     case 0:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
       val = (*this)[idx].GetCharge();
       break;
     case 1:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
       val = (*this)[idx].GetErrCharge();
       break;
     case 2:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
       val = (*this)[idx].GetSigmaCharge();
       break;
     case 3:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
       val = (*this)[idx].GetErrSigmaCharge();
       break;
     case 4:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
       val = (*this)[idx].GetChargeProb();
       break;
     case 5:
-      if (!(*this)[idx].IsTimeFitValid())
-        return kFALSE;
-      val = (*this)[idx].GetMeanTimeOffset() * gkTimeSliceWidth;
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetRSigmaCharge();
       break;
     case 6:
-      if (!(*this)[idx].IsTimeFitValid())
-        return kFALSE;
-      val = (*this)[idx].GetTimingPrecision() * gkTimeSliceWidth;
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetErrRSigmaCharge();
       break;
     case 7:
-      if (!(*this)[idx].IsTimeFitValid())
-        return kFALSE;
-      val = (*this)[idx].GetTimeProb();
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetRSigmaCharge() / (*this)[idx].GetCharge();
       break;
     case 8:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      // relative error RsigmaCharge square
+      val =    (*this)[idx].GetErrRSigmaCharge()* (*this)[idx].GetErrRSigmaCharge() 
+            / ((*this)[idx].GetRSigmaCharge()   * (*this)[idx].GetRSigmaCharge()   );
+      // relative error Charge square
+      val +=   (*this)[idx].GetErrCharge() * (*this)[idx].GetErrCharge()
+            / ((*this)[idx].GetCharge()    * (*this)[idx].GetCharge()   );
+      // calculate relative error out of squares
+      val  =   TMath::Sqrt(val) ;
+      // multiply with value to get absolute error
+      val  *=  (*this)[idx].GetRSigmaCharge() / (*this)[idx].GetCharge();
+      break;
+    case 9:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetPheFFactorMethod();
+      break;
+    case 10:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetPheFFactorMethodError();
+      break;
+    case 11:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetMeanConversionFFactorMethod();
+      break;
+    case 12:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetErrorConversionFFactorMethod();
+      break;
+    case 13:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetTotalFFactorFFactorMethod();
+      break;
+    case 14:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetTotalFFactorErrorFFactorMethod();
+      break;
+    case 15:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if (cam[idx].IsInOuterRing())
+	val = GetMeanPhotInsidePlexiglass()*gkCalibrationOutervsInnerPixelArea;
+      else
+	val = GetMeanPhotInsidePlexiglass();
+      break;
+    case 16:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if (cam[idx].IsInOuterRing())
+	val = (double)fMeanPhotInsidePlexiglass*gkCalibrationOutervsInnerPixelArea;
+      else
+	val = (double)fMeanPhotInsidePlexiglass;
+      break;
+    case 17:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if (cam[idx].IsInOuterRing())
+        val = (*this)[idx].GetMeanConversionBlindPixelMethod()*gkCalibrationOutervsInnerPixelArea;
+      else 
+        val = (*this)[idx].GetMeanConversionBlindPixelMethod();
+      break;
+    case 18:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if (cam[idx].IsInOuterRing())
+        {
+        val =  (*this)[idx].GetErrorConversionBlindPixelMethod()*(*this)[idx].GetErrorConversionBlindPixelMethod()
+                          * gkCalibrationOutervsInnerPixelArea * gkCalibrationOutervsInnerPixelArea;
+        val +=  gkCalibrationOutervsInnerPixelAreaError * gkCalibrationOutervsInnerPixelAreaError
+             * (*this)[idx].GetMeanConversionBlindPixelMethod() *(*this)[idx].GetMeanConversionBlindPixelMethod();
+        val = TMath::Sqrt(val);
+        }
+      else 
+        val = (*this)[idx].GetErrorConversionBlindPixelMethod();
+      break;
+    case 19:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetTotalFFactorBlindPixelMethod();
+      break;
+    case 20:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetTotalFFactorErrorBlindPixelMethod();
+      break;
+    case 21:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if (cam[idx].IsInOuterRing())
+	val = GetMeanPhotOutsidePlexiglass()*gkCalibrationOutervsInnerPixelArea;
+      else
+	val = GetMeanPhotOutsidePlexiglass();
+      break;
+    case 22:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if (cam[idx].IsInOuterRing())
+	val = (double)fMeanPhotOutsidePlexiglass*gkCalibrationOutervsInnerPixelArea;
+      else
+	val = (double)fMeanPhotOutsidePlexiglass;
+      break;
+    case 23:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if (cam[idx].IsInOuterRing())
+        val = (*this)[idx].GetMeanConversionPINDiodeMethod()*gkCalibrationOutervsInnerPixelArea;
+      else 
+        val = (*this)[idx].GetMeanConversionPINDiodeMethod();
+      break;
+    case 24:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if (cam[idx].IsInOuterRing())
+        {
+          val =  (*this)[idx].GetErrorConversionPINDiodeMethod()*(*this)[idx].GetErrorConversionPINDiodeMethod()
+                          * gkCalibrationOutervsInnerPixelArea * gkCalibrationOutervsInnerPixelArea;
+          val +=  gkCalibrationOutervsInnerPixelAreaError * gkCalibrationOutervsInnerPixelAreaError
+               * (*this)[idx].GetMeanConversionPINDiodeMethod() *(*this)[idx].GetMeanConversionPINDiodeMethod();
+          val = TMath::Sqrt(val);
+        }
+      else 
+        val = (*this)[idx].GetErrorConversionPINDiodeMethod();
+      break;
+    case 25:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetTotalFFactorBlindPixelMethod();
+      break;
+    case 26:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = (*this)[idx].GetTotalFFactorErrorBlindPixelMethod();
+      break;
+    case 27:
+      if ((*this)[idx].IsExcluded())
+        val = 1.;
+      else
+        return kFALSE;
+      break;
+    case 28:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if (!(*this)[idx].IsFitted())
+        val = 1;
+      else
+        return kFALSE;
+      break;
+    case 29:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if (!(*this)[idx].IsFitted())
+        return kFALSE;
+      if (!(*this)[idx].IsChargeFitValid())
+        val = 1;
+      else
+        return kFALSE;
+      break;
+    case 30:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if ((*this)[idx].IsOscillating())
+        val = 1;
+      else
+        return kFALSE;
+      break;
+    case 31:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if ((*this)[idx].IsHiGainSaturation())
+        val = 1;
+      else
+        return kFALSE;
+      break;
+    case 32:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if ((*this)[idx].IsFFactorMethodValid())
+        val = 1;
+      else
+        return kFALSE;
+      break;
+    case 33:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if ((*this)[idx].IsBlindPixelMethodValid())
+        val = 1;
+      else
+        return kFALSE;
+      break;
+    case 34:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      if ((*this)[idx].IsPINDiodeMethodValid())
+        val = 1;
+      else
+        return kFALSE;
+      break;
+    case 35:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
       val = (*this)[idx].GetPed();
       break;
-    case 9:
+    case 36:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = 1.;
+      //      val = (*this)[idx].GetPedError();
+      break;
+    case 37:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
       val = (*this)[idx].GetPedRms();
       break;
-    case 10:
-      val = (*this)[idx].GetRSigmaCharge();
-      break;
-    case 11:
-      val = (*this)[idx].GetPheFFactorMethod();
-      break;
-    case 12:
-      val = (*this)[idx].GetPheFFactorMethodError();
-      break;
-    case 13:
-      val = (*this)[idx].GetMeanConversionFFactorMethod();
-      break;
-    case 14:
-      val = (*this)[idx].GetErrorConversionFFactorMethod();
-      break;
-    case 15:
-      if (idx < 397)
-	val = (double)fMeanPhotInsidePlexiglass;
-      else
-	val = (double)fMeanPhotInsidePlexiglass*gkCalibrationOutervsInnerPixelArea;
-      break;
-    case 16:
-      if (idx < 397)
-        val = (*this)[idx].GetMeanConversionBlindPixelMethod();
-      else 
-        val = (*this)[idx].GetMeanConversionBlindPixelMethod()*gkCalibrationOutervsInnerPixelArea;
-      break;
-    case 17:
-      val = (*this)[idx].GetRSigmaCharge() / (*this)[idx].GetCharge();
-      break;
-    case 18:
-      if (!(*this)[idx].IsTimeFitValid())
+    case 38:
+      if ((*this)[idx].IsExcluded())
+        return kFALSE;
+      val = 1.;
+      //      val = (*this)[idx].GetPedRmsError();
+      break;
+    case 39:
+      if ((*this)[idx].IsExcluded())
         return kFALSE;
       val = (*this)[idx].GetAbsTimeMean();
       break;
-    case 19:
-      if (!(*this)[idx].IsTimeFitValid())
+    case 40:
+      if ((*this)[idx].IsExcluded())
         return kFALSE;
       val = (*this)[idx].GetAbsTimeMeanErr();
       break;
-    case 20:
-      if (!(*this)[idx].IsTimeFitValid())
+    case 41:
+      if ((*this)[idx].IsExcluded())
         return kFALSE;
       val = (*this)[idx].GetAbsTimeRms();
       break;
-    case 21:
-      if (!(*this)[idx].IsTimeFitValid())
+    case 42:
+      if ((*this)[idx].IsExcluded())
         return kFALSE;
       val = (*this)[idx].GetAbsTimeMeanErr()/TMath::Sqrt(2.);
