Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc	(revision 3007)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc	(revision 3012)
@@ -53,5 +53,5 @@
 const Int_t   MHCalibrationPixel::fChargeNbinsLoGain = 1010;
 const Int_t   MHCalibrationPixel::fAbsTimeNbins      = 32;
-const Int_t   MHCalibrationPixel::fRelTimeNbins      = 240;
+const Int_t   MHCalibrationPixel::fRelTimeNbins      = 480;
 const Int_t   MHCalibrationPixel::fChargevsNbins     = 5000;
 const Axis_t  MHCalibrationPixel::fAbsTimeFirst      = - 0.25;
@@ -59,4 +59,5 @@
 const Axis_t  MHCalibrationPixel::fRelTimeFirst      = -11.;
 const Axis_t  MHCalibrationPixel::fRelTimeLast       =  12.;
+const Float_t MHCalibrationPixel::fProbLimit         = 0.001;
 
 // --------------------------------------------------------------------------
@@ -205,4 +206,7 @@
   fAbsTimeLastLoGain      = -1.;
   
+  fAbsTimeMean            = -1.;
+  fAbsTimeMeanErr         = -1.;
+  fAbsTimeRms             = -1.;
 
   fOffset = 0.;
@@ -324,76 +328,32 @@
   // Names Hi gain Histograms
   //
-  TString nameQHiGain = TString(fHChargeHiGain->GetName());
-  nameQHiGain += id;
-  fHChargeHiGain->SetName(nameQHiGain.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());
-  nameQvsNHiGain += id;
-  fHChargevsNHiGain->SetName(nameQvsNHiGain.Data());
+  fHChargeHiGain->SetName(   Form("%s%d",fHChargeHiGain->GetName(),   id));
+  fHAbsTimeHiGain->SetName(  Form("%s%d",fHAbsTimeHiGain->GetName(),  id));
+  fHRelTimeHiGain->SetName(  Form("%s%d",fHRelTimeHiGain->GetName(),  id));
+  fHChargevsNHiGain->SetName(Form("%s%d",fHChargevsNHiGain->GetName(),id));
 
   //
   // Title Hi gain Histograms
   //
-  TString titleQHiGain = TString(fHChargeHiGain->GetTitle());
-  titleQHiGain += id;
-  fHChargeHiGain->SetTitle(titleQHiGain.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());
-  titleQvsNHiGain += id;
-  fHChargevsNHiGain->SetTitle(titleQvsNHiGain.Data());
+  fHChargeHiGain->SetTitle(    Form("%s%d",fHChargeHiGain->GetTitle(),   id));
+  fHAbsTimeHiGain->SetTitle(   Form("%s%d",fHAbsTimeHiGain->GetTitle(),  id));
+  fHRelTimeHiGain->SetTitle(   Form("%s%d",fHRelTimeHiGain->GetTitle(),  id));
+  fHChargevsNHiGain->SetTitle( Form("%s%d",fHChargevsNHiGain->GetTitle(),id));
 
   //
   // Names Low Gain Histograms
   //
-  TString nameQLoGain = TString(fHChargeLoGain->GetName());
-  nameQLoGain += id;
-  fHChargeLoGain->SetName(nameQLoGain.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());
-  nameQvsNLoGain += id;
-  fHChargevsNLoGain->SetName(nameQvsNLoGain.Data());
+  fHChargeLoGain->SetName( Form("%s%d",fHChargeLoGain->GetName(),id));
+  fHAbsTimeLoGain->SetName( Form("%s%d",fHAbsTimeLoGain->GetName(),id));
+  fHRelTimeLoGain->SetName( Form("%s%d",fHRelTimeLoGain->GetName(),id));
+  fHChargevsNLoGain->SetName( Form("%s%d",fHChargevsNLoGain->GetName(),id));
 
   //
   // Titles Low Gain Histograms
   //
-  TString titleQLoGain = TString(fHChargeLoGain->GetTitle());
-  titleQLoGain += id;
-  fHChargeLoGain->SetTitle(titleQLoGain.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());
-  titleQvsNLoGain += id;
-  fHChargevsNLoGain->SetTitle(titleQvsNLoGain.Data());
+  fHChargeLoGain->SetTitle( Form("%s%d",fHChargeLoGain->GetTitle(),id));
+  fHAbsTimeLoGain->SetTitle( Form("%s%d",fHAbsTimeLoGain->GetTitle(),id));
+  fHRelTimeLoGain->SetTitle( Form("%s%d",fHRelTimeLoGain->GetTitle(),id));
+  fHChargevsNLoGain->SetTitle( Form("%s%d",fHChargevsNLoGain->GetTitle(),id));
 }
 
@@ -528,5 +488,5 @@
   gROOT->SetSelectedPad(NULL);
   
-  TCanvas *c = MakeDefCanvas(this,600,900); 
+  TCanvas *c = MH::MakeDefCanvas(this,600,900); 
   
   c->Divide(2,5);
@@ -537,7 +497,5 @@
 
   if (fHChargeHiGain->Integral() > 0)
-    gPad->SetLogy(1);
-  else
-    gPad->SetLogy(0);
+    gPad->SetLogy();
 
   fHChargeHiGain->Draw(opt);
@@ -553,7 +511,5 @@
 
       if (fHChargeLoGain->Integral() > 0)
-        gPad->SetLogy(1);
-      else
-        gPad->SetLogy(0);
+        gPad->SetLogy();
 
       fHChargeLoGain->Draw(opt);
@@ -561,11 +517,8 @@
       if (fChargeGausFit)
         {
-          if (IsChargeFitOK())
-            fChargeGausFit->SetLineColor(kGreen);          
-          else
-            fChargeGausFit->SetLineColor(kRed);
-          
+          fChargeGausFit->SetLineColor(IsChargeFitOK() ? kGreen : kRed);          
           fChargeGausFit->Draw("same");
         }
+
       c->Modified();
       c->Update();
@@ -587,9 +540,5 @@
       if (fChargeGausFit)
         {
-          if (IsChargeFitOK())
-            fChargeGausFit->SetLineColor(kGreen);          
-          else
-            fChargeGausFit->SetLineColor(kRed);
-          
+          fChargeGausFit->SetLineColor(IsChargeFitOK() ? kGreen : kRed);          
           fChargeGausFit->Draw("same");
         }
@@ -600,6 +549,4 @@
       if (fHChargeLoGain->Integral() > 0)
         gPad->SetLogy(1);
-      else
-        gPad->SetLogy(0);
       
       fHChargeLoGain->Draw(opt);
@@ -644,13 +591,10 @@
 	if (fRelTimeGausFit)
 	  {
-	    if (fRelTimeChisquare > 20.) 
-	      fRelTimeGausFit->SetLineColor(kRed);
-	    else
-	      fRelTimeGausFit->SetLineColor(kGreen);
-	    
+            fRelTimeGausFit->SetLineColor(IsTimeFitOK() ? kGreen : kRed);
 	    fRelTimeGausFit->Draw("same");
-	    c->Modified();
-	    c->Update();
 	  }
+
+        c->Modified();
+        c->Update();
       }
     else
@@ -658,15 +602,12 @@
 	if (fRelTimeGausFit)
 	  {
-	    if (fRelTimeChisquare > 20.) 
-	      fRelTimeGausFit->SetLineColor(kRed);
-	    else
-	      fRelTimeGausFit->SetLineColor(kGreen);
-	    
+            fRelTimeGausFit->SetLineColor(IsTimeFitOK() ? kGreen : kRed);
 	    fRelTimeGausFit->Draw("same");
-	    c->Modified();
-	    c->Update();
 	  }
-
-	c->cd(6);
+        
+        c->Modified();
+        c->Update();
+	
+        c->cd(6);
         gPad->SetTicks();
 	gPad->SetLogy(0);
@@ -747,18 +688,31 @@
 
   //
+  // From the absolute time, we only take the mean and RMS
+  //
+  fAbsTimeMean    = (Float_t)fHAbsTimeHiGain->GetMean();
+  fAbsTimeRms     = (Float_t)fHAbsTimeHiGain->GetRMS();
+  fAbsTimeMeanErr = (Float_t)fAbsTimeRms / TMath::Sqrt(fHAbsTimeHiGain->GetEntries());
+  
+  if (TESTBIT(fFlags,kUseLoGain))
+    {
+      fAbsTimeMean    = fHAbsTimeLoGain->GetMean();
+      fAbsTimeRms     = fHAbsTimeLoGain->GetRMS();
+      fAbsTimeMeanErr = fAbsTimeRms / TMath::Sqrt(fHAbsTimeLoGain->GetEntries());
+    }
+  
+  //
   // Get the fitting ranges
   //
   Axis_t rmin = fRelTimeLowerFitRangeHiGain;
+  Axis_t rmax = fRelTimeUpperFitRangeHiGain;
+  TH1F *hist = fHRelTimeHiGain;
+
   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;
-
+    {
+      rmin = fRelTimeLowerFitRangeLoGain;
+      rmax = fRelTimeUpperFitRangeLoGain;
+      hist = fHRelTimeLoGain;
+    }
+  
   const Stat_t   entries     = hist->Integral("width");
   const Double_t mu_guess    = hist->GetBinCenter(hist->GetMaximumBin());
