Index: trunk/MagicSoft/Mars/mgeom/GeomLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/GeomLinkDef.h	(revision 9368)
+++ trunk/MagicSoft/Mars/mgeom/GeomLinkDef.h	(revision 9369)
@@ -5,5 +5,7 @@
 #pragma link off all functions;
 
+#pragma link C++ class MGeom+;
 #pragma link C++ class MGeomPix+;
+#pragma link C++ class MGeomRectangle+;
 #pragma link C++ class MGeomCam-;
 #pragma link C++ class MGeomPMT+;
@@ -16,4 +18,5 @@
 #pragma link C++ class MGeomCamDwarf+;
 #pragma link C++ class MGeomCamMagic+;
+#pragma link C++ class MGeomCamSquare+;
 //#pragma link C++ class MGeomCamMagicHG+;
 //#pragma link C++ class MGeomCamMagic919+;
Index: trunk/MagicSoft/Mars/mgeom/MGeomCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 9369)
@@ -85,6 +85,6 @@
 //
 MGeomCam::MGeomCam(UInt_t npix, Float_t dist, const char *name, const char *title)
-    : fNumPixels(npix), fCamDist(dist), fConvMm2Deg(kRad2Deg/(dist*1000)), 
-    fPixels(npix), fMaxRadius(1), fMinRadius(1), fPixRatio(npix), fPixRatioSqrt(npix)
+    : fNumPixels(npix), fCamDist(dist), fConvMm2Deg(kRad2Deg/(dist*1000)), fPixels(npix),
+    fMaxRadius(1), fMinRadius(1), fPixRatio(npix), fPixRatioSqrt(npix)
 {
     fName  = name  ? name  : "MGeomCam";
@@ -95,9 +95,4 @@
     //
     fPixels.SetOwner();
-
-    // For root versions <5.18 AddAt is mandatory, for newer
-    // root-version the []-operator can be used safely
-    for (UInt_t i=0; i<npix; i++)
-        fPixels.AddAt(new MGeomPix, i);
 }
 
@@ -126,11 +121,9 @@
     Int_t m = c.fPixels.GetEntriesFast();
 
+    c.fPixels.Delete();
     c.fPixels.Expand(n);
 
     for (int i=m; i<n; i++)
-        c.fPixels.AddAt(new MGeomPix, i);
-
-    for (int i=0; i<n; i++)
-        fPixels[i]->Copy(c[i]);
+        c.fPixels.AddAt(fPixels[i]->Clone(), i);
 }
 
@@ -141,7 +134,7 @@
 // entries may crash the program!
 //
-MGeomPix &MGeomCam::operator[](Int_t i)
-{
-    return *static_cast<MGeomPix*>(fPixels.UncheckedAt(i));
+MGeom &MGeomCam::operator[](Int_t i)
+{
+    return *static_cast<MGeom*>(fPixels.UncheckedAt(i));
 }
 
@@ -152,7 +145,7 @@
 // entries may crash the program!
 //
-MGeomPix &MGeomCam::operator[](Int_t i) const
-{
-    return *static_cast<MGeomPix*>(fPixels.UncheckedAt(i));
+MGeom &MGeomCam::operator[](Int_t i) const
+{
+    return *static_cast<MGeom*>(fPixels.UncheckedAt(i));
 }
 
@@ -240,5 +233,5 @@
     for (UInt_t i=0; i<fNumPixels; i++)
     {
-        const MGeomPix &pix = (*this)[i];
+        const MGeom &pix = (*this)[i];
 
         const UInt_t  s = pix.GetAidx();
@@ -289,5 +282,5 @@
     for (unsigned int i=0; i<fNumPixels; i++)
     {
-        MGeomPix &gpix = (*this)[i];
+        MGeom &gpix = (*this)[i];
 
         Double_t phi[6];
@@ -462,5 +455,5 @@
 // The center pixel is also returned.
 //
-void MGeomCam::GetNeighbors(TArrayI &arr, const MGeomPix &pix, Float_t r) const
+void MGeomCam::GetNeighbors(TArrayI &arr, const MGeom &pix, Float_t r) const
 {
     arr.Set(GetNumPixels());
@@ -490,5 +483,5 @@
     }
 
-    const MGeomPix &pix = (*this)[idx];
+    const MGeom &pix = (*this)[idx];
     GetNeighbors(arr, pix, r);
 }
@@ -499,5 +492,5 @@
 // The center pixel is also returned.
 //
-void MGeomCam::GetNeighbors(TList &arr, const MGeomPix &pix, Float_t r) const
+void MGeomCam::GetNeighbors(TList &arr, const MGeom &pix, Float_t r) const
 {
     for (unsigned int i=0; i<GetNumPixels(); i++)
@@ -518,5 +511,5 @@
         return;
 
-    const MGeomPix &pix = (*this)[idx];
+    const MGeom &pix = (*this)[idx];
     GetNeighbors(arr, pix, r);
 }
@@ -544,5 +537,5 @@
         return -1;
 
-    const MGeomPix &pix=operator[](idx);
+    const MGeom &pix=operator[](idx);
 
     //
@@ -598,2 +591,15 @@
         MGeomCam::Class()->WriteBuffer(b, this);
 }
+
+void MGeomCam::SetAt(UInt_t i, const MGeom &pix)
+{
+    if (i>=fNumPixels)
+        return;
+
+    if (fPixels[i])
+        delete fPixels.RemoveAt(i);
+
+    // For root versions <5.18 AddAt is mandatory, for newer
+    // root-version the []-operator can be used safely
+    fPixels.AddAt(pix.Clone(), i);
+}
Index: trunk/MagicSoft/Mars/mgeom/MGeomCam.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCam.h	(revision 9368)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCam.h	(revision 9369)
@@ -20,5 +20,5 @@
 class TVector2;
 class TArrayI;
-class MGeomPix;
+class MGeom;
 
 class MGeomCam : public MParContainer
@@ -43,5 +43,4 @@
 //    Int_t     fNumAreas;        // Number of different pixel sizes
 
-protected:
     void CalcMaxRadius();
     void CalcNumSectors();
@@ -52,4 +51,5 @@
 public:
     MGeomCam(UInt_t npix=0, Float_t dist=1, const char *name=NULL, const char *title=NULL);
+    MGeomCam(const MGeomCam &cam) { cam.Copy(*this); }
 
     void Copy(TObject &o) const;
@@ -95,6 +95,6 @@
     UShort_t GetNumPixWithAidx(UInt_t i) const { return (UShort_t)fNumPixWithAidx[i]; }
 
-    MGeomPix &operator[](Int_t i);
-    MGeomPix &operator[](Int_t i) const;
+    MGeom &operator[](Int_t i);
+    MGeom &operator[](Int_t i) const;
 
     Int_t GetPixelIdx(const TVector2 &v) const;
@@ -108,6 +108,6 @@
     void GetNeighbors(TArrayI &arr, UInt_t idx,          Float_t r) const;
     void GetNeighbors(TList &arr,   UInt_t idx,          Float_t r) const;
-    void GetNeighbors(TArrayI &arr, const MGeomPix &pix, Float_t r) const;
-    void GetNeighbors(TList &arr,   const MGeomPix &pix, Float_t r) const;
+    void GetNeighbors(TArrayI &arr, const MGeom &pix, Float_t r) const;
+    void GetNeighbors(TList &arr,   const MGeom &pix, Float_t r) const;
 
     Int_t GetDirection(UInt_t p1, UInt_t p2) const;
@@ -119,4 +119,6 @@
     void Print(Option_t *opt=NULL) const;
 
+    void SetAt(UInt_t i, const MGeom &pix);
+
     ClassDef(MGeomCam, 5)  // Geometry base class for the camera
 };
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.cc	(revision 9369)
@@ -222,7 +222,7 @@
     //  add the first pixel to the list
     //
-    Int_t pixnum = 0;
-
-    (*this)[pixnum++].Set(0, 0, diameter);
+    Int_t pixnum = 1;
+
+    SetAt(0, MGeomPix(0, 0, diameter));
 
     for (Int_t ring=1; ring<7; ring++)
@@ -233,32 +233,26 @@
         //
         for (int i=0; i<ring; i++)
-            (*this)[pixnum++].Set((ring-i*0.5)*diameter,
-                                  i*kS32*diameter,
-                                  diameter);
-
-        for (int i=0; i<ring; i++)
-            (*this)[pixnum++].Set((ring*0.5-i)*diameter,
-                                  ring*kS32 * diameter,
-                                  diameter);
-
-        for (int i=0; i<ring; i++)
-            (*this)[pixnum++].Set(-(ring+i)*0.5*diameter,
-                                  (ring-i)*kS32*diameter,
-                                  diameter);
-
-        for (int i=0; i<ring; i++)
-            (*this)[pixnum++].Set((0.5*i-ring)*diameter,
-                                  -i*kS32*diameter,
-                                  diameter);
-
-        for (int i=0; i<ring; i++)
-            (*this)[pixnum++].Set((i-ring*0.5)*diameter,
-                                  -ring*kS32 * diameter,
-                                  diameter);
-
-        for (int i=0; i<ring; i++)
-            (*this)[pixnum++].Set((ring+i)*0.5*diameter,
-                                  (-ring+i)*kS32*diameter,
-                                  diameter);
+            SetAt(pixnum++, MGeomPix((ring-i*0.5)*diameter,
+                                     i*kS32*diameter, diameter));
+
+        for (int i=0; i<ring; i++)
+            SetAt(pixnum++, MGeomPix((ring*0.5-i)*diameter,
+                                     ring*kS32 * diameter, diameter));
+
+        for (int i=0; i<ring; i++)
+            SetAt(pixnum++, MGeomPix(-(ring+i)*0.5*diameter,
+                                     (ring-i)*kS32*diameter, diameter));
+
+        for (int i=0; i<ring; i++)
+            SetAt(pixnum++, MGeomPix((0.5*i-ring)*diameter,
+                                     -i*kS32*diameter, diameter));
+
+        for (int i=0; i<ring; i++)
+            SetAt(pixnum++, MGeomPix((i-ring*0.5)*diameter,
+                                     -ring*kS32 * diameter, diameter));
+
+        for (int i=0; i<ring; i++)
+            SetAt(pixnum++, MGeomPix((ring+i)*0.5*diameter,
+                                     (-ring+i)*kS32*diameter, diameter));
     }
 }
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.cc	(revision 9369)
@@ -102,8 +102,5 @@
 TObject *MGeomCamDwarf::Clone(const char *newname) const
 {
-    MGeomCam *cam = new MGeomCam(GetNumPixels(), GetCameraDist());
-    for (UInt_t i=0; i<GetNumPixels(); i++)
-        (*this)[i].Copy((*cam)[i]);
-
+    MGeomCam *cam = new MGeomCam(*this);
     cam->InitGeometry();
     return cam;
@@ -256,5 +253,5 @@
     //  add the first pixel to the list
     //
-    (*this)[0].Set(0, 0, diameter);
+    SetAt(0, MGeomPix(0, 0, diameter));
 
     Int_t cnt  = 1;
@@ -268,5 +265,5 @@
                 Double_t x, y;
                 CalcXY(dir, ring, i, x, y);
-                (*this)[cnt++].Set(x*diameter, y*diameter, diameter);
+                SetAt(cnt++, MGeomPix(x*diameter, y*diameter, diameter));
             }
         }
@@ -285,5 +282,5 @@
     //  add the first pixel to the list
     //
-    (*this)[0].Set(0, 0, diameter);
+    SetAt(0, MGeomPix(0, 0, diameter));
 
     Int_t cnt  = 1;
@@ -300,5 +297,5 @@
                 Double_t x, y;
                 if (CalcXY(dir, ring, i, x, y)<rad)
-                    (*this)[cnt+n++].Set(x*diameter, y*diameter, diameter);
+                    SetAt(cnt+n++, MGeomPix(x*diameter, y*diameter, diameter));
             }
         }
@@ -323,5 +320,5 @@
     for (UInt_t i=0; i<GetNumPixels(); i++)
     {
-        MGeomPix &pix = (*this)[i];
+        MGeomPix &pix = static_cast<MGeomPix&>((*this)[i]);
 
         Int_t k = 0;
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.cc	(revision 9369)
@@ -361,5 +361,5 @@
     //
     for (UInt_t i=0; i<GetNumPixels(); i++)
-        (*this)[i].Set(xtemp[i], ytemp[i], i>396?60:30, sector[i], i>396?1:0);
+        SetAt(i, MGeomPix(xtemp[i], ytemp[i], i>396?60:30, sector[i], i>396?1:0));
     // (*this)[i].Set(xtemp[i], ytemp[i], i>396?60:30, i>396?sector[i]+6:sector[i]);
 }
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamSquare.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamSquare.cc	(revision 9369)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamSquare.cc	(revision 9369)
@@ -0,0 +1,108 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of CheObs, the Modular Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appears in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz,  1/2009 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: CheObs Software Development, 2000-2009
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MGeomCamSquare
+//
+// This class stores the geometry information of a camera with square
+// pixels
+//
+////////////////////////////////////////////////////////////////////////////
+#include "MGeomCamSquare.h"
+
+#include "MMath.h"
+
+#include "MGeomRectangle.h"
+
+ClassImp(MGeomCamSquare);
+
+// --------------------------------------------------------------------------
+//
+//  Square camera with 144 pixels in a distance of 4.96m with a
+// layout of 12x12
+//
+MGeomCamSquare::MGeomCamSquare(const char *name)
+    : MGeomCam(144, 4.96, name, "Geometry information of a square camera")
+{
+    CreateCam(12, 12, 7);
+    InitGeometry();
+}
+
+// --------------------------------------------------------------------------
+//
+//  For geometry and Next Neighbor info see
+//  CreateCam
+//
+MGeomCamSquare::MGeomCamSquare(UInt_t x, UInt_t y, Double_t diameter, Double_t dist, const char *name)
+    : MGeomCam(x*y, dist, name, "Geometry information of a square camera")
+{
+    CreateCam(x, y, diameter);
+    InitGeometry();
+}
+
+// --------------------------------------------------------------------------
+//
+// Check if the photon which is flying along the trajectory u has passed
+// (or will pass) the frame of the camera (and consequently get
+// absorbed). The position p and direction u must be in the
+// telescope coordinate frame, which is z parallel to the focal plane,
+// x to the right and y upwards, looking from the mirror towards the camera.
+//
+Bool_t MGeomCamSquare::HitFrame(MQuaternion p, const MQuaternion &u) const
+{
+    // z is defined from the mirror (0) to the camera (z>0).
+    // Thus we just propagate to the focal plane (z=fDist)
+    //p -= 1700./u.Z()*u;
+    p.PropagateZ(u, GetCameraDist()*100);
+
+    return TMath::Abs(p.X())*10<GetMaxRadius() && TMath::Abs(p.Y())*10<GetMaxRadius();
+}
+
+// --------------------------------------------------------------------------
+//
+//  This fills the geometry information from a table into the pixel objects.
+//
+void MGeomCamSquare::CreateCam(UInt_t nx, UInt_t ny, Double_t diameter)
+{
+    for (UInt_t x=0; x<nx; x++)
+        for (UInt_t y=0; y<ny; y++)
+        {
+            const UInt_t idx = x*ny+y;
+
+            SetAt(idx, MGeomRectangle((0.5*nx-x)*diameter, (0.5*ny-y)*diameter, diameter));
+
+            const Double_t n0 = x==nx-1 ? -1. : idx+ny;
+            const Double_t n1 = x==0    ? -1. : idx-ny;
+            const Double_t n2 = y==ny-1 ? -1. : idx+1;
+            const Double_t n3 = y==0    ? -1. : idx-1;
+
+            Double_t n[4] = { n0, n1, n2, n3 };
+
+            // Sort -1's to the end
+            MMath::ReSort(4, n, kTRUE);
+
+            (*this)[idx].SetNeighbors(n[0], n[1], n[2], n[3]);
+        }
+}
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamSquare.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamSquare.h	(revision 9369)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamSquare.h	(revision 9369)
@@ -0,0 +1,24 @@
+#ifndef MARS_MGeomCamSquare
+#define MARS_MGeomCamSquare
+
+#ifndef MARS_MGeomCam
+#include "MGeomCam.h"
+#endif
+
+class MGeomCamSquare : public MGeomCam
+{
+private:
+    void CreateCam(UInt_t x, UInt_t y, Double_t diameter);
+    void CreateNN();
+
+public:
+    MGeomCamSquare(UInt_t x, UInt_t y, Double_t diameter=7, Double_t dist=4.92, const char *name=NULL);
+    MGeomCamSquare(const char *name=NULL);
+
+    Bool_t HitFrame(MQuaternion p, const MQuaternion &u) const;
+
+    ClassDef(MGeomCamSquare, 1)	// Geometry class for a square pixel camera
+};
+
+#endif
+
Index: trunk/MagicSoft/Mars/mgeom/MGeomPix.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomPix.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mgeom/MGeomPix.cc	(revision 9369)
@@ -2,5 +2,5 @@
 !
 ! *
-! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * This file is part of CheObs, the Modular Analysis and Reconstruction
 ! * Software. It is distributed to you in the hope that it can be a useful
 ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
@@ -9,5 +9,5 @@
 ! * Permission to use, copy, modify and distribute this software and its
 ! * documentation for any purpose is hereby granted without fee,
-! * provided that the above copyright notice appear in all copies and
+! * provided that the above copyright notice appears in all copies and
 ! * that both that copyright notice and this permission notice appear
 ! * in supporting documentation. It is provided "as is" without express
@@ -17,7 +17,6 @@
 !
 !   Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
-!   Author(s): Harald Kornmayer 1/2001
-!
-!   Copyright: MAGIC Software Development, 2000-2008
+!
+!   Copyright: MAGIC Software Development, 2000-2009
 !
 !
@@ -48,6 +47,7 @@
 //  - added fUserBits
 //
-//
-// FIXME: According to an agreement we have to change the name 'Id' to 'idx'
+// Version 5:
+// ----------
+//  - now derives from MGeom to which some data members have been moved
 //
 ////////////////////////////////////////////////////////////////////////////
@@ -56,4 +56,5 @@
 #include <TMath.h>
 #include <TVector2.h>
+#include <TVirtualPad.h>
 
 #include "MLog.h"
@@ -61,11 +62,13 @@
 
 #include "MGeomCam.h"
+#include "MHexagon.h"
 
 ClassImp(MGeomPix);
 
-using namespace std;
-
-const Float_t MGeomPix::gsTan30 = TMath::Tan(30/kRad2Deg); // sqrt(3)/3
-const Float_t MGeomPix::gsTan60 = TMath::Tan(60/kRad2Deg); // sqrt(3)
+const Float_t MGeomPix::gsTan30 = TMath::Sqrt(3)/3;  //TMath::Tan(TMath::DegToRad()*30);
+const Float_t MGeomPix::gsTan60 = TMath::Sqrt(3);    //TMath::Tan(TMath::DegToRad()*60);
+
+const Float_t MGeomPix::gsCos60 = 0.5;               //TMath::Cos(TMath::DegToRad()*60);
+const Float_t MGeomPix::gsSin60 = TMath::Sqrt(3)/2;  //TMath::Sin(TMath::DegToRad()*60);
 
 // --------------------------------------------------------------------------
@@ -73,8 +76,7 @@
 // Initializes one pixel
 //
-MGeomPix::MGeomPix(Float_t x, Float_t y, Float_t r, UInt_t s, UInt_t a) : fUserBits(0)
-{
-    //  default constructor
-    Set(x, y, r, s, a);
+MGeomPix::MGeomPix(Float_t x, Float_t y, Float_t r, UInt_t s, UInt_t a) : MGeom(x, y, s, a)
+{
+    SetD(r);
     SetNeighbors();
 }
@@ -82,111 +84,35 @@
 // --------------------------------------------------------------------------
 //
-// Return position as TVector2(fX, fY)
-//
-TVector2 MGeomPix::GetP() const
-{
-    return TVector2(fX, fY);
-}
-
-// --------------------------------------------------------------------------
-//
-// Initializes Next Neighbors.
-//
-// WARNING: This function is public, but it is not meant for user access.
-// It should only be used from geometry classes (like MGeomCam)
-//
-void MGeomPix::SetNeighbors(Short_t i0, Short_t i1, Short_t i2,
-                            Short_t i3, Short_t i4, Short_t i5)
-{
-    fNeighbors[0] = i0;
-    fNeighbors[1] = i1;
-    fNeighbors[2] = i2;
-    fNeighbors[3] = i3;
-    fNeighbors[4] = i4;
-    fNeighbors[5] = i5;
-
-    int i;
-    for (i=0; i<6; i++)
-        if (fNeighbors[i]<0)
-            break;
-
-    fNumNeighbors = i;
-
-    fNumNeighbors<5 ? SETBIT(fUserBits, kIsInOutermostRing) : CLRBIT(fUserBits, kIsInOutermostRing);
-}
-
-// --------------------------------------------------------------------------
-//
-//  Set the kIsOuterRing flag if this pixel has a outermost pixel
-//  as Next Neighbor and don't have the kIsOutermostRing flag itself.
-//
-void MGeomPix::CheckOuterRing(const MGeomCam &cam)
-{
-    if (IsInOutermostRing())
-        return;
-
-    CLRBIT(fUserBits, kIsInOuterRing);
-
-    for (int i=0; i<fNumNeighbors; i++)
-        if (cam[fNeighbors[i]].IsInOutermostRing())
-        {
-            SETBIT(fUserBits, kIsInOuterRing);
-            return;
-        }
-}
-
-// --------------------------------------------------------------------------
-//
 // Print the geometry information of one pixel.
 //
 void MGeomPix::Print(Option_t *opt) const
-{ 
-    //   information about a pixel
-    *fLog << all << "MPixGeom:  x/y=" << fX << "/" << fY << "mm ";
-    *fLog << "d= " << fD << "mm  A= " << fA << "mm² (";
-    for (int i=0; i<fNumNeighbors; i++)
-        *fLog << fNeighbors[i] << (i<fNumNeighbors-1?",":"");
-    *fLog << ")" << endl;
-}
-
-// ------------------------------------------------------------------------
-//
-// Return distance of center to coordinate origin: hypot(fX,fY)
-//
-Float_t MGeomPix::GetDist() const
-{
-    return TMath::Hypot(fX, fY);
-}
-
-// ------------------------------------------------------------------------
-//
-// Return distance of center to center of pix: hypot(fX-pix.fX,fY-pix.fY)
-//
-Float_t MGeomPix::GetDist(const MGeomPix &pix) const
-{
-    return TMath::Hypot(fX-pix.fX, fY-pix.fY);
-}
-
-// ------------------------------------------------------------------------
-//
-// Return angle defined by the center and the center of pix:
-//  atan2(fX-pix.fX,fY-pix.fY)
-//
-Float_t MGeomPix::GetAngle(const MGeomPix &pix) const
-{
-    return TMath::ATan2(fX - pix.GetX(), fY - pix.GetY());
-}
-
-// ------------------------------------------------------------------------
-//
-// compute the distance of a point (px,py) to the Hexagon center in
-// MGeomPix coordinates. Return kTRUE if inside.
-//
-Bool_t MGeomPix::IsInside(Float_t px, Float_t py) const
-{
+{
+    MGeom::Print(opt);
+    gLog << " d=" << fD << "mm" << endl;
+}
+
+// ------------------------------------------------------------------------
+//
+// compute the distance of a point (px,py) to the Hexagon center in world
+// coordinates. Return -1 if inside.
+//
+Float_t MGeomPix::DistanceToPrimitive(Float_t px, Float_t py) const
+{
+    //FIXME: Rotation phi missing!
+
     //
     //  compute the distance of the Point to the center of the Hexagon
     //
-    const Double_t dx = px-fX;
+    //const Double_t dx = px-fX;
+    //const Double_t dy = py-fY;
+
+    TVector2 v(px-fX, py-fY);
+    // FIXME: fPhi or -fPhi?
+    // v = v.Rotate(-fPhi);             // FIXME: Replace with a precalculates sin/cos vector
+
+    const Double_t dx = v.X();
+    const Double_t dy = v.Y();
+
+    const Double_t disthex = TMath::Sqrt(dx*dx + dy*dy);
 
     //
@@ -196,45 +122,17 @@
     // more, rotated with respect to that one by +- 60 degrees.
     //
-    if (TMath::Abs(dx)>fD/2)
-        return kFALSE;
-
-    const Double_t dy = py-fY;
-
-    const static Double_t cos60 = TMath::Cos(60/kRad2Deg);
-    const static Double_t sin60 = TMath::Sin(60/kRad2Deg);
-
-    const Double_t dxc = dx*cos60;
-    const Double_t dys = dy*sin60;
-
-    if  (TMath::Abs(dxc + dys)>fD/2)
-        return kFALSE;
-
-    if (TMath::Abs(dxc - dys)>fD/2)
-        return kFALSE;
-
-    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;
-
-    cout << -1 << endl;
+
+    if (TMath::Abs(dx) > fD/2)
+      return disthex;
+
+    const Double_t dx2 = dx*gsCos60 + dy*gsSin60;
+
+    if  (TMath::Abs(dx2) > fD/2)
+      return disthex;
+
+    const Double_t dx3 = dx*gsCos60 - dy*gsSin60;
+
+    if  (TMath::Abs(dx3) > fD/2)
+      return disthex;
 
     return -1;
@@ -243,28 +141,28 @@
 // ------------------------------------------------------------------------
 //
-// compute the distance of a point (px,py) to the Hexagon center in world
-// coordinates. Return -1 if inside.
-//
-Float_t MGeomPix::DistanceToPrimitive(Float_t px, Float_t py) const
-{
-    //FIXME: Rotation phi missing!
-
-    static Double_t fgCos60 = 0.5;               //TMath::Cos(TMath::DegToRad()*60);
-    static Double_t fgSin60 = TMath::Sqrt(3.)/2; //TMath::Sin(TMath::DegToRad()*60);
-
+// Implementation of PaintPrimitive drwaing a hexagonal pixel
+//
+void MGeomPix::PaintPrimitive(const TAttLine &fill, const TAttFill &line, Double_t scalexy, Double_t scaled) const
+{
+    MHexagon hex;
+
+    fill.Copy(hex);
+    line.Copy(hex);
+
+    hex.PaintHexagon(fX*scalexy, fY*scalexy, fD*scaled);
+}
+
+
+// ------------------------------------------------------------------------
+//
+// compute the distance of a point (px,py) to the Hexagon center in
+// MGeomPix coordinates. Return kTRUE if inside.
+//
+Bool_t MGeomPix::IsInside(Float_t px, Float_t py) const
+{
     //
     //  compute the distance of the Point to the center of the Hexagon
     //
-    //const Double_t dx = px-fX;
-    //const Double_t dy = py-fY;
-
-    TVector2 v(px-fX, py-fY);
-    // FIXME: fPhi or -fPhi?
-    // v = v.Rotate(-fPhi);             // FIXME: Replace with a precalculates sin/cos vector
-
-    const Double_t dx = v.X();
-    const Double_t dy = v.Y();
-
-    const Double_t disthex = TMath::Sqrt(dx*dx + dy*dy);
+    const Double_t dx = px-fX;
 
     //
@@ -274,19 +172,22 @@
     // more, rotated with respect to that one by +- 60 degrees.
     //
-
-    if (TMath::Abs(dx) > fD/2.)
-      return disthex;
-
-    const Double_t dx2 = dx*fgCos60 + dy*fgSin60;
-
-    if  (TMath::Abs(dx2) > fD/2.)
-      return disthex;
-
-    const Double_t dx3 = dx*fgCos60 - dy*fgSin60;
-
-    if  (TMath::Abs(dx3) > fD/2.)
-      return disthex;
-
-    return -1;
+    if (TMath::Abs(dx)>fD/2)
+        return kFALSE;
+
+    const Double_t dy = py-fY;
+
+    const static Double_t cos60 = TMath::Cos(60/kRad2Deg);
+    const static Double_t sin60 = TMath::Sin(60/kRad2Deg);
+
+    const Double_t dxc = dx*cos60;
+    const Double_t dys = dy*sin60;
+
+    if  (TMath::Abs(dxc + dys)>fD/2)
+        return kFALSE;
+
+    if (TMath::Abs(dxc - dys)>fD/2)
+        return kFALSE;
+
+    return kTRUE;
 }
 
@@ -460,3 +361,2 @@
 }
 */
-
Index: trunk/MagicSoft/Mars/mgeom/MGeomPix.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomPix.h	(revision 9368)
+++ trunk/MagicSoft/Mars/mgeom/MGeomPix.h	(revision 9369)
@@ -2,14 +2,9 @@
 #define MARS_MGeomPix
 
-#ifndef MARS_MParContainer
-#include "MParContainer.h"
+#ifndef MARS_MGeom
+#include "MGeom.h"
 #endif
 
-class MGeomCam;
-class TVector2;
-class TOrdCollection;
-
-
-class MGeomPix : public MParContainer
+class MGeomPix : public MGeom
 { 
 public:
@@ -17,31 +12,9 @@
     static const Float_t gsTan30; // tan(30/kRad2Deg);
 
-    enum {
-        kRightTop,
-        kRight,
-        kRightBottom,
-        kLeftBottom,
-        kLeft,
-        kLeftTop
-    };
+    static const Float_t gsCos60; // cos(60/kRad2Deg);
+    static const Float_t gsSin60; // sin(30/kRad2Deg);
 
 private:
-    enum {
-        kIsInOutermostRing = 0,
-        kIsInOuterRing     = 1,
-    };
-
-    Float_t fX;            // [mm]   the x coordinate of the center
-    Float_t fY;            // [mm]   the y coordinate of the center
     Float_t fD;            // [mm]   the d coordinate of the pixel (dist between two parallel sides)
-    Float_t fA;            // [mm^2] Area of the pixel
-
-    Byte_t  fNumNeighbors; // number of valid neighbors
-    Short_t fNeighbors[6]; // the IDs of the pixel next to it (we are assuming an hexagonal geometry)
-
-    UInt_t fSector;        // Number of sector the pixels corresponds to
-    UInt_t fAidx;          // Area index of the pixel
-
-    Byte_t fUserBits;
 
 public:
@@ -51,59 +24,24 @@
     {
         MGeomPix &pix = (MGeomPix&)obj;
-        pix.fX = fX;
-        pix.fY = fY;
+
         pix.fD = fD;
-        pix.fA = fA;
-        pix.fNumNeighbors = fNumNeighbors;
-        pix.fSector = fSector;
-        pix.fAidx = fAidx;
-        pix.fUserBits = fUserBits;
-        for (int i=0; i<6; i++)
-            pix.fNeighbors[i] = fNeighbors[i];
 
+        MGeom::Copy(obj);
         TObject::Copy(obj);
     }
 
+    void SetD(Float_t d=1) { fD=d; fA=d*d*gsTan60/2; }
+
+    Float_t GetD() const  { return fD; }         // Distance between two parallel sides
+    Float_t GetL() const  { return fD*gsTan30; } // Length of one of the parallel sides
+    Float_t GetT() const  { return fD/gsTan60; } // Distance between two opposite edges (traverse)
+
+    Bool_t  IsInside(Float_t px, Float_t py) const;
+    Float_t DistanceToPrimitive(Float_t px, Float_t py) const;
+    void    PaintPrimitive(const TAttLine &line, const TAttFill &fill, Double_t scalexy=1, Double_t scaled=1) const;
+
     void Print(Option_t *opt=NULL) const;
 
-    void Set(Float_t x, Float_t y, Float_t d=1, UInt_t s=0, UInt_t aidx=0) { fX=x; fY=y; fD=d; fA=d*d*gsTan60/2; fSector=s; fAidx=aidx; }
-
-    void SetNeighbors(Short_t i0=-1, Short_t i1=-1, Short_t i2=-1,
-                      Short_t i3=-1, Short_t i4=-1, Short_t i5=-1);
-
-    void CheckOuterRing(const MGeomCam &cam);
-
-    Float_t GetX() const  { return fX; }
-    Float_t GetY() const  { return fY; }
-    Float_t GetD() const  { return fD; }         // Distance between two parellel sides
-    Float_t GetL() const  { return fD*gsTan30; } // Length of one of the parallel sides
-    Float_t GetT() const  { return fD/gsTan60; } // Distance between two opposite edges (traverse)
-    UInt_t  GetSector() const { return fSector; }
-
-    TVector2 GetP() const;
-
-    Float_t GetDist() const;
-    Float_t GetDist(const MGeomPix &pix) const;
-    Float_t GetAngle(const MGeomPix &pix) const;
-
-    Float_t GetA() const    { return fA; /*fD*fD*gsTan60/2;*/ }
-    Int_t   GetAidx() const { return fAidx; }
-
-    Byte_t  GetNumNeighbors() const { return fNumNeighbors; }
-    Short_t GetNeighbor(Byte_t i) const { return fNeighbors[i]; }
-
-    Bool_t IsInOutermostRing() const { return TESTBIT(fUserBits, kIsInOutermostRing); }
-    Bool_t IsInOuterRing() const     { return TESTBIT(fUserBits, kIsInOuterRing); }
-
-    Bool_t IsInside(Float_t px, Float_t py) const;
-    Int_t  GetDirection(const MGeomPix &pix) const;
-
-    virtual Float_t DistanceToPrimitive(Float_t px, Float_t py) const;
-    //void GetIntersectionBorder(TOrdCollection &col, const MGeomPix &hex) const;
-    //Double_t CalcOverlapArea(const MGeomPix &cam) const;
-
-    //TObject *GetGraphics() { return new MHexagon(*this); }
-
-    ClassDef(MGeomPix, 4) // Geometry class describing the geometry of one pixel
+    ClassDef(MGeomPix, 5) // Geometry class describing the geometry of one pixel
 };
 
Index: trunk/MagicSoft/Mars/mgeom/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mgeom/Makefile	(revision 9368)
+++ trunk/MagicSoft/Mars/mgeom/Makefile	(revision 9369)
@@ -19,11 +19,14 @@
 #  connect the include files defined in the config.mk file
 #
-INCLUDES = -I. -I../mbase -I../MBase
+INCLUDES = -I. -I../mbase -I../mgui -I../MBase
 
-SRCFILES = MGeomPix.cc \
+SRCFILES = MGeom.cc \
+           MGeomPix.cc \
+           MGeomRectangle.cc \
            MGeomCam.cc \
            MGeomCamCT1.cc \
            MGeomCamDwarf.cc \
            MGeomCamMagic.cc \
+           MGeomCamSquare.cc \
            MGeomCorsikaCT.cc \
 	   MGeomMirror.cc \
