Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 3028)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 3029)
@@ -17,4 +17,9 @@
    * mcalib/MCalibrationCam.cc
      - include relative times to display with GetPixelContent
+
+   * mcalib/MCalibrationCalc.[h,cc]
+     - flag to skip Hi-Lo Calibration
+     - Hi-LO Graph not filled any more after overflow of ChargevsN
+     - fill the blind pixel differently from the rest of pixels
 
 
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationBlindPix.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationBlindPix.h	(revision 3028)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationBlindPix.h	(revision 3029)
@@ -54,10 +54,10 @@
   MHCalibrationBlindPixel *GetHist()            { return fHist;  }
   
-  Bool_t IsFitOK()                        const  { return fHist->IsFitOK(); }
+  Bool_t IsFitOK()  const;
   
   // Fill histos
-  Bool_t FillCharge(Float_t q)                  const { return fHist->FillBlindPixelCharge(q); }
-  Bool_t FillTime(Float_t t)                    const { return fHist->FillBlindPixelTime(t); }  
-  Bool_t FillRChargevsTime(Float_t rq, Int_t t) const { return fHist->FillBlindPixelChargevsN(rq,t); }    
+  Bool_t FillCharge(const Float_t q); 
+  Bool_t FillTime(const Float_t t); 
+  Bool_t FillRChargevsTime(const Float_t rq, const Int_t t);
   
   // Fits
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc	(revision 3028)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc	(revision 3029)
@@ -68,4 +68,8 @@
 //                fits)
 //
+//                Hi-Gain vs. Lo-Gain Calibration (very memory-intensive)
+//                can be skipped with the command:
+//                MalibrationCam::SkipHiLoGainCalibration()
+//
 //  Input Containers:
 //   MRawEvtData
@@ -116,4 +120,7 @@
 const Int_t MCalibrationCalc::fBlindPixelId = 559;
 const Int_t MCalibrationCalc::fPINDiodeId   = 9999;
+const Byte_t MCalibrationCalc::fgSaturationLimit = 254;
+const Byte_t MCalibrationCalc::fgBlindPixelFirst = 3;
+const Byte_t MCalibrationCalc::fgBlindPixelLast  = 12;
 
 // --------------------------------------------------------------------------
@@ -144,4 +151,5 @@
     SETBIT(fFlags, kUseCosmicsRejection);
     SETBIT(fFlags, kUseQualityChecks);
+    SETBIT(fFlags, kHiLoGainCalibration);
 
     CLRBIT(fFlags, kBlindPixelOverFlow);
@@ -496,5 +504,5 @@
                 }
             }
-        }
+        }  /* if Use Times */
       
       switch(pixid)
@@ -502,56 +510,72 @@
           
         case fBlindPixelId:
-          
-          if (!blindpixel.FillCharge(sumhi)) 
-            *fLog << warn << 
-              "Overflow or Underflow occurred filling Blind Pixel sum = " << sumhi << endl;
-          
-          if (TESTBIT(fFlags,kUseTimes))
+
+          if (TESTBIT(fFlags,kUseBlindPixelFit))
             {
-              if (!blindpixel.FillTime(reltime))
+          
+              Float_t blindpixelsum = 0.;
+              //
+              // We need a dedicated signal extractor for the blind pixel
+              //
+              MPedestalPix &ped  = (*fPedestals)[pixid];
+              if (!CalcSignalBlindPixel(pixel.GetHiGainSamples(), blindpixelsum, ped.GetPedestal()))
+                return kFALSE;
+              
+              if (!blindpixel.FillCharge(blindpixelsum)) 
                 *fLog << warn << 
-                  "Overflow or Underflow occurred filling Blind Pixel time = " << reltime << endl;
-            }
-          
-          if (!TESTBIT(fFlags,kBlindPixelOverFlow))
-            if (!blindpixel.FillRChargevsTime(sumhi,fEvents))
-              {
+                  "Overflow or Underflow occurred filling Blind Pixel sum = " << blindpixelsum << endl;
+              
+              if (TESTBIT(fFlags,kUseTimes))
+                {
+                  if (!blindpixel.FillTime(reltime))
+                    *fLog << warn << 
+                      "Overflow or Underflow occurred filling Blind Pixel time = " << reltime << endl;
+                }
+              
+              if (!TESTBIT(fFlags,kBlindPixelOverFlow))
+                if (!blindpixel.FillRChargevsTime(blindpixelsum,fEvents))
+                  {
+                    *fLog << warn << 
+                      "Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
+                    SETBIT(fFlags,kBlindPixelOverFlow);
+                  }
+            } /* if use blind pixel */
+          
+          break;
+              
+        case fPINDiodeId:
+
+          if (TESTBIT(fFlags,kUsePinDiodeFit))
+            {
+          
+              if (!pindiode.FillCharge(sumhi)) 
                 *fLog << warn << 
-                  "Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
-                SETBIT(fFlags,kBlindPixelOverFlow);
-              }
+                  "Overflow or Underflow occurred filling PINDiode: sum = " << sumhi << endl;
+              
+              if (TESTBIT(fFlags,kUseTimes))
+                {
+                  if (!pindiode.FillAbsTime(abstime))
+                    *fLog << warn << 
+                      "Overflow or Underflow occurred filling PINDiode abs. time = " << abstime << endl;
+                  if (!pindiode.FillRelTime(reltime))
+                    *fLog << warn << 
+                      "Overflow or Underflow occurred filling PINDiode rel. time = " << reltime << endl;
+                }
+              
+              if (!TESTBIT(fFlags,kPINDiodeOverFlow))
+                if (!pindiode.FillRChargevsTime(sumhi,fEvents))
+                  {
+                    *fLog << warn 
+                          << "Overflow or Underflow occurred filling PINDiode: eventnr = " 
+                          << fEvents << endl;
+                    SETBIT(fFlags,kPINDiodeOverFlow);
+                  }
+              
+            } /* if use PIN Diode */
           
           break;
-          
-        case fPINDiodeId:
-
-          if (!pindiode.FillCharge(sumhi)) 
-            *fLog << warn << 
-              "Overflow or Underflow occurred filling PINDiode: sum = " << sumhi << endl;
-
-          if (TESTBIT(fFlags,kUseTimes))
-            {
-              if (!pindiode.FillAbsTime(abstime))
-                *fLog << warn << 
-                  "Overflow or Underflow occurred filling PINDiode abs. time = " << abstime << endl;
-              if (!pindiode.FillRelTime(reltime))
-                *fLog << warn << 
-                  "Overflow or Underflow occurred filling PINDiode rel. time = " << reltime << endl;
-            }
-          
-          if (!TESTBIT(fFlags,kPINDiodeOverFlow))
-            if (!pindiode.FillRChargevsTime(sumhi,fEvents))
-              {
-                *fLog << warn 
-                      << "Overflow or Underflow occurred filling PINDiode: eventnr = " 
-                      << fEvents << endl;
-                SETBIT(fFlags,kPINDiodeOverFlow);
-              }
-          break;
-          
+              
         default:
-          
-          pix.FillChargesInGraph(sumhi,sumlo);
-
+              
           if (!TESTBIT(fFlags,kLoGainOverFlow))
             if (!pix.FillRChargevsTimeLoGain(sumlo,fEvents))
@@ -561,4 +585,5 @@
                       << fEvents << endl;
                 SETBIT(fFlags,kLoGainOverFlow);
+                SkipHiLoGainCalibration();
               }
           
@@ -570,7 +595,11 @@
                       << fEvents << endl;
                 SETBIT(fFlags,kHiGainOverFlow);
+                SkipHiLoGainCalibration();
               }
 
-          
+
+          if (TESTBIT(fFlags,kHiLoGainCalibration))
+            pix.FillChargesInGraph(sumhi,sumlo);
+
           if (sig.IsLoGainUsed())
             {
@@ -670,10 +699,9 @@
           // Set the corresponding values
           //
-          const Float_t nslices     = (Float_t)fSignals->GetNumUsedFADCSlices();
+          const Float_t nslices     = (Float_t)(fgBlindPixelLast-fgBlindPixelFirst+1);
+          const Float_t sqrslice    = TMath::Sqrt(nslices);
           const ULong_t nentries    = fPedestals->GetTotalEntries();
           
           const Float_t peddiff     = (pedhist.GetChargeMean()-pedpix.GetPedestal())*nslices;
-
-          const Float_t sqrslice    = TMath::Sqrt(nslices);
 
           Float_t pederr  = pedhist.GetChargeMeanErr()*pedhist.GetChargeMeanErr();
@@ -721,20 +749,19 @@
 
       //
-      // get the pedestals
-      //
-      const Float_t ped    = (*fPedestals)[pixid].GetPedestal() * fNumHiGainSamples;
-      const Float_t prms   = (*fPedestals)[pixid].GetPedestalRms() * fSqrtHiGainSamples;
-
-      //
-      // set them in the calibration camera
-      //
-      pix.SetPedestal(ped,prms);
-
-
-      //
       // Check if the pixel has been excluded from the fits
       //
       if (pix.IsExcluded())
         continue;
+
+      //
+      // get the pedestals
+      //
+      const Float_t ped    = (*fPedestals)[pixid].GetPedestal();
+      const Float_t prms   = (*fPedestals)[pixid].GetPedestalRms();
+
+      //
+      // set them in the calibration camera
+      //
+      pix.SetPedestal(ped,prms,(Float_t)fNumHiGainSamples,(Float_t)fNumLoGainSamples);
 
       //
@@ -793,2 +820,32 @@
 }
 
+Bool_t MCalibrationCalc::CalcSignalBlindPixel(Byte_t *ptr, Float_t &signal, const Float_t ped) const
+{
+
+  Byte_t *start = ptr + fgBlindPixelFirst;
+  Byte_t *end   = ptr + fgBlindPixelLast;
+
+  Byte_t sum = 0;
+  Int_t  sat = 0;
+  
+  ptr = start;
+
+  while (ptr<end)
+    {
+      sum += *ptr;
+      
+      if (*ptr++ >= fgSaturationLimit)
+            sat++;
+    }
+
+  if (sat)
+    {
+      *fLog << err << "HI Gain Saturation occurred in the blind pixel! " 
+            << " Do not know yet how to treat this ... aborting " << endl;
+      return kFALSE;
+    }
+
+  signal = (Float_t)sum - ped*(Float_t)(fgBlindPixelLast-fgBlindPixelFirst+1);
+
+  return kTRUE;
+}
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.h	(revision 3028)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.h	(revision 3029)
@@ -41,4 +41,7 @@
   static const Int_t fBlindPixelId;         // ID of the blind pixel
   static const Int_t fPINDiodeId;           // ID of the PIN Diode
+  static const Byte_t fgSaturationLimit;    // Saturation of Hi Gain
+  static const Byte_t fgBlindPixelFirst;    // First FADC slice blind pixel
+  static const Byte_t fgBlindPixelLast;     // Last FADC slice blind pixel
   
   MPedestalCam             *fPedestals;    // Pedestals of all pixels in the camera
@@ -68,4 +71,5 @@
   enum  { kUseTimes, kUseBlindPixelFit, kUsePinDiodeFit,
           kUseCosmicsRejection, kUseQualityChecks,
+          kHiLoGainCalibration,
           kBlindPixelOverFlow, kPINDiodeOverFlow,
           kHiGainOverFlow, kLoGainOverFlow  };
@@ -83,4 +87,6 @@
   Int_t Process();
   Int_t PostProcess();
+
+  Bool_t CalcSignalBlindPixel(Byte_t *ptr, Float_t &signal, const Float_t ped) const;  
   
 public:
@@ -101,4 +107,6 @@
   void SkipQualityChecks(Bool_t b=kTRUE)
       {b ? CLRBIT(fFlags, kUseQualityChecks) : SETBIT(fFlags, kUseQualityChecks);}
+  void SkipHiLoGainCalibration(Bool_t b=kTRUE)
+      {b ? CLRBIT(fFlags, kHiLoGainCalibration) : SETBIT(fFlags, kHiLoGainCalibration);}
 
 
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc	(revision 3028)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationCam.cc	(revision 3029)
@@ -267,13 +267,9 @@
 	{
 
-          Float_t rsigma = pix->GetRSigmaSquare();
-          if (rsigma > 0.)
-            rsigma = TMath::Sqrt(rsigma);
-
 	  *fLog << all << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " 
                 << pix->GetPedRms() << " Reduced Charge: " << pix->GetCharge() << " +- " 
-		<< pix->GetSigmaCharge() << " Reduced Sigma: " << rsigma 
+                << pix->GetSigmaCharge() << " Reduced Sigma: " << pix->GetRSigmaCharge() 
                 << " Nr Phe's: " << pix->GetPheFFactorMethod() << endl;
-	  id++;
+          id++;
 	}
     }
@@ -293,11 +289,7 @@
           {
 
-            Float_t rsigma = pix->GetRSigmaSquare();
-            if (rsigma > 0.)
-              rsigma = TMath::Sqrt(rsigma);
-            
             *fLog << all << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " 
                   << pix->GetPedRms() << " Reduced Charge: " << pix->GetCharge() << " +- " 
-                  << pix->GetSigmaCharge() << " Reduced Sigma: " << rsigma << endl;
+                  << pix->GetSigmaCharge() << " Reduced Sigma: " << pix->GetRSigmaCharge() << endl;
             id++;
           }
@@ -420,10 +412,10 @@
       if (!(*this)[idx].IsTimeFitValid())
         return kFALSE;
-      val = (*this)[idx].GetTime() * gkTimeSliceWidth;
+      val = (*this)[idx].GetMeanTimeOffset() * gkTimeSliceWidth;
       break;
     case 6:
       if (!(*this)[idx].IsTimeFitValid())
         return kFALSE;
-      val = (*this)[idx].GetSigmaTime() * gkTimeSliceWidth;
+      val = (*this)[idx].GetTimingPrecision() * gkTimeSliceWidth;
       break;
     case 7:
@@ -439,8 +431,5 @@
       break;
     case 10:
-      if ((*this)[idx].GetRSigmaSquare() > 0.)
-	val = TMath::Sqrt((*this)[idx].GetRSigmaSquare());
-      else
-	val = -1.;
+      val = (*this)[idx].GetRSigmaCharge();
       break;
     case 11:
@@ -469,8 +458,5 @@
       break;
     case 17:
-      if ( (*this)[idx].GetRSigmaSquare() > 0. && (*this)[idx].GetCharge() > 0. )
-	val = TMath::Sqrt((*this)[idx].GetRSigmaSquare()) / (*this)[idx].GetCharge();
-      else
-	val = -1.;
+      val = (*this)[idx].GetRSigmaCharge() / (*this)[idx].GetCharge();
       break;
     case 18:
