Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 4846)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 4847)
@@ -25,5 +25,7 @@
      - small modification in QE of new blind pixel
 
-
+   * mcalib/MCalibrationChargeCam.[h,cc]
+     - two new functions GetAveragedConvFADC2PhotPerArea and 
+       GetAveragedConvFADC2PhotPerSector, to be used by the data check.
 
  2004/09/03: Wolfgang Wittek
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 4846)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 4847)
@@ -94,4 +94,7 @@
 #include "MBadPixelsPix.h"
 
+#include "MCalibrationQECam.h"
+#include "MCalibrationQEPix.h"
+
 #include "MCalibrationChargePix.h"
 #include "MCalibrationChargeBlindPix.h"
@@ -562,2 +565,108 @@
 
 
+// --------------------------------------------------------------------------
+//
+// Calculates the average conversion factor FADC counts to photons for pixel sizes. 
+// The geometry container is used to get the necessary
+// geometry information (area index). The MCalibrationQECam container is necessary for 
+// the quantum efficiency information. 
+// If the bad pixel container is given all pixels which have the flag 'kUnsuitableRun' are ignored
+// in the calculation of the size average.
+//
+// Returns a TArrayF of dimension 2: 
+// arr[0]: averaged conversion factors (default: -1.)
+// arr[1]: Error (rms) of averaged conversion factors (default: 0.)
+//
+// ATTENTION: THE USER HAS TO DELETE THE RETURNED TARRAYF ACCORDINGLY
+//
+TArrayF *MCalibrationChargeCam::GetAveragedConvFADC2PhotPerArea  ( const MGeomCam &geom, const MCalibrationQECam &qecam,
+                                           const UInt_t ai,  MBadPixelsCam *bad)
+{
+
+  const Int_t np = GetSize();
+
+  Double_t mean  = 0.;
+  Double_t mean2 = 0.;
+  Int_t    nr    = 0;
+
+  for (int i=0; i<np; i++)
+    {
+      if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
+        continue; 
+      
+      const UInt_t aidx = geom[i].GetAidx();
+      
+      if (ai != aidx)
+        continue;
+
+      const MCalibrationChargePix &pix = (MCalibrationChargePix&)(*this)[i];
+      const Float_t conv = pix.GetMeanConvFADC2Phe();
+
+      const MCalibrationQEPix &qepix = (MCalibrationQEPix&)qecam[i];
+      const Float_t qe = qepix.GetQECascadesCombined();
+
+      mean  += conv/qe;
+      mean2 += conv*conv/qe/qe;
+      nr    ++;
+      
+    }
+
+  TArrayF *arr = new TArrayF(2);
+  arr->AddAt(nr   ? mean/nr : -1.,0);
+  arr->AddAt(nr>1 ? TMath::Sqrt((mean2 - mean*mean/nr)/(nr-1)) : 0. ,1);
+
+  return arr;
+}
+
+// --------------------------------------------------------------------------
+//
+// Calculates the average conversion factor FADC counts to photons for camera sectors. 
+// The geometry container is used to get the necessary
+// geometry information (area index). The MCalibrationQECam container is necessary for 
+// the quantum efficiency information. 
+// If the bad pixel container is given all pixels which have the flag 'kUnsuitableRun' are ignored
+// in the calculation of the size average.
+//
+// Returns a TArrayF of dimension 2: 
+// arr[0]: averaged conversion factors (default: -1.)
+// arr[1]: Error (rms) of averaged conversion factors (default: 0.)
+//
+// ATTENTION: THE USER HAS TO DELETE THE RETURNED TARRAYF ACCORDINGLY
+//
+TArrayF *MCalibrationChargeCam::GetAveragedConvFADC2PhotPerSector( const MGeomCam &geom, const MCalibrationQECam &qecam,
+                                             const UInt_t sec, MBadPixelsCam *bad)
+{
+  const Int_t np = GetSize();
+
+  Double_t mean  = 0.;
+  Double_t mean2 = 0.;
+  Int_t    nr    = 0;
+
+  for (int i=0; i<np; i++)
+    {
+      if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
+        continue; 
+      
+      const UInt_t sector = geom[i].GetSector();
+      
+      if (sector != sec)
+        continue;
+
+      const MCalibrationChargePix &pix = (MCalibrationChargePix&)(*this)[i];
+      const Float_t conv = pix.GetMeanConvFADC2Phe();
+
+      const MCalibrationQEPix &qepix = (MCalibrationQEPix&)qecam[i];
+      const Float_t qe = qepix.GetQECascadesCombined();
+
+      mean  += conv/qe;
+      mean2 += conv*conv/qe/qe;
+      nr    ++;
+      
+    }
+
+  TArrayF *arr = new TArrayF(2);
+  arr->AddAt(nr   ? mean/nr : -1.,0);
+  arr->AddAt(nr>1 ? TMath::Sqrt((mean2 - mean*mean/nr)/(nr-1)) : 0. ,1);
+
+  return arr;
+}  
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h	(revision 4846)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.h	(revision 4847)
@@ -10,4 +10,5 @@
 #endif
 
+class MCalibrationQECam;
 class MCalibrationChargeCam : public MCalibrationCam
 {
@@ -46,4 +47,9 @@
   Bool_t  IsFFactorMethodValid            () const;
 
+  TArrayF *GetAveragedConvFADC2PhotPerArea  ( const MGeomCam &geom, const MCalibrationQECam &qecam,
+                                             const UInt_t ai=0,  MBadPixelsCam *bad=NULL);
+  TArrayF *GetAveragedConvFADC2PhotPerSector( const MGeomCam &geom, const MCalibrationQECam &qecam,
+                                             const UInt_t sec=0, MBadPixelsCam *bad=NULL);  
+  
   // Prints
   void   Print(Option_t *o="")         const;
