Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 3616)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 3617)
@@ -26,4 +26,5 @@
    * mcalib/MHCalibrationChargeLoGainPix.[h,cc]
    * mcalib/MHCalibrationChargeBlindPix.[h,cc]
+   * mcalib/MHCalibrationChargePINDiode.[h,cc]
      - updated and enlarged documentation
 
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargePINDiode.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargePINDiode.cc	(revision 3616)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargePINDiode.cc	(revision 3617)
@@ -100,6 +100,7 @@
   SetConversionChargePhotonsErr();
 
-  SetExcluded(kFALSE);
-  SetExcludeQualityCheck(kFALSE);
+  SetOscillating          ( kFALSE );
+  SetExcluded             ( kFALSE );
+  SetExcludeQualityCheck  ( kFALSE );
 }
 
@@ -154,4 +155,13 @@
   fPedRms = pedrms;
   
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the Oscillating Bit from outside 
+//
+void  MCalibrationChargePINDiode::SetOscillating( const Bool_t b)
+{
+    b ? SETBIT(fFlags,kOscillating) : CLRBIT(fFlags,kOscillating);
 }
 
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargePINDiode.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargePINDiode.h	(revision 3616)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargePINDiode.h	(revision 3617)
@@ -69,5 +69,5 @@
   PulserColor_t fColor;  
 
-  enum  { kExcluded, kExcludeQualityCheck,
+  enum  { kExcluded, kExcludeQualityCheck, kOscillating,
           kChargeFitValid, kTimeFitValid, 
 	  kMeanTimeInFirstBin, kMeanTimeInLastBin, 
@@ -106,4 +106,5 @@
   void SetPedestal(Float_t ped, Float_t pedrms);
 
+  void SetOscillating     ( const Bool_t b=kTRUE);
   void SetExcluded           ( const Bool_t b = kTRUE );
   void SetExcludeQualityCheck( const Bool_t b = kTRUE );
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.cc	(revision 3616)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.cc	(revision 3617)
@@ -179,14 +179,4 @@
 //
 // Sets:
-// - fHGausHist.SetBins(fChargeNbins,fChargeFirst,fChargeLast);
-//
-void MHCalibrationChargeBlindPix::Init()
-{
-  fHGausHist.SetBins( fChargeNbins, fChargeFirst, fChargeLast);
-}
-
-// --------------------------------------------------------------------------
-//
-// Sets:
 // - all variables to 0., except the fit result variables to -999.
 // - all flags to kFALSE
@@ -287,5 +277,6 @@
 // - fAPedestalFADCSlices(0);
 //
-// Calls Init()
+// Sets Binning of the following histograms:
+// - fHGausHist.SetBins(fChargeNbins,fChargeFirst,fChargeLast);
 //
 Bool_t MHCalibrationChargeBlindPix::SetupFill(const MParList *pList) 
@@ -309,5 +300,5 @@
   fAPedestalFADCSlices(0);
   
-  Init();
+  fHGausHist.SetBins( fChargeNbins, fChargeFirst, fChargeLast);
   
   return kTRUE;
@@ -349,5 +340,6 @@
 // - blind Pixel ID
 //
-// Executes MHGausEvents::FillHistAndArray(signal)
+// Fills the following histograms:
+// - MHGausEvents::FillHistAndArray(signal)
 //
 // Creates MRawEvtPixelIter, jumps to blind pixel ID, 
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.h	(revision 3616)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.h	(revision 3617)
@@ -96,5 +96,4 @@
 
   void Clear(Option_t *o="");  
-  void Init();
 
   Bool_t SetupFill(const MParList *pList);
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargePINDiode.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargePINDiode.cc	(revision 3616)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargePINDiode.cc	(revision 3617)
@@ -34,4 +34,5 @@
 
 #include <TH1.h>
+#include <TF1.h>
 #include <TPad.h>
 #include <TVirtualPad.h>
@@ -63,4 +64,35 @@
 // Default Constructor. 
 //
+// Sets: 
+// - the default number for fChargeNbins     (fgChargeNbins)
+// - the default number for fChargeFirst     (fgChargeFirst)
+// - the default number for fChargeLast      (fgChargeLast)
+// - the default number for fRmsChargeNbins  (fgRmsChargeNbins)
+// - the default number for fRmsChargeFirst  (fgRmsChargeFirst)
+// - the default number for fRmsChargeLast   (fgRmsChargeLast)
+// - the default number for fAbsTimeNbins    (fgAbsTimeNbins)
+// - the default number for fAbsTimeFirst    (fgAbsTimeFirst)
+// - the default number for fAbsTimeLast     (fgAbsTimeLast)
+//
+// - the default name of the  fHGausHist      ("HCalibrationChargePINDiode")
+// - the default title of the fHGausHist      ("Distribution of Summed FADC slices PIN Diode")
+// - the default x-axis title for fHGausHist  ("Sum FADC Slices")
+// - the default y-axis title for fHGausHist  ("Nr. of events")
+// - the default name of the  fHAbsTime       ("HAbsTimePINDiode")
+// - the default title of the fHAbsTime       ("Distribution of Absolute Arrival Times PIN Diode")
+// - the default x-axis title for fHAbsTime   ("Absolute Arrival Time [FADC slice nr]")
+// - the default y-axis title for fHAbsTime   ("Nr. of events")
+// - the default name of the  fHRmsCharge     ("HRmsChargePINDiode")
+// - the default title of the fHRmsCharge     ("Distribution of Variances of summed FADC slices PIN Diode")
+// - the default x-axis title for fHRmsCharge ("RMS (sum) [FADC slices]")
+// - the default y-axis title for fHRmsCharge ("Nr. of events")
+// - the default directory of the fHRmsCharge (NULL)
+//
+// Initializes:
+// - fHRmsCharge()
+// - all pointers to NULL
+// - all variables to 0.
+// - all flags to kFALSE
+//
 MHCalibrationChargePINDiode::MHCalibrationChargePINDiode(const char *name, const char *title)
     : fPINDiode(NULL), fHRmsCharge()
@@ -82,6 +114,16 @@
   SetAbsTimeLast();
 
-  fHRmsCharge.SetName("HRmsCharge");
-  fHRmsCharge.SetTitle("Distribution of Variances of summed FADC slices");  
+  fHGausHist.SetName("HCalibrationChargePINDiode");
+  fHGausHist.SetTitle("Distribution of Summed FADC slices PIN Diode");  
+  fHGausHist.SetXTitle("Sum FADC Slices");
+  fHGausHist.SetYTitle("Nr. of events");
+
+  fHAbsTime.SetName("HAbsTimePINDiode");
+  fHAbsTime.SetTitle("Distribution of Absolute Arrival Times PIN Diode");  
+  fHAbsTime.SetXTitle("Absolute Arrival Time [FADC slice nr]");
+  fHAbsTime.SetYTitle("Nr. of events");
+
+  fHRmsCharge.SetName("HRmsChargePINDiode");
+  fHRmsCharge.SetTitle("Distribution of Variances of summed FADC slices PIN Diode");  
   fHRmsCharge.SetXTitle("RMS (sum) [FADC slices]");
   fHRmsCharge.SetYTitle("Nr. of events");
@@ -92,43 +134,30 @@
 }
 
-
-void MHCalibrationChargePINDiode::Init()
-{
-
-  fHGausHist.SetName("HCalibrationChargePINDiode");
-  fHGausHist.SetTitle("Distribution of Summed FADC slices PIN Diode");  
-  fHGausHist.SetXTitle("Sum FADC Slices");
-  fHGausHist.SetYTitle("Nr. of events");
+// --------------------------------------------------------------------------
+//
+// Initializes Binning of the following histograms:
+// - fHGausHist.SetBins(fChargeNbins,fChargeFirst,fChargeLast);
+// - fHAbsTime.SetBins(fAbsTimeNbins,fAbsTimeFirst,fAbsTimeLast);
+// - fHRmsCharge.SetBins(fRmsChargeNbins,fRmsChargeFirst,fRmsChargeLast);
+//
+Bool_t MHCalibrationChargePINDiode::SetupFill(const MParList *pList) 
+{
+
   fHGausHist.SetBins(fChargeNbins,fChargeFirst,fChargeLast);
-  //  fHGausHist.Sumw2();
-
-  fHAbsTime.SetName("HAbsTimePINDiode");
-  fHAbsTime.SetTitle("Distribution of Absolute Arrival Times PIN Diode ");  
-  fHAbsTime.SetXTitle("Absolute Arrival Time [FADC slice nr]");
-  fHAbsTime.SetYTitle("Nr. of events");
   fHAbsTime.SetBins(fAbsTimeNbins,fAbsTimeFirst,fAbsTimeLast);
-
   fHRmsCharge.SetBins(fRmsChargeNbins,fRmsChargeFirst,fRmsChargeLast);
-}
-
-
-void MHCalibrationChargePINDiode::Clear(Option_t *o)
-{
-  
-  fExtractSlices = 0;
-
-  MHCalibrationChargePix::Clear();
-  return;
-}
-
-Bool_t MHCalibrationChargePINDiode::SetupFill(const MParList *pList) 
-{
-  Init();
+
   return kTRUE;
-}
-
+
+}
+
+// --------------------------------------------------------------------------
+//
+// Gets or creates the pointers to:
+// - MCalibrationChargePINDiode
+//
 Bool_t MHCalibrationChargePINDiode::ReInit(MParList *pList)
 {
-
+  
   fPINDiode = (MCalibrationChargePINDiode*)pList->FindCreateObj("MCalibrationChargePINDiode");
   if (!fPINDiode)
@@ -141,4 +170,17 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Retrieves from MExtractedSignalPINDiode:
+// - Number of used FADC samples
+// - Extracted signal 
+// - Signal Rms
+// - Arrival Time
+//
+// Fills the following histograms:
+// - MHGausEvents::FillHistAndArray(signal)
+// - FillAbsTime(time);
+// - FillRmsCharge(rms);
+//
 Bool_t MHCalibrationChargePINDiode::Fill(const MParContainer *par, const Stat_t w)
 {
@@ -161,13 +203,4 @@
     }
   
-  if (fExtractSlices != 0. && slices != fExtractSlices )
-    {
-      *fLog << err << "Number of used signal slices changed in MExtractedSignalCam  ... abort."
-           << endl;
-      return kFALSE;
-    }
-  
-  fExtractSlices = slices;
-  
   const Float_t signal = (float)extractor->GetExtractedSignal();
   const Float_t time   = extractor->GetExtractedTime();
@@ -181,4 +214,21 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Returns kFALSE, if empty
+//
+// Performs the following fits:
+// - MHGausEvents::FitGaus()
+// - FitRmsCharge()
+//
+// Creates the fourier spectrum and sets bit IsFourierSpectrumOK()
+// Retrieves the results of the following fits and stores them in MCalibrationChargePINDiode:
+// - Mean Charge and Error 
+// - Sigma Charge and Error
+// - Abs Time Mean
+// - Abs Time Rms
+// - Rms Charge Mean and Error
+// - Rms Charge Sigma and Error
+// 
 Bool_t MHCalibrationChargePINDiode::Finalize() 
 {
@@ -189,5 +239,7 @@
   FitGaus();
   FitRmsCharge();
+
   CreateFourierSpectrum();
+  fPINDiode->SetOscillating  ( !IsFourierSpectrumOK() );
 
   fPINDiode->SetMeanCharge(     GetMean()     );
@@ -207,4 +259,9 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Fills fHRmsCharge with q
+// Returns kFALSE, if overflow or underflow occurred, else kTRUE
+//
 Bool_t MHCalibrationChargePINDiode::FillRmsCharge(const Float_t q)
 {
@@ -222,4 +279,13 @@
 
 
+// -------------------------------------------------------------------------
+//
+// Draw the histogram
+//
+// The following options can be chosen:
+//
+// "": displays the fHGausHist with fits and fHRmsCharge
+// "all": executes additionally MHGausEvents::Draw(), with option "fourierevents"
+//
 void MHCalibrationChargePINDiode::Draw(const Option_t *opt)
 {
@@ -230,28 +296,47 @@
   Int_t win = 1;
 
-  TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas(this,600, 600);
-
-  pad->SetTicks();
-  pad->SetBorderMode(0);
+  TVirtualPad *oldpad = gPad ? gPad : MH::MakeDefCanvas(this,900, 600);
+  TVirtualPad *pad    = NULL;
+
+  oldpad->SetBorderMode(0);
     
-  if (option.Contains("rmscharge"))
-    win++;
-
-  pad->Divide(1,win);
-  pad->cd(1);
+  if (option.Contains("all"))
+  {
+      option.ReplaceAll("all","");
+      oldpad->Divide(2,1);
+      win = 2;
+      oldpad->cd(1);
+      TVirtualPad *newpad = gPad;
+      pad = newpad;
+      pad->Divide(1,2);
+      pad->cd(1);
+  }
+  else
+  {
+      pad = oldpad;
+      pad->Divide(1,2);
+      pad->cd(1);
+  }
 
   if (!IsEmpty())
-    gPad->SetLogy();
-
-  MHGausEvents::Draw(opt);
-
-  if (win > 1)
-    {
-      pad->cd(2);
-      fHRmsCharge.Draw(opt);
-    }
-}
-
-
-
-
+      gPad->SetLogy();
+
+  gPad->SetTicks();
+
+  fHGausHist.Draw(opt); 
+  if (fFGausFit)
+  {
+      fFGausFit->SetLineColor(IsGausFitOK() ? kGreen : kRed);
+      fFGausFit->Draw("same");
+  }
+
+  pad->cd(2);
+  fHRmsCharge.Draw(opt);
+
+  oldpad->cd(2);
+  MHGausEvents::Draw("fourierevents");
+}
+
+
+
+
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargePINDiode.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargePINDiode.h	(revision 3616)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargePINDiode.h	(revision 3617)
@@ -13,31 +13,27 @@
 private:
 
-  MCalibrationChargePINDiode *fPINDiode;  //! Storage container of the results
+  static const Int_t   fgChargeNbins;     // Default for fChargeNBins  (now set to: 200   )
+  static const Axis_t  fgChargeFirst;     // Default for fChargeFirst  (now set to: -0.5  )
+  static const Axis_t  fgChargeLast;      // Default for fChargeLast   (now set to: 199.5 )
+  static const Int_t   fgRmsChargeNbins;  // Default for fChargeNBins  (now set to: 100   )
+  static const Axis_t  fgRmsChargeFirst;  // Default for fChargeFirst  (now set to: 0.    )
+  static const Axis_t  fgRmsChargeLast;   // Default for fChargeLast   (now set to: 100.  )
+  static const Int_t   fgAbsTimeNbins;    // Default for fChargeNBins  (now set to: 30    )
+  static const Axis_t  fgAbsTimeFirst;    // Default for fChargeFirst  (now set to: -0.5  )
+  static const Axis_t  fgAbsTimeLast;     // Default for fChargeLast   (now set to: 29.5  )
 
-  TH1F fHRmsCharge;                       // Variance of summed FADC slices
+  MCalibrationChargePINDiode *fPINDiode; //! Storage container of the results
 
-  static const Int_t   fgChargeNbins;
-  static const Axis_t  fgChargeFirst;
-  static const Axis_t  fgChargeLast;  
+  TH1F fHRmsCharge;                      // Histogram containing Variance of summed FADC slices
 
-  static const Int_t   fgRmsChargeNbins;
-  static const Axis_t  fgRmsChargeFirst;
-  static const Axis_t  fgRmsChargeLast;  
+  Int_t   fRmsChargeNbins;               // Number of  bins used for the fHRmsCharge
+  Axis_t  fRmsChargeFirst;               // Lower bound bin used for the fHRmsCharge
+  Axis_t  fRmsChargeLast;                // Upper bound bin used for the fHRmsCharge
 
-  static const Int_t   fgAbsTimeNbins;
-  static const Axis_t  fgAbsTimeFirst;
-  static const Axis_t  fgAbsTimeLast;
+  Float_t fRmsChargeMean;                //  Mean of the Gauss fit               
+  Float_t fRmsChargeSigma;               //  Sigma of the Gauss fit             
+  Float_t fRmsChargeMeanErr;             //  Error of the mean of the Gauss fit 
+  Float_t fRmsChargeSigmaErr;            //  Error of the sigma of the Gauss fit
 
-  Int_t   fRmsChargeNbins;
-  Axis_t  fRmsChargeFirst;
-  Axis_t  fRmsChargeLast;  
-
-  Float_t  fRmsChargeMean;
-  Float_t  fRmsChargeMeanErr;
-  Float_t  fRmsChargeSigma;
-  Float_t  fRmsChargeSigmaErr;
-
-  Float_t fExtractSlices;
-  
 public:
 
@@ -45,7 +41,4 @@
   ~MHCalibrationChargePINDiode(){}
 
-  void Clear(Option_t *o="");
-  void Init();
-  
   Bool_t SetupFill(const MParList *pList);
   Bool_t ReInit   (      MParList *pList);
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargePix.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargePix.h	(revision 3616)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargePix.h	(revision 3617)
@@ -24,5 +24,5 @@
   Int_t    fPixId;         // The pixel ID
 
-  TH1F     fHAbsTime;      // Histogram to hold the absolute arrival times in number of FADC slices
+  TH1F     fHAbsTime;      // Histogram containing the absolute arrival times 
                           
   Int_t    fChargeNbins;   // Number of  bins used for the fHGausHist
Index: /trunk/MagicSoft/Mars/mcalib/MHGausEvents.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHGausEvents.cc	(revision 3616)
+++ /trunk/MagicSoft/Mars/mcalib/MHGausEvents.cc	(revision 3617)
@@ -282,9 +282,5 @@
 Bool_t MHGausEvents::FillHist(const Float_t f)
 {
-
-  if (fHGausHist.Fill(f) == -1)
-    return kFALSE;
-
- return kTRUE;
+  return fHGausHist.Fill(f) > -1;
 }
 
