Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc	(revision 3935)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc	(revision 3936)
@@ -88,5 +88,7 @@
 //
 MCalibrationCam::MCalibrationCam(const char *name, const char *title)
-    : fNumHiGainFADCSlices(0.), fNumLoGainFADCSlices(0.), fPulserColor(kNONE), 
+    : fNumUnsuitable(),
+      fNumUnreliable(),
+      fNumHiGainFADCSlices(0.), fNumLoGainFADCSlices(0.), fPulserColor(kNONE), 
       fPixels(NULL), fAverageAreas(NULL), fAverageSectors(NULL)
 {
@@ -189,4 +191,7 @@
   fAverageAreas->ExpandCreate(i);
   fAverageBadAreas->ExpandCreate(i);
+  
+  fNumUnsuitable.Set(i);
+  fNumUnreliable.Set(i);
 }
 
@@ -219,7 +224,70 @@
 // --------------------------------------------------------------------------
 //
+// Returns the number of un-suitable pixels per area index and -1 if 
+// the area index exceeds the initialized array.
+//
+const Int_t MCalibrationCam::GetNumUnsuitable( Int_t aidx ) const
+{
+  if (aidx < 0)
+    return -1;
+
+  return aidx > fNumUnsuitable.GetSize() ? -1 : fNumUnsuitable[aidx]; 
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the number of un-reliable pixels per area index and -1 if 
+// the area index exceeds the initialized array.
+//
+const Int_t MCalibrationCam::GetNumUnreliable( Int_t aidx ) const
+{
+  if (aidx < 0)
+    return -1;
+
+  return aidx > fNumUnreliable.GetSize() ? -1 : fNumUnreliable[aidx]; 
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Returns the current size of the TClonesArray fAverageAreas
+// independently if the MCalibrationPix is filled with values or not.
+//
+const Int_t MCalibrationCam::GetAverageAreas() const
+{
+  return fAverageAreas->GetEntriesFast();
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the current size of the TClonesArray fAverageSectors
+// independently if the MCalibrationPix is filled with values or not.
+//
+const Int_t MCalibrationCam::GetAverageSectors() const
+{
+  return fAverageSectors->GetEntriesFast();
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Get i-th pixel (pixel number)
+//
+MCalibrationPix &MCalibrationCam::operator[](UInt_t i)
+{
+  return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th pixel (pixel number)
+//
+const MCalibrationPix &MCalibrationCam::operator[](UInt_t i) const
+{
+  return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
+}
+
 // Returns the current size of the TClonesArray fPixels 
 // independently if the MCalibrationPix is filled with values or not.
-//
 const Int_t MCalibrationCam::GetSize() const
 {
@@ -229,43 +297,4 @@
 // --------------------------------------------------------------------------
 //
-// Returns the current size of the TClonesArray fAverageAreas
-// independently if the MCalibrationPix is filled with values or not.
-//
-const Int_t MCalibrationCam::GetAverageAreas() const
-{
-  return fAverageAreas->GetEntriesFast();
-}
-
-// --------------------------------------------------------------------------
-//
-// Returns the current size of the TClonesArray fAverageSectors
-// independently if the MCalibrationPix is filled with values or not.
-//
-const Int_t MCalibrationCam::GetAverageSectors() const
-{
-  return fAverageSectors->GetEntriesFast();
-}
-
-
-// --------------------------------------------------------------------------
-//
-// Get i-th pixel (pixel number)
-//
-MCalibrationPix &MCalibrationCam::operator[](UInt_t i)
-{
-  return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th pixel (pixel number)
-//
-const MCalibrationPix &MCalibrationCam::operator[](UInt_t i) const
-{
-  return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
 // Get i-th average pixel (area number)
 //
@@ -360,2 +389,18 @@
 }
 
+void MCalibrationCam::SetNumUnsuitable( const UInt_t i, const Int_t aidx)
+{
+  if (aidx < 0)
+    return;
+
+  if (aidx < fNumUnsuitable.GetSize())
+    fNumUnsuitable[aidx] = i;  
+}
+
+void MCalibrationCam::SetNumUnreliable( const UInt_t i, const Int_t aidx)
+{
+  if (aidx < 0)
+    return;
+  if (aidx < fNumUnreliable.GetSize())
+    fNumUnreliable[aidx] = i; 
+}
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.h	(revision 3935)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.h	(revision 3936)
@@ -8,4 +8,7 @@
 #include "MCamEvent.h"
 #endif
+#ifndef ROOT_TArrayI
+#include "TArrayI.h"
+#endif
 
 class TClonesArray;
@@ -15,5 +18,4 @@
 class MBadPixelsCam;
 class MGeomCam;
-
 class MCalibrationCam : public MParContainer, public MCamEvent
 {
@@ -24,4 +26,7 @@
   
 protected:
+
+  TArrayI fNumUnsuitable;
+  TArrayI fNumUnreliable;
 
   Float_t fNumHiGainFADCSlices;      // Number High-Gain FADC slices used by extractor      
@@ -57,4 +62,7 @@
   const Float_t          GetNumHiGainFADCSlices()         const { return fNumHiGainFADCSlices; }
   const Float_t          GetNumLoGainFADCSlices()         const { return fNumLoGainFADCSlices; }  
+  const Int_t            GetNumUnsuitable   ( Int_t aidx) const;
+  const Int_t            GetNumUnreliable   ( Int_t aidx) const;
+
   virtual Bool_t         GetPixelContent     ( Double_t &val, Int_t idx, 
                                                const MGeomCam &cam, Int_t type=0) const;
@@ -74,4 +82,6 @@
   void  SetNumHiGainFADCSlices ( const Float_t f              )  { fNumHiGainFADCSlices = f; }
   void  SetNumLoGainFADCSlices ( const Float_t f              )  { fNumLoGainFADCSlices = f; }  
+  void  SetNumUnsuitable     ( const UInt_t i, const Int_t aidx);  
+  void  SetNumUnreliable      ( const UInt_t i, const Int_t aidx); 
   void  SetPulserColor         ( const PulserColor_t col=kCT1 )  { fPulserColor = col; }
   
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 3935)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 3936)
@@ -1444,5 +1444,5 @@
   
   *fLog << inf << endl;
-  *fLog << GetDescriptor() << ": Calibration statistics:" << endl;
+  *fLog << GetDescriptor() << ": Charge Calibration status:" << endl;
   *fLog << dec << setfill(' ');
 
@@ -1479,5 +1479,5 @@
 
   for (Int_t aidx=0; aidx<nareas; aidx++)
-    fCam->SetNumUncalibrated(counts[aidx], aidx);
+    fCam->SetNumUnsuitable(counts[aidx], aidx);
 
   if (fGeom->InheritsFrom("MGeomCamMagic"))
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 3935)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 3936)
@@ -155,11 +155,7 @@
 // Calls:
 // - MCalibrationCam::Init()
-// - fNumUncalibrated.Set(NumAreas);
-// - fNumUnreliable.Set(NumAreas);
 //
 void MCalibrationChargeCam::Init(const MGeomCam &geom)
 {
-  fNumUncalibrated.Set(geom.GetNumAreas());
-  fNumUnreliable  .Set(geom.GetNumAreas());
   MCalibrationCam::Init(geom);
 }
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h	(revision 3935)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h	(revision 3936)
@@ -14,7 +14,4 @@
 private:
   
-  TArrayI fNumUncalibrated;
-  TArrayI fNumUnreliable;
-
   Byte_t  fFlags;                    // Bit-field to hold the flags
 
@@ -32,6 +29,4 @@
   // Getters
   Bool_t GetConversionFactorFFactor( Int_t ipx, Float_t &mean, Float_t &err, Float_t &ffactor );
-  Int_t  GetNumUncalibrated        ( const Int_t aidx) const   { return fNumUncalibrated[aidx]; }
-  Int_t  GetNumUnreliable          ( const Int_t aidx) const   { return fNumUnreliable  [aidx]; }
   Bool_t GetPixelContent           ( Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
   Bool_t IsFFactorMethodValid()      const;
@@ -45,6 +40,4 @@
   // Setters   
   void   SetFFactorMethodValid ( const Bool_t b=kTRUE );
-  void   SetNumUncalibrated    ( const Int_t i, const Int_t aidx)   { fNumUncalibrated[aidx] = i; }
-  void   SetNumUnreliable      ( const Int_t i, const Int_t aidx)   { fNumUnreliable  [aidx] = i; }
 
   ClassDef(MCalibrationChargeCam, 1) // Container Charge Calibration Results Camera
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc	(revision 3935)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc	(revision 3936)
@@ -72,5 +72,5 @@
 using namespace std;
 
-const Float_t MCalibrationRelTimeCalc::fgRelTimeRelErrLimit      = 3.;
+const Float_t MCalibrationRelTimeCalc::fgRelTimeRelErrLimit      = 6.;
 // --------------------------------------------------------------------------
 //
@@ -219,49 +219,6 @@
   // First loop over pixels, call FinalizePedestals and FinalizeRelTimes
   //
-  Int_t   nvalid      = 0;
-
-  for (Int_t pixid=0; pixid<fCam->GetSize(); pixid++)
-    {
-
-      MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*fCam)[pixid];
-      //
-      // Check if the pixel has been excluded from the fits
-      //
-      if (pix.IsExcluded())
-        continue;
-
-      MBadPixelsPix &bad = (*fBadPixels)[pixid];
-
-      if (FinalizeRelTimes(pix,bad))
-        nvalid++;
-    }
-  
-  //
-  // The Michele check ...
-  //
-  if (nvalid == 0)
-  {
-      *fLog << err << GetDescriptor() << ": All pixels have non-valid calibration. " 
-	    << "Did you forget to fill the histograms "
-            << "(filling MHCalibrationRelTimeCam from MArrivalTimeCam using MFillH) ? " << endl;
-      *fLog << err << GetDescriptor() << ": Or, maybe, you have used a pedestal run " 
-            << "instead of a calibration run " << endl;
-    return kFALSE;
-  }
-
-  for (UInt_t aidx=0; aidx<fGeom->GetNumAreas(); aidx++)
-    {
-
-      MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)fCam->GetAverageArea(aidx);
-      FinalizeRelTimes(pix, fCam->GetAverageBadArea(aidx));
-    }
-  
-  for (UInt_t sector=0; sector<fGeom->GetNumSectors(); sector++)
-    {
-
-      MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)fCam->GetAverageSector(sector);
-      FinalizeRelTimes(pix, fCam->GetAverageBadSector(sector));
-    }
-  
+  FinalizeRelTimes();
+
   //
   // Finalize Bad Pixels
@@ -281,5 +238,5 @@
 
   PrintUncalibrated(MBadPixelsPix::kDeviatingTimeResolution,    
-                    Form("%s%2.1f%s","Time resolution less than ",fRelTimeRelErrLimit," sigma from Mean:           "));
+                    Form("%s%2.1f%s","Time resolution less than ",fRelTimeRelErrLimit," sigma from Mean:   "));
   PrintUncalibrated(MBadPixelsPix::kRelTimeOscillating,   
                     "Pixels with changing Rel. Times   over time:      ");
@@ -301,5 +258,5 @@
 //              MBadPixelsPix::kDeviatingTimeResolution if excluded.
 // 
-Bool_t MCalibrationRelTimeCalc::FinalizeRelTimes(MCalibrationRelTimePix &cal, MBadPixelsPix &bad)
+void MCalibrationRelTimeCalc::FinalizeRelTimes()
 {
 
@@ -309,12 +266,12 @@
   Float_t lowlim      [nareas];
   Float_t upplim      [nareas];
-  Float_t areaerrs    [nareas];
-  Float_t areamean    [nareas];
+  Float_t areasum     [nareas];
+  Float_t areasum2    [nareas];
   Int_t   numareavalid[nareas];
 
   memset(lowlim        ,0, nareas   * sizeof(Float_t));
   memset(upplim        ,0, nareas   * sizeof(Float_t));
-  memset(areaerrs      ,0, nareas   * sizeof(Float_t));
-  memset(areamean      ,0, nareas   * sizeof(Float_t));
+  memset(areasum       ,0, nareas   * sizeof(Float_t));
+  memset(areasum2      ,0, nareas   * sizeof(Float_t));
   memset(numareavalid  ,0, nareas   * sizeof(Int_t  ));
 
@@ -326,8 +283,8 @@
     {
       
-      MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*fCam)  [i];
-      MBadPixelsPix         &bad = (*fBadPixels)[i];
-      
-      if (!pix.IsExcluded())
+      MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*fCam)[i];
+      MBadPixelsPix          &bad = (*fBadPixels)[i];
+      
+      if (pix.IsExcluded())
         continue;
 
@@ -338,62 +295,57 @@
         continue;
       
+      const Float_t res   = pix.GetTimePrecision();
+      const Int_t   aidx  = (*fGeom)[i].GetAidx();
+
+      areasum     [aidx] += res;
+      areasum2    [aidx] += res*res;
+      numareavalid[aidx] ++;
+    }
+
+
+  for (UInt_t aidx=0; aidx<nareas; aidx++)
+    {
+      if (numareavalid[aidx] == 0)
+        {
+          *fLog << warn << GetDescriptor() << ": No pixels with valid time resolution found "
+                << "in area index: " << aidx << endl;
+          continue;
+        }
+ 
+      // Calculate the rms out of sum2:
+      areasum2[aidx]  = (areasum2[aidx] - areasum[aidx]*areasum[aidx]/numareavalid[aidx]);
+      areasum [aidx] /= numareavalid[aidx];
+      areasum2[aidx] /= (numareavalid[aidx]-1.);
+      lowlim  [aidx]  = areamean[aidx] - fRelTimeRelErrLimit*areasum2[aidx];
+      upplim  [aidx]  = areamean[aidx] + fRelTimeRelErrLimit*areasum2[aidx];
+    }
+  
+
+
+  for (UInt_t i=0; i<npixels; i++)
+    {
+      
+      MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*fCam)[i];
+      MBadPixelsPix          &bad = (*fBadPixels)[i];
+      
+      if (pix.IsExcluded())
+        continue;
+      
+      if (bad.IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
+        continue;
+      
       const Float_t res  = pix.GetTimePrecision();
-      const Float_t perr  = pix.GetTimePrecisionErr();
-      const Int_t   aidx  = (*fGeom)[i].GetAidx();
-
-      areamean    [aidx] += res;
-      areaerrs    [aidx] += perr;
-      numareavalid[aidx] ++;
-    } 
-
-
-
-  for (UInt_t i=0; i<nareas; i++)
-    {
-      if (numareavalid[i] == 0)
-        {
-          *fLog << warn << GetDescriptor() << ": No pixels with valid number of photo-electrons found "
-                << "in area index: " << i << endl;
-          continue;
-        }
- 
-      areamean[i] = areamean[i] / numareavalid[i];
-      areaerrs[i] = areaerrs[i] / numareavalid[i];
-      lowlim  [i] = areamean[i] - fRelTimeRelErrLimit*areaerrs[i];
-      upplim  [i] = areamean[i] + fRelTimeRelErrLimit*areaerrs[i];
-    }
-
-
-
-  //
-  // Second loop: Exclude pixels deviating by more than fRelTimeErrLimit sigma. 
-  // 
-  for (UInt_t i=0; i<npixels; i++)
-    {
-      
-      MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*fCam)[i];
-
-      if (!pix.IsExcluded())
-        continue;
-
-      const Float_t res  = pix.GetTimePrecision();
-
-      MBadPixelsPix         &bad = (*fBadPixels)[i];
       const Int_t   aidx   = (*fGeom)[i].GetAidx();
-
+      
       if ( res < lowlim[aidx] || res > upplim[aidx] )
         {
           *fLog << warn << GetDescriptor() << ": Deviating time resolution: " 
-                << Form("%4.2f",res) << " out of accepted limits: [" 
+            << Form("%4.2f",res) << " out of accepted limits: [" 
                 << Form("%4.2f%s%4.2f",lowlim[aidx],",",upplim[aidx]) << "] in pixel " << i << endl;
           bad.SetUncalibrated( MBadPixelsPix::kDeviatingTimeResolution);
-          bad.SetUnsuitable  ( MBadPixelsPix::kUnsuitableRun    );
           pix.SetExcluded();
         }
     }
-  
-  return kTRUE;
-}
-
+}
 
 
@@ -441,5 +393,5 @@
   
   *fLog << inf << endl;
-  *fLog << GetDescriptor() << ": Calibration statistics:" << endl;
+  *fLog << GetDescriptor() << ": Rel. Times Calibration status:" << endl;
   *fLog << dec << setfill(' ');
 
@@ -460,5 +412,5 @@
 
   for (Int_t aidx=0; aidx<nareas; aidx++)
-    fCam->SetNumUncalibrated(counts[aidx], aidx);
+    fCam->SetNumUnsuitable(counts[aidx], aidx);
 
   if (fGeom->InheritsFrom("MGeomCamMagic"))
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.h	(revision 3935)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.h	(revision 3936)
@@ -32,10 +32,10 @@
 private:
 
-  static const Float_t fgRelTimeRelErrLimit;      //! Default for fRelTimeRelErrLimit      (now set to: 1.)
+  static const Float_t fgRelTimeRelErrLimit;      //! Default for fRelTimeRelErrLimit      (now set to: 6.)
  
   // Variables
   Float_t fRelTimeRelErrLimit;                  // Limit acceptance rel. error mean (in abs. numbers)
   Byte_t  fFlags;                              // Bit-field for the flags
-
+  
   // Pointers
   MBadPixelsCam              *fBadPixels;      //  Bad Pixels 
@@ -47,5 +47,6 @@
 
   // functions
-  Bool_t FinalizeRelTimes        ( MCalibrationRelTimePix &cal, MBadPixelsPix &bad      );
+  void   FinalizeAverageResolution();
+  void   FinalizeRelTimes     ();
   void   FinalizeBadPixels      ();
   void   FinalizeUnsuitablePixels();
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCam.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCam.h	(revision 3935)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCam.h	(revision 3936)
@@ -13,16 +13,8 @@
 class MCalibrationRelTimeCam : public MCalibrationCam
 {
-private:
-  
-  TArrayI fNumUncalibrated;
-  TArrayI fNumUnreliable;
-
 public:
 
   MCalibrationRelTimeCam(const char *name=NULL, const char *title=NULL);
   ~MCalibrationRelTimeCam() {}
-
-  Int_t  GetNumUncalibrated        ( const Int_t aidx) const   { return fNumUncalibrated[aidx]; }
-  Int_t  GetNumUnreliable          ( const Int_t aidx) const   { return fNumUnreliable  [aidx]; }
 
   // Prints
@@ -33,7 +25,4 @@
   void DrawPixelContent(Int_t num) const;    
 
-  void   SetNumUncalibrated    ( const Int_t i, const Int_t aidx)   { fNumUncalibrated[aidx] = i; }
-  void   SetNumUnreliable      ( const Int_t i, const Int_t aidx)   { fNumUnreliable  [aidx] = i; }
-  
   ClassDef(MCalibrationRelTimeCam, 1)	// Container Rel. Arrival Time Calibration Results Camera
 };
Index: /trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 3935)
+++ /trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 3936)
@@ -1608,5 +1608,5 @@
                   for (int j=0; j<2; j++)
                     {
-                      half[j]->SetLineColor(kRed+i+j);
+                      half[j]->SetLineColor(kRed+i+2*j);
                       half[j]->SetDirectory(0);
                       half[j]->SetBit(kCanDelete);
