Index: trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.h	(revision 3011)
+++ trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.h	(revision 3014)
@@ -33,6 +33,4 @@
     TArrayF fSumx2;  // sum of squared values
 
-    Bool_t fUseHists;
-    
     Bool_t ReInit(MParList *pList);
 
@@ -46,7 +44,4 @@
     void Clear(const Option_t *o="");
 
-    void SetUseHists(const Bool_t b = kTRUE)  {  fUseHists = b;  }
-    Bool_t IsUseHists()  const            {  return fUseHists;  }    
-    
     ClassDef(MPedCalcPedRun, 0)   // Task to calculate pedestals from pedestal runs raw data
 };
Index: trunk/MagicSoft/Mars/manalysis/MPedestalCam.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPedestalCam.cc	(revision 3011)
+++ trunk/MagicSoft/Mars/manalysis/MPedestalCam.cc	(revision 3014)
@@ -17,6 +17,7 @@
 !
 !   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
+!              Markus Gaug   02/2004 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
@@ -38,4 +39,11 @@
 #include "MLogManip.h"
 
+#include "MParList.h"
+
+#include "MHExtractedSignalPix.h"
+
+#include "MExtractedSignalCam.h"
+#include "MExtractedSignalPix.h"
+
 #include "MGeomCam.h"
 
@@ -44,4 +52,5 @@
 using namespace std;
 
+const UInt_t MPedestalCam::gkBlindPixelId = 559;
 // --------------------------------------------------------------------------
 //
@@ -49,5 +58,5 @@
 //
 MPedestalCam::MPedestalCam(const char *name, const char *title) 
-    : fNumTotSlices(0), fNumExtractSlices(0), fUseHists(kFALSE)
+    : fTotalEntries(0), fExtractSlices(0.)
 {
     fName  = name  ? name  : "MPedestalCam";
@@ -56,4 +65,12 @@
     fArray = new TClonesArray("MPedestalPix", 1);
     
+    //
+    // loop over all Pixels and create two histograms
+    // one for the Low and one for the High gain
+    // connect all the histogram with the container fHist
+    //
+    fHArray = new TObjArray;
+    fHArray->SetOwner();
+
 }
 
@@ -64,5 +81,6 @@
 MPedestalCam::~MPedestalCam()
 {
-    delete fArray;
+  delete fArray;
+  delete fHArray;
 }
 
@@ -85,6 +103,12 @@
 Int_t MPedestalCam::GetSize() const
 {
-    return fArray->GetEntriesFast();
-}
+  return fArray->GetEntriesFast();
+}
+
+Int_t MPedestalCam::GetHistSize() const 
+{
+  return fHArray->GetEntriesFast();
+}
+
 
 // --------------------------------------------------------------------------
@@ -106,18 +130,140 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Get i-th pixel (pixel number)
+//
+MHPedestalPixel &MPedestalCam::operator()(UInt_t i)
+{
+  return *static_cast<MHPedestalPixel*>(fHArray->UncheckedAt(i));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get i-th pixel (pixel number)
+//
+const MHPedestalPixel &MPedestalCam::operator()(UInt_t i) const
+{
+  return *static_cast<MHPedestalPixel*>(fHArray->UncheckedAt(i));
+}
+
+
+// -------------------------------------------------------------------------
+//
 void MPedestalCam::Clear(Option_t *o)
 {
+
     fArray->ForEach(TObject, Clear)();
-
-    fNumTotSlices     = 0;
-    fNumExtractSlices = 0;
-}
-
-void MPedestalCam::InitUseHists()
-{
-    fArray->ForEach(MPedestalPix, InitUseHists)();
-
-    fUseHists = kTRUE;
-}
+    //    fHArray->ForEach(TObject, Clear)();
+
+    fTotalEntries     = 0;
+    fExtractSlices    = 0.;
+}
+
+// --------------------------------------------------------------------------
+//
+// To setup the object we get the number of pixels from a MGeomCam object
+// in the Parameter list. 
+// MPedestalPix sets its parameters to 0. (other than default which is -1.)
+//
+Bool_t MPedestalCam::SetupFill(const MParList *pList)
+{
+
+  fArray->ForEach(MPedestalPix, InitUseHists)();
+  fHArray->Delete();
+
+  return kTRUE;
+
+}
+
+// --------------------------------------------------------------------------
+//
+Bool_t MPedestalCam::Fill(const MParContainer *par, const Stat_t w)
+{
+
+  MExtractedSignalCam *signal = (MExtractedSignalCam*)par;
+  if (!signal)
+    {
+      gLog << err << "No argument in MExtractedSignalCam::Fill... abort." << endl;
+      return kFALSE;
+    }
+  
+  Float_t slices = (Float_t)signal->GetNumUsedFADCSlices();
+
+  if (slices == 0.)
+    {
+      gLog << err << "Number of used signal slices in MExtractedSignalCam is zero  ... abort." 
+           << endl;
+      return kFALSE;
+    }
+
+  if (fExtractSlices != 0. && slices != fExtractSlices )
+    {
+      gLog << err << "Number of used signal slices changed in MExtractedSignalCam  ... abort." 
+           << endl;
+      return kFALSE;
+    }
+
+  fExtractSlices = slices;
+
+  const Int_t n = signal->GetSize();
+  
+  if (fHArray->GetEntries()==0)
+    {
+      fHArray->Expand(n);
+      
+      for (Int_t i=0; i<n; i++)
+        {
+          (*fHArray)[i] = new MHPedestalPixel;
+          MHPedestalPixel &hist = (*this)(i);
+          hist.ChangeHistId(i);
+        }
+    }
+  
+  if (fHArray->GetEntries() != n)
+    {
+      gLog << err << "ERROR - Size mismatch... abort." << endl;
+      return kFALSE;
+    }
+  
+  for (Int_t i=0; i<n; i++)
+    {
+      const MExtractedSignalPix &pix = (*signal)[i];
+      
+      const Float_t sig = pix.GetExtractedSignalHiGain();
+      const Float_t sigPerSlice = sig/fExtractSlices;
+      
+      MHPedestalPixel &hist = (*this)(i);
+
+      hist.FillCharge(sigPerSlice);
+      hist.FillChargevsN(sigPerSlice);
+    }
+  
+  return kTRUE;
+}
+
+Bool_t MPedestalCam::Finalize()
+{
+    for (Int_t i=0; i<fHArray->GetSize(); i++)
+    {
+        MHPedestalPixel &hist = (*this)(i);
+
+        //
+        // 1) Return if the charge distribution is already succesfully fitted
+        //    or if the histogram is empty
+        //
+        if (hist.IsFitOK() || hist.IsEmpty())
+            continue;
+
+        hist.CutAllEdges();
+      
+        //
+        // 2) Fit the Hi Gain histograms with a Gaussian
+        //
+        hist.FitCharge();
+    }
+    return kTRUE;
+}
+
 
 void MPedestalCam::Print(Option_t *o) const
@@ -190,5 +336,5 @@
     return kFALSE;
 
-  if (idx == 559)
+  if ((UInt_t)idx == gkBlindPixelId)
     return kFALSE;
 
@@ -196,11 +342,14 @@
   const Float_t rms      = (*this)[idx].GetPedestalRms();
 
-  const Float_t pederr   = rms/TMath::Sqrt((Float_t)fNumTotSlices);
-  const Float_t rmserr   = rms/TMath::Sqrt((Float_t)fNumTotSlices/2.);
-
-  const Float_t mean     = (*this)[idx].GetMean()     / (Float_t)fNumExtractSlices;
-  const Float_t meanerr  = (*this)[idx].GetMeanErr()  / (Float_t)fNumExtractSlices;
-  const Float_t sigma    = (*this)[idx].GetSigma()    / TMath::Sqrt((Float_t) fNumExtractSlices);
-  const Float_t sigmaerr = (*this)[idx].GetSigmaErr() / TMath::Sqrt((Float_t) fNumExtractSlices);
+  const Float_t pederr   = rms/TMath::Sqrt((Float_t)fTotalEntries);
+  const Float_t rmserr   = rms/TMath::Sqrt((Float_t)fTotalEntries/2.);
+
+  const MHPedestalPixel &hist = (*this)(idx);
+
+  const Float_t mean     = hist.GetChargeMean();
+  const Float_t meanerr  = hist.GetChargeMeanErr() * TMath::Sqrt((Float_t)fExtractSlices);
+  const Float_t sigma    = hist.GetChargeSigma()   * TMath::Sqrt((Float_t)fExtractSlices);
+  const Float_t sigmaerr = hist.GetChargeSigmaErr()* TMath::Sqrt((Float_t)fExtractSlices);
+  const Float_t prob     = hist.GetChargeProb();
 
   switch (type)
@@ -244,5 +393,5 @@
     case 8:
       //      if ((*this)[idx].IsFitValid())
-      val = (*this)[idx].GetProb();
+      val = prob;
         //      else
         //        return kFALSE;
Index: trunk/MagicSoft/Mars/manalysis/MPedestalCam.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPedestalCam.h	(revision 3011)
+++ trunk/MagicSoft/Mars/manalysis/MPedestalCam.h	(revision 3014)
@@ -2,4 +2,11 @@
 #define MARS_MPedestalCam
 
+#ifndef ROOT_TObjArray
+#include <TObjArray.h>
+#endif
+
+#ifndef MARS_MH
+#include "MH.h"
+#endif
 #ifndef MARS_MParContainer
 #include "MParContainer.h"
@@ -13,45 +20,56 @@
 class MGeomCam;
 class MPedestalPix;
+class MHPedestalPixel;
 
-class MPedestalCam : public MParContainer, public MCamEvent
+class MPedestalCam : public MH, public MCamEvent
 {
-private:
-    TClonesArray *fArray; // FIXME: Change TClonesArray away from a pointer?
 
-    ULong_t fNumTotSlices;
-    Byte_t  fNumExtractSlices;
+ private:
 
-    Bool_t fUseHists;
-    
+  static const UInt_t gkBlindPixelId;
+  
+  TClonesArray *fArray;  // FIXME: Change TClonesArray away from a pointer?
+  
+  TObjArray    *fHArray; //-> List of Lo/Hi gain Histograms
+  
+  ULong_t fTotalEntries;
+  Float_t fExtractSlices;
+  
 public:
-    MPedestalCam(const char *name=NULL, const char *title=NULL);
-    ~MPedestalCam();
+  MPedestalCam(const char *name=NULL, const char *title=NULL);
+  ~MPedestalCam();
+  
+  void Clear(Option_t *o="");
+  
+  void InitSize(const UInt_t i);
+  
+  MPedestalPix &operator[](Int_t i);
+  MPedestalPix &operator[](Int_t i) const;
+  
+  MHPedestalPixel      &operator()(UInt_t i);
+  const MHPedestalPixel &operator()(UInt_t i) const;
+  
+  Bool_t SetupFill(const MParList *pList);
+  Bool_t Fill(const MParContainer *par, const Stat_t w=1);
+  Bool_t Finalize();
+  
+  //  TObject *Clone(const char *) const;
+  
+  // Setters
+  void SetTotalEntries(ULong_t n)    { fTotalEntries = n; }
 
-    void Clear(Option_t *o="");
-    
-    void InitSize(const UInt_t i);
-
-    void InitUseHists();
-
-    MPedestalPix &operator[](Int_t i);
-    MPedestalPix &operator[](Int_t i) const;
-
-    // Setters
-    void SetNumTotSlices(ULong_t n)    { fNumTotSlices = n; }
-    void SetNumExtractSlices(Byte_t n)   { fNumExtractSlices = n; }
-
-    // Getters
-    Int_t   GetSize()                          const;
-    Float_t GetPedestalMin(const MGeomCam *cam) const;
-    Float_t GetPedestalMax(const MGeomCam *cam) const;
-    Bool_t  IsUseHists()                       const  { return fUseHists; }
-    
-    
-    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
+  // Getters
+  Int_t   GetSize()                          const;
+  Int_t   GetHistSize()                      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
 };
 
Index: trunk/MagicSoft/Mars/manalysis/MPedestalPix.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPedestalPix.cc	(revision 3011)
+++ trunk/MagicSoft/Mars/manalysis/MPedestalPix.cc	(revision 3014)
@@ -40,15 +40,9 @@
 using namespace std;
 
-MPedestalPix::MPedestalPix() : fHist(NULL), fFlags(0)
+MPedestalPix::MPedestalPix()
 {
   Clear();
 }
 
-MPedestalPix::~MPedestalPix()
-{
-  if (fHist)
-    delete fHist;
-}
-  
 
 // ------------------------------------------------------------------------
@@ -61,12 +55,4 @@
   fPedestalRms = -1.;
 
-  fMean       = -1.;
-  fMeanErr    = -1.;
-  fSigma      = -1.;
-  fProb       = -1.;
-
-  CLRBIT(fFlags,kFitted);
-  CLRBIT(fFlags,kFitValid);  
-
 }
 
@@ -75,20 +61,4 @@
   fPedestal = 0.;
   fPedestalRms = 0.;
-
-  fHist = new MHPedestalPixel("MHPedestalPixel","Pedestal Histograms Pixel ");
-
-  if (!fHist)
-    *fLog << warn << dbginf << " Could not create MHCalibrationPixel " << endl;
-
-}
-
-void MPedestalPix::FillHists(const Float_t f)
-{
-
-  if (!fHist)
-    return;
-  
-  fHist->FillCharge(f);
-  fHist->FillChargevsN(f);
 }
 
@@ -105,68 +75,2 @@
 }
 
-Bool_t MPedestalPix::IsFitted() const 
-{
-  return TESTBIT(fFlags,kFitted);
-}
-
-Bool_t MPedestalPix::IsFitValid() const 
-{
-  return TESTBIT(fFlags,kFitValid);
-}
-
-// --------------------------------------------------------------------------
-//
-// 1) Return if the charge distribution is already succesfully fitted  
-//    or if the histogram is empty
-// 2) Cut the histograms empty edges
-// 3) Fit the histograms with a Gaussian
-// 4) In case of failure print out the fit results
-// 5) Retrieve the results and store them in this class
-//
-void MPedestalPix::FitCharge()
-{
-  
-  //
-  // 1) Return if the charge distribution is already succesfully fitted  
-  //    or if the histogram is empty
-  //
-  if (fHist->IsFitOK() || fHist->IsEmpty())
-    return;
-
-
-  fHist->CutAllEdges();
-      
-  //
-  // 2) Fit the Lo Gain histograms with a Gaussian
-  //
-  if(fHist->FitCharge())
-    SETBIT(fFlags,kFitted);
-  else
-    CLRBIT(fFlags,kFitted);
-
-  //
-  // 6) Retrieve the results and store them in this class
-  //
-  fMean         = fHist->GetChargeMean();
-  fMeanErr      = fHist->GetChargeMeanErr(); 
-  fSigma        = fHist->GetChargeSigma();
-  fSigmaErr     = fHist->GetChargeSigmaErr();
-  fProb         = fHist->GetChargeProb();
-
-  if (CheckFitValidity())
-    SETBIT(fFlags,kFitValid);
-  else
-    CLRBIT(fFlags,kFitValid);
-
-  return;
-}
-
-Bool_t MPedestalPix::CheckFitValidity()
-{
-  
-  if (fProb < 0.001)
-    return kFALSE;
-  
-  return kTRUE;
-  
-}
Index: trunk/MagicSoft/Mars/manalysis/MPedestalPix.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPedestalPix.h	(revision 3011)
+++ trunk/MagicSoft/Mars/manalysis/MPedestalPix.h	(revision 3014)
@@ -18,19 +18,7 @@
   Float_t fPedestalRms;  // root mean square / sigma  / standard deviation of pedestal
 
-  MHPedestalPixel *fHist; // Pointer to the histograms performing the fits, etc.      
-  
-  Float_t fMean;
-  Float_t fMeanErr;
-  Float_t fSigma;
-  Float_t fSigmaErr;
-  Float_t fProb;
-  
-  Byte_t fFlags;
-  
-  enum   { kFitted, kFitValid };
   
 public:
   MPedestalPix();
-  ~MPedestalPix();
   
   void Clear(Option_t *o="");
@@ -38,5 +26,4 @@
   // Using histograms
   void InitUseHists();
-  void FillHists(const Float_t f);
   
     // Setters
@@ -47,27 +34,9 @@
   
   // Getters
-  MHPedestalPixel *GetHist() const { return fHist; } 
-
   Float_t GetPedestal()    const { return fPedestal; }
   Float_t GetPedestalRms() const { return fPedestalRms; }
   
-  Float_t GetMean()        const { return fMean;     }
-  Float_t GetMeanErr()     const { return fMeanErr;  }
-  Float_t GetSigma()       const { return fSigma;    }
-  Float_t GetSigmaErr()    const { return fSigmaErr; }
-  Float_t GetProb()        const { return fProb;     }
-  
   Bool_t IsValid()         const;
-  Bool_t IsFitted()        const;
-  Bool_t IsFitValid()      const;
-  
-  // Fits
-  void FitCharge();   
-  Bool_t CheckFitValidity();
-  
-  // Draws
-  void Draw(Option_t *opt="")                 { fHist->Draw(opt); }
-  TObject *DrawClone(Option_t *opt="") const { return fHist->DrawClone(opt); }  
-  
+
   ClassDef(MPedestalPix, 1)	// Storage Container for Pedestal information of one pixel
 };
