Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 2903)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 2904)
@@ -13,9 +13,18 @@
    * mcalib/MCalibrationBlindPix.h
    * mcalib/MHCalibrationBlindPixel.[h,cc]
+   * mcalib/MCalibrationPix.[h,cc]
    * mcalib/MHCalibrationPixel.[h,cc]
-   * mcalib/MHCalibrationPixel.[h,cc]
+   * mcalib/MCalibrationCalc.[h,cc]
      - use MArrivalTime for Storage (or calculation) of time
        in MExtractSignal
      - pass from TH1I histos to TH1F for times
+
+   * mcalib/MCalibrationBlindPix.h
+   * mcalib/MHCalibrationBlindPixel.[h,cc]
+   * mcalib/MCalibrationPix.[h,cc]
+   * mcalib/MHCalibrationPixel.[h,cc]
+   * mcalib/MCalibrationCalc.[h,cc]
+     - clean up  setters 
+     - pass to bit-fields for all flags
 
 
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationBlindPix.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationBlindPix.h	(revision 2903)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationBlindPix.h	(revision 2904)
@@ -57,5 +57,5 @@
   // Fill histos
   Bool_t FillCharge(Float_t q)                  { return fHist->FillBlindPixelCharge(q); }
-  Bool_t FillTime(Int_t t)                      { return fHist->FillBlindPixelTime(t); }  
+  Bool_t FillTime(Float_t t)                    { return fHist->FillBlindPixelTime(t); }  
   Bool_t FillRChargevsTime(Float_t rq, Int_t t) { return fHist->FillBlindPixelChargevsN(rq,t); }    
   
@@ -68,5 +68,4 @@
   void Draw(Option_t *opt="")                     { fHist->Draw(opt); }
   TObject *DrawClone(Option_t *opt="") const    { return fHist->DrawClone(opt); }  
-
   
   ClassDef(MCalibrationBlindPix, 1)	// Storage Container for Calibration information of one pixel
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc	(revision 2903)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc	(revision 2904)
@@ -27,22 +27,24 @@
 //   MCalibrationCalc
 //
-//   This is a task which calculates the number of photons from the FADC
-//   time slices. At the moment it integrates simply the FADC values.
-//
-//
-//  The class MCalibrationCam hold one entry of type MCalibrationPix for
-//  every pixel. It is filled in the following way:
-//  PreParocess: MalibrationCam::InitSize(577) is called which allocates
-//               memory in an TClonesArray of type MCalibrationPix and
-//               all pointers to NULL.
-//
-//  Process:     The NULL pointer is tested on every pixel via
-//               MalibrationCam::IsPixelUsed(npix).
-//
-//               In case, IsPixelUsed returns NULL,
-//               MalibrationCam::AddPixel(npix) is invoked which creates a
-//               new MCalibrationPix(npix) in the npix's entry
-//               of the TClonesArray.
-//
+//   Task to calculate the calibration conversion factors from the FADC
+//   time slices. The integrated time slices have to be delivered by an 
+//   MExtractedSignalCam. The pedestals by an MPedestalCam and possibly 
+//   arrival times from MArrivalTime
+//
+//   The output container MCalibrationCam holds one entry of type MCalibrationPix 
+//   for every pixel. It is filled in the following way:
+//
+//   ProProcess: Search for MPedestalCam, MExtractedSignalCam
+//               Initialize MCalibrationCam
+//               Initialize MArrivalTime if exists
+//               Initialize pulser light wavelength
+//               
+//   ReInit:     MCalibrationCam::InitSize(NumPixels) is called which allocates
+//               memory in a TClonesArray of type MCalibrationPix
+//               Initialize number of used FADC slices
+//               Optionally exclude pixels from calibration               
+//
+//   Process:    Optionally, a cut on cosmics can be performed
+//               
 //               Every MCalibrationPix holds a histogram class,
 //               MHCalibrationPixel which itself hold histograms of type:
@@ -52,22 +54,22 @@
 //               HChargevsN(npix) (distribution of charges vs. event number.
 //
-// PostProcess:  All histograms HCharge(npix) are fitted to a Gaussian
-//               All histograms HTime(npix) are fitted to a Gaussian
-//               The histogram HBlindPixelCharge (blind pixel) is fitted to
-//               a single
-//                   PhE fit
-//               The histogram HBlindPixelTime (blind pixel) is fitted to a
-//               Gaussian
-//               The histograms of the PIN Diode are fitted to Gaussians
-//
-//               Fits can be excluded via the commands:
-//               MalibrationCam::SetSkipTimeFits()   (skip all time fits)
-//               MalibrationCam::SetSkipBlindPixelFits()  (skip all blind
-//               pixel fits)
-//               MalibrationCam::SetSkipPinDiodeFits()  (skip all PIN Diode
-//               fits)
+//  PostProcess:  All histograms HCharge(npix) are fitted to a Gaussian
+//                All histograms HTime(npix) are fitted to a Gaussian
+//                The histogram HBlindPixelCharge (blind pixel) is fitted to
+//                a single PhE fit
+//
+//                The histograms of the PIN Diode are fitted to Gaussians
+//
+//                Fits can be excluded via the commands:
+//                MalibrationCam::SkipTimeFits()   (skip all time fits)
+//                MalibrationCam::SkipBlindPixelFits()  (skip all blind
+//                pixel fits)
+//                MalibrationCam::SkipPinDiodeFits()  (skip all PIN Diode
+//                fits)
 //
 //  Input Containers:
 //   MRawEvtData
+//   MPedestalCam
+//   MExtractedSignalCam
 //
 //  Output Containers:
@@ -80,5 +82,5 @@
 #include <fstream>
 
-// FXIME: This has to be removed!!!!
+// FXIME: This has to be removed!!!! (YES, WHEN WE HAVE ACCESS TO THE DATABASE!!!!!)
 #include "MCalibrationConfig.h"
 
@@ -106,4 +108,6 @@
 #include "MCalibrationPINDiode.h"
 
+#include "MArrivalTime.h"
+
 ClassImp(MCalibrationCalc);
 
@@ -116,6 +120,6 @@
 MCalibrationCalc::MCalibrationCalc(const char *name, const char *title)
     : fPedestals(NULL), fCalibrations(NULL), fSignals(NULL),
-      fRawEvt(NULL), fRunHeader(NULL), fEvtTime(NULL),
-      fEvents(0), fHistOverFlow(0), fCosmics(0),
+      fRawEvt(NULL), fRunHeader(NULL), fArrivalTime(NULL), fEvtTime(NULL),
+      fEvents(0), fCosmics(0),
       fNumHiGainSamples(0), fNumLoGainSamples(0), fConversionHiLo(0.),
       fNumExcludedPixels(0),
@@ -131,7 +135,9 @@
     AddToBranchList("MRawEvtData.fLoGainFadcSamples");
 
-    SETBIT(fFlags, kUseTimeFits);
+    SETBIT(fFlags, kUseTimes);
     SETBIT(fFlags, kUseBlindPixelFit);
     SETBIT(fFlags, kUsePinDiodeFit);
+    SETBIT(fFlags, kUseCosmicsRejection);
+    SETBIT(fFlags, kUseQualityChecks);
 
 }
@@ -158,4 +164,8 @@
 //  - MHCalibrationBlindPixel
 //  - MCalibrationCam
+//
+// The following output containers are only searched, but not created
+//
+//  - MArrivaltime
 //  - MTime
 //
@@ -186,4 +196,10 @@
       }
 
+    fArrivalTime  = (MArrivalTime*)pList->FindObject("MArrivalTime");
+
+    if (!fArrivalTime)
+      CLRBIT(fFlags,kUseTimes);
+
+    fEvtTime      = (MTime*)pList->FindObject("MTime");
 
     switch (fColor)
@@ -268,4 +284,7 @@
                                      fSignals->GetLastUsedSliceLoGain());
         
+        if (!TESTBIT(fFlags,kUseQualityChecks))
+          pix.SetExcludeQualityCheck();
+
       }
     
@@ -340,149 +359,175 @@
 {
 
-    Int_t cosmicpix = 0;
-
-    MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
-    MCalibrationPINDiode &pindiode   = *(fCalibrations->GetPINDiode());
-
-    MRawEvtPixelIter pixel(fRawEvt);
-
-    //
-    // Create a first loop to sort out the cosmics ...
-    // 
-    // This is a very primitive check for the number of cosmicpixs
-    // The cut will be applied in the fit, but for the blind pixel,
-    // we need to remove this event
-    //
-    // FIXME: In the future need a much more sophisticated one!!!
-    //
-
-    while (pixel.Next())
-      {
-	
-	const UInt_t pixid = pixel.GetPixelId();
-	
-	MExtractedSignalPix &sig =  (*fSignals)[pixid];
-        MPedestalPix        &ped =  (*fPedestals)[pixid];
-        Float_t pedrms           = ped.GetPedestalRms()*fSqrtHiGainSamples;
-	Float_t sumhi            = sig.GetExtractedSignalHiGain();
+  //
+  // Initialize pointers to blind pixel, PIN Diode and individual pixels
+  //
+  MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
+  MCalibrationPINDiode &pindiode   = *(fCalibrations->GetPINDiode());
+  
+  MRawEvtPixelIter pixel(fRawEvt);
+  
+  //
+  // Perform cosmics cut
+  //
+  if (TESTBIT(fFlags,kUseCosmicsRejection))
+    {
         
-        //
-        // We consider a pixel as presumably due to cosmics 
-        // if its sum of FADC slices is lower than 3 pedestal RMS
-        //
-	if (sumhi < 3.*pedrms )  
-	  cosmicpix++;
-     }
-
-    //
-    // If the camera contains more than 230 
-    // (this is the number of outer pixels plus about 50 inner ones)
-    // presumed pixels due to cosmics, then the event is discarted. 
-    // This procedure is more or less equivalent to keeping only events 
-    // with at least 350 pixels with high signals.
-    //
-    if (cosmicpix > 230.)
-      {
-	fCosmics++;
-	return kCONTINUE;
-      }
-
-    pixel.Reset();
-    fEvents++;
-
-
-    //
-    // Create a second loop to do fill the calibration histograms
-    // 
-
-    while (pixel.Next())
-      {
-
-	const UInt_t pixid = pixel.GetPixelId();
-	
-	MCalibrationPix &pix = (*fCalibrations)[pixid];
-
-        if (pix.IsExcluded())
-          continue;
-
-	MExtractedSignalPix &sig =  (*fSignals)[pixid];
-        
-	Float_t sumhi  = sig.GetExtractedSignalHiGain();
-	Float_t sumlo  = sig.GetExtractedSignalLoGain();
-	Float_t mtime  = sig.GetMeanArrivalTime();
-
-
-        switch(pixid)
-          {
-            
-          case gkCalibrationBlindPixelId:
-
-	    if (!blindpixel.FillCharge(sumhi)) 
-	      *fLog << warn << 
-		"Overflow or Underflow occurred filling Blind Pixel sum = " << sumhi << endl;
-
-	    if (!blindpixel.FillTime((int)mtime)) 
-	      *fLog << warn << 
-		"Overflow or Underflow occurred filling Blind Pixel time = " << mtime << endl;
-	    
-	    if (!blindpixel.FillRChargevsTime(sumhi,fEvents))
-	      *fLog << warn << 
-		"Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
-            break;
-            
-          case gkCalibrationPINDiodeId:
-            if (!pindiode.FillCharge(sumhi)) 
-              *fLog << warn << 
-                "Overflow or Underflow occurred filling PINDiode: sum = " << sumhi << endl;
-            if (!pindiode.FillTime((int)mtime)) 
-              *fLog << warn << 
-                "Overflow or Underflow occurred filling PINDiode: time = " << mtime << endl;
-            if (!pindiode.FillRChargevsTime(sumhi,fEvents))
-              *fLog << warn << 
-                "Overflow or Underflow occurred filling PINDiode: eventnr = " << fEvents << endl;
-	    break;
-
-          default:
-
-	    pix.SetChargesInGraph(sumhi,sumlo);
-
-	    if (!pix.FillRChargevsTimeLoGain(sumlo,fEvents))
-	      *fLog << warn << "Could not fill Lo Gain Charge vs. EvtNr of pixel: " 
-		    << pixid << " signal = " << sumlo  << " event Nr: " << fEvents << endl;
-		
-	    if (!pix.FillRChargevsTimeHiGain(sumhi,fEvents))
-	      *fLog << warn << "Could not fill Hi Gain Charge vs. EvtNr of pixel: " 
-		    << pixid << " signal = " << sumhi  << " event Nr: " << fEvents << endl;
-
-	    if (sig.IsLoGainUsed())
-	      {
-		
-		if (!pix.FillChargeLoGain(sumlo))
-		  *fLog << warn << "Could not fill Lo Gain Charge of pixel: " << pixid 
-			<< " signal = " << sumlo << endl;
-
-		if (!pix.FillTimeLoGain((int)mtime)) 
-		  *fLog << warn << "Could not fill Lo Gain Time of pixel: " 
-			<< pixid << " time = " << mtime << endl;
-		
-	      }
-	    else
-	      {
-		if (!pix.FillChargeHiGain(sumhi))
-		  *fLog << warn << "Could not fill Hi Gain Charge of pixel: " << pixid 
-			<< " signal = " << sumhi << endl;
-		
-		if (!pix.FillTimeHiGain((int)mtime)) 
-		  *fLog << warn << "Could not fill Hi Gain Time of pixel: " 
-			<< pixid << " time = " << mtime << endl;
-		
-	      }
-	    break;
-	    
-          } /* switch(pixid) */
-
-      } /* while (pixel.Next()) */
-
-    return kTRUE;
+      Int_t cosmicpix = 0;
+      
+      //
+      // Create a first loop to sort out the cosmics ...
+      // 
+      // This is a very primitive check for the number of cosmicpixs
+      // The cut will be applied in the fit, but for the blind pixel,
+      // we need to remove this event
+      //
+      // FIXME: In the future need a much more sophisticated one!!!
+      //
+      
+      while (pixel.Next())
+        {
+          
+          const UInt_t pixid = pixel.GetPixelId();
+          
+          MExtractedSignalPix &sig =  (*fSignals)[pixid];
+          MPedestalPix        &ped =  (*fPedestals)[pixid];
+          Float_t pedrms           = ped.GetPedestalRms()*fSqrtHiGainSamples;
+          Float_t sumhi            = sig.GetExtractedSignalHiGain();
+          
+          //
+          // We consider a pixel as presumably due to cosmics 
+          // if its sum of FADC slices is lower than 3 pedestal RMS
+          //
+          if (sumhi < 3.*pedrms )  
+            cosmicpix++;
+        }
+      
+      //
+      // If the camera contains more than 230 
+      // (this is the number of outer pixels plus about 50 inner ones)
+      // presumed pixels due to cosmics, then the event is discarted. 
+      // This procedure is more or less equivalent to keeping only events 
+      // with at least 350 pixels with high signals.
+      //
+      if (cosmicpix > 230.)
+        {
+          fCosmics++;
+          return kCONTINUE;
+        }
+      
+      pixel.Reset();
+    }
+  
+  fEvents++;
+  
+  //
+  // Create a (second) loop to do fill the calibration histograms
+  // 
+  
+  while (pixel.Next())
+    {
+      
+      const UInt_t pixid = pixel.GetPixelId();
+      
+      MCalibrationPix &pix = (*fCalibrations)[pixid];
+      
+      if (pix.IsExcluded())
+        continue;
+      
+      MExtractedSignalPix &sig =  (*fSignals)[pixid];
+      
+      const Float_t sumhi  = sig.GetExtractedSignalHiGain();
+      const Float_t sumlo  = sig.GetExtractedSignalLoGain();
+
+      Double_t mtime = 0.;
+
+      if (TESTBIT(fFlags,kUseTimes))
+        mtime = (*fArrivalTime)[pixid];
+      
+      switch(pixid)
+        {
+          
+        case gkCalibrationBlindPixelId:
+          
+          if (!blindpixel.FillCharge(sumhi)) 
+            *fLog << warn << 
+              "Overflow or Underflow occurred filling Blind Pixel sum = " << sumhi << endl;
+          
+          if (TESTBIT(fFlags,kUseTimes))
+            {
+              if (!blindpixel.FillTime(mtime))
+                *fLog << warn << 
+                  "Overflow or Underflow occurred filling Blind Pixel time = " << mtime << endl;
+            }
+          
+          if (!blindpixel.FillRChargevsTime(sumhi,fEvents))
+            *fLog << warn << 
+              "Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
+          break;
+          
+        case gkCalibrationPINDiodeId:
+
+          if (!pindiode.FillCharge(sumhi)) 
+            *fLog << warn << 
+              "Overflow or Underflow occurred filling PINDiode: sum = " << sumhi << endl;
+
+          if (TESTBIT(fFlags,kUseTimes))
+            {
+              if (!pindiode.FillTime(mtime))
+                *fLog << warn << 
+                  "Overflow or Underflow occurred filling PINDiode: time = " << mtime << endl;
+            }
+          
+          if (!pindiode.FillRChargevsTime(sumhi,fEvents))
+            *fLog << warn << 
+              "Overflow or Underflow occurred filling PINDiode: eventnr = " << fEvents << endl;
+          break;
+          
+        default:
+          
+          pix.FillChargesInGraph(sumhi,sumlo);
+
+          if (!pix.FillRChargevsTimeLoGain(sumlo,fEvents))
+            *fLog << warn << "Could not fill Lo Gain Charge vs. EvtNr of pixel: " 
+                  << pixid << " signal = " << sumlo  << " event Nr: " << fEvents << endl;
+          
+          if (!pix.FillRChargevsTimeHiGain(sumhi,fEvents))
+            *fLog << warn << "Could not fill Hi Gain Charge vs. EvtNr of pixel: " 
+                  << pixid << " signal = " << sumhi  << " event Nr: " << fEvents << endl;
+          
+          if (sig.IsLoGainUsed())
+            {
+              
+              if (!pix.FillChargeLoGain(sumlo))
+                *fLog << warn << "Could not fill Lo Gain Charge of pixel: " << pixid 
+                      << " signal = " << sumlo << endl;
+              
+              if (TESTBIT(fFlags,kUseTimes))
+                {
+                  if (!pix.FillTimeLoGain(mtime)) 
+                    *fLog << warn << "Could not fill Lo Gain Time of pixel: " 
+                          << pixid << " time = " << mtime << endl;
+                }
+            } /* if (sig.IsLoGainUsed()) */
+          else
+            {
+              if (!pix.FillChargeHiGain(sumhi))
+                *fLog << warn << "Could not fill Hi Gain Charge of pixel: " << pixid 
+                      << " signal = " << sumhi << endl;
+              
+              if (TESTBIT(fFlags,kUseTimes))
+                {
+                  if (!pix.FillTimeHiGain(mtime))
+                    *fLog << warn << "Could not fill Hi Gain Time of pixel: " 
+                          << pixid << " time = " << mtime << endl;
+                }
+            } /* else (sig.IsLoGainUsed()) */
+          break;
+          
+        } /* switch(pixid) */
+      
+    } /* while (pixel.Next()) */
+  
+  return kTRUE;
 }
 
@@ -531,5 +576,5 @@
         }
 
-      //blindpixel.DrawClone();
+      blindpixel.DrawClone();
     }
   else 
@@ -573,5 +618,5 @@
       // Perform the Gauss fits to the arrival times
       //
-      if (TESTBIT(fFlags,kUseTimeFits))
+      if (TESTBIT(fFlags,kUseTimes))
         pix.FitTime();
       
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.h	(revision 2903)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.h	(revision 2904)
@@ -1,4 +1,13 @@
 #ifndef MARS_MCalibrationCalc
 #define MARS_MCalibrationCalc
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MCalibrationCalc                                                   //
+//                                                                         //
+// Integrates the time slices of the all pixels of a calibration event     //
+// and substract the pedestal value                                        //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
 
 #ifndef MARS_MTask
@@ -6,14 +15,23 @@
 #endif
 
+#ifndef ROOT_TArrayI
+#include "TArrayI.h"
+#endif
+
+#ifndef MARS_MCalibrationCam
+#include "MCalibrationCam.h"
+#endif
+
+#include "TString.h"
+
+class MRawEvtData;
+class MRawRunHeader;
+
 class MPedestalCam;
 class MCalibrationCam;
 class MExtractedSignalCam;
-
-class MCalibrationBlindPix;
-class MCalibrationPINDiode;
+class MArrivalTime;
 
 class MTime;
-class MRawEvtData;
-class MRawRunHeader;
 
 class MCalibrationCalc : public MTask
@@ -28,8 +46,9 @@
   MRawRunHeader            *fRunHeader;    // RunHeader information
 
+  MArrivalTime             *fArrivalTime;  // Calculated Arrival Times
+  
   MTime                    *fEvtTime;      // Time of the event
 
   Int_t fEvents;                           // Number of events  
-  Int_t fHistOverFlow;                     // Number of events with saturated Low Gain
   Int_t fCosmics;                          // Number of events due to supposed cosmics
 
@@ -61,18 +80,22 @@
   MCalibrationCalc(const char *name=NULL, const char *title=NULL);
 
-
 private:
 
-  enum  { kUseTimeFits, kUseBlindPixelFit, kUsePinDiodeFit };
+  enum  { kUseTimes, kUseBlindPixelFit, kUsePinDiodeFit,
+          kUseCosmicsRejection, kUseQualityChecks };
 
 public:
 
-  // Skipping fits 
-  void SkipTimeFits(Bool_t b=kTRUE)
-      {b ? CLRBIT(fFlags, kUseTimeFits) : SETBIT(fFlags, kUseTimeFits);}
+  // Skipping parts of the work
+  void SkipTime(Bool_t b=kTRUE)
+      {b ? CLRBIT(fFlags, kUseTimes) : SETBIT(fFlags, kUseTimes);}
   void SkipBlindPixelFit(Bool_t b=kTRUE)
       {b ? CLRBIT(fFlags, kUseBlindPixelFit) : SETBIT(fFlags, kUseBlindPixelFit);}
   void SkipPinDiodeFit(Bool_t b=kTRUE)
       {b ? CLRBIT(fFlags, kUsePinDiodeFit) : SETBIT(fFlags, kUsePinDiodeFit);}
+  void SkipCosmicsRejection(Bool_t b=kTRUE)
+      {b ? CLRBIT(fFlags, kUseCosmicsRejection) : SETBIT(fFlags, kUseCosmicsRejection);}
+  void SkipQualityChecks(Bool_t b=kTRUE)
+      {b ? CLRBIT(fFlags, kUseQualityChecks) : SETBIT(fFlags, kUseQualityChecks);}
 
   // Setters 
@@ -82,5 +105,5 @@
   // Getters
   MCalibrationBlindPix *GetBlindPixel() const;
-  MCalibrationPINDiode *GetPINDiode() const;
+  MCalibrationPINDiode *GetPINDiode()   const;
 
   // Exclude pixels from configuration file
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.h	(revision 2903)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationPINDiode.h	(revision 2904)
@@ -37,5 +37,5 @@
 
   Bool_t FillCharge(Float_t q)      { return fHist->FillChargeHiGain(q); }
-  Bool_t FillTime(Int_t t)          { return fHist->FillTimeHiGain(t); }  
+  Bool_t FillTime(Float_t t)        { return fHist->FillTimeHiGain(t); }  
   Bool_t FillRChargevsTime(Float_t rq, Int_t t) { return fHist->FillChargevsNHiGain(rq,t); }    
   
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc	(revision 2903)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.cc	(revision 2904)
@@ -83,13 +83,8 @@
       fConversionSigmaBlindPixelMethod(-1.),
       fConversionSigmaPINDiodeMethod(-1.),
-      fHiGainSaturation(kFALSE),
-      fExcluded(kFALSE),
-      fFitValid(kFALSE),        
-      fFitted(kFALSE), 
-      fBlindPixelMethodValid(kFALSE),
-      fFFactorMethodValid(kFALSE),
-      fPINDiodeMethodValid(kFALSE),
-      fChargeLimit(5.),
-      fChargeErrLimit(0.)
+      fFlags(0),
+      fChargeLimit(3.),
+      fChargeErrLimit(0.),
+      fChargeRelErrLimit(1.)
 {
 
@@ -109,4 +104,12 @@
     *fLog << warn << dbginf << " Could not create MHCalibrationPixel " << endl;
 
+  CLRBIT(fFlags, kHiGainSaturation);
+  CLRBIT(fFlags, kExcluded);
+  CLRBIT(fFlags, kFitValid);
+  CLRBIT(fFlags, kFitted);
+  CLRBIT(fFlags, kBlindPixelMethodValid);
+  CLRBIT(fFlags, kFFactorMethodValid);
+  CLRBIT(fFlags, kPINDiodeMethodValid);
+
 }
 
@@ -115,4 +118,6 @@
   delete fHist;
 }
+
+
 
 
@@ -132,5 +137,175 @@
 void MCalibrationPix::Clear(Option_t *o)
 {
+
   fHist->Reset();
+
+  CLRBIT(fFlags, kHiGainSaturation);
+  CLRBIT(fFlags, kExcluded);
+  CLRBIT(fFlags, kFitValid);
+  CLRBIT(fFlags, kFitted);
+  CLRBIT(fFlags, kBlindPixelMethodValid);
+  CLRBIT(fFlags, kFFactorMethodValid);
+  CLRBIT(fFlags, kPINDiodeMethodValid);
+
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the pedestals from outside
+//
+void MCalibrationPix::SetPedestal(Float_t ped, Float_t pedrms)
+{
+
+  fPed    = ped;    
+  fPedRms = pedrms;
+  
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the conversion factors from outside (only for MC)
+//
+void MCalibrationPix::SetConversionFFactorMethod(Float_t c, Float_t err, Float_t sig)
+{
+  fConversionFFactorMethod = c;
+  fConversionErrorFFactorMethod = err;
+  fConversionSigmaFFactorMethod = sig;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Set the conversion factors from outside (only for MC)
+//
+void MCalibrationPix::SetConversionBlindPixelMethod(Float_t c, Float_t err, Float_t sig)
+{
+  fConversionBlindPixelMethod = c;
+  fConversionErrorBlindPixelMethod = err;
+  fConversionSigmaBlindPixelMethod = sig;
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the conversion factors from outside (only for MC)
+//
+void MCalibrationPix::SetConversionPINDiodeMethod(Float_t c, Float_t err, Float_t sig)
+{
+  fConversionPINDiodeMethod = c ;
+  fConversionErrorPINDiodeMethod = err;
+  fConversionSigmaPINDiodeMethod = sig;
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the Hi Gain Saturation Bit from outside (only for MC)
+//
+void MCalibrationPix::SetHiGainSaturation(Bool_t b)
+{
+
+  if (b) 
+    { 
+      SETBIT(fFlags, kHiGainSaturation); 
+      fHist->SetUseLoGain(1); 
+    }
+  else    
+    {
+      CLRBIT(fFlags, kHiGainSaturation); 
+      fHist->SetUseLoGain(0); 
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the Excluded Bit from outside 
+//
+void MCalibrationPix::SetExcluded(Bool_t b )
+{ 
+  b ?  SETBIT(fFlags, kExcluded) : CLRBIT(fFlags, kExcluded); 
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Set the Excluded Bit from outside 
+//
+void MCalibrationPix::SetExcludeQualityCheck(Bool_t b )
+{ 
+  b ?  SETBIT(fFlags, kExcludeQualityCheck) : CLRBIT(fFlags, kExcludeQualityCheck); 
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the Excluded Bit from outside 
+//
+void MCalibrationPix::SetFitValid(Bool_t b )    
+{ 
+  b ?  SETBIT(fFlags, kFitValid) : CLRBIT(fFlags, kFitValid); 
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the Excluded Bit from outside 
+//
+void MCalibrationPix::SetFitted(Bool_t b )
+{ 
+  b ?  SETBIT(fFlags, kFitted) : CLRBIT(fFlags, kFitted); 
+}
+    
+// --------------------------------------------------------------------------
+//
+// Set the Excluded Bit from outside 
+//
+void MCalibrationPix::SetBlindPixelMethodValid(Bool_t b )
+{ 
+  b ?  SETBIT(fFlags, kBlindPixelMethodValid) : CLRBIT(fFlags, kBlindPixelMethodValid); 
+}    
+
+// --------------------------------------------------------------------------
+//
+// Set the Excluded Bit from outside 
+//
+void MCalibrationPix::SetFFactorMethodValid(Bool_t b )
+{ 
+  b ?  SETBIT(fFlags, kFFactorMethodValid) : CLRBIT(fFlags, kFFactorMethodValid); 
+}    
+
+// --------------------------------------------------------------------------
+//
+// Set the Excluded Bit from outside 
+//
+void MCalibrationPix::SetPINDiodeMethodValid(Bool_t b )  
+{ 
+  b ?  SETBIT(fFlags, kPINDiodeMethodValid) : CLRBIT(fFlags, kPINDiodeMethodValid); 
+}
+
+
+Bool_t MCalibrationPix::IsExcluded() const
+ { 
+   return TESTBIT(fFlags,kExcluded);  
+ }
+
+Bool_t MCalibrationPix::IsFitValid() const 
+{
+  return TESTBIT(fFlags, kFitValid);  
+}
+
+Bool_t MCalibrationPix::IsFitted() const 
+{ 
+  return TESTBIT(fFlags, kFitted);    
+}
+
+Bool_t MCalibrationPix::IsBlindPixelMethodValid() const 
+{ 
+  return TESTBIT(fFlags, kBlindPixelMethodValid); 
+}
+
+Bool_t MCalibrationPix::IsFFactorMethodValid()  const 
+{ 
+  return TESTBIT(fFlags, kFFactorMethodValid);     
+}
+
+Bool_t MCalibrationPix::IsPINDiodeMethodValid() const 
+{ 
+  return TESTBIT(fFlags, kPINDiodeMethodValid);    
 }
 
@@ -203,6 +378,9 @@
           // 5) In case of failure print out the fit results
           //
-	  fHist->PrintChargeFitResult();
+          //	  fHist->PrintChargeFitResult();
+          CLRBIT(fFlags,kFitted);
 	}
+      else
+        SETBIT(fFlags,kFitted);
     }
   else 
@@ -217,6 +395,9 @@
           // 5) In case of failure print out the fit results
           //
-	  fHist->PrintChargeFitResult();
+          //	  fHist->PrintChargeFitResult();
+          CLRBIT(fFlags,kFitted);
 	}
+      else
+        SETBIT(fFlags,kFitted);
     }
   
@@ -231,17 +412,11 @@
   fChargeProb     = fHist->GetChargeProb();
 
-  if (fCharge <= 0.)
-    {
-      *fLog << warn << "WARNING: Cannot apply calibration: Mean Fitted Charges are smaller than 0 in pixel " 
-            << fPixId << endl;
+  if (CheckChargeFitValidity())
+    SETBIT(fFlags,kFitValid);
+  else
+    {
+      CLRBIT(fFlags,kFitValid);
       return kFALSE;
     }
-
-  if (fErrCharge > 0.) 
-    fFitted = kTRUE;
-
-  if (CheckChargeFitValidity())
-    fFitValid = kTRUE;
-
   
   //
@@ -273,5 +448,5 @@
       Float_t pedRmsSquareErrSquare           = 4.*fErrPedRms*fErrPedRms * pedRmsSquare;
 
-      if (fHiGainSaturation)
+      if (TESTBIT(fFlags,kHiGainSaturation))
 	{
           
@@ -306,5 +481,5 @@
           pedRmsSquareErrSquare  = convertedNsbSquareErrSquare  + elecRmsSquareErrSquare;
           
-	}    /* if (fHiGainSaturation) */
+	}    /* if (kHiGainSaturation) */
       
       //
@@ -317,5 +492,5 @@
                 << "WARNING: Cannot apply F-Factor calibration: Reduced Sigma smaller than 0 in pixel " 
                 << fPixId << endl;
-          if (fHiGainSaturation)
+          if (TESTBIT(fFlags,kHiGainSaturation))
             ApplyLoGainConversion();
           return kFALSE;
@@ -340,5 +515,5 @@
       // Calculate the conversion factors 
       //
-      if (fHiGainSaturation)
+      if (TESTBIT(fFlags,kHiGainSaturation))
         ApplyLoGainConversion();
       
@@ -352,6 +527,7 @@
            (fConversionFFactorMethod > 0.) &&
            (fConversionErrorFFactorMethod/fConversionFFactorMethod < 0.1) )
-        fFFactorMethodValid = kTRUE;
-      
+        SETBIT(fFlags,kFFactorMethodValid);
+      else 
+        CLRBIT(fFlags,kFFactorMethodValid);
       
     } /*   if ((fPed > 0.)  && (fPedRms > 0.)) */
@@ -366,13 +542,17 @@
 // 1) Pixel has a fitted charge greater than 5*PedRMS
 // 2) Pixel has a fit error greater than 0.
-// 3) Pixel has a fit Probability greater than 0.0001 
-// 4) Pixel has a charge sigma bigger than its Pedestal RMS
+// 3) Pixel has a fitted charge greater its charge error
+// 4) Pixel has a fit Probability greater than 0.0001 
+// 5) Pixel has a charge sigma bigger than its Pedestal RMS
 // 
 Bool_t MCalibrationPix::CheckChargeFitValidity()
 {
 
+  if (TESTBIT(fFlags,kExcludeQualityCheck))
+    return kTRUE;
+
   Float_t equivpedestal = GetPedRms();
 
-  if (fHiGainSaturation)
+  if (TESTBIT(fFlags,kHiGainSaturation))
     equivpedestal /= fConversionHiLo;
       
@@ -391,4 +571,11 @@
     }
       
+  if (fCharge < fChargeRelErrLimit*fErrCharge) 
+    {
+      *fLog << warn << "WARNING: Error of Fitted Charge is greater than "
+            << fChargeRelErrLimit << "* Fitted Charges itself in Pixel " << fPixId << endl;
+      return kFALSE;
+    }
+      
   if (!fHist->IsFitOK()) 
     {
@@ -413,8 +600,11 @@
 {
 
+  if (TESTBIT(fFlags,kExcludeQualityCheck))
+    return kTRUE;
+
   Float_t lowerrange;
   Float_t upperrange;
 
-  if (fHiGainSaturation)
+  if (TESTBIT(fFlags,kHiGainSaturation))
     {
       lowerrange = (Float_t)fHist->GetTimeLowerFitRangeLoGain()+1.;
@@ -481,15 +671,4 @@
 
 
-// --------------------------------------------------------------------------
-//
-// Set the pedestals from outside
-//
-void MCalibrationPix::SetPedestal(Float_t ped, Float_t pedrms)
-{
-
-  fPed    = ped;    
-  fPedRms = pedrms;
-  
-}
 
 // --------------------------------------------------------------------------
@@ -510,5 +689,5 @@
   // Fit the Low Gain
   //
-  if (fHiGainSaturation)
+  if (TESTBIT(fFlags,kHiGainSaturation))
     {
       if(!fHist->FitTimeLoGain())
@@ -538,6 +717,8 @@
   fTimeProb      = fHist->GetTimeProb();
 
-  if (!CheckTimeFitValidity())
-    fFitValid = kFALSE;
+  if (CheckTimeFitValidity())
+    SETBIT(fFlags,kFitValid);
+  else
+    CLRBIT(fFlags,kFitValid);
 
   return kTRUE;
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.h	(revision 2903)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationPix.h	(revision 2904)
@@ -52,17 +52,16 @@
   Float_t fConversionHiLoError;             // The error of the conversion factor between Hi Gain and Lo Gain  
   
-  Bool_t  fHiGainSaturation;                // Is Lo-Gain used at all?
+  Byte_t  fFlags;                           // Flag for the set Bits
 
-  Bool_t  fExcluded;
-  Bool_t  fFitValid;        
-  Bool_t  fFitted; 
-  Bool_t  fBlindPixelMethodValid;
-  Bool_t  fFFactorMethodValid;
-  Bool_t  fPINDiodeMethodValid;
+  enum  { kHiGainSaturation,
+          kExcluded, kExcludeQualityCheck,
+          kFitValid, kFitted,
+          kBlindPixelMethodValid, kFFactorMethodValid, kPINDiodeMethodValid };
   
-  MHCalibrationPixel *fHist;    //! Pointer to the histograms performing the fits, etc.  
+  MHCalibrationPixel *fHist;                //! Pointer to the histograms performing the fits, etc.  
 
   Float_t fChargeLimit;
   Float_t fChargeErrLimit;
+  Float_t fChargeRelErrLimit;  
   
   Bool_t CheckChargeFitValidity();
@@ -78,10 +77,5 @@
 
   // Getter
-  Bool_t IsExcluded()              const { return fExcluded;  }  
-  Bool_t IsFitValid()              const { return fFitValid;  }
-  Bool_t IsFitted()                const { return fFitted;    }
-  Bool_t IsBlindPixelMethodValid() const { return fBlindPixelMethodValid;  }
-  Bool_t IsFFactorMethodValid()    const { return fFFactorMethodValid;     }
-  Bool_t IsPINDiodeMethodValid()   const { return fPINDiodeMethodValid;    }
+  MHCalibrationPixel *GetHist() const   { return fHist;     }
 
   // Charges
@@ -117,66 +111,60 @@
   Float_t GetSigmaConversionPINDiodeMethod()   const { return fConversionSigmaPINDiodeMethod ; }
 
-  // FIXME: Remove this from stored data members
+  Int_t   GetPixId()                           const  { return fPixId;   }
+
   Float_t GetPed()                             const { return fPed;    }
   Float_t GetPedRms()                          const { return fPedRms; }
 
+  Bool_t IsExcluded()              const;
+  Bool_t IsFitValid()              const;
+  Bool_t IsFitted()                const;
+  Bool_t IsBlindPixelMethodValid() const;
+  Bool_t IsFFactorMethodValid()    const;
+  Bool_t IsPINDiodeMethodValid()   const;
+
   // Setter
   void SetPedestal(Float_t ped, Float_t pedrms);
-  void SetHiGainSaturation()             { fHiGainSaturation = kTRUE; fHist->SetUseLoGain(); }
+  void SetConversionHiLo(Float_t c)      { fConversionHiLo      = c;    }
+  void SetConversionHiLoError(Float_t e)  { fConversionHiLoError = e;    }
 
-  void SetConversionHiLo(Float_t c)      { fConversionHiLo      = c;    }
-  void SetConversionHiLoError(Float_t e) { fConversionHiLoError = e;    }
+  // Setters for MC
+  void SetConversionFFactorMethod(Float_t c, Float_t err, Float_t sig);
+  void SetConversionBlindPixelMethod(Float_t c, Float_t err, Float_t sig);
+  void SetConversionPINDiodeMethod(Float_t c, Float_t err, Float_t sig);
 
-  void SetConversionFFactorMethod(Float_t c, Float_t err, Float_t sig)
-  {
-      fConversionFFactorMethod = c;
-      fConversionErrorFFactorMethod = err;
-      fConversionSigmaFFactorMethod = sig;
-  }
-  void SetConversionBlindPixelMethod(Float_t c, Float_t err, Float_t sig)
-  {
-      fConversionBlindPixelMethod = c;
-      fConversionErrorBlindPixelMethod = err;
-      fConversionSigmaBlindPixelMethod = sig;
-  }
-
-  void SetConversionPINDiodeMethod(Float_t c, Float_t err, Float_t sig)
-  {
-      fConversionPINDiodeMethod = c ;
-      fConversionErrorPINDiodeMethod = err;
-      fConversionSigmaPINDiodeMethod = sig;
-  }
-
-  void SetExcluded(Bool_t b = kTRUE)            { fExcluded = b;   }  
-  void SetFitValid(Bool_t b = kTRUE)            { fFitValid = b;  }
-  void SetFitted(Bool_t b = kTRUE)             { fFitted   = b;  }
-  void SetBlindPixelMethodValid(Bool_t b = kTRUE)    { fBlindPixelMethodValid = b;  }
-  void SetFFactorMethodValid(Bool_t b = kTRUE)      { fFFactorMethodValid = b;  }
-  void SetPINDiodeMethodValid(Bool_t b = kTRUE)      { fPINDiodeMethodValid = b;  }
-
-  // Unknown
-  void   ApplyLoGainConversion();
-
-  void   SetChargesInGraph(Float_t qhi,Float_t qlo) { fHist->SetPointInGraph(qhi,qlo); }
-
+  // Bit Setters
+  void SetHiGainSaturation(Bool_t b = kTRUE);
+  void SetExcluded(Bool_t b = kTRUE);
+  void SetExcludeQualityCheck(Bool_t b = kTRUE);
+  void SetFitValid(Bool_t b = kTRUE);
+  void SetFitted(Bool_t b = kTRUE);
+  void SetBlindPixelMethodValid(Bool_t b = kTRUE);
+  void SetFFactorMethodValid(Bool_t b = kTRUE);
+  void SetPINDiodeMethodValid(Bool_t b = kTRUE);
+  
+  // Fill histos
   Bool_t FillChargeHiGain(Float_t q)                   { return fHist->FillChargeHiGain(q); }
-  Bool_t FillTimeHiGain(Int_t t)                       { return fHist->FillTimeHiGain(t); }  
+  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 FillChargeLoGain(Float_t q)                   { return fHist->FillChargeLoGain(q); }
-  Bool_t FillTimeLoGain(Int_t t)                       { return fHist->FillTimeLoGain(t); }  
+  Bool_t FillTimeLoGain(Float_t t)                     { return fHist->FillTimeLoGain(t); }  
   Bool_t FillRChargevsTimeLoGain(Float_t rq, Int_t t)  { return fHist->FillChargevsNLoGain(rq,t); }    
   
-  // FIXME: Not necessary -> pixidx (not id anyhow!) == index in array!
-  //        Only needed n histograms which have to move to an MH-class anyhow!
-  Int_t  GetPixId()                              const  { return fPixId;   }
+  Bool_t FillChargesInGraph(Float_t qhi,Float_t qlo)   { return fHist->FillPointInGraph(qhi,qlo); }
+
   void   DefinePixId(Int_t i);
-  
+
+  // Fits
   Bool_t FitCharge();
   Bool_t FitTime();
   
-  MHCalibrationPixel *GetHist() const   { return fHist;     }
-  void Draw(Option_t *opt="")            { fHist->Draw(opt); }
+  // Draws
+  void Draw(Option_t *opt="")                    { fHist->Draw(opt); }
+  TObject *DrawClone(Option_t *opt="") const    { return fHist->DrawClone(opt); }  
   
+  // Miscellaneous
+  void   ApplyLoGainConversion();
+
   ClassDef(MCalibrationPix, 1)	// Storage Container for Calibration information of one pixel
 };
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.cc	(revision 2903)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.cc	(revision 2904)
@@ -96,5 +96,5 @@
     Int_t nbins   = 16;
 
-    fHBlindPixelTime = new TH1I("HBlindPixelTime","Distribution of Mean Arrival Times",nbins,tfirst,tlast);
+    fHBlindPixelTime = new TH1F("HBlindPixelTime","Distribution of Mean Arrival Times",nbins,tfirst,tlast);
     fHBlindPixelTime->SetXTitle("Mean Arrival Times [FADC slice nr]");
     fHBlindPixelTime->SetYTitle("Nr. of events");
@@ -141,5 +141,5 @@
 }
 
-Bool_t MHCalibrationBlindPixel::FillBlindPixelTime(Int_t t)
+Bool_t MHCalibrationBlindPixel::FillBlindPixelTime(Float_t t)
 {
     return fHBlindPixelTime->Fill(t) > -1;
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.h	(revision 2903)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.h	(revision 2904)
@@ -10,33 +10,4 @@
 class TF1;
 class TPaveText;
-
-/*
-#ifndef MARS_MHCalibrationConfig
-#include "MHCalibrationConfig.h"
-#endif
-
-#ifndef MARS_MFFT
-#include "MFFT.h"
-#endif
-
-#ifndef ROOT_TH1
-#include "TH1.h"
-#endif
-
-#ifndef ROOT_TH1F
-#include "TH1F.h"
-#endif
-
-#ifndef ROOT_TF1
-#include "TF1.h"
-#endif
-
-#ifndef ROOT_TPaveText
-#include "TPaveText.h"
-#endif
-*/
-
-
-const Double_t NoWay = 10000000000.0;
 
 class TMath;
@@ -47,5 +18,5 @@
 
   TH1F* fHBlindPixelCharge;        // Histogram with the single Phe spectrum
-  TH1I* fHBlindPixelTime;          // Variance of summed FADC slices
+  TH1F* fHBlindPixelTime;          // Variance of summed FADC slices
   TH1I* fHBlindPixelChargevsN;     // Summed Charge vs. Event Nr.
   TH1F* fHBlindPixelPSD;           // Power spectrum density of fHBlindPixelChargevsN
@@ -95,5 +66,5 @@
 
   Bool_t FillBlindPixelCharge(Float_t q);
-  Bool_t FillBlindPixelTime(Int_t t);
+  Bool_t FillBlindPixelTime(Float_t t);
   Bool_t FillBlindPixelChargevsN(Stat_t rq, Int_t t);
   
@@ -153,4 +124,6 @@
 private:
 
+  const static Double_t fNoWay = 10000000000.0;
+
   Bool_t InitFit(Axis_t min, Axis_t max);
   void ExitFit(TF1 *f);  
@@ -168,5 +141,5 @@
       
       if (mu1 < mu0)
-        return NoWay;
+        return fNoWay;
 
       Double_t sigma0 = par[3];
@@ -174,5 +147,5 @@
       
       if (sigma1 < sigma0)
-        return NoWay;
+        return fNoWay;
       
       Double_t mu2 = (2.*mu1)-mu0;  
@@ -224,5 +197,5 @@
       
       if (mu1 < mu0)
-        return NoWay;
+        return fNoWay;
 
       Double_t sigma0 = par[3];
@@ -230,5 +203,5 @@
       
       if (sigma1 < sigma0)
-        return NoWay;
+        return fNoWay;
       
       Double_t mu2 = (2.*mu1)-mu0;  
@@ -281,5 +254,5 @@
       
       if (mu1 < mu0)
-        return NoWay;
+        return fNoWay;
       
       Double_t sigma0 = par[3];
@@ -287,5 +260,5 @@
       
       if (sigma1 < sigma0)
-        return NoWay;
+        return fNoWay;
       
       
@@ -346,5 +319,5 @@
       
       if (mu1 < mu0)
-        return NoWay;
+        return fNoWay;
       
       Double_t sigma0 = par[3];
@@ -352,5 +325,5 @@
       
       if (sigma1 < sigma0)
-        return NoWay;
+        return fNoWay;
       
       
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationPINDiode.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationPINDiode.h	(revision 2903)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationPINDiode.h	(revision 2904)
@@ -16,6 +16,5 @@
   TH1I* fHPCharge;           //-> Histogram containing the summed 32 PINDiode slices
   TH1F* fHErrCharge;         //-> Variance of summed FADC slices
-  TH1I* fHPTime;             //-> Histogram with time evolution of summed charges
-  
+  TH1F* fHPTime;             //-> Histogram with time evolution of summed charges
   
   TF1 *fVarGausFit;
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc	(revision 2903)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.cc	(revision 2904)
@@ -41,4 +41,5 @@
 #include <TCanvas.h>
 #include <TPaveText.h>
+#include <TText.h>
 
 #include "MLog.h"
@@ -56,17 +57,21 @@
       : fPixId(-1),
 	fTotalEntries(0),
-	fHiGains(NULL),
-	fLoGains(NULL),
+        fHChargeHiGain(NULL),  
+        fHTimeHiGain(NULL), 
+        fHChargevsNHiGain(NULL),
+        fHChargeLoGain(NULL),  
+        fHTimeLoGain(NULL),    
+        fHChargevsNLoGain(NULL),
         fChargeGausFit(NULL), 
 	fTimeGausFit(NULL), 
 	fHivsLoGain(NULL),
 	fFitLegend(NULL),
-	fLowerFitRange(-2000.),
-	fChargeFirstHiGain(-2000.5),
-	fChargeLastHiGain(9999.5),
-	fChargeNbinsHiGain(12000),
-	fChargeFirstLoGain(-2000.5),
+	fLowerFitRange(-100.),
+	fChargeFirstHiGain(-100.5),
+	fChargeLastHiGain(1999.5),
+	fChargeNbinsHiGain(2100),
+	fChargeFirstLoGain(-100.5),
 	fChargeLastLoGain(9999.5),
-	fChargeNbinsLoGain(1200),
+	fChargeNbinsLoGain(1010),
         fChargeChisquare(-1.),
         fChargeProb(-1.),
@@ -81,6 +86,4 @@
         fTimeLowerFitRangeLoGain(0),
         fTimeUpperFitRangeLoGain(0),
-	fUseLoGain(kFALSE),
-        fFitOK(kFALSE),
 	fOffset(0.),
 	fSlope(0.)
@@ -111,5 +114,5 @@
     Int_t  ntbins = 16;
 
-    fHTimeHiGain = new TH1I("HTimeHiGain","Distribution of Mean Arrival Hi Gain Times Pixel ",
+    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]");
@@ -117,5 +120,5 @@
     fHTimeHiGain->SetDirectory(NULL);
 
-    fHTimeLoGain = new TH1I("HTimeLoGain","Distribution of Mean Arrival Lo Gain Times Pixel ",
+    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]");
@@ -170,22 +173,21 @@
     delete fHivsLoGain;
 
-
-}
-
-const Double_t MHCalibrationPixel::GetArea() const
-{
-    return fChargeGausFit->GetParameter(0);
-}
-
-const Double_t MHCalibrationPixel::GetAreaErr() const
-{
-    return fChargeGausFit->GetParError(0);
-}
-
-Bool_t MHCalibrationPixel::IsEmpty()
+}
+
+Bool_t MHCalibrationPixel::IsEmpty() const
 {
     return !(fHChargeHiGain->GetEntries() || fHChargeLoGain->GetEntries());
 }
-  
+
+Bool_t MHCalibrationPixel::IsUseLoGain() const
+{
+  return TESTBIT(fFlags,kUseLoGain);
+}
+
+Bool_t MHCalibrationPixel::IsFitOK() const 
+{
+    return TESTBIT(fFlags,kFitOK);
+}
+
 Bool_t MHCalibrationPixel::FillChargeLoGain(Float_t q)
 {
@@ -193,5 +195,5 @@
 }
 
-Bool_t MHCalibrationPixel::FillTimeLoGain(Int_t t)
+Bool_t MHCalibrationPixel::FillTimeLoGain(Float_t t)
 {
     return (fHTimeLoGain->Fill(t)   > -1);
@@ -205,10 +207,10 @@
 Bool_t MHCalibrationPixel::FillChargeHiGain(Float_t q)
 {
-    return (fHChargeHiGain->Fill(q)      > -1);
-}
-
-Bool_t MHCalibrationPixel::FillTimeHiGain(Int_t t)
-{
-    return (fHTimeHiGain->Fill(t)        > -1);
+    return (fHChargeHiGain->Fill(q) > -1);
+}
+
+Bool_t MHCalibrationPixel::FillTimeHiGain(Float_t t)
+{
+    return (fHTimeHiGain->Fill(t) > -1);
 }
 
@@ -285,4 +287,16 @@
 
 
+Bool_t MHCalibrationPixel::SetupFill(const MParList *plist)
+{
+ 
+  fHChargeHiGain->Reset();
+  fHTimeHiGain->Reset();
+  fHChargeLoGain->Reset();
+  fHTimeLoGain->Reset();
+
+  return kTRUE;
+}
+
+
 void MHCalibrationPixel::Reset()
 {
@@ -293,9 +307,10 @@
 
   for (Int_t i = 0; i < 16; i++)
-      fHTimeHiGain->SetBinContent(i, 1.e-20);
-  
-  fChargeLastHiGain     = 9999.5;
-
-  fHChargeHiGain->GetXaxis()->SetRangeUser(0.,fChargeLastHiGain);
+    fHTimeHiGain->SetBinContent(i, 1.e-20);
+
+  fChargeFirstHiGain    = -100.5;
+  fChargeLastHiGain     = 1999.5;
+
+  fHChargeHiGain->GetXaxis()->UnZoom();
 
  for (Int_t i = fHChargeLoGain->FindBin(fChargeFirstLoGain); 
@@ -306,7 +321,8 @@
       fHTimeLoGain->SetBinContent(i, 1.e-20);
   
+  fChargeFirstLoGain    = -100.5;
   fChargeLastLoGain     = 9999.5;
 
-  fHChargeLoGain->GetXaxis()->SetRangeUser(0.,fChargeLastLoGain);
+  fHChargeLoGain->GetXaxis()->UnZoom();
 
   return;
@@ -319,15 +335,15 @@
   if (fHChargeHiGain->Integral() > fHChargeLoGain->Integral())
     {
-      fUseLoGain = kFALSE;
+      CLRBIT(fFlags,kUseLoGain);
       return kFALSE;
     }
   else
     {
-      fUseLoGain = kTRUE;
+      SETBIT(fFlags,kUseLoGain);
       return kTRUE;
     }
 }
 
-void MHCalibrationPixel::SetPointInGraph(Float_t qhi,Float_t qlo)
+Bool_t MHCalibrationPixel::FillPointInGraph(Float_t qhi,Float_t qlo)
 {
 
@@ -337,4 +353,6 @@
   fHiGains->AddAt(qhi,fTotalEntries-1);
   fLoGains->AddAt(qlo,fTotalEntries-1);
+
+  return kTRUE;
 
 }
@@ -350,5 +368,5 @@
   fFitLegend = new TPaveText(0.05,0.05,0.95,0.95);
 
-  if (fFitOK) 
+  if (IsFitOK()) 
       fFitLegend->SetFillColor(80);
   else
@@ -360,34 +378,59 @@
   const TString line1 = 
     Form("Mean: Q_{#mu} = %2.2f #pm %2.2f",fChargeMean,fChargeMeanErr);
-
-  fFitLegend->AddText(line1);
-
+  TText *t1 = fFitLegend->AddText(line1);
+  t1->SetBit(kCanDelete);
 
   const TString line4 =
     Form("Sigma: #sigma_{Q} = %2.2f #pm %2.2f",fChargeSigma,fChargeSigmaErr);
-
-  fFitLegend->AddText(line4);
-
+  TText *t2 =  fFitLegend->AddText(line4);
+  t2->SetBit(kCanDelete);
 
   const TString line7 =
     Form("#chi^{2} / N_{dof}: %4.2f / %3i",fChargeChisquare,fChargeNdf);
-
-  fFitLegend->AddText(line7);
-
+  TText *t3 =  fFitLegend->AddText(line7);
+  t3->SetBit(kCanDelete);
 
   const TString line8 =
     Form("Probability: %4.3f ",fChargeProb);
-
-  fFitLegend->AddText(line8);
-
-  if (fFitOK)
-    fFitLegend->AddText("Result of the Fit: OK");
+  TText *t4 =  fFitLegend->AddText(line8);
+  t4->SetBit(kCanDelete);
+
+  if (IsFitOK())
+    {
+      TText *t5 = fFitLegend->AddText("Result of the Fit: OK");
+      t5->SetBit(kCanDelete);
+    }
   else
-    fFitLegend->AddText("Result of the Fit: NOT OK");
-
+    {
+      TText *t6 = fFitLegend->AddText("Result of the Fit: NOT OK");
+      t6->SetBit(kCanDelete);
+    }
+  
   fFitLegend->SetBit(kCanDelete);
   fFitLegend->Draw();
 
 }
+
+
+TObject *MHCalibrationPixel::DrawClone(Option_t *option) const
+{
+
+  gROOT->SetSelectedPad(NULL);
+  
+  MHCalibrationPixel *newobj = (MHCalibrationPixel*)Clone();
+
+  if (!newobj) 
+    return 0;
+  newobj->SetBit(kCanDelete);
+
+
+  if (strlen(option)) 
+    newobj->Draw(option);
+  else    
+    newobj->Draw(GetDrawOption());
+  
+  return newobj;
+}
+  
 
 
@@ -400,12 +443,12 @@
 
   if (!fHivsLoGain)
-    FitHiGainvsLoGain();
+   FitHiGainvsLoGain();
       
   gStyle->SetOptFit(0);
-  gStyle->SetOptStat(1111111);
+  gStyle->SetOptStat(111111);
+  
+  gROOT->SetSelectedPad(NULL);
   
   TCanvas *c = MakeDefCanvas(this,600,900); 
-  
-  gROOT->SetSelectedPad(NULL);
   
   c->Divide(2,4);
@@ -420,10 +463,10 @@
     gPad->SetLogy(0);
 
-  fHChargeHiGain->DrawCopy(opt);
+  fHChargeHiGain->Draw(opt);
   
   c->Modified();
   c->Update();
   
-  if (fUseLoGain)
+  if (IsUseLoGain())
     {
 
@@ -436,14 +479,14 @@
         gPad->SetLogy(0);
 
-      fHChargeLoGain->DrawCopy(opt);
+      fHChargeLoGain->Draw(opt);
       
       if (fChargeGausFit)
         {
-          if (fFitOK)
+          if (IsFitOK())
             fChargeGausFit->SetLineColor(kGreen);          
           else
             fChargeGausFit->SetLineColor(kRed);
           
-          fChargeGausFit->DrawCopy("same");
+          fChargeGausFit->Draw("same");
         }
       c->Modified();
@@ -453,6 +496,6 @@
       gROOT->SetSelectedPad(NULL);
       gStyle->SetOptFit();
-      fHivsLoGain->Draw("prof");
-
+      if (fHivsLoGain)
+        fHivsLoGain->Draw("prof");
       gPad->Modified();
       gPad->Update();
@@ -466,10 +509,10 @@
       if (fChargeGausFit)
         {
-          if (fFitOK)
+          if (IsFitOK())
             fChargeGausFit->SetLineColor(kGreen);          
           else
             fChargeGausFit->SetLineColor(kRed);
           
-          fChargeGausFit->DrawCopy("same");
+          fChargeGausFit->Draw("same");
         }
 
@@ -482,5 +525,5 @@
         gPad->SetLogy(0);
       
-      fHChargeLoGain->DrawCopy(opt);
+      fHChargeLoGain->Draw(opt);
       c->Modified();
       c->Update();
@@ -493,5 +536,6 @@
       gROOT->SetSelectedPad(NULL);
       gStyle->SetOptFit();
-      fHivsLoGain->Draw("prof");
+      if (fHivsLoGain)
+        fHivsLoGain->Draw("prof");
       gPad->Modified();
       gPad->Update();
@@ -506,9 +550,9 @@
   gPad->SetTicks();  
   gPad->SetLogy(0);
-  fHTimeHiGain->DrawCopy(opt);
+  fHTimeHiGain->Draw(opt);
   c->Modified();
   c->Update();
   
-  if (fUseLoGain)
+  if (IsUseLoGain())
       {
         
@@ -516,5 +560,5 @@
         gPad->SetTicks();
 	gPad->SetLogy(0);
-	fHTimeLoGain->DrawCopy(opt);
+	fHTimeLoGain->Draw(opt);
 	c->Modified();
 	c->Update();
@@ -527,5 +571,5 @@
 	      fTimeGausFit->SetLineColor(kGreen);
 	    
-	    fTimeGausFit->DrawCopy("same");
+	    fTimeGausFit->Draw("same");
 	    c->Modified();
 	    c->Update();
@@ -541,5 +585,5 @@
 	      fTimeGausFit->SetLineColor(kGreen);
 	    
-	    fTimeGausFit->DrawCopy("same");
+	    fTimeGausFit->Draw("same");
 	    c->Modified();
 	    c->Update();
@@ -549,5 +593,5 @@
         gPad->SetTicks();
 	gPad->SetLogy(0);
-	fHTimeLoGain->DrawCopy(opt);	
+	fHTimeLoGain->Draw(opt);	
 	c->Modified();
 	c->Update();
@@ -559,5 +603,5 @@
     c->cd(7);
     gPad->SetTicks();
-    fHChargevsNHiGain->DrawCopy(opt);
+    fHChargevsNHiGain->Draw(opt);
     c->Modified();
     c->Update();
@@ -565,9 +609,9 @@
     c->cd(8);
     gPad->SetTicks();
-    fHChargevsNLoGain->DrawCopy(opt);
+    fHChargevsNLoGain->Draw(opt);
     c->Modified();
     c->Update();
 
-
+    return;
 }
 
@@ -575,5 +619,10 @@
 {
 
+  *fLog << inf << "Fit Hi Gain vs Lo Gain " << endl;
+
   if (fHivsLoGain)
+    return;
+
+  if ((!fHiGains) || (!fLoGains) || (fHiGains->GetSize() == 0) || (fLoGains->GetSize() == 0))
     return;
 
@@ -587,10 +636,10 @@
   titleHiLoGain += fPixId;
   fHivsLoGain->SetName(titleHiLoGain.Data());
-
   
   for (Int_t i=0;i<fTotalEntries;i++)
     fHivsLoGain->Fill(fHiGains->At(i),fLoGains->At(i),1);
   
-  fHivsLoGain->Fit("pol1","rq","",fHivsLoGain->GetMean()-2.5*fHivsLoGain->GetRMS(),fHivsLoGain->GetMean()+2.*fHivsLoGain->GetRMS());
+  fHivsLoGain->Fit("pol1","rq","",fHivsLoGain->GetMean()-2.5*fHivsLoGain->GetRMS(),
+                                  fHivsLoGain->GetMean()+2.0*fHivsLoGain->GetRMS());
   
   fOffset = fHivsLoGain->GetFunction("pol1")->GetParameter(0);
@@ -772,11 +821,11 @@
   if (fChargeProb < gkProbLimit) 
     {
-      *fLog << warn << "WARNING: Fit Probability " << fChargeProb 
-            << " is smaller than the allowed value: " << gkProbLimit << endl;
-      fFitOK = kFALSE;
+      //      *fLog << warn << "WARNING: Fit Probability " << fChargeProb 
+      //            << " is smaller than the allowed value: " << gkProbLimit << endl;
+      CLRBIT(fFlags,kFitOK);
       return kFALSE;
     }
   
-  fFitOK = kTRUE;
+  SETBIT(fFlags,kFitOK);
   return kTRUE;
 }
@@ -852,12 +901,11 @@
   if (fChargeProb < gkProbLimit) 
     {
-      *fLog << warn << "WARNING: Fit Probability " << fChargeProb 
-            << " is smaller than the allowed value: " << gkProbLimit << endl;
-      fFitOK = kFALSE;
+      //      *fLog << warn << "WARNING: Fit Probability " << fChargeProb 
+      //            << " is smaller than the allowed value: " << gkProbLimit << endl;
+      CLRBIT(fFlags,kFitOK);
       return kFALSE;
     }
   
-  
-  fFitOK = kTRUE;
+  SETBIT(fFlags,kFitOK);
     
   return kTRUE;
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.h	(revision 2903)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationPixel.h	(revision 2904)
@@ -21,15 +21,15 @@
   Int_t fTotalEntries;           // Number of entries
 
-  TArrayF *fHiGains;
-  TArrayF *fLoGains;
+  TArrayF *fHiGains;             //->
+  TArrayF *fLoGains;             //->
 
 protected:
 
   TH1F* fHChargeHiGain;          // Summed FADC slices High Gain
-  TH1I* fHTimeHiGain;            // Mean arrival time in number of FADC sice
+  TH1F* fHTimeHiGain;            // Mean arrival time in number of FADC sice
   TH1I* fHChargevsNHiGain;       // Summed Charge vs. Event Nr. 
-  
+                          
   TH1F* fHChargeLoGain;          // Summed FADC slices Low Gain
-  TH1I* fHTimeLoGain;            // Mean arrival time in number of FADC sice
+  TH1F* fHTimeLoGain;            // Mean arrival time in number of FADC sice
   TH1I* fHChargevsNLoGain;       // Summed Charge vs. Event Nr. 
 
@@ -70,8 +70,9 @@
   Byte_t   fTimeLowerFitRangeLoGain;
   Byte_t   fTimeUpperFitRangeLoGain;
+
+  Byte_t   fFlags;
+
+  enum   { kUseLoGain, kFitOK };
   
-  Bool_t fUseLoGain;
-  Bool_t fFitOK;
-
   Double_t fOffset;
   Double_t fSlope;
@@ -87,6 +88,6 @@
   
   // Setters
-  void   SetPointInGraph(Float_t qhi, Float_t qlo);
-  void   SetUseLoGain(Bool_t b = kTRUE)                { fUseLoGain = b; }
+  void   SetUseLoGain(Bool_t b = kTRUE)
+    { b ? SETBIT(fFlags, kUseLoGain) : SETBIT(fFlags, kUseLoGain); }
 
   void SetTimeFitRangesHiGain(Byte_t low, Byte_t up) { fTimeLowerFitRangeHiGain = low,
@@ -105,7 +106,4 @@
   const Double_t GetChargeSigma()    const { return fChargeSigma;   }
   const Double_t GetChargeSigmaErr() const { return fChargeSigmaErr; }
-  const Double_t GetArea()           const;
-  const Double_t GetAreaErr()        const;
-
   const Double_t GetChargeChiSquare() const { return fChargeChisquare; }
   const Double_t GetChargeProb()      const { return fChargeProb;      }  
@@ -124,6 +122,6 @@
   const Int_t    GetTimeNdf()         const { return fTimeNdf;       }   
   
-  const TH1I *GetHTime()                    { return fHTimeHiGain; }
-  const TH1I *GetHTime()              const { return fHTimeHiGain; }
+  const TH1F *GetHTime()                    { return fHTimeHiGain; }
+  const TH1F *GetHTime()              const { return fHTimeHiGain; }
   
   const TH1I *GetHChargevsN()               { return fHChargevsNHiGain; }
@@ -135,16 +133,22 @@
   Bool_t UseLoGain();
 
-  Bool_t IsFitOK() { return fFitOK; }
-  Bool_t IsEmpty();
+  Bool_t IsFitOK()     const;    
+  Bool_t IsUseLoGain() const;
+  Bool_t IsEmpty()     const;
   
   // Fill histos
   Bool_t FillChargeLoGain(Float_t q);
-  Bool_t FillTimeLoGain(Int_t t);
+  Bool_t FillTimeLoGain(Float_t t);
   Bool_t FillChargevsNLoGain(Float_t q, Int_t n);
 
   Bool_t FillChargeHiGain(Float_t q);
-  Bool_t FillTimeHiGain(Int_t t);
+  Bool_t FillTimeHiGain(Float_t t);
   Bool_t FillChargevsNHiGain(Float_t q, Int_t n);
 
+  Bool_t FillPointInGraph(Float_t qhi, Float_t qlo);
+
+  Bool_t SetupFill(const MParList *pList);
+  Bool_t Fill(const MParContainer *, const Stat_t w=1) { return kTRUE; }
+  
   // Fits
   Bool_t FitChargeHiGain(Option_t *option="RQ0");  
@@ -158,5 +162,6 @@
   // Draws
   virtual void Draw(Option_t *option="");
-
+  TObject *DrawClone(Option_t *option="") const;
+  
   // Prints
   void PrintChargeFitResult();
