Index: trunk/MagicSoft/Mars/mgeom/MGeomCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 8399)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 8756)
@@ -473,2 +473,37 @@
     GetNeighbors(arr, pix, r);
 }
+
+// --------------------------------------------------------------------------
+//
+// Return direction of p2 w.r.t. p1. For more details
+// see MGeomPix::GetDirection
+//
+Int_t MGeomCam::GetDirection(UInt_t p1, UInt_t p2) const
+{
+    if (p1>fNumPixels || p2>fNumPixels)
+        return -1;
+
+    return operator[](p1).GetDirection(operator[](p2));
+}
+
+// --------------------------------------------------------------------------
+//
+// Get index of neighbor of pixel idx in direction dir, if existing.
+//
+Int_t MGeomCam::GetNeighbor(UInt_t idx, Int_t dir) const
+{
+    if (idx>fNumPixels)
+        return -1;
+
+    const MGeomPix &pix=operator[](idx);
+
+    //
+    // search for the neighbor in the given direction
+    //
+    int i;
+    for (i=0; i<pix.GetNumNeighbors(); i++)
+        if (GetDirection(idx, pix.GetNeighbor(i))==dir)
+            return pix.GetNeighbor(i);
+
+    return -1;
+}
Index: trunk/MagicSoft/Mars/mgeom/MGeomCam.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCam.h	(revision 8399)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCam.h	(revision 8756)
@@ -102,4 +102,7 @@
     void GetNeighbors(TList &arr,   const MGeomPix &pix, Float_t r) const;
 
+    Int_t GetDirection(UInt_t p1, UInt_t p2) const;
+    Int_t GetNeighbor(UInt_t idx, Int_t dir) const;
+
     virtual void Print(Option_t *opt=NULL)   const;
 
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.cc	(revision 8399)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.cc	(revision 8756)
@@ -183,4 +183,7 @@
 // distance to (0,0) is retruned.
 //
+// Due to possible rounding errors we need to use exactly the same
+// algorithm as for creating the pixels!
+//
 Int_t MGeomCamDwarf::CalcNumPix(Double_t rad)
 {
@@ -198,9 +201,12 @@
         // starting number to the ending number
         //
-        for (int i=0; i<ring; i++)
-        {
-            Double_t x, y;
-            if (CalcXY(kDirN, ring, i, x, y)<rad)
-                n++;
+        for (Int_t dir=kDirNE; dir<=kDirSE; dir++)
+        {
+            for (int i=0; i<ring; i++)
+            {
+                Double_t x, y;
+                if (CalcXY(dir, ring, i, x, y)<rad)
+                    n++;
+            }
         }
 
@@ -209,5 +215,5 @@
 
         ring++;
-        cnt += 6*n; // Because of symmetry only one direction is enough
+        cnt += n;
     }
 
@@ -276,5 +282,8 @@
 
         if (n==0)
+        {
+            cout << cnt << " pixels created of " << GetNumPixels() << endl;
             return;
+        }
 
         ring++;
Index: trunk/MagicSoft/Mars/mgeom/MGeomPix.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomPix.cc	(revision 8399)
+++ trunk/MagicSoft/Mars/mgeom/MGeomPix.cc	(revision 8756)
@@ -173,2 +173,25 @@
     return kTRUE;
 }
+
+// ------------------------------------------------------------------------
+//
+// Return the direction of the pixel pix w.r.t. this pixel.
+// Remark: This function assumes a simple geometry.
+//
+Int_t MGeomPix::GetDirection(const MGeomPix &pix) const
+{
+    const Double_t x1 = GetX();
+    const Double_t y1 = GetY();
+
+    const Double_t x2 = pix.GetX();
+    const Double_t y2 = pix.GetY();
+
+    if (x1>=x2 && y1>y2) return kRightTop;
+    if (x1>=x2 && y1<y2) return kRightBottom;
+    if (x1<=x2 && y1>y2) return kLeftTop;
+    if (x1<=x2 && y1<y2) return kLeftBottom;
+    if (x1>x2)           return kRight;
+    if (x1<x2)           return kLeft;
+
+    return -1;
+}
Index: trunk/MagicSoft/Mars/mgeom/MGeomPix.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomPix.h	(revision 8399)
+++ trunk/MagicSoft/Mars/mgeom/MGeomPix.h	(revision 8756)
@@ -13,4 +13,13 @@
     static const Float_t gsTan60; // tan(60/kRad2Deg);
     static const Float_t gsTan30; // tan(30/kRad2Deg);
+
+    enum {
+        kRightTop,
+        kRight,
+        kRightBottom,
+        kLeftBottom,
+        kLeft,
+        kLeftTop
+    };
 
 private:
@@ -68,5 +77,4 @@
     Float_t GetAngle(const MGeomPix &pix) const { return TMath::ATan2(fX - pix.GetX(), fY - pix.GetY()); }
 
-
     Float_t GetA() const    { return fA; /*fD*fD*gsTan60/2;*/ }
     Int_t   GetAidx() const { return fAidx; }
@@ -79,4 +87,5 @@
 
     Bool_t IsInside(Float_t px, Float_t py) const;
+    Int_t  GetDirection(const MGeomPix &pix) const;
 
     /*
