Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 3349)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 3350)
@@ -345,6 +345,9 @@
   // loop over the pedestal events and check if we have calibration
   //
-  Int_t nvalid = 0;
-  for (UInt_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
+  Int_t nvalid   = 0;
+  Float_t avped  = 0;
+  Float_t avprms = 0;
+  Float_t avnum  = 0;
+  for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
     {
 
@@ -364,4 +367,7 @@
       const Float_t num    = TMath::Sqrt((Float_t)fPedestals->GetTotalEntries());
 
+      avped  += ped;
+      avprms += prms;
+      avnum  += num;
       //
       // set them in the calibration camera
@@ -394,4 +400,6 @@
     }
 
+
+
   //
   // The Michele check ...
@@ -404,4 +412,48 @@
   }
 
+  MCalibrationChargePix *avinnerpix = fCam->GetAverageInnerPix();
+  MCalibrationChargePix *avouterpix = fCam->GetAverageOuterPix();
+  //
+  // set the pedestans in the calibration camera
+  //
+  if (avinnerpix->IsHiGainSaturation())
+  {
+      avinnerpix->SetPedestal(avped  * fNumLoGainSamples,
+			 avprms * TMath::Sqrt((Float_t)fNumLoGainSamples),
+			 avprms * fNumLoGainSamples / avnum);
+      avinnerpix->SetNumLoGainSamples((Float_t)fNumLoGainSamples);
+      avinnerpix->ApplyLoGainConversion();
+  }
+  else
+  {
+      avinnerpix->SetPedestal(avped  * fNumHiGainSamples,
+			 avprms * TMath::Sqrt((Float_t)fNumHiGainSamples),
+			 avprms * fNumHiGainSamples / avnum);
+  }
+
+  if (avouterpix->IsHiGainSaturation())
+  {
+      avouterpix->SetPedestal(avped  * fNumLoGainSamples,
+			 avprms * TMath::Sqrt((Float_t)fNumLoGainSamples),
+			 avprms * fNumLoGainSamples / avnum);
+      avouterpix->SetNumLoGainSamples((Float_t)fNumLoGainSamples);
+      avouterpix->ApplyLoGainConversion();
+  }
+  else
+  {
+      avouterpix->SetPedestal(avped  * fNumHiGainSamples,
+			 avprms * TMath::Sqrt((Float_t)fNumHiGainSamples),
+			 avprms * fNumHiGainSamples / avnum);
+  }
+  
+  if (!avinnerpix->CheckChargeValidity() || !avinnerpix->CheckTimeValidity())
+      if (!avinnerpix->CalcReducedSigma())
+	  avinnerpix->CalcFFactorMethod();
+
+  if (!avouterpix->CheckChargeValidity() || !avouterpix->CheckTimeValidity())
+      if (!avouterpix->CalcReducedSigma())
+	  avouterpix->CalcFFactorMethod();
+
+
   if (!fBlindPixel->CheckChargeFitValidity())
   {
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 3349)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 3350)
@@ -159,5 +159,7 @@
     fTitle = title ? title : "Storage container for the Calibration Information in the camera";
 
-    fPixels     = new TClonesArray("MCalibrationChargePix",1);
+    fPixels          = new TClonesArray("MCalibrationChargePix",1);
+    fAverageInnerPix = new MCalibrationChargePix("AverageInnerPix","Container of the fit results of the camera average inner pixels");
+    fAverageOuterPix = new MCalibrationChargePix("AverageOuterPix","Container of the fit results of the camera average outer pixels");
 
     Clear();
@@ -178,5 +180,7 @@
   // 
   delete fPixels;
-
+  delete fAverageInnerPix;
+  delete fAverageOuterPix;
+  
   if (fOffsets)
     delete fOffsets;
@@ -199,10 +203,4 @@
 {
   
-  //
-  // check if we have already initialized to size
-  //
-  if (CheckBounds(i))
-    return;
-  
   fPixels->ExpandCreate(i);
 
@@ -221,13 +219,13 @@
 }
 
+
 // --------------------------------------------------------------------------
 //
-// Check if position i is inside the current bounds of the TClonesArray
-//
-Bool_t MCalibrationChargeCam::CheckBounds(Int_t i) const 
-{
-  return i < GetSize();
-} 
-
+// Get i-th pixel (pixel number)
+//
+MCalibrationChargePix &MCalibrationChargeCam::operator[](UInt_t i)
+{
+  return *static_cast<MCalibrationChargePix*>(fPixels->UncheckedAt(i));
+}
 
 // --------------------------------------------------------------------------
@@ -235,18 +233,9 @@
 // Get i-th pixel (pixel number)
 //
-MCalibrationChargePix &MCalibrationChargeCam::operator[](UInt_t i)
+const MCalibrationChargePix &MCalibrationChargeCam::operator[](UInt_t i) const
 {
   return *static_cast<MCalibrationChargePix*>(fPixels->UncheckedAt(i));
 }
 
-// --------------------------------------------------------------------------
-//
-// Get i-th pixel (pixel number)
-//
-const MCalibrationChargePix &MCalibrationChargeCam::operator[](UInt_t i) const
-{
-  return *static_cast<MCalibrationChargePix*>(fPixels->UncheckedAt(i));
-}
-
 
 // --------------------------------------
@@ -256,4 +245,6 @@
 
   fPixels->ForEach(TObject, Clear)();
+  fAverageInnerPix->Clear();
+  fAverageOuterPix->Clear();
 
   fNumExcludedPixels                 = 0;
@@ -385,4 +376,18 @@
   }
   *fLog << all << id << " Excluded pixels " << endl;
+  *fLog << endl;
+  *fLog << all << "Average Inner Pix:         " 
+		<< ":  Ped.  Rms: "            << fAverageInnerPix->GetPedRms()        << " +- " << fAverageInnerPix->GetPedRmsErr() 
+		<< "   Mean signal: "          << fAverageInnerPix->GetMeanCharge()    << " +- " << fAverageInnerPix->GetSigmaCharge() 
+		<< "   Reduced Sigma: "        << fAverageInnerPix->GetRSigmaCharge() 
+		<< "   Nr Phe's: "             << fAverageInnerPix->GetPheFFactorMethod() 
+		<< endl;
+  *fLog << all << "Average Outer Pix:         " 
+		<< ":  Ped.  Rms: "            << fAverageOuterPix->GetPedRms()        << " +- " << fAverageOuterPix->GetPedRmsErr() 
+		<< "   Mean signal: "          << fAverageOuterPix->GetMeanCharge()    << " +- " << fAverageOuterPix->GetSigmaCharge() 
+		<< "   Reduced Sigma: "        << fAverageOuterPix->GetRSigmaCharge() 
+		<< "   Nr Phe's: "             << fAverageOuterPix->GetPheFFactorMethod() 
+		<< endl;
+
 }
 
@@ -755,5 +760,10 @@
 void MCalibrationChargeCam::DrawPixelContent(Int_t idx) const
 {
-  (*this)[idx].DrawClone();
+    if (idx == -1)
+	fAverageInnerPix->DrawClone();
+    if (idx == -2)
+	fAverageOuterPix->DrawClone();
+
+    (*this)[idx].DrawClone();
 }
 
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h	(revision 3349)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h	(revision 3350)
@@ -22,4 +22,6 @@
   Int_t fNumPixels;
   TClonesArray *fPixels;                                        //-> Array of MCalibrationPix with fit results
+  MCalibrationChargePix *fAverageInnerPix;                      //-> Average Pixel of all events
+  MCalibrationChargePix *fAverageOuterPix;                      //-> Average Pixel of all events
   
   const MCalibrationChargeBlindPix *fBlindPixel;                //! Pointer to the Blind Pixel with fit results
@@ -73,6 +75,10 @@
   MCalibrationChargePix &operator[](UInt_t i);
   const MCalibrationChargePix &operator[](UInt_t i) const;
-  
-  Bool_t CheckBounds(Int_t i) const;
+
+  MCalibrationChargePix *GetAverageInnerPix()              { return fAverageInnerPix; }
+  const MCalibrationChargePix *GetAverageInnerPix() const  { return fAverageInnerPix; }
+
+  MCalibrationChargePix *GetAverageOuterPix()              { return fAverageOuterPix; }
+  const MCalibrationChargePix *GetAverageOuterPix() const  { return fAverageOuterPix; }
 
   // Prints
