Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationCam.cc	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationCam.cc	(revision 5137)
@@ -26,5 +26,5 @@
 // MHCalibrationCam                                               
 //
-// Base class for camera calibration classes. Incorporates the TObjArray's:
+// Base class for camera calibration classes. Incorporates the TOrdCollection's:
 // - fHiGainArray (for calibrated High Gains per pixel)
 // - fLoGainArray (for calibrated Low Gains per pixel) 
@@ -33,5 +33,5 @@
 // - fAverageHiGainSectors (for averaged High Gains events per camera sector )
 // - fAverageLoGainSectors (for averaged High Gains events per camera sector )
-// These TObjArray's are called by their default constructors, thus no objects 
+// These TOrdCollection's are called by their default constructors, thus no objects 
 // are created, until the derived class does so. 
 //
@@ -61,4 +61,6 @@
 #include <TText.h>
 #include <TPaveText.h>
+#include <TOrdCollection.h>
+#include <TROOT.h>
 
 #include "MLog.h"
@@ -117,20 +119,20 @@
 {
 
-    fHiGainArray = new TObjArray;
+    fHiGainArray = new TOrdCollection;
     fHiGainArray->SetOwner();
-    
-    fLoGainArray = new TObjArray;
+
+    fLoGainArray = new TOrdCollection;
     fLoGainArray->SetOwner();
 
-    fAverageHiGainAreas = new TObjArray;
+    fAverageHiGainAreas = new TOrdCollection;
     fAverageHiGainAreas->SetOwner();
 
-    fAverageLoGainAreas = new TObjArray;
+    fAverageLoGainAreas = new TOrdCollection;
     fAverageLoGainAreas->SetOwner();
 
-    fAverageHiGainSectors = new TObjArray;
+    fAverageHiGainSectors = new TOrdCollection;
     fAverageHiGainSectors->SetOwner();
 
-    fAverageLoGainSectors = new TObjArray;
+    fAverageLoGainSectors = new TOrdCollection;
     fAverageLoGainSectors->SetOwner();
 
@@ -146,14 +148,5 @@
 // --------------------------------------------------------------------------
 //
-// Returns size of fHiGainArray
-//
-const Int_t MHCalibrationCam::GetSize() const
-{
-  return fHiGainArray->GetSize();
-}
-
-// --------------------------------------------------------------------------
-//
-// Deletes the TClonesArray of:
+// Deletes the TOrdCollection of:
 // - fHiGainArray, fLoGainArray
 // - fAverageHiGainAreas, fAverageLoGainAreas
@@ -171,7 +164,181 @@
   delete fAverageHiGainSectors;
   delete fAverageLoGainSectors;
-}
-
-// --------------------------------------------------------------------------
+  /*
+
+  Remove ( fHiGainArray );
+  Remove ( fLoGainArray );
+
+  Remove ( fAverageHiGainAreas );
+  Remove ( fAverageLoGainAreas );
+
+  Remove ( fAverageHiGainSectors );
+  Remove ( fAverageLoGainSectors );
+  */
+
+}
+
+void MHCalibrationCam::Remove(TOrdCollection *col)
+{
+
+  if (!col)
+    return;
+
+  TOrdCollectionIter Next(col);
+  
+  Int_t count = 0;
+
+  while (MHCalibrationPix *obj = (MHCalibrationPix*)Next())
+    {
+      *fLog << ++count << " " << obj << flush;
+      if (obj && obj->IsOnHeap())
+        {
+          obj->Draw();
+          delete obj;
+        }
+    }
+  
+  delete col;
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns size of fHiGainArray
+//
+const Int_t MHCalibrationCam::GetSize() const
+{
+  return fHiGainArray->GetSize();
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th High Gain pixel (pixel number)
+//
+MHCalibrationPix &MHCalibrationCam::operator[](UInt_t i)
+{
+  return *static_cast<MHCalibrationPix*>(fHiGainArray->At(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th High Gain pixel (pixel number)
+//
+const MHCalibrationPix &MHCalibrationCam::operator[](UInt_t i) const
+{
+  return *static_cast<MHCalibrationPix*>(fHiGainArray->At(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th Low Gain pixel (pixel number)
+//
+MHCalibrationPix  &MHCalibrationCam::operator()(UInt_t i)
+{
+  return *static_cast<MHCalibrationPix*>(fLoGainArray->At(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th Low Gain pixel (pixel number)
+//
+const MHCalibrationPix  &MHCalibrationCam::operator()(UInt_t i) const
+{
+  return *static_cast<MHCalibrationPix*>(fLoGainArray->At(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the current size of the TOrdCollection fAverageHiGainAreas
+// independently if the MHCalibrationPix is filled with values or not.
+//
+const Int_t MHCalibrationCam::GetAverageAreas() const
+{
+  return fAverageHiGainAreas->GetSize();
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th High Gain pixel Area (area number)
+//
+MHCalibrationPix  &MHCalibrationCam::GetAverageHiGainArea(UInt_t i)
+{
+  return *static_cast<MHCalibrationPix*>(fAverageHiGainAreas->At(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th High Gain pixel Area (area number)
+//
+const MHCalibrationPix  &MHCalibrationCam::GetAverageHiGainArea(UInt_t i) const
+{
+  return *static_cast<MHCalibrationPix *>(fAverageHiGainAreas->At(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th Low Gain pixel Area (area number)
+//
+MHCalibrationPix  &MHCalibrationCam::GetAverageLoGainArea(UInt_t i)
+{
+  return *static_cast<MHCalibrationPix*>(fAverageLoGainAreas->At(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th Low Gain pixel Area (area number)
+//
+const MHCalibrationPix  &MHCalibrationCam::GetAverageLoGainArea(UInt_t i) const
+{
+  return *static_cast<MHCalibrationPix*>(fAverageLoGainAreas->At(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the current size of the TOrdCollection fAverageHiGainSectors
+// independently if the MHCalibrationPix is filled with values or not.
+//
+const Int_t MHCalibrationCam::GetAverageSectors() const
+{
+  return fAverageHiGainSectors->GetSize();
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th High Gain Sector (sector number)
+//
+MHCalibrationPix  &MHCalibrationCam::GetAverageHiGainSector(UInt_t i)
+{
+  return *static_cast<MHCalibrationPix*>(fAverageHiGainSectors->At(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th High Gain Sector (sector number)
+//
+const MHCalibrationPix  &MHCalibrationCam::GetAverageHiGainSector(UInt_t i) const
+{
+  return *static_cast<MHCalibrationPix*>(fAverageHiGainSectors->At(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th Low Gain Sector (sector number)
+//
+MHCalibrationPix  &MHCalibrationCam::GetAverageLoGainSector(UInt_t i)
+{
+  return *static_cast<MHCalibrationPix*>(fAverageLoGainSectors->At(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th Low Gain Sector (sector number)
+//
+const MHCalibrationPix  &MHCalibrationCam::GetAverageLoGainSector(UInt_t i) const
+{
+  return *static_cast<MHCalibrationPix*>(fAverageLoGainSectors->At(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Calls ResetHistTitles()
 //
 // Calls Reset() for each entry in:
@@ -183,6 +350,9 @@
 {
   
+  ResetHistTitles();
+
   if (fHiGainArray)
     { fHiGainArray->ForEach(MHCalibrationPix,Reset)();  }
+
   if (IsAverageing())
     {
@@ -209,128 +379,100 @@
 // --------------------------------------------------------------------------
 //
-// Get i-th High Gain pixel (pixel number)
-//
-MHCalibrationPix &MHCalibrationCam::operator[](UInt_t i)
-{
-  return *static_cast<MHCalibrationPix*>(fHiGainArray->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th High Gain pixel (pixel number)
-//
-const MHCalibrationPix &MHCalibrationCam::operator[](UInt_t i) const
-{
-  return *static_cast<MHCalibrationPix*>(fHiGainArray->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th Low Gain pixel (pixel number)
-//
-MHCalibrationPix  &MHCalibrationCam::operator()(UInt_t i)
-{
-  return *static_cast<MHCalibrationPix*>(fLoGainArray->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th Low Gain pixel (pixel number)
-//
-const MHCalibrationPix  &MHCalibrationCam::operator()(UInt_t i) const
-{
-  return *static_cast<MHCalibrationPix*>(fLoGainArray->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Returns the current size of the TObjArray fAverageHiGainAreas
-// independently if the MHCalibrationPix is filled with values or not.
-//
-const Int_t MHCalibrationCam::GetAverageAreas() const
-{
-  return fAverageHiGainAreas->GetEntries();
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th High Gain pixel Area (area number)
-//
-MHCalibrationPix  &MHCalibrationCam::GetAverageHiGainArea(UInt_t i)
-{
-  return *static_cast<MHCalibrationPix*>(fAverageHiGainAreas->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th High Gain pixel Area (area number)
-//
-const MHCalibrationPix  &MHCalibrationCam::GetAverageHiGainArea(UInt_t i) const
-{
-  return *static_cast<MHCalibrationPix *>(fAverageHiGainAreas->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th Low Gain pixel Area (area number)
-//
-MHCalibrationPix  &MHCalibrationCam::GetAverageLoGainArea(UInt_t i)
-{
-  return *static_cast<MHCalibrationPix*>(fAverageLoGainAreas->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th Low Gain pixel Area (area number)
-//
-const MHCalibrationPix  &MHCalibrationCam::GetAverageLoGainArea(UInt_t i) const
-{
-  return *static_cast<MHCalibrationPix*>(fAverageLoGainAreas->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Returns the current size of the TObjArray fAverageHiGainSectors
-// independently if the MHCalibrationPix is filled with values or not.
-//
-const Int_t MHCalibrationCam::GetAverageSectors() const
-{
-  return fAverageHiGainSectors->GetEntries();
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th High Gain Sector (sector number)
-//
-MHCalibrationPix  &MHCalibrationCam::GetAverageHiGainSector(UInt_t i)
-{
-  return *static_cast<MHCalibrationPix*>(fAverageHiGainSectors->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th High Gain Sector (sector number)
-//
-const MHCalibrationPix  &MHCalibrationCam::GetAverageHiGainSector(UInt_t i) const
-{
-  return *static_cast<MHCalibrationPix*>(fAverageHiGainSectors->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th Low Gain Sector (sector number)
-//
-MHCalibrationPix  &MHCalibrationCam::GetAverageLoGainSector(UInt_t i)
-{
-  return *static_cast<MHCalibrationPix*>(fAverageLoGainSectors->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th Low Gain Sector (sector number)
-//
-const MHCalibrationPix  &MHCalibrationCam::GetAverageLoGainSector(UInt_t i) const
-{
-  return *static_cast<MHCalibrationPix*>(fAverageLoGainSectors->UncheckedAt(i));
+// Resets the histogram titles for each entry in:
+// - fHiGainArray, fLoGainArray
+// - fAverageHiGainAreas, fAverageLoGainAreas
+// - fAverageHiGainSectors, fAverageLoGainSectors
+//
+void MHCalibrationCam::ResetHistTitles()
+{
+  
+  TH1F *h;
+
+  if (fHiGainArray)
+    for (Int_t i=0;i<fHiGainArray->GetSize(); i++)
+      {
+        MHCalibrationPix &pix = (*this)[i];        
+        h = pix.GetHGausHist();
+        h->SetName (Form("%s%s%s%4i","H",fHistName.Data(),"HiGainPix",i));
+        h->SetTitle(Form("%s%s%4i%s",fHistTitle.Data()," High Gain Pixel ",i," Runs: "));  
+        h->SetXTitle(fHistXTitle.Data());
+        h->SetYTitle(fHistYTitle.Data());
+      }
+  
+  if (IsAverageing())
+    {
+      if (fAverageHiGainAreas)
+        for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
+          {
+            MHCalibrationPix &pix = GetAverageHiGainArea(j);        
+            h = pix.GetHGausHist();
+            h->SetName (Form("%s%s%s%d","H",fHistName.Data(),"HiGainArea",j));
+            h->SetXTitle(fHistXTitle.Data());
+            h->SetYTitle(fHistYTitle.Data());
+            if (fGeom->InheritsFrom("MGeomCamMagic"))
+              h->SetTitle(Form("%s%s%s%s",fHistTitle.Data()," averaged on event-by-event basis ",
+                               j==0 ? "Inner Pixels " : "Outer Pixels ","High Gain Runs: "));
+            else
+              h->SetTitle(Form("%s%s%d%s",fHistTitle.Data(),
+                               " averaged on event-by-event basis High Gain Area Idx ",j," Runs: "));
+          }
+      
+      if (fAverageHiGainSectors)
+        for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
+          {
+            MHCalibrationPix &pix = GetAverageHiGainSector(j);        
+            h = pix.GetHGausHist();
+            h->SetName (Form("%s%s%s%2i","H",fHistName.Data(),"HiGainSector",j));
+            h->SetTitle(Form("%s%s%2i%s",fHistTitle.Data(),
+                             " averaged on event-by-event basis High Gain Sector ",j," Runs: "));
+            h->SetXTitle(fHistXTitle.Data());
+            h->SetYTitle(fHistYTitle.Data());
+          }
+    }
+  
+  if (!IsLoGain())
+    return;
+  
+  if (fLoGainArray)
+    for (Int_t i=0;i<fLoGainArray->GetSize(); i++)
+      {
+        MHCalibrationPix &pix = (*this)(i);        
+        h = pix.GetHGausHist();
+        h->SetName (Form("%s%s%s%4i","H",fHistName.Data(),"LoGainPix",i));
+        h->SetTitle(Form("%s%s%4i%s",fHistTitle.Data()," Low Gain Pixel ",i," Runs: "));  
+        h->SetXTitle(fHistXTitle.Data());
+        h->SetYTitle(fHistYTitle.Data());
+      }
+  
+  if (IsAverageing())
+    {
+      if (fAverageLoGainAreas)
+        for (Int_t j=0; j<fAverageLoGainAreas->GetSize(); j++)
+          {
+            MHCalibrationPix &pix = GetAverageLoGainArea(j);        
+            h = pix.GetHGausHist();
+            h->SetName (Form("%s%s%s%d","H",fHistName.Data(),"LoGainArea",j));
+            h->SetXTitle(fHistXTitle.Data());
+            h->SetYTitle(fHistYTitle.Data());
+            if (fGeom->InheritsFrom("MGeomCamMagic"))
+              h->SetTitle(Form("%s%s%s%s",fHistTitle.Data()," averaged on event-by-event basis ",
+                               j==0 ? "Inner Pixels " : "Outer Pixels ","Low Gain Runs: "));
+            else
+              h->SetTitle(Form("%s%s%d%s",fHistTitle.Data(),
+                               " averaged on event-by-event basis Low Gain Area Idx ",j," Runs: "));
+          }
+      
+      if (fAverageLoGainSectors)
+        for (Int_t j=0; j<fAverageLoGainSectors->GetSize(); j++)
+          {
+            MHCalibrationPix &pix = GetAverageLoGainSector(j);        
+            h = pix.GetHGausHist();
+            h->SetName (Form("%s%s%s%2i","H",fHistName.Data(),"LoGainSector",j));
+            h->SetTitle(Form("%s%s%2i%s",fHistTitle.Data(),
+                             " averaged on event-by-event basis Low Gain Sector ",j," Runs: "));
+            h->SetXTitle(fHistXTitle.Data());
+            h->SetYTitle(fHistYTitle.Data());
+          }
+    }
 }
 
@@ -381,4 +523,6 @@
 
 // --------------------------------------------------------------------------
+//
+// Searches MRawEvtHeader to find the correct pulser colour
 //
 // Gets or creates the pointers to:
@@ -487,8 +631,10 @@
     return kFALSE;
 
+  ResetHistTitles();
+
   if (!fRunHeader)
     return kTRUE;
   
-  for (Int_t i=0; i<fHiGainArray->GetEntries(); i++)
+  for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
     {
       TH1F *h = (*this)[i].GetHGausHist();
@@ -497,5 +643,5 @@
 
   if (IsLoGain())
-    for (Int_t i=0; i<fLoGainArray->GetEntries(); i++)
+    for (Int_t i=0; i<fLoGainArray->GetSize(); i++)
       {
         TH1F *h = (*this)(i).GetHGausHist();
@@ -538,8 +684,4 @@
 //
 // Initializes the High Gain Arrays:
-//
-// - Expand fHiGainArrays to npixels
-// - Expand fAverageHiGainAreas to nareas
-// - Expand fAverageHiGainSectors to nsectors
 // 
 // - For every entry in the expanded arrays: 
@@ -553,11 +695,10 @@
 {
 
-  if (fHiGainArray->GetEntries()==0)
+  if (fHiGainArray->GetSize()==0)
   {
-      fHiGainArray->Expand(npixels);
       for (Int_t i=0; i<npixels; i++)
       {
-        (*fHiGainArray)[i] = new MHCalibrationPix(Form("%s%s",fHistName.Data(),"HiGainPix"),
-                                                  Form("%s%s",fHistTitle.Data()," High Gain Pixel"));
+        fHiGainArray->AddAt(new MHCalibrationPix(Form("%s%s",fHistName.Data(),"HiGainPix"),
+                                                 Form("%s%s",fHistTitle.Data()," High Gain Pixel")),i);
         
         MHCalibrationPix &pix = (*this)[i];          
@@ -566,11 +707,4 @@
         pix.SetLast (fLast);
         
-        TH1F *h =  pix.GetHGausHist();
-        
-        h->SetName (Form("%s%s%s","H",fHistName.Data(),"HiGainPix"));
-        h->SetTitle(Form("%s%s",fHistTitle.Data()," High Gain Pixel "));  
-        h->SetXTitle(fHistXTitle.Data());
-        h->SetYTitle(fHistYTitle.Data());
-        
         MBadPixelsPix &bad = fIntensBad ? (*fIntensBad)[i] : (*fBadPixels)[i];
         InitHists(pix,bad,i);
@@ -581,12 +715,10 @@
     return;
 
-  if (fAverageHiGainAreas->GetEntries()==0)
+  if (fAverageHiGainAreas->GetSize()==0)
   {
-    fAverageHiGainAreas->Expand(nareas);
-    
     for (Int_t j=0; j<nareas; j++)
       {
-        (*fAverageHiGainAreas)[j] = new MHCalibrationPix(Form("%s%s",fHistName.Data(),"HiGainArea"),
-                                                         Form("%s%s",fHistTitle.Data()," High Gain Area Idx "));
+        fAverageHiGainAreas->AddAt(new MHCalibrationPix(Form("%s%s",fHistName.Data(),"HiGainArea"),
+                                                        Form("%s%s",fHistTitle.Data()," High Gain Area Idx ")),j);
         
         MHCalibrationPix &pix = GetAverageHiGainArea(j);
@@ -595,34 +727,21 @@
         pix.SetFirst(fFirst);
         pix.SetLast (fLast);
-        
-        TH1F *h =  pix.GetHGausHist();
-
-        h->SetName (Form("%s%s%s","H",fHistName.Data(),"HiGainArea"));
-        h->SetXTitle(fHistXTitle.Data());
-        h->SetYTitle(fHistYTitle.Data());
 
         if (fGeom && fGeom->InheritsFrom("MGeomCamMagic"))
           {
-            h->SetTitle(Form("%s%s%s%s",fHistTitle.Data()," averaged on event-by-event basis ",
-                             j==0 ? "Inner Pixels " : "Outer Pixels ","High Gain Runs: "));
             pix.InitBins();
             pix.SetEventFrequency(fPulserFrequency);
           }
         else
-          {
-            h->SetTitle(Form("%s%s",fHistTitle.Data()," averaged on event-by-event basis High Gain Area Idx ")); 
-            InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
-          }
+          InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
       }
   }
 
-  if (fAverageHiGainSectors->GetEntries()==0)
-    {
-      fAverageHiGainSectors->Expand(nsectors);
-
+  if (fAverageHiGainSectors->GetSize()==0)
+    {
       for (Int_t j=0; j<nsectors; j++)
         {
-          (*fAverageHiGainSectors)[j] = new MHCalibrationPix(Form("%s%s",fHistName.Data(),"HiGainSector"),
-                                                             Form("%s%s",fHistTitle.Data()," High Gain Sector "));
+          fAverageHiGainSectors->AddAt(new MHCalibrationPix(Form("%s%s",fHistName.Data(),"HiGainSector"),
+                                                            Form("%s%s",fHistTitle.Data()," High Gain Sector ")),j);
           MHCalibrationPix &pix = GetAverageHiGainSector(j);
 
@@ -631,11 +750,4 @@
           pix.SetLast (fLast);
           
-          TH1F *h =  pix.GetHGausHist();
-
-          h->SetName (Form("%s%s%s","H",fHistName.Data(),"HiGainSector"));
-          h->SetTitle(Form("%s%s",fHistTitle.Data()," High Gain Sector "));  
-          h->SetXTitle(fHistXTitle.Data());
-          h->SetYTitle(fHistYTitle.Data());
-
           InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadSector(j) : fCam->GetAverageBadSector(j),j);
       }
@@ -649,8 +761,4 @@
 // Initializes the Low Gain Arrays:
 //
-// - Expand fLoGainArrays to npixels
-// - Expand fAverageLoGainAreas to nareas
-// - Expand fAverageLoGainSectors to nsectors
-// 
 // - For every entry in the expanded arrays: 
 //   * Initialize an MHCalibrationPix
@@ -666,11 +774,10 @@
     return;
 
-  if (fLoGainArray->GetEntries()==0)
+  if (fLoGainArray->GetSize()==0)
   {
-      fLoGainArray->Expand(npixels);
       for (Int_t i=0; i<npixels; i++)
       {
-        (*fLoGainArray)[i] = new MHCalibrationPix(Form("%s%s",fHistName.Data(),"LoGainPix"),
-                                                  Form("%s%s",fHistTitle.Data()," Low Gain Pixel"));
+        fLoGainArray->AddAt(new MHCalibrationPix(Form("%s%s",fHistName.Data(),"LoGainPix"),
+                                                 Form("%s%s",fHistTitle.Data()," Low Gain Pixel")),i);
 
           MHCalibrationPix &pix = (*this)[i];          
@@ -679,11 +786,4 @@
           pix.SetLast (fLast);
 
-          TH1F *h =  pix.GetHGausHist();
-          
-          h->SetName (Form("%s%s%s","H",fHistName.Data(),"LoGainPix"));
-          h->SetTitle(Form("%s%s",fHistTitle.Data()," Low Gain Pixel "));  
-          h->SetXTitle(fHistXTitle.Data());
-          h->SetYTitle(fHistYTitle.Data());
-
           MBadPixelsPix &bad = fIntensBad ? (*fIntensBad)[i] : (*fBadPixels)[i];
           InitHists(pix,bad,i);
@@ -694,12 +794,10 @@
     return;
 
-  if (fAverageLoGainAreas->GetEntries()==0)
+  if (fAverageLoGainAreas->GetSize()==0)
   {
-    fAverageLoGainAreas->Expand(nareas);
-    
     for (Int_t j=0; j<nareas; j++)
       {
-        (*fAverageLoGainAreas)[j] = new MHCalibrationPix(Form("%s%s",fHistName.Data(),"LoGainArea"),
-                                                         Form("%s%s",fHistTitle.Data()," Low Gain Area Idx "));
+        fAverageLoGainAreas->AddAt(new MHCalibrationPix(Form("%s%s",fHistName.Data(),"LoGainArea"),
+                                                        Form("%s%s",fHistTitle.Data()," Low Gain Area Idx ")),j);
         
         MHCalibrationPix &pix = GetAverageLoGainArea(j);
@@ -709,33 +807,20 @@
         pix.SetLast (fLast);
         
-        TH1F *h =  pix.GetHGausHist();
-
-        h->SetName (Form("%s%s%s","H",fHistName.Data(),"LoGainArea"));
-        h->SetXTitle(fHistXTitle.Data());
-        h->SetYTitle(fHistYTitle.Data());
-
         if (fGeom && fGeom->InheritsFrom("MGeomCamMagic"))
           {
-            h->SetTitle(Form("%s%s%s%s",fHistTitle.Data()," averaged on event-by-event basis ",
-                             j==0 ? "Inner Pixels " : "Outer Pixels ","Low Gain Runs: "));
             pix.InitBins();
             pix.SetEventFrequency(fPulserFrequency);
           }
         else
-          {
-            h->SetTitle(Form("%s%s",fHistTitle.Data()," averaged on event-by-event basis Low Gain Area Idx ")); 
-            InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
-          }
+          InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
       }
   }
 
-  if (fAverageLoGainSectors->GetEntries()==0)
-    {
-      fAverageLoGainSectors->Expand(nsectors);
-
+  if (fAverageLoGainSectors->GetSize()==0)
+    {
       for (Int_t j=0; j<nsectors; j++)
         {
-          (*fAverageLoGainSectors)[j] = new MHCalibrationPix(Form("%s%s",fHistName.Data(),"LoGainSector"),
-                                                             Form("%s%s",fHistTitle.Data()," Low Gain Sector "));
+          fAverageLoGainSectors->AddAt(new MHCalibrationPix(Form("%s%s",fHistName.Data(),"LoGainSector"),
+                                                            Form("%s%s",fHistTitle.Data()," Low Gain Sector ")),j);
           MHCalibrationPix &pix = GetAverageLoGainSector(j);
 
@@ -744,11 +829,4 @@
           pix.SetLast (fLast);
           
-          TH1F *h =  pix.GetHGausHist();
-
-          h->SetName (Form("%s%s%s","H",fHistName.Data(),"LoGainSector"));
-          h->SetTitle(Form("%s%s",fHistTitle.Data()," Low Gain Sector "));  
-          h->SetXTitle(fHistXTitle.Data());
-          h->SetYTitle(fHistYTitle.Data());
-
           InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadSector(j) : fCam->GetAverageBadSector(j),j);
       }
@@ -763,5 +841,5 @@
 // - number of sectors
 //
-// Return kFALSE, if sizes of the TObjArrays do not match npixels, nareas or nsectors
+// Return kFALSE, if sizes of the TOrdCollections do not match npixels, nareas or nsectors
 // 
 // Call FillHists()
@@ -778,7 +856,7 @@
   
   //
-  // Hi-Gain ObjArrays
+  // Hi-Gain OrdCollections
   //
-  if (fHiGainArray->GetEntries() != npixels)
+  if (fHiGainArray->GetSize() != npixels)
     {
       *fLog << err << "ERROR - Size mismatch in number of pixels... abort." << endl;
@@ -788,5 +866,5 @@
   if (IsLoGain())
     {
-      if (fLoGainArray->GetEntries() != npixels)
+      if (fLoGainArray->GetSize() != npixels)
         {
           *fLog << err << "ERROR - Size mismatch in number of pixels... abort." << endl;
@@ -798,5 +876,5 @@
     return FillHists(par,w);
 
-  if (fAverageHiGainAreas->GetEntries() != nareas)
+  if (fAverageHiGainAreas->GetSize() != nareas)
     {
       *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl;
@@ -804,5 +882,5 @@
     }
   
-  if (fAverageHiGainSectors->GetEntries() != nsectors)
+  if (fAverageHiGainSectors->GetSize() != nsectors)
     {
       *fLog << err << "ERROR - Size mismatch in number of sectors ... abort." << endl;
@@ -813,5 +891,5 @@
     {
       
-      if (fAverageLoGainAreas->GetEntries() != nareas)
+      if (fAverageLoGainAreas->GetSize() != nareas)
         {
           *fLog << err << "ERROR - Size mismatch in number of areas ... abort." << endl;
@@ -819,5 +897,5 @@
         }
       
-      if (fAverageLoGainSectors->GetEntries() != nsectors)
+      if (fAverageLoGainSectors->GetSize() != nsectors)
         {
           *fLog << err << "ERROR - Size mismatch in number of sectors ... abort." << endl;
@@ -840,5 +918,5 @@
 {
 
-  if (fHiGainArray->GetEntries() == 0 && fLoGainArray->GetEntries() == 0)
+  if (fHiGainArray->GetSize() == 0 && fLoGainArray->GetSize() == 0)
     {
       *fLog << err << GetDescriptor() 
@@ -847,6 +925,51 @@
     }
   
+  for (Int_t i=0; i<fAverageHiGainAreas->GetSize(); i++)
+    {
+      TH1F *h = GetAverageHiGainArea(i).GetHGausHist();
+      switch (fColor)
+        {
+        case MCalibrationCam::kNONE: 
+          break;
+        case MCalibrationCam::kBLUE: 
+          h->SetTitle( Form("%s%s", h->GetTitle(),"BLUE "));
+          break;
+        case MCalibrationCam::kGREEN: 
+          h->SetTitle( Form("%s%s", h->GetTitle(),"GREEN "));
+          break;
+        case MCalibrationCam::kUV: 
+          h->SetTitle( Form("%s%s", h->GetTitle(),"UV "));
+          break;
+        case MCalibrationCam::kCT1: 
+          h->SetTitle( Form("%s%s", h->GetTitle(),"CT1-Pulser "));
+          break;
+        }
+    }
+
+  for (Int_t i=0; i<fAverageLoGainAreas->GetSize(); i++)
+    {
+      TH1F *h = GetAverageLoGainArea(i).GetHGausHist();
+      switch (fColor)
+        {
+        case MCalibrationCam::kNONE: 
+          break;
+        case MCalibrationCam::kBLUE: 
+          h->SetTitle( Form("%s%s", h->GetTitle(),"BLUE "));
+          break;
+        case MCalibrationCam::kGREEN: 
+          h->SetTitle( Form("%s%s", h->GetTitle(),"GREEN "));
+          break;
+        case MCalibrationCam::kUV: 
+          h->SetTitle( Form("%s%s", h->GetTitle(),"UV "));
+          break;
+        case MCalibrationCam::kCT1: 
+          h->SetTitle( Form("%s%s", h->GetTitle(),"CT1-Pulser "));
+          break;
+        }
+    }
+  
   if (!FinalizeHists())
     return kFALSE;
+
 
   FinalizeBadPixels();
@@ -873,9 +996,5 @@
 
   hist.InitBins();
-  hist.ChangeHistId(i);
   hist.SetEventFrequency(fPulserFrequency);
-
-  TH1F *h = hist.GetHGausHist();
-  h->SetTitle( Form("%s%s", h->GetTitle()," Runs: "));
 }
 
@@ -904,5 +1023,4 @@
       
       FitHiGainHists(hist,pix,bad,fittyp,osctyp);
-      
     }
 
@@ -913,22 +1031,19 @@
     {
       
-      MHCalibrationPix     &hist = GetAverageHiGainArea(j);      
+      MHCalibrationPix &hist = GetAverageHiGainArea(j);      
       MCalibrationPix  &pix  = calcam.GetAverageArea(j);
       MBadPixelsPix    &bad  = calcam.GetAverageBadArea(j);        
-      
+
       FitHiGainHists(hist,pix,bad,fittyp,osctyp);
   }
   
-
   for (Int_t j=0; j<fAverageHiGainSectors->GetSize(); j++)
     {
-      
-      MHCalibrationPix     &hist = GetAverageHiGainSector(j);      
+      MHCalibrationPix &hist = GetAverageHiGainSector(j);      
       MCalibrationPix  &pix  = calcam.GetAverageSector(j);
       MBadPixelsPix    &bad  = calcam.GetAverageBadSector(j);        
-      
+
       FitHiGainHists(hist,pix,bad,fittyp,osctyp);
     }
-
 }
 
@@ -976,5 +1091,4 @@
   }
   
-
   for (Int_t j=0; j<fAverageLoGainSectors->GetSize(); j++)
     {
@@ -1045,5 +1159,4 @@
                                       MBadPixelsPix::UncalibratedType_t osctyp)
 {
-
 
   if (hist.IsEmpty() || hist.IsOnlyOverflow() || hist.IsOnlyUnderflow())
@@ -1088,5 +1201,5 @@
   if (IsDebug())
     {
-      *fLog << dbginf << GetDescriptor() << ": ID " << hist.GetPixId() 
+      *fLog << dbginf << GetDescriptor() << ": ID " << GetName() 
             << " HiGainSaturation: "   << pix.IsHiGainSaturation() 
             << " HiGainMean: "         << hist.GetMean    ()
@@ -1170,5 +1283,5 @@
   if (IsDebug())
     {
-      *fLog << dbginf << GetDescriptor() << "ID: " << hist.GetPixId() 
+      *fLog << dbginf << GetDescriptor() << "ID: " << hist.GetName() 
             << " HiGainSaturation: "   << pix.IsHiGainSaturation() 
             << " LoGainMean: "         << hist.GetMean    ()
@@ -1200,5 +1313,5 @@
     return;
 
-  const Int_t nareas = fAverageHiGainAreas->GetEntries();
+  const Int_t nareas = fAverageHiGainAreas->GetSize();
   if (nareas == 0)
     return;
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationCam.h
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationCam.h	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationCam.h	(revision 5137)
@@ -24,5 +24,5 @@
 
 class TText;
-class TObjArray;
+class TOrdCollection;
 
 class MHCalibrationPix;
@@ -54,8 +54,8 @@
   Axis_t  fLast;                         // Upper histogram limit 
 
-  TString fHistName;                     // Histogram names
-  TString fHistTitle;                    // Histogram titles
-  TString fHistXTitle;                   // Histogram x-axis titles
-  TString fHistYTitle;                   // Histogram y-axis titles
+  TString fHistName;                     //! Histogram names
+  TString fHistTitle;                    //! Histogram titles
+  TString fHistXTitle;                   //! Histogram x-axis titles
+  TString fHistYTitle;                   //! Histogram y-axis titles
   
   Float_t fNumHiGainSaturationLimit;     // Rel. amount sat. higain FADC slices until pixel is called saturated
@@ -70,10 +70,10 @@
   MArrayF fAverageAreaSigmaVar;          // Variance Re-normalized sigmas in average pixels per area
   MArrayI fAverageAreaNum;               // Number of pixels in average pixels per area
-  MArrayI fAverageSectorNum;             // Number of pixels in average pixels per sector 
-
-  TObjArray *fAverageHiGainAreas;        // Array of calibration pixels, one per pixel area
-  TObjArray *fAverageHiGainSectors;      // Array of calibration pixels, one per camera sector
-  TObjArray *fAverageLoGainAreas;        // Array of calibration pixels, one per pixel area
-  TObjArray *fAverageLoGainSectors;      // Array of calibration pixels, one per camera sector
+  MArrayI fAverageSectorNum;             // Number of pixels in average pixels per sector
+
+  TOrdCollection *fAverageHiGainAreas;   // Array of calibration pixels, one per pixel area
+  TOrdCollection *fAverageHiGainSectors; // Array of calibration pixels, one per camera sector
+  TOrdCollection *fAverageLoGainAreas;   // Array of calibration pixels, one per pixel area
+  TOrdCollection *fAverageLoGainSectors; // Array of calibration pixels, one per camera sector
 
   MCalibrationCam::PulserColor_t fColor; // Colour of the pulsed LEDs
@@ -86,6 +86,6 @@
   MRawRunHeader    *fRunHeader;          //! Run Header
   
-  TObjArray *fHiGainArray;               // Array of calibration pixels, one per pixel
-  TObjArray *fLoGainArray;               // Array of calibration pixels, one per pixel
+  TOrdCollection *fHiGainArray;          // Array of calibration pixels, one per pixel
+  TOrdCollection *fLoGainArray;          // Array of calibration pixels, one per pixel
 
   Int_t      fPulserFrequency;           // Light pulser frequency
@@ -108,4 +108,6 @@
   virtual void   InitLoGainArrays( const Int_t npix, const Int_t nareas, const Int_t nsectors );
 
+  virtual void   ResetHistTitles();
+  
   void DrawAverageSigma( Bool_t sat, Bool_t inner,
                          Float_t sigma, Float_t sigmaerr,
@@ -139,4 +141,6 @@
   Bool_t IsOscillations() const  { return TESTBIT(fFlags,kOscillations); }
   Bool_t IsSizeCheck   () const  { return TESTBIT(fFlags,kSizeCheck);    }
+  
+  void   Remove(TOrdCollection *col);
   
   Int_t ReadEnv        ( const TEnv &env, TString prefix, Bool_t print);
@@ -214,11 +218,2 @@
 
 #endif
-
-
-
-
-
-
-
-
-
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindCam.cc	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindCam.cc	(revision 5137)
@@ -35,4 +35,5 @@
 #include <TCanvas.h>
 #include <TPad.h>
+#include <TOrdCollection.h>
 
 #include "MLog.h"
@@ -59,5 +60,5 @@
 const Axis_t    MHCalibrationChargeBlindCam::fgSPheCut  =  20.;
 const TString   MHCalibrationChargeBlindCam::gsHistName   = "ChargeBlind";
-const TString   MHCalibrationChargeBlindCam::gsHistTitle  = "Signals Blind ";
+const TString   MHCalibrationChargeBlindCam::gsHistTitle  = "Signals Blind";
 const TString   MHCalibrationChargeBlindCam::gsHistXTitle = "Signal [FADC counts]";
 const TString   MHCalibrationChargeBlindCam::gsHistYTitle = "Nr. events";
@@ -184,13 +185,10 @@
   const Int_t integ        = signal->IsExtractionType( MExtractBlindPixel::kIntegral );
   
-  TH1F *h;
-
-  if (fHiGainArray->GetEntries()==0)
+  if (fHiGainArray->GetSize()==0)
   {
-      fHiGainArray->Expand(nblindpixels);
       for (Int_t i=0; i<nblindpixels; i++)
       {
-        (*fHiGainArray)[i] = new MHCalibrationChargeBlindPix(Form("%s%s",fHistName.Data(),"Pix"),
-                                                  Form("%s%s",fHistTitle.Data()," Pixel "));
+        fHiGainArray->AddAt(new MHCalibrationChargeBlindPix(Form("%s%s%d",fHistName.Data(),"Pix",i),
+                                                  Form("%s%s%d",fHistTitle.Data()," Pixel ",i)),i);
 
         MHCalibrationChargeBlindPix &pix = (MHCalibrationChargeBlindPix&)(*this)[i];
@@ -202,18 +200,31 @@
         pix.SetFitFunc      ( integ ? MHCalibrationChargeBlindPix::kEPoisson5 : fFitFunc );
 
-        h = pix.GetHGausHist();
-
-        h->SetName (Form("%s%s%s","H",fHistName.Data(),"Pix"));
-        h->SetTitle(Form("%s%s",fHistTitle.Data()," Pixel "));  
-        h->SetXTitle(fHistXTitle.Data());
-        h->SetYTitle(fHistYTitle.Data());
-
-        pix.ChangeHistId(i);
         pix.InitBins();
 
-        h->SetTitle( Form("%s%s", h->GetTitle()," Runs: "));
       }
   }
   return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Resets the histogram titles for each entry in:
+// - fHiGainArray
+//
+void MHCalibrationChargeBlindCam::ResetHistTitles()
+{
+  
+  TH1F *h;
+
+  if (fHiGainArray)
+    for (Int_t i=0;i<fHiGainArray->GetSize(); i++)
+      {
+        MHCalibrationPix &pix = (*this)[i];        
+        h = pix.GetHGausHist();
+        h->SetName (Form("%s%s%s%d","H",fHistName.Data(),"Pix",i));
+        h->SetTitle(Form("%s%s%d%s",fHistTitle.Data()," Pixel ",i," Runs: "));  
+        h->SetXTitle(fHistXTitle.Data());
+        h->SetYTitle(fHistYTitle.Data());
+      }
 }
 
@@ -327,9 +338,26 @@
   for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
     {
-      
       MHCalibrationChargeBlindPix &hist = (MHCalibrationChargeBlindPix&)(*this)[i];
       
       TH1F *h = hist.GetHGausHist();
 
+      switch (fColor)
+        {
+        case MCalibrationCam::kNONE: 
+          break;
+        case MCalibrationCam::kBLUE: 
+          h->SetTitle( Form("%s%s", h->GetTitle(),"BLUE "));
+          break;
+        case MCalibrationCam::kGREEN: 
+          h->SetTitle( Form("%s%s", h->GetTitle(),"GREEN "));
+          break;
+        case MCalibrationCam::kUV: 
+          h->SetTitle( Form("%s%s", h->GetTitle(),"UV "));
+          break;
+        case MCalibrationCam::kCT1: 
+          h->SetTitle( Form("%s%s", h->GetTitle(),"CT1-Pulser "));
+          break;
+        }
+      
       Stat_t overflow = h->GetBinContent(h->GetNbinsX()+1);
       if (overflow > 0.1)
@@ -373,5 +401,5 @@
   if (hist.IsEmpty())
   {
-    *fLog << err << GetDescriptor() << " ID: " << hist.GetPixId()
+    *fLog << err << GetDescriptor() << " ID: " << hist.GetName()
 	  << " My histogram has not been filled !! " << endl;
       return;
@@ -405,4 +433,38 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This Clone-function has to be different from the MHCalibrationCam 
+// Clone function since it does not store and display the averaged values 
+// (in fAverageAreas), but the blind pixels stored in fHiGainArray. 
+//
+// Creates new MHCalibrationChargeBlindCam and
+// Clones MHCalibrationChargeBlindPix's individually
+//
+#if 0
+TObject *MHCalibrationChargeBlindCam::Clone(const char *name) const
+{
+
+  MHCalibrationChargeBlindCam *cam = new MHCalibrationChargeBlindCam();
+
+  //
+  // Copy the data members
+  //
+  cam->fRunNumbers             = fRunNumbers;
+  cam->fPulserFrequency        = fPulserFrequency;
+  cam->fFlags                  = fFlags;
+  cam->fNbins                  = fNbins;
+  cam->fFirst                  = fFirst;
+  cam->fLast                   = fLast;
+  cam->fFitFunc                = fFitFunc;
+
+  const Int_t nhi = fHiGainArray->GetSize();
+  
+  for (int i=0; i<nhi; i++)
+    cam->fHiGainArray->AddAt((*this)[i].Clone(),i);
+
+  return cam;
+}
+#endif
 // -----------------------------------------------------------------------------
 // 
@@ -416,5 +478,5 @@
 {
 
-  const Int_t size = fHiGainArray->GetEntries();
+  const Int_t size = fHiGainArray->GetSize();
 
   if (size == 0)
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindCam.h
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindCam.h	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindCam.h	(revision 5137)
@@ -1,2 +1,3 @@
+
 #ifndef MARS_MHCalibrationChargeBlindCam
 #define MARS_MHCalibrationChargeBlindCam
@@ -39,4 +40,5 @@
   Bool_t FinalizeHists();
 
+  void   ResetHistTitles();
   void   FitBlindPixel( MHCalibrationChargeBlindPix &hist, MCalibrationBlindPix &pix);
 
@@ -46,5 +48,6 @@
 
   MHCalibrationChargeBlindCam(const char *name=NULL, const char *title=NULL);
-
+  ~MHCalibrationChargeBlindCam() {}
+  
   // Draw
   void  Draw(Option_t *opt="");
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindPix.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindPix.cc	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindPix.cc	(revision 5137)
@@ -146,4 +146,12 @@
 {
 
+  //
+  // The next two lines are important for the case that 
+  // the class has been stored to a file and is read again. 
+  // In this case, the next two lines prevent a segm. violation
+  // in the destructor
+  //
+  gROOT->GetListOfFunctions()->Remove(fSinglePheFit);
+
   if (fSinglePheFit)
       delete fSinglePheFit;
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeCam.cc	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeCam.cc	(revision 5137)
@@ -29,13 +29,13 @@
 // MHCalibrationChargeHiGainPix and MHCalibrationChargeLoGainPix for every:
 //
-// - Pixel, stored in the TObjArray's MHCalibrationCam::fHiGainArray and 
+// - Pixel, stored in the TOrdCollection's MHCalibrationCam::fHiGainArray and 
 //   MHCalibrationCam::fLoGainArray
 //
 // - Average pixel per AREA index (e.g. inner and outer for the MAGIC camera), 
-//   stored in the TObjArray's MHCalibrationCam::fAverageHiGainAreas and 
+//   stored in the TOrdCollection's MHCalibrationCam::fAverageHiGainAreas and 
 //   MHCalibrationCam::fAverageLoGainAreas
 //
 // - Average pixel per camera SECTOR (e.g. sectors 1-6 for the MAGIC camera), 
-//   stored in the TObjArray's MHCalibrationCam::fAverageHiGainSectors and 
+//   stored in the TOrdCollection's MHCalibrationCam::fAverageHiGainSectors and 
 //   MHCalibrationCam::fAverageLoGainSectors
 // 
@@ -141,4 +141,5 @@
 #include "MArrayD.h"
 
+#include <TOrdCollection.h>
 #include <TPad.h>
 #include <TVirtualPad.h>
@@ -156,8 +157,8 @@
 const Int_t   MHCalibrationChargeCam::fgChargeHiGainNbins =  550;
 const Axis_t  MHCalibrationChargeCam::fgChargeHiGainFirst = -100.5;
-const Axis_t  MHCalibrationChargeCam::fgChargeHiGainLast  = 999.5;
-const Int_t   MHCalibrationChargeCam::fgChargeLoGainNbins =  325;
+const Axis_t  MHCalibrationChargeCam::fgChargeHiGainLast  =  999.5;
+const Int_t   MHCalibrationChargeCam::fgChargeLoGainNbins =  525;
 const Axis_t  MHCalibrationChargeCam::fgChargeLoGainFirst = -150.5;
-const Axis_t  MHCalibrationChargeCam::fgChargeLoGainLast  =  499.5;
+const Axis_t  MHCalibrationChargeCam::fgChargeLoGainLast  =  899.5;
 const TString MHCalibrationChargeCam::gsHistName          = "Charge";
 const TString MHCalibrationChargeCam::gsHistTitle         = "Signals";
@@ -241,4 +242,62 @@
 // --------------------------------------------------------------------------
 //
+// Creates new MHCalibrationChargeCam only with the averaged areas:
+// the rest has to be retrieved directly, e.g. via: 
+//     MHCalibrationChargeCam *cam = MParList::FindObject("MHCalibrationChargeCam");
+//  -  cam->GetAverageSector(5).DrawClone();
+//  -  (*cam)[100].DrawClone()
+//
+TObject *MHCalibrationChargeCam::Clone(const char *) const
+{
+
+  MHCalibrationChargeCam *cam = new MHCalibrationChargeCam();
+
+  //
+  // Copy the data members
+  //
+  cam->fColor                  = fColor;
+  cam->fRunNumbers             = fRunNumbers;
+  cam->fPulserFrequency        = fPulserFrequency;
+  cam->fFlags                  = fFlags;
+  cam->fNbins                  = fNbins;
+  cam->fFirst                  = fFirst;
+  cam->fLast                   = fLast;
+  cam->fLoGainNbins            = fLoGainNbins;
+  cam->fLoGainFirst            = fLoGainFirst;
+  cam->fLoGainLast             = fLoGainLast;
+
+  //
+  // Copy the MArrays
+  //
+  cam->fAverageAreaRelSigma    = fAverageAreaRelSigma;
+  cam->fAverageAreaRelSigmaVar = fAverageAreaRelSigmaVar;
+  cam->fAverageAreaSat         = fAverageAreaSat;
+  cam->fAverageAreaSigma       = fAverageAreaSigma;
+  cam->fAverageAreaSigmaVar    = fAverageAreaSigmaVar;
+  cam->fAverageAreaNum         = fAverageAreaNum;
+  cam->fAverageSectorNum       = fAverageSectorNum;
+
+  if (!IsAverageing())
+    return cam;
+
+  const Int_t navhi   =  fAverageHiGainAreas->GetSize();
+
+  for (int i=0; i<navhi; i++)
+    cam->fAverageHiGainAreas->AddAt(GetAverageHiGainArea(i).Clone(),i);
+
+  if (IsLoGain())
+    {
+      
+      const Int_t navlo = fAverageLoGainAreas->GetSize();
+      for (int i=0; i<navlo; i++)
+        cam->fAverageLoGainAreas->AddAt(GetAverageLoGainArea(i).Clone(),i);
+
+    }
+
+  return cam;
+}
+
+// --------------------------------------------------------------------------
+//
 // Gets the pointers to:
 // - MRawEvtData
@@ -323,5 +382,4 @@
   const Float_t numlogain = signal->GetNumUsedLoGainFADCSlices();  
 
-
   if (fCam)
     {
@@ -350,4 +408,11 @@
   const Int_t nareas   = fGeom->GetNumAreas();
 
+  //
+  // In case of the intense blue, double the range
+  //
+  if (fGeom->InheritsFrom("MGeomCamMagic"))
+    if ( fColor == MCalibrationCam::kBLUE)
+      SetLoGainLast(2.*fLoGainLast - fLoGainFirst);
+  
   InitHiGainArrays(npixels,nareas,nsectors);
   InitLoGainArrays(npixels,nareas,nsectors);
@@ -377,8 +442,4 @@
 // Initializes the High Gain Arrays:
 //
-// - Expand fHiGainArrays to npixels
-// - Expand fAverageHiGainAreas to nareas
-// - Expand fAverageHiGainSectors to nsectors
-// 
 // - For every entry in the expanded arrays: 
 //   * Initialize an MHCalibrationChargePix
@@ -399,11 +460,10 @@
   const Int_t higainsamples = fRunHeader->GetNumSamplesHiGain();
 
-  if (fHiGainArray->GetEntries()==0)
+  if (fHiGainArray->GetSize()==0)
   {
-      fHiGainArray->Expand(npixels);
       for (Int_t i=0; i<npixels; i++)
       {
-        (*fHiGainArray)[i] = new MHCalibrationChargePix(Form("%s%s",fHistName.Data(),"HiGainPix"),
-                                                  Form("%s%s",fHistTitle.Data()," High Gain Pixel"));
+        fHiGainArray->AddAt(new MHCalibrationChargePix(Form("%s%s%4i",fHistName.Data(),"HiGainPix",i),
+                                                       Form("%s%s%4i",fHistTitle.Data()," High Gain Pixel",i)),i);
 
         MHCalibrationChargePix &pix = (MHCalibrationChargePix&)(*this)[i];
@@ -417,15 +477,8 @@
         pix.SetAbsTimeLast(higainsamples-0.5);
 
-        h = pix.GetHGausHist();
-
-        h->SetName (Form("%s%s%s","H",fHistName.Data(),"HiGainPix"));
-        h->SetTitle(Form("%s%s",fHistTitle.Data()," High Gain Pixel "));  
-        h->SetXTitle(fHistXTitle.Data());
-        h->SetYTitle(fHistYTitle.Data());
-        
         h = pix.GetHAbsTime();
 
-        h->SetName (Form("%s%s%s","H",fAbsHistName.Data(),"HiGainPix"));
-        h->SetTitle(Form("%s%s",fAbsHistTitle.Data()," High Gain Pixel "));
+        h->SetName (Form("%s%s%s%4i","H",fAbsHistName.Data(),"HiGainPix",i));
+        h->SetTitle(Form("%s%s%4i",fAbsHistTitle.Data()," High Gain Pixel ",i));
         h->SetXTitle(fAbsHistXTitle.Data());
         h->SetYTitle(fAbsHistYTitle.Data());
@@ -437,13 +490,10 @@
 
 
-  if (fAverageHiGainAreas->GetEntries()==0)
+  if (fAverageHiGainAreas->GetSize()==0)
   {
-    fAverageHiGainAreas->Expand(nareas);
-    
     for (Int_t j=0; j<nareas; j++)
       {
-        (*fAverageHiGainAreas)[j] = 
-          new MHCalibrationChargePix(Form("%s%s",fHistName.Data(),"HiGainArea"),
-                                     Form("%s%s",fHistTitle.Data()," High Gain Area Idx "));
+        fAverageHiGainAreas->AddAt(new MHCalibrationChargePix(Form("%s%s%d",fHistName.Data(),"HiGainArea",j),
+                                                  Form("%s%s%d",fHistTitle.Data()," High Gain Area Idx ",j)),j);
         
         MHCalibrationChargePix &pix = (MHCalibrationChargePix&)GetAverageHiGainArea(j);
@@ -457,29 +507,11 @@
         pix.SetAbsTimeLast(higainsamples-0.5);
 
-        h =  pix.GetHGausHist();
-        
-        h->SetName (Form("%s%s%s","H",fHistName.Data(),"HiGainArea"));
-        h->SetXTitle(fHistXTitle.Data());
-        h->SetYTitle(fHistYTitle.Data());
-        
-        if (fGeom->InheritsFrom("MGeomCamMagic"))
-          {
-            h->SetTitle(Form("%s%s%s%s",fHistTitle.Data()," averaged on event-by-event basis ",
-                             j==0 ? "Inner Pixels " : "Outer Pixels ","High Gain Runs: "));
-            pix.InitBins();
-            pix.SetEventFrequency(fPulserFrequency);
-          }
-        else
-          {
-            h->SetTitle(Form("%s%s",fHistTitle.Data(),
-                             " averaged on event-by-event basis High Gain Area Idx "));
-            InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
-          }
+        InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
 
         h =  pix.GetHAbsTime();
         
-        h->SetName (Form("%s%s%s","H",fAbsHistName.Data(),"HiGainArea"));
-        h->SetTitle(Form("%s%s",fAbsHistTitle.Data(),
-                         " averaged on event-by-event basis High Gain Area Idx "));
+        h->SetName (Form("%s%s%s%d","H",fAbsHistName.Data(),"HiGainArea",j));
+        h->SetTitle(Form("%s%s%d",fAbsHistTitle.Data(),
+                         " averaged on event-by-event basis High Gain Area Idx ",j));
         h->SetXTitle(fAbsHistXTitle.Data());
         h->SetYTitle(fAbsHistYTitle.Data());
@@ -487,13 +519,10 @@
   }
   
-  if (fAverageHiGainSectors->GetEntries()==0)
+  if (fAverageHiGainSectors->GetSize()==0)
   {
-      fAverageHiGainSectors->Expand(nsectors);
-
       for (Int_t j=0; j<nsectors; j++)
-      {
-	  (*fAverageHiGainSectors)[j] = 
-            new MHCalibrationChargePix(Form("%s%s",fHistName.Data(),"HiGainSector"),
-                                       Form("%s%s",fHistTitle.Data()," High Gain Sector "));
+        {
+	  fAverageHiGainSectors->AddAt(new MHCalibrationChargePix(Form("%s%s%2i",fHistName.Data(),"HiGainSector",j),
+                                                      Form("%s%s%2i",fHistTitle.Data()," High Gain Sector ",j)),j);
 
           MHCalibrationChargePix &pix = (MHCalibrationChargePix&)GetAverageHiGainSector(j);
@@ -507,16 +536,9 @@
           pix.SetAbsTimeLast(higainsamples-0.5);
           
-          h =  pix.GetHGausHist();
-          
-          h->SetName (Form("%s%s%s","H",fHistName.Data(),"HiGainSector"));
-          h->SetTitle(Form("%s%s",fHistTitle.Data()," High Gain Sector "));  
-          h->SetXTitle(fHistXTitle.Data());
-          h->SetYTitle(fHistYTitle.Data());
-
           h =  pix.GetHAbsTime();
           
-          h->SetName (Form("%s%s%s","H",fAbsHistName.Data(),"HiGainSector"));
-          h->SetTitle(Form("%s%s",fAbsHistTitle.Data(),
-                           " averaged on event-by-event basis High Gain Area Sector "));
+          h->SetName (Form("%s%s%s%2i","H",fAbsHistName.Data(),"HiGainSector",j));
+          h->SetTitle(Form("%s%s%2i",fAbsHistTitle.Data(),
+                           " averaged on event-by-event basis High Gain Area Sector ",j));
           h->SetXTitle(fAbsHistXTitle.Data());
           h->SetYTitle(fAbsHistYTitle.Data());
@@ -536,8 +558,4 @@
 // Initializes the Low Gain Arrays:
 //
-// - Expand fLoGainArrays to npixels
-// - Expand fAverageLoGainAreas to nareas
-// - Expand fAverageLoGainSectors to nsectors
-// 
 // - For every entry in the expanded arrays: 
 //   * Initialize an MHCalibrationChargePix
@@ -560,13 +578,10 @@
   TH1F *h;
 
-  if (fLoGainArray->GetEntries()==0 )
-    {
-      fLoGainArray->Expand(npixels);
-      
+  if (fLoGainArray->GetSize()==0 )
+    {
       for (Int_t i=0; i<npixels; i++)
         {
-          (*fLoGainArray)[i] = 
-            new MHCalibrationChargePix(Form("%s%s",fHistName.Data(),"LoGainPix"),
-                                       Form("%s%s",fHistTitle.Data()," Low Gain Pixel"));
+          fLoGainArray->AddAt(new MHCalibrationChargePix(Form("%s%s%4i",fHistName.Data(),"LoGainPix",i),
+                                       Form("%s%s%4i",fHistTitle.Data()," Low Gain Pixel",i)),i);
 
           MHCalibrationChargePix &pix = (MHCalibrationChargePix&)(*this)(i);
@@ -580,15 +595,8 @@
           pix.SetAbsTimeLast(logainsamples-0.5);
           
-          h =  pix.GetHGausHist();
-          
-          h->SetName (Form("%s%s%s","H",fHistName.Data(),"LoGainPix"));
-          h->SetTitle(Form("%s%s",fHistTitle.Data()," Low Gain Pixel "));  
-          h->SetXTitle(fHistXTitle.Data());
-          h->SetYTitle(fHistYTitle.Data());
-          
           h = pix.GetHAbsTime();
           
-          h->SetName (Form("%s%s%s","H",fAbsHistName.Data(),"HiGainPix"));
-          h->SetTitle(Form("%s%s",fAbsHistTitle.Data()," High Gain Pixel "));
+          h->SetName (Form("%s%s%s%4i","H",fAbsHistName.Data(),"HiGainPix",i));
+          h->SetTitle(Form("%s%s%4i",fAbsHistTitle.Data()," High Gain Pixel ",i));
           h->SetXTitle(fAbsHistXTitle.Data());
           h->SetYTitle(fAbsHistYTitle.Data());
@@ -599,112 +607,65 @@
   }
 
-  if (fAverageLoGainAreas->GetEntries()==0)
-    {
-      fAverageLoGainAreas->Expand(nareas);
-      
+  if (fAverageLoGainAreas->GetSize()==0)
+    {
       for (Int_t j=0; j<nareas; j++)
         {
-	  (*fAverageLoGainAreas)[j] = 
-            new MHCalibrationChargePix(Form("%s%s",fHistName.Data(),"LoGainArea"),
-                                       Form("%s%s",fHistTitle.Data()," Low Gain Area Idx "));
-        
-        MHCalibrationChargePix &pix = (MHCalibrationChargePix&)GetAverageLoGainArea(j);
-
-        pix.SetNbins(fLoGainNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
-        pix.SetFirst(fLoGainFirst);
-        pix.SetLast (fLoGainLast);
-
-        pix.SetAbsTimeNbins(logainsamples);
-        pix.SetAbsTimeFirst(-0.5);
-        pix.SetAbsTimeLast(logainsamples-0.5);
-
-        h =  pix.GetHGausHist();
-        
-        h->SetName (Form("%s%s%s","H",fHistName.Data(),"LoGainArea"));
-        h->SetXTitle(fHistXTitle.Data());
-        h->SetYTitle(fHistYTitle.Data());
-
-
-        if (fGeom->InheritsFrom("MGeomCamMagic"))
-          {
-            h->SetTitle(Form("%s%s%s%s",fHistTitle.Data()," averaged on event-by-event basis ",
-                             j==0 ? "Inner Pixels " : "Outer Pixels ","Low Gain Runs: "));
-            pix.InitBins();
-            pix.SetEventFrequency(fPulserFrequency);
-          }
-        else
-          {
-            h->SetTitle(Form("%s%s",fHistTitle.Data()," averaged on event-by-event basis Low Gain Area Idx ")); 
-            InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
-          }
-
-        h =  pix.GetHAbsTime();
-        
-        h->SetName (Form("%s%s%s","H",fAbsHistName.Data(),"LoGainArea"));
-        h->SetTitle(Form("%s%s",fAbsHistTitle.Data(),
-                         " averaged on event-by-event basis Low Gain Area Idx "));
-        h->SetXTitle(fAbsHistXTitle.Data());
-        h->SetYTitle(fAbsHistYTitle.Data());
-
-        }
-    }
-  
-
-  if (fAverageLoGainSectors->GetEntries()==0 && IsLoGain())
-  {
-      fAverageLoGainSectors->Expand(nsectors);
-  
-      for (Int_t j=0; j<nsectors; j++)
-      {
-	  (*fAverageLoGainSectors)[j] = 
-            new MHCalibrationChargePix(Form("%s%s",fHistName.Data(),"LoGainSector"),
-                                       Form("%s%s",fHistTitle.Data()," Low Gain Sector "));
-
-          MHCalibrationChargePix &pix = (MHCalibrationChargePix&)GetAverageLoGainSector(j);
-
+	  fAverageLoGainAreas->AddAt(new MHCalibrationChargePix(Form("%s%s%d",fHistName.Data(),"LoGainArea",j),
+                                       Form("%s%s%d",fHistTitle.Data()," Low Gain Area Idx ",j)),j);
+        
+          MHCalibrationChargePix &pix = (MHCalibrationChargePix&)GetAverageLoGainArea(j);
+          
           pix.SetNbins(fLoGainNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
           pix.SetFirst(fLoGainFirst);
           pix.SetLast (fLoGainLast);
-
+          
           pix.SetAbsTimeNbins(logainsamples);
           pix.SetAbsTimeFirst(-0.5);
           pix.SetAbsTimeLast(logainsamples-0.5);
           
-          h =  pix.GetHGausHist();
-          
-          h->SetName (Form("%s%s%s","H",fHistName.Data(),"LoGainSector"));
-          h->SetTitle(Form("%s%s",fHistTitle.Data()," Low Gain Sector "));  
-          h->SetXTitle(fHistXTitle.Data());
-          h->SetYTitle(fHistYTitle.Data());
-
           h =  pix.GetHAbsTime();
           
-          h->SetName (Form("%s%s%s","H",fAbsHistName.Data(),"LoGainSector"));
-          h->SetTitle(Form("%s%s",fAbsHistTitle.Data(),
-                           " averaged on event-by-event basis Low Gain Area Sector "));
+          h->SetName (Form("%s%s%s%2i","H",fAbsHistName.Data(),"LoGainArea",j));
+          h->SetTitle(Form("%s%s%2i",fAbsHistTitle.Data(),
+                           " averaged on event-by-event basis Low Gain Area Idx ",j));
           h->SetXTitle(fAbsHistXTitle.Data());
           h->SetYTitle(fAbsHistYTitle.Data());
           
-          //
-          // Adapt the range for the case, the intense blue is used:
-          // FIXME: this is a nasty workaround, but for the moment necessary 
-          // in order to avoid default memory space.
-          //
-          if (fGeom->InheritsFrom("MGeomCamMagic"))
-            {
-              if ( fColor == MCalibrationCam::kBLUE)
-                {
-                  pix.SetFirst(-10.5);
-                  pix.SetLast(999.5);
-                  pix.SetNbins(3030);
-                }
-            }
-          
-          InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadSector(j) : fCam->GetAverageBadSector(j),j);
+          InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadArea(j) : fCam->GetAverageBadArea(j),j);
+        }
+    }
+  
+
+  if (fAverageLoGainSectors->GetSize()==0 && IsLoGain())
+  {
+    for (Int_t j=0; j<nsectors; j++)
+      {
+        fAverageLoGainSectors->AddAt(new MHCalibrationChargePix(Form("%s%s%2i",fHistName.Data(),"LoGainSector",j),
+                                                        Form("%s%s%2i",fHistTitle.Data()," Low Gain Sector ",j)),j);
+        
+        MHCalibrationChargePix &pix = (MHCalibrationChargePix&)GetAverageLoGainSector(j);
+        
+        pix.SetNbins(fLoGainNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
+        pix.SetFirst(fLoGainFirst);
+        pix.SetLast (fLoGainLast);
+        
+        pix.SetAbsTimeNbins(logainsamples);
+        pix.SetAbsTimeFirst(-0.5);
+        pix.SetAbsTimeLast(logainsamples-0.5);
+        
+        h =  pix.GetHAbsTime();
+        
+        h->SetName (Form("%s%s%s%2i","H",fAbsHistName.Data(),"LoGainSector",j));
+        h->SetTitle(Form("%s%s%2i",fAbsHistTitle.Data(),
+                           " averaged on event-by-event basis Low Gain Area Sector ",j));
+        h->SetXTitle(fAbsHistXTitle.Data());
+        h->SetYTitle(fAbsHistYTitle.Data());
+
+        InitHists(pix,fIntensCam ? fIntensCam->GetAverageBadSector(j) : fCam->GetAverageBadSector(j),j);
       }
   }
 }
 
-  
+
 // --------------------------------------------------------------------------
 //
@@ -717,5 +678,5 @@
 // - number of sectors
 //
-// For all TObjArray's (including the averaged ones), the following steps are performed: 
+// For all TOrdCollection's (including the averaged ones), the following steps are performed: 
 //
 // 1) Fill Charges histograms (MHGausEvents::FillHistAndArray()) with:
@@ -852,4 +813,5 @@
 
       MHCalibrationChargePix &hipix = (MHCalibrationChargePix&)GetAverageHiGainArea(j);
+      
 
       if (IsOscillations())
@@ -910,5 +872,5 @@
 // --------------------------------------------------------------------------
 //
-// For all TObjArray's (including the averaged ones), the following steps are performed: 
+// For all TOrdCollection's (including the averaged ones), the following steps are performed: 
 //
 // 1) Returns if the pixel is excluded.
@@ -934,5 +896,6 @@
   MCalibrationCam *chargecam = fIntensCam ? fIntensCam->GetCam() : fCam;
   MBadPixelsCam   *badcam    = fIntensBad ? fIntensBad->GetCam() : fBadPixels;
-      
+
+
   for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
     {
@@ -1022,5 +985,5 @@
           FinalizeAbsTimes(histlo, pix, bad, fFirstLoGain, fLastLoGain);
       }
-  
+
   for (Int_t j=0; j<fAverageHiGainAreas->GetSize(); j++)
     {
@@ -1040,5 +1003,5 @@
       FinalizeAbsTimes(histhi, pix, bad, fFirstHiGain, fLastHiGain);
    }
-  
+
   if (IsLoGain())
     for (Int_t j=0; j<fAverageLoGainAreas->GetSize(); j++)
@@ -1147,5 +1110,5 @@
       *fLog << warn << GetDescriptor() 
             << Form("%s%3.1f%s%2.1f%s%4i",": Mean ArrivalTime: ",mean," smaller than ",fTimeLowerLimit,
-                    " FADC slices from lower edge in pixel ",hist.GetPixId()) << endl;
+                    " FADC slices from lower edge in pixel ",hist.GetName()) << endl;
       bad.SetUncalibrated( MBadPixelsPix::kMeanTimeInFirstBin );
     }
@@ -1155,5 +1118,5 @@
       *fLog << warn << GetDescriptor() 
             << Form("%s%3.1f%s%2.1f%s%4i",": Mean ArrivalTime: ",mean," greater than ",fTimeUpperLimit,
-                    " FADC slices from upper edge in pixel ",hist.GetPixId()) << endl;
+                    " FADC slices from upper edge in pixel ",hist.GetName()) << endl;
       bad.SetUncalibrated( MBadPixelsPix::kMeanTimeInLast2Bins );
     }
@@ -1230,5 +1193,5 @@
 {
 
-  const Int_t nareas = fAverageHiGainAreas->GetEntries();
+  const Int_t nareas = fAverageHiGainAreas->GetSize();
   if (nareas == 0)
     return;
@@ -1262,4 +1225,5 @@
        // Ask for Hi-Gain saturation
        //
+       *fLog << err << hipix.GetSaturated() << "   " << fNumHiGainSaturationLimit*hipix.GetHGausHist()->GetEntries() <<  endl;
        if (hipix.GetSaturated() > fNumHiGainSaturationLimit*hipix.GetHGausHist()->GetEntries() && IsLoGain())
          {
@@ -1269,4 +1233,5 @@
        else
          DrawDataCheckPixel(hipix,i ? gkHiGainOuterRefLines : gkHiGainInnerRefLines);
+
     }      
 }
@@ -1296,5 +1261,7 @@
                         pix.GetFirst() > 0. ? pix.GetFirst() : 0.,
                         pix.GetLast() > pix.GetFirst()
-                        ? ( pix.GetLast() > 450. ? 450. : pix.GetLast() )
+                        ? ( pix.GetLast() > 450. 
+                            ? ( fColor == MCalibrationCam::kBLUE ? 800. : 450. )
+                            : pix.GetLast() )
                         : pix.GetFirst()*2.);
 
@@ -1383,4 +1350,8 @@
 
   pix.DrawEvents("same");
+
+  //  newpad->cd(3);
+  //  pix.DrawPowerSpectrum(*newpad,4);
+
   return;
   
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeCam.h
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeCam.h	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeCam.h	(revision 5137)
@@ -105,4 +105,7 @@
   ~MHCalibrationChargeCam() {}
   
+  // Clone
+  TObject *Clone(const char *name="") const;
+
   void SetLoGainNbins       ( const Int_t  i )       { fLoGainNbins   = i; }
   void SetLoGainFirst       ( const Axis_t f )       { fLoGainFirst   = f; }
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargePix.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargePix.cc	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargePix.cc	(revision 5137)
@@ -101,21 +101,4 @@
   MHGausEvents::Reset();
   fHAbsTime.Reset();
-}
-
-// --------------------------------------------------------------------------
-//
-// Calls MHCalibrationPix::ChangeHistId()
-//
-// Add id to names and titles of: 
-// - fHAbsTime
-//
-void MHCalibrationChargePix::ChangeHistId(Int_t id)
-{
-
-  MHCalibrationPix::ChangeHistId(id);
-
-  fHAbsTime.SetName (Form("%s%d", fHAbsTime.GetName(),  id));
-  fHAbsTime.SetTitle(Form("%s%d", fHAbsTime.GetTitle(), id));
-
 }
 
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargePix.h
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargePix.h	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargePix.h	(revision 5137)
@@ -44,7 +44,4 @@
   virtual void Draw(Option_t *opt="");
 
-  // Miscelleaneous
-  void ChangeHistId(Int_t id);
-  
   ClassDef(MHCalibrationChargePix, 1)     // Base Histogram class for Charge Pixel Calibration
 };
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationPix.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationPix.cc	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationPix.cc	(revision 5137)
@@ -62,5 +62,4 @@
 //
 MHCalibrationPix::MHCalibrationPix(const char *name, const char *title)
-    : fPixId(-1)
 { 
 
@@ -108,5 +107,5 @@
     {
       *fLog << warn << GetDescriptor() 
-            << ": Cannot bypass fit. Number of entries smaller or equal 0 in pixel: " << fPixId << endl;
+            << ": Cannot bypass fit. Number of entries smaller or equal 0 in pixel: " << GetName() << endl;
       return;
     }
@@ -116,24 +115,4 @@
   fSigma    = fHGausHist.GetRMS() ;
   fSigmaErr = fHGausHist.GetRMS() / TMath::Sqrt(entries) / 2.;
-}
-
-// --------------------------------------------------------------------------
-//
-// - Set fPixId to id
-//
-// Add id to names and titles of:
-// - fHGausHist
-//
-void MHCalibrationPix::ChangeHistId(const Int_t id)
-{
-
-  fPixId = id;
-
-  fHGausHist.SetName(  Form("%s%d", fHGausHist.GetName(),  id));
-  fHGausHist.SetTitle( Form("%s%d", fHGausHist.GetTitle(), id));
-
-  fName  = Form("%s%d", fName.Data(),  id);
-  fTitle = Form("%s%d", fTitle.Data(), id);
-
 }
 
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationPix.h
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationPix.h	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationPix.h	(revision 5137)
@@ -18,10 +18,8 @@
   Int_t    fSaturated;                   // Number of events classified as saturated
   Float_t  fPickupLimit;                 // Upper nr sigmas from mean until event is considered pickup
-  Int_t    fPixId;                       // Pixel ID 
 
 public:
 
   MHCalibrationPix(const char* name=NULL, const char* title=NULL);
-  ~MHCalibrationPix() {}
 
   void  Clear(Option_t *o="");
@@ -30,5 +28,4 @@
   const Double_t GetBlackout       () const;  
   const Double_t GetPickup         () const;
-  const Int_t    GetPixId          () const { return fPixId;          }
   const Float_t  GetSaturated      () const { return fSaturated;      }
 
@@ -41,8 +38,6 @@
   void  SetBlackoutLimit    ( const Float_t  lim=fgBlackoutLimit ) { fBlackoutLimit  = lim; }
   void  SetPickupLimit      ( const Float_t  lim=fgPickupLimit   ) { fPickupLimit    = lim; }
-  void  SetPixId            ( const Int_t    i                   ) { fPixId          = i;   }
 
   // Miscelleaneous
-  virtual void ChangeHistId(const Int_t id);      // Changes names and titles of the histogram
   virtual void Renorm();                          // Re-normalize the results 
   
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationRelTimeCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationRelTimeCam.cc	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationRelTimeCam.cc	(revision 5137)
@@ -109,4 +109,5 @@
 #include "MBadPixelsPix.h"
 
+#include <TOrdCollection.h>
 #include <TPad.h>
 #include <TVirtualPad.h>
@@ -167,4 +168,60 @@
 
 }
+
+// --------------------------------------------------------------------------
+//
+// Creates new MHCalibrationRelTimeCam only with the averaged areas:
+// the rest has to be retrieved directly, e.g. via: 
+//     MHCalibrationRelTimeCam *cam = MParList::FindObject("MHCalibrationRelTimeCam");
+//  -  cam->GetAverageSector(5).DrawClone();
+//  -  (*cam)[100].DrawClone()
+//
+#if 0
+TObject *MHCalibrationRelTimeCam::Clone(const char *) const
+{
+
+  MHCalibrationRelTimeCam *cam = new MHCalibrationRelTimeCam();
+
+  //
+  // Copy the data members
+  //
+  cam->fRunNumbers             = fRunNumbers;
+  cam->fPulserFrequency        = fPulserFrequency;
+  cam->fFlags                  = fFlags;
+  cam->fNbins                  = fNbins;
+  cam->fFirst                  = fFirst;
+  cam->fLast                   = fLast;
+
+  //
+  // Copy the MArrays
+  //
+  cam->fAverageAreaRelSigma    = fAverageAreaRelSigma;
+  cam->fAverageAreaRelSigmaVar = fAverageAreaRelSigmaVar;
+  cam->fAverageAreaSat         = fAverageAreaSat;
+  cam->fAverageAreaSigma       = fAverageAreaSigma;
+  cam->fAverageAreaSigmaVar    = fAverageAreaSigmaVar;
+  cam->fAverageAreaNum         = fAverageAreaNum;
+  cam->fAverageSectorNum       = fAverageSectorNum;
+
+  if (!IsAverageing())
+    return cam;
+
+  const Int_t navhi   =  fAverageHiGainAreas->GetSize();
+
+  for (int i=0; i<navhi; i++)
+    cam->fAverageHiGainAreas->AddAt(GetAverageHiGainArea(i).Clone(),i);
+
+  if (IsLoGain())
+    {
+      
+      const Int_t navlo = fAverageLoGainAreas->GetSize();
+      for (int i=0; i<navlo; i++)
+        cam->fAverageLoGainAreas->AddAt(GetAverageLoGainArea(i).Clone(),i);
+
+    }
+
+  return cam;
+}
+#endif
 
 // --------------------------------------------------------------------------
@@ -351,4 +408,10 @@
 Bool_t MHCalibrationRelTimeCam::FinalizeHists()
 {
+
+  *fLog << endl;
+
+  MCalibrationCam *relcam = fIntensCam ? fIntensCam->GetCam() : fCam;
+  MBadPixelsCam   *badcam = fIntensBad ? fIntensBad->GetCam() : fBadPixels;
+
   for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
     {
@@ -359,7 +422,5 @@
         continue;
       
-      MCalibrationRelTimePix &pix = fIntensCam 
-        ? (MCalibrationRelTimePix&)(*fIntensCam)[i] 
-        : (MCalibrationRelTimePix&)(*fCam)[i];
+      MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*relcam)[i] ;
 
       if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
@@ -398,7 +459,5 @@
       if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
         {
-          MCalibrationRelTimePix  &pix    = fIntensCam
-            ? (MCalibrationRelTimePix&)fIntensCam->GetAverageArea(j)
-            : (MCalibrationRelTimePix&)fCam->GetAverageArea(j);
+          MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)relcam->GetAverageArea(j);
           pix.SetHiGainSaturation();
           histhi.SetExcluded();
@@ -414,7 +473,5 @@
       
       MHCalibrationPix &histhi = GetAverageHiGainSector(j);      
-      MCalibrationRelTimePix  &pix = fIntensCam
-        ? (MCalibrationRelTimePix&)fIntensCam->GetAverageSector(j)  
-        : (MCalibrationRelTimePix&)fCam->GetAverageSector(j);
+      MCalibrationRelTimePix  &pix = (MCalibrationRelTimePix&)relcam->GetAverageSector(j) ;
 
       if (histhi.GetSaturated() > fNumHiGainSaturationLimit*histhi.GetHGausHist()->GetEntries())
@@ -428,12 +485,10 @@
     }
 
-  FitHiGainArrays(fIntensCam ? (MCalibrationCam&)(*fIntensCam->GetCam()) : (MCalibrationCam&)(*fCam),
-                  fIntensBad ?                   (*fIntensBad->GetCam()) : *fBadPixels,
+  FitHiGainArrays(*relcam,*badcam,
                   MBadPixelsPix::kRelTimeNotFitted,
                   MBadPixelsPix::kRelTimeOscillating);
   
   if (IsLoGain())        
-    FitLoGainArrays(fIntensCam ? (MCalibrationCam&)(*fIntensCam->GetCam()) : (MCalibrationCam&)(*fCam),
-                    fIntensBad ?                   (*fIntensBad->GetCam()) : *fBadPixels,
+    FitLoGainArrays(*relcam,*badcam,
                     MBadPixelsPix::kRelTimeNotFitted,
                     MBadPixelsPix::kRelTimeOscillating);
@@ -548,5 +603,5 @@
 {
 
-  const Int_t nareas = fAverageHiGainAreas->GetEntries();
+  const Int_t nareas = fAverageHiGainAreas->GetSize();
   if (nareas == 0)
     return;
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationRelTimeCam.h
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationRelTimeCam.h	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationRelTimeCam.h	(revision 5137)
@@ -32,12 +32,12 @@
   static const TString gsHistYTitle;                 //! Default Histogram y-axis titles
   
-  MArrayD fSumareahi  ;                             //!
-  MArrayD fSumarealo  ;                             //!
-  MArrayD fSumsectorhi;                             //!
-  MArrayD fSumsectorlo;                             //!
-  MArrayI fNumareahi  ;                             //!
-  MArrayI fNumarealo  ;                             //!
-  MArrayI fNumsectorhi;                             //!
-  MArrayI fNumsectorlo;                             //!
+  MArrayD fSumareahi  ;                             //
+  MArrayD fSumarealo  ;                             //
+  MArrayD fSumsectorhi;                             //
+  MArrayD fSumsectorlo;                             //
+  MArrayI fNumareahi  ;                             //
+  MArrayI fNumarealo  ;                             //
+  MArrayI fNumsectorhi;                             //
+  MArrayI fNumsectorlo;                             //
 
   UInt_t fReferencePixel;                           // The reference pixel for rel. times
@@ -57,4 +57,7 @@
   UInt_t GetReferencePixel() const { return fReferencePixel; }
 
+  // Clone
+  //  TObject *Clone(const char *name="") const;
+
   // Setters
   void  SetReferencePixel( const UInt_t i=fgReferencePixel) { fReferencePixel = i; }
@@ -70,3 +73,2 @@
 
 #endif
-
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationTestCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationTestCam.cc	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationTestCam.cc	(revision 5137)
@@ -103,11 +103,13 @@
 #include "MBadPixelsPix.h"
 
+#include <TOrdCollection.h>
+
 ClassImp(MHCalibrationTestCam);
 
 using namespace std;
 
-const Int_t   MHCalibrationTestCam::fgNbins    = 900;
-const Axis_t  MHCalibrationTestCam::fgFirst    = -5.;
-const Axis_t  MHCalibrationTestCam::fgLast     =  5.;
+const Int_t   MHCalibrationTestCam::fgNbins    = 1000;
+const Axis_t  MHCalibrationTestCam::fgFirst    = -0.5;
+const Axis_t  MHCalibrationTestCam::fgLast     = 39999.5;
 const TString MHCalibrationTestCam::gsHistName   = "Test";
 const TString MHCalibrationTestCam::gsHistTitle  = "Calibrated Calibration Signals";  
@@ -188,4 +190,74 @@
 
 
+//--------------------------------------------------------------------------------------
+//
+// Initializes the High Gain Arrays:
+// 
+// - For every entry in the expanded arrays: 
+//   * Initialize an MHCalibrationPix
+//   * Set Binning from  fNbins, fFirst and fLast
+//   * Set Histgram names and titles from fHistName and fHistTitle
+//   * Set X-axis and Y-axis titles with fHistXTitle and fHistYTitle
+//   * Call InitHists
+//
+void MHCalibrationTestCam::InitHiGainArrays(const Int_t npixels, const Int_t nareas, const Int_t nsectors)
+{
+
+  if (fHiGainArray->GetSize()==0)
+  {
+      for (Int_t i=0; i<npixels; i++)
+      {
+        fHiGainArray->AddAt(new MHCalibrationPix(Form("%s%s",fHistName.Data(),"HiGainPix"),
+                                                 Form("%s%s",fHistTitle.Data()," High Gain Pixel")),i);
+        
+        MHCalibrationPix &pix = (*this)[i];          
+        pix.SetNbins(fNbins);
+        pix.SetFirst(fFirst);
+        pix.SetLast (fLast);
+        
+        MBadPixelsPix &bad = (*fBadPixels)[i];
+        InitHists(pix,bad,i);
+      }
+  }
+
+  if (!IsAverageing())
+    return;
+
+  if (fAverageHiGainAreas->GetSize()==0)
+  {
+    for (Int_t j=0; j<nareas; j++)
+      {
+        fAverageHiGainAreas->AddAt(new MHCalibrationPix(Form("%s%s",fHistName.Data(),"HiGainArea"),
+                                                        Form("%s%s",fHistTitle.Data()," High Gain Area Idx ")),j);
+        
+        MHCalibrationPix &pix = GetAverageHiGainArea(j);
+        
+        pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nareas));
+        pix.SetFirst(fFirst);
+        pix.SetLast (fLast);
+
+        pix.InitBins();
+        pix.SetEventFrequency(fPulserFrequency);
+      }
+  }
+
+  if (fAverageHiGainSectors->GetSize()==0)
+    {
+      for (Int_t j=0; j<nsectors; j++)
+        {
+          fAverageHiGainSectors->AddAt(new MHCalibrationPix(Form("%s%s",fHistName.Data(),"HiGainSector"),
+                                                            Form("%s%s",fHistTitle.Data()," High Gain Sector ")),j);
+          MHCalibrationPix &pix = GetAverageHiGainSector(j);
+
+          pix.SetNbins(fNbins*(Int_t)TMath::Sqrt((Float_t)npixels/nsectors));
+          pix.SetFirst(fFirst);
+          pix.SetLast (fLast);
+          
+          pix.InitBins();
+          pix.SetEventFrequency(fPulserFrequency);
+      }
+  }
+}
+
 // -------------------------------------------------------------------------------
 //
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationTestCam.h
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationTestCam.h	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationTestCam.h	(revision 5137)
@@ -35,4 +35,6 @@
   Bool_t FillHists(const MParContainer *par, const Stat_t w=1);
   Bool_t FinalizeHists();
+
+  void InitHiGainArrays(const Int_t npix, const Int_t nareas, const Int_t nsectors);
   
 public:
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationTestTimeCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationTestTimeCam.cc	(revision 5135)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationTestTimeCam.cc	(revision 5137)
@@ -102,4 +102,6 @@
 #include "MBadPixelsPix.h"
 
+#include <TOrdCollection.h>
+
 ClassImp(MHCalibrationTestTimeCam);
 
