Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 4389)
+++ trunk/MagicSoft/Mars/Changelog	(revision 4390)
@@ -26,4 +26,11 @@
     - hard coded the reference lines for the DataCheck Display. Should be faster and 
       easier to read than the TArrayF's. 
+
+  * mcalib/MCalibrationChargeCalc.[h,cc]
+    - removed obsolete pointer to MEvtTime
+    - fixed bug in calculation of RMS for FFactor of inner pixels in case that the 
+      fit does not converge. 
+    - introduced blind pixel and PIN Diode result flags for later output or 
+      storage in DB.
 
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 4389)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 4390)
@@ -236,5 +236,5 @@
 // Default constructor. 
 //
-// Sets all pointers to NULL
+// Sets the pointer to fQECam and fGeom to NULL
 // 
 // Calls AddToBranchList for: 
@@ -255,11 +255,11 @@
 // - fOutputPath        to "."
 // - fOutputFile        to "ChargeCalibStat.txt"
-// 
+// - flag debug         to kFALSE
+//
 // Calls:
 // - Clear()
 //
 MCalibrationChargeCalc::MCalibrationChargeCalc(const char *name, const char *title)
-    : fBadPixels(NULL), fCam(NULL), fBlindPixel(NULL), fPINDiode(NULL), 
-      fQECam(NULL), fGeom(NULL), fPedestals(NULL), fEvtTime(NULL)
+    : fQECam(NULL), fGeom(NULL)
 {
         
@@ -279,8 +279,7 @@
   SetLambdaErrLimit    ();
   SetPheErrLimit       ();
-  SetPulserColor       ( MCalibrationCam::kNONE );
   SetOutputPath        ();
   SetOutputFile        ();
-  SetDebug             ( kFALSE );
+  SetDebug       ( kFALSE );
 
   Clear();
@@ -293,4 +292,8 @@
 // - all variables to 0., 
 // - all flags to kFALSE
+// - all pointers to NULL
+// - the pulser colour to kNONE
+// - fBlindPixelFlags to 0
+// - fPINDiodeFlags   to 0
 //
 void MCalibrationChargeCalc::Clear(const Option_t *o)
@@ -302,5 +305,16 @@
     fSqrtLoGainSamples         = 0.;
     fNumInnerFFactorMethodUsed = 0;
-    SkipHiLoGainCalibration( kFALSE );    
+
+    fBadPixels  = NULL;
+    fCam        = NULL;
+    fBlindPixel = NULL;
+    fPINDiode   = NULL;
+    fPedestals  = NULL;
+
+    SetPulserColor ( MCalibrationCam::kNONE );
+    
+    fBlindPixelFlags.Set(0);
+    fPINDiodeFlags  .Set(0);
+    fResultFlags    .Set(0);
 }
 
@@ -316,9 +330,4 @@
 //  - MBadPixelsCam
 //
-// The following output containers are only searched,  but not created. If they 
-// cannot be found, the corresponding calibration part is only skipped.
-//
-//  - MTime
-//
 Int_t MCalibrationChargeCalc::PreProcess(MParList *pList)
 {
@@ -352,6 +361,4 @@
 
   
-  fEvtTime = (MTime*)pList->FindObject("MTime");
-
   //
   // Check the pulser colour --> FIXME: this solution is only valid until the arrival of the DM's
@@ -953,5 +960,4 @@
       
       const Float_t nphe  = pix.GetPheFFactorMethod();
-      const Float_t nvar  = pix.GetPheFFactorMethod()*pix.GetPheFFactorMethod();
       const Int_t   aidx  = (*fGeom)[i].GetAidx();
 
@@ -960,5 +966,5 @@
 
       areaphes    [aidx] += nphe;
-      areavars    [aidx] += nvar;
+      areavars    [aidx] += nphe*nphe;
       numareavalid[aidx] ++;
     } 
@@ -973,10 +979,8 @@
         }
 
+      areavars[i] = (areavars[i] - areaphes[i]*areaphes[i]/numareavalid[i]) / (numareavalid[i]-1.);
       areaphes[i] = areaphes[i] / numareavalid[i];
-      areavars[i] = (areavars[i] - areaphes[i]*areaphes[i]/numareavalid[i]) / (numareavalid[i]-1.);
-
-      if (areavars[i] > 0.)
-        areavars[i] = TMath::Sqrt(areavars[i]);
-      else
+
+      if (areavars[i] < 0.)
         {
           *fLog << warn << GetDescriptor() << ": No pixels with valid variance of photo-electrons found "
@@ -1384,5 +1388,5 @@
 
       avffactorphotons[aidx] += ffactor;
-      avffactorphotvar[aidx] += pix.GetMeanFFactorFADC2PhotVar();
+      avffactorphotvar[aidx] += ffactor*ffactor;
       numffactor[aidx]++;
     }
@@ -1390,6 +1394,21 @@
   for (UInt_t i=0; i<nareas; i++)
     {
-      avffactorphotons[i] /= numffactor[i];
-      avffactorphotvar[i] /= numffactor[i];
+
+      if (numffactor[i] == 0)
+        {
+          *fLog << warn << GetDescriptor() << ": No pixels with valid total F-Factor found "
+                << "in area index: " << i << endl;
+          continue;
+        }
+
+      avffactorphotvar[i] = (avffactorphotvar[i] - avffactorphotons[i]*avffactorphotons[i]/numffactor[i]) / (numffactor[i]-1.);
+      avffactorphotons[i] = avffactorphotons[i] / numffactor[i];
+
+      if (avffactorphotvar[i] < 0.)
+        {
+          *fLog << warn << GetDescriptor() << ": No pixels with valid variance of total F-Factor found "
+                << "in area index: " << i << endl;
+          continue;
+        }
 
       lowlim  [i] = 1.1;   // Lowest known F-Factor of a PMT
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 4389)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 4390)
@@ -23,4 +23,8 @@
 #endif
 
+#ifndef ROOT_TArrayC
+#include "TArrayC.h"
+#endif
+
 class MRawEvtData;
 class MRawRunHeader;
@@ -43,11 +47,11 @@
 private:
 
-  static const Float_t fgChargeLimit;            //! Default for fChargeLimit            (now set to: 2.5)
-  static const Float_t fgChargeErrLimit;         //! Default for fChargeErrLimit         (now set to: 0.)
-  static const Float_t fgChargeRelErrLimit;      //! Default for fChargeRelErrLimit      (now set to: 1.)
-  static const Float_t fgLambdaCheckLimit;       //! Default for fLambdaCheckLimit       (now set to: 0.2)
-  static const Float_t fgLambdaErrLimit;         //! Default for fLabmdaErrLimit         (now set to: 0.2)
-  static const Float_t fgPheErrLimit;            //! Default for fPheErrLimit            (now set to: 4.)
-  static const Float_t fgFFactorErrLimit;        //! Default for fFFactorErrLimit        (now set to: 3.)
+  static const Float_t fgChargeLimit;          //! Default for fChargeLimit            (now set to: 2.5)
+  static const Float_t fgChargeErrLimit;       //! Default for fChargeErrLimit         (now set to: 0.)
+  static const Float_t fgChargeRelErrLimit;    //! Default for fChargeRelErrLimit      (now set to: 1.)
+  static const Float_t fgLambdaCheckLimit;     //! Default for fLambdaCheckLimit       (now set to: 0.2)
+  static const Float_t fgLambdaErrLimit;       //! Default for fLabmdaErrLimit         (now set to: 0.5)
+  static const Float_t fgPheErrLimit;          //! Default for fPheErrLimit            (now set to: 4.)
+  static const Float_t fgFFactorErrLimit;      //! Default for fFFactorErrLimit        (now set to: 4.)
  
   // Variables
@@ -55,5 +59,4 @@
   Float_t fChargeErrLimit;                     // Limit acceptance charge error (in abs. numbers)
   Float_t fChargeRelErrLimit;                  // Limit acceptance rel. error mean (in abs. numbers)
-  Byte_t  fFlags;                              // Bit-field for the flags
   Float_t fLambdaCheckLimit;                   // Limit rel. diff. lambda and lambdacheck in Blind Pixel
   Float_t fLambdaErrLimit;                     // Limit acceptance lambda error in Blind Pixel
@@ -66,4 +69,9 @@
   MCalibrationCam::PulserColor_t fPulserColor; // Calibration LEDs colour 
   Int_t   fNumInnerFFactorMethodUsed;          // Number of inner pixels used for F-Factor Method calibration
+
+  Byte_t  fFlags;                              // Bit-field for the general flags
+  TArrayC fResultFlags;                        // Bit-fields for the fitting results   (one field per area index)
+  TArrayC fBlindPixelFlags;                    // Bit-fields for the blind pixel flags (one field per blind pixel)
+  TArrayC fPINDiodeFlags;                      // Bit-fields for the PIN Diode flags   (one field per PIN Diode  )
   
   TString fOutputPath;                         // Path to the output file
@@ -78,23 +86,33 @@
   MGeomCam                   *fGeom;           //! Camera geometry
   MPedestalCam               *fPedestals;      //! Pedestals all pixels (calculated previously from ped.file)
-  MTime                      *fEvtTime;        //! Time of the event
 
   // enums
-  enum  { kHiLoGainCalibration, kDebug };
+  enum  { kDebug, kPheFitOK, kFFactorFitOK, kBlindPixelFitOK, kBlindPixelPedFitOK, kPINDiodeFitOK };
 
   // functions
   const char* GetOutputFile();
-  void   FinalizePedestals      ( const MPedestalPix &ped, MCalibrationChargePix &cal, const Int_t aidx );
-  Bool_t FinalizeCharges        ( MCalibrationChargePix &cal, MBadPixelsPix &bad      );
-  Bool_t FinalizePINDiode       ();
-  Bool_t FinalizeBlindPixel     ();
-  Bool_t FinalizeFFactorMethod  ();
-  void   FinalizeBadPixels      ();
-  void   FinalizeFFactorQECam   ();  
-  void   FinalizeBlindPixelQECam();
-  void   FinalizePINDiodeQECam  ();
+  void   FinalizePedestals       ( const MPedestalPix    &ped, MCalibrationChargePix &cal, const Int_t aidx );
+  Bool_t FinalizeCharges         ( MCalibrationChargePix &cal, MBadPixelsPix &bad                           );
+  Bool_t FinalizePINDiode        ();
+  Bool_t FinalizeBlindPixel      ();
+  Bool_t FinalizeFFactorMethod   ();
+  void   FinalizeBadPixels       ();
+  void   FinalizeFFactorQECam    ();  
+  void   FinalizeBlindPixelQECam ();
+  void   FinalizePINDiodeQECam   ();
   void   FinalizeUnsuitablePixels();
 
   void   PrintUncalibrated( MBadPixelsPix::UncalibratedType_t typ, const char *text) const;
+
+  void   SetPheFitOK          ( const Int_t aidx, const Bool_t b=kTRUE ) { b ? SETBIT(fResultFlags[aidx], kPheFitOK) 
+							                     : CLRBIT(fResultFlags[aidx], kPheFitOK);      }
+  void   SetFFactorFitOK      ( const Int_t aidx, const Bool_t b=kTRUE ) { b ? SETBIT(fResultFlags[aidx], kFFactorFitOK) 
+							                     : CLRBIT(fResultFlags[aidx], kFFactorFitOK);  }
+  void   SetBlindPixelFitOK   ( const Int_t  idx, const Bool_t b=kTRUE ) { b ? SETBIT(fBlindPixelFlags[idx], kBlindPixelFitOK) 
+							                     : CLRBIT(fBlindPixelFlags[idx], kBlindPixelFitOK); }
+  void   SetBlindPixelPedFitOK( const Int_t  idx, const Bool_t b=kTRUE ) { b ? SETBIT(fBlindPixelFlags[idx], kBlindPixelPedFitOK) 
+								             : CLRBIT(fBlindPixelFlags[idx], kBlindPixelPedFitOK); }
+  void   SetPINDiodeFitOK     ( const Int_t  idx, const Bool_t b=kTRUE ) { b ? SETBIT(fPINDiodeFlags[idx], kPINDiodeFitOK) 
+							                     : CLRBIT(fPINDiodeFlags[idx], kPINDiodeFitOK); }
 
   Int_t  PreProcess (MParList *pList);
@@ -111,19 +129,17 @@
   Bool_t IsDebug() const   {  return TESTBIT(fFlags,kDebug); }
   
-  void SetChargeLimit       ( const Float_t f=fgChargeLimit            ) { fChargeLimit       = f;   }
-  void SetChargeErrLimit    ( const Float_t f=fgChargeErrLimit         ) { fChargeErrLimit    = f;   }
-  void SetChargeRelErrLimit ( const Float_t f=fgChargeRelErrLimit      ) { fChargeRelErrLimit = f;   }
-  void SetFFactorErrLimit   ( const Float_t f=fgFFactorErrLimit        ) { fFFactorErrLimit   = f;   }
-  void SetLambdaErrLimit    ( const Float_t f=fgLambdaErrLimit         ) { fLambdaErrLimit    = f;   }
-  void SetLambdaCheckLimit  ( const Float_t f=fgLambdaCheckLimit       ) { fLambdaCheckLimit  = f;   }
+  void SetChargeLimit       ( const Float_t f=fgChargeLimit            ) { fChargeLimit       = f;     }
+  void SetChargeErrLimit    ( const Float_t f=fgChargeErrLimit         ) { fChargeErrLimit    = f;     }
+  void SetChargeRelErrLimit ( const Float_t f=fgChargeRelErrLimit      ) { fChargeRelErrLimit = f;     }
+  void SetDebug             ( const Bool_t  b=kTRUE                    ) { b ? SETBIT(fFlags, kDebug) 
+									     : CLRBIT(fFlags, kDebug); }
+  void SetFFactorErrLimit   ( const Float_t f=fgFFactorErrLimit        ) { fFFactorErrLimit   = f;     }
+  void SetLambdaErrLimit    ( const Float_t f=fgLambdaErrLimit         ) { fLambdaErrLimit    = f;     }
+  void SetLambdaCheckLimit  ( const Float_t f=fgLambdaCheckLimit       ) { fLambdaCheckLimit  = f;     }
   void SetOutputPath        ( TString path="."                   );
   void SetOutputFile        ( TString file="ChargeCalibStat.txt" );
-  void SetPheErrLimit       ( const Float_t f=fgPheErrLimit            ) { fPheErrLimit       = f;   }  
-  void SetPulserColor       ( const MCalibrationCam::PulserColor_t col ) { fPulserColor       = col; }
+  void SetPheErrLimit       ( const Float_t f=fgPheErrLimit            ) { fPheErrLimit       = f;     }  
+  void SetPulserColor       ( const MCalibrationCam::PulserColor_t col ) { fPulserColor       = col;   }
 
-  void SkipHiLoGainCalibration ( const Bool_t b=kTRUE )
-      { b ? CLRBIT(fFlags, kHiLoGainCalibration) : SETBIT(fFlags, kHiLoGainCalibration); }
-  void SetDebug              ( const Bool_t b=kTRUE )
-      { b ? SETBIT(fFlags, kDebug              ) : CLRBIT(fFlags, kDebug              ); }
 
   ClassDef(MCalibrationChargeCalc, 1)   // Task calculating Calibration Containers and Quantum Efficiencies
