Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 3006)
+++ trunk/MagicSoft/Mars/Changelog	(revision 3007)
@@ -9,4 +9,10 @@
   * manalysis/MPedCalcPedRun.cc
     - corrected formulae in Class descriptino
+
+  * mcalib/MCalibration.*
+  * mcalib/MHCalibration.*
+  * manalysis/MMcCalibrationUpdate.cc
+    - calculate relative times and absolute times. Fit only 
+      the relative ones. 
 
 
Index: trunk/MagicSoft/Mars/macros/calibration.C
===================================================================
--- trunk/MagicSoft/Mars/macros/calibration.C	(revision 3006)
+++ trunk/MagicSoft/Mars/macros/calibration.C	(revision 3007)
@@ -24,5 +24,5 @@
 
 const TString pedfile = "/mnt/Data/rootdata/CrabNebula/2004_01_27/20040126_12149_P_Cab-On_E.root";
-const TString calfile = "/mnt/Data/rootdata/CrabNebula/2004_01_27/20040126_1252*_C_Cab-On_E.root";
+const TString calfile = "/mnt/Data/rootdata/CrabNebula/2004_01_27/20040126_12525_C_Cab-On_E.root";
 
 //const TString pedfile = "/mnt/Data/rootdata/Miscellaneous/2003_12_19/20031218_03522_P_Park_E.root";
@@ -52,5 +52,11 @@
     MGeomApply     geomapl;
     MExtractSignal sigcalc;
+    //
+    // We saw that the signal jumps between slices, 
+    // thus set the extraction range as high as possible
+    // Sliding window will be implemented asap.
+    //		
     sigcalc.SetRange(1,14,1,14);
+
     MPedCalcPedRun pedcalc;
     pedcalc.SetUseHists();
@@ -209,5 +215,5 @@
     // faster results
     // 
-    timecalc.SetStepSize(0.5);
+    //    timecalc.SetStepSize(0.02);
 
     //
@@ -246,5 +252,5 @@
     //
     MCalibrationBlindPix *bp = calcam.GetBlindPixel();
-    //    bp->ChangeFitFunc(MHCalibrationBlindPixel::kEPolya);
+//    bp->ChangeFitFunc(MHCalibrationBlindPixel::kEPolya);
     //    bp->ChangeFitFunc(MHCalibrationBlindPixel::kEPoisson4);
 
@@ -285,7 +291,7 @@
     MHCamera disp3   (geomcam, "MCalibrationPix;SigmaCharge", "Sigma of Fitted Charges");
     MHCamera disp5   (geomcam, "MCalibrationPix;ChargeProb", "Probability of Fit");
-    MHCamera disp6   (geomcam, "MCalibrationPix;Time", "Arrival Times");
-    MHCamera disp7   (geomcam, "MCalibrationPix;SigmaTime", "Sigma of Arrival Times");
-    MHCamera disp8   (geomcam, "MCalibrationPix;TimeChiSquare", "Chi Square of Time Fit");
+    MHCamera disp6   (geomcam, "MCalibrationPix;Time", "Rel. Arrival Times");
+    MHCamera disp7   (geomcam, "MCalibrationPix;SigmaTime", "Sigma of Rel. Arrival Times");
+    MHCamera disp8   (geomcam, "MCalibrationPix;TimeProb", "Probability of Time Fit");
     MHCamera disp9   (geomcam, "MCalibrationPix;Ped", "Pedestals");
     MHCamera disp10  (geomcam, "MCalibrationPix;PedRms", "Pedestal RMS");
@@ -333,7 +339,7 @@
     disp3.SetYTitle("\\sigma_{Charge} [FADC counts]");
     disp5.SetYTitle("P_{Charge} [1]");
-    disp6.SetYTitle("Arr. Time [Time Slice Nr.]");
-    disp7.SetYTitle("\\sigma_{Time} [Time Slices]");
-    disp8.SetYTitle("\\chi^{2}_{Time} [1]");
+    disp6.SetYTitle("Arr. Time [ns]");
+    disp7.SetYTitle("\\sigma_{Time} [ns]");
+    disp8.SetYTitle("P_{Time} [1]");
     disp9.SetYTitle("Ped [FADC Counts ]");
     disp10.SetYTitle("RMS_{Ped} [FADC Counts ]");
@@ -366,9 +372,9 @@
 
     // Times
-    TCanvas &c3 = d3->AddTab("Fitted Times");
+    TCanvas &c3 = d3->AddTab("Fitted Rel. Times");
     c3.Divide(3,3);
 
     CamDraw(c3,disp6,calcam,1,3,1);
-    CamDraw(c3,disp7,calcam,2,3,0);
+    CamDraw(c3,disp7,calcam,2,3,1);
     CamDraw(c3,disp8,calcam,3,3,0);
 
Index: trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.cc	(revision 3006)
+++ trunk/MagicSoft/Mars/manalysis/MMcCalibrationUpdate.cc	(revision 3007)
@@ -222,5 +222,6 @@
 
 	calpix.SetBlindPixelMethodValid();
-	calpix.SetFitValid();
+	calpix.SetChargeFitValid();
+	calpix.SetTimeFitValid();
 
 	calpix.SetConversionHiLo(fConversionHiLo);
Index: trunk/MagicSoft/Mars/mcalib/MCalibrate.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrate.cc	(revision 3006)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrate.cc	(revision 3007)
@@ -169,5 +169,5 @@
 	  const MCalibrationPix &pix = (*fCalibrations)[pixidx];       
 	  
-	  if (!pix.IsFitValid())
+	  if (!pix.IsChargeFitValid())
 	    continue;
 	  
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc	(revision 3006)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc	(revision 3007)
@@ -148,11 +148,11 @@
     CLRBIT(fFlags, kUsePinDiodeFit);
 
-    fEvents = 0;
-    fCosmics = 0;
-    fNumHiGainSamples = 0;
-    fNumLoGainSamples = 0;
-    fConversionHiLo = 0;
+    fEvents            = 0;
+    fCosmics           = 0;
+    fNumHiGainSamples  = 0;
+    fNumLoGainSamples  = 0;
+    fConversionHiLo    = 0;
     fNumExcludedPixels = 0;
-    
+
     fColor = kECT1;
 }
@@ -287,15 +287,14 @@
         MCalibrationPix &pix = (*fCalibrations)[i];
         pix.DefinePixId(i);
-        MHCalibrationPixel *hist = pix.GetHist();
-        
-        hist->SetTimeFitRangesHiGain(fSignals->GetFirstUsedSliceHiGain(),
-                                     fSignals->GetLastUsedSliceHiGain());
-        hist->SetTimeFitRangesLoGain(fSignals->GetFirstUsedSliceLoGain(),
-                                     fSignals->GetLastUsedSliceLoGain());
+
+        pix.SetAbsTimeBordersHiGain(fSignals->GetFirstUsedSliceHiGain(),
+                                    fSignals->GetLastUsedSliceHiGain());
+        pix.SetAbsTimeBordersLoGain(fSignals->GetFirstUsedSliceLoGain(),
+                                    fSignals->GetLastUsedSliceLoGain());
         
         if (!TESTBIT(fFlags,kUseQualityChecks))
           pix.SetExcludeQualityCheck();
 
-      }
+     }
     
     //
@@ -431,10 +430,16 @@
   fEvents++;
 
-  Int_t overflow = 0;
+  Int_t   overflow      = 0;
+  Float_t referencetime = 0.;
   
   //
   // Create a (second) loop to do fill the calibration histograms
-  // 
-  
+  // Search for: a signal in MExtractedSignalCam 
+  //             a time in MArrivalTime. 
+  // Fill histograms with:
+  //             charge
+  //             charge vs. event nr.
+  //             relative arrival time w.r.t. pixel 1
+  //
   while (pixel.Next())
     {
@@ -452,20 +457,37 @@
       const Float_t sumlo  = sig.GetExtractedSignalLoGain();
 
-      Float_t mtime = 0.;
+      Float_t abstime = 0.;
+      Float_t reltime = 0.;
 
       if (TESTBIT(fFlags,kUseTimes))
         {
-          //
-          // first, have a look in MArrivalTime, 
+
+          //
+          // Have a look in MArrivalTime, 
           // otherwise search the position of maximum bin 
           // in MRawEvtData
           //
           if (fArrivalTime)
-            mtime = (*fArrivalTime)[pixid];
+            {
+              abstime = (*fArrivalTime)[pixid];
+              reltime = abstime - (*fArrivalTime)[1];
+            }
+          
           else
-            if (sig.IsLoGainUsed())
-              mtime = (Double_t)pixel.GetIdxMaxLoGainSample();
-            else
-              mtime = (Double_t)pixel.GetIdxMaxHiGainSample();
+            {
+              if (pixid == 1)
+                referencetime = (Float_t)pixel.GetIdxMaxHiGainSample();
+
+              if (sig.IsLoGainUsed())
+                {
+                  abstime = (Float_t)pixel.GetIdxMaxLoGainSample();
+                  reltime = abstime - referencetime;
+                }
+              else
+                {
+                  abstime = (Float_t)pixel.GetIdxMaxHiGainSample();
+                  reltime = abstime - referencetime;
+                }
+            }
         }
       
@@ -481,7 +503,7 @@
           if (TESTBIT(fFlags,kUseTimes))
             {
-              if (!blindpixel.FillTime(mtime))
+              if (!blindpixel.FillTime(reltime))
                 *fLog << warn << 
-                  "Overflow or Underflow occurred filling Blind Pixel time = " << mtime << endl;
+                  "Overflow or Underflow occurred filling Blind Pixel time = " << reltime << endl;
             }
           
@@ -499,7 +521,10 @@
           if (TESTBIT(fFlags,kUseTimes))
             {
-              if (!pindiode.FillTime(mtime))
+              if (!pindiode.FillAbsTime(abstime))
                 *fLog << warn << 
-                  "Overflow or Underflow occurred filling PINDiode: time = " << mtime << endl;
+                  "Overflow or Underflow occurred filling PINDiode abs. time = " << abstime << endl;
+              if (!pindiode.FillRelTime(reltime))
+                *fLog << warn << 
+                  "Overflow or Underflow occurred filling PINDiode rel. time = " << reltime << endl;
             }
           
@@ -528,7 +553,10 @@
               if (TESTBIT(fFlags,kUseTimes))
                 {
-                  if (!pix.FillTimeLoGain(mtime)) 
-                    *fLog << warn << "Could not fill Lo Gain Time of pixel: " 
-                          << pixid << " time = " << mtime << endl;
+                  if (!pix.FillAbsTimeLoGain(abstime)) 
+                    *fLog << warn << "Could not fill Lo Gain Abs. Time of pixel: " 
+                          << pixid << " time = " << abstime << endl;
+                  if (!pix.FillRelTimeLoGain(reltime)) 
+                    *fLog << warn << "Could not fill Lo Gain Rel. Time of pixel: " 
+                          << pixid << " time = " << reltime << endl;
                 }
             } /* if (sig.IsLoGainUsed()) */
@@ -541,7 +569,10 @@
               if (TESTBIT(fFlags,kUseTimes))
                 {
-                  if (!pix.FillTimeHiGain(mtime))
-                    *fLog << warn << "Could not fill Hi Gain Time of pixel: " 
-                          << pixid << " time = " << mtime << endl;
+                  if (!pix.FillAbsTimeHiGain(abstime))
+                    *fLog << warn << "Could not fill Hi Gain Abs. Time of pixel: " 
+                          << pixid << " time = " << abstime << endl;
+                  if (!pix.FillRelTimeHiGain(reltime))
+                    *fLog << warn << "Could not fill Hi Gain Rel. Time of pixel: " 
+                          << pixid << " time = " << reltime << endl;
                 }
             } /* else (sig.IsLoGainUsed()) */
@@ -606,13 +637,20 @@
           MPedestalPix &ped = (*fPedestals)[fBlindPixelId];
           //
-          // retrieve the blind pixel histogram container
+          // retrieve the histogram containers
           //
           MHCalibrationBlindPixel *hist = blindpixel.GetHist();
+          MHPedestalPixel *pedhist = ped.GetHist();
           //
           // Set the corresponding values
           //
-          const Float_t peddiff     = ped.GetMean() 
-                                    - ped.GetPedestal()*fSignals->GetNumUsedFADCSlices();
-          const Float_t pederr      = ped.GetMeanErr();
+          const Float_t nslices     = (Float_t)fSignals->GetNumUsedFADCSlices();
+          const Int_t   nentries    = pedhist->GetTotalEntries();
+          
+          const Float_t peddiff     = ped.GetMean() - ped.GetPedestal()*nslices;
+
+          Float_t pederr  = ped.GetMeanErr()*ped.GetMeanErr();
+          pederr         += ped.GetPedestalRms()*ped.GetPedestalRms()*nslices*nslices/nentries/nentries;
+          pederr          = TMath::Sqrt(pederr);
+          
           const Float_t pedsigma    = ped.GetSigma();
           const Float_t pedsigmaerr = ped.GetSigmaErr();
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc	(revision 3006)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc	(revision 3007)
@@ -59,4 +59,9 @@
 
 using namespace std;
+
+const Int_t   MCalibrationCam::gkBlindPixelId   =  559;
+const Int_t   MCalibrationCam::gkPINDiodeId     = 9999;
+const Float_t MCalibrationCam::gkTimeSliceWidth = 3.3;
+
 // --------------------------------------------------------------------------
 //
@@ -72,7 +77,5 @@
     : fOffsets(NULL),
       fSlopes(NULL),
-      fOffvsSlope(NULL),
-      fBlindPixelId(559),
-      fPINDiodeId(9999)
+      fOffvsSlope(NULL)
 {
     fName  = name  ? name  : "MCalibrationCam";
@@ -261,5 +264,5 @@
     {
       
-      if (pix->IsFitValid() && !pix->IsExcluded()) 
+      if (pix->IsChargeFitValid() && !pix->IsExcluded()) 
 	{
 
@@ -287,5 +290,5 @@
       {
         
-        if (!pix->IsFitValid() && !pix->IsExcluded())
+        if (!pix->IsChargeFitValid() && !pix->IsExcluded())
           {
 
@@ -388,11 +391,11 @@
     return kFALSE;
 
-  if ( (!(*this)[idx].IsFitValid()) || (*this)[idx].IsExcluded())
-    return kFALSE;
-  
-  if (idx == fBlindPixelId)
-    return kFALSE;
-
-  if (idx == fPINDiodeId)
+  if ( (!(*this)[idx].IsChargeFitValid()) || (*this)[idx].IsExcluded())
+    return kFALSE;
+  
+  if (idx == gkBlindPixelId)
+    return kFALSE;
+
+  if (idx == gkPINDiodeId)
     return kFALSE;
 
@@ -415,11 +418,17 @@
       break;
     case 5:
-      val = (*this)[idx].GetTime();
+      if (!(*this)[idx].IsTimeFitValid())
+        return kFALSE;
+      val = (*this)[idx].GetTime() * gkTimeSliceWidth;
       break;
     case 6:
-      val = (*this)[idx].GetSigmaTime();
+      if (!(*this)[idx].IsTimeFitValid())
+        return kFALSE;
+      val = (*this)[idx].GetSigmaTime() * gkTimeSliceWidth;
       break;
     case 7:
-      val = (*this)[idx].GetTimeChiSquare();
+      if (!(*this)[idx].IsTimeFitValid())
+        return kFALSE;
+      val = (*this)[idx].GetTimeProb();
       break;
     case 8:
@@ -550,5 +559,5 @@
 {
 
-  if (!fPINDiode->IsFitValid())
+  if (!fPINDiode->IsChargeFitValid())
     return kFALSE;
   
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationCam.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationCam.h	(revision 3006)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationCam.h	(revision 3007)
@@ -21,4 +21,9 @@
 private:
   
+  static const Int_t   gkBlindPixelId;
+  static const Int_t   gkPINDiodeId;
+  static const Float_t gkTimeSliceWidth;
+  
+
   Int_t fNumPixels;
   TClonesArray *fPixels;                      //-> Array of MCalibrationPix with fit results
@@ -27,12 +32,8 @@
   MCalibrationPINDiode *fPINDiode;            //-> Pointer to the PIN Diode with fit results
 
-
   TH1D* fOffsets;                             //! 
   TH1D* fSlopes;                              //! 
   
   TH2D* fOffvsSlope;                          //! 
-
-  const Int_t fBlindPixelId;
-  const Int_t fPINDiodeId;  
 
   Float_t fMeanPhotInsidePlexiglass;     //  The mean number of photons in an INNER PIXEL inside the plexiglass
@@ -94,5 +95,4 @@
   Bool_t IsNumPhotOutsidePlexiglassAvailable() const;
 
-
   // Others
   MCalibrationPix &operator[](Int_t i);
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.cc	(revision 3006)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.cc	(revision 3007)
@@ -76,5 +76,6 @@
 
   CLRBIT(fFlags, kExcluded);
-  CLRBIT(fFlags, kFitValid);
+  CLRBIT(fFlags, kChargeFitValid);
+  CLRBIT(fFlags, kChargeFitValid);
   CLRBIT(fFlags, kFitted);
 
@@ -129,7 +130,16 @@
 // Set the Excluded Bit from outside 
 //
-void MCalibrationPINDiode::SetFitValid(Bool_t b )    
-{ 
-  b ?  SETBIT(fFlags, kFitValid) : CLRBIT(fFlags, kFitValid); 
+void MCalibrationPINDiode::SetChargeFitValid(Bool_t b )    
+{ 
+  b ?  SETBIT(fFlags, kChargeFitValid) : CLRBIT(fFlags, kChargeFitValid); 
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the Excluded Bit from outside 
+//
+void MCalibrationPINDiode::SetTimeFitValid(Bool_t b )    
+{ 
+  b ?  SETBIT(fFlags, kTimeFitValid) : CLRBIT(fFlags, kTimeFitValid); 
 }
 
@@ -148,7 +158,12 @@
  }
 
-Bool_t MCalibrationPINDiode::IsFitValid() const 
-{
-  return TESTBIT(fFlags, kFitValid);  
+Bool_t MCalibrationPINDiode::IsChargeFitValid() const 
+{
+  return TESTBIT(fFlags, kChargeFitValid);  
+}
+
+Bool_t MCalibrationPINDiode::IsTimeFitValid() const 
+{
+  return TESTBIT(fFlags, kTimeFitValid);  
 }
 
@@ -165,5 +180,5 @@
   //    or if the histogram is empty
   //
-  if (fHist->IsFitOK() || fHist->IsEmpty())
+  if (fHist->IsChargeFitOK() || fHist->IsEmpty())
     return kTRUE;
 
@@ -195,8 +210,8 @@
 
   if (CheckChargeFitValidity())
-    SETBIT(fFlags,kFitValid);
+    SETBIT(fFlags,kChargeFitValid);
   else
     {
-      CLRBIT(fFlags,kFitValid);
+      CLRBIT(fFlags,kChargeFitValid);
       return kFALSE;
     }
@@ -242,5 +257,5 @@
     }
       
-  if (!fHist->IsFitOK()) 
+  if (!fHist->IsChargeFitOK()) 
     {
       *fLog << warn << "WARNING: Probability of Fitted Charge too low in PINDiode " << endl;
@@ -267,5 +282,5 @@
 {
 
-  if(!fHist->FitTimeHiGain())
+  if(!fHist->FitTime())
     {
       *fLog << warn << "WARNING: Could not fit Hi Gain times of PIN Diode" << endl;
@@ -274,13 +289,12 @@
     }
   
-  fTime          = fHist->GetTimeMean();
-  fSigmaTime     = fHist->GetTimeSigma();
-  fTimeChiSquare = fHist->GetTimeChiSquare();
-  fTimeProb      = fHist->GetTimeProb();
+  fTime          = fHist->GetRelTimeMean();
+  fSigmaTime     = fHist->GetRelTimeSigma();
+  fTimeProb      = fHist->GetRelTimeProb();
   
   if (CheckTimeFitValidity())
-    SETBIT(fFlags,kFitValid);
+    SETBIT(fFlags,kTimeFitValid);
   else
-    CLRBIT(fFlags,kFitValid);
+    CLRBIT(fFlags,kTimeFitValid);
 
   return kTRUE;
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.h	(revision 3006)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.h	(revision 3007)
@@ -34,5 +34,5 @@
 
   enum  { kExcluded, kExcludeQualityCheck,
-          kFitValid, kFitted  };
+          kChargeFitValid, kTimeFitValid, kFitted  };
   
   Bool_t CheckChargeFitValidity();
@@ -69,5 +69,6 @@
 
   Bool_t IsExcluded()              const;
-  Bool_t IsFitValid()              const;
+  Bool_t IsChargeFitValid()        const;
+  Bool_t IsTimeFitValid()          const;
   Bool_t IsFitted()                const;
 
@@ -76,10 +77,12 @@
   void SetExcluded(Bool_t b = kTRUE);
   void SetExcludeQualityCheck(Bool_t b = kTRUE);
-  void SetFitValid(Bool_t b = kTRUE);
+  void SetChargeFitValid(Bool_t b = kTRUE);
+  void SetTimeFitValid(Bool_t b = kTRUE);
   void SetFitted(Bool_t b = kTRUE);
 
   // Fill histos
   Bool_t FillCharge(Float_t q)      { return fHist->FillChargeHiGain(q); }
-  Bool_t FillTime(Float_t t)        { return fHist->FillTimeHiGain(t); }  
+  Bool_t FillAbsTime(Float_t t)     { return fHist->FillAbsTimeHiGain(t); }
+  Bool_t FillRelTime(Float_t t)     { return fHist->FillRelTimeHiGain(t); }
   Bool_t FillRChargevsTime(Float_t rq, Int_t t) { return fHist->FillChargevsNHiGain(rq,t); }    
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc	(revision 3006)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc	(revision 3007)
@@ -30,19 +30,4 @@
 // (offset) value of one Pixel (PMT).                                      //
 //                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-#include "MCalibrationPix.h"
-#include "MCalibrationConfig.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MCalibrationPix);
-
-using namespace std;
-
-// --------------------------------------------------------------------------
-//
-// Default Constructor: 
-//
 // The following values are initialized to meaningful values:
 //
@@ -54,13 +39,31 @@
 //   Error F-Factor = 2.*0.02   = 0.04
 //
+/////////////////////////////////////////////////////////////////////////////
+#include "MCalibrationPix.h"
+#include "MCalibrationConfig.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MCalibrationPix);
+
+using namespace std;
+
+const Float_t MCalibrationPix::gkElectronicPedRms    = 1.5;
+const Float_t MCalibrationPix::gkErrElectronicPedRms = 0.3;
+const Float_t MCalibrationPix::gkFFactor             = 1.32;
+const Float_t MCalibrationPix::gkFFactorError        = 0.04;
+const Float_t MCalibrationPix::gkChargeLimit         = 3.;
+const Float_t MCalibrationPix::gkChargeErrLimit      = 0.;
+const Float_t MCalibrationPix::gkChargeRelErrLimit   = 1.;
+const Float_t MCalibrationPix::gkTimeLimit           = 1.5;
+const Float_t MCalibrationPix::gkTimeErrLimit        = 3.;
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor: 
+//
 MCalibrationPix::MCalibrationPix(const char *name, const char *title)
     : fPixId(-1),
-      fElectronicPedRms(1.5),
-      fErrElectronicPedRms(0.3),
-      fFactor(1.32),
-      fFactorError(0.04),
-      fChargeLimit(3.),
-      fChargeErrLimit(0.),
-      fChargeRelErrLimit(1.),
       fFlags(0)
 {
@@ -101,5 +104,6 @@
   CLRBIT(fFlags, kHiGainSaturation);
   CLRBIT(fFlags, kExcluded);
-  CLRBIT(fFlags, kFitValid);
+  CLRBIT(fFlags, kChargeFitValid);
+  CLRBIT(fFlags, kTimeFitValid);
   CLRBIT(fFlags, kFitted);
   CLRBIT(fFlags, kBlindPixelMethodValid);
@@ -117,6 +121,12 @@
   fErrPedRms                        =   0.;
   fTime                             =  -1.;
+  fErrTime                          =  -1.;
   fSigmaTime                        =  -1.;
-  fTimeChiSquare                    =  -1.;
+  fTimeProb                         =  -1.;
+  fTimeFirstHiGain                  =   0 ;
+  fTimeLastHiGain                   =   0 ;
+  fTimeFirstLoGain                  =   0 ;
+  fTimeLastLoGain                   =   0 ;
+
   fPheFFactorMethod                 =  -1.;
   fPheFFactorMethodError            =  -1.;
@@ -231,7 +241,16 @@
 // Set the Excluded Bit from outside 
 //
-void MCalibrationPix::SetFitValid(Bool_t b )    
-{ 
-  b ?  SETBIT(fFlags, kFitValid) : CLRBIT(fFlags, kFitValid); 
+void MCalibrationPix::SetChargeFitValid(Bool_t b )    
+{ 
+  b ?  SETBIT(fFlags, kChargeFitValid) : CLRBIT(fFlags, kChargeFitValid); 
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the Excluded Bit from outside 
+//
+void MCalibrationPix::SetTimeFitValid(Bool_t b )    
+{ 
+  b ?  SETBIT(fFlags, kTimeFitValid) : CLRBIT(fFlags, kTimeFitValid); 
 }
 
@@ -271,4 +290,21 @@
   b ?  SETBIT(fFlags, kPINDiodeMethodValid) : CLRBIT(fFlags, kPINDiodeMethodValid); 
 }
+
+void MCalibrationPix::SetAbsTimeBordersHiGain(Byte_t f, Byte_t l)
+{
+
+  fTimeFirstHiGain = f;
+  fTimeLastHiGain  = l;
+  
+}
+
+void MCalibrationPix::SetAbsTimeBordersLoGain(Byte_t f, Byte_t l)
+{
+
+  fTimeFirstLoGain = f;
+  fTimeLastLoGain  = l;
+  
+}
+
 
 
@@ -278,7 +314,12 @@
  }
 
-Bool_t MCalibrationPix::IsFitValid() const 
-{
-  return TESTBIT(fFlags, kFitValid);  
+Bool_t MCalibrationPix::IsChargeFitValid() const 
+{
+  return TESTBIT(fFlags, kChargeFitValid);  
+}
+
+Bool_t MCalibrationPix::IsTimeFitValid() const 
+{
+  return TESTBIT(fFlags, kTimeFitValid);  
 }
 
@@ -342,5 +383,5 @@
   //    or if the histogram is empty
   //
-  if (fHist->IsFitOK() || fHist->IsEmpty())
+  if (fHist->IsChargeFitOK() || fHist->IsEmpty())
     return kTRUE;
 
@@ -386,8 +427,8 @@
 
   if (CheckChargeFitValidity())
-    SETBIT(fFlags,kFitValid);
+    SETBIT(fFlags,kChargeFitValid);
   else
     {
-      CLRBIT(fFlags,kFitValid);
+      CLRBIT(fFlags,kChargeFitValid);
       return kFALSE;
     }
@@ -408,5 +449,5 @@
       const Float_t chargeSquareRelErrSquare  = 4.*fErrCharge*fErrCharge / chargeSquare;
 
-      const Float_t fFactorRelErrSquare       = fFactorError * fFactorError / (fFactor * fFactor);
+      const Float_t fFactorRelErrSquare       = gkFFactorError * gkFFactorError / (gkFFactor * gkFFactor);
       //
       // Now the absolute error squares
@@ -415,6 +456,6 @@
       const Float_t sigmaSquareErrSquare      = 4.*fErrSigmaCharge*fErrSigmaCharge * sigmaSquare;
 
-      const Float_t elecRmsSquare             =       fElectronicPedRms*   fElectronicPedRms;
-      const Float_t elecRmsSquareErrSquare    = 4.*fErrElectronicPedRms*fErrElectronicPedRms * elecRmsSquare;
+      const Float_t elecRmsSquare             =       gkElectronicPedRms*   gkElectronicPedRms;
+      const Float_t elecRmsSquareErrSquare    = 4.*gkErrElectronicPedRms*gkErrElectronicPedRms * elecRmsSquare;
 
       Float_t pedRmsSquare                    =       fPedRms*   fPedRms;
@@ -477,5 +518,5 @@
       // (independent on Hi Gain or Lo Gain)
       //
-      fPheFFactorMethod = fFactor * chargeSquare / fRSigmaSquare;
+      fPheFFactorMethod = gkFFactor * chargeSquare / fRSigmaSquare;
 
       const Float_t pheFFactorRelErrSquare =  fFactorRelErrSquare
@@ -497,5 +538,5 @@
                                          * fConversionFFactorMethod * fConversionFFactorMethod;
       
-      if ( IsFitValid()                     &&
+      if ( IsChargeFitValid()               &&
            (fConversionFFactorMethod > 0.) &&
            (fConversionErrorFFactorMethod/fConversionFFactorMethod < 0.1) )
@@ -525,5 +566,4 @@
   if (TMath::IsNaN(fCharge)
       || TMath::IsNaN(fErrCharge)
-      || TMath::IsNaN(fErrCharge)
       || TMath::IsNaN(fSigmaCharge)
       || TMath::IsNaN(fErrSigmaCharge)
@@ -543,28 +583,29 @@
     equivpedestal /= fConversionHiLo;
       
-  if (fCharge < fChargeLimit*equivpedestal)
+  if (fCharge < gkChargeLimit*equivpedestal)
     {
       *fLog << warn << "WARNING: Fitted Charge is smaller than "
-            << fChargeLimit << " Pedestal RMS in Pixel " << fPixId << endl;
-      return kFALSE;
-    }
-  
-  if (fErrCharge < fChargeErrLimit) 
+            << gkChargeLimit << " Pedestal RMS in Pixel " << fPixId << endl;
+      return kFALSE;
+    }
+  
+  if (fErrCharge < gkChargeErrLimit) 
     {
       *fLog << warn << "WARNING: Error of Fitted Charge is smaller than "
-            << fChargeErrLimit << " in Pixel " << fPixId << endl;
-      return kFALSE;
-    }
-      
-  if (fCharge < fChargeRelErrLimit*fErrCharge) 
+            << gkChargeErrLimit << " in Pixel " << fPixId << endl;
+      return kFALSE;
+    }
+      
+  if (fCharge < gkChargeRelErrLimit*fErrCharge) 
     {
       *fLog << warn << "WARNING: Fitted Charge is smaller than "
-            << fChargeRelErrLimit << "* its error in Pixel " << fPixId << endl;
-      return kFALSE;
-    }
-      
-  if (!fHist->IsFitOK()) 
-    {
-      *fLog << warn << "WARNING: Probability of Fitted Charge too low in Pixel " << fPixId << endl;
+            << gkChargeRelErrLimit << "* its error in Pixel " << fPixId << endl;
+      return kFALSE;
+    }
+      
+  if (!fHist->IsChargeFitOK()) 
+    {
+      *fLog << warn << "WARNING: Probability of Fitted Charge too low in Pixel " 
+            << fPixId << endl;
       return kFALSE;
     }
@@ -572,5 +613,6 @@
   if (fSigmaCharge < equivpedestal)
     {
-      *fLog << warn << "WARNING: Sigma of Fitted Charge smaller than Pedestal RMS in Pixel " << fPixId << endl;
+      *fLog << warn << "WARNING: Sigma of Fitted Charge smaller than Pedestal RMS in Pixel " 
+            << fPixId << endl;
       return kFALSE;
     }
@@ -579,44 +621,98 @@
 
 //
-// The check returns kTRUE if:
-//
-// The mean arrival time is at least 1.0 slices from the used edge slices 
+// The check return kTRUE if:
+//
+// 0) No value is nan
+// 1) Pixel has a fitted rel. time smaller than 3*FADC slices
+// 2) Pixel has a fit error greater than 0. 
+// 4) Pixel has a fit Probability greater than 0.001 
+// 5) The absolute arrival time is at least 1.0 slices from the used edge slices 
 //
 Bool_t MCalibrationPix::CheckTimeFitValidity()
 {
 
+  if (TMath::IsNaN(fTime)
+      || TMath::IsNaN(fErrTime)
+      || TMath::IsNaN(fSigmaTime)
+      || TMath::IsNaN(fTimeProb))
+    {
+      *fLog << warn << "WARNING: Some of the time fit values are NAN in Pixel " 
+            << fPixId << endl;
+      return kFALSE;
+    }
+  
   if (TESTBIT(fFlags,kExcludeQualityCheck))
     return kTRUE;
 
-  Float_t lowerrange;
-  Float_t upperrange;
+  if (TMath::Abs(fTime) > gkTimeLimit) 
+    {
+      *fLog << warn << "WARNING: Abs(Fitted Rel. Time) is greater than "
+            << gkTimeLimit << " in Pixel " << fPixId << endl;
+      return kFALSE;
+    }
+
+  if (fErrTime > gkTimeErrLimit) 
+    {
+      *fLog << warn << "WARNING: Error of Fitted Time is smaller than "
+            << gkTimeErrLimit << " in Pixel " << fPixId << endl;
+      return kFALSE;
+    }
+
+  if (!fHist->IsTimeFitOK()) 
+    {
+      *fLog << warn << "WARNING: Probability of Fitted Time too low in Pixel " 
+            << fPixId << endl;
+      return kFALSE;
+    }
+
+  Float_t first;
+  Float_t last;
 
   if (TESTBIT(fFlags,kHiGainSaturation))
     {
-      lowerrange = (Float_t)fHist->GetTimeLowerFitRangeLoGain()+1.;
-      upperrange = (Float_t)fHist->GetTimeUpperFitRangeLoGain()+1.;
+      first = (Float_t)fHist->GetAbsTimeFirstLoGain();
+      last = (Float_t)fHist->GetAbsTimeLastLoGain();
+
+      if (first < (Float_t)fTimeFirstLoGain+1)
+        {
+          *fLog << warn 
+                << "WARNING: Some absolute times smaller than limit in Pixel " 
+                << fPixId << " time: " << first << " Limit: " << fTimeFirstLoGain+1 << endl;
+          return kFALSE;
+        }
+
+      if ((Float_t)fTimeLastLoGain-1 > last)
+        {
+          *fLog << warn 
+                << "WARNING: Some absolute times bigger than limit in Pixel " 
+                << fPixId << " time: " << last << " Limit: " << fTimeLastLoGain-1 << endl;
+          return kFALSE;
+        }
+
     }
   else
     {
-      lowerrange = (Float_t)fHist->GetTimeLowerFitRangeHiGain()+1.;
-      upperrange = (Float_t)fHist->GetTimeUpperFitRangeHiGain()+1.;
-    }
-
-
-  if (fTime < lowerrange)
-    {
-      *fLog << warn 
-            << "WARNING: Mean Fitted Time inside or smaller than first used FADC slice in Pixel " 
-            << fPixId << " time: " << fTime << " Range: " << lowerrange << endl;
-      return kFALSE;
-    }
-
-  if (fTime > upperrange)
-    {
-      *fLog << warn 
-            << "WARNING: Mean Fitted Time inside or greater than last used FADC slice in Pixel " 
-            << fPixId << " time: " << fTime << " Range: " << upperrange << endl;
-      return kFALSE;
-    }
+      first = (Float_t)fHist->GetAbsTimeFirstHiGain();
+      last = (Float_t)fHist->GetAbsTimeLastHiGain();
+
+      if (first > ((Float_t)fTimeFirstHiGain+1.))
+        {
+          *fLog << warn 
+                << "WARNING: Some absolute times smaller than limit in Pixel " 
+                << fPixId << " time: " << first << " Limit: " << (Float_t)fTimeFirstHiGain+1. << endl;
+          //          return kFALSE;
+        }
+
+      if (((Float_t)fTimeLastHiGain-1.) > last)
+        {
+          *fLog << warn 
+                << "WARNING: Some absolute times bigger than limit in Pixel " 
+                << fPixId << " time: " << last << " Limit: " << (Float_t)fTimeLastHiGain-1. << endl;
+          //          return kFALSE;
+        }
+
+    }
+
+
 
   return kTRUE;
@@ -662,6 +758,4 @@
 // 1) Fit the arrival times
 // 2) Retrieve the results
-// 3) Note that because of the low number of bins, the NDf is sometimes 0, so 
-//    Root does not give a reasonable Probability, the Chisquare is more significant
 //
 // This fit has to be done AFTER the Charges fit, 
@@ -672,39 +766,19 @@
 {
 
-  //
-  // Fit the Low Gain
-  //
-  if (TESTBIT(fFlags,kHiGainSaturation))
-    {
-      if(!fHist->FitTimeLoGain())
-	{
-	  *fLog << warn << "WARNING: Could not fit Lo Gain times of pixel " << fPixId << endl;
-          //	  fHist->PrintTimeFitResult();
-	  return kFALSE;
-	}
-    }
-
-  //
-  // Fit the High Gain
-  //
+  if(!fHist->FitTime())
+    {
+      *fLog << warn << "WARNING: Could not fit relative times of pixel " << fPixId << endl;
+      return kFALSE;
+    }
+  
+  fTime          = fHist->GetRelTimeMean();
+  fErrTime       = fHist->GetRelTimeMeanErr();
+  fSigmaTime     = fHist->GetRelTimeSigma();
+  fTimeProb      = fHist->GetRelTimeProb();
+
+  if (CheckTimeFitValidity())
+    SETBIT(fFlags,kTimeFitValid);
   else
-    {
-      if(!fHist->FitTimeHiGain())
-	{
-	  *fLog << warn << "WARNING: Could not fit Hi Gain times of pixel " << fPixId << endl;
-          //	  fHist->PrintTimeFitResult();
-	  return kFALSE;
-	}
-    }
-    
-  fTime          = fHist->GetTimeMean();
-  fSigmaTime     = fHist->GetTimeSigma();
-  fTimeChiSquare = fHist->GetTimeChiSquare();
-  fTimeProb      = fHist->GetTimeProb();
-
-  if (CheckTimeFitValidity())
-    SETBIT(fFlags,kFitValid);
-  else
-    CLRBIT(fFlags,kFitValid);
+    CLRBIT(fFlags,kTimeFitValid);
 
   return kTRUE;
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationPix.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationPix.h	(revision 3006)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationPix.h	(revision 3007)
@@ -12,16 +12,17 @@
 private:
 
+  static const Float_t gkElectronicPedRms;    // The pure electronic component of the RMS
+  static const Float_t gkErrElectronicPedRms; // The error of the pure electronic component of the RMS
+  static const Float_t gkFFactor;             // The laboratory F-factor
+  static const Float_t gkFFactorError;        // The laboratory F-factor Error
+  static const Float_t gkChargeLimit;         // The limit (in units of PedRMS) for acceptance of the fitted mean charge
+  static const Float_t gkChargeErrLimit;      // The limit (in units of PedRMS) for acceptance of the fitted charge sigma
+  static const Float_t gkChargeRelErrLimit;   // The limit (in units of Error of fitted charge) for acceptance of the fitted mean  
+  static const Float_t gkTimeLimit;           // The limit (in units of FADC slices) for acceptance of the fitted time
+  static const Float_t gkTimeErrLimit;        // The limit (in units of FADC slices) for acceptance of the fitted time sigma
+   
   Int_t   fPixId;                     // the pixel Id
-  
-  const Float_t fElectronicPedRms;    // The pure electronic component of the RMS
-  const Float_t fErrElectronicPedRms; // The error of the pure electronic component of the RMS
 
-  const Float_t fFactor;              // The laboratory F-factor
-  const Float_t fFactorError;         // The laboratory F-factor Error
-
-  const Float_t fChargeLimit;         // The limit (in units of PedRMS) for acceptance of the fitted mean charge
-  const Float_t fChargeErrLimit;      // The limit (in units of PedRMS) for acceptance of the fitted charge sigma
-  const Float_t fChargeRelErrLimit;   // The limit (in units of Error of fitted charge) for acceptance of the fitted mean  
-  Byte_t  fFlags;               // Flag for the set Bits
+  UInt_t  fFlags;               // Flag for the set Bits
   
   Float_t fCharge;              // The mean reduced charge after the fit
@@ -36,8 +37,14 @@
   Float_t fErrPedRms;           // The error of the pedestal  RMS (from MPedestalPix)  
 
-  Float_t fTime;                // The mean arrival time after the fit  
+  Float_t fTime;                // The mean arrival time after the fit
+  Float_t fErrTime;             // The mean arrival time error after the fit    
   Float_t fSigmaTime;           // The error of the mean arrival time after the fit
-  Float_t fTimeChiSquare;       // The Chi Square of the fit function 
   Float_t fTimeProb;            // The probability of the fit function 
+
+  Byte_t  fTimeFirstHiGain;           // The first used FADC slice
+  Byte_t  fTimeLastHiGain;            // The last used FADC slice
+  
+  Byte_t  fTimeFirstLoGain;           // The first used FADC slice
+  Byte_t  fTimeLastLoGain;            // The last used FADC slice
   
   Float_t fPheFFactorMethod;                // The number of Phe's calculated (F-factor method)
@@ -61,5 +68,6 @@
   enum  { kHiGainSaturation,
           kExcluded, kExcludeQualityCheck,
-          kFitValid, kFitted,
+          kChargeFitValid, kTimeFitValid,
+          kFitted,
           kBlindPixelMethodValid, kFFactorMethodValid, kPINDiodeMethodValid };
   
@@ -90,6 +98,6 @@
   // Times  
   Float_t GetTime()                const { return fTime;           }
+  Float_t GetErrTime()             const { return fErrTime;        }  
   Float_t GetSigmaTime()           const { return fSigmaTime;      }
-  Float_t GetTimeChiSquare()       const { return fTimeChiSquare;  }
   Float_t GetTimeProb()            const { return fTimeProb;  }      
 
@@ -118,5 +126,6 @@
 
   Bool_t IsExcluded()              const;
-  Bool_t IsFitValid()              const;
+  Bool_t IsChargeFitValid()        const;
+  Bool_t IsTimeFitValid()          const;
   Bool_t IsFitted()                const;
   Bool_t IsBlindPixelMethodValid() const;
@@ -138,17 +147,22 @@
   void SetExcluded(Bool_t b = kTRUE);
   void SetExcludeQualityCheck(Bool_t b = kTRUE);
-  void SetFitValid(Bool_t b = kTRUE);
+  void SetChargeFitValid(Bool_t b = kTRUE);
+  void SetTimeFitValid(Bool_t b = kTRUE);
   void SetFitted(Bool_t b = kTRUE);
   void SetBlindPixelMethodValid(Bool_t b = kTRUE);
   void SetFFactorMethodValid(Bool_t b = kTRUE);
   void SetPINDiodeMethodValid(Bool_t b = kTRUE);
+  void SetAbsTimeBordersHiGain(Byte_t f, Byte_t l);
+  void SetAbsTimeBordersLoGain(Byte_t f, Byte_t l);
   
   // Fill histos
-  Bool_t FillChargeHiGain(Float_t q) const                  { return fHist->FillChargeHiGain(q); }
-  Bool_t FillTimeHiGain(Float_t t)   const                  { return fHist->FillTimeHiGain(t); }  
+  Bool_t FillChargeHiGain(Float_t q)                  const { return fHist->FillChargeHiGain(q); }
+  Bool_t FillAbsTimeHiGain(Float_t t)                 const { return fHist->FillAbsTimeHiGain(t); }
+  Bool_t FillRelTimeHiGain(Float_t t)                 const { return fHist->FillRelTimeHiGain(t); }  
   Bool_t FillRChargevsTimeHiGain(Float_t rq, Int_t t) const { return fHist->FillChargevsNHiGain(rq,t); }    
 
-  Bool_t FillChargeLoGain(Float_t q) const                  { return fHist->FillChargeLoGain(q); }
-  Bool_t FillTimeLoGain(Float_t t)   const                  { return fHist->FillTimeLoGain(t); }  
+  Bool_t FillChargeLoGain(Float_t q)                  const { return fHist->FillChargeLoGain(q); }
+  Bool_t FillAbsTimeLoGain(Float_t t)                 const { return fHist->FillAbsTimeLoGain(t); }
+  Bool_t FillRelTimeLoGain(Float_t t)                 const { return fHist->FillRelTimeLoGain(t); }    
   Bool_t FillRChargevsTimeLoGain(Float_t rq, Int_t t) const { return fHist->FillChargevsNLoGain(rq,t); }    
   
Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.cc	(revision 3006)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.cc	(revision 3007)
@@ -79,8 +79,8 @@
 
 const Int_t    MHCalibrationBlindPixel::fgBlindPixelChargeNbins        = 1000;
-const Int_t    MHCalibrationBlindPixel::fgBlindPixelTimeNbins          = 32;
+const Int_t    MHCalibrationBlindPixel::fgBlindPixelTimeNbins          = 22;
 const Int_t    MHCalibrationBlindPixel::fgBlindPixelChargevsNbins      = 10000;
-const Axis_t   MHCalibrationBlindPixel::fgBlindPixelTimeFirst          = -0.25;
-const Axis_t   MHCalibrationBlindPixel::fgBlindPixelTimeLast           = 15.75;
+const Axis_t   MHCalibrationBlindPixel::fgBlindPixelTimeFirst          = -9.00;
+const Axis_t   MHCalibrationBlindPixel::fgBlindPixelTimeLast           = 12.00;
 const Double_t MHCalibrationBlindPixel::fgBlindPixelElectronicAmp      = 0.008;
 const Double_t MHCalibrationBlindPixel::fgBlindPixelElectronicAmpError = 0.002;
Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationPINDiode.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationPINDiode.cc	(revision 3006)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationPINDiode.cc	(revision 3007)
@@ -93,6 +93,6 @@
   if (fChargeGausFit)
     delete fChargeGausFit;
-  if (fTimeGausFit)
-    delete fTimeGausFit;
+  if (fRelTimeGausFit)
+    delete fRelTimeGausFit;
   if (fFitLegend)
     delete fFitLegend;
@@ -110,19 +110,18 @@
   fChargeProb              = -1.;
   fChargeNdf               = -1;
-  fTimeChisquare           = -1.;
-  fTimeProb                = -1.;
-  fTimeNdf                 = -1;
-  fTimeMean                = -1.;
-  fTimeSigma               = -1.;
+  fRelTimeProb             = -1.;
+  fRelTimeNdf              = -1;
+  fRelTimeMean             = -1.;
+  fRelTimeSigma            = -1.;
 
-  fTimeLowerFitRangeHiGain = 0;
-  fTimeUpperFitRangeHiGain = 0;
-  fTimeLowerFitRangeLoGain = 0;
-  fTimeUpperFitRangeLoGain = 0;
+  fRelTimeLowerFitRangeHiGain = -99.;
+  fRelTimeUpperFitRangeHiGain = -99.;
+  fRelTimeLowerFitRangeLoGain = -99.;
+  fRelTimeUpperFitRangeLoGain = -99.;
 
   if (fChargeGausFit)
     delete fChargeGausFit;
-  if (fTimeGausFit)
-    delete fTimeGausFit;
+  if (fRelTimeGausFit)
+    delete fRelTimeGausFit;
   if (fFitLegend)
     delete fFitLegend;
Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc	(revision 3006)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc	(revision 3007)
@@ -50,4 +50,14 @@
 using namespace std;
 
+const Int_t   MHCalibrationPixel::fChargeNbinsHiGain = 2100;
+const Int_t   MHCalibrationPixel::fChargeNbinsLoGain = 1010;
+const Int_t   MHCalibrationPixel::fAbsTimeNbins      = 32;
+const Int_t   MHCalibrationPixel::fRelTimeNbins      = 240;
+const Int_t   MHCalibrationPixel::fChargevsNbins     = 5000;
+const Axis_t  MHCalibrationPixel::fAbsTimeFirst      = - 0.25;
+const Axis_t  MHCalibrationPixel::fAbsTimeLast       =  15.75;
+const Axis_t  MHCalibrationPixel::fRelTimeFirst      = -11.;
+const Axis_t  MHCalibrationPixel::fRelTimeLast       =  12.;
+
 // --------------------------------------------------------------------------
 //
@@ -56,14 +66,8 @@
 MHCalibrationPixel::MHCalibrationPixel(const char *name, const char *title)
       : fPixId(-1),
-        fChargeNbinsHiGain(2100),
-        fChargeNbinsLoGain(1010),
-        fTimeNbins(32),
-        fChargevsNbins(5000),
-        fTimeFirst(-0.25),
-        fTimeLast(15.75),
 	fHivsLoGain(NULL),
         fHPSD(NULL),
         fChargeGausFit(NULL),
-	fTimeGausFit(NULL), 
+	fRelTimeGausFit(NULL), 
 	fFitLegend(NULL)
 { 
@@ -92,14 +96,27 @@
     fHChargeLoGain->Sumw2();
 
-    fHTimeHiGain = new TH1F("HTimeHiGain","Distribution of Mean Arrival Hi Gain Times Pixel ",
-			    fTimeNbins,fTimeFirst,fTimeLast);
-    fHTimeLoGain = new TH1F("HTimeLoGain","Distribution of Mean Arrival Lo Gain Times Pixel ",
-			    fTimeNbins,fTimeFirst,fTimeLast);
-
-    fHTimeHiGain->SetXTitle("Mean Arrival Times [Hi Gain FADC slice nr]");
-    fHTimeLoGain->SetXTitle("Mean Arrival Times [Lo Gain FADC slice nr]");
-
-    fHTimeHiGain->SetYTitle("Nr. of events");
-    fHTimeLoGain->SetYTitle("Nr. of events");
+    // Absolute Times
+    fHAbsTimeHiGain = new TH1F("HAbsTimeHiGain","Distribution of Absolute Arrival Hi Gain Times Pixel ",
+                               fAbsTimeNbins,fAbsTimeFirst,fAbsTimeLast);
+    fHAbsTimeLoGain = new TH1F("HAbsTimeLoGain","Distribution of Absolute Arrival Lo Gain Times Pixel ",
+                               fAbsTimeNbins,fAbsTimeFirst,fAbsTimeLast);
+
+    fHAbsTimeHiGain->SetXTitle("Absolute Arrival Time [Hi Gain FADC slice nr]");
+    fHAbsTimeLoGain->SetXTitle("Absolute Arrival Time [Lo Gain FADC slice nr]");
+
+    fHAbsTimeHiGain->SetYTitle("Nr. of events");
+    fHAbsTimeLoGain->SetYTitle("Nr. of events");
+
+    // Relative Times
+    fHRelTimeHiGain = new TH1F("HRelTimeHiGain","Distribution of Relative Arrival Times High Gain Pixel ",
+                               fRelTimeNbins,fRelTimeFirst,fRelTimeLast);
+    fHRelTimeLoGain = new TH1F("HRelTimeLoGain","Distribution of Relative Arrival Time Low Gain Pixel ",
+                               fRelTimeNbins,fRelTimeFirst,fRelTimeLast);
+
+    fHRelTimeHiGain->SetXTitle("Relative Arrival Times [Hi Gain FADC slice nr]");
+    fHRelTimeLoGain->SetXTitle("Relative Arrival Times [Lo Gain FADC slice nr]");
+
+    fHRelTimeHiGain->SetYTitle("Nr. of events");
+    fHRelTimeLoGain->SetYTitle("Nr. of events");
 
     // We define a reasonable number and later enlarge it if necessary
@@ -117,6 +134,8 @@
     fHChargeHiGain->SetDirectory(NULL);
     fHChargeLoGain->SetDirectory(NULL);
-    fHTimeHiGain->SetDirectory(NULL);
-    fHTimeLoGain->SetDirectory(NULL);
+    fHAbsTimeHiGain->SetDirectory(NULL);
+    fHAbsTimeLoGain->SetDirectory(NULL);
+    fHRelTimeHiGain->SetDirectory(NULL);
+    fHRelTimeLoGain->SetDirectory(NULL);
     fHChargevsNHiGain->SetDirectory(NULL);
     fHChargevsNLoGain->SetDirectory(NULL);
@@ -133,9 +152,11 @@
 
   delete fHChargeHiGain;
-  delete fHTimeHiGain;
+  delete fHAbsTimeHiGain;
+  delete fHRelTimeHiGain;
   delete fHChargevsNHiGain;
 
   delete fHChargeLoGain;
-  delete fHTimeLoGain;
+  delete fHAbsTimeLoGain;
+  delete fHRelTimeLoGain;
   delete fHChargevsNLoGain;
 
@@ -145,6 +166,6 @@
   if (fChargeGausFit)
     delete fChargeGausFit;
-  if (fTimeGausFit)
-    delete fTimeGausFit;
+  if (fRelTimeGausFit)
+    delete fRelTimeGausFit;
   if (fFitLegend)
     delete fFitLegend;
@@ -168,14 +189,20 @@
   fChargeNdf               = -1;
 
-  fTimeChisquare           = -1.;
-  fTimeProb                = -1.;
-  fTimeNdf                 = -1;
-  fTimeMean                = -1.;
-  fTimeSigma               = -1.;
-
-  fTimeLowerFitRangeHiGain = 0;
-  fTimeUpperFitRangeHiGain = 0;
-  fTimeLowerFitRangeLoGain = 0;
-  fTimeUpperFitRangeLoGain = 0;
+  fRelTimeChisquare        = -1.;
+  fRelTimeProb             = -1.;
+  fRelTimeNdf              = -1;
+  fRelTimeMean             = -1.;
+  fRelTimeSigma            = -1.;
+
+  fRelTimeLowerFitRangeHiGain = -99.;
+  fRelTimeUpperFitRangeHiGain = -99.;
+  fRelTimeLowerFitRangeLoGain = -99.;
+  fRelTimeUpperFitRangeLoGain = -99.;
+
+  fAbsTimeFirstHiGain     = -1.;
+  fAbsTimeFirstLoGain     = -1.;
+  fAbsTimeLastHiGain      = -1.;
+  fAbsTimeLastLoGain      = -1.;
+  
 
   fOffset = 0.;
@@ -184,6 +211,6 @@
   if (fChargeGausFit)
     delete fChargeGausFit;
-  if (fTimeGausFit)
-    delete fTimeGausFit;
+  if (fRelTimeGausFit)
+    delete fRelTimeGausFit;
   if (fFitLegend)
     delete fFitLegend;
@@ -193,4 +220,8 @@
     delete fHPSD;
 
+  CLRBIT(fFlags,kUseLoGain);
+  CLRBIT(fFlags,kChargeFitOK);
+  CLRBIT(fFlags,kTimeFitOK);
+
   return;
 }
@@ -204,6 +235,8 @@
   fHChargeHiGain->Reset();
   fHChargeLoGain->Reset();
-  fHTimeHiGain->Reset();
-  fHTimeLoGain->Reset();
+  fHAbsTimeHiGain->Reset();
+  fHAbsTimeLoGain->Reset();
+  fHRelTimeHiGain->Reset();
+  fHRelTimeLoGain->Reset();
   fHChargevsNHiGain->Reset();
   fHChargevsNLoGain->Reset();
@@ -214,4 +247,11 @@
 }
 
+void MHCalibrationPixel::SetUseLoGain(Bool_t b)
+{
+  if (b)
+    SETBIT(fFlags, kUseLoGain) ;
+  else
+    CLRBIT(fFlags, kUseLoGain);
+}
 
 
@@ -226,7 +266,12 @@
 }
 
-Bool_t MHCalibrationPixel::IsFitOK() const 
-{
-    return TESTBIT(fFlags,kFitOK);
+Bool_t MHCalibrationPixel::IsChargeFitOK() const 
+{
+    return TESTBIT(fFlags,kChargeFitOK);
+}
+
+Bool_t MHCalibrationPixel::IsTimeFitOK() const 
+{
+    return TESTBIT(fFlags,kTimeFitOK);
 }
 
@@ -236,7 +281,12 @@
 }
 
-Bool_t MHCalibrationPixel::FillTimeLoGain(Float_t t)
-{
-    return (fHTimeLoGain->Fill(t)   > -1);
+Bool_t MHCalibrationPixel::FillAbsTimeLoGain(Float_t t)
+{
+    return (fHAbsTimeLoGain->Fill(t)   > -1);
+}
+
+Bool_t MHCalibrationPixel::FillRelTimeLoGain(Float_t t)
+{
+    return (fHRelTimeLoGain->Fill(t)   > -1);
 }
 
@@ -251,7 +301,12 @@
 }
 
-Bool_t MHCalibrationPixel::FillTimeHiGain(Float_t t)
-{
-    return (fHTimeHiGain->Fill(t) > -1);
+Bool_t MHCalibrationPixel::FillAbsTimeHiGain(Float_t t)
+{
+    return (fHAbsTimeHiGain->Fill(t) > -1);
+}
+
+Bool_t MHCalibrationPixel::FillRelTimeHiGain(Float_t t)
+{
+    return (fHRelTimeHiGain->Fill(t) > -1);
 }
 
@@ -273,7 +328,11 @@
   fHChargeHiGain->SetName(nameQHiGain.Data());
 
-  TString nameTHiGain = TString(fHTimeHiGain->GetName());
-  nameTHiGain += id;
-  fHTimeHiGain->SetName(nameTHiGain.Data());
+  TString nameTAHiGain = TString(fHAbsTimeHiGain->GetName());
+  nameTAHiGain += id;
+  fHAbsTimeHiGain->SetName(nameTAHiGain.Data());
+
+  TString nameTRHiGain = TString(fHRelTimeHiGain->GetName());
+  nameTRHiGain += id;
+  fHRelTimeHiGain->SetName(nameTRHiGain.Data());
 
   TString nameQvsNHiGain  = TString(fHChargevsNHiGain->GetName());
@@ -288,7 +347,11 @@
   fHChargeHiGain->SetTitle(titleQHiGain.Data());
 
-  TString titleTHiGain = TString(fHTimeHiGain->GetTitle());
-  titleTHiGain += id;
-  fHTimeHiGain->SetTitle(titleTHiGain.Data());
+  TString titleTAHiGain = TString(fHAbsTimeHiGain->GetTitle());
+  titleTAHiGain += id;
+  fHAbsTimeHiGain->SetTitle(titleTAHiGain.Data());
+
+  TString titleTRHiGain = TString(fHRelTimeHiGain->GetTitle());
+  titleTRHiGain += id;
+  fHRelTimeHiGain->SetTitle(titleTRHiGain.Data());
 
   TString titleQvsNHiGain  = TString(fHChargevsNHiGain->GetTitle());
@@ -303,7 +366,11 @@
   fHChargeLoGain->SetName(nameQLoGain.Data());
 
-  TString nameTLoGain = TString(fHTimeLoGain->GetName());
-  nameTLoGain += id;
-  fHTimeLoGain->SetName(nameTLoGain.Data());
+  TString nameTALoGain = TString(fHAbsTimeLoGain->GetName());
+  nameTALoGain += id;
+  fHAbsTimeLoGain->SetName(nameTALoGain.Data());
+
+  TString nameTRLoGain = TString(fHRelTimeLoGain->GetName());
+  nameTRLoGain += id;
+  fHRelTimeLoGain->SetName(nameTRLoGain.Data());
 
   TString nameQvsNLoGain  = TString(fHChargevsNLoGain->GetName());
@@ -318,7 +385,11 @@
   fHChargeLoGain->SetTitle(titleQLoGain.Data());
 
-  TString titleTLoGain = TString(fHTimeLoGain->GetTitle());
-  titleTLoGain += id;
-  fHTimeLoGain->SetTitle(titleTLoGain.Data());
+  TString titleTALoGain = TString(fHAbsTimeLoGain->GetTitle());
+  titleTALoGain += id;
+  fHAbsTimeLoGain->SetTitle(titleTALoGain.Data());
+
+  TString titleTRLoGain = TString(fHRelTimeLoGain->GetTitle());
+  titleTRLoGain += id;
+  fHRelTimeLoGain->SetTitle(titleTRLoGain.Data());
 
   TString titleQvsNLoGain  = TString(fHChargevsNLoGain->GetTitle());
@@ -375,5 +446,5 @@
   fFitLegend = new TPaveText(0.05,0.05,0.95,0.95);
 
-  if (IsFitOK()) 
+  if (IsChargeFitOK()) 
       fFitLegend->SetFillColor(80);
   else
@@ -403,5 +474,5 @@
   t4->SetBit(kCanDelete);
 
-  if (IsFitOK())
+  if (IsChargeFitOK())
     {
       TText *t5 = fFitLegend->AddText("Result of the Fit: OK");
@@ -459,5 +530,5 @@
   TCanvas *c = MakeDefCanvas(this,600,900); 
   
-  c->Divide(2,4);
+  c->Divide(2,5);
   
   c->cd(1);
@@ -490,5 +561,5 @@
       if (fChargeGausFit)
         {
-          if (IsFitOK())
+          if (IsChargeFitOK())
             fChargeGausFit->SetLineColor(kGreen);          
           else
@@ -516,5 +587,5 @@
       if (fChargeGausFit)
         {
-          if (IsFitOK())
+          if (IsChargeFitOK())
             fChargeGausFit->SetLineColor(kGreen);          
           else
@@ -557,5 +628,5 @@
   gPad->SetTicks();  
   gPad->SetLogy(0);
-  fHTimeHiGain->Draw(opt);
+  fHRelTimeHiGain->Draw(opt);
   c->Modified();
   c->Update();
@@ -567,16 +638,16 @@
         gPad->SetTicks();
 	gPad->SetLogy(0);
-	fHTimeLoGain->Draw(opt);
+	fHRelTimeLoGain->Draw(opt);
 	c->Modified();
 	c->Update();
 	
-	if (fTimeGausFit)
+	if (fRelTimeGausFit)
 	  {
-	    if (fTimeChisquare > 20.) 
-	      fTimeGausFit->SetLineColor(kRed);
+	    if (fRelTimeChisquare > 20.) 
+	      fRelTimeGausFit->SetLineColor(kRed);
 	    else
-	      fTimeGausFit->SetLineColor(kGreen);
+	      fRelTimeGausFit->SetLineColor(kGreen);
 	    
-	    fTimeGausFit->Draw("same");
+	    fRelTimeGausFit->Draw("same");
 	    c->Modified();
 	    c->Update();
@@ -585,12 +656,12 @@
     else
       {  
-	if (fTimeGausFit)
+	if (fRelTimeGausFit)
 	  {
-	    if (fTimeChisquare > 20.) 
-	      fTimeGausFit->SetLineColor(kRed);
+	    if (fRelTimeChisquare > 20.) 
+	      fRelTimeGausFit->SetLineColor(kRed);
 	    else
-	      fTimeGausFit->SetLineColor(kGreen);
+	      fRelTimeGausFit->SetLineColor(kGreen);
 	    
-	    fTimeGausFit->Draw("same");
+	    fRelTimeGausFit->Draw("same");
 	    c->Modified();
 	    c->Update();
@@ -600,5 +671,5 @@
         gPad->SetTicks();
 	gPad->SetLogy(0);
-	fHTimeLoGain->Draw(opt);	
+	fHRelTimeLoGain->Draw(opt);	
 	c->Modified();
 	c->Update();
@@ -610,9 +681,22 @@
     c->cd(7);
     gPad->SetTicks();
+    fHAbsTimeHiGain->Draw(opt);
+    c->Modified();
+    c->Update();
+
+    c->cd(8);
+    gPad->SetTicks();
+    fHAbsTimeLoGain->Draw(opt);
+    c->Modified();
+    c->Update();
+
+
+    c->cd(9);
+    gPad->SetTicks();
     fHChargevsNHiGain->Draw(opt);
     c->Modified();
     c->Update();
 
-    c->cd(8);
+    c->cd(10);
     gPad->SetTicks();
     fHChargevsNLoGain->Draw(opt);
@@ -656,55 +740,82 @@
 
 
-Bool_t MHCalibrationPixel::FitTimeHiGain(Axis_t rmin, Axis_t rmax, Option_t *option)
-{
-
-  if (fTimeGausFit)
+Bool_t MHCalibrationPixel::FitTime(Option_t *option)
+{
+
+  if (fRelTimeGausFit)
     return kFALSE;
 
-  rmin = (rmin != 0.) ? rmin : (Axis_t)fTimeLowerFitRangeHiGain;
-  rmax = (rmax != 0.) ? rmax : (Axis_t)fTimeUpperFitRangeHiGain;
-
-  const Stat_t entries       = fHTimeHiGain->Integral();
-  const Double_t mu_guess    = fHTimeHiGain->GetBinCenter(fHTimeHiGain->GetMaximumBin());
+  //
+  // Get the fitting ranges
+  //
+  Axis_t rmin = fRelTimeLowerFitRangeHiGain;
+  if (TESTBIT(fFlags,kUseLoGain))
+    rmin = fRelTimeLowerFitRangeLoGain;
+
+  Axis_t rmax = fRelTimeUpperFitRangeHiGain;
+  if (TESTBIT(fFlags,kUseLoGain))
+    rmin = fRelTimeUpperFitRangeLoGain;
+
+  TH1F *hist = fHRelTimeHiGain;
+  if (TESTBIT(fFlags,kUseLoGain))
+    hist = fHRelTimeLoGain;
+
+  const Stat_t   entries     = hist->Integral("width");
+  const Double_t mu_guess    = hist->GetBinCenter(hist->GetMaximumBin());
   const Double_t sigma_guess = (rmax - rmin)/2.;
-  const Double_t area_guess  = entries/gkSq2Pi;
-
-  TString name = TString("GausTime");
+  const Double_t area_guess  = 2.*entries/gkSq2Pi/sigma_guess;
+
+  TString name = TString("GausRelTime");
   name += fPixId;
-  fTimeGausFit = new TF1(name.Data(),"gaus",rmin,rmax);  
-
-  if (!fTimeGausFit) 
-    {
-    *fLog << warn << dbginf << "WARNING: Could not create fit function for Time fit" << endl;
+  fRelTimeGausFit = new TF1(name.Data(),"gaus",rmin,rmax);  
+
+  if (!fRelTimeGausFit) 
+    {
+    *fLog << warn << dbginf << "WARNING: Could not create fit function for RelTime fit" << endl;
     return kFALSE;
     }
 
-  fTimeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
-  fTimeGausFit->SetParNames("Area","#mu","#sigma");
-  fTimeGausFit->SetParLimits(0,0.,entries);
-  fTimeGausFit->SetParLimits(1,rmin,rmax);
-  fTimeGausFit->SetParLimits(2,0.,(rmax-rmin));
-  fTimeGausFit->SetRange(rmin,rmax);
-
-  fHTimeHiGain->Fit(fTimeGausFit,option);
-
-  rmin = fTimeGausFit->GetParameter(1) - 3.*fTimeGausFit->GetParameter(2);
-  rmax = fTimeGausFit->GetParameter(1) + 3.*fTimeGausFit->GetParameter(2);
-  fTimeGausFit->SetRange(rmin,rmax);  
-
-  fHTimeHiGain->Fit(fTimeGausFit,option);
-
-  fTimeChisquare = fTimeGausFit->GetChisquare();
-  fTimeNdf       = fTimeGausFit->GetNDF();
-  fTimeProb      = fTimeGausFit->GetProb();
-
-  fTimeMean      = fTimeGausFit->GetParameter(1);
-  fTimeSigma     = fTimeGausFit->GetParameter(2);
-
-  if (TMath::IsNaN(fTimeMean) || TMath::IsNaN(fTimeSigma))
-    return kFALSE;
-
-  if (TMath::IsNaN(fTimeChisquare) || fTimeChisquare > 20.)  // Cannot use Probability because Ndf is sometimes < 1
-    return kFALSE;
+  fRelTimeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
+  fRelTimeGausFit->SetParNames("Area","#mu","#sigma");
+  fRelTimeGausFit->SetParLimits(0,0.,5.*area_guess);
+  fRelTimeGausFit->SetParLimits(1,rmin,rmax);
+  fRelTimeGausFit->SetParLimits(2,0.,(rmax-rmin));
+  fRelTimeGausFit->SetRange(rmin,rmax);
+
+  hist->Fit(fRelTimeGausFit,option);
+
+  //
+  // If the fit does not converge, try another one with smaller bounderies
+  //
+  if (fRelTimeGausFit->GetProb() < 0.001)
+    {
+      rmin = fRelTimeGausFit->GetParameter(1) - 2.*fRelTimeGausFit->GetParameter(2);
+      rmax = fRelTimeGausFit->GetParameter(1) + 2.*fRelTimeGausFit->GetParameter(2);
+      fRelTimeGausFit->SetRange(rmin,rmax);  
+      hist->Fit(fRelTimeGausFit,option);
+    }
+  
+  fRelTimeChisquare = fRelTimeGausFit->GetChisquare();
+  fRelTimeNdf       = fRelTimeGausFit->GetNDF();
+  fRelTimeProb      = fRelTimeGausFit->GetProb();
+
+  fRelTimeMean      = fRelTimeGausFit->GetParameter(1);
+  fRelTimeSigma     = fRelTimeGausFit->GetParameter(2);
+
+  fRelTimeMeanErr   = fRelTimeGausFit->GetParError(1);
+
+  if (TMath::IsNaN(fRelTimeMean) || TMath::IsNaN(fRelTimeSigma))
+    {
+      CLRBIT(fFlags,kTimeFitOK);
+      return kFALSE;
+    }
+  
+  if (TMath::IsNaN(fRelTimeChisquare) || (fRelTimeProb < gkProbLimit))
+    {
+      CLRBIT(fFlags,kTimeFitOK);
+      return kFALSE;
+    }
+  
+  SETBIT(fFlags,kTimeFitOK);
 
   return kTRUE;
@@ -712,59 +823,4 @@
 }
 
-Bool_t MHCalibrationPixel::FitTimeLoGain(Axis_t rmin, Axis_t rmax, Option_t *option)
-{
-
-  if (fTimeGausFit)
-    return kFALSE;
-
-  rmin = (rmin != 0.) ? rmin : (Axis_t)fTimeLowerFitRangeLoGain;
-  rmax = (rmax != 0.) ? rmax : (Axis_t)fTimeUpperFitRangeLoGain;
-
-  const Stat_t   entries     = fHTimeLoGain->Integral();
-  const Double_t mu_guess    = fHTimeLoGain->GetBinCenter(fHTimeLoGain->GetMaximumBin());
-  const Double_t sigma_guess = (rmax - rmin)/2.;
-  const Double_t area_guess  = entries/gkSq2Pi;
-
-  TString name = TString("GausTime");
-  name += fPixId;
-  fTimeGausFit = new TF1(name.Data(),"gaus",rmin,rmax);  
-
-  if (!fTimeGausFit) 
-    {
-    *fLog << warn << dbginf << "WARNING: Could not create fit function for Time fit" << endl;
-    return kFALSE;
-    }
-
-  fTimeGausFit->SetParameters(area_guess,mu_guess,sigma_guess);
-  fTimeGausFit->SetParNames("Area","#mu","#sigma");
-  fTimeGausFit->SetParLimits(0,0.,entries);
-  fTimeGausFit->SetParLimits(1,rmin,rmax);
-  fTimeGausFit->SetParLimits(2,0.,(rmax-rmin));
-  fTimeGausFit->SetRange(rmin,rmax);
-
-  fHTimeLoGain->Fit(fTimeGausFit,option);
-
-  rmin = fTimeGausFit->GetParameter(1) - 3.*fTimeGausFit->GetParameter(2);
-  rmax = fTimeGausFit->GetParameter(1) + 3.*fTimeGausFit->GetParameter(2);
-  fTimeGausFit->SetRange(rmin,rmax);  
-
-  fHTimeLoGain->Fit(fTimeGausFit,option);
-
-  fTimeChisquare = fTimeGausFit->GetChisquare();
-  fTimeNdf       = fTimeGausFit->GetNDF();
-  fTimeProb      = fTimeGausFit->GetProb();
-
-  fTimeMean      = fTimeGausFit->GetParameter(1);
-  fTimeSigma     = fTimeGausFit->GetParameter(2);
-
-  if (fTimeChisquare > 20.)  // Cannot use Probability because Ndf is sometimes < 1
-    {
-      *fLog << warn << "WARNING: Fit of the Arrival times failed ! " << endl;
-      return kFALSE;
-    }
-  
-  return kTRUE;
-
-}
 
 Bool_t MHCalibrationPixel::FitCharge(Option_t *option)
@@ -783,5 +839,5 @@
   Axis_t rmax = fChargeLastHiGain;
   if (TESTBIT(fFlags,kUseLoGain))
-    rmin = fChargeFirstLoGain;
+    rmax = fChargeLastLoGain;
 
   TH1F *hist = fHChargeHiGain;
@@ -847,5 +903,5 @@
   if (TMath::IsNaN(fChargeMean) || TMath::IsNaN(fChargeMeanErr))
     {
-      CLRBIT(fFlags,kFitOK);
+      CLRBIT(fFlags,kChargeFitOK);
       return kFALSE;
     }
@@ -853,9 +909,9 @@
   if ((fChargeProb < gkProbLimit) || (TMath::IsNaN(fChargeProb)))
     {
-      CLRBIT(fFlags,kFitOK);
+      CLRBIT(fFlags,kChargeFitOK);
       return kFALSE;
     }
   
-  SETBIT(fFlags,kFitOK);
+  SETBIT(fFlags,kChargeFitOK);
   return kTRUE;
 }
@@ -880,4 +936,28 @@
   fChargeLastLoGain  = fHChargeLoGain->GetBinLowEdge(fHChargeLoGain->GetXaxis()->GetLast())
                       +fHChargeLoGain->GetBinWidth(0);
+
+  CutEdges(fHRelTimeHiGain,nbins);
+
+  fRelTimeLowerFitRangeHiGain = fHRelTimeHiGain->GetBinLowEdge(fHRelTimeHiGain->GetXaxis()->GetFirst());
+  fRelTimeUpperFitRangeHiGain = fHRelTimeHiGain->GetBinLowEdge(fHRelTimeHiGain->GetXaxis()->GetLast())
+                               +fHRelTimeHiGain->GetBinWidth(0);
+
+  CutEdges(fHRelTimeLoGain,nbins);
+
+  fRelTimeLowerFitRangeLoGain = fHRelTimeLoGain->GetBinLowEdge(fHRelTimeLoGain->GetXaxis()->GetFirst());
+  fRelTimeUpperFitRangeLoGain = fHRelTimeLoGain->GetBinLowEdge(fHRelTimeLoGain->GetXaxis()->GetLast())
+                               +fHRelTimeLoGain->GetBinWidth(0);
+
+  CutEdges(fHAbsTimeHiGain,nbins);
+
+  fAbsTimeFirstHiGain = fHAbsTimeHiGain->GetBinLowEdge(fHAbsTimeHiGain->GetXaxis()->GetFirst());
+  fAbsTimeLastHiGain  = fHAbsTimeHiGain->GetBinLowEdge(fHAbsTimeHiGain->GetXaxis()->GetLast())
+                       +fHAbsTimeHiGain->GetBinWidth(0);
+
+  CutEdges(fHAbsTimeLoGain,nbins);
+
+  fAbsTimeFirstLoGain = fHAbsTimeLoGain->GetBinLowEdge(fHAbsTimeLoGain->GetXaxis()->GetFirst());
+  fAbsTimeLastLoGain  = fHAbsTimeLoGain->GetBinLowEdge(fHAbsTimeLoGain->GetXaxis()->GetLast())
+                       +fHAbsTimeLoGain->GetBinWidth(0);
 
   CutEdges(fHChargevsNHiGain,0);
@@ -901,7 +981,7 @@
 
   *fLog << all << "Results of the Time Slices Fit: "                        << endl;
-  *fLog << all << "Chisquare: "   << fTimeChisquare                         << endl;
-  *fLog << all << "Ndf: "         << fTimeNdf                               << endl;
-  *fLog << all << "Probability: " << fTimeProb                              << endl;
+  *fLog << all << "Chisquare: "   << fRelTimeChisquare                      << endl;
+  *fLog << all << "Ndf: "         << fRelTimeNdf                            << endl;
+  *fLog << all << "Probability: " << fRelTimeProb                           << endl;
   *fLog << all                                                              << endl;
 
Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.h	(revision 3006)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.h	(revision 3007)
@@ -18,4 +18,14 @@
 private:
 
+  static const Int_t   fChargeNbinsHiGain;
+  static const Int_t   fChargeNbinsLoGain;
+  static const Int_t   fAbsTimeNbins;
+  static const Int_t   fRelTimeNbins;
+  static const Int_t   fChargevsNbins;
+  static const Axis_t  fAbsTimeFirst;
+  static const Axis_t  fAbsTimeLast;
+  static const Axis_t  fRelTimeFirst;
+  static const Axis_t  fRelTimeLast;
+
   Int_t fPixId;                  // Pixel Nr
 
@@ -23,12 +33,4 @@
   TArrayF *fLoGains;             //->
 
-  const Int_t   fChargeNbinsHiGain;
-  const Int_t   fChargeNbinsLoGain;
-  const Int_t   fTimeNbins;
-  const Int_t   fChargevsNbins;
-
-  const Axis_t  fTimeFirst;
-  const Axis_t  fTimeLast;
-  
   TProfile* fHivsLoGain;
 
@@ -39,9 +41,11 @@
 
   TH1F* fHChargeHiGain;          //-> Summed FADC slices High Gain
-  TH1F* fHTimeHiGain;            //-> Mean arrival time in number of FADC sice
+  TH1F* fHAbsTimeHiGain;         //-> Mean arrival time in number of FADC sice
+  TH1F* fHRelTimeHiGain;         //-> Mean arrival time in number of FADC sice
   TH1I* fHChargevsNHiGain;       //-> Summed Charge vs. Event Nr. 
                           
   TH1F* fHChargeLoGain;          //-> Summed FADC slices Low Gain
-  TH1F* fHTimeLoGain;            //-> Mean arrival time in number of FADC sice
+  TH1F* fHAbsTimeLoGain;         //-> Mean arrival time in number of FADC sice
+  TH1F* fHRelTimeLoGain;         //-> Mean arrival time in number of FADC sice
   TH1I* fHChargevsNLoGain;       //-> Summed Charge vs. Event Nr. 
 
@@ -49,5 +53,5 @@
   
   TF1* fChargeGausFit;
-  TF1* fTimeGausFit;
+  TF1* fRelTimeGausFit;  
   
   TPaveText *fFitLegend;  
@@ -69,19 +73,24 @@
   Double_t fChargeSigmaErr;
   
-  Double_t fTimeChisquare;
-  Double_t fTimeProb;
-  Int_t    fTimeNdf;
+  Double_t fRelTimeChisquare;
+  Double_t fRelTimeProb;
+  Int_t    fRelTimeNdf;
+  Double_t fRelTimeMean;
+  Double_t fRelTimeMeanErr;
+  Double_t fRelTimeSigma;
 
-  Double_t fTimeMean;
-  Double_t fTimeSigma;
+  Float_t   fRelTimeLowerFitRangeHiGain;
+  Float_t   fRelTimeUpperFitRangeHiGain;
+  Float_t   fRelTimeLowerFitRangeLoGain;
+  Float_t   fRelTimeUpperFitRangeLoGain;
 
-  Byte_t   fTimeLowerFitRangeHiGain;
-  Byte_t   fTimeUpperFitRangeHiGain;
-  Byte_t   fTimeLowerFitRangeLoGain;
-  Byte_t   fTimeUpperFitRangeLoGain;
+  Float_t   fAbsTimeFirstHiGain;
+  Float_t   fAbsTimeFirstLoGain;
+  Float_t   fAbsTimeLastHiGain;
+  Float_t   fAbsTimeLastLoGain;
+  
+  Byte_t    fFlags;
 
-  Byte_t   fFlags;
-
-  enum   { kUseLoGain, kFitOK };
+  enum      { kUseLoGain, kChargeFitOK, kTimeFitOK };
   
   virtual void DrawLegend();
@@ -98,58 +107,58 @@
   
   // Setters
-  void   SetUseLoGain(Bool_t b = kTRUE)
-    { b ? SETBIT(fFlags, kUseLoGain) : SETBIT(fFlags, kUseLoGain); }
+  void SetUseLoGain(Bool_t b = kTRUE);
+  
+  // Getters
+  const Double_t GetChargeMean()       const { return fChargeMean;      }
+  const Double_t GetChargeMeanErr()    const { return fChargeMeanErr;   }
+  const Double_t GetChargeSigma()      const { return fChargeSigma;     }
+  const Double_t GetChargeSigmaErr()   const { return fChargeSigmaErr;  }
+  const Double_t GetChargeChiSquare()  const { return fChargeChisquare; }
+  const Double_t GetChargeProb()       const { return fChargeProb;      }  
+  const Int_t    GetChargeNdf()        const { return fChargeNdf;       }   
 
-  void SetTimeFitRangesHiGain(Byte_t low, Byte_t up) { fTimeLowerFitRangeHiGain = low,
-                                               fTimeUpperFitRangeHiGain = up ;  }
-  void SetTimeFitRangesLoGain(Byte_t low, Byte_t up) { fTimeLowerFitRangeLoGain = low,
-                                               fTimeUpperFitRangeLoGain = up ;  }
+  const Float_t  GetAbsTimeFirstHiGain() const { return fAbsTimeFirstHiGain; }
+  const Float_t  GetAbsTimeFirstLoGain() const { return fAbsTimeFirstLoGain; }
+  const Float_t  GetAbsTimeLastHiGain()  const { return fAbsTimeLastHiGain;  }
+  const Float_t  GetAbsTimeLastLoGain()  const { return fAbsTimeLastLoGain;  }
 
-  // Getters
-  const Double_t GetChargeMean()     const { return fChargeMean;    }
-  const Double_t GetChargeMeanErr()  const { return fChargeMeanErr; }
-  const Double_t GetChargeSigma()    const { return fChargeSigma;   }
-  const Double_t GetChargeSigmaErr() const { return fChargeSigmaErr; }
-  const Double_t GetChargeChiSquare() const { return fChargeChisquare; }
-  const Double_t GetChargeProb()      const { return fChargeProb;      }  
-  const Int_t    GetChargeNdf()       const { return fChargeNdf;       }   
+  const Double_t GetRelTimeMean()      const { return fRelTimeMean;     }
+  const Double_t GetRelTimeMeanErr()    const { return fRelTimeMeanErr;     }
+  const Double_t GetRelTimeSigma()     const { return fRelTimeSigma;    }
+  const Double_t GetRelTimeChiSquare() const { return fRelTimeChisquare;}
+  const Double_t GetRelTimeProb()      const { return fRelTimeProb;     }
+  const Int_t    GetRelTimeNdf()       const { return fRelTimeNdf;      }   
 
-  const Double_t GetTimeMean()        const { return fTimeMean;  }
-  const Double_t GetTimeSigma()       const { return fTimeSigma; }
+  const TH1F *GetHCharge()                   { return fHChargeHiGain;   }
+  const TH1F *GetHCharge()             const { return fHChargeHiGain;   } 
 
-  const Byte_t   GetTimeLowerFitRangeHiGain()  const { return fTimeLowerFitRangeHiGain;  }
-  const Byte_t   GetTimeUpperFitRangeHiGain()  const { return fTimeUpperFitRangeHiGain;  }
-  const Byte_t   GetTimeLowerFitRangeLoGain()  const { return fTimeLowerFitRangeLoGain;  }
-  const Byte_t   GetTimeUpperFitRangeLoGain()  const { return fTimeUpperFitRangeLoGain;  }
+  const TH1F *GetHAbsTime()                  { return fHAbsTimeHiGain;  }
+  const TH1F *GetHAbsTime()            const { return fHAbsTimeHiGain;  }
   
-  const Double_t GetTimeChiSquare()     const { return fTimeChisquare; }
-  const Double_t GetTimeProb()        const { return fTimeProb;      }
-  const Int_t    GetTimeNdf()         const { return fTimeNdf;       }   
+  const TH1F *GetHRelTime()                  { return fHRelTimeHiGain;  }
+  const TH1F *GetHRelTime()            const { return fHRelTimeHiGain;  }
   
-  const TH1F *GetHCharge()                  { return fHChargeHiGain;    }
-  const TH1F *GetHCharge()            const { return fHChargeHiGain;    }
+  const TH1I *GetHChargevsN()                { return fHChargevsNHiGain;}
+  const TH1I *GetHChargevsN()          const { return fHChargevsNHiGain;}
 
-  const TH1F *GetHTime()                    { return fHTimeHiGain; }
-  const TH1F *GetHTime()              const { return fHTimeHiGain; }
-  
-  const TH1I *GetHChargevsN()               { return fHChargevsNHiGain; }
-  const TH1I *GetHChargevsN()         const { return fHChargevsNHiGain; }
-
-  Double_t GetOffset()  { return fOffset; }
-  Double_t GetSlope()   { return fSlope;  }
+  Double_t GetOffset()                 const { return fOffset;          }
+  Double_t GetSlope()                  const { return fSlope;           }
 
   Bool_t UseLoGain();
 
-  Bool_t IsFitOK()     const;    
-  Bool_t IsUseLoGain() const;
-  Bool_t IsEmpty()     const;
+  Bool_t IsChargeFitOK()               const;
+  Bool_t IsTimeFitOK()                 const;      
+  Bool_t IsUseLoGain()                 const;
+  Bool_t IsEmpty()                     const;
   
   // Fill histos
   Bool_t FillChargeLoGain(Float_t q);
-  Bool_t FillTimeLoGain(Float_t t);
+  Bool_t FillAbsTimeLoGain(Float_t t);
+  Bool_t FillRelTimeLoGain(Float_t t);
   Bool_t FillChargevsNLoGain(Float_t q, Int_t n);
 
   Bool_t FillChargeHiGain(Float_t q);
-  Bool_t FillTimeHiGain(Float_t t);
+  Bool_t FillAbsTimeHiGain(Float_t t);
+  Bool_t FillRelTimeHiGain(Float_t t);
   Bool_t FillChargevsNHiGain(Float_t q, Int_t n);
 
@@ -161,7 +170,5 @@
   // Fits
   Bool_t FitCharge(Option_t *option="RQ0");  
-
-  Bool_t FitTimeHiGain(Axis_t rmin=0, Axis_t rmax=0, Option_t *option="RQ0");    
-  Bool_t FitTimeLoGain(Axis_t rmin=0, Axis_t rmax=0, Option_t *option="RQ0");    
+  Bool_t FitTime(Option_t *option="RQ0");    
 
   void   FitHiGainvsLoGain();
