Index: trunk/MagicSoft/Mars/mgeom/MGeomCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 7355)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 7360)
@@ -223,4 +223,50 @@
 // --------------------------------------------------------------------------
 //
+// sort neighbours from angle of -180 degree to -180 degree
+//
+// where right side of main pixel contains negative degrees
+// and left side positive degrees
+//
+// angle measured from top (0 degree) to bottom (180 degree)
+//             ^  -     |     +         //
+//             |      _ | _             //
+//             |     / \|/ \            //
+//  30 degree -+-   |   |   |           //
+//             |   / \ / \ / \          //
+//  90 degree -+- |   | X |   |         //
+//             |   \ / \ / \ /          //
+// 150 degree -+-   |   |   |           //
+//             |     \_/|\_/            //
+//             |        |               //
+//             |  -     |     +         //
+//             ------------------>      //
+//                                      //
+void MGeomCam::SortNeighbors()
+{
+    for (unsigned int i=0; i<fNumPixels; i++)
+    {
+        MGeomPix &gpix = (*this)[i];
+
+        Double_t phi[6];
+        Int_t    idx[7] = { 0, 0, 0, 0, 0, 0, -1 };
+
+        const Int_t n2 = gpix.GetNumNeighbors();
+        for (int j=0; j<n2; j++)
+        {
+            idx[j] = gpix.GetNeighbor(j);
+            phi[j] = (*this)[idx[j]].GetAngle(gpix);
+        }
+
+        Int_t sort[6] = { 6, 6, 6, 6, 6, 6 };
+
+        TMath::Sort(n2, phi, sort, kFALSE);
+
+        gpix.SetNeighbors(idx[sort[0]], idx[sort[1]], idx[sort[2]],
+                          idx[sort[3]], idx[sort[4]], idx[sort[5]]);
+    }
+}
+
+// --------------------------------------------------------------------------
+//
 // Returns the distance between the pixels i and j. -1 if an index
 // doesn't exist. The default for j is 0. Assuming that 0 is the index
Index: trunk/MagicSoft/Mars/mgeom/MGeomCam.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCam.h	(revision 7355)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCam.h	(revision 7360)
@@ -39,4 +39,5 @@
     void CalcNumAreas();
     void InitOuterRing();
+    void SortNeighbors();
 
 public:
@@ -56,4 +57,5 @@
         CalcPixRatio();
         InitOuterRing();
+        SortNeighbors();
     }
 
