Index: trunk/MagicSoft/Mars/mcalib/MCalibrationPix.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationPix.h	(revision 2931)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationPix.h	(revision 2932)
@@ -12,32 +12,39 @@
 private:
 
-  Int_t   fPixId;                        // the pixel Id
+  Int_t   fPixId;                     // the pixel Id
   
-  Float_t fCharge;                       // The mean reduced charge after the fit
-  Float_t fErrCharge;                    // The error of reduced mean charge after the fit
-  Float_t fSigmaCharge;                  // The sigma of the mean charge after the fit
-  Float_t fErrSigmaCharge;               // The error of the sigma of the mean charge after the fit
-  Float_t fRSigmaSquare;                 // The reduced squares of sigmas after the fit
-  Float_t fChargeProb;                   // The probability of the fit function 
+  const Float_t fElectronicPedRms;    // The pure electronic component of the RMS
+  const Float_t fErrElectronicPedRms; // The error of the pure electronic component of the RMS
 
-  Float_t fPed;                          // The mean pedestal (from MPedestalPix)
-  Float_t fPedRms;                       // The pedestal  RMS (from MPedestalPix)
-  Float_t fErrPedRms;                    // The error of the pedestal  RMS (from MPedestalPix)  
-  Float_t fElectronicPedRms;             // The pure electronic component of the RMS
-  Float_t fErrElectronicPedRms;          // The error of the pure electronic component of the RMS
+  const Float_t fFactor;              // The laboratory F-factor
+  const Float_t fFactorError;         // The laboratory F-factor Error
 
-  Float_t fTime;                         // The mean arrival time after the fit  
-  Float_t fSigmaTime;                    // The error of the mean arrival time after the fit
-  Float_t fTimeChiSquare;                // The Chi Square of the fit function 
-  Float_t fTimeProb;                     // The probability of the fit function 
+  const Float_t fChargeLimit;         // The limit (in units of PedRMS) for acceptance of the fitted mean charge
+  const Float_t fChargeErrLimit;      // The limit (in units of PedRMS) for acceptance of the fitted charge sigma
+  const Float_t fChargeRelErrLimit;   // The limit (in units of Error of fitted charge) for acceptance of the fitted mean  
+  Byte_t  fFlags;               // Flag for the set Bits
   
-  Float_t fFactor;                       // The laboratory F-factor
-  Float_t fFactorError;                  // The laboratory F-factor Error
-  Float_t fPheFFactorMethod;             // The number of Phe's calculated (F-factor method)
-  Float_t fPheFFactorMethodError;        // The error on the number of Phe's calculated (F-factor method)
+  Float_t fCharge;              // The mean reduced charge after the fit
+  Float_t fErrCharge;           // The error of reduced mean charge after the fit
+  Float_t fSigmaCharge;         // The sigma of the mean charge after the fit
+  Float_t fErrSigmaCharge;      // The error of the sigma of the mean charge after the fit
+  Float_t fRSigmaSquare;        // The reduced squares of sigmas after the fit
+  Float_t fChargeProb;          // The probability of the fit function 
 
-  Float_t fConversionFFactorMethod;      // The conversion factor to Phe's (F-factor method)
-  Float_t fConversionBlindPixelMethod;   // The conversion factor to Ph's (Blind Pixel method)
-  Float_t fConversionPINDiodeMethod;     // The conversion factor to Ph's (PIN Diode method)
+  Float_t fPed;                 // The mean pedestal (from MPedestalPix)
+  Float_t fPedRms;              // The pedestal  RMS (from MPedestalPix)
+  Float_t fErrPedRms;           // The error of the pedestal  RMS (from MPedestalPix)  
+
+  Float_t fTime;                // The mean arrival time after the fit  
+  Float_t fSigmaTime;           // The error of the mean arrival time after the fit
+  Float_t fTimeChiSquare;       // The Chi Square of the fit function 
+  Float_t fTimeProb;            // The probability of the fit function 
+  
+  Float_t fPheFFactorMethod;                // The number of Phe's calculated (F-factor method)
+  Float_t fPheFFactorMethodError;           // The error on the number of Phe's calculated (F-factor method)
+
+  Float_t fConversionFFactorMethod;         // The conversion factor to Phe's (F-factor method)
+  Float_t fConversionBlindPixelMethod;      // The conversion factor to Ph's (Blind Pixel method)
+  Float_t fConversionPINDiodeMethod;        // The conversion factor to Ph's (PIN Diode method)
 
   Float_t fConversionErrorFFactorMethod;    // The error of the conversion factor to Phe's (F-factor method)
@@ -52,6 +59,4 @@
   Float_t fConversionHiLoError;             // The error of the conversion factor between Hi Gain and Lo Gain  
   
-  Byte_t  fFlags;                           // Flag for the set Bits
-
   enum  { kHiGainSaturation,
           kExcluded, kExcludeQualityCheck,
@@ -61,8 +66,4 @@
   MHCalibrationPixel *fHist;                //! Pointer to the histograms performing the fits, etc.  
 
-  Float_t fChargeLimit;
-  Float_t fChargeErrLimit;
-  Float_t fChargeRelErrLimit;  
-  
   Bool_t CheckChargeFitValidity();
   Bool_t CheckTimeFitValidity();
@@ -144,13 +145,13 @@
   
   // Fill histos
-  Bool_t FillChargeHiGain(Float_t q)                   { return fHist->FillChargeHiGain(q); }
-  Bool_t FillTimeHiGain(Float_t t)                     { return fHist->FillTimeHiGain(t); }  
-  Bool_t FillRChargevsTimeHiGain(Float_t rq, Int_t t)  { return fHist->FillChargevsNHiGain(rq,t); }    
+  Bool_t FillChargeHiGain(Float_t q) const                  { return fHist->FillChargeHiGain(q); }
+  Bool_t FillTimeHiGain(Float_t t)   const                  { return fHist->FillTimeHiGain(t); }  
+  Bool_t FillRChargevsTimeHiGain(Float_t rq, Int_t t) const { return fHist->FillChargevsNHiGain(rq,t); }    
 
-  Bool_t FillChargeLoGain(Float_t q)                   { return fHist->FillChargeLoGain(q); }
-  Bool_t FillTimeLoGain(Float_t t)                     { return fHist->FillTimeLoGain(t); }  
-  Bool_t FillRChargevsTimeLoGain(Float_t rq, Int_t t)  { return fHist->FillChargevsNLoGain(rq,t); }    
+  Bool_t FillChargeLoGain(Float_t q) const                  { return fHist->FillChargeLoGain(q); }
+  Bool_t FillTimeLoGain(Float_t t)   const                  { return fHist->FillTimeLoGain(t); }  
+  Bool_t FillRChargevsTimeLoGain(Float_t rq, Int_t t) const { return fHist->FillChargevsNLoGain(rq,t); }    
   
-  Bool_t FillChargesInGraph(Float_t qhi,Float_t qlo)   { return fHist->FillPointInGraph(qhi,qlo); }
+  Bool_t FillChargesInGraph(Float_t qhi,Float_t qlo) const  { return fHist->FillPointInGraph(qhi,qlo); }
 
   void   DefinePixId(Int_t i);
Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc	(revision 2931)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc	(revision 2932)
@@ -56,94 +56,73 @@
 MHCalibrationPixel::MHCalibrationPixel(const char *name, const char *title)
       : fPixId(-1),
-	fTotalEntries(0),
-        fHChargeHiGain(NULL),  
-        fHTimeHiGain(NULL), 
-        fHChargevsNHiGain(NULL),
-        fHChargeLoGain(NULL),  
-        fHTimeLoGain(NULL),    
-        fHChargevsNLoGain(NULL),
-        fChargeGausFit(NULL), 
+        fChargeNbinsHiGain(2100),
+        fChargeNbinsLoGain(1010),
+        fTimeNbins(32),
+        fChargevsNbins(1000),
+        fTimeFirst(-0.25),
+        fTimeLast(15.75),
+	fHivsLoGain(NULL),
+        fChargeGausFit(NULL),
 	fTimeGausFit(NULL), 
-	fHivsLoGain(NULL),
-	fFitLegend(NULL),
-	fChargeFirstHiGain(-100.5),
-	fChargeLastHiGain(1999.5),
-	fChargeNbinsHiGain(2100),
-	fChargeFirstLoGain(-100.5),
-	fChargeLastLoGain(9999.5),
-	fChargeNbinsLoGain(1010),
-        fChargeChisquare(-1.),
-        fChargeProb(-1.),
-        fChargeNdf(-1),
-        fTimeChisquare(-1.),
-        fTimeProb(-1.),
-        fTimeNdf(-1),
-        fTimeMean(-1.),
-        fTimeSigma(-1.),
-        fTimeLowerFitRangeHiGain(0),
-        fTimeUpperFitRangeHiGain(0),
-        fTimeLowerFitRangeLoGain(0),
-        fTimeUpperFitRangeLoGain(0),
-	fOffset(0.),
-	fSlope(0.)
+	fFitLegend(NULL)
 { 
 
     fName  = name  ? name  : "MHCalibrationPixel";
     fTitle = title ? title : "Fill the accumulated charges and times of all events and perform fits";
+
+    fChargeFirstHiGain = -100.5;
+    fChargeLastHiGain  = 1999.5;
+    fChargeFirstLoGain = -100.5;
+    fChargeLastLoGain  = 9999.5;
 
     // Create a large number of bins, later we will rebin
     fHChargeHiGain = new TH1F("HChargeHiGain","Distribution of Summed FADC Hi Gain Slices Pixel ",
 			      fChargeNbinsHiGain,fChargeFirstHiGain,fChargeLastHiGain);
-    fHChargeHiGain->SetXTitle("Sum FADC Slices (Hi Gain)");
-    fHChargeHiGain->SetYTitle("Nr. of events");
-    fHChargeHiGain->Sumw2();
-
-    fHChargeHiGain->SetDirectory(NULL);
-
     fHChargeLoGain = new TH1F("HChargeLoGain","Distribution of Summed FADC Lo Gain Slices Pixel ",
 			      fChargeNbinsLoGain,fChargeFirstLoGain,fChargeLastLoGain);
+
     fHChargeLoGain->SetXTitle("Sum FADC Slices (Lo Gain)");
+    fHChargeHiGain->SetXTitle("Sum FADC Slices (Hi Gain)");
+
     fHChargeLoGain->SetYTitle("Nr. of events");
+    fHChargeHiGain->SetYTitle("Nr. of events");
+
+    fHChargeHiGain->Sumw2();
     fHChargeLoGain->Sumw2();
 
+    fHTimeHiGain = new TH1F("HTimeHiGain","Distribution of Mean Arrival Hi Gain Times Pixel ",
+			    fTimeNbins,fTimeFirst,fTimeLast);
+    fHTimeLoGain = new TH1F("HTimeLoGain","Distribution of Mean Arrival Lo Gain Times Pixel ",
+			    fTimeNbins,fTimeFirst,fTimeLast);
+
+    fHTimeHiGain->SetXTitle("Mean Arrival Times [Hi Gain FADC slice nr]");
+    fHTimeLoGain->SetXTitle("Mean Arrival Times [Lo Gain FADC slice nr]");
+
+    fHTimeHiGain->SetYTitle("Nr. of events");
+    fHTimeLoGain->SetYTitle("Nr. of events");
+
+    // We define a reasonable number and later enlarge it if necessary
+    fHChargevsNHiGain = new TH1I("HChargevsNHiGain","Sum of Hi Gain Charges vs. Event Number Pixel ",
+				 fChargevsNbins,-0.5,(Axis_t)fChargevsNbins - 0.5);
+    fHChargevsNLoGain = new TH1I("HChargevsNLoGain","Sum of Lo Gain Charges vs. Event Number Pixel ",
+				 fChargevsNbins,-0.5,(Axis_t)fChargevsNbins - 0.5);
+
+    fHChargevsNHiGain->SetXTitle("Event Nr.");
+    fHChargevsNLoGain->SetXTitle("Event Nr.");
+
+    fHChargevsNHiGain->SetYTitle("Sum of Hi Gain FADC slices");
+    fHChargevsNLoGain->SetYTitle("Sum of Lo Gain FADC slices");
+
+    fHChargeHiGain->SetDirectory(NULL);
     fHChargeLoGain->SetDirectory(NULL);
-
-    Axis_t tfirst = -0.5;
-    Axis_t tlast  = 15.5;
-    Int_t  ntbins = 32;
-
-    fHTimeHiGain = new TH1F("HTimeHiGain","Distribution of Mean Arrival Hi Gain Times Pixel ",
-			    ntbins,tfirst,tlast);
-    fHTimeHiGain->SetXTitle("Mean Arrival Times [Hi Gain FADC slice nr]");
-    fHTimeHiGain->SetYTitle("Nr. of events");
     fHTimeHiGain->SetDirectory(NULL);
-
-    fHTimeLoGain = new TH1F("HTimeLoGain","Distribution of Mean Arrival Lo Gain Times Pixel ",
-			    ntbins,tfirst,tlast);
-    fHTimeLoGain->SetXTitle("Mean Arrival Times [Lo Gain FADC slice nr]");
-    fHTimeLoGain->SetYTitle("Nr. of events");
     fHTimeLoGain->SetDirectory(NULL);
-
-    // We define a reasonable number and later enlarge it if necessary
-    Int_t  nqbins = 20000;
-    Axis_t nfirst = -0.5;
-    Axis_t nlast  = (Axis_t)nqbins - 0.5;
-
-    fHChargevsNHiGain = new TH1I("HChargevsNHiGain","Sum of Hi Gain Charges vs. Event Number Pixel ",
-				 nqbins,nfirst,nlast);
-    fHChargevsNHiGain->SetXTitle("Event Nr.");
-    fHChargevsNHiGain->SetYTitle("Sum of Hi Gain FADC slices");
-
     fHChargevsNHiGain->SetDirectory(NULL);
-
-    fHChargevsNLoGain = new TH1I("HChargevsNLoGain","Sum of Lo Gain Charges vs. Event Number Pixel ",
-				 nqbins,nfirst,nlast);
-    fHChargevsNLoGain->SetXTitle("Event Nr.");
-    fHChargevsNLoGain->SetYTitle("Sum of Lo Gain FADC slices");
-
     fHChargevsNLoGain->SetDirectory(NULL);
 
     fHiGains = new TArrayF();
     fLoGains = new TArrayF();
+
+    Clear();
 
 }
@@ -171,6 +150,74 @@
   if (fHivsLoGain)
     delete fHivsLoGain;
-
-}
+}
+
+
+void MHCalibrationPixel::Clear(Option_t *o)
+{
+  
+  fTotalEntries            = 0;
+
+  fChargeFirstHiGain       = -100.5;
+  fChargeLastHiGain        = 1999.5;
+  fChargeFirstLoGain       = -100.5;
+  fChargeLastLoGain        = 9999.5;
+
+  fChargeChisquare         = -1.;
+  fChargeProb              = -1.;
+  fChargeNdf               = -1;
+  fTimeChisquare           = -1.;
+  fTimeProb                = -1.;
+  fTimeNdf                 = -1;
+  fTimeMean                = -1.;
+  fTimeSigma               = -1.;
+
+  fTimeLowerFitRangeHiGain = 0;
+  fTimeUpperFitRangeHiGain = 0;
+  fTimeLowerFitRangeLoGain = 0;
+  fTimeUpperFitRangeLoGain = 0;
+
+  fOffset = 0.;
+  fSlope  = 0;
+
+  if (fChargeGausFit)
+    delete fChargeGausFit;
+  if (fTimeGausFit)
+    delete fTimeGausFit;
+  if (fFitLegend)
+    delete fFitLegend;
+  if (fHivsLoGain)
+    delete fHivsLoGain;
+  if (fHPSD)
+    delete fHPSD;
+
+  return;
+}
+
+
+void MHCalibrationPixel::Reset()
+{
+  
+  Clear();
+  
+  fHChargeHiGain->Reset();
+  fHChargeLoGain->Reset();
+  fHTimeHiGain->Reset();
+  fHTimeLoGain->Reset();
+  fHChargevsNHiGain->Reset();
+  fHChargevsNLoGain->Reset();
+
+  fHChargeHiGain->SetName("HChargeHiGain");
+  fHChargeLoGain->SetName("HChargeLoGain");
+  fHTimeHiGain->SetName("HTimeHiGain");
+  fHTimeLoGain->SetName("HTimeLoGain");
+  fHChargevsNHiGain->SetName("HChargevsNHiGain");
+  fHChargevsNLoGain->SetName("HChargevsNLoGain");
+
+  fHiGains->Reset();
+  fLoGains->Reset();
+
+}
+
+
 
 Bool_t MHCalibrationPixel::IsEmpty() const
@@ -295,35 +342,4 @@
 
   return kTRUE;
-}
-
-
-void MHCalibrationPixel::Reset()
-{
-  
-  for (Int_t i = fHChargeHiGain->FindBin(fChargeFirstHiGain); 
-       i <= fHChargeHiGain->FindBin(fChargeLastHiGain); i++)
-    fHChargeHiGain->SetBinContent(i, 1.e-20);
-
-  for (Int_t i = 0; i < 16; i++)
-    fHTimeHiGain->SetBinContent(i, 1.e-20);
-
-  fChargeFirstHiGain    = -100.5;
-  fChargeLastHiGain     = 1999.5;
-
-  fHChargeHiGain->GetXaxis()->UnZoom();
-
- for (Int_t i = fHChargeLoGain->FindBin(fChargeFirstLoGain); 
-       i <= fHChargeLoGain->FindBin(fChargeLastLoGain); i++)
-    fHChargeLoGain->SetBinContent(i, 1.e-20);
-
-  for (Int_t i = 0; i < 16; i++)
-      fHTimeLoGain->SetBinContent(i, 1.e-20);
-  
-  fChargeFirstLoGain    = -100.5;
-  fChargeLastLoGain     = 9999.5;
-
-  fHChargeLoGain->GetXaxis()->UnZoom();
-
-  return;
 }
 
@@ -866,5 +882,4 @@
   fChargeLastHiGain  = fHChargeHiGain->GetBinLowEdge(fHChargeHiGain->GetXaxis()->GetLast())
                       +fHChargeHiGain->GetBinWidth(0);
-  fChargeNbinsHiGain = nbins;
 
   CutEdges(fHChargeLoGain,nbins);
@@ -873,5 +888,4 @@
   fChargeLastLoGain  = fHChargeLoGain->GetBinLowEdge(fHChargeLoGain->GetXaxis()->GetLast())
                       +fHChargeLoGain->GetBinWidth(0);
-  fChargeNbinsLoGain = nbins;
 
   CutEdges(fHChargevsNHiGain,0);
Index: trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.h	(revision 2931)
+++ trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.h	(revision 2932)
@@ -4,4 +4,8 @@
 #ifndef MARS_MH
 #include "MH.h"
+#endif
+
+#ifndef MARS_MFFT
+#include "MFFT.h"
 #endif
 
@@ -12,4 +16,5 @@
 class TProfile;
 class TPaveText;
+class MFFT;
 
 class MHCalibrationPixel : public MH
@@ -23,7 +28,18 @@
   TArrayF *fLoGains;             //->
 
+  const Int_t   fChargeNbinsHiGain;
+  const Int_t   fChargeNbinsLoGain;
+  const Int_t   fTimeNbins;
+  const Int_t   fChargevsNbins;
+
+  const Axis_t  fTimeFirst;
+  const Axis_t  fTimeLast;
+  
+  TProfile* fHivsLoGain;
+
+  Double_t fOffset;
+  Double_t fSlope;
+  
 protected:
-
-  Int_t fTotalEntries;           // Number of entries
 
   TH1F* fHChargeHiGain;          // Summed FADC slices High Gain
@@ -35,18 +51,17 @@
   TH1I* fHChargevsNLoGain;       // Summed Charge vs. Event Nr. 
 
+  TH1F* fHPSD;                   // Power spectrum density of fHBlindPixelChargevsN
+  
   TF1* fChargeGausFit;
   TF1* fTimeGausFit;
   
-  TProfile* fHivsLoGain;
-
   TPaveText *fFitLegend;  
   
+  Int_t fTotalEntries;           // Number of entries
+
   Axis_t  fChargeFirstHiGain;
   Axis_t  fChargeLastHiGain;
-  Int_t   fChargeNbinsHiGain;
-
   Axis_t  fChargeFirstLoGain;
   Axis_t  fChargeLastLoGain;
-  Int_t   fChargeNbinsLoGain;
 
   Double_t fChargeChisquare;
@@ -75,7 +90,4 @@
   enum   { kUseLoGain, kFitOK };
   
-  Double_t fOffset;
-  Double_t fSlope;
-  
   virtual void DrawLegend();
   
@@ -84,4 +96,7 @@
   MHCalibrationPixel(const char *name=NULL, const char *title=NULL);
   ~MHCalibrationPixel();
+
+  void Clear(Option_t *o="");
+  void Reset();  
 
   void ChangeHistId(Int_t i);
@@ -97,5 +112,4 @@
 
   // Getters
-  const TH1F *GetHCharge()                 { return fHChargeHiGain;    }
   const TH1F *GetHCharge() const           { return fHChargeHiGain;    }
 
@@ -167,7 +181,6 @@
   // Others
   virtual void CutAllEdges();
-  virtual void Reset();
 
-  ClassDef(MHCalibrationPixel, 1)     // Histograms for each calibrated pixel
+  ClassDef(MHCalibrationPixel, 0)     // Histograms for each calibrated pixel
 };
 
