Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindCam.cc	(revision 4985)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindCam.cc	(revision 4986)
@@ -40,9 +40,12 @@
 #include "MLogManip.h"
 
-#include "MCalibrationChargeBlindPix.h"
-#include "MCalibrationChargeBlindCam.h"
+#include "MRawEvtData.h"
+#include "MRawEvtPixelIter.h"
 
 #include "MExtractedSignalBlindPixel.h"
 
+#include "MCalibrationBlindPix.h"
+#include "MCalibrationIntensityBlindCam.h"
+
 #include "MParList.h"
 
@@ -52,5 +55,12 @@
 
 using namespace std;
-
+const Int_t     MHCalibrationChargeBlindCam::fgNbins    =  128;
+const Axis_t    MHCalibrationChargeBlindCam::fgFirst    = -0.5;
+const Axis_t    MHCalibrationChargeBlindCam::fgLast     =  511.5;
+const Axis_t    MHCalibrationChargeBlindCam::fgSPheCut  =  20.;
+const TString   MHCalibrationChargeBlindCam::gsHistName   = "ChargeBlind";
+const TString   MHCalibrationChargeBlindCam::gsHistTitle  = "Signals Blind ";
+const TString   MHCalibrationChargeBlindCam::gsHistXTitle = "Signal [FADC counts]";
+const TString   MHCalibrationChargeBlindCam::gsHistYTitle = "Nr. events";
 // --------------------------------------------------------------------------
 //
@@ -60,11 +70,22 @@
 // - all pointers to NULL
 //
-// Initializes and sets owner of:
-// - fBlindPixelsArray
+// - fFitFunc to kEPoisson4
+// - fNbins   to fgNbins
+// - fFirst   to fgFirst
+// - fLast    to fgLast 
+// - fSPheCut to fgSPheCut
 // 
-// Sets fFitFunc to kEPoisson4
+// - fHistName   to gsHistName  
+// - fHistTitle  to gsHistTitle 
+// - fHistXTitle to gsHistXTitle
+// - fHistYTitle to gsHistYTitle
+//
+// - SetAverageing  (kFALSE);
+// - SetLoGain      (kFALSE);
+// - SetOscillations(kFALSE);
+// - SetSizeCheck   (kFALSE);
 //
 MHCalibrationChargeBlindCam::MHCalibrationChargeBlindCam(const char *name, const char *title)
-    :  fCam(NULL), fRunHeader(NULL)
+    : fRawEvt(NULL)
 {
 
@@ -72,38 +93,316 @@
   fTitle = title ? title : "Class to fille the blind pixel histograms";
 
-  fBlindPixelsArray = new TObjArray;
-  fBlindPixelsArray->SetOwner();
-
-  fFitFunc = MHCalibrationChargeBlindPix::kEPoisson4;
-
-}
-
-// --------------------------------------------------------------------------
-//
-// Deletes the TClonesArray of:
-// - fBlindPixelsArray
-//
-MHCalibrationChargeBlindCam::~MHCalibrationChargeBlindCam()
-{
-  delete fBlindPixelsArray;
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th High Gain pixel (pixel number)
-//
-MHCalibrationChargeBlindPix &MHCalibrationChargeBlindCam::operator[](UInt_t i)
-{
-  return *static_cast<MHCalibrationChargeBlindPix*>(fBlindPixelsArray->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Get i-th High Gain pixel (pixel number)
-//
-const MHCalibrationChargeBlindPix &MHCalibrationChargeBlindCam::operator[](UInt_t i) const
-{
-  return *static_cast<MHCalibrationChargeBlindPix*>(fBlindPixelsArray->UncheckedAt(i));
-}
+  SetFitFunc();
+  SetSPheCut();
+
+  SetNbins(fgNbins);
+  SetFirst(fgFirst);
+  SetLast (fgLast );
+
+  SetHistName  (gsHistName  .Data());
+  SetHistTitle (gsHistTitle .Data());
+  SetHistXTitle(gsHistXTitle.Data());
+  SetHistYTitle(gsHistYTitle.Data());
+
+  SetAverageing  (kFALSE);
+  SetLoGain      (kFALSE);
+  SetOscillations(kFALSE);
+  SetSizeCheck   (kFALSE);
+}
+
+// --------------------------------------------------------------------------
+//
+// Gets the pointers to:
+// - MRawEvtData
+//
+Bool_t MHCalibrationChargeBlindCam::SetupHists(const MParList *pList)
+{
+
+  fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
+  if (!fRawEvt)
+  {
+      *fLog << err << dbginf << "MRawEvtData not found... aborting." << endl;
+      return kFALSE;
+  }
+
+  return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Gets or creates the pointers to:
+// - MExtractedSignalBlindPixel
+// - MCalibrationChargeCam or MCalibrationIntensityBlindCam
+//
+// Initializes the number of used FADC slices from MExtractedSignalCam 
+// into MCalibrationChargeCam and test for changes in that variable
+//
+// Retrieve:
+// - fRunHeader->GetNumSamplesHiGain();
+//
+// Initializes the High Gain Arrays:
+//
+// - Expand fHiGainArrays to nblindpixels
+// 
+// - 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 from fHistXTitle and fHistYTitle
+//   * Call InitHists
+//
+Bool_t MHCalibrationChargeBlindCam::ReInitHists(MParList *pList)
+{
+
+  MExtractedSignalBlindPixel *signal = 
+    (MExtractedSignalBlindPixel*)pList->FindObject(AddSerialNumber("MExtractedSignalBlindPixel"));
+  if (!signal)
+  {
+      *fLog << err << "MExtractedSignalBlindPixel not found... abort." << endl;
+      return kFALSE;
+  }
+
+  fIntensCam = (MCalibrationIntensityCam*)pList->FindObject(AddSerialNumber("MCalibrationIntensityBlindCam"));
+  if (fIntensCam)
+    *fLog << inf << "Found MCalibrationIntensityBlindCam ... " << endl;
+  else
+    {
+      fCam = (MCalibrationCam*)pList->FindObject(AddSerialNumber("MCalibrationBlindCam"));
+      if (!fCam)
+        {
+          fCam = (MCalibrationCam*)pList->FindCreateObj(AddSerialNumber("MCalibrationBlindCam"));
+          if (!fCam)
+            {
+              *fLog << err << "Cannot find nor create MCalibrationBlindCam ... abort." << endl;
+              return kFALSE;
+            }
+        }
+    }
+
+  const Int_t nblindpixels = signal->GetNumBlindPixels();
+  const Int_t samples      = signal->GetNumFADCSamples();
+  const Int_t integ        = signal->IsExtractionType( MExtractBlindPixel::kIntegral );
+  
+  TH1F *h;
+
+  if (fHiGainArray->GetEntries()==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 "));
+
+        MHCalibrationChargeBlindPix &pix = (MHCalibrationChargeBlindPix&)(*this)[i];
+
+        pix.SetNbins        ( fNbins );
+        pix.SetFirst        ( fFirst );
+        pix.SetLast         ( integ ? ((fLast+0.5)*samples)-0.5 : fLast    );
+        pix.SetSinglePheCut ( integ ? fSPheCut * samples        : fSPheCut );
+        pix.SetFitFunc      ( integ ? 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;
+}
+
+// --------------------------------------------------------------------------
+//
+// Retrieves from MExtractedSignalBlindPixel:
+// - number of blind pixels
+//
+// Retrieves from MExtractedSignalBlindPixel:
+// - number of FADC samples
+// - extracted signal 
+// - blind Pixel ID
+//
+// Resizes (if necessary):
+// - fASinglePheFADCSlices to sum of HiGain and LoGain samples
+// - fAPedestalFADCSlices to sum of HiGain and LoGain samples
+//
+// Fills the following histograms:
+// - MHGausEvents::FillHistAndArray(signal)
+//
+// Creates MRawEvtPixelIter, jumps to blind pixel ID, 
+// fills the vectors fASinglePheFADCSlices and fAPedestalFADCSlices 
+// with the full FADC slices, depending on the size of the signal w.r.t. fSinglePheCut
+//
+Bool_t MHCalibrationChargeBlindCam::FillHists(const MParContainer *par, const Stat_t w)
+{
+
+  MExtractedSignalBlindPixel *signal = (MExtractedSignalBlindPixel*)par;
+  if (!signal)
+    {
+      *fLog << err << "No argument in MExtractedSignalBlindCam::Fill... abort." << endl;
+      return kFALSE;
+    }
+  
+  const Int_t nblindpixels  = signal->GetNumBlindPixels();
+  
+  if (GetSize() != nblindpixels)
+    {
+      gLog << err << "ERROR - Size mismatch... abort." << endl;
+      return kFALSE;
+    }
+
+  Float_t slices = (Float_t)signal->GetNumFADCSamples();
+  
+  if (slices == 0.)
+    {
+      *fLog << err << dbginf
+	    << "Number of used signal slices in MExtractedSignalBlindPix "
+	    << "is zero  ... abort." 
+            << endl;
+      return kFALSE;
+    }
+  
+  for (Int_t i=0; i<nblindpixels; i++)
+    {
+
+      //
+      // Signal extraction and histogram filling
+      // If filter has been applied, sig has been set to -1.
+      //
+      const Float_t sig = signal->GetExtractedSignal(i);
+      
+      if (sig < -0.5)
+        continue;
+
+      MHCalibrationChargeBlindPix &hist = (MHCalibrationChargeBlindPix&)(*this)[i];
+
+      hist.FillHist(sig);
+      //
+      // In order to study the single-phe posistion, we extract the slices
+      //
+      const Int_t blindpixIdx = signal->GetBlindPixelIdx(i);
+      
+      MRawEvtPixelIter pixel(fRawEvt);
+      pixel.Jump(blindpixIdx);
+      
+      if (sig > fSPheCut)
+        hist.FillSinglePheFADCSlices(pixel);
+      else
+        hist.FillPedestalFADCSlices(pixel);
+
+    }
+
+  return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// For all TObjArray's (including the averaged ones), the following steps are performed: 
+//
+// 1) Returns if the pixel is excluded.
+// 2) Tests saturation. In case yes, set the flag: MCalibrationPix::SetHiGainSaturation()
+//    or the flag: MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainSaturated )
+// 3) Store the absolute arrival times in the MCalibrationChargePix's. If flag 
+//    MCalibrationPix::IsHiGainSaturation() is set, the Low-Gain arrival times are stored, 
+//    otherwise the Hi-Gain ones.
+// 4) Calls to MHCalibrationCam::FitHiGainArrays() and MCalibrationCam::FitLoGainArrays() 
+//    with the flags:
+//    - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainNotFitted )
+//    - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainNotFitted )
+//    - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kHiGainOscillating )
+//    - MBadPixelsPix::SetUncalibrated( MBadPixelsPix::kLoGainOscillating )
+//
+Bool_t MHCalibrationChargeBlindCam::FinalizeHists()
+{
+
+  *fLog << endl;
+
+  for (Int_t i=0; i<fHiGainArray->GetSize(); i++)
+    {
+      
+      MHCalibrationChargeBlindPix &hist = (MHCalibrationChargeBlindPix&)(*this)[i];
+      
+      TH1F *h = hist.GetHGausHist();
+
+      Stat_t overflow = h->GetBinContent(h->GetNbinsX()+1);
+      if (overflow > 0.1)
+        {
+          *fLog << warn << GetDescriptor()
+                << ": Histogram Overflow occurred " << overflow 
+                << " times in blind pixel: " << i << endl;
+        }
+
+      overflow = h->GetBinContent(0);
+      if (overflow > 0.1)
+        {
+          *fLog << warn << GetDescriptor()
+                << ": Histogram Underflow occurred " << overflow
+                << " times in blind pixel: " << i << endl;
+        }
+
+      MCalibrationBlindPix  &pix    = fIntensCam 
+        ? (MCalibrationBlindPix&)(*fIntensCam)[i] 
+        : (MCalibrationBlindPix&)(*fCam)[i];
+
+      FitBlindPixel(hist,pix);
+    }
+
+  return kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Returns kFALSE, if empty
+//
+// - Creates the fourier spectrum and sets bit MHGausEvents::IsFourierSpectrumOK()
+// - Retrieves the pedestals from MExtractedSignalBlindPixel
+// - Normalizes fASinglePheFADCSlices and fAPedestalFADCSlices
+// - Executes FitPedestal()
+// - Executes FitSinglePhe()
+// - Retrieves fit results and stores them in MCalibrationBlindPix
+// 
+void MHCalibrationChargeBlindCam::FitBlindPixel(MHCalibrationChargeBlindPix &hist, MCalibrationBlindPix &pix)
+{
+
+  if (hist.IsEmpty())
+  {
+    *fLog << err << GetDescriptor() << " ID: " << hist.GetPixId()
+	  << " My histogram has not been filled !! " << endl;
+      return;
+  }
+
+  hist.FinalizeSinglePheSpectrum();
+  
+  hist.FitPedestal();
+
+  pix.SetValid(kTRUE);
+
+  if (hist.FitSinglePhe())
+    pix.SetSinglePheFitOK();
+  else
+    pix.SetValid(hist.IsPedestalFitOK());
+
+  pix.SetLambda      ( hist.GetLambda   () );
+  pix.SetLambdaVar   ( hist.GetLambdaErr()*hist.GetLambdaErr() );
+  pix.SetMu0         ( hist.GetMu0      () );
+  pix.SetMu0Err      ( hist.GetMu0Err   () );
+  pix.SetMu1         ( hist.GetMu1      () );
+  pix.SetMu1Err      ( hist.GetMu1Err   () );
+  pix.SetSigma0      ( hist.GetSigma0   () );
+  pix.SetSigma0Err   ( hist.GetSigma0Err() );
+  pix.SetSigma1      ( hist.GetSigma1   () );
+  pix.SetSigma1Err   ( hist.GetSigma1Err() );
+  pix.SetProb        ( hist.GetProb     () );
+
+  pix.SetLambdaCheck    ( hist.GetLambdaCheck()    );
+  pix.SetLambdaCheckErr ( hist.GetLambdaCheckErr() );
+}
+
 
 // --------------------------------------------------------------------------
@@ -118,6 +417,4 @@
 {
 
-  const Int_t nhi   = fBlindPixelsArray->GetEntries();
-  
   //
   // FIXME, this might be done faster and more elegant, by direct copy.
@@ -125,160 +422,24 @@
   MHCalibrationChargeBlindCam *cam = new MHCalibrationChargeBlindCam();
 
-  cam->fBlindPixelsArray->Expand(nhi);
+  //
+  // 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->GetEntries();
+  
+  cam->fHiGainArray->Expand(nhi);
 
   for (int i=0; i<nhi; i++)
-    (*cam->fBlindPixelsArray)[i] = (*fBlindPixelsArray)[i]->Clone();
+    (*cam->fHiGainArray)[i] = (*fHiGainArray)[i]->Clone();
 
   return cam;
 }
-
-// --------------------------------------------------------------------------
-//
-// Gets the pointers to:
-// - MRunHeader
-// - MExtractedSignalBlindPix
-//
-// Calls Delete-Function of:
-// - MHCalibrationChargeBlindCam::fBlindPixelsArray
-//
-Bool_t MHCalibrationChargeBlindCam::SetupFill(const MParList *pList)
-{
-  
-  fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
-  if (!fRunHeader)
-  {
-    *fLog << warn << GetDescriptor() 
-          << ": MRawRunHeader not found... will not store run numbers." << endl;
-    return kFALSE;
-  }
-
-  fSignal  = (MExtractedSignalBlindPixel*)pList->FindObject("MExtractedSignalBlindPixel");
-  if (!fSignal)
-    {
-      *fLog << err << "MExtractedSignalBlindPixel not found... aborting " << endl;
-      return kFALSE;
-    }
-
-  return kTRUE;
-}
-
-
-// --------------------------------------------------------------------------
-//
-// Initializes, if empty to MExtractedSignalCam::GetSize() for:
-// - MHCalibrationChargeBlindCam::fBlindPixelsArray
-//
-// Calls InitializeHists() for every entry in:
-// - MHCalibrationChargeBlindCam::fBlindPixelsArray
-//
-// Retrieves the run numbers from MRawRunHeader and stores them in fRunNumbers
-//
-Bool_t MHCalibrationChargeBlindCam::ReInit(MParList *pList)
-{
-
-  const UInt_t nblindpixels  = fSignal->GetNumBlindPixels();
-
-  Int_t runnr = 0;
-
-  if (fRunHeader)
-    runnr = fRunHeader->GetRunNumber();
-
-  fCam = (MCalibrationChargeBlindCam*)pList->FindCreateObj("MCalibrationChargeBlindCam");
-  if (!fCam)
-    {
-      *fLog << err << "Cannot find nor create MCalibrationChargeBlindCam ... abort." << endl;
-      return kFALSE;
-    }
-
-  if (fCam->GetNumBlindPixels() != nblindpixels)
-    {
-        *fLog << err;
-        *fLog << "Size mismatch in MCalibrationChargeBlindCam ... abort." << endl;
-        *fLog << "  Size of MCalibrationChargeBlindCam: " << fCam->GetNumBlindPixels() << endl;
-        *fLog << "  Size of MExtractedSignalBlindPixel: " << nblindpixels << endl;
-      return kFALSE;
-    }
-  
-
-  const Int_t samples = fSignal->GetNumFADCSamples();
-  const Int_t integ   = fSignal->IsExtractionType( MExtractBlindPixel::kIntegral );
-
-  if (fBlindPixelsArray->GetEntries()==0)
-  {
-
-      fBlindPixelsArray->Expand(nblindpixels);
-
-      for (UInt_t i=0; i<nblindpixels; i++)
-	{
-	  (*fBlindPixelsArray)[i] = new MHCalibrationChargeBlindPix;
-	  (*this)[i].ChangeHistId(i);
-	  if (integ)
-	    {
-	      (*this)[i].SetLast( samples * integ * 
-				  ((*this)[i].GetLast()+0.5) - 0.5 );
-	      (*this)[i].SetSinglePheCut( samples * integ *
-					  (*this)[i].GetSinglePheCut() );
-	    }
-	  (*this)[i].InitBins();
-	  TH1F *h = (*this)[i].GetHGausHist();
-	  h->SetTitle( Form("%s%s", h->GetTitle()," Runs: "));
-          (*this)[i].ChangeFitFunc(fFitFunc);
-	  (*this)[i].SetupFill(pList);
-	  (*this)[i].SetCalibrationChargeBlindPix(&(*fCam)[i]);
-      }
-  }
-
-  for (UInt_t i=0; i<nblindpixels; i++)
-    {
-      TH1F *h = (*this)[i].GetHGausHist();
-      h->SetTitle( Form("%s%i%s", h->GetTitle(),runnr," "));
-    }
-
-  return kTRUE;
-}
-
-
-//--------------------------------------------------------------------------------
-//
-// Retrieves from MExtractedSignalBlindPixel:
-// - number of blind pixels
-//
-// For all TObjArray's, the following steps are performed: 
-//
-// 1) Test size and return kFALSE if not matching
-// 2) 
-//
-Bool_t MHCalibrationChargeBlindCam::Fill(const MParContainer *par, const Stat_t w)
-{
-
-  const Int_t nblindpixels  = fSignal->GetNumBlindPixels();
-  
-  if (GetSize() != nblindpixels)
-    {
-      gLog << err << "ERROR - Size mismatch... abort." << endl;
-      return kFALSE;
-    }
-  
-  for (Int_t i=0; i<nblindpixels; i++)
-    (*this)[i].Fill(par,w);
-
-  return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Calls the Finalize() function of the blind pixels
-//
-Bool_t MHCalibrationChargeBlindCam::Finalize()
-{
-
-  for (Int_t i=0; i<GetSize(); i++)
-    if (!(*this)[i].Finalize())
-      return kFALSE;
-
-  return kTRUE;
-}
-
-
 
 // -----------------------------------------------------------------------------
@@ -293,5 +454,5 @@
 {
 
-  const Int_t size = fBlindPixelsArray->GetEntries();
+  const Int_t size = fHiGainArray->GetEntries();
 
   if (size == 0)
@@ -330,2 +491,27 @@
 
 }
+
+Int_t MHCalibrationChargeBlindCam::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+
+  Bool_t rc = kFALSE;
+
+  if (MHCalibrationCam::ReadEnv(env,prefix,print))
+    rc = kTRUE;
+  
+  if (IsEnvDefined(env, prefix, "SPheCut", print))
+    {
+      SetSPheCut(GetEnvValue(env, prefix, "SPheCut", fSPheCut));
+      rc = kTRUE;
+    }
+  
+  // FIXME: GetEnvValue does not work with enums yet
+  /*
+  if (IsEnvDefined(env, prefix, "FitFunc", print))
+    {
+      SetFitFunc((Int_t)GetEnvValue(env, prefix, "FitFunc", fFitFunc));
+      rc = kTRUE;
+  }
+  */
+  return rc;
+}
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindCam.h
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindCam.h	(revision 4985)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindCam.h	(revision 4986)
@@ -2,37 +2,54 @@
 #define MARS_MHCalibrationChargeBlindCam
 
-#ifndef MARS_MH
-#include "MH.h"
-#endif
-#ifndef MARS_MHCalibrationChargeBlindPix
-#include "MHCalibrationChargeBlindPix.h"
+#ifndef MARS_MHCalibrationCam
+#include "MHCalibrationCam.h"
 #endif
 
-class TObjArray;
-class MRawRunHeader;
-class MExtractedSignalBlindPixel;
-class MCalibrationChargeBlindCam;
+class MRawEvtData;
+class MCalibrationBlindPix;
 class MHCalibrationChargeBlindPix;
-class MHCalibrationChargeBlindCam : public MH
+class MHCalibrationChargeBlindCam : public MHCalibrationCam
 {
 private:
 
-  MExtractedSignalBlindPixel *fSignal;     //!  Extracted Signal class
-  MCalibrationChargeBlindCam *fCam;        //!  Calibration Cam with the results
-  MRawRunHeader              *fRunHeader;  //!  Run Header
+  static const Int_t   fgNbins;        //! Default for fNBins new style blind pixel (now set to:  128   )
+  static const Axis_t  fgFirst;        //! Default for fFirst new style blind pixel (now set to: - 0.5 )
+  static const Axis_t  fgLast;         //! Default for fLast  new style blind pixel (now set to: 511.5 )
+
+  static const Axis_t  fgSPheCut;      //! Default for fSinglePheCut new style blind pixel (now set to: 20)
   
-  TObjArray *fBlindPixelsArray;            // Array of calibration pixels, one per pixel
+  static const TString gsHistName;     //! Default Histogram names
+  static const TString gsHistTitle;    //! Default Histogram titles
+  static const TString gsHistXTitle;   //! Default Histogram x-axis titles
+  static const TString gsHistYTitle;   //! Default Histogram y-axis titles
+  
+  Axis_t fSPheCut;                    // Signal value upon which event considered as single-phe
+  
+  MRawEvtData *fRawEvt;                 //!  Raw event data
 
-  MHCalibrationChargeBlindPix::FitFunc_t fFitFunc;
+public:
+
+  enum FitFunc_t { kEPoisson4, kEPoisson5,
+                   kEPoisson6, kEPoisson7,
+                   kEPolya, kEMichele }; // Possible fit functions types (see MHCalibrationChargeBlindPix)
+  
+  static const FitFunc_t fgFitFunc = kEPoisson4;    //! Default for fFitFunc
+
+private:
+
+  FitFunc_t fFitFunc;                 // The actual fit function type
+  
+  Bool_t SetupHists   (const MParList *pList );
+  Bool_t ReInitHists  (      MParList *pList );
+  Bool_t FillHists    (const MParContainer *par, const Stat_t w=1 );
+  Bool_t FinalizeHists();
+
+  void   FitBlindPixel( MHCalibrationChargeBlindPix &hist, MCalibrationBlindPix &pix);
+
+  Int_t ReadEnv        ( const TEnv &env, TString prefix, Bool_t print);  
   
 public:
 
   MHCalibrationChargeBlindCam(const char *name=NULL, const char *title=NULL);
-  ~MHCalibrationChargeBlindCam();
-
-  Bool_t SetupFill( const MParList *pList);
-  Bool_t ReInit   (       MParList *pList);
-  Bool_t Fill     ( const MParContainer *par, const Stat_t w=1);
-  Bool_t Finalize ( );
 
   // Clone
@@ -40,12 +57,7 @@
   
   // Draw
-  void   Draw(Option_t *opt="");
-  
-  const Int_t GetSize() const  { return fBlindPixelsArray->GetSize(); }
-  
-        MHCalibrationChargeBlindPix &operator[] (UInt_t i);
-  const MHCalibrationChargeBlindPix &operator[] (UInt_t i)  const;
-
-  void   SetFitFunc(const MHCalibrationChargeBlindPix::FitFunc_t func)  { fFitFunc = func;  }  
+  void  Draw(Option_t *opt="");
+  void  SetFitFunc( const FitFunc_t func=fgFitFunc)  { fFitFunc = func;  }
+  void  SetSPheCut( const Axis_t a=fgSPheCut )  { fSPheCut = a;  }    
   
   ClassDef(MHCalibrationChargeBlindCam, 1)	// Histogram class for Blind Pixel Calibration
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindPix.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindPix.cc	(revision 4985)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindPix.cc	(revision 4986)
@@ -32,5 +32,5 @@
 //  Performs the Single Photo-electron fit to extract the Poisson mean and its errors.
 //
-//  Different fits can be chosen with the function ChangeFitFunc().
+//  Different fits can be chosen with the function SetFitFunc().
 //
 //  The fit result is accepted under the condition that:
@@ -69,5 +69,5 @@
 //////////////////////////////////////////////////////////////////////////////
 #include "MHCalibrationChargeBlindPix.h"
-#include "MExtractBlindPixel.h"
+#include "MHCalibrationChargeBlindCam.h"
 
 #include <TStyle.h>
@@ -88,9 +88,5 @@
 #include "MParList.h"
 
-#include "MRawEvtData.h"
 #include "MRawEvtPixelIter.h"
-
-#include "MExtractedSignalBlindPixel.h"
-#include "MCalibrationChargeBlindPix.h"
 
 ClassImp(MHCalibrationChargeBlindPix);
@@ -101,9 +97,4 @@
 const Double_t MHCalibrationChargeBlindPix::gkElectronicAmpErr   = 0.002;
 const Float_t  MHCalibrationChargeBlindPix::gkSignalInitializer  = -9999.;
-
-const Int_t    MHCalibrationChargeBlindPix::fgChargeNbins        = 128;
-const Axis_t   MHCalibrationChargeBlindPix::fgChargeFirst        = -0.5;
-const Axis_t   MHCalibrationChargeBlindPix::fgChargeLast         = 511.5;
-const Float_t  MHCalibrationChargeBlindPix::fgSinglePheCut       =  20.;
 const Float_t  MHCalibrationChargeBlindPix::fgNumSinglePheLimit  =  50.;
 // --------------------------------------------------------------------------
@@ -112,15 +103,6 @@
 //
 // Sets: 
-// - the default number for fNbins        (fgChargeNbins)
-// - the default number for fFirst        (fgChargeFirst)
-// - the default number for fLast         (fgChargeLast)
-// - the default number for fSinglePheCut (fgSingePheCut)
 // - the default number for fNumSinglePheLimit (fgNumSinglePheLimit)
 // - the default number of bins after stripping (30)
-//
-// - the default name of the  fHGausHist ("HCalibrationChargeBlindPix")
-// - the default title of the fHGausHist ("Distribution of Summed FADC slices Blind Pixel ")
-// - the default x-axis title for fHGausHist ("Sum FADC Slices")
-// - the default y-axis title for fHGausHist ("Nr. of events")
 //
 // Initializes:
@@ -128,5 +110,4 @@
 // - fASinglePheFADCSlices(0);
 // - fAPedestalFADCSlices(0);
-// - fPixId to 0
 //
 // Calls:
@@ -134,6 +115,5 @@
 //
 MHCalibrationChargeBlindPix::MHCalibrationChargeBlindPix(const char *name, const char *title)
-    :  fBlindPix(NULL), fSignal(NULL), fRawEvt(NULL), 
-       fSinglePheFit(NULL), 
+    :  fSinglePheFit(NULL), 
        fFitLegend(NULL),
        fHSinglePheFADCSlices(NULL), fHPedestalFADCSlices(NULL)
@@ -143,22 +123,10 @@
     fTitle = title ? title : "Statistics of the FADC sums of Blind Pixel calibration events";
 
-    SetNbins( fgChargeNbins );
-    SetFirst( fgChargeFirst );
-    SetLast ( fgChargeLast  );
-    
     fASinglePheFADCSlices.ResizeTo(1);
     fAPedestalFADCSlices.ResizeTo(1);
 
-    SetSinglePheCut();
     SetNumSinglePheLimit();
     SetProbLimit(0.001);
     SetBinsAfterStripping(0);
-
-    fHGausHist.SetName("HCalibrationChargeBlindPix");
-    fHGausHist.SetTitle("Distribution of Summed FADC slices Blind Pixel");  
-    fHGausHist.SetXTitle("Signal Amplitude");
-    fHGausHist.SetYTitle("Nr. of events");
-
-    fPixId     = 0;
 
     Clear();
@@ -224,6 +192,5 @@
   fLambdaCheckErr = gkSignalInitializer;
   
-  //  fFitFunc = kEMichele;
-  fFitFunc = kEPoisson5;
+  fFitFunc = MHCalibrationChargeBlindCam::kEPoisson5;
 
   fNumSinglePhes    = 0;
@@ -356,8 +323,4 @@
   pix.fNDF            = fNDF;              
   pix.fProb           = fProb;             
-  pix.fMeanPedestal   = fMeanPedestal;     
-  pix.fSigmaPedestal  = fSigmaPedestal;    
-  pix.fMeanPedestalErr  = fMeanPedestalErr;  
-  pix.fSigmaPedestalErr = fSigmaPedestalErr; 
 
   return &pix;
@@ -427,159 +390,9 @@
 // --------------------------------------------------------------------------
 //
-// Gets the pointers to:
-// - MRawEvtData
-// - MExtractedSignalBlindPixel
+// Normalizes fASinglePheFADCSlices and fAPedestalFADCSlices
 // 
-Bool_t MHCalibrationChargeBlindPix::SetupFill(const MParList *pList) 
-{
-
-  fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
-  if (!fRawEvt)
-    {
-      *fLog << err << "MRawEvtData not found... aborting." << endl;
-      return kFALSE;
-    }
-  
-  fSignal  = (MExtractedSignalBlindPixel*)pList->FindObject("MExtractedSignalBlindPixel");
-  if (!fSignal)
-    {
-      *fLog << err << "MExtractedSignalBlindPixel not found... aborting " << endl;
-      return kFALSE;
-    }
-  
-  return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Gets or creates the pointers to:
-// - MCalibrationChargeBlindPix
-//
-// Calls:
-// - MHGausHist::InitBins()
-//
-Bool_t MHCalibrationChargeBlindPix::ReInit(MParList *pList)
-{
-
-  fBlindPix = (MCalibrationChargeBlindPix*)pList->FindCreateObj("MCalibrationChargeBlindPix");
-  if (!fBlindPix)
-      return kFALSE;
-
-  const Int_t samples = fSignal->GetNumFADCSamples();
-  const Int_t integ   = fSignal->IsExtractionType( MExtractBlindPixel::kIntegral );
-
-  //
-  // Modify the histogram size in case, integrals have been used
-  //
-  if ( fLast < samples*integ*fgChargeLast )
-    {
-      SetLast        ( samples * (fgChargeLast+0.5) - 0.5 );
-      SetSinglePheCut( samples * fgSinglePheCut );
-    }
-
-  MHCalibrationPix::InitBins();
-  
-  return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Retrieves from MExtractedSignalBlindPixel:
-// - number of FADC samples
-// - extracted signal 
-// - blind Pixel ID
-//
-// Resizes (if necessary):
-// - fASinglePheFADCSlices to sum of HiGain and LoGain samples
-// - fAPedestalFADCSlices to sum of HiGain and LoGain samples
-//
-// Fills the following histograms:
-// - MHGausEvents::FillHistAndArray(signal)
-//
-// Creates MRawEvtPixelIter, jumps to blind pixel ID, 
-// fills the vectors fASinglePheFADCSlices and fAPedestalFADCSlices 
-// with the full FADC slices, depending on the size of the signal w.r.t. fSinglePheCut
-//
-Bool_t MHCalibrationChargeBlindPix::Fill(const MParContainer *par, const Stat_t w)
-{
-
-  const Int_t samples = (Int_t)fRawEvt->GetNumHiGainSamples()
-                      +(Int_t)fRawEvt->GetNumLoGainSamples();
-
-  if (!fASinglePheFADCSlices.IsValid())
-    {
-      fASinglePheFADCSlices.ResizeTo(samples);
-      fAPedestalFADCSlices.ResizeTo(samples);
-    }
-
-  if (fASinglePheFADCSlices.GetNrows() != samples)
-    {
-      fASinglePheFADCSlices.ResizeTo(samples);
-      fAPedestalFADCSlices.ResizeTo(samples);
-    }
-
-  Float_t slices = (Float_t)fSignal->GetNumFADCSamples();
-  
-  if (slices == 0.)
-    {
-      *fLog << err 
-	    << "Number of used signal slices in MExtractedSignalBlindPix "
-	    << "is zero  ... abort." 
-            << endl;
-      return kFALSE;
-    }
-  
-  //
-  // Signal extraction and histogram filling
-  //
-  const Float_t signal = fSignal->GetExtractedSignal(fPixId);
-
-  if (signal > -0.5)
-    FillHist(signal);
-  else
-    return kTRUE;
-
-  //
-  // In order to study the single-phe posistion, we extract the slices
-  //
-  const Int_t blindpixIdx = fSignal->GetBlindPixelIdx(fPixId);
-
-  MRawEvtPixelIter pixel(fRawEvt);
-  pixel.Jump(blindpixIdx);
-
-  if (signal > fSinglePheCut)
-      FillSinglePheFADCSlices(pixel);
-  else
-      FillPedestalFADCSlices(pixel);
-
-  return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Returns kFALSE, if empty
-//
-// - Creates the fourier spectrum and sets bit MHGausEvents::IsFourierSpectrumOK()
-// - Retrieves the pedestals from MExtractedSignalBlindPixel
-// - Normalizes fASinglePheFADCSlices and fAPedestalFADCSlices
-// - Executes FitPedestal()
-// - Executes FitSinglePhe()
-// - Retrieves fit results and stores them in MCalibrationChargeBlindPix
-// 
-Bool_t MHCalibrationChargeBlindPix::Finalize() 
-{
-  
-  if (IsEmpty())
-  {
-    *fLog << err << GetDescriptor() << " ID: " << fPixId 
-	  << " My histogram has not been filled !! " << endl;
-      return kFALSE;
-  }
-
-  fMeanPedestal     = fSignal->GetPed();
-  fMeanPedestalErr  = fSignal->GetPedErr();
-  fSigmaPedestal    = fSignal->GetPedRms();
-  fSigmaPedestalErr = fSignal->GetPedRmsErr();
-
+void MHCalibrationChargeBlindPix::FinalizeSinglePheSpectrum() 
+{
+  
   if (fNumSinglePhes > 1)
       for (Int_t i=0;i<fASinglePheFADCSlices.GetNrows();i++)
@@ -587,33 +400,6 @@
   if (fNumPedestals > 1)
       for (Int_t i=0;i<fAPedestalFADCSlices.GetNrows();i++)
-	  fAPedestalFADCSlices[i]  = fAPedestalFADCSlices[i]/fNumPedestals;
-
-  FitPedestal();
-
-  fBlindPix->SetValid(kTRUE);
-
-  if (FitSinglePhe())
-    fBlindPix->SetSinglePheFitOK();
-  else
-    fBlindPix->SetValid(IsPedestalFitOK());
-
-  fBlindPix->SetLambda      (    fLambda               );
-  fBlindPix->SetLambdaVar   (    fLambdaErr*fLambdaErr );
-  fBlindPix->SetMu0         (    fMu0                  );
-  fBlindPix->SetMu0Err      (    fMu0Err               );
-  fBlindPix->SetMu1         (    fMu1                  );
-  fBlindPix->SetMu1Err      (    fMu1Err               );
-  fBlindPix->SetSigma0      (    fSigma0               );
-  fBlindPix->SetSigma0Err   (    fSigma0Err            );
-  fBlindPix->SetSigma1      (    fSigma1               );
-  fBlindPix->SetSigma1Err   (    fSigma1Err            );
-  fBlindPix->SetProb        (    fProb                 );
-
-  fBlindPix->SetLambdaCheck    ( fLambdaCheck          );
-  fBlindPix->SetLambdaCheckErr ( fLambdaCheckErr       );
-
-  return kTRUE;
-}
-
+        fAPedestalFADCSlices[i]  = fAPedestalFADCSlices[i]/fNumPedestals;
+}
 
 // --------------------------------------------------------------------------
@@ -733,19 +519,19 @@
   switch (fFitFunc)
     {
-    case kEPoisson4:
+    case MHCalibrationChargeBlindCam::kEPoisson4:
       fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto4,rmin,rmax,6);
       rmin += 6.5;
       break;
-    case kEPoisson5:
+    case MHCalibrationChargeBlindCam::kEPoisson5:
       fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto5,rmin,rmax,6);
       rmin = 0.;
       break;
-    case kEPoisson6:
+    case MHCalibrationChargeBlindCam::kEPoisson6:
       fSinglePheFit = new TF1("SinglePheFit",&fPoissonKto6,rmin,rmax,6);
       break;
-    case kEPolya:
+    case MHCalibrationChargeBlindCam::kEPolya:
       fSinglePheFit = new TF1("SinglePheFit",&fPolya,rmin,rmax,8);
       break;
-    case kEMichele:
+    case MHCalibrationChargeBlindCam::kEMichele:
       fSinglePheFit = new TF1("SinglePheFit",&fFitFuncMichele,rmin,rmax,9);
       break;
@@ -786,5 +572,5 @@
     {
       
-    case kEPoisson4:
+    case MHCalibrationChargeBlindCam::kEPoisson4:
 	fSinglePheFit->SetParNames(  "#lambda",   "#mu_{0}",    "#mu_{1}", "#sigma_{0}",  "#sigma_{1}","Area");
         fSinglePheFit->SetParameters(lambda_guess,mu_0_guess,mu_1_guess,si_0_guess,si_1_guess,norm);
@@ -796,6 +582,6 @@
 	fSinglePheFit->SetParLimits(5,norm-(0.5*norm),norm+(0.7*norm));
 	break;
-    case kEPoisson5:
-    case kEPoisson6:
+    case MHCalibrationChargeBlindCam::kEPoisson5:
+    case MHCalibrationChargeBlindCam::kEPoisson6:
       fSinglePheFit->SetParNames("#lambda","#mu_{0}","#mu_{1}","#sigma_{0}","#sigma_{1}","Area");
       fSinglePheFit->SetParameters(lambda_guess,mu_0_guess,800.,si_0_guess,500.,norm);
@@ -808,11 +594,11 @@
       break;
 
-    case kEPolya:
+    case MHCalibrationChargeBlindCam::kEPolya:
         fSinglePheFit->SetParameters(lambda_guess, excessPoisson_guess,
                                      delta1_guess,delta2_guess,
                                      electronicAmp_guess,
-                                     fSigmaPedestal,
+                                     10.,
                                      norm, 
-                                     fMeanPedestal);
+                                     0.);
       fSinglePheFit->SetParNames("#lambda","b_{tot}",
                                  "#delta_{1}","#delta_{2}",
@@ -825,13 +611,9 @@
       fSinglePheFit->SetParLimits(4,electronicAmp_guess-electronicAmp_limit,
                                     electronicAmp_guess+electronicAmp_limit);    
-      fSinglePheFit->SetParLimits(5,
-                                    fSigmaPedestal-3.*fSigmaPedestalErr,
-                                    fSigmaPedestal+3.*fSigmaPedestalErr);
+      fSinglePheFit->SetParLimits(5,0.,40.);
       fSinglePheFit->SetParLimits(6,norm-0.1,norm+0.1);
-      fSinglePheFit->SetParLimits(7,
-                                    fMeanPedestal-3.*fMeanPedestalErr,
-                                    fMeanPedestal+3.*fMeanPedestalErr);
-      break;
-    case kEMichele:
+      fSinglePheFit->SetParLimits(7,-10.,10.);
+      break;
+    case MHCalibrationChargeBlindCam::kEMichele:
       fSinglePheFit->SetParNames("#lambda_{cat}","#lambda_{dyn}",
                                  "#mu_{0}","#mu_{1cat}","#mu_{1dyn}",
@@ -879,8 +661,8 @@
     {
       
-    case kEPoisson4:
-    case kEPoisson5:
-    case kEPoisson6:
-    case kEPoisson7:
+    case MHCalibrationChargeBlindCam::kEPoisson4:
+    case MHCalibrationChargeBlindCam::kEPoisson5:
+    case MHCalibrationChargeBlindCam::kEPoisson6:
+    case MHCalibrationChargeBlindCam::kEPoisson7:
       fLambda = fSinglePheFit->GetParameter(0);
       fMu0    = fSinglePheFit->GetParameter(1);
@@ -895,5 +677,5 @@
       fSigma1Err = fSinglePheFit->GetParError(4);
       break;
-    case kEPolya:
+    case MHCalibrationChargeBlindCam::kEPolya:
       fLambda =  fSinglePheFit->GetParameter(0);
       fMu0    =  fSinglePheFit->GetParameter(7);
@@ -907,5 +689,5 @@
       fSigma0Err = fSinglePheFit->GetParError(5);
       fSigma1Err = 0.;
-    case kEMichele:
+    case MHCalibrationChargeBlindCam::kEMichele:
       fLambda =  fSinglePheFit->GetParameter(0);
       fMu0    =  fSinglePheFit->GetParameter(2);
@@ -1037,9 +819,10 @@
       fFitLegend = new TPaveText(0.05,0.05,0.95,0.95);
       fFitLegend->SetLabel(Form("%s%s", "Results of the single PhE Fit (",
-				(fFitFunc ==  kEPoisson4) ? "Poisson(k=4))" : 
-				(fFitFunc ==  kEPoisson5) ? "Poisson(k=5))" : 
-				(fFitFunc ==  kEPoisson6) ? "Poisson(k=6))" :
-				(fFitFunc ==  kEPolya   ) ? "Polya(k=4))"   : 
-				(fFitFunc ==  kEMichele ) ?  "Michele)"     : " none )" ));
+				(fFitFunc ==  MHCalibrationChargeBlindCam::kEPoisson4) ? "Poisson(k=4))" : 
+				(fFitFunc ==  MHCalibrationChargeBlindCam::kEPoisson5) ? "Poisson(k=5))" : 
+				(fFitFunc ==  MHCalibrationChargeBlindCam::kEPoisson6) ? "Poisson(k=6))" :
+				(fFitFunc ==  MHCalibrationChargeBlindCam::kEPolya   ) ? "Polya(k=4))"   : 
+				(fFitFunc ==  MHCalibrationChargeBlindCam::kEMichele ) ?  "Michele)"     
+                                                                                       : " none )" ));
       fFitLegend->SetTextSize(0.05);
   }
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindPix.h
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindPix.h	(revision 4985)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeBlindPix.h	(revision 4986)
@@ -7,4 +7,8 @@
 #endif
 
+#ifndef MARS_MHCalibrationChargeBlindCam
+#include "MHCalibrationChargeBlindCam.h"
+#endif
+
 #ifndef ROOT_TF1
 #include <TF1.h>
@@ -18,9 +22,6 @@
 class TPaveText;
 class TText;
-class MRawEvtData;
+class MExtractedSignalBlindPixel;
 class MRawEvtPixelIter;
-class MCalibrationChargeBlindPix;
-class MExtractBlindPixel;
-class MExtractedSignalBlindPixel;
 
 class MHCalibrationChargeBlindPix : public MHCalibrationPix
@@ -28,8 +29,4 @@
 private:
 
-  static const Int_t    fgChargeNbins;       //! Default for fNBins        (now set to: 5300   )
-  static const Axis_t   fgChargeFirst;       //! Default for fFirst        (now set to: -100.5 )
-  static const Axis_t   fgChargeLast;        //! Default for fLast         (now set to: 5199.5 )
-  static const Float_t  fgSinglePheCut;      //! Default for fSinglePheCut (now set to: 200    )
   static const Float_t  fgNumSinglePheLimit; //! Default for fNumSinglePheLimit (now set to: 50)
   static const Float_t  gkSignalInitializer; //! Signal initializer (-9999.)
@@ -41,8 +38,4 @@
   Float_t fNumSinglePheLimit;                // Minimum number of single-phe events 
 
-  MCalibrationChargeBlindPix *fBlindPix;     //! Storage container results  
-  MExtractedSignalBlindPixel *fSignal;       //! Storage container extracted signal
-  MRawEvtData                *fRawEvt;       //! Storage container raw data
- 
   TVector fASinglePheFADCSlices;             // Averaged FADC slice entries supposed single-phe events
   TVector fAPedestalFADCSlices;              // Averaged FADC slice entries supposed pedestal   events
@@ -68,24 +61,20 @@
   Int_t     fNDF;                            // Ndof of single-phe fit 
   Double_t  fProb;                           // Probability of singleo-phe fit
-  Double_t  fMeanPedestal;                   // Mean pedestal from pedestal run
-  Double_t  fSigmaPedestal;                  // Sigma pedestal from pedestal run
-  Double_t  fMeanPedestalErr;                // Error of Mean pedestal from pedestal run 
-  Double_t  fSigmaPedestalErr;               // Error of Sigma pedestal from pedestal run
 				     
   Byte_t    fFlags;                          // Bit-field for the flags
   enum { kSinglePheFitOK, kPedestalFitOK };  // Possible bits to be set
 
+  MHCalibrationChargeBlindCam::FitFunc_t fFitFunc;
+
   TPaveText *fFitLegend;                     //! Some legend to display the fit results
   TH1F      *fHSinglePheFADCSlices;          //! A histogram created and deleted only in Draw()
   TH1F      *fHPedestalFADCSlices;           //! A histogram created and deleted only in Draw()
 
-  // Fill histos
-  void  FillSinglePheFADCSlices(const MRawEvtPixelIter &iter);
-  void  FillPedestalFADCSlices( const MRawEvtPixelIter &iter);
-
   // Fit
   Bool_t InitFit();
   void   ExitFit();  
   
+  void DrawLegend(Option_t *opt="");
+  
 public:
 
@@ -98,9 +87,4 @@
   //  TObject *Clone(const char *) const;
 
-  Bool_t SetupFill(const MParList *pList);
-  Bool_t ReInit   (      MParList *pList);
-  Bool_t Fill     (const MParContainer *par, const Stat_t w=1);
-  Bool_t Finalize();
-  
   // Getters
   const Double_t GetLambda        ()  const { return fLambda;         }
@@ -128,35 +112,23 @@
   
   // Setters
-  void SetCalibrationChargeBlindPix ( MCalibrationChargeBlindPix *pix)    { fBlindPix          = pix;  }
-  void SetSinglePheCut      ( const Float_t cut =fgSinglePheCut      )    { fSinglePheCut      = cut;  }
+  void SetFitFunc(const MHCalibrationChargeBlindCam::FitFunc_t func)  { fFitFunc = func;  }
+  void SetSinglePheCut      ( const Float_t cut = 0.               )    { fSinglePheCut      = cut;  }
   void SetNumSinglePheLimit ( const Float_t lim =fgNumSinglePheLimit )    { fNumSinglePheLimit = lim;  }
-
-  void SetMeanPedestal      ( const Float_t f )   { fMeanPedestal     = f;  }
-  void SetMeanPedestalErr   ( const Float_t f )   { fMeanPedestalErr  = f;  }
-  void SetSigmaPedestal     ( const Float_t f )   { fSigmaPedestal    = f;  }
-  void SetSigmaPedestalErr  ( const Float_t f )   { fSigmaPedestalErr = f;  }
 
   void SetSinglePheFitOK    ( const Bool_t b=kTRUE);
   void SetPedestalFitOK     ( const Bool_t b=kTRUE);
   
+  // Fill histos
+  void  FillSinglePheFADCSlices(const MRawEvtPixelIter &iter);
+  void  FillPedestalFADCSlices( const MRawEvtPixelIter &iter);
+  void  FinalizeSinglePheSpectrum();
+  
   // Draws
   void Draw(Option_t *opt="");
 
-private:
-  void DrawLegend(Option_t *opt="");
-  
   // Fits
-public:
-  enum FitFunc_t { kEPoisson4, kEPoisson5, kEPoisson6, kEPoisson7, kEPolya, kEMichele }; // The possible fit functions
-
-private:
-  FitFunc_t fFitFunc;
-
-public:
   Bool_t FitSinglePhe (Option_t *opt="RL0+Q");
   void   FitPedestal  (Option_t *opt="RL0+Q");
 
-  void   ChangeFitFunc(const FitFunc_t func)  { fFitFunc = func;  }
-  
   // Simulation
   Bool_t SimulateSinglePhe(const Double_t lambda,
Index: trunk/MagicSoft/Mars/mhcalib/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/Makefile	(revision 4985)
+++ trunk/MagicSoft/Mars/mhcalib/Makefile	(revision 4986)
@@ -32,10 +32,10 @@
 # mimage     MHillas
 
-SRCFILES = MHCalibrationChargeBlindPix.cc \
-           MHCalibrationChargeBlindCam.cc \
-           MHCalibrationChargePix.cc \
-           MHCalibrationCam.cc \
+SRCFILES = MHCalibrationCam.cc \
            MHCalibrationPix.cc \
            MHCalibrationChargeCam.cc \
+           MHCalibrationChargePix.cc \
+           MHCalibrationChargeBlindCam.cc \
+           MHCalibrationChargeBlindPix.cc \
            MHCalibrationChargePINDiode.cc \
            MHCalibrationRelTimeCam.cc \
