Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationCam.cc	(revision 3902)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationCam.cc	(revision 3903)
@@ -66,4 +66,6 @@
 #include "MParList.h"
 
+#include "MRawRunHeader.h"
+
 ClassImp(MHCalibrationCam);
 
@@ -84,9 +86,27 @@
 // - fAverageHiGainSectors, fAverageLoGainSectors
 //
+// Initializes to 0 entries:
+// - fAverageAreaNum           
+// - fAverageAreaRelSigma      
+// - fAverageAreaRelSigmaVar   
+// - fAverageAreaSat           
+// - fAverageAreaSigma         
+// - fAverageAreaSigmaVar 
+// - fAverageSectorNum         
+// - fRunNumbers               
+//
 // Initializes:
 // - fPulserFrequency to fgPulserFrequency
 //
 MHCalibrationCam::MHCalibrationCam(const char *name, const char *title)
-    :  fBadPixels(NULL), fCam(NULL), fGeom(NULL)
+    :    fAverageAreaNum(0),           
+         fAverageAreaRelSigma(0),      
+         fAverageAreaRelSigmaVar(0),   
+         fAverageAreaSat(0),           
+         fAverageAreaSigma(0),         
+         fAverageAreaSigmaVar(0), 
+         fAverageSectorNum(0),         
+         fRunNumbers(0),               
+         fBadPixels(NULL), fCam(NULL), fGeom(NULL), fRunHeader(NULL)
 {
     fName  = name  ? name  : "MHCalibrationCam";
@@ -260,4 +280,10 @@
 {
   return *static_cast<MHGausEvents*>(fAverageLoGainSectors->UncheckedAt(i));
+}
+
+
+const TArrayI &MHCalibrationCam::GetRunNumbers() const 
+{
+  return fRunNumbers;
 }
 
@@ -357,6 +383,14 @@
   if (!fGeom)
   {
-      *fLog << err << "MGeomCam not found... aborting." << endl;
+      *fLog << err << GetDescriptor() 
+            << ": MGeomCam not found... aborting." << endl;
       return kFALSE;
+  }
+
+  fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
+  if (!fRunHeader)
+  {
+    *fLog << warn << GetDescriptor() 
+          << ": MRawRunHeader not found... will not store run numbers." << endl;
   }
 
@@ -410,4 +444,6 @@
 // - MHCalibrationCam::fAverageHiGainSectors
 // 
+// Retrieves the run numbers from MRawRunHeader and stores them in fRunNumbers
+//
 Bool_t MHCalibrationCam::ReInit(MParList *pList)
 {
@@ -441,4 +477,5 @@
   fAverageAreaRelSigmaVar.Set(nareas);
   fAverageSectorNum.      Set(nsectors);
+  fRunNumbers.            Set(fRunNumbers.GetSize()+1);
 
   for (Int_t aidx=0; aidx<nareas; aidx++)
@@ -457,4 +494,7 @@
       fAverageSectorNum[(*fGeom)[i].GetSector()]++;
     }
+
+  if (fRunHeader)
+    fRunNumbers[fRunNumbers.GetSize()-1] = fRunHeader->GetRunNumber();
 
   return ReInitHists(pList);
@@ -578,5 +618,7 @@
   hist.ChangeHistId(i);
   hist.SetEventFrequency(fPulserFrequency);
-          
+
+  TH1F *h = hist.GetHGausHist();
+  h->SetTitle( Form("%s%s", h->GetTitle()," Runs: "));
 }
 
Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationRelTimeCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationRelTimeCam.cc	(revision 3902)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationRelTimeCam.cc	(revision 3903)
@@ -108,7 +108,12 @@
 
 using namespace std;
+
+const UInt_t MHCalibrationRelTimeCam::fgReferencePixel = 1;
 // --------------------------------------------------------------------------
 //
-// Default Constructor. 
+// Default Constructor.
+//
+// Sets: 
+// - fReferencePixel to fgReferencePixel
 //
 MHCalibrationRelTimeCam::MHCalibrationRelTimeCam(const char *name, const char *title) 
@@ -117,5 +122,6 @@
   fName  = name  ? name  : "MHCalibrationRelTimeCam";
   fTitle = title ? title : "Histogram class for the relative time calibration of the camera";
-  
+
+  SetReferencePixel();
 }
 
@@ -183,9 +189,16 @@
       {
 	  (*fHiGainArray)[i] = new MHCalibrationRelTimePix("MHCalibrationRelTimePixHiGain",
-                                                          "Relative Arrival Time High Gain Pixel");
+                                                          "Rel. Arr. Time Hi-Gain Pixel ");
           InitHists((*this)[i],(*fBadPixels)[i],i);
       }
   }
-
+  
+  if (fRunHeader)
+    for (Int_t i=0; i<npixels; i++)
+      {
+        TH1F *h = (*this)[i].GetHGausHist();
+          h->SetTitle( Form("%s%i%s", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]," "));
+      }
+  
   if (fLoGainArray->GetEntries()==0)
   {
@@ -194,8 +207,15 @@
       {
 	  (*fLoGainArray)[i] = new MHCalibrationRelTimePix("MHCalibrationRelTimePixLoGain",
-                                                          "Relative Arrival Time Low Gain Pixel");
+                                                          "Rel. Arr. Time Lo-Gain Pixel ");
           InitHists((*this)(i),(*fBadPixels)[i],i);
       }
   }
+
+  if (fRunHeader)
+    for (Int_t i=0; i<npixels; i++)
+      {
+        TH1F *h = (*this)(i).GetHGausHist();
+        h->SetTitle( Form("%s%i%s", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]," "));
+      }
 
   if (fAverageHiGainAreas->GetEntries()==0)
@@ -207,5 +227,5 @@
         (*fAverageHiGainAreas)[j] = 
           new MHCalibrationRelTimePix("MHCalibrationRelTimeAverageAreaHiGain",
-                                      "Average Relative Arrival Times High Gain Area Idx ");
+                                      "Average Rel. Arr. Times Hi-Gain Area Idx ");
 
         GetAverageHiGainArea(j).GetHGausHist()->SetTitle("Rel. Arr. Times HiGain Area Idx ");
@@ -216,4 +236,11 @@
   }
 
+  if (fRunHeader)
+    for (Int_t j=0; j<nareas; j++)
+      {
+        TH1F *h = GetAverageHiGainArea(j).GetHGausHist();
+        h->SetTitle( Form("%s%i%s", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]," "));
+      }
+  
   if (fAverageLoGainAreas->GetEntries()==0)
   {
@@ -224,5 +251,5 @@
         (*fAverageLoGainAreas)[j] = 
           new MHCalibrationRelTimePix("MHCalibrationRelTimeAverageAreaLoGain",
-                                      "Average Relative Arrival Times Low Gain Area Idx ");
+                                      "Average Rel. Arr. Times Lo-Gain Area Idx ");
 
         GetAverageLoGainArea(j).GetHGausHist()->SetTitle("Rel. Arr. Times LoGain Area Idx ");
@@ -232,40 +259,61 @@
       }
   }
-
+  
+  if (fRunHeader)
+    for (Int_t j=0; j<nareas; j++)
+        {
+          TH1F *h = GetAverageLoGainArea(j).GetHGausHist();
+          h->SetTitle( Form("%s%i%s", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]," "));
+        }
+  
   if (fAverageHiGainSectors->GetEntries()==0)
-  {
+    {
       fAverageHiGainSectors->Expand(nsectors);
 
       for (Int_t j=0; j<nsectors; j++)
-      {
+        {
 	  (*fAverageHiGainSectors)[j] = 
             new MHCalibrationRelTimePix("MHCalibrationRelTimeAverageSectorHiGain",
-                                        "Average Relative Arrival Times High Gain Sector ");
-
+                                        "Average Rel. Arr. Times Hi-Gain Sector ");
+          
           GetAverageHiGainSector(j).GetHGausHist()->SetTitle("Rel. Arr. Times HiGain Sector ");
           GetAverageHiGainSector(j).SetNbins(fAverageNbins);
-
+          
           InitHists(GetAverageHiGainSector(j),fCam->GetAverageBadSector(j),j);
       }
   }
+  
+  if (fRunHeader)
+    for (Int_t j=0; j<nsectors; j++)
+      {
+        TH1F *h = GetAverageHiGainSector(j).GetHGausHist();
+        h->SetTitle( Form("%s%i%s", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]," "));
+      }
 
   if (fAverageLoGainSectors->GetEntries()==0)
-  {
+    {
       fAverageLoGainSectors->Expand(nsectors);
-
+      
       for (Int_t j=0; j<nsectors; j++)
-      {
+        {
 	  (*fAverageLoGainSectors)[j] = 
             new MHCalibrationRelTimePix("MHCalibrationRelTimeAverageSectorLoGain",
-                                        "Average Relative Arrival Times Low Gain Sector ");
-
+                                        "Average Rel. Arr. Times Lo-Gain Sector ");
+          
           GetAverageLoGainSector(j).GetHGausHist()->SetTitle("Rel. Arr. Times LoGain Sector ");
           GetAverageLoGainSector(j).SetNbins(fAverageNbins);
-
+          
           InitHists(GetAverageLoGainSector(j),fCam->GetAverageBadSector(j),j);
           
-      }
-  }
-
+        }
+    }
+
+  if (fRunHeader)
+    for (Int_t j=0; j<nsectors; j++)
+      {
+        TH1F *h = GetAverageLoGainSector(j).GetHGausHist();
+        h->SetTitle( Form("%s%i%s", h->GetTitle(),fRunNumbers[fRunNumbers.GetSize()-1]," "));
+      }
+  
   return kTRUE;
 }
@@ -309,6 +357,10 @@
   memset(sumsectorhi, 0, nsectors*sizeof(Float_t));
   memset(sumsectorlo, 0, nsectors*sizeof(Float_t));
-  
-  const MArrivalTimePix &refpix = (*arrtime)[1];
+  memset(numareahi,   0, nareas * sizeof(Float_t));
+  memset(numarealo,   0, nareas * sizeof(Float_t));
+  memset(numsectorhi, 0, nsectors*sizeof(Float_t));
+  memset(numsectorlo, 0, nsectors*sizeof(Float_t));
+  
+  const MArrivalTimePix &refpix = (*arrtime)[fReferencePixel];
   const Float_t reftime = refpix.IsLoGainUsed() 
     ? refpix.GetArrivalTimeLoGain() : refpix.GetArrivalTimeHiGain();
@@ -324,8 +376,4 @@
 
       const MArrivalTimePix &pix = (*arrtime)[i];
-      const Float_t time    = pix.IsLoGainUsed() 
-        ? pix.GetArrivalTimeLoGain() : pix.GetArrivalTimeHiGain();  
-      const Float_t reltime = time - reftime;
-      
       const Int_t aidx   = (*fGeom)[i].GetAidx();
       const Int_t sector = (*fGeom)[i].GetSector();
@@ -333,5 +381,5 @@
       if (pix.IsLoGainUsed())
         { 
-
+          const Float_t reltime = pix.GetArrivalTimeLoGain() - reftime;
           histlo.FillHistAndArray(reltime);
           sumarealo  [aidx]   += reltime;
@@ -342,5 +390,5 @@
       else
         {
-
+          const Float_t reltime = pix.GetArrivalTimeHiGain() - reftime;
           histhi.FillHistAndArray(reltime) ;
           sumareahi  [aidx]   += reltime;
Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationRelTimeCam.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationRelTimeCam.h	(revision 3902)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationRelTimeCam.h	(revision 3903)
@@ -12,4 +12,7 @@
 private:
 
+  static const UInt_t fgReferencePixel;             // Default for fReferencePixel (now set to: 1)
+  UInt_t fReferencePixel;                          // The reference pixel for rel. times
+
   Bool_t ReInitHists(MParList *pList);
   Bool_t FillHists(const MParContainer *par, const Stat_t w=1);
@@ -22,4 +25,8 @@
   ~MHCalibrationRelTimeCam() {}
 
+  UInt_t GetReferencePixel() const   { return fReferencePixel; }
+  void   SetReferencePixel(const UInt_t i=fgReferencePixel)   {  fReferencePixel = i; }
+  
+  
   Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
   void DrawPixelContent(Int_t idx) const;
