Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 4677)
+++ trunk/MagicSoft/Mars/Changelog	(revision 4678)
@@ -21,21 +21,28 @@
 
 
-  2004/08/18 : Wolfgang Wittek
-
-    * mastro/MTransCelLocCam.[h,cc]
-      - new class; allows to calculate for any point (X, Y) in the 
-        camera the local (celestial) coordinates if the local 
-        (celestial) coordinates are known for some fixed point (X0, Y0) 
-        in the camera
-      - for given local (celestial) coordinates of the camera center,
-        the meber function PlotGrid draws the lines of constant theta 
-        and phi (and of constant dec and hourangle) onto the camera 
-        plane 
-    
-    * mastro/Makefile, mastro/AstroLinkDef.h
-      - MTransCelLocCam added
-
-    * macros/testMTrans.C
-      - macro to test the class MTransCelLocCam
+ 2004/08/18: Thomas Bretz
+
+   * mbadpixels/MBadPixelsCam.[h,cc]:
+     - implemented function to calculate max cluster sizes
+
+
+
+ 2004/08/18 : Wolfgang Wittek
+
+   * mastro/MTransCelLocCam.[h,cc]
+     - new class; allows to calculate for any point (X, Y) in the 
+       camera the local (celestial) coordinates if the local 
+       (celestial) coordinates are known for some fixed point (X0, Y0) 
+       in the camera
+     - for given local (celestial) coordinates of the camera center,
+       the meber function PlotGrid draws the lines of constant theta 
+       and phi (and of constant dec and hourangle) onto the camera 
+       plane 
+
+   * mastro/Makefile, mastro/AstroLinkDef.h
+     - MTransCelLocCam added
+
+   * macros/testMTrans.C
+     - macro to test the class MTransCelLocCam
 
 
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc	(revision 4677)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc	(revision 4678)
@@ -42,4 +42,7 @@
 #include "MBadPixelsPix.h"
 
+#include "MGeomCam.h"
+#include "MGeomPix.h"
+
 ClassImp(MBadPixelsCam);
 
@@ -163,4 +166,145 @@
 {
     fArray->ForEach(TObject, Clear)();
+}
+
+// --------------------------------------------------------------------------
+//
+// Calculate the number of pixels with the given type-flags.
+//
+// The second argument aidx is the area index (see MGeomCam, MGeomPix)
+// The default (or any value less than 0) means: all
+//
+// Returns -1 if the geometry doesn't match.
+//
+Short_t MBadPixelsCam::GetNumUnsuitable(MBadPixelsPix::UnsuitableType_t type, const MGeomCam *geom, Int_t aidx) const
+{
+    const UInt_t n = GetSize();
+
+    if (aidx>=0 && geom->GetNumPixels()!=n)
+    {
+        *fLog << err << GetDescriptor() << "ERROR - Geometry (" << geom->ClassName() << ") size mismatch!" << endl;
+        return -1;
+    }
+
+    Short_t rc = 0;
+    for (UInt_t i=0; i<n; i++)
+    {
+        if (aidx>=0 && (*geom)[i].GetAidx()!=aidx)
+            continue;
+
+        if ((*this)[i].IsUnsuitable(type))
+            rc++;
+    }
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
+// Calculate the number of pixels which are - under no circumstances -
+// interpolatable, called isolated. This means that a pixel (its own status
+// doesn't matter) has less than two reliable neighbor pixels.
+//
+// The second argument aidx is the area index (see MGeomCam, MGeomPix)
+// The default (or any value less than 0) means: all
+//
+// Returns -1 if the geometry doesn't match.
+//
+Short_t MBadPixelsCam::GetNumIsolated(MBadPixelsPix::UnsuitableType_t type, const MGeomCam &geom, Int_t aidx) const
+{
+    const Int_t n = geom.GetNumPixels();
+
+    if (n!=GetSize())
+    {
+        *fLog << err << GetDescriptor() << "ERROR - Geometry (" << geom.ClassName() << ") size mismatch!" << endl;
+        return -1;
+    }
+
+    Short_t rc = 0;
+    for (int i=0; i<n; i++)
+    {
+        const MGeomPix &pix = geom[i];
+        if (aidx>=0 && pix.GetAidx()!=aidx)
+            continue;
+
+        const Int_t n2 = pix.GetNumNeighbors();
+
+        Int_t cnt=0;
+        for (int j=0; j<n2; j++)
+        {
+            const Int_t id2 = pix.GetNeighbor(j);
+            if (!(*this)[id2].IsUnsuitable(type))
+                cnt++;
+        }
+
+        if (cnt<2)
+            rc++;
+    }
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
+// This is a helper function which calculates the size of a single cluster
+// by iterative calling.
+//
+// If a pixel matches the criterias the counter is increased by 1 and
+// the function is called for all its neighbors. If
+//
+// The second argument aidx is the area index (see MGeomCam, MGeomPix)
+// The default (or any value less than 0) means: all
+//
+// Returns -1 if the geometry doesn't match.
+//
+Short_t MBadPixelsCam::GetNumMaxCluster(MBadPixelsPix::UnsuitableType_t type, TObjArray &list, Int_t idx, Int_t aidx) const
+{
+    const MGeomPix *pix = (MGeomPix*)list[idx];
+    if (!pix)
+        return 0;
+
+    if (!(*this)[idx].IsUnsuitable(type))
+        return 0;
+
+    if (aidx>=0 && pix->GetAidx()!=aidx)
+        return 1;
+
+    list.RemoveAt(idx);
+
+    Short_t cnt = 1;
+    const Int_t n = pix->GetNumNeighbors();
+    for (int i=0; i<n; i++)
+        cnt += GetNumMaxCluster(type, list, pix->GetNeighbor(i), aidx);
+
+    return cnt;
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the size of the biggest cluster with the given USuitableType
+// type and the given area index.
+//
+// The second argument aidx is the area index (see MGeomCam, MGeomPix)
+// The default (or any value less than 0) means: all
+//
+// Returns -1 if the geometry doesn't match.
+//
+Short_t MBadPixelsCam::GetNumMaxCluster(MBadPixelsPix::UnsuitableType_t type, const MGeomCam &geom, Int_t aidx) const
+{
+    const Int_t n = geom.GetNumPixels();
+
+    if (n!=GetSize())
+    {
+        *fLog << err << GetDescriptor() << "ERROR - Geometry (" << geom.ClassName() << ") size mismatch!" << endl;
+        return -1;
+    }
+
+    TObjArray list(n);
+    for (int i=0; i<n; i++)
+        list.AddAt(&geom[i], i);
+
+    Short_t max = 0;
+    for (int i=0; i<n; i++)
+        max = TMath::Max(GetNumMaxCluster(type, list, i, aidx), max);
+
+    return max;
 }
 
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.h
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.h	(revision 4677)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.h	(revision 4678)
@@ -2,6 +2,6 @@
 #define MARS_MBadPixelsCam
 
-#ifndef MARS_MParContainer
-#include "MParContainer.h"
+#ifndef MARS_MBadPixelsPix
+#include "MBadPixelsPix.h"
 #endif
 #ifndef MARS_MCamEvent
@@ -10,5 +10,4 @@
 
 class TClonesArray;
-class MBadPixelsPix;
 
 class MBadPixelsCam : public MParContainer, public MCamEvent
@@ -16,4 +15,6 @@
 private:
     TClonesArray *fArray; //-> 
+
+    Short_t GetNumMaxCluster(MBadPixelsPix::UnsuitableType_t type, TObjArray &list, Int_t idx, Int_t aidx) const;
 
 public:
@@ -34,4 +35,11 @@
     void Merge(const MBadPixelsCam &cam);
 
+    Short_t GetNumUnsuitable(MBadPixelsPix::UnsuitableType_t type, const MGeomCam *geom, Int_t aidx=-1) const;
+    Short_t GetNumUnsuitable(MBadPixelsPix::UnsuitableType_t type) const { return GetNumUnsuitable(type, 0); }
+    Short_t GetNumIsolated(MBadPixelsPix::UnsuitableType_t type, const MGeomCam &geom, Int_t aidx=-1) const;
+    Short_t GetNumIsolated(const MGeomCam &geom, Int_t aidx=-1) const { return GetNumIsolated(MBadPixelsPix::kUnsuitableRun, geom, aidx); }
+    Short_t GetNumMaxCluster(MBadPixelsPix::UnsuitableType_t type, const MGeomCam &geom, Int_t aidx=-1) const;
+    Short_t GetNumMaxCluster(const MGeomCam &geom, Int_t aidx=-1) { return GetNumMaxCluster(MBadPixelsPix::kUnsuitableRun, geom, aidx); }
+
     void   AsciiRead(ifstream &fin, UInt_t run);
     void   AsciiRead(ifstream &fin) { AsciiRead(fin, 0); }
