Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 8755)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 8756)
@@ -18,4 +18,26 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2007/10/13 Thomas Bretz
+
+   * mgeom/MGeomCam.[h,cc]:
+     - added new member functions GetDirections and GetNeighbor
+
+   * mgeom/MGeomCamDwarf.cc:
+     - fixed counting of pixels
+
+   * mgeom/MGeomPix.[h,cc]:
+     - added enumfor direction
+     - added new member function GetDirection
+
+   * mhist/MHCamera.cc:
+     - make sure that fGeomCam is correctly duplicated. The standard
+       clone fails if the MGeomCam clone has been overwritten
+     - added "text" option to Draw
+
+   * mtools/MagicReversi.[h,cc]:
+     - moved GetDirection and GetNeighbor to MGeomCam
+
+
 
  2007/10/10 Thomas Bretz
Index: /trunk/MagicSoft/Mars/mgeom/MGeomCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 8755)
+++ /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 8755)
+++ /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 8755)
+++ /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 8755)
+++ /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 8755)
+++ /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;
 
     /*
Index: /trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 8755)
+++ /trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 8756)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.105 2007-10-08 15:45:24 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.106 2007-10-13 18:56:27 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -162,6 +162,13 @@
 TObject *MHCamera::Clone(const char *newname) const
 {
-    TH1 *rc = static_cast<TH1*>(TH1D::Clone(newname));
+    MHCamera *rc = static_cast<MHCamera*>(TH1D::Clone(newname));
     rc->SetDirectory(NULL);
+
+    if (rc->fGeomCam && fGeomCam)
+    {
+        delete rc->fGeomCam;
+        rc->fGeomCam = static_cast<MGeomCam*>(fGeomCam->Clone());
+    }
+
     return rc;
 }
@@ -571,4 +578,5 @@
 //   'content'     Display the relative content aligned to GetMaximum() and
 //                 GeMinimum() ((val-min)/(max-min))
+//   'text'        Draw GetBinContent as char
 //   'proj'        Display the y-projection of the histogram
 //   'pal0'        Use Pretty palette
@@ -1176,4 +1184,9 @@
         return;
     }
+    if (opt.Contains("text"))
+    {
+        PaintIndices(5);
+        return;
+    }
 }
 
@@ -1301,4 +1314,5 @@
 //  1: sector number
 //  2: content
+//  5: Assume GetBinContent is a char
 //
 void MHCamera::PaintIndices(Int_t type)
@@ -1314,5 +1328,6 @@
 
     TText txt;
-    txt.SetTextFont(122);
+    if (type!=5)
+        txt.SetTextFont(122);
     txt.SetTextAlign(22);   // centered/centered
 
@@ -1329,4 +1344,5 @@
         case 3: num += TMath::Nint(fArray[i+1]); break;
         case 4: num += fBinEntries[i+1]; break;
+        case 5: num = (char)TMath::Nint(GetBinContent(i+1)); break;
         }
 
Index: /trunk/MagicSoft/Mars/mtools/MagicReversi.cc
===================================================================
--- /trunk/MagicSoft/Mars/mtools/MagicReversi.cc	(revision 8755)
+++ /trunk/MagicSoft/Mars/mtools/MagicReversi.cc	(revision 8756)
@@ -481,40 +481,4 @@
 }
 
-Int_t MagicReversi::GetDirection(Int_t src, Int_t dst) const
-{
-    const MGeomPix &pix1=(*fGeomCam)[dst];
-    const MGeomPix &pix2=(*fGeomCam)[src];
-
-    const Double_t x1 = pix1.GetX();
-    const Double_t y1 = pix1.GetY();
-
-    const Double_t x2 = pix2.GetX();
-    const Double_t y2 = pix2.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;
-}
-
-Int_t MagicReversi::GetNeighbor(Int_t idx, Int_t dir) const
-{
-    MGeomPix &pix=(*fGeomCam)[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;
-}
-
 Bool_t MagicReversi::Flip(Int_t origidx, Bool_t flip)
 {
@@ -523,5 +487,5 @@
     int test[6] = {0,0,0,0,0,0};
 
-    for (int dir=kRightTop; dir<=kLeftTop; dir++)
+    for (int dir=MGeomPix::kRightTop; dir<=MGeomPix::kLeftTop; dir++)
     {
         Int_t idx = origidx;
@@ -530,5 +494,5 @@
         while (1)
         {
-            idx = GetNeighbor(idx, dir);
+            idx = fGeomCam->GetNeighbor(idx, dir);
             if (idx<0 || (*this)[idx].GetFillColor()==kEmpty)
                 break;
@@ -547,5 +511,5 @@
     int cnt = 0;
 
-    for (int dir=kRightTop; dir<=kLeftTop; dir++)
+    for (int dir=MGeomPix::kRightTop; dir<=MGeomPix::kLeftTop; dir++)
     {
         Int_t idx = origidx;
@@ -557,5 +521,5 @@
             for (int i=0; i<test[dir]; i++)
             {
-                idx = GetNeighbor(idx, dir);
+                idx = fGeomCam->GetNeighbor(idx, dir);
 
                 fUsrPts[(*this)[idx].GetFillColor()-kRed]--;
Index: /trunk/MagicSoft/Mars/mtools/MagicReversi.h
===================================================================
--- /trunk/MagicSoft/Mars/mtools/MagicReversi.h	(revision 8755)
+++ /trunk/MagicSoft/Mars/mtools/MagicReversi.h	(revision 8756)
@@ -19,14 +19,4 @@
 {
 private:
-    enum {
-        kRightTop,
-        kRight,
-        kRightBottom,
-        kLeftBottom,
-        kLeft,
-        kLeftTop
-    };
-//    static const Int_t fColorBombs[7]; // colors for the hexagons
-
     MGeomCam      *fGeomCam;       // pointer to camera geometry
 
@@ -73,6 +63,4 @@
 
     Bool_t Flip(Int_t idx, Bool_t flip);
-    Int_t  GetDirection(Int_t src, Int_t dst) const;
-    Int_t  GetNeighbor(Int_t idx, Int_t dir) const;
     Bool_t CheckMoves();
 
