Index: trunk/MagicSoft/Mars/mcalib/MCalibrate.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrate.cc	(revision 3686)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrate.cc	(revision 3687)
@@ -70,4 +70,7 @@
 #include "MCalibrationChargePix.h"
 
+#include "MCalibrationQECam.h"
+#include "MCalibrationQEPix.h"
+
 #include "MExtractedSignalCam.h"
 #include "MExtractedSignalPix.h"
@@ -86,5 +89,5 @@
 //
 MCalibrate::MCalibrate(CalibrationMode_t calmode,const char *name, const char *title) 
-    : fGeomCam(NULL), fCalibrations(NULL), fBadPixels(NULL), fSignals(NULL), 
+    : fGeomCam(NULL), fCalibrations(NULL), fQEs(NULL), fBadPixels(NULL), fSignals(NULL), 
       fCerPhotEvt(NULL), fCalibrationMode(calmode)
 {
@@ -131,4 +134,11 @@
 	  }
 
+	fQEs = (MCalibrationQECam*)pList->FindObject(AddSerialNumber("MCalibrationQECam"));
+	if (!fQEs)
+	  {
+	    *fLog << err << AddSerialNumber("MCalibrationQECam") << " not found ... aborting." << endl;
+	    return kFALSE;
+	  }
+        
       }
 
@@ -148,13 +158,22 @@
 {
 
-  if(fCalibrationMode == kBlindPixel && !fCalibrations->IsBlindPixelMethodValid())
-    {
-      *fLog << warn << GetDescriptor() << "Warning: Blind pixel calibration method not valid, switching to F-factor method" << endl;
+  if(fCalibrationMode == kBlindPixel && !fQEs->IsBlindPixelMethodValid())
+    {
+      *fLog << warn << GetDescriptor() 
+            << "Warning: Blind pixel calibration method not valid, switching to F-factor method" << endl;
       fCalibrationMode = kFfactor;
     }
-
-  if(fCalibrationMode == kPinDiode && !fCalibrations->IsPINDiodeMethodValid())
+  
+  if(fCalibrationMode == kPinDiode && !fQEs->IsPINDiodeMethodValid())
     { 
-      *fLog << warn << GetDescriptor() << "Warning: PIN diode calibration method not valid, switching to F-factor method" << endl;
+      *fLog << warn << GetDescriptor() 
+            << "Warning: PIN diode calibration method not valid, switching to F-factor method" << endl;
+      fCalibrationMode = kFfactor;
+    }
+
+  if(fCalibrationMode == kCombined && !fQEs->IsCombinedMethodValid())
+    { 
+      *fLog << warn << GetDescriptor() 
+            << "Warning: Combined calibration method not valid, switching to F-factor method" << endl;
       fCalibrationMode = kFfactor;
     }
@@ -200,4 +219,10 @@
 Int_t MCalibrate::Process()
 {
+
+  //
+  // For the moment, we use only a dummy zenith for the calibration:
+  //
+  const Float_t zenith = 0;
+
   /*
     if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
@@ -216,6 +241,9 @@
   Float_t hiloconv      = 0.;
   Float_t hiloconverr   = 0.;
-  Float_t calibrationConversionFactor    = 0.;
-  Float_t calibrationConversionFactorErr = 0.;
+  Float_t calibConv     = 0.;
+  Float_t calibConvVar  = 0.;
+  Float_t calibFFactor  = 0.;
+  Float_t calibQE       = 0.;
+  Float_t calibQEVar    = 0.;
   
   for (UInt_t pixidx=0; pixidx<npix; pixidx++)
@@ -227,4 +255,5 @@
 	  
 	  MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCalibrations)[pixidx];
+	  MCalibrationQEPix     &qe  = (MCalibrationQEPix&)    (*fQEs         )[pixidx];
 	  MBadPixelsPix         &bad = (*fBadPixels)[pixidx];
 
@@ -233,52 +262,56 @@
               continue;
 
+          calibConv      = pix.GetMeanConvFADC2Phe();
+          calibConvVar   = pix.GetMeanConvFADC2PheVar();
+          calibFFactor   = pix.GetMeanFFactorFADC2Phot();
+
 	  switch(fCalibrationMode)
 	    {
 	    case kBlindPixel:
-		if (pix.IsBlindPixelMethodValid())
+              if (qe.IsBlindPixelMethodValid())
 		{
-		    calibrationConversionFactor      = pix.GetMeanConversionBlindPixelMethod();
-		    calibrationConversionFactorErr   = pix.GetConversionBlindPixelMethodErr();
+                  calibQE      = qe.GetQECascadesBlindPixel   ( zenith );
+                  calibQEVar   = qe.GetQECascadesBlindPixelVar( zenith );
+		}
+              else
+                continue;
+	      break;
+	    case kPinDiode:
+              if (qe.IsPINDiodeMethodValid())
+		{
+                  calibQE      = qe.GetQECascadesPINDiode   ( zenith );
+                  calibQEVar   = qe.GetQECascadesPINDiodeVar( zenith );
 		}
 		else
-		    continue;
-	      break;
-	    case kPinDiode:
-		if (pix.IsPINDiodeMethodValid())
-		{
-		    calibrationConversionFactor      = pix.GetMeanConversionPINDiodeMethod();
-		    calibrationConversionFactorErr   = pix.GetConversionPINDiodeMethodErr();
-		}
-		else
-		    continue;
+                  continue;
 	      break;
 	    case kFfactor:
-		if (pix.IsFFactorMethodValid())
+              if (pix.IsFFactorMethodValid())
 		{
-		    calibrationConversionFactor      = pix.GetMeanConversionFFactorMethod();
-		    calibrationConversionFactorErr   = pix.GetConversionFFactorMethodErr();
+                  calibQE      = qe.GetQECascadesFFactor   ( zenith );
+                  calibQEVar   = qe.GetQECascadesFFactorVar( zenith );
 		}
-		else
-		    continue;
+              else
+                continue;
 	      break;
 	    case kCombined:
-		if (pix.IsCombinedMethodValid())
+              if (qe.IsCombinedMethodValid())
 		{
-		    calibrationConversionFactor      = pix.GetMeanConversionCombinedMethod();
-		    calibrationConversionFactorErr   = pix.GetConversionCombinedMethodErr();
+                  calibQE      = qe.GetQECascadesCombined   ( zenith );
+                  calibQEVar   = qe.GetQECascadesCombinedVar( zenith );
 		}
-		else
-		    continue;
-		break;
+              else
+                continue;
+              break;
             case kDummy:
- 	      hiloconv                         = 1.;
-	      hiloconverr                      = 0.;
-	      calibrationConversionFactor      = 1.;
-	      calibrationConversionFactorErr   = 0.;
+ 	      hiloconv     = 1.;
+	      hiloconverr  = 0.;
+	      calibQE      = 1.;
+	      calibQEVar   = 0.;
               break;
 
 	    } /* switch calibration mode */
 	  
-	  hiloconv   = pix.GetConversionHiLo();
+	  hiloconv   = pix.GetConversionHiLo   ();
 	  hiloconverr= pix.GetConversionHiLoErr();
 	  
@@ -286,8 +319,11 @@
       else
       {
-	  hiloconv                         = 1.;
-	  hiloconverr                      = 0.;
-	  calibrationConversionFactor      = 1.;
-	  calibrationConversionFactorErr   = 0.;
+	  hiloconv       = 1.;
+	  hiloconverr    = 0.;
+	  calibConv      = 1.;
+	  calibConvVar   = 0.;
+	  calibFFactor   = 0.;
+	  calibQE        = 1.;
+	  calibQEVar     = 0.;
       }      
       MExtractedSignalPix &sig =  (*fSignals)[pixidx];
@@ -306,5 +342,5 @@
 	  if (sig.GetExtractedSignalHiGain() > 9999.)
 	    {
-	      signal = 0.;
+	      signal    = 0.;
 	      signalErr = 0.;
 	    }
@@ -313,12 +349,18 @@
         }
       
-      nphot    = signal*calibrationConversionFactor;
-      nphotErr = signal*calibrationConversionFactorErr
-        	*signal*calibrationConversionFactorErr
-	       + signalErr*calibrationConversionFactor
-        	*signalErr*calibrationConversionFactor;
-      
-      nphotErr  = TMath::Sqrt(nphotErr);
-      
+      nphot    = signal*calibConv/calibQE;
+      nphotErr = calibFFactor*TMath::Sqrt(nphot);
+
+      //
+      // The following part is the outcommented first version of the error calculation
+      // Contact Markus Gaug for questions (or wait for the next documentation update...)
+      //
+      /*
+        nphotErr = signal    > 0 ? signalErr*signalErr / (signal * signal)  : 0.
+                 + calibConv > 0 ? calibConvVar  / (calibConv * calibConv ) : 0.
+                 + calibQE   > 0 ? calibQEVar    / (calibQE   * calibQE   ) : 0.;
+        nphotErr  = TMath::Sqrt(nphotErr) * nphot;
+      */
+
       MCerPhotPix *cpix = fCerPhotEvt->AddPixel(pixidx, nphot, nphotErr);
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrateData.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrateData.cc	(revision 3686)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrateData.cc	(revision 3687)
@@ -19,4 +19,5 @@
 !   Author(s): Javier Rico     01/2004 <mailto:jrico@ifae.es>
 !   Author(s): Wolfgang Wittek 02/2004 <mailto:wittek@mppmu.mpg.de>
+!   Author(s): Markus Gaug     04/2004 <mailto:markus@ifae.es>
 !
 !   Copyright: MAGIC Software Development, 2000-2004
@@ -40,5 +41,6 @@
 //    MPedestalCam
 //    MExtractedSingalCam
-//    MCalibrationCam
+//    MCalibrationChargeCam
+//    MCalibrationQECam
 //
 //   Output Containers:
@@ -62,4 +64,7 @@
 #include "MCalibrationChargeCam.h"
 #include "MCalibrationChargePix.h"
+
+#include "MCalibrationQECam.h"
+#include "MCalibrationQEPix.h"
 
 #include "MExtractedSignalCam.h"
@@ -95,4 +100,5 @@
 //  - MPedestalCam
 //  - MCalibrationChargeCam
+//  - MCalibrationQECam
 //  - MExtractedSignalCam
 //
@@ -136,4 +142,10 @@
             return kFALSE;
         }
+        fQEs = (MCalibrationQECam*)pList->FindObject(AddSerialNumber("MCalibrationQECam"));
+        if (!fQEs)
+        {
+            *fLog << err << AddSerialNumber("MCalibrationQECam") << " not found ... aborting." << endl;
+            return kFALSE;
+        }
     }
 
@@ -161,5 +173,5 @@
 {
 
-  if(fCalibrationMode == kBlindPixel && !fCalibrations->IsBlindPixelMethodValid())
+  if(fCalibrationMode == kBlindPixel && !fQEs->IsBlindPixelMethodValid())
     {
       *fLog << warn << GetDescriptor() << "Warning: Blind pixel calibration method not valid, switching to F-factor method" << endl;
@@ -167,5 +179,5 @@
     }
 
-  if(fCalibrationMode == kPinDiode && !fCalibrations->IsPINDiodeMethodValid())
+  if(fCalibrationMode == kPinDiode && !fQEs->IsPINDiodeMethodValid())
     { 
       *fLog << warn << GetDescriptor() << "Warning: PIN diode calibration method not valid, switching to F-factor method" << endl;
@@ -201,13 +213,13 @@
 
     //----------------------------------
-    // get photon/ADC conversion factor
+    // get phe/ADC conversion factor
 
     Float_t hiloconv;
     Float_t hiloconverr;
-    Float_t calibrationConversionFactor;
-    Float_t calibrationConversionFactorErr;
+    Float_t calibConv;
+    Float_t calibFFactor;
 
     if ( !GetConversionFactor(pixid, hiloconv, hiloconverr,
-			      calibrationConversionFactor, calibrationConversionFactorErr ))
+			      calibConv, calibFFactor ))
       continue;
 
@@ -215,10 +227,10 @@
 
     // pedestals/(used FADC slices)   in [number of photons] 
-    Float_t pedphot    = pedes  * calibrationConversionFactor;
-    Float_t pedphotrms = pedrms * calibrationConversionFactor;
+    Float_t pedphot    = pedes  * calibConv;
+    Float_t pedphotrms = pedrms * calibConv;
 
     (*fPedPhot)[pixid].Set(pedphot, pedphotrms);
 
-    *fLog << all << pixid << ",  " << calibrationConversionFactor << ",  "
+    *fLog << all << pixid << ",  " << calibConv << ",  "
           << ped.GetPedestal() << ",  " << ped.GetPedestalRms() << ",  " 
           << pedphot << ",  " << pedphotrms << endl;
@@ -239,15 +251,22 @@
 Bool_t MCalibrateData::GetConversionFactor(UInt_t pixidx,
  Float_t &hiloconv, Float_t &hiloconverr,
- Float_t &calibrationConversionFactor, Float_t &calibrationConversionFactorErr)
-{
-  hiloconv    = 1.;
-  hiloconverr = 0.;
-  calibrationConversionFactor      = 1.;
-  calibrationConversionFactorErr   = 0.;
+ Float_t &calibConv, Float_t &calibFFactor)
+{
+
+  //
+  // For the moment, we use only a dummy zenith for the calibration:
+  //
+  const Float_t zenith = -1.;
+
+  hiloconv     = 1.;
+  hiloconverr  = 0.;
+  calibConv    = 1.;
+  calibFFactor = 0.;
 
   if(fCalibrationMode!=kNone)
   {
-    MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCalibrations)[pixidx];       
-    MBadPixelsPix         &bad = (*fBadPixels)[pixidx];
+    MCalibrationChargePix &pix   = (MCalibrationChargePix&)(*fCalibrations)[pixidx];       
+    MCalibrationQEPix     &qepix = (MCalibrationQEPix&)    (*fQEs)         [pixidx];       
+    MBadPixelsPix         &bad   = (*fBadPixels)[pixidx];
     
     if (!bad.IsCalibrationResultOK())
@@ -256,14 +275,18 @@
     hiloconv   = pix.GetConversionHiLo();
     hiloconverr= pix.GetConversionHiLoErr();
-	  
+
+    const Float_t pheConv = pix.GetMeanConvFADC2Phe();
+    calibFFactor          = pix.GetMeanFFactorFADC2Phot();
+    Float_t calibQE       = 1.;
+    
     switch(fCalibrationMode)
     {
       case kBlindPixel:
-      calibrationConversionFactor      = pix.GetMeanConversionBlindPixelMethod();
-      calibrationConversionFactorErr   = pix.GetConversionBlindPixelMethodErr();
+        calibQE      = qepix.GetQECascadesBlindPixel   ( zenith );
+        //        calibQEVar   = qepix.GetQECascadesBlindPixelVar( zenith );
       break;
       case kFfactor:
-      calibrationConversionFactor      = pix.GetMeanConversionFFactorMethod();
-      calibrationConversionFactorErr   = pix.GetConversionFFactorMethodErr();
+        calibQE      = qepix.GetQECascadesFFactor   ( zenith );
+        //        calibQEVar   = qepix.GetQECascadesFFactorVar( zenith );
       break;
       default:
@@ -271,8 +294,11 @@
 	      break;
     }
+    calibConv = pheConv / calibQE;
+
   }
 
   return kTRUE;
 }
+
 
 // --------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/mcalib/MCalibrateData.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrateData.h	(revision 3686)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrateData.h	(revision 3687)
@@ -26,4 +26,5 @@
 class MPedestalCam;
 class MCalibrationChargeCam;
+class MCalibrationQECam;
 class MExtractedSignalCam;
 
@@ -37,5 +38,6 @@
     MPedestalCam          *fPedestal;     // Pedestals/slice [ADC counts]
     MBadPixelsCam         *fBadPixels;    // Bad Pixels information
-    MCalibrationChargeCam *fCalibrations; // Calibration constants 
+    MCalibrationChargeCam *fCalibrations; // Calibration constants
+    MCalibrationQECam     *fQEs;          // Quantum efficiencies
     MExtractedSignalCam   *fSignals;      // Integrated charge in FADCs counts
 
Index: trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h	(revision 3686)
+++ trunk/MagicSoft/Mars/mcalib/MMcCalibrationCalc.h	(revision 3687)
@@ -7,4 +7,5 @@
 
 class MCalibrationChargeCam;
+class MCalibrationQECam;
 class MGeomCam;
 class MHillas;
@@ -19,4 +20,5 @@
 private:
     MCalibrationChargeCam     *fCalCam;
+    MCalibrationQECam         *fQECam;    
     MGeomCam                  *fGeom;
     MHillas                   *fHillas;
