Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 3291)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 3292)
@@ -20,4 +20,21 @@
 
  2004/02/24: Markus Gaug
+
+   * mcalib/MHCalibrationChargeBlindPix.[h,cc]
+
+   - receives a pointer to MCalibrationChargePINDiode which is filled 
+     with the results and told to calculate the fluxes in the 
+     Finalize function
+   - is filled via MFillH from MExtractBlindPixel
+
+   * mcalib/MCalibrationChargeBlindPix.[h,cc]
+    - new storage container of the blind pxiel resutls, replaces 
+      MCalibrationBlindPix
+
+   * mcalib/MCalibrationChargeCalc.[h,cc]
+
+     - does not fill the histograms any more, but does ony the 
+       calculations in the postprocess. No pointer to MExtractPINDidoe
+       or MExtractBlindPixel any more.
 
    * mcalib/MCalibrationChargePix.cc
Index: /trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h	(revision 3291)
+++ /trunk/MagicSoft/Mars/mcalib/CalibLinkDef.h	(revision 3292)
@@ -9,10 +9,11 @@
 
 #pragma link C++ class MCalibrationChargePix+;
-#pragma link C++ class MCalibrationBlindPix+;
+#pragma link C++ class MCalibrationChargeBlindPix+;
 #pragma link C++ class MCalibrationChargeCam+;
 #pragma link C++ class MCalibrationChargeCalc+;
 #pragma link C++ class MCalibrationChargePINDiode+;
 
-#pragma link C++ class MHCalibrationBlindPixel+;
+#pragma link C++ class MHCalibrationChargeBlindPix+;
+#pragma link C++ class MHCalibrationChargeBlindPix+;
 #pragma link C++ class MHCalibrationChargePix+;
 #pragma link C++ class MHCalibrationChargeCam+;
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindPix.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindPix.h	(revision 3292)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindPix.h	(revision 3292)
@@ -0,0 +1,136 @@
+#ifndef MARS_MCalibrationChargeBlindPix
+#define MARS_MCalibrationChargeBlindPix
+
+#ifndef MARS_MCalibrationChargePix
+#include "MCalibrationChargePix.h"
+#endif
+
+class MCalibrationChargeBlindPix : public MCalibrationChargePix
+{
+private:
+
+  static const Float_t fgLambdaCheckLimit;  // The default limit (in units of PedRMS) for acceptance of the fitted mean charge
+  static const Float_t fgLambdaErrLimit;    // The default limit (in units of PedRMS) for acceptance of the fitted charge sigma
+
+  static const Float_t gkBlindPixelArea;       // The Blind Pixel area in mm^2
+
+  static const Float_t gkBlindPixelQEGreen;
+  static const Float_t gkBlindPixelQEBlue ;
+  static const Float_t gkBlindPixelQEUV   ;
+  static const Float_t gkBlindPixelQECT1  ;
+
+  static const Float_t gkBlindPixelQEGreenErr;
+  static const Float_t gkBlindPixelQEBlueErr ;
+  static const Float_t gkBlindPixelQEUVErr   ;
+  static const Float_t gkBlindPixelQECT1Err  ;
+ 
+  static const Float_t gkBlindPixelAttGreen;
+  static const Float_t gkBlindPixelAttBlue ;
+  static const Float_t gkBlindPixelAttUV   ;
+  static const Float_t gkBlindPixelAttCT1  ;
+
+  Float_t fLambdaCheckLimit; // The rel. limit for the rel difference between lambda and lambda check
+  Float_t fLambdaErrLimit;   // The limit for acceptance of the fitted lambda
+
+  Float_t fLambda;           // The mean of the Poisson fit
+  Float_t fLambdaCheck;      // The mean of the pedestal Check fit
+  Float_t fMu0;              // The position of the pedestal-peak
+  Float_t fMu1;              // The position of the first phe-peak
+  Float_t fSigma0;           // The width of the pedestal-peak
+  Float_t fSigma1;           // The width of the first phe-peak  
+
+  Float_t fLambdaErr;        // The error of the mean charge after the fit
+  Float_t fLambdaCheckErr;   // The error of the mean of the pedestal Check fit
+  Float_t fMu0Err;           // The error of the position of the pedestal-peak
+  Float_t fMu1Err;           // The error of the position of the first phe-peak
+  Float_t fSigma0Err;        // The error of the width of the pedestal-peak
+  Float_t fSigma1Err;        // The error of the width of the first phe-peak  
+
+  Float_t fProb;             // The probability of the fit
+  
+  Float_t fMeanFluxInsidePlexiglass;          //  The mean number of photons in an INNER PIXEL inside the plexiglass
+  Float_t fMeanFluxErrInsidePlexiglass;       //  The uncertainty about the number of photons in an INNER PIXEL  
+
+  Byte_t fFlags;
+
+  enum { kOscillating, kPedestalFitOK, kSinglePheFitOK, kChargeFitValid, kExcluded, 
+         kFluxInsidePlexiglassAvailable };
+
+public:
+
+  enum PulserColor_t { kEBlue, kEGreen, kEUV, kECT1 } ;
+
+private:
+
+  PulserColor_t fColor;  
+
+public:
+
+  MCalibrationChargeBlindPix(const char *name=NULL, const char *title=NULL);
+  ~MCalibrationChargeBlindPix() {}
+  
+  void Clear(Option_t *o="");
+
+  // Setters
+  void SetLambda      ( const Float_t f ) { fLambda      = f;  }
+  void SetLambdaCheck ( const Float_t f ) { fLambdaCheck = f;  }
+  void SetMu0         ( const Float_t f ) { fMu0         = f;  }
+  void SetMu1         ( const Float_t f ) { fMu1         = f;  }
+  void SetSigma0      ( const Float_t f ) { fSigma0      = f;  }
+  void SetSigma1      ( const Float_t f ) { fSigma1      = f;  }
+
+  void SetLambdaErr       ( const Float_t f ) { fLambdaErr    = f;  }
+  void SetLambdaCheckErr  ( const Float_t f ) { fLambdaCheck = f;   }
+  void SetMu0Err          ( const Float_t f ) { fMu0Err       = f;  }
+  void SetMu1Err          ( const Float_t f ) { fMu1Err       = f;  }
+  void SetSigma0Err       ( const Float_t f ) { fSigma0Err    = f;  }
+  void SetSigma1Err       ( const Float_t f ) { fSigma1Err    = f;  }
+
+  void SetProb            ( const Float_t f ) { fProb         = f;  }
+
+  void SetLambdaCheckLimit ( const Float_t f=fgLambdaCheckLimit  ) { fLambdaCheckLimit  = f; }
+  void SetLambdaErrLimit   ( const Float_t f=fgLambdaErrLimit    ) { fLambdaErrLimit    = f; }
+
+  void SetOscillating     ( const Bool_t b=kTRUE);
+  void SetChargeFitValid  ( const Bool_t b=kTRUE);
+  void SetPedestalFitOK   ( const Bool_t b=kTRUE);
+  void SetSinglePheFitOK ( const Bool_t b=kTRUE);
+  void SetFluxInsidePlexiglassAvailable  ( const Bool_t b=kTRUE);
+  void SetExcluded        ( const Bool_t b=kTRUE);
+  
+  // Getters
+  Float_t GetLambda()      const    { return fLambda;      }
+  Float_t GetLambdaCheck() const    { return fLambdaCheck; }
+  Float_t GetMu0()         const    { return fMu0;         }
+  Float_t GetMu1()         const    { return fMu1;         }
+  Float_t GetSigma0()      const    { return fSigma0;      }
+  Float_t GetSigma1()      const    { return fSigma1;      }
+
+  Float_t GetLambdaErr()      const    { return fLambdaErr;      }
+  Float_t GetLambdaCheckErr() const    { return fLambdaCheckErr; }
+  Float_t GetMu0Err()         const    { return fMu0Err;         }
+  Float_t GetMu1Err()         const    { return fMu1Err;         }
+  Float_t GetSigma0Err()      const    { return fSigma0Err;      } 
+  Float_t GetSigma1Err()      const    { return fSigma1Err;      }
+
+  Float_t GetMeanFluxInsidePlexiglass()     const { return fMeanFluxInsidePlexiglass;     }
+  Float_t GetMeanFluxErrInsidePlexiglass()  const { return fMeanFluxErrInsidePlexiglass;  }
+
+  Bool_t  IsOscillating()                    const;
+  Bool_t  IsChargeFitValid()                 const;
+  Bool_t  IsPedestalFitOK()                  const;
+  Bool_t  IsSinglePheFitOK()                 const;
+  Bool_t  IsExcluded()                       const;
+  Bool_t  IsFluxInsidePlexiglassAvailable()  const;
+  
+  Bool_t CalcFluxInsidePlexiglass();
+  Bool_t CheckChargeFitValidity();
+
+  ClassDef(MCalibrationChargeBlindPix, 1)	// Container for Calibration ChargeBlind Pixel
+};
+
+#endif
+
+
+
+
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 3291)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 3292)
@@ -96,20 +96,15 @@
 
 #include "MCalibrationChargeCam.h"
+#include "MCalibrationChargePix.h"
 #include "MCalibrationChargePINDiode.h"
-#include "MCalibrationChargePix.h"
+#include "MCalibrationChargeBlindPix.h"
 
 #include "MExtractedSignalCam.h"
 #include "MExtractedSignalPix.h"
-#include "MExtractedSignalBlindPixel.h"
-
-#include "MCalibrationBlindPix.h"
+
 
 ClassImp(MCalibrationChargeCalc);
 
 using namespace std;
-
-const UInt_t MCalibrationChargeCalc::fgBlindPixelIdx   = 559;
-const UInt_t MCalibrationChargeCalc::fgPINDiodeIdx     = 9999;
-const UInt_t MCalibrationChargeCalc::fgBlindPixelSinglePheCut = 400;
 
 // --------------------------------------------------------------------------
@@ -120,5 +115,5 @@
     : fPedestals(NULL), fCam(NULL), 
       fRawEvt(NULL), fRunHeader(NULL), fEvtTime(NULL),
-      fSignals(NULL), fBlindPixel(NULL), fPINDiode(NULL)
+      fSignals(NULL), fPINDiode(NULL), fBlindPixel(NULL)
 {
 
@@ -132,6 +127,4 @@
 
     Clear();
-    SetBlindPixelIdx();
-    SetPINDiodeIdx();
 }
 
@@ -139,10 +132,6 @@
 {
   
-    SETBIT(fFlags, kUseBlindPixelFit);
     SETBIT(fFlags, kUseQualityChecks);
     SETBIT(fFlags, kHiLoGainCalibration);
-
-    fNumBlindPixelSinglePhe = 0;
-    fNumBlindPixelPedestal  = 0;  
 
     fNumHiGainSamples  = 0;
@@ -163,5 +152,4 @@
 // they were not found:
 //
-//  - MHCalibrationBlindPixel
 //  - MCalibrationCam
 //
@@ -205,4 +193,13 @@
     fCam->SetPINDiode(fPINDiode);
 
+    fBlindPixel = (MCalibrationChargeBlindPix*)pList->FindCreateObj("MCalibrationChargeBlindPix");
+    if (!fBlindPixel)
+      {
+        *fLog << err << dbginf << "MCalibrationChargeBlindPix could not be created ... aborting." << endl;        
+        return kFALSE;
+      }
+
+    fCam->SetBlindPixel(fBlindPixel);
+
     fEvtTime      = (MTime*)pList->FindObject("MTime");
 
@@ -222,11 +219,4 @@
       }
 
-    fBlindPixel = (MExtractedSignalBlindPixel*)pList->FindObject("MExtractedSignalBlindPixel");
-    if (!fBlindPixel)
-      {
-        *fLog << err << dbginf << "Cannot find MExtractedSignalBlindPixel ... aborting" << endl;
-        return kFALSE;
-      }
-    
     return kTRUE;
 }
@@ -275,12 +265,4 @@
                                     fSignals->GetLastUsedSliceLoGain());
         
-
-        // Exclude the blind pixel and the PIN Diode from normal pixel calibration:
-        if (i == fBlindPixelIdx)
-          pix.SetExcluded();
-
-        if (i == fPINDiodeIdx)
-          pix.SetExcluded();
-
      }
     
@@ -354,57 +336,4 @@
 Int_t MCalibrationChargeCalc::Process()
 {
-
-  
-  MRawEvtPixelIter pixel(fRawEvt);
-  
-  //
-  // Create a loop to fill the calibration histograms
-  // Search for: a signal in MExtractedSignalCam 
-  // Search for: a signal in MExtractedSignalBlindPixel
-  // Fill histograms with:
-  //             charge
-  //             charge vs. event nr.
-  //
-  //
-  // Initialize pointers to blind pixel and individual pixels
-  //
-  // FIXME: filling the bind pixel histograms in this class is preliminary 
-  //        and will be replaced soon to fill them with MFillH
-  //
-  MCalibrationBlindPix       &blindpixel = *(fCam->GetBlindPixel());
-  MExtractedSignalBlindPixel &blindsig   = (*fBlindPixel);
-
-  const UInt_t signal = blindsig.GetExtractedSignal();
-  
-  if (!blindpixel.FillCharge(signal)) 
-    *fLog << warn << 
-      "Overflow or Underflow occurred filling Blind Pixel sum = " << signal << endl;
-
-  blindpixel.FillGraphs(signal,0);
-  
-  TH1I *hist;
-  
-  if (signal > fBlindPixelSinglePheCut)
-    {
-      hist = (blindpixel.GetHist())->GetHSinglePheFADCSlices();
-      fNumBlindPixelSinglePhe++;
-    }
-  else
-    {
-      hist = (blindpixel.GetHist())->GetHPedestalFADCSlices();
-      fNumBlindPixelPedestal++;
-    }
-
-  pixel.Jump(fBlindPixelIdx);
-  
-  const Byte_t *ptr = pixel.GetHiGainSamples();
-
-  for (Int_t i=1;i<16;i++)
-    hist->Fill(i,*ptr++);
-  
-  ptr = pixel.GetLoGainSamples();
-  for (Int_t i=16;i<31;i++)
-    hist->Fill(i,*ptr++);
-
   return kTRUE;
 }
@@ -412,80 +341,9 @@
 Int_t MCalibrationChargeCalc::PostProcess()
 {
-  *fLog << inf << GetDescriptor() << ": Cut Histogram Edges" << endl;
-
-  // 
-  // Fit the blind pixel
-  //
-  if (TESTBIT(fFlags,kUseBlindPixelFit))
-  {
-      //
-      // Get pointer to blind pixel
-      //
-      MCalibrationBlindPix &blindpixel = *(fCam->GetBlindPixel());
-      
-      *fLog << inf << GetDescriptor() << ": Fitting the Blind Pixel" << endl;
-
-      //
-      // retrieve the histogram containers
-      //
-      MHCalibrationBlindPixel *hist = blindpixel.GetHist();
-          
-      //
-      // retrieve mean and sigma of the blind pixel pedestal, 
-      // so that we can use it for the fit
-      //
-      // FIXME: This part has to be migrated into the future MHCalibrationChargeBlindPix class
-      // 
-      const UInt_t nentries    = fPedestals->GetTotalEntries();
-      const UInt_t nslices     = 12;
-      const Float_t sqrslice   = TMath::Sqrt((Float_t)nslices);
-
-      MPedestalPix &pedpix  = (*fPedestals)[fBlindPixelIdx];
-      if (&pedpix)
-        {
-          const Float_t pedestal    = pedpix.GetPedestal()*nslices;
-          const Float_t pederr      = pedpix.GetPedestalRms()*nslices/nentries;
-          const Float_t pedsigma    = pedpix.GetPedestalRms()*sqrslice;
-          const Float_t pedsigmaerr = pederr/2.;
-          
-          hist->SetMeanPedestal(pedestal);
-          hist->SetMeanPedestalErr(pederr);
-          hist->SetSigmaPedestal(pedsigma);
-          hist->SetSigmaPedestalErr(pedsigmaerr);
-        }
-      
-      if (!blindpixel.FitCharge())
-        {
-          *fLog << warn << "Could not fit the blind pixel! " << endl;
-          *fLog << warn << "Setting bit kBlindPixelMethodValid to FALSE in MCalibrationCam" << endl;
-          fCam->SetBlindPixelMethodValid(kFALSE);
-        }
-      else
-        fCam->SetBlindPixelMethodValid(kTRUE);
-      
-      if (blindpixel.CheckOscillations())
-        fCam->SetBlindPixelMethodValid(kFALSE);
-
-      TH1I *sphehist = hist->GetHSinglePheFADCSlices();
-      TH1I *pedhist  = hist->GetHPedestalFADCSlices();
-
-      if (fNumBlindPixelSinglePhe > 1)
-        sphehist->Scale(1./fNumBlindPixelSinglePhe);
-      if (fNumBlindPixelPedestal > 1)
-        pedhist->Scale(1./fNumBlindPixelPedestal);
-      
-      blindpixel.DrawClone();
-  }
-  else 
-      *fLog << inf << GetDescriptor() << ": Skipping Blind Pixel Fit " << endl;
-
-  *fLog << inf << "total: " << GetNumExecutions() << " sphe: " << fNumBlindPixelSinglePhe << " ped: " << fNumBlindPixelPedestal << endl;
-
-  
-  *fLog << inf << GetDescriptor() << ": Fitting the Normal Pixels" << endl;
 
   //
   // loop over the pedestal events and check if we have calibration
   //
+  Int_t nvalid = 0;
   for (Int_t pixid=0; pixid<fPedestals->GetSize(); pixid++)
     {
@@ -504,5 +362,5 @@
       const Float_t ped    = (*fPedestals)[pixid].GetPedestal();
       const Float_t prms   = (*fPedestals)[pixid].GetPedestalRms();
-      const Int_t   num    = fPedestals->GetTotalEntries();
+      const Float_t num    = TMath::Sqrt((Float_t)fPedestals->GetTotalEntries());
 
       //
@@ -511,7 +369,7 @@
       if (pix.IsHiGainSaturation())
       {
-	  pix.SetPedestal(ped  * (Float_t)fNumLoGainSamples,
+	  pix.SetPedestal(ped  * fNumLoGainSamples,
 			  prms * TMath::Sqrt((Float_t)fNumLoGainSamples),
-			  prms * (Float_t)fNumLoGainSamples / num);
+			  prms * fNumLoGainSamples / num);
 	  pix.SetNumLoGainSamples((Float_t)fNumLoGainSamples);
           pix.ApplyLoGainConversion();
@@ -519,7 +377,7 @@
       else
       {
-	  pix.SetPedestal(ped  * (Float_t)fNumHiGainSamples,
+	  pix.SetPedestal(ped  * fNumHiGainSamples,
 			  prms * TMath::Sqrt((Float_t)fNumHiGainSamples),
-			  prms * (Float_t)fNumHiGainSamples / num);
+			  prms * fNumHiGainSamples / num);
       }
 
@@ -527,4 +385,6 @@
 	  continue;
 
+      nvalid++;
+
       if (!pix.CalcReducedSigma())
 	  continue;
@@ -534,15 +394,32 @@
     }
 
-  if (TESTBIT(fFlags,kUseBlindPixelFit) && fCam->IsBlindPixelMethodValid())
+  //
+  // The Michele check ...
+  //
+  if (nvalid == 0)
   {
-      if (!fCam->CalcFluxInsidePlexiglass())
-      {
-          *fLog << warn << "Could not calculate the number of photons from the blind pixel " << endl;
-          *fLog << "You can try to calibrate using the MCalibrationChargeCalc::SkipBlindPixelFit()" << endl;
-        fCam->SetBlindPixelMethodValid(kFALSE);          
-      }
+      *fLog << err << GetDescriptor() << ": Dear Michele! All pixels have non-valid calibration. " 
+	    << "Did you forget to fill the histograms (filling MHCalibrationChargeCam from MExtractedSignalCam using MFillH) ? " << endl;
+      return kFALSE;
+  }
+
+  if (!fBlindPixel->CheckChargeFitValidity())
+  {
+      *fLog << warn << "Could not calculate the flux of photons from the PIN Diode, charge fit not valid " << endl;
+      fCam->SetBlindPixelMethodValid(kFALSE);
   }
   else
-    *fLog << inf << GetDescriptor() << ": Skipping Blind Pixel Calibration! " << endl;
+  { 
+      if (!fBlindPixel->CalcFluxInsidePlexiglass())
+      {
+	  *fLog << warn << "Could not calculate the flux of photons from the PIN Diode, will skip PIN Diode Calibration " << endl;
+	  fCam->SetBlindPixelMethodValid(kFALSE);
+      }
+      else
+      {
+	  fCam->SetBlindPixelMethodValid(kTRUE);
+	  fCam->ApplyBlindPixelCalibration();
+      }
+  }
 
   if (!fPINDiode->CheckChargeFitValidity() || !fPINDiode->CheckTimeFitValidity())
@@ -561,4 +438,5 @@
       {
 	  fCam->SetPINDiodeMethodValid(kTRUE);
+	  fCam->ApplyPINDiodeCalibration();
       }
   }
@@ -571,2 +449,5 @@
 
 
+
+
+
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 3291)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 3292)
@@ -21,8 +21,8 @@
 class MPedestalCam;
 class MCalibrationChargePINDiode;
+class MCalibrationChargeBlindPix;
 class MCalibrationChargeCam;
 class MGeomCam;
 class MExtractedSignalCam;
-class MExtractedSignalBlindPixel;
 class MTime;
 class MCalibrationChargeCalc : public MTask
@@ -31,8 +31,4 @@
 private:
 
-  static const UInt_t fgBlindPixelIdx;                    // ID of the blind pixel
-  static const UInt_t fgPINDiodeIdx;                      // ID of the PIN Diode
-  static const UInt_t fgBlindPixelSinglePheCut;           // FADC sum from which on an event is considered as a S.ph. one.
-  
   MPedestalCam               *fPedestals;                 //! Pedestals of all pixels in the camera
   MCalibrationChargeCam      *fCam;                       // Calibration events of all pixels in the camera
@@ -43,19 +39,11 @@
 
   MExtractedSignalCam        *fSignals;                   // Extracted signal of all pixels in the camera
-  MExtractedSignalBlindPixel *fBlindPixel;                // Extracted signal of the blind pixel  
-  MCalibrationChargePINDiode *fPINDiode;                  // Calibration events of all pixels in the camera
+  MCalibrationChargePINDiode *fPINDiode;                  // Calibration results of the PIN Diode
+  MCalibrationChargeBlindPix *fBlindPixel;                // Calibration results of the Blind Pixel 
 
-
-  UInt_t  fBlindPixelIdx;  
-  UInt_t  fPINDiodeIdx;      
   
   Byte_t  fNumHiGainSamples; 
   Byte_t  fNumLoGainSamples; 
   Float_t fSqrtHiGainSamples; 
-  
-  UInt_t  fBlindPixelSinglePheCut;
-
-  Int_t   fNumBlindPixelSinglePhe;
-  Int_t   fNumBlindPixelPedestal;  
   
   Float_t fConversionHiLo;
@@ -65,6 +53,5 @@
   UInt_t  fNumExcludedPixels;
 
-  enum  { kUseBlindPixelFit, 
-          kUseQualityChecks,
+  enum  { kUseQualityChecks,
           kHiLoGainCalibration };
   
@@ -80,6 +67,4 @@
   void Clear(const Option_t *o="");
   
-  void SkipBlindPixelFit(Bool_t b=kTRUE)
-      {b ? CLRBIT(fFlags, kUseBlindPixelFit)    : SETBIT(fFlags, kUseBlindPixelFit);}
   void SkipQualityChecks(Bool_t b=kTRUE)
       {b ? CLRBIT(fFlags, kUseQualityChecks)    : SETBIT(fFlags, kUseQualityChecks);}
@@ -87,11 +72,4 @@
       {b ? CLRBIT(fFlags, kHiLoGainCalibration) : SETBIT(fFlags, kHiLoGainCalibration);}
 
-
-  // Setters 
-  void SetBlindPixelSinglePheCut ( const Int_t         cut=fgBlindPixelSinglePheCut)    
-                                                                    { fBlindPixelSinglePheCut = cut; }
-
-  void SetPINDiodeIdx(   const UInt_t idx=fgPINDiodeIdx   ) {   fPINDiodeIdx   = idx; }
-  void SetBlindPixelIdx( const UInt_t idx=fgBlindPixelIdx ) {   fBlindPixelIdx = idx; }
 
   // Exclude pixels from configuration file
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 3291)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 3292)
@@ -37,4 +37,8 @@
 //
 // The calculated values (types of GetPixelContent) are:
+// 
+// --------------------------------------------------------------------------
+//
+// The types are as follows:
 // 
 // Fitted values:
@@ -82,34 +86,35 @@
 // 27: Excluded Pixels
 // 28: Pixels where the fit did not succeed --> results obtained only from the histograms
-// 29: Pixels with succeeded fit, but apparently wrong results
-// 30: Pixels with un-expected behavior in the fourier spectrum (e.g. oscillations)
+// 29: Pixels with apparently wrong results
+// 30: Pixels with un-expected behavior in the Hi Gain fourier spectrum (e.g. oscillations)
+// 31: Pixels with un-expected behavior in the Lo Gain fourier spectrum (e.g. oscillations)a
+// 32: Number of probable pickup events in the Hi Gain 
+// 33: Number of probable pickup events in the Lo Gain
 //
 // Other classifications of pixels:
 // ================================
 //
-// 31: Pixels with saturated Hi-Gain
+// 34: Pixels with saturated Hi-Gain
 //
 // Classification of validity of the calibrations:
 // ===============================================
 //
-// 32: Pixels with valid calibration by the F-Factor-Method
-// 33: Pixels with valid calibration by the Blind Pixel-Method
-// 34: Pixels with valid calibration by the PIN Diode-Method
+// 35: Pixels with valid calibration by the F-Factor-Method
+// 36: Pixels with valid calibration by the Blind Pixel-Method
+// 37: Pixels with valid calibration by the PIN Diode-Method
 //
 // Used Pedestals:
 // ===============
 //
-// 35: Mean Pedestal over the entire range of signal extraction
-// 36: Error on the Mean Pedestal over the entire range of signal extraction
-// 37: Pedestal RMS over the entire range of signal extraction
-// 38: Error on the Pedestal RMS over the entire range of signal extraction
+// 38: Mean Pedestal over the entire range of signal extraction
+// 39: Error on the Mean Pedestal over the entire range of signal extraction
+// 40: Pedestal RMS over the entire range of signal extraction
+// 41: Error on the Pedestal RMS over the entire range of signal extraction
 //
 // Calculated absolute arrival times (very low precision!):
 // ========================================================
 //
-// 39: Absolute Arrival time of the signal
-// 40: Error on the Absolute Arrival time of the signal
-// 41: RMS of the Absolute Arrival time of the signal
-// 42: Error on the RMS of the Absolute Arrival time of the signal
+// 42: Absolute Arrival time of the signal
+// 43: RMS of the Absolute Arrival time of the signal
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -127,5 +132,5 @@
 
 #include "MCalibrationChargePix.h"
-#include "MCalibrationBlindPix.h"
+#include "MCalibrationChargeBlindPix.h"
 #include "MCalibrationChargePINDiode.h"
 
@@ -137,20 +142,4 @@
 const Int_t   MCalibrationChargeCam::gkBlindPixelId   =  559;
 const Int_t   MCalibrationChargeCam::gkPINDiodeId     = 9999;
-const Float_t MCalibrationChargeCam::gkBlindPixelArea = 100;
-// Average QE of Blind Pixel (three colours)
-const Float_t MCalibrationChargeCam::gkCalibrationBlindPixelQEGreen = 0.154;
-const Float_t MCalibrationChargeCam::gkCalibrationBlindPixelQEBlue  = 0.226;
-const Float_t MCalibrationChargeCam::gkCalibrationBlindPixelQEUV    = 0.247;
-const Float_t MCalibrationChargeCam::gkCalibrationBlindPixelQECT1   = 0.247;
-// Average QE Error of Blind Pixel (three colours)
-const Float_t MCalibrationChargeCam::gkCalibrationBlindPixelQEGreenErr = 0.015;
-const Float_t MCalibrationChargeCam::gkCalibrationBlindPixelQEBlueErr  = 0.02;
-const Float_t MCalibrationChargeCam::gkCalibrationBlindPixelQEUVErr    = 0.02;
-const Float_t MCalibrationChargeCam::gkCalibrationBlindPixelQECT1Err   = 0.02;
-// Attenuation factor Blind Pixel (three colours)
-const Float_t MCalibrationChargeCam::gkCalibrationBlindPixelAttGreen = 1.97;
-const Float_t MCalibrationChargeCam::gkCalibrationBlindPixelAttBlue  = 1.96;
-const Float_t MCalibrationChargeCam::gkCalibrationBlindPixelAttUV    = 1.95;
-const Float_t MCalibrationChargeCam::gkCalibrationBlindPixelAttCT1   = 1.95;
 
 // --------------------------------------------------------------------------
@@ -174,5 +163,4 @@
 
     fPixels     = new TClonesArray("MCalibrationChargePix",1);
-    fBlindPixel = new MCalibrationBlindPix();
 
     Clear();
@@ -193,5 +181,4 @@
   // 
   delete fPixels;
-  delete fBlindPixel;
 
   if (fOffsets)
@@ -272,8 +259,4 @@
 
   fPixels->ForEach(TObject, Clear)();
-  fBlindPixel->Clear();
-
-  fMeanFluxInsidePlexiglass          = -1.;
-  fMeanFluxErrInsidePlexiglass       = -1.;
 
   fNumExcludedPixels                 = 0;
@@ -281,5 +264,4 @@
   CLRBIT(fFlags,kBlindPixelMethodValid);
   CLRBIT(fFlags,kPINDiodeMethodValid);
-  CLRBIT(fFlags,kFluxInsidePlexiglassAvailable);
 
   return;
@@ -304,10 +286,4 @@
 {
   return TESTBIT(fFlags,kPINDiodeMethodValid);  
-}
-
-
-Bool_t  MCalibrationChargeCam::IsFluxInsidePlexiglassAvailable()   const
-{
-  return TESTBIT(fFlags,kFluxInsidePlexiglassAvailable);
 }
 
@@ -335,8 +311,10 @@
 	{
 
-	  *fLog << all << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " 
-                << pix->GetPedRms() << " Reduced Charge: " << pix->GetMeanCharge() << " +- " 
-                << pix->GetSigmaCharge() << " Reduced Sigma: " << pix->GetRSigmaCharge() 
-                << " Nr Phe's: " << pix->GetPheFFactorMethod() << endl;
+	    *fLog << all << "Pix " << pix->GetPixId() 
+		<< ":  Ped.  Rms: "            << pix->GetPedRms()        << " +- " << pix->GetPedRmsErr() 
+		<< "   Mean signal: "          << pix->GetMeanCharge()    << " +- " << pix->GetSigmaCharge() 
+		<< "   Reduced Sigma: "        << pix->GetRSigmaCharge() 
+		<< "   Nr Phe's: "             << pix->GetPheFFactorMethod() 
+		<< endl;
           id++;
 	}
@@ -357,7 +335,11 @@
           {
 
-            *fLog << all << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " 
-                  << pix->GetPedRms() << " Reduced Charge: " <<  pix->GetMeanCharge() << " +- " 
-                  << pix->GetSigmaCharge() << " Reduced Sigma: " << pix->GetRSigmaCharge() << endl;
+
+	    *fLog << all << "Pix " << pix->GetPixId() 
+		<< ":  Ped.  Rms: "            << pix->GetPedRms()        << " +- " << pix->GetPedRmsErr() 
+		<< "   Mean signal: "          << pix->GetMeanCharge()    << " +- " << pix->GetSigmaCharge() 
+		<< "   Reduced Sigma: "        << pix->GetRSigmaCharge() 
+		<< "   Nr Phe's: "             << pix->GetPheFFactorMethod() 
+		<< endl;
             id++;
           }
@@ -377,9 +359,12 @@
       if ( pix->IsOscillating()  && !pix->IsExcluded())
         {
-          
-          *fLog << all << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " 
-                << pix->GetPedRms() << " Reduced Charge: " << pix->GetMeanCharge() << " +- " 
-                << pix->GetSigmaCharge() << " Reduced Sigma: " << pix->GetRSigmaCharge() << endl;
-          id++;
+
+	    *fLog << all << "Pix " << pix->GetPixId() 
+		<< ":  Ped.  Rms: "            << pix->GetPedRms()        << " +- " << pix->GetPedRmsErr() 
+		<< "   Mean signal: "          << pix->GetMeanCharge()    << " +- " << pix->GetSigmaCharge() 
+		<< "   Reduced Sigma: "        << pix->GetRSigmaCharge() 
+		<< "   Nr Phe's: "             << pix->GetPheFFactorMethod() 
+		<< endl;
+	    id++;
         }
     }
@@ -406,18 +391,4 @@
 
 
-// --------------------------------------------------------------------------
-//
-// Sets the user ranges of all histograms such that 
-// empty bins at the edges are not used. Additionally, it rebins the 
-// histograms such that in total, 50 bins are used.
-//
-void MCalibrationChargeCam::CutEdges()
-{
-
-  fBlindPixel->GetHist()->CutAllEdges();
-
-  return;
-}
-  
 // --------------------------------------------------------------------------
 //
@@ -468,5 +439,5 @@
 // 27: Excluded Pixels
 // 28: Pixels where the fit did not succeed --> results obtained only from the histograms
-// 29: Pixels with succeeded fit, but apparently wrong results
+// 29: Pixels with apparently wrong results
 // 30: Pixels with un-expected behavior in the Hi Gain fourier spectrum (e.g. oscillations)
 // 31: Pixels with un-expected behavior in the Lo Gain fourier spectrum (e.g. oscillations)a
@@ -600,10 +571,10 @@
       if ((*this)[idx].IsExcluded())
         return kFALSE;
-      val = GetMeanFluxInsidePlexiglass()*area;
+      val = fBlindPixel->GetMeanFluxInsidePlexiglass()*area;
       break;
     case 16:
       if ((*this)[idx].IsExcluded())
         return kFALSE;
-      val = GetMeanFluxInsidePlexiglass()*area;
+      val = fBlindPixel->GetMeanFluxErrInsidePlexiglass()*area;
       break;
     case 17:
@@ -635,5 +606,5 @@
       if ((*this)[idx].IsExcluded())
         return kFALSE;
-      val = fPINDiode->GetMeanFluxOutsidePlexiglass()*area;
+      val = fPINDiode->GetMeanFluxErrOutsidePlexiglass()*area;
       break;
     case 23:
@@ -673,6 +644,4 @@
     case 29:
       if ((*this)[idx].IsExcluded())
-        return kFALSE;
-      if (!(*this)[idx].IsFitted())
         return kFALSE;
       if (!(*this)[idx].IsChargeValid())
@@ -784,92 +753,9 @@
 }
 
-
-// --------------------------------------------------------------------------
-//
-//
-//
-Bool_t MCalibrationChargeCam::CalcFluxInsidePlexiglass()
-{
-
-  if (!fBlindPixel->IsFitOK())
-    return kFALSE;
-  
-  const Float_t mean = fBlindPixel->GetLambda();
-  const Float_t merr = fBlindPixel->GetErrLambda();
-
-  //
-  // Start calculation of number of photons 
-  //
-  // The blind pixel has exactly 100 mm^2 area (with negligible error), 
-  //
-  fMeanFluxInsidePlexiglass    = mean*gkBlindPixelArea;
-
-  // Start calculation of number of photons relative Variance (!!)
-  fMeanFluxErrInsidePlexiglass  = merr*merr/mean/mean;
-  
-  switch (fColor)
-    {
-    case kEGreen:
-      fMeanFluxInsidePlexiglass    /= gkCalibrationBlindPixelQEGreen;   
-      fMeanFluxErrInsidePlexiglass += gkCalibrationBlindPixelQEGreenErr*gkCalibrationBlindPixelQEGreenErr
-                                    / gkCalibrationBlindPixelQEGreen  /   gkCalibrationBlindPixelQEGreen;   
-
-      fMeanFluxInsidePlexiglass  *= TMath::Power(10,gkCalibrationBlindPixelAttGreen); // correct for absorption 
-      // attenuation has negligible error
-      break;
-    case kEBlue:
-      fMeanFluxInsidePlexiglass    /= gkCalibrationBlindPixelQEBlue;   
-      fMeanFluxErrInsidePlexiglass += gkCalibrationBlindPixelQEBlueErr*gkCalibrationBlindPixelQEBlueErr
-                                    / gkCalibrationBlindPixelQEBlue  /   gkCalibrationBlindPixelQEBlue;   
-
-      fMeanFluxInsidePlexiglass *= TMath::Power(10,gkCalibrationBlindPixelAttBlue); // correct for absorption 
-      // attenuation has negligible error
-      break;
-    case kEUV:
-      fMeanFluxInsidePlexiglass    /= gkCalibrationBlindPixelQEUV;   
-      fMeanFluxErrInsidePlexiglass += gkCalibrationBlindPixelQEUVErr*gkCalibrationBlindPixelQEUVErr
-                                    / gkCalibrationBlindPixelQEUV  /   gkCalibrationBlindPixelQEUV;   
-
-      fMeanFluxInsidePlexiglass *= TMath::Power(10,gkCalibrationBlindPixelAttUV); // correct for absorption 
-      // attenuation has negligible error
-      break;
-    case kECT1:
-    default:
-      fMeanFluxInsidePlexiglass    /= gkCalibrationBlindPixelQECT1;   
-      fMeanFluxErrInsidePlexiglass += gkCalibrationBlindPixelQECT1Err*gkCalibrationBlindPixelQECT1Err
-                                    / gkCalibrationBlindPixelQECT1  /   gkCalibrationBlindPixelQECT1;   
-
-      fMeanFluxInsidePlexiglass *= TMath::Power(10,gkCalibrationBlindPixelAttCT1); // correct for absorption 
-      // attenuation has negligible error
-      break;
-    }
-
-  *fLog << inf << endl;
-  *fLog << inf << " Photon flux [ph/mm^2] inside Plexiglass: " 
-        << fMeanFluxInsidePlexiglass << endl;
-
-  if (fMeanFluxInsidePlexiglass > 0.)
-    SETBIT(fFlags,kFluxInsidePlexiglassAvailable);  
-  else
-    {
-      CLRBIT(fFlags,kFluxInsidePlexiglassAvailable);        
-      return kFALSE;
-    }
-
-  if (fMeanFluxErrInsidePlexiglass < 0.)
-    {
-      *fLog << warn << " Relative Variance on Photon flux inside Plexiglass: " 
-            << fMeanFluxErrInsidePlexiglass << endl;
-      CLRBIT(fFlags,kFluxInsidePlexiglassAvailable);        
-      return kFALSE;
-    }
-
-  // Finish calculation of errors -> convert from relative variance to absolute error
-  fMeanFluxErrInsidePlexiglass = TMath::Sqrt(fMeanFluxErrInsidePlexiglass);
-  fMeanFluxErrInsidePlexiglass *= fMeanFluxInsidePlexiglass;
-
-  *fLog << inf << " Error on photon flux [ph/mm^2] inside Plexiglass: " 
-        << fMeanFluxErrInsidePlexiglass << endl;
-  *fLog << inf << endl;
+void MCalibrationChargeCam::ApplyBlindPixelCalibration()
+{
+
+  Float_t flux    = fBlindPixel->GetMeanFluxInsidePlexiglass();
+  Float_t fluxerr = fBlindPixel->GetMeanFluxErrInsidePlexiglass();
 
   TIter Next(fPixels);
@@ -887,6 +773,6 @@
           const Float_t chargeerr = pix->GetMeanChargeErr();          
 
-          const Float_t nphot      = fMeanFluxInsidePlexiglass*area;
-          const Float_t nphoterr   = fMeanFluxErrInsidePlexiglass*area;
+          const Float_t nphot      = flux    * area;
+          const Float_t nphoterr   = fluxerr * area;
           const Float_t conversion = nphot/charge;
           Float_t conversionerr;
@@ -907,5 +793,4 @@
         }
     }
-  return kTRUE;
 }
 
@@ -960,9 +845,4 @@
 Bool_t MCalibrationChargeCam::GetConversionFactorBlindPixel(Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma)
 {
-  
-
-  if (!IsFluxInsidePlexiglassAvailable())
-    if (!CalcFluxInsidePlexiglass())
-      return kFALSE;
 
   mean  = (*this)[ipx].GetMeanConversionBlindPixelMethod();
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h	(revision 3291)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h	(revision 3292)
@@ -13,5 +13,5 @@
 class TClonesArray;
 
-class MCalibrationBlindPix;
+class MCalibrationChargeBlindPix;
 class MCalibrationChargePINDiode;
 class MCalibrationChargePix;
@@ -22,25 +22,9 @@
   static const Int_t   gkBlindPixelId;
   static const Int_t   gkPINDiodeId;
-  static const Float_t gkBlindPixelArea;       // The Blind Pixel area in mm^2
-
-  static const Float_t gkCalibrationBlindPixelQEGreen;
-  static const Float_t gkCalibrationBlindPixelQEBlue ;
-  static const Float_t gkCalibrationBlindPixelQEUV   ;
-  static const Float_t gkCalibrationBlindPixelQECT1  ;
-
-  static const Float_t gkCalibrationBlindPixelQEGreenErr;
-  static const Float_t gkCalibrationBlindPixelQEBlueErr ;
-  static const Float_t gkCalibrationBlindPixelQEUVErr   ;
-  static const Float_t gkCalibrationBlindPixelQECT1Err  ;
- 
-  static const Float_t gkCalibrationBlindPixelAttGreen;
-  static const Float_t gkCalibrationBlindPixelAttBlue ;
-  static const Float_t gkCalibrationBlindPixelAttUV   ;
-  static const Float_t gkCalibrationBlindPixelAttCT1  ;
 
   Int_t fNumPixels;
   TClonesArray *fPixels;                                        //-> Array of MCalibrationPix with fit results
   
-  MCalibrationBlindPix       *fBlindPixel;                      //-> Pointer to the Blind Pixel with fit results
+  const MCalibrationChargeBlindPix *fBlindPixel;                //! Pointer to the Blind Pixel with fit results
   const MCalibrationChargePINDiode *fPINDiode;                  //! Pointer to the PIN Diode with fit results
 
@@ -52,13 +36,9 @@
   TH2D* fOffvsSlope;                                            //! 
 
-  Float_t fMeanFluxInsidePlexiglass;          //  The mean number of photons in an INNER PIXEL inside the plexiglass
-  Float_t fMeanFluxErrInsidePlexiglass;       //  The uncertainty about the number of photons in an INNER PIXEL  
-
   UInt_t  fNumExcludedPixels;
 
   Byte_t  fFlags;
 
-  enum  { kBlindPixelMethodValid, kPINDiodeMethodValid, kCombinedMethodValid, 
-          kFluxInsidePlexiglassAvailable };
+  enum  { kBlindPixelMethodValid, kPINDiodeMethodValid, kCombinedMethodValid };
   
 public:
@@ -82,5 +62,7 @@
   void SetNumPixelsExcluded(  const UInt_t n )            {  fNumExcludedPixels = n; }
   void SetGeomCam(  const MGeomCam *geom)                 {  fGeomCam = geom;        }
-  void SetPINDiode( const MCalibrationChargePINDiode *d ) {  fPINDiode = d;          }
+
+  void SetPINDiode  ( const MCalibrationChargePINDiode *d ) {  fPINDiode   = d;      }
+  void SetBlindPixel( const MCalibrationChargeBlindPix *b ) {  fBlindPixel = b;      }
 
   // Setters only for MC!!
@@ -89,12 +71,6 @@
 
   // Getters
-  Int_t GetSize()                                  const;
-  UInt_t GetNumPixels()                            const { return fNumPixels; }
-
-  MCalibrationBlindPix *GetBlindPixel()                  { return fBlindPixel;  }
-  const MCalibrationBlindPix *GetBlindPixel()      const { return fBlindPixel;  }
-
-  Float_t GetMeanFluxInsidePlexiglass()     const { return fMeanFluxInsidePlexiglass;     }
-  Float_t GetMeanFluxErrInsidePlexiglass()  const { return fMeanFluxErrInsidePlexiglass;  }
+  Int_t  GetSize()               const;
+  UInt_t GetNumPixels()          const { return fNumPixels; }
 
   Bool_t GetConversionFactorFFactor(    Int_t ipx, Float_t &mean, Float_t &err, Float_t &sigma );
@@ -106,11 +82,8 @@
   Bool_t IsPINDiodeMethodValid()     const;  
 
-  Bool_t IsFluxInsidePlexiglassAvailable()  const;
-
   // Others
   MCalibrationChargePix &operator[](UInt_t i);
   const MCalibrationChargePix &operator[](UInt_t i) const;
   
-  void CutEdges();
   Bool_t CheckBounds(Int_t i) const;
 
@@ -125,6 +98,6 @@
   Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
 
-  Bool_t CalcFluxInsidePlexiglass();
   void   ApplyPINDiodeCalibration();
+  void   ApplyBlindPixelCalibration();
 
   ClassDef(MCalibrationChargeCam, 1)	// Container for calibration information of the camera
@@ -135,2 +108,4 @@
 
 
+
+
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.cc	(revision 3291)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.cc	(revision 3292)
@@ -317,5 +317,5 @@
   
   if (FitSinglePhe())
-      fBlindPix->SetFitted(kTRUE);
+      fBlindPix->SetSinglePheFitOK();
 
   fBlindPix->SetLambda      (    fLambda      );
Index: /trunk/MagicSoft/Mars/mcalib/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/Makefile	(revision 3291)
+++ /trunk/MagicSoft/Mars/mcalib/Makefile	(revision 3292)
@@ -41,8 +41,9 @@
 	   MCalibrationChargeCalc.cc \
            MCalibrationChargePix.cc  \
-           MCalibrationBlindPix.cc  \
+           MCalibrationChargeBlindPix.cc  \
            MCalibrationChargePINDiode.cc  \
            MCalibrationChargeCam.cc \
-           MHCalibrationBlindPixel.cc \
+           MHCalibrationChargeBlindPix.cc \
+           MHCalibrationChargeBlindPix.cc \
            MHCalibrationChargePix.cc \
            MHCalibrationChargeCam.cc \
