Index: /trunk/MagicSoft/Mars/macros/calibration.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/calibration.C	(revision 3292)
+++ /trunk/MagicSoft/Mars/macros/calibration.C	(revision 3293)
@@ -23,6 +23,8 @@
 \* ======================================================================== */
 
-//const TString pedfile = "../20040215_16770_P_OffCrab4_E.root";
-//const TString calfile = "../20040215_16771_C_OffCrab4_E.root";
+//const TString pedfile = "/remote/home/pc2/operator/Crab20040214/20040215_16743_P_CrabOn_E.root";
+//const TString calfile = "/remote/home/pc2/operator/Crab20040214/20040215_16744_C_CrabOn_E.root";
+const TString pedfile = "../20040215_16770_P_OffCrab4_E.root";
+const TString calfile = "../20040215_16771_C_OffCrab4_E.root";
 
 //const TString pedfile = "/mnt/users/mdoro/Mars/Data/20040201_14418_P_OffMrk421-1_E.root";
@@ -39,5 +41,5 @@
 
 void calibration(TString pedname=pedfile,
-             TString calname=calfile)
+                 TString calname=calfile)
 {
 
@@ -220,11 +222,20 @@
     plist2.AddToList(&tlist2);
 
-    MExtractedSignalCam     sigcam;
-    MCalibrationChargeCam   calcam;
-    MHCalibrationRelTimeCam timecam;
-    MHCalibrationChargeCam  chargecam;
-    MHCalibrationChargePINDiode chargepin;
-
-   //
+    MExtractedSignalCam        sigcam;
+    MCalibrationChargeCam      calcam;
+    MCalibrationChargePINDiode pindiode;   
+    MCalibrationChargeBlindPix blindpix;   
+    
+    MHCalibrationRelTimeCam     histtime;
+    MHCalibrationChargeCam      histcharge;
+    MHCalibrationChargePINDiode histpin;
+    MHCalibrationChargeBlindPix histblind;
+    //
+    // As long, as we don't have digital modules,
+    // we have to set the color of the pulser LED by hand
+    //
+    calcam.SetColor(MCalibrationChargeCam::kECT1);
+    pindiode.SetColor(MCalibrationChargePINDiode::kECT1);
+    //
     // Get the previously created MPedestalCam into the new Parameter List 
     //
@@ -233,7 +244,8 @@
     plist2.AddToList(&sigcam);
     plist2.AddToList(&calcam);
-    plist2.AddToList(&timecam);
-    plist2.AddToList(&chargecam);
-    plist2.AddToList(&chargepin);
+    plist2.AddToList(&histtime);
+    plist2.AddToList(&histcharge);
+    plist2.AddToList(&histpin);
+    plist2.AddToList(&histblind);
     //
     // Get the MAGIC geometry
@@ -258,7 +270,8 @@
     MCalibrationChargeCalc calcalc;
 
-    MFillH filltime("MHCalibrationRelTimeCam", "MArrivalTime");
-    MFillH fillpin("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode");
-    MFillH fillcam("MHCalibrationChargeCam"     , "MExtractedSignalCam");
+    MFillH filltime ("MHCalibrationRelTimeCam"    , "MArrivalTime");
+    MFillH fillpin  ("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode");
+    MFillH fillblind("MHCalibrationChargeBlindPix", "MExtractedSignalBlindPixel");
+    MFillH fillcam  ("MHCalibrationChargeCam"     , "MExtractedSignalCam");
 
     //
@@ -321,4 +334,5 @@
     tlist2.AddToList(&filltime);
     tlist2.AddToList(&fillpin);
+    tlist2.AddToList(&fillblind);
     tlist2.AddToList(&fillcam);
     //
@@ -347,5 +361,6 @@
     // just one example how to get the plots of individual pixels
     //
-    chargecam[5].DrawClone("fourierevents");
+//    histblind.DrawClone("all");
+//    histcharge[5].DrawClone("time");
 
     // Create histograms to display
@@ -355,23 +370,23 @@
     MHCamera disp4  (geomcam, "Cal;RSigma",         "Reduced Sigmas");
     MHCamera disp5  (geomcam, "Cal;RSigma/Charge",  "Reduced Sigma per Charge");
-    MHCamera disp6  (geomcam, "Cal;FFactorPh",      "Nr. of Photons (F-Factor Method)");
-    MHCamera disp7  (geomcam, "Cal;FFactorConv",    "Conversion Factor (F-Factor Method)");
+    MHCamera disp6  (geomcam, "Cal;FFactorPh",      "Nr. of Photo-electrons (F-Factor Method)");
+    MHCamera disp7  (geomcam, "Cal;FFactorConv",    "Conversion Factor to photons (F-Factor Method)");
     MHCamera disp8  (geomcam, "Cal;FFactorFFactor", "Total F-Factor (F-Factor Method)");
     MHCamera disp9  (geomcam, "Cal;BlindPixPh",     "Photon flux inside plexiglass (Blind Pixel Method)");
-    MHCamera disp10 (geomcam, "Cal;BlindPixConv",   "Conversion Factor (Blind Pixel Method)");
+    MHCamera disp10 (geomcam, "Cal;BlindPixConv",   "Conversion Factor to photons (Blind Pixel Method)");
     MHCamera disp11 (geomcam, "Cal;BlindPixFFactor","Total F-Factor (Blind Pixel Method)");
     MHCamera disp12 (geomcam, "Cal;PINDiodePh",     "Photon flux outside plexiglass (PIN Diode Method)");
-    MHCamera disp13 (geomcam, "Cal;PINDiodeConv",   "Conversion Factor (PIN Diode Method)");
+    MHCamera disp13 (geomcam, "Cal;PINDiodeConv",   "Conversion Factor tp photons (PIN Diode Method)");
     MHCamera disp14 (geomcam, "Cal;PINDiodeFFactor","Total F-Factor (PIN Diode Method)");
     MHCamera disp15 (geomcam, "Cal;Excluded",       "Pixels previously excluded");
     MHCamera disp16 (geomcam, "Cal;NotFitted",      "Pixels that could not be fitted");
     MHCamera disp17 (geomcam, "Cal;NotFitValid",    "Pixels with not valid fit results");
-    MHCamera disp18 (geomcam, "Cal;HiGainOscillating", "Oscillating Pixels HI Gain");
-    MHCamera disp19 (geomcam, "Cal;LoGainOscillating", "Oscillating Pixels LO Gain");
-    MHCamera disp20 (geomcam, "Cal;HiGainPickup",      "Number Pickup events Hi Gain");
-    MHCamera disp21 (geomcam, "Cal;LoGainPickup",      "Number Pickup events Lo Gain");
-    MHCamera disp22 (geomcam, "Cal;Saturation",        "Pixels with saturated Hi Gain");
-    MHCamera disp23 (geomcam, "Cal;FFactorValid",      "Pixels with valid F-Factor calibration");
-    MHCamera disp24 (geomcam, "Cal;BlindPixelValid",   "Pixels with valid BlindPixel calibration");
+    MHCamera disp18 (geomcam, "Cal;HiGainOscillating",     "Oscillating Pixels HI Gain");
+    MHCamera disp19 (geomcam, "Cal;LoGainOscillating",     "Oscillating Pixels LO Gain");
+    MHCamera disp20 (geomcam, "Cal;HiGainPickup",          "Number Pickup events Hi Gain");
+    MHCamera disp21 (geomcam, "Cal;LoGainPickup",          "Number Pickup events Lo Gain");
+    MHCamera disp22 (geomcam, "Cal;Saturation",            "Pixels with saturated Hi Gain");
+    MHCamera disp23 (geomcam, "Cal;FFactorValid",          "Pixels with valid F-Factor calibration");
+    MHCamera disp24 (geomcam, "Cal;BlindPixelValid",       "Pixels with valid BlindPixel calibration");
     MHCamera disp25 (geomcam, "Cal;PINdiodeFFactorValid",  "Pixels with valid PINDiode calibration");
 
@@ -450,5 +465,4 @@
     disp27.SetCamError(  calcam,41);
 
-/*
     // Relative Times
     disp28.SetCamContent(timecam,0);
@@ -459,5 +473,5 @@
     disp31.SetCamContent(timecam,5);
     disp32.SetCamContent(timecam,6);
-*/
+
     // Absolute Times
     disp33.SetCamContent(calcam,42);
@@ -472,7 +486,7 @@
     disp5.SetYTitle("Reduced Sigma / Mean Charge [1]");
 
-    disp6.SetYTitle("Nr. Photons [1]");
+    disp6.SetYTitle("Nr. Photo-electrons [1]");
     disp7.SetYTitle("Conversion Factor [Ph/FADC Count]");
-    disp8.SetYTitle("\\sqrt{N_{PhE}}*\\sigma_{Charge}/\\mu_{Charge} [1]");
+    disp8.SetYTitle("\\sqrt{N_{Ph}}*\\sigma_{Charge}/\\mu_{Charge} [1] ");
 
     disp9.SetYTitle("Photon flux [ph/mm^2]");
@@ -585,5 +599,4 @@
     CamDraw(c9,disp27,calcam,2,2,2);
 
-/*
     // Rel. Times
     TCanvas &c10 = display->AddTab("Fitted Rel. Times");
@@ -600,5 +613,5 @@
     CamDraw(c11, disp31,calcam,1,2, 0);
     CamDraw(c11, disp32,calcam,2,2, 0);
-*/
+
     // Abs. Times
     TCanvas &c12 = display->AddTab("Abs. Times");
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindPix.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindPix.cc	(revision 3293)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindPix.cc	(revision 3293)
@@ -0,0 +1,287 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Markus Gaug   02/2004 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MCalibrationChargeBlindPix                                                    //
+//                                                                         //
+// This is the storage container to hold informations about the calibration//
+// blind pixel                                                             //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#include "MCalibrationChargeBlindPix.h"
+
+#include <TH1.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MCalibrationChargeBlindPix);
+
+using namespace std;
+const Float_t MCalibrationChargeBlindPix::gkBlindPixelArea = 100;
+// Average QE of Blind Pixel (three colours)
+const Float_t MCalibrationChargeBlindPix::gkBlindPixelQEGreen = 0.154;
+const Float_t MCalibrationChargeBlindPix::gkBlindPixelQEBlue  = 0.226;
+const Float_t MCalibrationChargeBlindPix::gkBlindPixelQEUV    = 0.247;
+const Float_t MCalibrationChargeBlindPix::gkBlindPixelQECT1   = 0.247;
+// Average QE Error of Blind Pixel (three colours)
+const Float_t MCalibrationChargeBlindPix::gkBlindPixelQEGreenErr = 0.015;
+const Float_t MCalibrationChargeBlindPix::gkBlindPixelQEBlueErr  = 0.02;
+const Float_t MCalibrationChargeBlindPix::gkBlindPixelQEUVErr    = 0.02;
+const Float_t MCalibrationChargeBlindPix::gkBlindPixelQECT1Err   = 0.02;
+// Attenuation factor Blind Pixel (three colours)
+const Float_t MCalibrationChargeBlindPix::gkBlindPixelAttGreen = 1.97;
+const Float_t MCalibrationChargeBlindPix::gkBlindPixelAttBlue  = 1.96;
+const Float_t MCalibrationChargeBlindPix::gkBlindPixelAttUV    = 1.95;
+const Float_t MCalibrationChargeBlindPix::gkBlindPixelAttCT1   = 1.95;
+
+const Float_t MCalibrationChargeBlindPix::fgLambdaCheckLimit   = 0.2;
+const Float_t MCalibrationChargeBlindPix::fgLambdaErrLimit     = 0.2;
+// --------------------------------------------------------------------------
+//
+// Default Constructor. 
+//
+MCalibrationChargeBlindPix::MCalibrationChargeBlindPix(const char *name, const char *title)
+{
+
+  fName  = name  ? name  : "MCalibrationChargeBlindPix";
+  fTitle = title ? title : "Container of the fit results of the blind pixel";
+
+  SetLambdaCheckLimit();
+  SetLambdaErrLimit();
+
+  Clear();
+}
+
+
+// ------------------------------------------------------------------------
+//
+// Invalidate values
+//
+void MCalibrationChargeBlindPix::Clear(Option_t *o)
+{
+
+  fLambda      = -1.;
+  fLambdaCheck = -1.;
+  fMu0         = -1.;
+  fMu1         = -1.;
+  fSigma0      = -1.;
+  fSigma1      = -1.;
+  fLambdaErr   = -1.;
+  fMu0Err      = -1.;
+  fMu1Err      = -1.;
+  fSigma0Err   = -1.;
+  fSigma1Err   = -1.;
+
+  fMeanFluxInsidePlexiglass          = -1.;
+  fMeanFluxErrInsidePlexiglass       = -1.;
+
+  SetOscillating                   ( kFALSE );
+  SetExcluded                      ( kFALSE );
+  SetChargeFitValid                ( kFALSE );
+  SetPedestalFitOK                 ( kFALSE );
+  SetSinglePheFitOK                ( kFALSE );
+  SetFluxInsidePlexiglassAvailable ( kFALSE );
+
+}
+
+void  MCalibrationChargeBlindPix::SetFluxInsidePlexiglassAvailable( const Bool_t b)
+{
+    b ? SETBIT(fFlags,kFluxInsidePlexiglassAvailable) : CLRBIT(fFlags,kFluxInsidePlexiglassAvailable);
+}
+
+void  MCalibrationChargeBlindPix::SetOscillating( const Bool_t b)
+{
+    b ? SETBIT(fFlags,kOscillating) : CLRBIT(fFlags,kOscillating);
+}
+
+void  MCalibrationChargeBlindPix::SetChargeFitValid( const Bool_t b)
+{
+    b ? SETBIT(fFlags,kChargeFitValid) : CLRBIT(fFlags,kChargeFitValid);
+}
+void  MCalibrationChargeBlindPix::SetPedestalFitOK( const Bool_t b)
+{
+    b ? SETBIT(fFlags,kPedestalFitOK) : CLRBIT(fFlags,kPedestalFitOK);
+}
+
+void  MCalibrationChargeBlindPix::SetSinglePheFitOK( const Bool_t b)
+{
+    b ? SETBIT(fFlags,kSinglePheFitOK) : CLRBIT(fFlags,kSinglePheFitOK);
+}
+
+void  MCalibrationChargeBlindPix::SetExcluded( const Bool_t b)
+{
+    b ? SETBIT(fFlags,kExcluded) : CLRBIT(fFlags,kExcluded);
+}
+
+Bool_t MCalibrationChargeBlindPix::IsExcluded()       const
+{ 
+   return TESTBIT(fFlags,kExcluded);  
+}
+
+Bool_t MCalibrationChargeBlindPix::IsOscillating()  const 
+{
+    return TESTBIT(fFlags,kOscillating);
+}
+
+Bool_t MCalibrationChargeBlindPix::IsChargeFitValid()  const 
+{
+    return TESTBIT(fFlags,kChargeFitValid);
+}
+
+Bool_t MCalibrationChargeBlindPix::IsPedestalFitOK()  const 
+{
+    return TESTBIT(fFlags,kPedestalFitOK);
+}
+
+Bool_t MCalibrationChargeBlindPix::IsSinglePheFitOK()  const 
+{
+    return TESTBIT(fFlags,kSinglePheFitOK);
+}
+
+Bool_t  MCalibrationChargeBlindPix::IsFluxInsidePlexiglassAvailable()   const
+{
+  return TESTBIT(fFlags,kFluxInsidePlexiglassAvailable);
+}
+
+
+//
+// The check return kTRUE if:
+//
+// 1) fLambda and fLambdaCheck are separated relatively by fLambdaCheckLimit
+// 2) BlindPixel has an fLambdaErr smaller than  fLambdaErrLimit
+// 
+Bool_t MCalibrationChargeBlindPix::CheckChargeFitValidity()
+{
+
+  if (2.*(fLambdaCheck-fLambda)/(fLambdaCheck+fLambda) < fLambdaCheckLimit)
+    {
+      *fLog << warn << "WARNING: Lambda and Lambda-Check differ by more than "
+            << fLambdaCheckLimit << " in the Blind Pixel " << endl;
+      return kFALSE;
+    }
+  
+  if (fLambdaErr < fLambdaErrLimit) 
+    {
+      *fLog << warn << "WARNING: Error of Fitted Lambda is greater than "
+            << fLambdaErrLimit << " in Blind Pixel " << endl;
+      return kFALSE;
+    }
+      
+  return kTRUE;
+}
+
+
+
+// --------------------------------------------------------------------------
+//
+//
+//
+Bool_t MCalibrationChargeBlindPix::CalcFluxInsidePlexiglass()
+{
+
+  if (IsChargeFitValid())
+    return kFALSE;
+  
+
+  //
+  // Start calculation of number of photons 
+  //
+  // The blind pixel has exactly 100 mm^2 area (with negligible error), 
+  //
+  fMeanFluxInsidePlexiglass    = fLambda*gkBlindPixelArea;
+
+  // Start calculation of number of photons relative Variance 
+  fMeanFluxErrInsidePlexiglass  = fLambdaErr*fLambdaErr/fLambda/fLambda;
+  
+  switch (fColor)
+    {
+    case kEGreen:
+      fMeanFluxInsidePlexiglass    /= gkBlindPixelQEGreen;   
+      fMeanFluxErrInsidePlexiglass += gkBlindPixelQEGreenErr*gkBlindPixelQEGreenErr
+                                    / gkBlindPixelQEGreen  /   gkBlindPixelQEGreen;   
+
+      fMeanFluxInsidePlexiglass  *= TMath::Power(10,gkBlindPixelAttGreen); // correct for absorption 
+      // attenuation has negligible error
+      break;
+    case kEBlue:
+      fMeanFluxInsidePlexiglass    /= gkBlindPixelQEBlue;   
+      fMeanFluxErrInsidePlexiglass += gkBlindPixelQEBlueErr*gkBlindPixelQEBlueErr
+                                    / gkBlindPixelQEBlue  /   gkBlindPixelQEBlue;   
+
+      fMeanFluxInsidePlexiglass *= TMath::Power(10,gkBlindPixelAttBlue); // correct for absorption 
+      // attenuation has negligible error
+      break;
+    case kEUV:
+      fMeanFluxInsidePlexiglass    /= gkBlindPixelQEUV;   
+      fMeanFluxErrInsidePlexiglass += gkBlindPixelQEUVErr*gkBlindPixelQEUVErr
+                                    / gkBlindPixelQEUV  /   gkBlindPixelQEUV;   
+
+      fMeanFluxInsidePlexiglass *= TMath::Power(10,gkBlindPixelAttUV); // correct for absorption 
+      // attenuation has negligible error
+      break;
+    case kECT1:
+    default:
+      fMeanFluxInsidePlexiglass    /= gkBlindPixelQECT1;   
+      fMeanFluxErrInsidePlexiglass += gkBlindPixelQECT1Err*gkBlindPixelQECT1Err
+                                    / gkBlindPixelQECT1  /   gkBlindPixelQECT1;   
+
+      fMeanFluxInsidePlexiglass *= TMath::Power(10,gkBlindPixelAttCT1); // 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.)
+      return kFALSE;
+
+  if (fMeanFluxErrInsidePlexiglass < 0.)
+      return kFALSE;
+
+  SetFluxInsidePlexiglassAvailable(kTRUE);  
+
+  // 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;
+
+  return kTRUE;
+}
+
+
+
+
+
+
+
+
+
+
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindPix.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindPix.h	(revision 3292)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeBlindPix.h	(revision 3293)
@@ -73,4 +73,6 @@
 
   // Setters
+  void SetColor       ( const PulserColor_t color )  {  fColor = color;  }
+
   void SetLambda      ( const Float_t f ) { fLambda      = f;  }
   void SetLambdaCheck ( const Float_t f ) { fLambdaCheck = f;  }
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h	(revision 3292)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h	(revision 3293)
@@ -44,12 +44,4 @@
 public:
 
-  enum PulserColor_t { kEBlue, kEGreen, kEUV, kECT1 } ;
-
-private:
-
-  PulserColor_t fColor;  
-  
-public:
-
   MCalibrationChargeCam(const char *name=NULL, const char *title=NULL);
   ~MCalibrationChargeCam();
@@ -59,5 +51,4 @@
 
   // Setters   
-  void SetColor(    const PulserColor_t color )           {  fColor = color;         }
   void SetNumPixelsExcluded(  const UInt_t n )            {  fNumExcludedPixels = n; }
   void SetGeomCam(  const MGeomCam *geom)                 {  fGeomCam = geom;        }
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.cc	(revision 3292)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindPix.cc	(revision 3293)
@@ -196,10 +196,10 @@
 }
 
-void MHCalibrationChargeBlindPix::SetSinglePheFitOK   ( const Bool_t b=kTRUE) 
+void MHCalibrationChargeBlindPix::SetSinglePheFitOK (const Bool_t b) 
 {
     b ? SETBIT(fFlags,kSinglePheFitOK) : CLRBIT(fFlags,kSinglePheFitOK);
 }
 
-void MHCalibrationChargeBlindPix::SetPedestalFitOK( const Bool_t b=kTRUE)
+void MHCalibrationChargeBlindPix::SetPedestalFitOK(const Bool_t b)
 {
     b ? SETBIT(fFlags,kPedestalFitOK) : CLRBIT(fFlags,kPedestalFitOK);
