Index: trunk/MagicSoft/Mars/mcalib/MCalibrate.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrate.cc	(revision 3774)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrate.cc	(revision 3792)
@@ -18,5 +18,5 @@
 !   Author(s): Javier Lopez 12/2003 <mailto:jlopez@ifae.es>
 !   Author(s): Javier Rico  01/2004 <mailto:jrico@ifae.es>
-!   Author(s): Markus Gaug  02/2004 <mailto:markus@ifae.es>
+!   Author(s): Markus Gaug  04/2004 <mailto:markus@ifae.es>
 !
 !   Copyright: MAGIC Software Development, 2000-2004
@@ -41,4 +41,5 @@
 //   kBlindpixel: calibrates using the BlindPixel method 
 //   kBlindpixel: calibrates using the BlindPixel method 
+//   kFlatCharge: perform a charge flat-flatfielding. Outer pixels are area-corrected.
 //   kDummy:      calibrates with fixed conversion factors of 1 and errors of 0.
 //
@@ -134,11 +135,13 @@
 	  }
 
-	fQEs = (MCalibrationQECam*)pList->FindObject(AddSerialNumber("MCalibrationQECam"));
-	if (!fQEs)
-	  {
-	    *fLog << err << AddSerialNumber("MCalibrationQECam") << " not found ... aborting." << endl;
-	    return kFALSE;
-	  }
-        
+	if (fCalibrationMode>kFlatCharge)
+	{
+	    fQEs = (MCalibrationQECam*)pList->FindObject(AddSerialNumber("MCalibrationQECam"));
+	    if (!fQEs)
+	    {
+		*fLog << err << AddSerialNumber("MCalibrationQECam") << " not found ... aborting." << endl;
+		return kFALSE;
+	    }
+        }
       }
 
@@ -179,4 +182,18 @@
     }
 
+
+  if (fCalibrationMode == kFlatCharge)
+  {
+      fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
+      if (!fGeomCam)
+      {
+	  *fLog << err << AddSerialNumber("MGeomCam") << " not found ... aborting." << endl;
+	  return kFALSE;
+      }
+  }
+
+
+
+
   switch(fCalibrationMode)
     {
@@ -194,4 +211,8 @@
                     << ": Combined Calibration mode not yet available " << endl;
       return kFALSE;
+      break;
+	case kFlatCharge:
+      *fLog << warn << GetDescriptor() 
+                    << ": WARNING: Flat-fielding charges - only for Keiichi!!" << endl;
       break;
     case kDummy:
@@ -246,4 +267,15 @@
   Float_t calibQE       = 1.;
   Float_t calibQEVar    = 0.;
+  Float_t avMean        = 1.;
+  Float_t avMeanRelVar  = 0.;
+  
+
+  if (fCalibrationMode == kFlatCharge)
+  {
+      MCalibrationChargePix &avpix = (MCalibrationChargePix&)fCalibrations->GetAverageArea(0);
+      avMean       =  avpix.GetMean();
+      avMeanRelVar =  avpix.GetMeanRelVar();
+  }
+  
   
   for (UInt_t pixidx=0; pixidx<npix; pixidx++)
@@ -252,9 +284,10 @@
       if(fCalibrationMode!=kNone)
 	{
-
 	  
 	  MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCalibrations)[pixidx];
-	  MCalibrationQEPix     &qe  = (MCalibrationQEPix&)    (*fQEs         )[pixidx];
-
+
+	  hiloconv   = pix.GetConversionHiLo   ();
+	  hiloconverr= pix.GetConversionHiLoErr();
+	  
           if (fBadPixels)
             {
@@ -268,54 +301,62 @@
           calibFFactor   = pix.GetMeanFFactorFADC2Phot();
 
-	  switch(fCalibrationMode)
-	    {
-	    case kBlindPixel:
-              if (qe.IsBlindPixelMethodValid())
-		{
-                  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 kFfactor:
-              if (pix.IsFFactorMethodValid())
-		{
-                  calibQE      = qe.GetQECascadesFFactor   ( zenith );
-                  calibQEVar   = qe.GetQECascadesFFactorVar( zenith );
-		}
-              else
-                continue;
-	      break;
-	    case kCombined:
-              if (qe.IsCombinedMethodValid())
-		{
-                  calibQE      = qe.GetQECascadesCombined   ( zenith );
-                  calibQEVar   = qe.GetQECascadesCombinedVar( zenith );
-		}
-              else
-                continue;
-              break;
-            case kDummy:
- 	      hiloconv     = 1.;
-	      hiloconverr  = 0.;
-	      calibQE      = 1.;
-	      calibQEVar   = 0.;
-              break;
-
-	    } /* switch calibration mode */
-	  
-	  hiloconv   = pix.GetConversionHiLo   ();
-	  hiloconverr= pix.GetConversionHiLoErr();
-	  
+   	  if (fCalibrationMode== kFlatCharge)
+	  {
+	      calibConv        = avMean / pix.GetMean() / fGeomCam->GetPixRatio(pixidx) ;
+	      calibConvVar     = (avMeanRelVar + pix.GetMeanRelVar()) * calibConv * calibConv;
+	      calibFFactor     = pix.GetRSigmaPerCharge();
+	  }
+	  else
+	  {
+
+	      MCalibrationQEPix &qe  = (MCalibrationQEPix&) (*fQEs)[pixidx];
+
+	      switch(fCalibrationMode)
+	      {
+		  case kBlindPixel:
+		      if (qe.IsBlindPixelMethodValid())
+		      {
+			  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 kFfactor:
+		      if (pix.IsFFactorMethodValid())
+		      {
+			  calibQE      = qe.GetQECascadesFFactor   ( zenith );
+			  calibQEVar   = qe.GetQECascadesFFactorVar( zenith );
+		      }
+		      else
+			  continue;
+		      break;
+		  case kCombined:
+		      if (qe.IsCombinedMethodValid())
+		      {
+			  calibQE      = qe.GetQECascadesCombined   ( zenith );
+			  calibQEVar   = qe.GetQECascadesCombinedVar( zenith );
+		      }
+		      else
+			  continue;
+		      break;
+		  case kDummy:
+		      hiloconv     = 1.;
+		      hiloconverr  = 0.;
+		      calibQE      = 1.;
+		      calibQEVar   = 0.;
+		      break;
+		      
+	      } /* switch calibration mode */
+	  } /* else fCalibrationMode == kFlatCharge */
 	} /* if(fCalibrationMode!=kNone) */
       else
@@ -329,4 +370,5 @@
 	  calibQEVar     = 0.;
       }      
+
       MExtractedSignalPix &sig =  (*fSignals)[pixidx];
       
@@ -354,4 +396,8 @@
       nphotErr = calibFFactor*TMath::Sqrt(nphot);
 
+      if (fCalibrationMode == kFlatCharge)
+	  nphotErr = calibFFactor * signal;
+
+
       //
       // The following part is the outcommented first version of the error calculation
Index: trunk/MagicSoft/Mars/mcalib/MCalibrate.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrate.h	(revision 3774)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrate.h	(revision 3792)
@@ -40,5 +40,5 @@
 public:
 
-    enum CalibrationMode_t{kNone=0,kBlindPixel,kFfactor,kPinDiode,kCombined, kDummy};
+    enum CalibrationMode_t{kNone=0,kFlatCharge=1,kBlindPixel,kFfactor,kPinDiode,kCombined, kDummy};
     static const CalibrationMode_t kDefault = kBlindPixel;
 
