Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 4648)
+++ trunk/MagicSoft/Mars/Changelog	(revision 4649)
@@ -27,5 +27,14 @@
        with Florian
 
-
+   * mcalib/MCalibrationTestPix.[h,cc]
+   * mcalib/MCalibrationTestCam.[h,cc]
+   * mcalib/Makefile
+   * mcalib/CalibLinkDef.h
+     - new container class to store results of MCalibrationTestCalc
+       and MHCalibrationTestCam
+
+   * mcalib/MCalibrationTestCalc,[h,cc]
+     - adapted to use of MCalibrationTestCam
+    
 
  2004/08/17: Thomas Bretz
Index: trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h	(revision 4648)
+++ trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h	(revision 4649)
@@ -18,4 +18,6 @@
 #pragma link C++ class MCalibrationQEPix+;
 #pragma link C++ class MCalibrationTestCalc+;
+#pragma link C++ class MCalibrationTestCam+;
+#pragma link C++ class MCalibrationTestPix+;
 #pragma link C++ class MCalibrationChargeCalc+;
 #pragma link C++ class MCalibrationChargeCam+;
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationTestCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationTestCalc.cc	(revision 4648)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationTestCalc.cc	(revision 4649)
@@ -64,4 +64,7 @@
 #include "MHCalibrationTestPix.h"
 
+#include "MCalibrationTestCam.h"
+#include "MCalibrationTestPix.h"
+
 #include "MBadPixelsCam.h"
 #include "MBadPixelsPix.h"
@@ -85,6 +88,5 @@
 //
 MCalibrationTestCalc::MCalibrationTestCalc(const char *name, const char *title)
-    : fMaxNumBadPixelsCluster(-1), 
-      fBadPixels(NULL), fTestCam(NULL), fGeom(NULL)
+    : fBadPixels(NULL), fTestCam(NULL), fCam(NULL), fGeom(NULL)
 {
         
@@ -112,8 +114,15 @@
   // Containers that are created in case that they are not there.
   //
-  fBadPixels = (MBadPixelsCam*)pList->FindCreateObj("MBadPixelsCam");
+  fBadPixels = (MBadPixelsCam*)pList->FindCreateObj(AddSerialNumber("MBadPixelsCam"));
   if (!fBadPixels)
     {
       *fLog << err << "Could not find or create MBadPixelsCam ... aborting." << endl;
+      return kFALSE;
+    }
+  
+  fCam = (MCalibrationTestCam*)pList->FindCreateObj(AddSerialNumber("MCalibrationTestCam"));
+  if (!fCam)
+    {
+      *fLog << err << "Could not find or create MCalibrationTestCam ... aborting." << endl;
       return kFALSE;
     }
@@ -170,6 +179,6 @@
 {
 
-  //  if (GetNumExecutions()==0)
-  //    return kFALSE;
+  if (GetNumExecutions()==0)
+    return kFALSE;
 
   //
@@ -184,5 +193,5 @@
   FinalizeCalibratedPhotons();
   FinalizeNotInterpolated();
-  CalcMaxNumBadPixelsCluster();
+  const Int_t maxbad = CalcMaxNumBadPixelsCluster();
 
 
@@ -193,10 +202,12 @@
     {
       *fLog << " " << setw(7) << "Not interpolateable Pixels: " 
-            << Form("%s%3i%s%3i","Inner: ",fNumUninterpolateable[0],
-                    " Outer: ",fNumUninterpolateable[1]) << endl;
+            << Form("%s%3i%s%3i","Inner: ",fCam->GetNumUninterpolated(0),
+                    " Outer: ",fCam->GetNumUninterpolated(1)) << endl;
       *fLog << " " << setw(7) << "Biggest not-interpolateable cluster: " 
-            << fMaxNumBadPixelsCluster << endl;
-    }
-  
+            << maxbad << endl;
+    }
+  
+  fCam->SetNumUninterpolatedInMaxCluster(maxbad);
+
   *fLog << endl;  
   SetLogStream(&gLog);
@@ -251,17 +262,26 @@
     {
       
-      MHCalibrationTestPix &pix = (MHCalibrationTestPix&)(*fTestCam)[i];
+      MHCalibrationTestPix &hist = (MHCalibrationTestPix&)(*fTestCam)[i];
+      MCalibrationTestPix  &pix =                         (*fCam)[i];
       //
       // We assume that the pixels have been interpolated so far. 
       // The MBadPixelsCam does not give any more information
       //
-      if (pix.IsEmpty())
-          continue;
-
-      const Double_t nphot = pix.GetMean();
-      const Int_t    aidx  = (*fGeom)[i].GetAidx();
+      if (hist.IsEmpty())
+        {
+          pix.SetExcluded();
+          continue;
+        }
+      
+
+      const Double_t nphot    = hist.GetMean();
+      const Double_t nphoterr = hist.GetMeanErr();
+      const Int_t    aidx     = (*fGeom)[i].GetAidx();
 
       camphotons.Fill(i,nphot);
       camphotons.SetUsed(i);
+
+      pix.SetNumPhotons   ( nphot    );
+      pix.SetNumPhotonsErr( nphoterr );
 
       areaphotons [aidx] += nphot;
@@ -299,7 +319,14 @@
           continue;
         }
-      
-      lowlim [aidx] = areaphotons[aidx] - fPhotErrLimit*TMath::Sqrt(areavars[aidx]);
-      upplim [aidx] = areaphotons[aidx] + fPhotErrLimit*TMath::Sqrt(areavars[aidx]);
+
+      const Float_t areamean = areaphotons[aidx];
+      const Float_t areaerr  = TMath::Sqrt(areavars[aidx]);
+      
+      MCalibrationTestPix &avpix = fCam->GetAverageArea(aidx);
+      avpix.SetNumPhotons   (areamean);
+      avpix.SetNumPhotonsErr(areaerr );
+
+      lowlim [aidx] = areamean - fPhotErrLimit*areaerr;
+      upplim [aidx] = areamean + fPhotErrLimit*areaerr;
 
       TArrayI area(1);
@@ -338,4 +365,7 @@
       fittedsigma[aidx] = sigma;
       
+      avpix.SetNumPhotons   (mean );
+      avpix.SetNumPhotonsErr(sigma);
+
       lowlim  [aidx] = mean  - fPhotErrLimit*sigma;
       upplim  [aidx] = mean  + fPhotErrLimit*sigma;
@@ -361,10 +391,15 @@
     {
       
-      MHCalibrationTestPix &pix = (MHCalibrationTestPix&)(*fTestCam)[i];
-
-      const Int_t    aidx   = (*fGeom)[i].GetAidx();
-      const Int_t    sector = (*fGeom)[i].GetSector();
-      const Float_t  area   = (*fGeom)[i].GetA();
-      const Double_t nphot  = pix.GetMean();
+      MHCalibrationTestPix &hist = (MHCalibrationTestPix&)(*fTestCam)[i];
+      MCalibrationTestPix  &pix =                         (*fCam)[i];
+
+      const Int_t    aidx         = (*fGeom)[i].GetAidx();
+      const Int_t    sector       = (*fGeom)[i].GetSector();
+      const Double_t nphot        = hist.GetMean();
+      const Double_t nphotpera    = nphot            / (*fGeom)[i].GetA();
+      const Double_t nphotperaerr = hist.GetMeanErr()/ (*fGeom)[i].GetA();
+
+      pix.SetNumPhotonsPerArea   ( nphotpera    );
+      pix.SetNumPhotonsPerAreaErr( nphotperaerr );
 
       if ( nphot < lowlim[aidx] || nphot > upplim[aidx] )
@@ -376,13 +411,14 @@
           bad.SetUncalibrated( MBadPixelsPix::kDeviatingNumPhots );
           bad.SetUnsuitable  ( MBadPixelsPix::kUnsuitableRun     );
-          continue;
-        }
-      
-      areavars     [aidx] += nphot*nphot/area/area;
-      areaphotons  [aidx] += nphot/area;
+          pix.SetExcluded();
+          continue;
+        }
+      
+      areavars     [aidx] += nphotpera*nphotpera;
+      areaphotons  [aidx] += nphotpera;
       numareavalid [aidx] ++;
 
-      sectorvars    [sector] += nphot*nphot/area/area;
-      sectorphotons [sector] += nphot/area;
+      sectorvars    [sector] += nphotpera*nphotpera;
+      sectorphotons [sector] += nphotpera;
       numsectorvalid[sector] ++;
     } 
@@ -392,5 +428,5 @@
   for (UInt_t aidx=0; aidx<nareas; aidx++)
     {
-
+      
       if (numareavalid[aidx] == 1)
         areavars[aidx] = 0.;
@@ -407,4 +443,7 @@
         }
       
+
+      MCalibrationTestPix &avpix = fCam->GetAverageArea(aidx);
+
       if (areavars[aidx] < 0. || areaphotons[aidx] <= 0.)
         {
@@ -413,10 +452,16 @@
                 << aidx << " could not be calculated! Mean: " << areaphotons[aidx] 
                 << " Variance: " << areavars[aidx] << endl;
-          continue;
-        }
-      
+          avpix.SetExcluded();
+          continue;
+        }
+
+      const Float_t areaerr = TMath::Sqrt(areavars[aidx]);
+      
+      avpix.SetNumPhotonsPerArea   (areaphotons[aidx]);
+      avpix.SetNumPhotonsPerAreaErr(areaerr );
+
       *fLog << inf << GetDescriptor() << ": Mean number of equiv. Cher. photons "
             << "per area in area idx " << aidx << ": "  
-            << Form("%5.3f+-%5.4f  [ph/mm^2]",areaphotons[aidx],TMath::Sqrt(areavars[aidx])) << endl;
+            << Form("%5.3f+-%5.4f  [ph/mm^2]",areaphotons[aidx],areaerr) << endl;
     }
 
@@ -442,4 +487,6 @@
         }
       
+      MCalibrationTestPix &avpix = fCam->GetAverageSector(sector);
+
       if (sectorvars[sector] < 0. || sectorphotons[sector] <= 0.)
         {
@@ -448,11 +495,17 @@
                 << sector << " could not be calculated! Mean: " << sectorphotons[sector] 
                 << " Variance: " << sectorvars[sector] << endl;
-          continue;
-        }
-      
-  
+          avpix.SetExcluded();
+          continue;
+        }
+      
+  
+      const Float_t sectorerr = TMath::Sqrt(sectorvars[sector]);
+
+      avpix.SetNumPhotonsPerArea   (sectorphotons[sector]);
+      avpix.SetNumPhotonsPerAreaErr(sectorerr );
+
       *fLog << inf << GetDescriptor() << ": Mean number of equiv. Cher. photons "
             << "per area in sector " << sector << ":   "  
-            << Form("%5.3f+-%5.4f  [ph/mm^2]",sectorphotons[sector],TMath::Sqrt(sectorvars[sector])) << endl;
+            << Form("%5.3f+-%5.4f  [ph/mm^2]",sectorphotons[sector],sectorerr) << endl;
     }
 
@@ -468,7 +521,5 @@
 {
   
-  const TArrayI &arr = fTestCam->GetNotInterpolateablePixels();
   const Int_t areas  = fGeom->GetNumAreas();
-
   TArrayI *newarr[areas];
 
@@ -476,14 +527,13 @@
     newarr[aidx] = new TArrayI(0);
 
-  fNumUninterpolateable.Set(areas);
-
-  for (Int_t i=0; i<arr.GetSize(); i++)
-    {
-      const Int_t id   = arr[i];
-      const Int_t aidx = (*fGeom)[id].GetAidx();
-      const Int_t size = newarr[aidx]->GetSize();
-      newarr[aidx]->Set(size+1);
-      newarr[aidx]->AddAt(id,size);
-      fNumUninterpolateable[aidx]++;
+  for (Int_t i=0; i<fCam->GetSize(); i++)
+    {
+      const Int_t aidx = (*fGeom)[i].GetAidx();
+      if ((*fCam)[i].IsExcluded())
+        {
+          const Int_t size = newarr[aidx]->GetSize();
+          newarr[aidx]->Set(size+1);
+          newarr[aidx]->AddAt(i,size);
+        }
     }
 
@@ -500,8 +550,7 @@
           num++;
         }
+      fCam->SetNumUninterpolated(newarr[aidx]->GetSize(),aidx);
       *fLog << endl;
     }
-
-
   
   *fLog << " " << setw(7) << num << " total not interpolateable pixels " << endl;
@@ -509,5 +558,5 @@
 }
 
-void MCalibrationTestCalc::CalcMaxNumBadPixelsCluster()
+Int_t MCalibrationTestCalc::CalcMaxNumBadPixelsCluster()
 {
 
@@ -516,14 +565,8 @@
   
   if (size == 0)
-    {
-      fMaxNumBadPixelsCluster = 0; 
-      return;
-    }
+    return 0;
   
   if (size == 1)
-    {
-      fMaxNumBadPixelsCluster = 1; 
-      return;
-    }
+    return 1;
 
   TArrayI knownpixels(0);
@@ -546,5 +589,5 @@
     }
 
-  fMaxNumBadPixelsCluster = oldclustersize; 
+  return oldclustersize; 
 
 }
@@ -619,9 +662,2 @@
 }
 
-const Int_t MCalibrationTestCalc::GetNumUninterpolateable(const Int_t aidx) const
-{
-  if (aidx < 0)
-    return -1;
-
-  return aidx > fNumUninterpolateable.GetSize() ? -1 : fNumUninterpolateable[aidx]; 
-}
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationTestCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationTestCalc.h	(revision 4648)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationTestCalc.h	(revision 4649)
@@ -20,4 +20,5 @@
 
 class MHCalibrationTestCam;
+class MCalibrationTestCam;
 class MBadPixelsCam;
 class MGeomCam;
@@ -30,7 +31,4 @@
   // Variables
   Float_t fPhotErrLimit;               // Limit acceptance nr. cal. phots w.r.t. area idx mean (in sigmas)
-  Int_t   fMaxNumBadPixelsCluster;     // Number of not interpolateable pixels in biggest cluster
-
-  TArrayI fNumUninterpolateable;       // Number uninterpolated Pixels per area index 
 
   TString fOutputPath;                 // Path to the output file
@@ -40,4 +38,5 @@
   MBadPixelsCam         *fBadPixels;   //! Bad Pixels 
   MHCalibrationTestCam  *fTestCam;     //! Calibrated Photons in the camera
+  MCalibrationTestCam   *fCam;         //! Storage Calibrated Photons in the camera
   MGeomCam              *fGeom;        //! Camera geometry
 
@@ -47,5 +46,5 @@
   void   FinalizeNotInterpolated();
   void   FinalizeCalibratedPhotons() const;
-  void   CalcMaxNumBadPixelsCluster();
+  Int_t  CalcMaxNumBadPixelsCluster();
   void   LoopNeighbours( const TArrayI &arr, TArrayI &known, Int_t &clustersize, const Int_t idx );
   
@@ -59,7 +58,4 @@
   MCalibrationTestCalc(const char *name=NULL, const char *title=NULL);
 
-  const Int_t GetMaxNumBadPixelsCluster () const  { return fMaxNumBadPixelsCluster; }
-  const Int_t GetNumUninterpolateable   ( const Int_t aidx ) const;
-
   void SetOutputFile  ( TString file="TestCalibStat.txt" );
   void SetOutputPath  ( TString path="."                 );
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationTestCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationTestCam.cc	(revision 4649)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationTestCam.cc	(revision 4649)
@@ -0,0 +1,428 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Markus Gaug   11/2003 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+/////////////////////////////////////////////////////////////////////////////
+//                                                               
+// MCalibrationTestCam                                               
+//                                                               
+// Storage container for calibrated photons, with calibration applied on the 
+// same calibration run (see MHCalibrationTestCam and MHCalibrationTestPix).
+//
+// Contains TClonesArrays for the following objects:
+// - fPixels:         Array of classes derived from MCalibrationTestPix, one entry 
+//                    per pixel.
+// - fAverageAreas:   Array of classes derived from MCalibrationTestPix, one entry
+//                    per pixel AREA. 
+// - fAverageSectors: Array of classes derived from MCalibrationTestPix, one entry
+//                    per camera SECTOR. 
+//
+// Averaged values over one whole area index (e.g. inner or outer pixels for 
+// the MAGIC camera), can be retrieved via: 
+// MCalibrationTestPix &avpix = fTestCam->GetAverageArea(i)
+//
+// Averaged values over one whole camera sector can be retrieved via: 
+// MCalibrationTestPix &avpix = fTestCam->GetAverageSector(i)
+//
+// See also: MCalibrationTestPix, MCalibrationTestCalc, MCalibrationQECam
+//           MHCalibrationTestPix, MHCalibrationTestCam              
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MCalibrationTestCam.h"
+#include "MCalibrationTestPix.h"
+
+#include <TClonesArray.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MGeomCam.h"
+#include "MGeomPix.h"
+
+ClassImp(MCalibrationTestCam);
+
+using namespace std;
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+// Sets all pointers to 0
+// 
+// Creates a TClonesArray of MCalibrationTestPix containers, initialized to 1 entry, destinated 
+// to hold one container per pixel. Later, a call to MCalibrationTestCam::InitSize() 
+// has to be performed (in MGeomApply). 
+//
+// Creates a TClonesArray of MCalibrationTestPix containers, initialized to 1 entry, destinated 
+// to hold one container per pixel AREA. Later, a call to MCalibrationTestCam::InitAreas() 
+// has to be performed (in MGeomApply). 
+//
+// Creates a TClonesArray of MCalibrationTestPix containers, initialized to 1 entry, destinated
+// to hold one container per camera SECTOR. Later, a call to MCalibrationTestCam::InitSectors() 
+// has to be performed (in MGeomApply). 
+//
+// Calls:
+// - Clear()
+//
+MCalibrationTestCam::MCalibrationTestCam(const char *name, const char *title)
+{
+
+  fName  = name  ? name  : "MCalibrationTestCam";
+  fTitle = title ? title : "Storage container for the Calibration Test Information in the camera";
+  
+  fPixels           = new TClonesArray("MCalibrationTestPix",1);
+  fAverageAreas     = new TClonesArray("MCalibrationTestPix",1);
+  fAverageSectors   = new TClonesArray("MCalibrationTestPix",1);
+
+  Clear();
+}
+
+// --------------------------------------------------------------------------
+//
+// Deletes the following TClonesArray's of MCalibrationPix containers (if exist):
+// - fPixels
+// - fAverageAreas
+// - fAverageSectors
+//  
+MCalibrationTestCam::~MCalibrationTestCam()
+{
+
+  delete fPixels;
+  delete fAverageAreas;
+  delete fAverageSectors;
+  
+}
+
+// --------------------------------------
+//
+// Sets all variable to 0.
+// Sets all flags to kFALSE
+// Calls MCalibrationCam::Clear()
+//
+void MCalibrationTestCam::Clear(Option_t *o)
+{
+
+  fNumUninterpolatedInMaxCluster = 0; 
+
+  {  fPixels        ->ForEach(TObject, Clear)();  }
+  {  fAverageAreas  ->ForEach(TObject, Clear)();  }
+  {  fAverageSectors->ForEach(TObject, Clear)();  }
+  
+  return;
+}
+
+// -------------------------------------------------------------------
+//
+// Calls TClonesArray::ExpandCreate() for fPixels
+//
+void MCalibrationTestCam::InitSize(const UInt_t i)
+{
+  fPixels->ExpandCreate(i);
+}
+
+// -------------------------------------------------------------------
+//
+// Calls TClonesArray::ExpandCreate() for:
+// - fAverageAreas
+//
+void MCalibrationTestCam::InitAverageAreas(const UInt_t i)
+{
+
+  fAverageAreas->ExpandCreate(i);
+
+  for (UInt_t j=0; j<i; j++)
+    GetAverageArea(j).SetPixId(j);
+  
+  fNumUninterpolated.Set(i);
+}
+
+// -------------------------------------------------------------------
+//
+// Calls TClonesArray::ExpandCreate() for:
+// - fAverageSectors
+//
+void MCalibrationTestCam::InitAverageSectors(const UInt_t i)
+{
+
+  fAverageSectors->ExpandCreate(i);
+
+  for (UInt_t j=0; j<i; j++)
+    GetAverageSector(j).SetPixId(j);
+
+}
+
+// -------------------------------------------------------------------
+//
+// Calls:
+// - InitSize()
+// - InitAverageAreas()
+// - InitAverageSectors()
+//
+void MCalibrationTestCam::Init(const MGeomCam &geom)
+{
+
+  InitSize          (geom.GetNumPixels() );
+  InitAverageAreas  (geom.GetNumAreas()  );
+  InitAverageSectors(geom.GetNumSectors());
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the current size of the TClonesArray fAverageAreas
+// independently if the MCalibrationPix is filled with values or not.
+//
+const Int_t MCalibrationTestCam::GetAverageAreas() const
+{
+  return fAverageAreas->GetEntriesFast();
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the current size of the TClonesArray fAverageSectors
+// independently if the MCalibrationPix is filled with values or not.
+//
+const Int_t MCalibrationTestCam::GetAverageSectors() const
+{
+  return fAverageSectors->GetEntriesFast();
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Get i-th pixel (pixel number)
+//
+MCalibrationTestPix &MCalibrationTestCam::operator[](UInt_t i)
+{
+  return *static_cast<MCalibrationTestPix*>(fPixels->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th pixel (pixel number)
+//
+const MCalibrationTestPix &MCalibrationTestCam::operator[](UInt_t i) const
+{
+  return *static_cast<MCalibrationTestPix*>(fPixels->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the current size of the TClonesArray fPixels 
+// independently if the MCalibrationTestPix is filled with values or not.
+//
+const Int_t MCalibrationTestCam::GetSize() const
+{
+  return fPixels->GetEntriesFast();
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th average pixel (area number)
+//
+MCalibrationTestPix &MCalibrationTestCam::GetAverageArea(UInt_t i)
+{
+  return *static_cast<MCalibrationTestPix*>(fAverageAreas->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th average pixel (area number)
+//
+const MCalibrationTestPix &MCalibrationTestCam::GetAverageArea(UInt_t i) const 
+{
+  return *static_cast<MCalibrationTestPix*>(fAverageAreas->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th average pixel (sector number)
+//
+MCalibrationTestPix &MCalibrationTestCam::GetAverageSector(UInt_t i)
+{
+  return *static_cast<MCalibrationTestPix*>(fAverageSectors->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th average pixel (sector number)
+//
+const MCalibrationTestPix &MCalibrationTestCam::GetAverageSector(UInt_t i) const 
+{
+  return *static_cast<MCalibrationTestPix*>(fAverageSectors->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Print first the well fitted pixels 
+// and then the ones which are not FitValid
+//
+void MCalibrationTestCam::Print(Option_t *o) const
+{
+
+  *fLog << all << GetDescriptor() << ":" << endl;
+  int id = 0;
+  
+  *fLog << all << "Calibrated (or interpolated) pixels:" << endl;
+  *fLog << all << endl;
+
+  TIter Next(fPixels);
+  MCalibrationTestPix *pix;
+  while ((pix=(MCalibrationTestPix*)Next()))
+    {
+      
+      if (!pix->IsExcluded()) 
+	{                            
+
+          *fLog << all 
+                << Form("%s%3i","Pixel: ",pix->GetPixId())
+		<< Form("%s%4.2f%s%4.2f","  Num.Photons: ",pix->GetNumPhotons(),"+-",pix->GetNumPhotonsErr()) 
+		<< Form("%s%4.2f%s%4.2f","  Num.Photons/mm^2: ",pix->GetNumPhotonsPerArea()
+                        ,"+-",pix->GetNumPhotonsPerAreaErr()) 
+		<< endl;
+          id++;
+	}
+    }
+  
+  *fLog << all << id << " pixels" << endl;
+  id = 0;
+  
+   
+  *fLog << all << endl;
+  *fLog << all << "Not interpolated pixels:" << endl;
+  *fLog << all << endl;
+  
+  id = 0;
+
+  TIter Next4(fPixels);
+  while ((pix=(MCalibrationTestPix*)Next4()))
+  {
+      if (pix->IsExcluded())
+      {
+        *fLog << all << pix->GetPixId() << " ";
+        id++;
+
+        if (!(id % 25))
+          *fLog << endl;
+      }
+  }
+  
+  *fLog << endl;
+  *fLog << all << id << " Excluded pixels " << endl;
+  *fLog << endl;
+
+  *fLog << all << endl;
+  *fLog << all << "Averaged Areas:" << endl;
+  *fLog << all << endl;
+
+  TIter Next5(fAverageAreas);
+  while ((pix=(MCalibrationTestPix*)Next5()))
+  {
+    *fLog << all << Form("%s%3i","Area Idx: ",pix->GetPixId())
+          << Form("%s%4.2f%s%4.2f","  Num.Photons: ",pix->GetNumPhotons(),"+-",pix->GetNumPhotonsErr()) 
+          << Form("%s%4.2f%s%4.2f","  Num.Photons/mm^2: ",pix->GetNumPhotonsPerArea()
+                  ,"+-",pix->GetNumPhotonsPerAreaErr()) 
+          << endl;
+  }
+
+  *fLog << all << endl;
+  *fLog << all << "Averaged Sectors:" << endl;
+  *fLog << all << endl;
+
+  TIter Next6(fAverageSectors);
+  while ((pix=(MCalibrationTestPix*)Next6()))
+  {
+    *fLog << all << Form("%s%3i","Sector: ",pix->GetPixId())
+          << Form("%s%4.2f%s%4.2f","  Num.Photons: ",pix->GetNumPhotons(),"+-",pix->GetNumPhotonsErr()) 
+          << Form("%s%4.2f%s%4.2f","  Num.Photons/mm^2: ",pix->GetNumPhotonsPerArea()
+                  ,"+-",pix->GetNumPhotonsPerAreaErr()) 
+          << endl;
+  }
+  *fLog << all << endl;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// The types are as follows:
+// 
+// 0: Number Photons
+// 1: Error Number Photons
+// 2: Number photons per area
+// 3: Error Number Photons per area
+// 4: Pixels which are not interpolateable
+//
+Bool_t MCalibrationTestCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
+{
+
+  if (idx > GetSize())
+    return kFALSE;
+
+  Float_t area = cam[idx].GetA();
+
+ if (area == 0)
+    return kFALSE;
+
+ MCalibrationTestPix &pix = (MCalibrationTestPix&)(*this)[idx];
+
+  switch (type)
+    {
+    case 0:
+      if (pix.IsExcluded())
+        return kFALSE;
+      val = pix.GetNumPhotons();
+      break;
+    case 1:
+      if (pix.IsExcluded())
+        return kFALSE;
+      val = pix.GetNumPhotonsErr();
+      break;
+    case 2:
+      if (pix.IsExcluded())
+        return kFALSE;
+      val = pix.GetNumPhotonsPerArea();
+      break;
+    case 3:
+      if (pix.IsExcluded())
+        return kFALSE;
+      val = pix.GetNumPhotonsPerAreaErr();
+      break;
+    case 4:
+      if (!pix.IsExcluded())
+        return kFALSE;
+      val = 1;
+      break;
+    default:
+      return kFALSE;
+    }
+
+  return val!=-1.;
+}
+
+void  MCalibrationTestCam::SetNumUninterpolated( const UInt_t i, const Int_t aidx ) 
+{
+
+  if (aidx < 0)
+    return;
+
+  if (aidx < fNumUninterpolated.GetSize())
+    fNumUninterpolated[aidx] = i;  
+}
+
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationTestCam.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationTestCam.h	(revision 4649)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationTestCam.h	(revision 4649)
@@ -0,0 +1,70 @@
+#ifndef MARS_MCalibrationTestCam
+#define MARS_MCalibrationTestCam
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+#ifndef MARS_MCamEvent
+#include "MCamEvent.h"
+#endif
+
+#ifndef ROOT_TArrayI
+#include "TArrayI.h"
+#endif
+
+class TClonesArray;
+class MCalibrationTestPix;
+class MCalibrationTestCam : public MParContainer, public MCamEvent
+{
+private:
+  
+  TArrayI fNumUninterpolated;             // Number uninterpolated Pixels per area index 
+  Int_t   fNumUninterpolatedInMaxCluster; // Number of not interpolateable pixels in biggest cluster
+
+  TClonesArray *fPixels;                  //-> Array of MCalibrationTestPix, one per pixel
+  TClonesArray *fAverageAreas;            //-> Array of MCalibrationTestPix, one per pixel area
+  TClonesArray *fAverageSectors;          //-> Array of MCalibrationTestPix, one per camera sector
+  
+public:
+
+  MCalibrationTestCam(const char *name=NULL, const char *title=NULL);
+  ~MCalibrationTestCam();
+  
+  void   Clear ( Option_t *o="" );
+  
+  // Getters
+  const Int_t                GetAverageAreas      ()             const;
+        MCalibrationTestPix &GetAverageArea       ( UInt_t i );
+  const MCalibrationTestPix &GetAverageArea       ( UInt_t i )   const;
+        MCalibrationTestPix &GetAverageSector     ( UInt_t i );
+  const Int_t                GetAverageSectors    ()             const;  
+  const MCalibrationTestPix &GetAverageSector     ( UInt_t i   ) const;
+  const Int_t                GetNumUninterpolated ( Int_t aidx ) const { 
+	return fNumUninterpolated[aidx];  }
+  const Int_t                GetNumUninterplatedInMaxCluster ()  const { 
+	return fNumUninterpolatedInMaxCluster; }
+  Bool_t                     GetPixelContent      ( Double_t &val, Int_t idx, 
+	                                            const MGeomCam &cam, Int_t type=0) const;
+  const Int_t                GetSize              ()             const;  
+
+        MCalibrationTestPix &operator[]           ( UInt_t i );
+  const MCalibrationTestPix &operator[]           ( UInt_t i ) const;
+
+  // Inits
+  void  Init               ( const MGeomCam &geom );
+  void  InitSize           ( const UInt_t i       );
+  void  InitAverageAreas   ( const UInt_t i       );
+  void  InitAverageSectors ( const UInt_t i       );
+  
+  // Prints
+  void  Print              ( Option_t *o=""       ) const;
+
+  // Setters   
+  void  SetNumUninterpolated            ( const UInt_t i, const Int_t aidx );
+  void  SetNumUninterpolatedInMaxCluster( const UInt_t i ) { fNumUninterpolatedInMaxCluster = i; }
+  
+  ClassDef(MCalibrationTestCam, 1) // Container Test Calibration Results Camera
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationTestPix.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationTestPix.cc	(revision 4649)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationTestPix.cc	(revision 4649)
@@ -0,0 +1,75 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Markus Gaug   08/2004 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+\* ======================================================================== */
+/////////////////////////////////////////////////////////////////////////////
+//                                                     
+// MCalibrationTestPix                                     
+//                                                     
+// Base Storage container for the test result of a calibration pixel. 
+// Holds calibrated number of photons, number of photons per area (mm^2) and 
+// their errors. Not interpolateable pixels are declared excluded.
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MCalibrationTestPix.h"
+
+ClassImp(MCalibrationTestPix);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor: 
+//
+// Sets:
+// - fPixId to -1
+//
+// Calls:
+// - Clear()
+//
+MCalibrationTestPix::MCalibrationTestPix(const char *name, const char *title)
+    : fPixId(-1)
+{
+
+  fName  = name  ? name  : "MCalibrationTestPix";
+  fTitle = title ? title : "Container of the fit results of MHCalibrationTestPix ";
+
+  Clear();
+
+}
+
+// ------------------------------------------------------------------------
+//
+// Sets:
+// - all data members to -1
+// - all excluded to kFALSE
+//
+void MCalibrationTestPix::Clear(Option_t *o)
+{
+
+  fNumPhotons           =  -1.;
+  fNumPhotonsErr        =  -1.;
+  fNumPhotonsPerArea    =  -1.;
+  fNumPhotonsPerAreaErr =  -1.;
+
+  SetExcluded          ( kFALSE );
+}
+
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationTestPix.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationTestPix.h	(revision 4649)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationTestPix.h	(revision 4649)
@@ -0,0 +1,49 @@
+#ifndef MARS_MCalibrationTestPix
+#define MARS_MCalibrationTestPix
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+class MCalibrationTestPix : public MParContainer
+{
+private:
+
+  Int_t   fPixId;                // Software PixId (needed to get Id in calls to Next())
+  Bool_t  fExcluded;             // If pixels is excluded or not (not interpolateable)
+
+  Float_t fNumPhotons;           // Number of calibrated photons
+  Float_t fNumPhotonsErr;        // Error Number of calibrated photons
+  Float_t fNumPhotonsPerArea;    // Number of calibrated photons per mm^2     
+  Float_t fNumPhotonsPerAreaErr; // Error Number of calibrated photons per mm^2
+
+public:
+
+  MCalibrationTestPix(const char *name=NULL, const char *title=NULL);
+  ~MCalibrationTestPix() {}
+  
+  void Clear(Option_t *o="");
+  
+  // Getters
+  Float_t GetNumPhotons          () const { return fNumPhotons;           }
+  Float_t GetNumPhotonsErr       () const { return fNumPhotonsErr;        }
+  Float_t GetNumPhotonsPerArea   () const { return fNumPhotonsPerArea;    }
+  Float_t GetNumPhotonsPerAreaErr() const { return fNumPhotonsPerAreaErr; }
+  Int_t   GetPixId               () const { return fPixId;                }
+  
+  Bool_t  IsExcluded             () const { return fExcluded;             }
+
+  // Setters
+  void SetPixId               ( const Int_t   i )       { fPixId                = i; }
+  void SetExcluded            ( const Bool_t  b=kTRUE ) { fExcluded             = b; }
+  void SetNumPhotons          ( const Float_t f )       { fNumPhotons           = f; }          
+  void SetNumPhotonsErr       ( const Float_t f )       { fNumPhotonsErr        = f; }       
+  void SetNumPhotonsPerArea   ( const Float_t f )       { fNumPhotonsPerArea    = f; }   
+  void SetNumPhotonsPerAreaErr( const Float_t f )       { fNumPhotonsPerAreaErr = f; }
+
+
+  ClassDef(MCalibrationTestPix, 1)	// Container for Calibration Test Results Pixel
+};
+
+#endif
+
Index: trunk/MagicSoft/Mars/mcalib/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mcalib/Makefile	(revision 4648)
+++ trunk/MagicSoft/Mars/mcalib/Makefile	(revision 4649)
@@ -43,4 +43,6 @@
            MCalibrationPedCam.cc \
 	   MCalibrationTestCalc.cc \
+	   MCalibrationTestCam.cc \
+	   MCalibrationTestPix.cc \
 	   MCalibrationChargeCalc.cc \
            MCalibrationChargeCam.cc \
