Index: trunk/MagicSoft/Mars/manalysis/MCameraData.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCameraData.cc	(revision 4384)
+++ trunk/MagicSoft/Mars/manalysis/MCameraData.cc	(revision 4444)
@@ -17,4 +17,5 @@
 !
 !   Author(s): Thomas Bretz, 10/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!              Hendrik Bartko, 08/2004 <mailto:hbartko@mppmu.mpg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2003
@@ -34,4 +35,5 @@
 
 #include "MGeomCam.h"
+#include "MGeomPix.h"
 
 #include "MLog.h"
@@ -57,9 +59,10 @@
 }
 
+/*
 // --------------------------------------------------------------------------
 //
 // This is not yet implemented like it should.
 //
-/*
+
 void MCameraData::Draw(Option_t* option) 
 {
@@ -76,4 +79,16 @@
 }
 */
+
+
+// --------------------------------------------------------------------------
+//
+// Function to calculate the cleaning level for all pixels in a given event
+// as the ratio between the measured photons and the pedestal rms.
+// In order to do the image cleaning on average in the same photon flux
+// (reconstructed photons per pixel area) for the inner and outer pixels,
+// a correction factor is applied to the outer pixels (see TDAS 02-14).
+// The correction factor assumes the ideal case that the pedestal rms 
+// scales with the inverse square root of the pixel area.
+//
 
 void MCameraData::CalcCleaningLevel(const MCerPhotEvt &evt, const MPedPhotCam &cam,
@@ -113,4 +128,66 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Function to calculate the cleaning level for all pixels in a given event
+// as the ratio between the measured photons and the pedestal rms.
+// In order to do the image cleaning on average in the same photon flux
+// (reconstructed photons per pixel area) for the inner and outer pixels,
+// a correction factor is applied to the outer pixels (see TDAS 02-14).
+// The correction factor takes the actual average pedestal RMS of the
+// inner and outer pixels into account.
+//
+
+void MCameraData::CalcCleaningLevel2(const MCerPhotEvt &evt, const MPedPhotCam &cam,
+                                    const MGeomCam &geom)
+{
+    const Int_t n = geom.GetNumPixels();
+
+    fData.Set(n);
+    fData.Reset();
+
+    fValidity.Set(n);
+    fValidity.Reset();
+
+    const Int_t entries = evt.GetNumPixels();
+
+    const Float_t meannoise[2] = {cam.GetArea(0).GetRms(), cam.GetArea(1).GetRms()} ; // mean noise for the inner and the outer pixels
+
+    //
+    // check the number of all pixels against the noise level and
+    // set them to 'unused' state if necessary
+    // 
+    for (Int_t i=0; i<entries; i++)
+    {
+        const MCerPhotPix &pix = evt[i];
+
+        const Int_t idx = pix.GetPixId();
+        const Float_t noise = cam[idx].GetRms();
+
+        if (noise<=0) // fData[idx]=0, fValidity[idx]=0
+            continue;
+
+        //
+	// We calculate a correction factor which accounts for the 
+	// fact that pixels have different size (see TDAS 02-14).
+	// We also take into account that the RMS does not scale 
+	// with the square root of the pixel area.
+	// 
+
+	const UInt_t aidx = geom[idx].GetAidx();
+
+
+	if (meannoise[0] > 0 && meannoise[1] > 0)  
+	{
+	  fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) * meannoise[aidx] / meannoise[0] / noise;
+	 
+	}
+	else fData[idx] = pix.GetNumPhotons() * geom.GetPixRatioSqrt(idx) / noise;
+
+        fValidity[idx] = 1;
+    }
+}
+
+
 void MCameraData::CalcCleaningLevel(const MCerPhotEvt &evt, const MSigmabar &sgb,
                                     const MGeomCam &geom)
@@ -154,4 +231,62 @@
 }
 
+
+// --------------------------------------------------------------------------
+//
+// Function to calculate the cleaning level for all pixels in a given event
+// as the ratio between the reconstructed number of photons per area of an
+// inner pixel and the average pedestal RMS of the inner pixels (democratic
+// image cleaning, see TDAS 02-14).
+
+
+void MCameraData::CalcCleaningLevelDemocratic(const MCerPhotEvt &evt, const MPedPhotCam &cam,
+                                              const MGeomCam &geom)
+{
+    const Int_t n = geom.GetNumPixels();
+
+    fData.Set(n);
+    fData.Reset();
+
+    fValidity.Set(n);
+    fValidity.Reset();
+
+    const Int_t entries = evt.GetNumPixels();
+
+    const Float_t meannoise[2] = {cam.GetArea(0).GetRms(), cam.GetArea(1).GetRms()} ; // mean noise for the inner and the outer pixels
+
+        
+    //
+    // check the number of all pixels against the noise level and
+    // set them to 'unused' state if necessary
+    // 
+    for (Int_t i=0; i<entries; i++)
+    {
+      const MCerPhotPix &pix = evt[i];
+      
+      const Int_t idx = pix.GetPixId();
+      const Float_t noise = cam[idx].GetRms();
+      
+      if (noise<=0)
+	continue;
+	
+      //
+      // We calculate a correction factor which accounts for the     
+      // fact that pixels have different size (see TDAS 02-14).
+      // 
+      
+      
+      if (meannoise[0]>0) // fData[idx]=0, fValidity[idx]=0
+      {
+	fData[idx] = pix.GetNumPhotons() * geom.GetPixRatio(idx) / meannoise[0];
+	fValidity[idx] = 1;
+      }
+      else 
+	fValidity[idx] = 0;
+    }
+    
+}
+
+
+
 // --------------------------------------------------------------------------
 //
Index: trunk/MagicSoft/Mars/manalysis/MCameraData.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCameraData.h	(revision 4384)
+++ trunk/MagicSoft/Mars/manalysis/MCameraData.h	(revision 4444)
@@ -38,4 +38,11 @@
     void CalcCleaningLevel(const MCerPhotEvt &evt, Double_t noise,
                            const MGeomCam &geom);
+
+    void CalcCleaningLevel2(const MCerPhotEvt &evt, const MPedPhotCam &fCam,
+                           const MGeomCam &geom);
+
+    void CalcCleaningLevelDemocratic(const MCerPhotEvt &evt, const MPedPhotCam &cam,
+                                     const MGeomCam &geom);
+
 /*
     void Calc(const MCerPhotEvt &evt, const MGeomCam &geom)
