Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 3014)
+++ trunk/MagicSoft/Mars/Changelog	(revision 3015)
@@ -14,4 +14,7 @@
       Thomas Bretz. Some modifications had to be done, however. 
     - Class to hold MHPedestalPixel is still MPedestalCam
+    - MPedCalcPedRun does nothing any more (except from what is was 
+      doing before)
+
 
  2004/02/03: Markus Gaug
Index: trunk/MagicSoft/Mars/manalysis/MHPedestalPixel.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHPedestalPixel.cc	(revision 3014)
+++ trunk/MagicSoft/Mars/manalysis/MHPedestalPixel.cc	(revision 3015)
@@ -48,4 +48,10 @@
 const Float_t gkSq2Pi = 2.506628274631;
 const Float_t gkProbLimit = 0.01;
+const Int_t   MHPedestalPixel::gkChargeNbins    = 500 ;
+const Int_t   MHPedestalPixel::gkChargevsNbins  = 1000;
+const Axis_t  MHPedestalPixel::gkChargevsNFirst = -0.5;
+const Axis_t  MHPedestalPixel::gkChargevsNLast  = 999.5;
+const Axis_t  MHPedestalPixel::gkChargeFirst    = -0.5;
+const Axis_t  MHPedestalPixel::gkChargeLast     = 499.5;
 
 // --------------------------------------------------------------------------
@@ -53,35 +59,26 @@
 // Default Constructor. 
 //
-MHPedestalPixel::MHPedestalPixel(const char *name, const char *title)
+MHPedestalPixel::MHPedestalPixel()
       : fPixId(-1),
-        fChargeNbins(500),
-        fChargeFirst(-0.5),
-        fChargeLast(499.5),
-        fChargevsNbins(1000),
-        fChargevsNFirst(-0.5),
-        fChargevsNLast(999.5),        
         fGausFit(NULL)
 { 
-
-    fName  = name  ? name  : "MHPedestalPixel";
-    fTitle = title ? title : "Fill the accumulated charges and times of all events and perform fits";
-
-    // Create a large number of bins, later we will rebin
-    fHPedestalCharge = new TH1F("HPedestalCharge","Distribution of Summed FADC Pedestal Slices Pixel ",
-                        fChargeNbins,fChargeFirst,fChargeLast);
-    fHPedestalCharge->SetXTitle("Sum FADC Slices");
-    fHPedestalCharge->SetYTitle("Nr. of events");
-    fHPedestalCharge->Sumw2();
-
-    // We define a reasonable number and later enlarge it if necessary
-    fHPedestalChargevsN = new TH1I("HChargevsN","Sum of Charges vs. Event Number Pixel ",
-                           fChargevsNbins,fChargevsNFirst,fChargevsNLast);
-    fHPedestalChargevsN->SetXTitle("Event Nr.");
-    fHPedestalChargevsN->SetYTitle("Sum of FADC slices");
-
-    fHPedestalCharge->SetDirectory(NULL);
-    fHPedestalChargevsN->SetDirectory(NULL);
-
-    Clear();
+  
+  // Create a large number of bins, later we will rebin
+  fHPedestalCharge = new TH1F("HPedestalCharge","Distribution of Summed FADC Pedestal Slices Pixel ",
+                              gkChargeNbins,gkChargeFirst,gkChargeLast);
+  fHPedestalCharge->SetXTitle("Sum FADC Slices");
+  fHPedestalCharge->SetYTitle("Nr. of events");
+  fHPedestalCharge->Sumw2();
+  
+  // We define a reasonable number and later enlarge it if necessary
+  fHPedestalChargevsN = new TH1I("HChargevsN","Sum of Charges vs. Event Number Pixel ",
+                                 gkChargevsNbins,gkChargevsNFirst,gkChargevsNLast);
+  fHPedestalChargevsN->SetXTitle("Event Nr.");
+  fHPedestalChargevsN->SetYTitle("Sum of FADC slices");
+  
+  fHPedestalCharge->SetDirectory(NULL);
+  fHPedestalChargevsN->SetDirectory(NULL);
+  
+  Clear();
 }
 
@@ -91,5 +88,5 @@
   delete fHPedestalCharge;
   delete fHPedestalChargevsN;
-
+  
   if (fGausFit)
     delete fGausFit;
@@ -111,10 +108,14 @@
   fChargeNdf       = -1;
 
-  fChargeFirst     = -0.5;
-  fChargeLast      = 499.5;
+  fChargeFirst     = gkChargeFirst;
+  fChargeLast      = gkChargeLast;
 
   if (fGausFit)
     delete fGausFit;
 
+  CLRBIT(fFlags,kFitted);
+  CLRBIT(fFlags,kFitOK);
+  CLRBIT(fFlags,kOscillating);
+
   return;
 }
@@ -160,33 +161,10 @@
   fPixId = id;
 
-  TString nameQ = TString(fHPedestalCharge->GetName());
-  nameQ += id;
-  fHPedestalCharge->SetName(nameQ.Data());
-
-  TString nameQvsN  = TString(fHPedestalChargevsN->GetName());
-  nameQvsN += id;
-  fHPedestalChargevsN->SetName(nameQvsN.Data());
-
-  TString titleQ = TString(fHPedestalCharge->GetTitle());
-  titleQ += id;
-  fHPedestalCharge->SetTitle(titleQ.Data());
-
-  TString titleQvsN  = TString(fHPedestalChargevsN->GetTitle());
-  titleQvsN += id;
-  fHPedestalChargevsN->SetTitle(titleQvsN.Data());
-
-}
-
-
-Bool_t MHPedestalPixel::SetupFill(const MParList *plist)
-{
- 
-  Reset();
-
-  return kTRUE;
-}
-
-
-
+  fHPedestalCharge->SetName(Form("%s%d", fHPedestalCharge->GetName(), id));
+  fHPedestalChargevsN->SetName(Form("%s%d", fHPedestalChargevsN->GetName(), id));
+  fHPedestalCharge->SetTitle(Form("%s%d", fHPedestalCharge->GetTitle(), id));
+  fHPedestalChargevsN->SetTitle(Form("%s%d", fHPedestalChargevsN->GetTitle(), id));
+
+}
 
 TObject *MHPedestalPixel::DrawClone(Option_t *option) const
@@ -223,5 +201,5 @@
   gROOT->SetSelectedPad(NULL);
   
-  TCanvas *c = MakeDefCanvas(this,600,900); 
+  TCanvas *c = MH::MakeDefCanvas(this,600,900); 
   
   c->Divide(1,2);
@@ -233,6 +211,4 @@
   if (fHPedestalCharge->Integral() > 0)
     gPad->SetLogy(1);
-  else
-    gPad->SetLogy(0);
 
   fHPedestalCharge->Draw(opt);
@@ -243,9 +219,5 @@
   if (fGausFit)
     {
-      if (IsFitOK())
-        fGausFit->SetLineColor(kGreen);          
-      else
-        fGausFit->SetLineColor(kRed);
-      
+      fGausFit->SetLineColor(IsFitOK() ? kGreen : kRed);
       fGausFit->Draw("same");
     }
@@ -265,4 +237,13 @@
 
 
+// --------------------------------------------------------------------------
+//
+// 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
+//
 Bool_t MHPedestalPixel::FitCharge(Option_t *option)
 {
@@ -282,12 +263,9 @@
   //
   const Stat_t   entries     = fHPedestalCharge->Integral();
-  const Double_t area_guess  = entries/gkSq2Pi;
   const Double_t mu_guess    = fHPedestalCharge->GetBinCenter(fHPedestalCharge->GetMaximumBin());
   const Double_t sigma_guess = mu_guess/15.;
-
-  TString name = TString("GausFit");
-  name += fPixId;
-
-  fGausFit = new TF1(name.Data(),"gaus",rmin,rmax);
+  const Double_t area_guess  = entries/gkSq2Pi/sigma_guess;
+
+  fGausFit = new TF1(Form("%s%d","GausFit ",fPixId),"gaus",rmin,rmax);
 
   if (!fGausFit) 
@@ -312,7 +290,7 @@
     {
 
-      Axis_t rtry = fGausFit->GetParameter(1) - 3.0*fGausFit->GetParameter(2);
+      Axis_t rtry = fGausFit->GetParameter(1) - 2.0*fGausFit->GetParameter(2);
       rmin        = (rtry < rmin ? rmin : rtry);
-      rmax        = fGausFit->GetParameter(1) + 3.0*fGausFit->GetParameter(2);
+      rmax        = fGausFit->GetParameter(1) + 2.0*fGausFit->GetParameter(2);
       fGausFit->SetRange(rmin,rmax);  
 
@@ -353,13 +331,13 @@
 {
 
-  Int_t nbins = 50;
-
-  CutEdges(fHPedestalCharge,nbins);
+  Int_t nbins = 30;
+
+  MH::CutEdges(fHPedestalCharge,nbins);
 
   fChargeFirst = fHPedestalCharge->GetBinLowEdge(fHPedestalCharge->GetXaxis()->GetFirst());
   fChargeLast  = fHPedestalCharge->GetBinLowEdge(fHPedestalCharge->GetXaxis()->GetLast())
-                      +fHPedestalCharge->GetBinWidth(0);
-
-  CutEdges(fHPedestalChargevsN,0);
+                +fHPedestalCharge->GetBinWidth(0);
+
+  MH::CutEdges(fHPedestalChargevsN,0);
 
 }
@@ -370,23 +348,15 @@
   *fLog << all << "Pedestal Fits Pixel: "  << fPixId  << endl;
 
-  if (TESTBIT(fFlags,kFitted))
-    {
-      
-      *fLog << all << "Results of the Summed Charges Fit: "                      << endl;
-      *fLog << all << "Chisquare: "        << fChargeChisquare                   << endl;
-      *fLog << all << "DoF: "              << fChargeNdf                         << endl;
-      *fLog << all << "Probability: "      << fChargeProb                        << endl;
-      *fLog << all << "Results of fit: "   ;
-        if (TESTBIT(fFlags,kFitOK))
-          *fLog << inf << "OK" << endl;
-        else 
-          *fLog << err << "NOT OK" << endl;          
-      *fLog << all                                                               << endl;
-    }
-  else
-    {
-      *fLog << all << "Pedestal Histogram has not yet been fitted"               << endl;      
-      *fLog << all                                                               << endl;      
-    }
+  if (!TESTBIT(fFlags,kFitted))
+    {
+      gLog << "Pedestal Histogram has not yet been fitted" << endl;
+      return;
+    }
+  
+  gLog << "Results of the Summed Charges Fit: "   << endl;
+  gLog << "Chisquare:      " << fChargeChisquare  << endl;
+  gLog << "DoF:            " << fChargeNdf        << endl;
+  gLog << "Probability:    " << fChargeProb       << endl;
+  gLog << "Results of fit: " << (TESTBIT(fFlags,kFitOK) ? "Ok.": "Not OK!") << endl;
     
 }
Index: trunk/MagicSoft/Mars/manalysis/MHPedestalPixel.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHPedestalPixel.h	(revision 3014)
+++ trunk/MagicSoft/Mars/manalysis/MHPedestalPixel.h	(revision 3015)
@@ -14,10 +14,16 @@
 private:
 
+  static const Int_t  gkChargeNbins;
+  static const Int_t  gkChargevsNbins;
+  static const Axis_t gkChargevsNFirst;
+  static const Axis_t gkChargevsNLast;
+  static const Axis_t gkChargeFirst;
+  static const Axis_t gkChargeLast; 
+  
   Int_t fPixId;                  // Pixel Nr
 
-  const Int_t   fChargeNbins;
   Axis_t  fChargeFirst;
   Axis_t  fChargeLast;
-
+  
   const Int_t   fChargevsNbins;
   const Axis_t  fChargevsNFirst;
@@ -41,9 +47,9 @@
   Byte_t   fFlags;
 
-  enum   { kFitted, kFitOK };
+   enum { kFitted, kFitOK, kOscillating };
   
 public:
 
-  MHPedestalPixel(const char *name=NULL, const char *title=NULL);
+  MHPedestalPixel();
   ~MHPedestalPixel();
 
@@ -73,7 +79,4 @@
   Bool_t FillChargevsN(Float_t q);
 
-  Bool_t SetupFill(const MParList *pList);
-  Bool_t Fill(const MParContainer *, const Stat_t w=1) { return kTRUE; }
-  
   // Fits
   Bool_t FitCharge(Option_t *option="RQ0");  
Index: trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc	(revision 3014)
+++ trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc	(revision 3015)
@@ -124,5 +124,4 @@
   fNumPixels        = 0;
   fNumSamplesTot    = 0;
-  fUseHists         = kFALSE;
   
   fRawEvt    = NULL;
@@ -160,10 +159,4 @@
 
     fSignals = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
-
-    if (!fSignals && fUseHists)
-    {
-        *fLog << warn << "Cannot find MExtractedSignalCam... will not use histograms!" << endl;
-        fUseHists = kFALSE;
-    }
 
     fNumSamplesTot=0;
@@ -207,7 +200,4 @@
     // the other one
     fNumHiGainSamples = runheader->GetNumSamplesHiGain() & ~1;
-
-    if (fUseHists)
-      fPedestals->InitUseHists();
 
     return kTRUE;
@@ -260,10 +250,4 @@
 	fSumx2[idx] += msum*msum;
 
-        if (fUseHists)
-          {
-            MExtractedSignalPix &sig =  (*fSignals)[idx];            
-            const Float_t signal = sig.GetExtractedSignalHiGain();
-            (*fPedestals)[idx].FillHists(signal);
-          }
     }
     
@@ -290,5 +274,5 @@
   while (pixel.Next())
     {
-      const UInt_t pixid = pixel.GetPixelId();
+      const Int_t pixid = pixel.GetPixelId();
       
       const Float_t sum  = fSumx.At(pixid);
@@ -307,13 +291,7 @@
       (*fPedestals)[pixid].Set(higainped, higainrms);
 
-      if (fUseHists)
-        (*fPedestals)[pixid].FitCharge();
-      
     }
   
-  fPedestals->SetNumTotSlices(fNumSamplesTot);
-
-  if (fUseHists)
-    fPedestals->SetNumExtractSlices(fSignals->GetNumUsedHiGainFADCSlices());
+  fPedestals->SetTotalEntries(fNumSamplesTot);
 
   return kTRUE;
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc	(revision 3014)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc	(revision 3015)
@@ -630,29 +630,31 @@
       // so that we can use it for the fit
       //
-      if (fPedestals->IsUseHists())
+      if (fPedestals->GetHistSize() > fBlindPixelId)
         {
           //
           // retrieve the pedestal pix of the blind pixel
           //
-          MPedestalPix &ped = (*fPedestals)[fBlindPixelId];
+          MHPedestalPixel &pedhist = (*fPedestals)(fBlindPixelId);
+          MPedestalPix    &pedpix  = (*fPedestals)[fBlindPixelId];
           //
           // retrieve the histogram containers
           //
           MHCalibrationBlindPixel *hist = blindpixel.GetHist();
-          MHPedestalPixel *pedhist = ped.GetHist();
           //
           // Set the corresponding values
           //
           const Float_t nslices     = (Float_t)fSignals->GetNumUsedFADCSlices();
-          const Int_t   nentries    = pedhist->GetTotalEntries();
-          
-          const Float_t peddiff     = ped.GetMean() - ped.GetPedestal()*nslices;
-
-          Float_t pederr  = ped.GetMeanErr()*ped.GetMeanErr();
-          pederr         += ped.GetPedestalRms()*ped.GetPedestalRms()*nslices*nslices/nentries/nentries;
-          pederr          = TMath::Sqrt(pederr);
-          
-          const Float_t pedsigma    = ped.GetSigma();
-          const Float_t pedsigmaerr = ped.GetSigmaErr();
+          const ULong_t nentries    = fPedestals->GetTotalEntries();
+          
+          const Float_t peddiff     = (pedhist.GetChargeMean()-pedpix.GetPedestal())*nslices;
+
+          const Float_t sqrslice    = TMath::Sqrt(nslices);
+
+          Float_t pederr  = pedhist.GetChargeMeanErr()*pedhist.GetChargeMeanErr();
+          pederr         += pedpix.GetPedestalRms()*pedpix.GetPedestalRms()/nentries;
+          pederr          = TMath::Sqrt(pederr)*sqrslice;
+          
+          const Float_t pedsigma    = pedhist.GetChargeSigma()*sqrslice;
+          const Float_t pedsigmaerr = pedhist.GetChargeSigmaErr()*sqrslice;
           
           hist->SetMeanPedestal(peddiff);
