Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 3699)
+++ trunk/MagicSoft/Mars/Changelog	(revision 3700)
@@ -36,4 +36,8 @@
    * mcalib/MCalibrationCam.[h,cc]	
      - put a default pulser color kNONE
+
+   * manalysis/MPedestalCam.[h,cc]
+   * manalysis/MGeomApply.cc
+     - added average pixels in the way like it is done in MCalibrationCam
 
 
Index: trunk/MagicSoft/Mars/manalysis/MGeomApply.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MGeomApply.cc	(revision 3699)
+++ trunk/MagicSoft/Mars/manalysis/MGeomApply.cc	(revision 3700)
@@ -135,5 +135,5 @@
     MPedestalCam *ped = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
     if (ped)
-        ped->InitSize(cam->GetNumPixels());
+        ped->Init(*cam);
 
     MCalibrationCam *cal = (MCalibrationCam*)pList->FindObject(AddSerialNumber("MCalibrationChargeCam"));
Index: trunk/MagicSoft/Mars/manalysis/MPedestalCam.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPedestalCam.cc	(revision 3699)
+++ trunk/MagicSoft/Mars/manalysis/MPedestalCam.cc	(revision 3700)
@@ -49,22 +49,41 @@
 // --------------------------------------------------------------------------
 //
-// Default constructor. Creates a MPedestalPix object for each pixel
+// Default constructor. 
+//
+// Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated 
+// to hold one container per pixel. Later, a call to MPedestalCam::InitSize() 
+// has to be performed (in MGeomApply). 
+//
+// Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated 
+// to hold one container per pixel AREA. Later, a call to MPedestalCam::InitAreas() 
+// has to be performed (in MGeomApply). 
+//
+// Creates a TClonesArray of MPedestalPix containers, initialized to 1 entry, destinated
+// to hold one container per camera SECTOR. Later, a call to MPedestalCam::InitSectors() 
+// has to be performed (in MGeomApply). 
 //
 MPedestalCam::MPedestalCam(const char *name, const char *title) 
     : fTotalEntries(0)
 {
-    fName  = name  ? name  : "MPedestalCam";
-    fTitle = title ? title : "Storage container for all Pedestal Information in the camera";
-
-    fArray = new TClonesArray("MPedestalPix", 1);
-}
-
-// --------------------------------------------------------------------------
-//
-// Delete the array conatining the pixel pedest information
-//
+  fName  = name  ? name  : "MPedestalCam";
+  fTitle = title ? title : "Storage container for all Pedestal Information in the camera";
+  
+  fArray            = new TClonesArray("MPedestalPix", 1);
+  fAverageAreas     = new TClonesArray("MPedestalPix", 1);
+  fAverageSectors   = new TClonesArray("MPedestalPix", 1);
+}
+
+// --------------------------------------------------------------------------
+//
+// Deletes the following TClonesArray's of MPedestalPix containers (if exist):
+// - fArray
+// - fAverageAreas
+// - fAverageSectors
+//  
 MPedestalCam::~MPedestalCam()
 {
-    delete fArray;
+  delete fArray;
+  delete fAverageAreas;
+  delete fAverageSectors;
 }
 
@@ -76,4 +95,38 @@
 {
     fArray->ExpandCreate(i);
+}
+
+// -------------------------------------------------------------------
+//
+// Calls TClonesArray::ExpandCreate() for:
+// - fAverageAreas
+//
+void MPedestalCam::InitAverageAreas(const UInt_t i)
+{
+  fAverageAreas->ExpandCreate(i);
+}
+
+// -------------------------------------------------------------------
+//
+// Calls TClonesArray::ExpandCreate() for:
+// - fAverageSectors
+//
+void MPedestalCam::InitAverageSectors(const UInt_t i)
+{
+  fAverageSectors->ExpandCreate(i);
+}
+
+// -------------------------------------------------------------------
+//
+// Calls:
+// - InitSize()
+// - InitAverageAreas()
+// - InitAverageSectors()
+//
+void MPedestalCam::Init(const MGeomCam &geom)
+{
+  InitSize          (geom.GetNumPixels() );
+  InitAverageAreas  (geom.GetNumAreas()  );
+  InitAverageSectors(geom.GetNumSectors());
 }
 
@@ -92,4 +145,24 @@
 // --------------------------------------------------------------------------
 //
+// Returns the current size of the TClonesArray fAverageAreas
+// independently if the MPedestalPix is filled with values or not.
+//
+const Int_t MPedestalCam::GetAverageAreas() const
+{
+  return fAverageAreas->GetEntriesFast();
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the current size of the TClonesArray fAverageSectors
+// independently if the MPedestalPix is filled with values or not.
+//
+const Int_t MPedestalCam::GetAverageSectors() const
+{
+  return fAverageSectors->GetEntriesFast();
+}
+
+// --------------------------------------------------------------------------
+//
 // Get i-th pixel (pixel number)
 //
@@ -108,11 +181,68 @@
 }
 
-// -------------------------------------------------------------------------
-//
+// --------------------------------------------------------------------------
+//
+// Get i-th average pixel (area number)
+//
+MPedestalPix &MPedestalCam::GetAverageArea(UInt_t i)
+{
+  return *static_cast<MPedestalPix*>(fAverageAreas->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th average pixel (area number)
+//
+const MPedestalPix &MPedestalCam::GetAverageArea(UInt_t i) const 
+{
+  return *static_cast<MPedestalPix*>(fAverageAreas->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th average pixel (sector number)
+//
+MPedestalPix &MPedestalCam::GetAverageSector(UInt_t i)
+{
+  return *static_cast<MPedestalPix*>(fAverageSectors->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th average pixel (sector number)
+//
+const MPedestalPix &MPedestalCam::GetAverageSector(UInt_t i) const 
+{
+  return *static_cast<MPedestalPix*>(fAverageSectors->UncheckedAt(i));
+}
+
+// --------------------------------------
+//
+// Calls the ForEach macro for the TClonesArray fArray with the argument Clear()
+// 
+// Loops over the fAverageAreas, calling the function Clear() for 
+// every entry in fAverageAreas
+//
+// Loops over the fAverageSectors, calling the function Clear() for 
+// every entry in fAverageSectors
+// 
 void MPedestalCam::Clear(Option_t *o)
 {
-    fArray->ForEach(TObject, Clear)();
-
-    fTotalEntries = 0;
+  fArray->ForEach(TObject, Clear)();
+  
+  //
+  // another ForEach does not compile, thus have to do the loop ourselves:
+  //
+  for (Int_t i=0;i<GetAverageAreas();i++)
+    fAverageAreas[i].Clear();
+
+
+  //
+  // another ForEach does not compile, thus have to do the loop ourselves:
+  //
+  for (Int_t i=0;i<GetAverageSectors();i++)
+    fAverageSectors[i].Clear();
+  
+  fTotalEntries = 0;
 }
 
Index: trunk/MagicSoft/Mars/manalysis/MPedestalCam.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPedestalCam.h	(revision 3699)
+++ trunk/MagicSoft/Mars/manalysis/MPedestalCam.h	(revision 3700)
@@ -17,34 +17,47 @@
 {
 private:
-    TClonesArray *fArray;  //-> FIXME: Change TClonesArray away from a pointer?
-    UInt_t fTotalEntries;  // Total number of times, the Process was executed (to estimate the error of pedestal)
+
+  TClonesArray *fArray;           //-> FIXME: Change TClonesArray away from a pointer?
+  TClonesArray *fAverageAreas;    //-> Array of MPedestalPix, one per pixel area
+  TClonesArray *fAverageSectors;  //-> Array of MPedestalPix, one per camera sector
+
+  UInt_t fTotalEntries;  // Total number of times, the Process was executed (to estimate the error of pedestal)
 
 public:
-    MPedestalCam(const char *name=NULL, const char *title=NULL);
-    ~MPedestalCam();
 
-    void Clear(Option_t *o="");
+  MPedestalCam(const char *name=NULL, const char *title=NULL);
+  ~MPedestalCam();
+  
+  void Clear(Option_t *o="");
+  
+  // Getters 
+        MPedestalPix &GetAverageArea   ( UInt_t i );
+  const MPedestalPix &GetAverageArea   ( UInt_t i )            const;
+  const Int_t         GetAverageAreas  ()                      const;
+        MPedestalPix &GetAverageSector ( UInt_t i );
+  const MPedestalPix &GetAverageSector ( UInt_t i )            const;
+  const Int_t         GetAverageSectors()                      const;
+  Float_t             GetPedestalMin   ( const MGeomCam *cam ) const;
+  Float_t             GetPedestalMax   ( const MGeomCam *cam ) const;
+  Int_t               GetSize          ()                      const;
+  ULong_t             GetTotalEntries  ()                      const { return fTotalEntries; }
+  
+        MPedestalPix &operator[]       ( Int_t i             );
+  const MPedestalPix &operator[]       ( Int_t i             ) const;
 
-    void InitSize(const UInt_t i);
+  void  Init                           ( const MGeomCam &geom);
+  void  InitSize                       ( const UInt_t i      );
+  void  InitAverageAreas               ( const UInt_t i      );
+  void  InitAverageSectors             ( const UInt_t i      );
 
-    MPedestalPix &operator[](Int_t i);
-    const MPedestalPix &operator[](Int_t i) const;
+  void Print(Option_t *o="") const;
+  
+  // Setters
+  void SetTotalEntries(const ULong_t n) { fTotalEntries = n; }
 
-    // Setters
-    void SetTotalEntries(const ULong_t n) { fTotalEntries = n; }
+  Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
+  void DrawPixelContent(Int_t idx) const;
 
-    // Getters
-    Int_t  GetSize()         const;
-    ULong_t GetTotalEntries() const { return fTotalEntries; }
-
-    Float_t GetPedestalMin(const MGeomCam *cam) const;
-    Float_t GetPedestalMax(const MGeomCam *cam) const;
-
-    void Print(Option_t *o="") const;
-
-    Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
-    void DrawPixelContent(Int_t idx) const;
-
-    ClassDef(MPedestalCam, 1)	// Storage Container for all pedestal information of the camera
+  ClassDef(MPedestalCam, 1)	// Storage Container for all pedestal information of the camera
 };
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc	(revision 3699)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc	(revision 3700)
@@ -203,9 +203,16 @@
 }
 
+// -------------------------------------------------------------------
+//
+// Calls:
+// - InitSize()
+// - InitAverageAreas()
+// - InitAverageSectors()
+//
 void MCalibrationCam::Init(const MGeomCam &geom)
 {
-    InitSize          (geom.GetNumPixels() );
-    InitAverageAreas  (geom.GetNumAreas()  );
-    InitAverageSectors(geom.GetNumSectors());
+  InitSize          (geom.GetNumPixels() );
+  InitAverageAreas  (geom.GetNumAreas()  );
+  InitAverageSectors(geom.GetNumSectors());
 }
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 3699)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 3700)
@@ -382,5 +382,6 @@
 // - MCalibrationQEPix
 //
-// It tests the pulser colour one more time...
+// It initializes the pulser color in MCalibrationChargeCam, MCalibrationChargeBlindPix 
+// and MCalibrationChargePINDiode and tests, if it has not changed w.r.t. fPulserColor 
 //
 Bool_t MCalibrationChargeCalc::ReInit(MParList *pList )
@@ -496,12 +497,9 @@
 // ----------------------------------------------------------------------------------
 //  
-// Finalize pedestals: 
-// 
-// - Retrieve pedestal and pedestal RMS from MPedestalPix
-// - Retrieve total entries from MPedestalCam
-// - Sum up pedestal and pedestalRMS for the average pixel
-// - Set pedestal*number of used samples in MCalibrationChargePix
-// - Set pedestal RMS * sqrt of number of used samples in MCalibrationChargePix
-// 
+// Retrieves pedestal and pedestal RMS from MPedestalPix 
+// Retrieves total entries from MPedestalCam
+// Sums up pedestal and pedestalRMS for the average pixel
+// Sets pedestal*fNumHiGainSamples and pedestal*fNumLoGainSamples in MCalibrationChargePix
+// Sets pedRMS *fSqrtHiGainSamples and pedRMS *fSqrtLoGainSamples in MCalibrationChargePix
 //
 void MCalibrationChargeCalc::FinalizePedestals(const MPedestalPix &ped, MCalibrationChargePix &cal,
