Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9368)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9369)
@@ -46,4 +46,94 @@
      - moved getter and setter to source file to avoid including of
        TMath
+
+   * mgeom/MGeom.[h,cc]:
+     - added
+
+   * mgeom/MGeomRectangle.[h,cc]:
+     - added
+
+   * mgeom/MGeomCamSquare.[h,cc]:
+     - added
+
+   * mgeom/Makefile, mgeom/GeomLinkDef.h:
+     - added MGeom
+     - added MGeomRectangle
+     - added MGeomCamSquare
+
+   * Makefile.rules:
+     - removed dependance on ROOTSYS from rmkdepend. It should be in 
+       the path anyway as rootcint
+
+   * ceres.rc:
+     - added an example of setting the APD type
+
+   * mbadpixels/MBadPixelsCam.[h,cc], mbadpixels/MBadPixelsTreat.cc,
+     mcalib/MCalibrationChargeCalc.cc, mcalib/MCalibrationTestCalc.cc,
+     mfilter/MFSoftwareTrigger.cc:
+     - replaced references to MGeomPix by references to MGeom
+
+   * mbase/MStatusDisplay.cc:
+     - evaluate the return code of fwrite as suggested by newer 
+       gcc versions
+     - set a paranthesis as suggested by a warning 
+
+   * mgeom/MGeomCam.[h,cc]:
+     - adapted to the changes in MGeomPix/MGeom
+     - added SetAt function for external setup
+     - added Copy constructor
+
+   * mgeom/MGeomCamCT1.cc, mgeom/MGeomCamDwarf.cc, 
+     mgeom/MGeomCamMagic.cc, mhft/MHexagonFreqSpace.cc,
+     mimage/MHillas.cc, mimage/MHillasExt.cc,
+     mimage/MImgCleanStd.[h,cc], mimage/MNewImagePar.cc,
+     mimage/MNewImagePar2.cc, mmuon/MHSingleMuon.cc,
+     msignal/MSignalCam.cc, mtools/MagicJam.cc,
+     
+     - adapted to the changes in MGeomPix/MGeom
+     - use SetAt for setup
+
+   * mgeom/MGeomPix.cc:
+     - moved most of the code to new base class MGeom
+     - now derives from MGeom
+     - increased version number accordingly
+
+   * mhbase/MBinning.cc:
+     - replaced a Int_t by UInt_t as suggested by a warning
+
+   * mhbase/MH.cc:
+     - added a const_cast for GetObjectInfo (should be const,
+       but isn't)
+
+   * mhbase/MHMatrix.cc, mhflux/MHAlpha.cc, mhflux/MHThetaSq.cc,
+     mhflux/MHThetaSqN.cc, mhist/MHCamEventRot.cc, hvstime/MHVsTime.cc,
+     mjobs/MJStar.cc, mraw/MRawEvtHeader.cc:
+     - added paranthesis as suggested by a warning
+
+   * mhft/MGeomCamMagicXT.[h,cc]:
+     - replaced by deriving from MGeomCamDwarf
+
+   * mhist/MHCamera.cc:
+     - adapted to the changes in MGeomPix/MGeom
+     - use SetAt for setup
+     - use new PaintPrimitive to skip the usage of MHexagon
+
+   * mmc/MMcTrigHeader.hxx:
+     - fixed wrong condition in SetTrigger
+
+   * msimcamera/MSimAPD.[h,cc]:
+     - added a possibility to switch between the 50mu and 100mu
+       Diodes
+
+   * mtools/MagicCivilization.[h,cc], mtools/MagicDomino.[h,cc],
+     mtools/MagicReversi.[h,cc], mtools/MagicShow.[h,cc],
+     mtools/MagicSnake.[h,cc], mtools/MineSweeper.[h,cc],
+     - adapted to the changes in MGeomPix/MGeom, therefore restructered
+       the code to get rid of MHexagon
+
+   *  mmovie/MMovieWrite.cc:
+     - allow to switch off timing via preprocessor directive
+     - replaced MGeomPix by MGeom
+     - slightly changed palette
+     - evaluate return of fwrite
 
 
Index: trunk/MagicSoft/Mars/Makefile.rules
===================================================================
--- trunk/MagicSoft/Mars/Makefile.rules	(revision 9368)
+++ trunk/MagicSoft/Mars/Makefile.rules	(revision 9369)
@@ -104,5 +104,5 @@
 
 diff:
-	@cvs -d diff | grep -v "^? " > mars.diff
+	@cvs diff | grep -v "^? " > mars.diff
 
 zdiff:
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 9368)
+++ trunk/MagicSoft/Mars/NEWS	(revision 9369)
@@ -18,4 +18,6 @@
      leading date with the underscore is missing in the expected filename
 
+   * the geometry class now also supports other geometries than just hexagons
+
  ;automation
 
@@ -93,4 +95,7 @@
 
    * Now outputs MSrcPosCam for Monte Carlos in the Events tree.
+
+   * The definition of fConcCore has slightly changed. The numbers
+     might decrease a little bit (the effect should be rather small)
 
  ;ganymed
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc	(revision 9369)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MBadPixelsCam.cc,v 1.52 2007-06-24 16:31:57 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MBadPixelsCam.cc,v 1.53 2009-03-01 21:48:13 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -185,5 +185,5 @@
 // Calculate the number of pixels without the given type-flags.
 //
-// The second argument aidx is the area index (see MGeomCam, MGeomPix)
+// The second argument aidx is the area index (see MGeomCam, MGeom)
 // The default (or any value less than 0) means: all
 //
@@ -216,5 +216,5 @@
 // Calculate the number of pixels with the given type-flags.
 //
-// The second argument aidx is the area index (see MGeomCam, MGeomPix)
+// The second argument aidx is the area index (see MGeomCam, MGeom)
 // The default (or any value less than 0) means: all
 //
@@ -263,5 +263,5 @@
 // Counts the number of neighbors matching NOT UnsuitableType type
 //
-Short_t MBadPixelsCam::GetNumSuitableNeighbors(MBadPixelsPix::UnsuitableType_t type, const MGeomPix &pix) const
+Short_t MBadPixelsCam::GetNumSuitableNeighbors(MBadPixelsPix::UnsuitableType_t type, const MGeom &pix) const
 {
     const Int_t n2 = pix.GetNumNeighbors();
@@ -284,5 +284,5 @@
 // doesn't matter) has less than two reliable neighbor pixels.
 //
-// The second argument aidx is the area index (see MGeomCam, MGeomPix)
+// The second argument aidx is the area index (see MGeomCam, MGeom)
 // The default (or any value less than 0) means: all
 //
@@ -302,5 +302,5 @@
     for (int i=0; i<n; i++)
     {
-        const MGeomPix &pix = geom[i];
+        const MGeom &pix = geom[i];
         if (aidx>=0 && pix.GetAidx()!=aidx)
             continue;
@@ -320,5 +320,5 @@
 // the function is called for all its neighbors. If
 //
-// The second argument aidx is the area index (see MGeomCam, MGeomPix)
+// The second argument aidx is the area index (see MGeomCam, MGeom)
 // The default (or any value less than 0) means: all
 //
@@ -327,5 +327,5 @@
 Short_t MBadPixelsCam::GetNumMaxCluster(MBadPixelsPix::UnsuitableType_t type, TObjArray &list, Int_t idx, Int_t aidx) const
 {
-    const MGeomPix *pix = (MGeomPix*)list[idx];
+    const MGeom *pix = (MGeom*)list[idx];
     if (!pix)
         return 0;
@@ -358,5 +358,5 @@
 // type and the given area index.
 //
-// The second argument aidx is the area index (see MGeomCam, MGeomPix)
+// The second argument aidx is the area index (see MGeomCam, MGeom)
 // The default (or any value less than 0) means: all
 //
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.h
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.h	(revision 9368)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.h	(revision 9369)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-!  $Name: not supported by cvs2svn $:$Id: MBadPixelsCam.h,v 1.12 2007-12-14 09:56:01 tbretz Exp $
+!  $Name: not supported by cvs2svn $:$Id: MBadPixelsCam.h,v 1.13 2009-03-01 21:48:13 tbretz Exp $
 \* ======================================================================== */
 #ifndef MARS_MBadPixelsCam
@@ -15,5 +15,5 @@
 class TClonesArray;
 
-class MGeomPix;
+class MGeom;
 
 class MBadPixelsCam : public MParContainer, public MCamEvent
@@ -22,5 +22,5 @@
     TClonesArray *fArray; //-> 
 
-    Short_t GetNumSuitableNeighbors(MBadPixelsPix::UnsuitableType_t type, const MGeomPix &pix) const;
+    Short_t GetNumSuitableNeighbors(MBadPixelsPix::UnsuitableType_t type, const MGeom &pix) const;
     Short_t GetNumMaxCluster(MBadPixelsPix::UnsuitableType_t type, TObjArray &list, Int_t idx, Int_t aidx) const;
 
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc	(revision 9369)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MBadPixelsTreat.cc,v 1.41 2008-01-09 11:30:24 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MBadPixelsTreat.cc,v 1.42 2009-03-01 21:48:13 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -257,6 +257,6 @@
         // Get the corresponding geometry and pedestal
         //
-        MSignalPix     &pix  = (*fEvt)[i];
-        const MGeomPix &gpix = (*fGeomCam)[i];
+        MSignalPix  &pix  = (*fEvt)[i];
+        const MGeom &gpix = (*fGeomCam)[i];
 
         // Do Not-Use-Central-Pixel
@@ -346,5 +346,5 @@
         // Get the corresponding geometry and pedestal
         //
-        const MGeomPix    &gpix = (*fGeomCam)[i];
+        const MGeom       &gpix = (*fGeomCam)[i];
         const MPedPhotPix &ppix = pedphot[i];
 
@@ -442,5 +442,5 @@
 
         // Geometry of bad pixel
-        const MGeomPix &gpix = (*fGeomCam)[i];
+        const MGeom &gpix = (*fGeomCam)[i];
 
         // Number of neighbor pixels
Index: trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 9369)
@@ -1504,5 +1504,5 @@
     if (!p)
     {
-        *fLog << err << "ERROR - Couldn't open pipe " << pipe << endl;
+        *fLog << err << "ERROR - Couldn't open pipe " << pipe << ": " << strerror(errno) << endl;
         return kFALSE;
     }
@@ -1514,4 +1514,6 @@
     ULong_t i = 0;
     TGLongPosition pos;
+
+    Bool_t rc = kTRUE;
 
     pos.fX = pos.fY = 0;
@@ -1533,8 +1535,18 @@
             i++;
         }
-        fwrite(buf2, sizeof(char), strlen(buf2)+1, p);
-
+
+        const UInt_t len = sizeof(char)*(strlen(buf2)+1);
+
+        const size_t ret = fwrite(buf2, len, 1, p);
         delete [] buf1;
         delete [] buf2;
+
+        if (ret!=1)
+        {
+            *fLog << err << "ERROR - fwrite to pipe " << pipe << " failed: " << strerror(errno) << endl;
+            rc = kFALSE;
+            break;
+        }
+
         pos.fY++;
     }
@@ -2487,5 +2499,5 @@
 {
     if (gROOT->IsBatch())
-        return num>0 && num<=fBatch->GetSize() || num<0;
+        return (num>0 && num<=fBatch->GetSize()) || num<0;
 
     if (num>=fTab->GetNumberOfTabs())
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 9369)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MCalibrationChargeCalc.cc,v 1.185 2009-02-11 10:48:24 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MCalibrationChargeCalc.cc,v 1.186 2009-03-01 21:48:13 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -2050,5 +2050,5 @@
       
       MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[i];
-      MGeomPix &geo = (*fGeom)[i];
+      MGeom &geo = (*fGeom)[i];
 
       const Float_t qe        = pix.GetPheFFactorMethod() 
@@ -2126,5 +2126,5 @@
 
       MCalibrationChargePix &pix = (MCalibrationChargePix&)(*fCam)[i];
-      MGeomPix &geo = (*fGeom)[i];
+      MGeom &geo = (*fGeom)[i];
 
       const Float_t qe       =  pix.GetPheFFactorMethod()
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationTestCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationTestCalc.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationTestCalc.cc	(revision 9369)
@@ -577,5 +577,5 @@
 {
   
-  const MGeomPix &pix = (*fGeom)[idx];
+  const MGeom &pix = (*fGeom)[idx];
   const Byte_t neighbours = pix.GetNumNeighbors();
 
Index: trunk/MagicSoft/Mars/mfilter/MFSoftwareTrigger.cc
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFSoftwareTrigger.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mfilter/MFSoftwareTrigger.cc	(revision 9369)
@@ -137,5 +137,5 @@
 
     // Get the geometry information (neighbors) of this pixel
-    const MGeomPix &gpix = (*fCam)[idx];
+    const MGeom &gpix = (*fCam)[idx];
 
     // Now do the same with all its neighbors and sum the
@@ -342,5 +342,5 @@
         Int_t num = 1;
 
-        const MGeomPix &gpix = (*fCam)[i];
+        const MGeom &gpix = (*fCam)[i];
 
         const Int_t nneighbors = gpix.GetNumNeighbors();
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 \
Index: trunk/MagicSoft/Mars/mhbase/MBinning.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MBinning.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mhbase/MBinning.cc	(revision 9369)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MBinning.cc,v 1.19 2008-06-02 08:46:47 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MBinning.cc,v 1.20 2009-03-01 21:48:14 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -193,5 +193,5 @@
 void MBinning::AddEdge(Axis_t up)
 {
-    const Int_t n = fEdges.GetSize();
+    const UInt_t n = fEdges.GetSize();
 
     if (up<=fEdges[n-1])
Index: trunk/MagicSoft/Mars/mhbase/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 9369)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.46 2009-02-22 23:36:00 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.47 2009-03-01 21:48:14 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -1845,5 +1845,5 @@
         return GetObjectInfoH(px, py, static_cast<const TH1&>(o));
 
-    return "MH::GetObjectInfo: unknown class.";
+    return const_cast<char*>("MH::GetObjectInfo: unknown class.");
 }
 
Index: trunk/MagicSoft/Mars/mhbase/MHMatrix.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MHMatrix.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mhbase/MHMatrix.cc	(revision 9369)
@@ -1177,4 +1177,5 @@
 
         if (i==0)
+        {
             if (fData)
             {
@@ -1187,4 +1188,5 @@
                 SetBit(kIsOwner);
             }
+        }
 
         fData->AddEntry(name);
Index: trunk/MagicSoft/Mars/mhflux/MHAlpha.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHAlpha.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mhflux/MHAlpha.cc	(revision 9369)
@@ -778,5 +778,5 @@
         delete pad->GetPad(2);
 
-    if (fTimeEffOn && fTime || fHTime.GetNbinsX()>1 || fHTime.GetBinError(1)>0)
+    if ((fTimeEffOn && fTime) || fHTime.GetNbinsX()>1 || fHTime.GetBinError(1)>0)
     {
         pad->cd(3);
@@ -1097,14 +1097,8 @@
 
     if (!fSkipHistEnergy)
-        if (type==0)
-        {
-            fMap[1] = fMatrix->AddColumn("MEnergyEst.fVal");
-            fMap[2] = -1;
-        }
-        else
-        {
-            fMap[1] = -1;
-            fMap[2] = fMatrix->AddColumn("MHillas.fSize");
-        }
+    {
+        fMap[1] = type==0 ? fMatrix->AddColumn("MEnergyEst.fVal") : -1;
+        fMap[2] = type==0 ? -1 : fMatrix->AddColumn("MHillas.fSize");
+    }
 
     if (!fSkipHistTheta)
Index: trunk/MagicSoft/Mars/mhflux/MHThetaSq.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHThetaSq.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mhflux/MHThetaSq.cc	(revision 9369)
@@ -189,14 +189,8 @@
 
     if (!fSkipHistEnergy)
-        if (type==0)
-        {
-            fMap[1] = fMatrix->AddColumn("MEnergyEst.fVal");
-            fMap[2] = -1;
-        }
-        else
-        {
-            fMap[1] = -1;
-            fMap[2] = fMatrix->AddColumn("MHillas.fSize");
-        }
+    {
+        fMap[1] = type==0 ? fMatrix->AddColumn("MEnergyEst.fVal") : -1;
+        fMap[2] = type==0 ? -1 : fMatrix->AddColumn("MHillas.fSize");
+    }
 
     if (!fSkipHistTheta)
Index: trunk/MagicSoft/Mars/mhflux/MHThetaSqN.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHThetaSqN.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mhflux/MHThetaSqN.cc	(revision 9369)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MHThetaSqN.cc,v 1.11 2009-02-15 15:43:30 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MHThetaSqN.cc,v 1.12 2009-03-01 21:48:14 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -354,14 +354,8 @@
 
     if (!fSkipHistEnergy)
-        if (type==0)
-        {
-            fMap[1] = fMatrix->AddColumn("MEnergyEst.fVal");
-            fMap[2] = -1;
-        }
-        else
-        {
-            fMap[1] = -1;
-            fMap[2] = fMatrix->AddColumn("MHillas.fSize");
-        }
+    {
+        fMap[1] = type==0 ? fMatrix->AddColumn("MEnergyEst.fVal") : -1;
+        fMap[2] = type==0 ? -1 : fMatrix->AddColumn("MHillas.fSize");
+    }
 
     if (!fSkipHistTheta)
Index: trunk/MagicSoft/Mars/mhft/MGeomCamMagicXT.cc
===================================================================
--- trunk/MagicSoft/Mars/mhft/MGeomCamMagicXT.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mhft/MGeomCamMagicXT.cc	(revision 9369)
@@ -36,8 +36,4 @@
 #include "MGeomCamMagicXT.h"
 
-#include <TMath.h>
-
-#include "MGeomPix.h"
-
 ClassImp(MGeomCamMagicXT);
 
@@ -48,137 +44,5 @@
 //
 MGeomCamMagicXT::MGeomCamMagicXT(const char *name)
-    : MGeomCam(1141, 17, name, "Geometry information of Magic Camera")
+    : MGeomCamDwarf(19, 30, 17, name)
 {
-    CreateCam();
-    CreateNN();
-    InitGeometry();
 }
-
-// --------------------------------------------------------------------------
-//
-//  This fills the geometry information from a table into the pixel objects.
-//
-void MGeomCamMagicXT::CreateCam()
-{
-    //
-    // fill the geometry class with the coordinates of the CT1 camera
-    //
-    //*fLog << inf << " Create CT1 geometry " << endl;
-
-    //
-    // this algorithm is from Martin Kestel originally
-    // it was punt into a root/C++ context by Harald Kornmayer and Thomas Bretz
-   
-    const Float_t diameter = 30;    // units are mm
-    const Float_t kS32  = sqrt(3)/2;
-
-    //
-    //  add the first pixel to the list
-    //
-    Int_t pixnum = 0;
-
-    (*this)[pixnum++].Set(0, 0, diameter);
-
-    for (Int_t ring=1; ring<20; ring++)
-    {
-        //
-        // calc. coords for this ring counting from the
-        // starting number to the ending number
-        //
-        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);
-    }
-}
-
-// --------------------------------------------------------------------------
-//
-//  This fills the next neighbor information from a table into the pixel
-//  objects.
-//
-void MGeomCamMagicXT::CreateNN()
-{
-    Int_t pos = 0;
-
-    const Short_t nn[7][6] = {         // Neighbors of #
-        {   1,   2,   3,   4,   5,   6}, // 0
-        {   0,   2,   6,   7,   8,  18},
-        {   0,   1,   3,   8,   9,  10},
-        {   0,   2,   4,  10,  11,  12},
-        {   0,   3,   5,  12,  13,  14},
-        {   0,   4,   6,  14,  15,  16},
-        {   0,   1,   5,  16,  17,  18}
-    };
-
-    for (Int_t i=0; i<7; i++)
-        (*this)[pos++].SetNeighbors(nn[i][0], nn[i][1], nn[i][2],
-                                    nn[i][3], nn[i][4], nn[i][5]);
-
-    for (Int_t ring=2; ring<20; ring++)
-    {
-        for (Int_t s=0; s<6; s++)
-        {
-            for (int i=pos; i<ring+pos; i++)
-            {
-                Int_t n[6], idx[6];
-
-                n[0] = i==pos&&s==0 ? i+6*ring : i-1;                // vor
-                n[1] = i==ring+pos-1&&s==5 ? i-12*(ring-1)-5 : i+1;  // danach
-                n[2] = i==pos ? i+6*ring-1+s   : i-6*(ring-1)-s;     // ring- groesser
-                n[3] = i==pos ? i-6*(ring-1)-s : i-6*(ring-1)-1-s;   // ring- kleiner
-                n[4] = i==pos&&s==0 ? i+12*ring+5 : i+6*ring+s;      // ring+ kleiner
-                n[5] = i+6*ring+1+s;                                 // ring+ groesser
-
-                if (n[0]>1140)
-                    n[0] = -1;
-                if (n[1]>1140)
-                    n[1] = -1;
-                if (n[2]>1140)
-                    n[2] = -1;
-                if (n[3]>1140)
-                    n[3] = -1;
-                if (n[4]>1140)
-                    n[4] = -1;
-                if (n[5]>1140)
-                    n[5] = -1;
-
-                TMath::Sort(6, n, idx);
-
-                (*this)[i].SetNeighbors(n[idx[0]],
-                                        n[idx[1]],
-                                        n[idx[2]],
-                                        n[idx[3]],
-                                        n[idx[4]],
-                                        n[idx[5]]);
-            }
-
-            pos += ring;
-        }
-    }
-}
Index: trunk/MagicSoft/Mars/mhft/MGeomCamMagicXT.h
===================================================================
--- trunk/MagicSoft/Mars/mhft/MGeomCamMagicXT.h	(revision 9368)
+++ trunk/MagicSoft/Mars/mhft/MGeomCamMagicXT.h	(revision 9369)
@@ -2,14 +2,10 @@
 #define MARS_MGeomCamMagicXT
 
-#ifndef MARS_MGeomCam
-#include "MGeomCam.h"
+#ifndef MARS_MGeomCamDwarf
+#include "MGeomCamDwarf.h"
 #endif
 
-class MGeomCamMagicXT : public MGeomCam
+class MGeomCamMagicXT : public MGeomCamDwarf
 {
-private:
-    void CreateCam();
-    void CreateNN();
-
 public:
     MGeomCamMagicXT(const char *name=NULL);
Index: trunk/MagicSoft/Mars/mhft/MHexagonFreqSpace.cc
===================================================================
--- trunk/MagicSoft/Mars/mhft/MHexagonFreqSpace.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mhft/MHexagonFreqSpace.cc	(revision 9369)
@@ -169,6 +169,6 @@
             int idx1 = (j+n)*(j+n+1)/2 + j;
 
-            (*cam)[idx1].Set(n-j, (n+j-num/2)*fgTan30, 2);
-            (*cam)[idx1].SetNeighbors(-1, -1, -1, -1, -1, -1);
+            cam->SetAt(idx1, MGeomPix(n-j, (n+j-num/2)*fgTan30, 2));
+            (*cam)[idx1].SetNeighbors();
         }
     }
Index: trunk/MagicSoft/Mars/mhist/MHCamEventRot.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamEventRot.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mhist/MHCamEventRot.cc	(revision 9369)
@@ -226,6 +226,6 @@
             if (fUseThreshold!=kNoBound)
             {
-                if (val>fThreshold && fUseThreshold==kIsLowerBound ||
-                    val<fThreshold && fUseThreshold==kIsUpperBound)
+                if ((val>fThreshold && fUseThreshold==kIsLowerBound) ||
+                    (val<fThreshold && fUseThreshold==kIsUpperBound))
                     fHist.Fill(cx[ix], cy[iy]);
             }
Index: trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 9369)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.118 2009-03-01 12:51:03 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.119 2009-03-01 21:48:14 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -79,5 +79,4 @@
 #include "MString.h"
 #include "MBinning.h"
-#include "MHexagon.h"
 
 #include "MGeomPix.h"
@@ -109,7 +108,7 @@
     gROOT->GetListOfCleanups()->Add(fNotify);
 
+    /*
     TVirtualPad *save = gPad;
     gPad = 0;
-    /*
 #if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
     SetPalette(1, 0);
@@ -123,6 +122,6 @@
     SetInvDeepBlueSeaPalette();
 #endif
+    gPad = save;
 */
-    gPad = save;
 }
 
@@ -218,5 +217,5 @@
 Bool_t MHCamera::MatchSector(Int_t idx, const TArrayI &sector, const TArrayI &aidx) const
 {
-    const MGeomPix &pix = (*fGeomCam)[idx];
+    const MGeom &pix = (*fGeomCam)[idx];
     return FindVal(sector, pix.GetSector()) && FindVal(aidx, pix.GetAidx());
 }
@@ -980,8 +979,11 @@
         gPad->GetX2()> maxr || gPad->GetY2()>maxr ? 1 : fGeomCam->GetConvMm2Deg();
 
-    MHexagon hex;
+    TAttLine line;
+    TAttFill fill;
+    line.SetLineStyle(kSolid);
+    line.SetLineColor(kBlack);
     for (Int_t i=0; i<fNcells-2; i++)
     {
-        hex.SetFillStyle(issame || (IsTransparent() && !IsUsed(i)) ? 0 : 1001);
+        fill.SetFillStyle(issame || (IsTransparent() && !IsUsed(i)) ? 0 : 1001);
 
         if (!issame)
@@ -990,5 +992,5 @@
             if (!IsUsed(i) || !iscol || isnan)
             {
-                hex.SetFillColor(10);
+                fill.SetFillColor(10);
 
                 if (isnan)
@@ -996,24 +998,25 @@
             }
             else
-                hex.SetFillColor(GetColor(GetBinContent(i+1), min, max, islog));
+                fill.SetFillColor(GetColor(GetBinContent(i+1), min, max, islog));
         }
 
-        const MGeomPix &pix = (*fGeomCam)[i];
-
-        Float_t x = pix.GetX()*conv/(fAbberation+1);
-        Float_t y = pix.GetY()*conv/(fAbberation+1);
-        Float_t d = pix.GetD()*conv;
-
-        if (!isbox)
-            if (IsUsed(i) || !TestBit(kNoUnused))
-                hex.PaintHexagon(x, y, d);
-        else
-            if (IsUsed(i) && TMath::Finite(fArray[i+1]))
-            {
-                Float_t size = d*(GetBinContent(i+1)-min)/(max-min);
-                if (size>d)
-                    size=d;
-                hex.PaintHexagon(x, y, size);
-            }
+        const MGeom &pix = (*fGeomCam)[i];
+
+        Double_t scale = 1;//conv/(fAbberation+1);
+
+        if (!isbox && !IsUsed(i) && TestBit(kNoUnused))
+            continue;
+
+        if (isbox && (!IsUsed(i) || !TMath::Finite(fArray[i+1])))
+            continue;
+
+        if (isbox)
+        {
+            scale = (GetBinContent(i+1)-min)/(max-min);
+            if (scale>1)
+                scale=1;
+        }
+
+        pix.PaintPrimitive(line, fill, conv, scale/(fAbberation+1));
     }
 }
@@ -1319,5 +1322,5 @@
     for (Int_t i=0; i<fNcells-2; i++)
     {
-        const MGeomPix &h = (*fGeomCam)[i];
+        const MGeom &h = (*fGeomCam)[i];
 
         TString num;
@@ -1335,5 +1338,5 @@
         //(GetColor(GetBinContent(i+1), min, max, 0));
         txt.SetTextColor(kRed);
-        txt.SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius()/1.05);
+        txt.SetTextSize(0.3*h.GetT()/fGeomCam->GetMaxRadius()/1.05);
         txt.PaintText(h.GetX(), h.GetY(), num);
     }
@@ -2024,13 +2027,8 @@
         return -1;
 
-    Int_t i;
-    for (i=0; i<fNcells-2; i++)
-    {
-        MHexagon hex((*fGeomCam)[i]);
-        if (hex.DistancetoPrimitive(px, py, conv)>0)
-            continue;
-
-        return i;
-    }
+    for (Int_t i=0; i<fNcells-2; i++)
+        if ((*fGeomCam)[i].DistancetoPrimitive(px*conv, py*conv)<=0)
+            return i;
+
     return -1;
 }
Index: trunk/MagicSoft/Mars/mhvstime/MHVsTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mhvstime/MHVsTime.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mhvstime/MHVsTime.cc	(revision 9369)
@@ -245,5 +245,5 @@
     if (fN==fNumEvents)
     {
-        if (fMaxPts>0 && fGraph->GetN()>fMaxPts || fGraph->IsEditable())
+        if ((fMaxPts>0 && fGraph->GetN()>fMaxPts) || fGraph->IsEditable())
         {
             fGraph->RemovePoint(0);
Index: trunk/MagicSoft/Mars/mimage/MHillas.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHillas.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mimage/MHillas.cc	(revision 9369)
@@ -291,5 +291,5 @@
             continue;
 
-        const MGeomPix &gpix = geom[i];
+        const MGeom &gpix = geom[i];
 
         const Float_t nphot = pix.GetNumPhotons();
@@ -339,5 +339,5 @@
             continue;
 
-        const MGeomPix &gpix = geom[i];
+        const MGeom &gpix = geom[i];
 
         const Float_t dx = gpix.GetX() - fMeanX;     // [mm]
Index: trunk/MagicSoft/Mars/mimage/MHillasExt.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHillasExt.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mimage/MHillasExt.cc	(revision 9369)
@@ -161,5 +161,5 @@
             continue;
 
-        const MGeomPix &gpix = geom[i];
+        const MGeom &gpix = geom[i];
 
         const Double_t x = gpix.GetX();
@@ -238,5 +238,5 @@
     // Asymmetry
     //
-    const MGeomPix &maxp = geom[maxpixid];
+    const MGeom &maxp = geom[maxpixid];
     fAsym = (hil.GetMeanX()-maxp.GetX())*c + (hil.GetMeanY()-maxp.GetY())*s;            // [mm]
 
Index: trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 9369)
@@ -395,5 +395,5 @@
 //
 //
-Bool_t MImgCleanStd::HasCoreNeighbors(const MGeomPix &gpix) const
+Bool_t MImgCleanStd::HasCoreNeighbors(const MGeom &gpix) const
 {
 //    if (fKeepIsolatedPixels)
@@ -428,5 +428,5 @@
 }
 
-Bool_t MImgCleanStd::HasUsedNeighbors(const MGeomPix &gpix) const
+Bool_t MImgCleanStd::HasUsedNeighbors(const MGeom &gpix) const
 {
     //loop on the neighbors to check if they are used
@@ -448,5 +448,5 @@
 
 
-void MImgCleanStd::SetUsedNeighbors(const MGeomPix &gpix, Int_t r) const
+void MImgCleanStd::SetUsedNeighbors(const MGeom &gpix, Int_t r) const
 {
     if (r>fCleanRings)
@@ -527,5 +527,5 @@
             continue;
 
-        const MGeomPix &gpix = (*fCam)[idx];
+        const MGeom &gpix = (*fCam)[idx];
 
         // Check if the pixel is an isolated core pixel
@@ -556,5 +556,5 @@
 
 /*
-Float_t MImgCleanStd::GetArrivalTimeNeighbor(const MGeomPix &gpix) const
+Float_t MImgCleanStd::GetArrivalTimeNeighbor(const MGeom &gpix) const
 {
     Float_t min = FLT_MAX;
@@ -595,5 +595,5 @@
             continue;
 
-        const MGeomPix &gpix = (*fCam)[idx];
+        const MGeom &gpix = (*fCam)[idx];
 
         // If isolated possible-corepixel doesn't have used
@@ -638,5 +638,5 @@
             continue;
 
-        const MGeomPix &gpix = (*fCam)[idx];
+        const MGeom &gpix = (*fCam)[idx];
 
         // If isolated possible-corepixel doesn't have used
@@ -676,5 +676,5 @@
 
         // loop over its neighbpors
-        const MGeomPix &gpix = (*fCam)[idx];
+        const MGeom &gpix = (*fCam)[idx];
 
         Int_t cnt = 0;
Index: trunk/MagicSoft/Mars/mimage/MImgCleanStd.h
===================================================================
--- trunk/MagicSoft/Mars/mimage/MImgCleanStd.h	(revision 9368)
+++ trunk/MagicSoft/Mars/mimage/MImgCleanStd.h	(revision 9369)
@@ -7,5 +7,5 @@
 
 class MGeomCam;
-class MGeomPix;
+class MGeom;
 class MSignalCam;
 class MPedPhotCam;
@@ -58,7 +58,7 @@
 
     // MImgCleanStd
-    Bool_t HasCoreNeighbors(const MGeomPix &gpix) const;
-    Bool_t HasUsedNeighbors(const MGeomPix &gpix) const;
-    void   SetUsedNeighbors(const MGeomPix &gpix, Int_t r=1) const;
+    Bool_t HasCoreNeighbors(const MGeom &gpix) const;
+    Bool_t HasUsedNeighbors(const MGeom &gpix) const;
+    void   SetUsedNeighbors(const MGeom &gpix, Int_t r=1) const;
     Int_t  DoCleaning(Float_t &size) const;
     void   ResetCleaning() const;
Index: trunk/MagicSoft/Mars/mimage/MNewImagePar.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MNewImagePar.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mimage/MNewImagePar.cc	(revision 9369)
@@ -160,5 +160,5 @@
 
         // Get geometry of pixel
-        const MGeomPix &gpix = geom[i];
+        const MGeom &gpix = geom[i];
 
         // Find the three pixels which are next to the COG
@@ -220,5 +220,5 @@
         const Double_t dzx   =  hillas.GetCosDelta()*dx + hillas.GetSinDelta()*dy; // [mm]
         const Double_t dzy   = -hillas.GetSinDelta()*dx + hillas.GetCosDelta()*dy; // [mm]
-        const Double_t dz    =  gpix.GetD()*gpix.GetD()/4;
+        const Double_t dz    =  gpix.GetT()*gpix.GetT()/4;
         const Double_t tana  =  dzy*dzy/(dzx*dzx);
         const Double_t distr =  (1+tana)/(rl + tana*rw);
Index: trunk/MagicSoft/Mars/mimage/MNewImagePar2.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MNewImagePar2.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mimage/MNewImagePar2.cc	(revision 9369)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MNewImagePar2.cc,v 1.2 2006-10-17 17:16:00 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MNewImagePar2.cc,v 1.3 2009-03-01 21:48:14 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -91,5 +91,5 @@
         Int_t used=0;
 
-        const MGeomPix &gpix = geom[i];
+        const MGeom &gpix = geom[i];
         const Int_t nn = gpix.GetNumNeighbors();
         for (int j=0; j<nn; j++)
@@ -108,5 +108,6 @@
             evt[i].ResetBit(BIT(14));
 
-        fBorderLinePixel += (nn-used)*gpix.GetL();
+        // FIXME: GetT is not the correct value
+        fBorderLinePixel += (nn-used)*gpix.GetT();
     }
 
@@ -115,5 +116,5 @@
         const Int_t l = idx[m];
 
-        const MGeomPix &gpix = geom[l];
+        const MGeom &gpix = geom[l];
 
         const Int_t nn = gpix.GetNumNeighbors();
Index: trunk/MagicSoft/Mars/mjobs/MJStar.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJStar.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mjobs/MJStar.cc	(revision 9369)
@@ -373,8 +373,10 @@
 
     if (fSequence.IsMonteCarlo())
+    {
         if (fMuonAnalysis)
             writem.AddCopySource("OriginalMC");
         else
             write.AddCopySource("OriginalMC");
+    }
 
     MTaskList tlist2("Events");
Index: trunk/MagicSoft/Mars/mmovie/MMovieWrite.cc
===================================================================
--- trunk/MagicSoft/Mars/mmovie/MMovieWrite.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mmovie/MMovieWrite.cc	(revision 9369)
@@ -290,5 +290,7 @@
 }
 
+#ifdef USE_TIMING
 TStopwatch clockT, clock1, clock2, clock3;
+#endif
 
 // --------------------------------------------------------------------------
@@ -304,4 +306,5 @@
     }
 
+#ifdef USE_TIMING
     *fLog << all << endl;
     *fLog << "Snap: " << flush;
@@ -314,4 +317,5 @@
     clockT.Print();
     *fLog << endl;
+#endif
 
     return kTRUE;
@@ -338,6 +342,6 @@
 
     double r[6] = {1.0, 1.0,  1.0, 0.85,  0.1,     0.0 };
-    double g[6] = {1.0, 1.0,  1.0, 0.0,   0.1,     0.0 };
-    double b[6] = {0.9, 0.55, 0.4, 0.0,   0.7,     0.1 };
+    double g[6] = {1.0, 1.0,  1.0, 0.15,  0.1,     0.0 };
+    double b[6] = {0.9, 0.55, 0.4, 0.15,  0.7,     0.1 };
 
     TArrayI col(99);
@@ -481,5 +485,6 @@
     UInt_t *argb = img.GetArgbArray();
     for (UInt_t *ptr=argb; ptr<argb+img.GetWidth()*img.GetHeight(); ptr++)
-        fwrite(ptr, 1, 3, fPipe);
+        if (fwrite(ptr, 3, 1, fPipe)!=1)
+            break;
 
     return CheckPipe();
@@ -493,4 +498,5 @@
 Bool_t MMovieWrite::WriteImage(TASImage &img, TVirtualPad &pad)
 {
+#ifdef USE_TIMING
     clock1.Start(kFALSE);
     UpdateImage(img, pad);
@@ -502,4 +508,8 @@
 
     return rc;
+#else
+    UpdateImage(img, pad);
+    return WriteImage(img);
+#endif
 }
 
@@ -524,5 +534,5 @@
             continue;
 
-        const MGeomPix &gpix = (*fCam)[i];
+        const MGeom &gpix = (*fCam)[i];
 
         Int_t    num = 0;
@@ -572,5 +582,5 @@
             continue;
 
-        const MGeomPix &gpix = (*fCam)[i];
+        const MGeom &gpix = (*fCam)[i];
 
         //
@@ -671,8 +681,9 @@
 Int_t MMovieWrite::Process()
 {
+#ifdef USE_TIMING
     clockT.Start(kFALSE);
 
     clock3.Start(kFALSE);
-
+#endif
     // ---------------- Prepare display ------------------
 
@@ -802,5 +813,5 @@
     // ---------------- Show data ------------------
     gStyle->SetOptStat(1000000001);
-/*                     
+/*
     p0.Modified();
     p1.Modified();
@@ -815,6 +826,7 @@
 
     // ---------------- Show data ------------------
-
+#ifdef USE_TIMING
     clock3.Stop();
+#endif
 
     // Switch off automatical adding to directory (SetName would do)
@@ -827,5 +839,7 @@
     TH1::AddDirectory(add);
 
+#ifdef USE_TIMING
     clockT.Stop();
+#endif
 
     gROOT->SetBatch(batch);
Index: trunk/MagicSoft/Mars/mmuon/MHSingleMuon.cc
===================================================================
--- trunk/MagicSoft/Mars/mmuon/MHSingleMuon.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mmuon/MHSingleMuon.cc	(revision 9369)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MHSingleMuon.cc,v 1.18 2008-11-11 11:46:25 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MHSingleMuon.cc,v 1.19 2009-03-01 21:48:14 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -215,5 +215,5 @@
     {
         const MSignalPix &pix  = (*fSignalCam)[i];
-        const MGeomPix   &gpix = (*fGeomCam)[i];
+        const MGeom      &gpix = (*fGeomCam)[i];
 
         const Float_t dx = gpix.GetX() - cenx;
@@ -266,5 +266,5 @@
     {
         const MSignalPix &pix  = (*fSignalCam)[i];
-        const MGeomPix   &gpix = (*fGeomCam)[i];
+        const MGeom      &gpix = (*fGeomCam)[i];
 
         const Float_t dx = gpix.GetX() - cenx;
@@ -403,8 +403,10 @@
     const Int_t m = fHistWidth.GetMaximumBin();
     if (first>last)
+    {
         if (m>n)       // If maximum is on the right side of histogram
             last = n;
         else
             first = 0; // If maximum is on the left side of histogram
+    }
 
     if (last-first<=3)
Index: trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc	(revision 9369)
@@ -282,9 +282,9 @@
 
     abstime[0] =
-        abstime[0]>>7 & 0x00010000 |
-        abstime[0]>>5 & 0x00020000 |
-        abstime[0]>>3 & 0x00040000 |
-        abstime[0]>>1 & 0x00080000 |
-        abstime[0]    & 0xff00ffff;
+        (abstime[0]>>7 & 0x00010000) |
+        (abstime[0]>>5 & 0x00020000) |
+        (abstime[0]>>3 & 0x00040000) |
+        (abstime[0]>>1 & 0x00080000) |
+        (abstime[0]    & 0xff00ffff);
 
     // 
Index: trunk/MagicSoft/Mars/msignal/MSignalCam.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MSignalCam.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/msignal/MSignalCam.cc	(revision 9369)
@@ -374,5 +374,5 @@
 
     // Get the geometry information (neighbors) of this pixel
-    const MGeomPix &gpix = geom[idx];
+    const MGeom &gpix = geom[idx];
 
     // Get the size of this pixel
Index: trunk/MagicSoft/Mars/msimcamera/MSimAPD.cc
===================================================================
--- trunk/MagicSoft/Mars/msimcamera/MSimAPD.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/msimcamera/MSimAPD.cc	(revision 9369)
@@ -77,5 +77,5 @@
 //
 MSimAPD::MSimAPD(const char* name, const char *title)
-: fGeom(0), fEvt(0), fStat(0)
+: fGeom(0), fEvt(0), fStat(0), fType(1)
 {
     fName  = name  ? name  : "MSimAPD";
@@ -131,18 +131,42 @@
 Bool_t MSimAPD::ReInit(MParList *plist)
 {
-    if (UInt_t(fAPDs.GetEntriesFast())!=fGeom->GetNumPixels())
-    {
-        fAPDs.Delete();
-
-        // FIXME:
-        //   * initialize an empty APD and read the APD setup from a file to
-        //     allow different APDs.
-        //   * Make the arguments a data member of MSimAPD
-
-        for (UInt_t i=0; i<fGeom->GetNumPixels(); i++)
-            //fAPDs.Add(new APD(60, 0.2, 3, 8.75));
-            //fAPDs.Add(new APD(60/2, 0.2, 3e-9, 8.75e-9*4));
-            fAPDs.Add(new APD(60/2, 0.2, 3, 8.75*4));
-    }
+    if (UInt_t(fAPDs.GetEntriesFast())==fGeom->GetNumPixels())
+        return kTRUE;
+
+    fAPDs.Delete();
+
+    // FIXME:
+    //   * initialize an empty APD and read the APD setup from a file to
+    //     allow different APDs.
+    //   * Make the arguments a data member of MSimAPD
+
+    Int_t   ncells    = 0;
+    Float_t crosstalk = 0;
+    Float_t deadtime  = 0;
+    Float_t recovery  = 0;
+
+    switch (fType)
+    {
+    case 1:
+        ncells    = 30;
+        crosstalk = 0.2;
+        deadtime  = 3;
+        recovery  = 8.75*4;
+        break;
+
+    case 2:
+        ncells    = 60;
+        crosstalk = 0.2;
+        deadtime  = 3;
+        recovery  = 8.75;
+        break;
+
+    default:
+        *fLog << err << "ERROR - APD type " << fType << " undefined." << endl;
+        return kFALSE;
+    }
+
+    for (UInt_t i=0; i<fGeom->GetNumPixels(); i++)
+        fAPDs.Add(new APD(ncells, crosstalk, deadtime, recovery));
 
     return kTRUE;
@@ -216,4 +240,5 @@
 //
 // NameGeomCam
+// Type: 1
 //
 Int_t MSimAPD::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
@@ -226,4 +251,10 @@
     }
 
+    if (IsEnvDefined(env, prefix, "Type", print))
+    {
+        rc = kTRUE;
+        fType = GetEnvValue(env, prefix, "Type", fType);
+    }
+
     return rc;
 }
Index: trunk/MagicSoft/Mars/msimcamera/MSimAPD.h
===================================================================
--- trunk/MagicSoft/Mars/msimcamera/MSimAPD.h	(revision 9368)
+++ trunk/MagicSoft/Mars/msimcamera/MSimAPD.h	(revision 9369)
@@ -28,4 +28,6 @@
     Double_t fFreq;              // Frequency of random phtons which hit the APDs
 
+    Int_t fType;
+
     // MParContainer
     Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
Index: trunk/MagicSoft/Mars/mtools/MagicCivilization.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MagicCivilization.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mtools/MagicCivilization.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
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz 07/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2002
+!   Author(s): Thomas Bretz,  7/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: CheObs Software Development, 2000-2009
 !
 !
@@ -65,5 +65,5 @@
 #include <TInterpreter.h>
 
-#include "MHexagon.h"
+#include "MH.h"
 
 #include "MGeomPix.h"
@@ -80,20 +80,5 @@
         return;
 
-    fPixels->Delete();
-
-    delete fPixels;
-
     delete fGeomCam;
-}
-
-// ------------------------------------------------------------------------
-//
-// Draw all pixels of the camera
-//  (means apend all pixelobjects to the current pad)
-//
-void MagicCivilization::DrawHexagons()
-{
-    for (UInt_t i=0; i<fNumPixels; i++)
-        (*this)[i].Draw();
 }
 
@@ -111,5 +96,5 @@
     ct1 = !ct1;
 
-    DrawHexagons();
+    AppendPad();
 }
 
@@ -117,10 +102,4 @@
 {
     Free();
-
-    //
-    //  Reset the display geometry
-    //
-    fW=0;
-    fH=0;
 
     //
@@ -135,16 +114,5 @@
     fRange     = fGeomCam->GetMaxRadius();
 
-    //
-    // Construct all hexagons. Use new-operator with placement
-    //
-    fPixels = new TClonesArray("MHexagon", fNumPixels);
-
-    for (UInt_t i=0; i<fNumPixels; i++)
-    {
-        MHexagon &h = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
-#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-        h.SetBit(kNoContextMenu|kCannotPick);
-#endif
-    }
+    fColors.Set(fNumPixels);
 }
 
@@ -154,5 +122,5 @@
 //
 MagicCivilization::MagicCivilization(Byte_t lim, UShort_t init)
-    : fTimer(this, 500, kTRUE), fGeomCam(NULL), fNumInit(init), fLimit(lim), fW(0), fH(0)
+    : fTimer(this, 500, kTRUE), fGeomCam(NULL), fNumInit(init), fLimit(lim)
 {
     SetNewCamera(new MGeomCamMagic);
@@ -179,10 +147,4 @@
     fTimer.TurnOff();
     Free();
-
-    if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)
-    {
-        fDrawingPad->RecursiveRemove(this);
-        delete fDrawingPad;
-    }
 }
 
@@ -195,40 +157,23 @@
 void MagicCivilization::Paint(Option_t *opt)
 {
-    const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC());
-    const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC());
-
-    //
-    // Check for a change in width or height, and make sure, that the
-    // first call also sets the range
-    //
-    if (w*fH == h*fW && fW && fH)
-        return;
-
-    //
-    // Calculate aspect ratio (5/4=1.25 recommended)
-    //
-    const Double_t ratio = (Double_t)w/h;
-
-    Float_t x;
-    Float_t y;
-
-    if (ratio>1.0)
-    {
-        x = fRange*(ratio*2-1);
-        y = fRange;
-    }
-    else
-    {
-        x = fRange;
-        y = fRange/ratio;
-    }
-
-    fH = h;
-    fW = w;
-
-    //
-    // Set new range
-    //
-    fDrawingPad->Range(-fRange, -y, x, y);
+    const Float_t r = fGeomCam->GetMaxRadius();
+
+    MH::SetPadRange(-r, -r, r, r*1.1);
+
+    TAttLine line;
+    TAttFill fill;
+
+    // FIXME:
+    for (UInt_t i=0; i<fNumPixels; i++)
+    {
+        const MGeom &pix = (*fGeomCam)[i];
+
+        fill.SetFillColor(fColors[i]);
+        pix.PaintPrimitive(line, fill);
+    }
+ /*
+    for (int i=0; i<6; i++)
+        fText[i]->Paint();
+        */
 }
 
@@ -266,8 +211,10 @@
     fStep = 0;
 
+    fColors.Reset();
+
     Update();
 
-    fDrawingPad->Modified();
-    fDrawingPad->Update();
+    gPad->Modified();
+    gPad->Update();
 }
 
@@ -284,10 +231,8 @@
     // if no canvas is yet existing to draw into, create a new one
     //
-    /*TCanvas *c =*/ new TCanvas("MagicCivilization", "Magic Civilization", 0, 0, 800, 800);
-    //c->ToggleEventStatus();
-
-    fDrawingPad = gPad;
-    fDrawingPad->SetBorderMode(0);
-    fDrawingPad->SetFillColor(22);
+    new TCanvas("MagicCivilization", "Magic Civilization", 0, 0, 800, 800);
+
+    gPad->SetBorderMode(0);
+    gPad->SetFillColor(22);
 
     //
@@ -296,9 +241,4 @@
     //
     AppendPad(option);
-
-    //
-    // Reset the game pad
-    //
-    DrawHexagons();
 
     fCivilization.SetTextAlign(23);   // centered/bottom
@@ -349,5 +289,5 @@
         fAuto = !fAuto;
         Update();
-        fDrawingPad->Update();
+        gPad->Update();
         return;
 
@@ -395,5 +335,5 @@
     for (int i=0; i<fNumPixels; i++)
     {
-        MGeomPix &pix = (*fGeomCam)[i];
+        MGeom &pix = (*fGeomCam)[i];
 
         Byte_t cnt=0;
@@ -411,11 +351,10 @@
     for (int i=0; i<fNumPixels; i++)
     {
-        MGeomPix &pix = (*fGeomCam)[i];
-        MHexagon &hex = (*this)[i];
+        MGeom &pix = (*fGeomCam)[i];
 
         if (pix.TestBit(kHasCreation))
         {
             pix.SetBit(kHasFlag);
-            hex.SetFillColor(kBlack);
+            fColors[i] = kBlack;
             fNumCivilizations++;
         }
@@ -423,5 +362,5 @@
         {
             pix.ResetBit(kHasFlag);
-            hex.SetFillColor(kBackground);
+            fColors[i] = kBackground;
         }
         pix.ResetBit(kHasCreation);
@@ -435,5 +374,5 @@
     Update();
 
-    fDrawingPad->Update();
+    gPad->Update();
 
     return kTRUE;
Index: trunk/MagicSoft/Mars/mtools/MagicCivilization.h
===================================================================
--- trunk/MagicSoft/Mars/mtools/MagicCivilization.h	(revision 9368)
+++ trunk/MagicSoft/Mars/mtools/MagicCivilization.h	(revision 9369)
@@ -14,4 +14,7 @@
 #ifndef ROOT_TClonesArray
 #include <TClonesArray.h>
+#endif
+#ifndef ROOT_TArrayI
+#include <TArrayI.h>
 #endif
 
@@ -50,15 +53,8 @@
     TText     fCivilization;    // TText showing the numbers of pixels and bombs
 
-    UInt_t    fW;               // Width of canvas
-    UInt_t    fH;               // Height of canvas
-
-    TClonesArray *fPixels;      // array of all hexagons
-    TVirtualPad  *fDrawingPad;  // pad in which we are drawing
-
-    MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
+    TArrayI fColors;
 
     void   Update();
     void   Free();
-    void   DrawHexagons();
     void   SetNewCamera(MGeomCam *);
 
Index: trunk/MagicSoft/Mars/mtools/MagicDomino.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MagicDomino.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mtools/MagicDomino.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
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz 07/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Thomas Bretz,  7/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2008
+!   Copyright: CheObs Software Development, 2000-2009
 !
 !
@@ -68,5 +68,5 @@
 #include <TInterpreter.h>
 
-#include "MHexagon.h"
+#include "MH.h"
 
 #include "MGeomPix.h"
@@ -87,20 +87,5 @@
         return;
 
-    fPixels->Delete();
-
-    delete fPixels;
-
     delete fGeomCam;
-}
-
-// ------------------------------------------------------------------------
-//
-// Draw all pixels of the camera
-//  (means apend all pixelobjects to the current pad)
-//
-void MagicDomino::DrawHexagons()
-{
-    for (UInt_t i=0; i<fNumPixels; i++)
-        (*this)[i].Draw();
 }
 
@@ -123,5 +108,5 @@
 
     Reset();
-    DrawHexagons();
+    AppendPad();
 }
 
@@ -133,10 +118,4 @@
 {
     Free();
-
-    //
-    //  Reset the display geometry
-    //
-    fW=0;
-    fH=0;
 
     //
@@ -151,48 +130,31 @@
     fRange     = fGeomCam->GetMaxRadius();
 
-    //
-    // Construct all hexagons. Use new-operator with placement
-    //
-    fPixels = new TClonesArray("MHexagon", fNumPixels);
-
+    fColors.Set(fNumPixels);
+}
+
+// ------------------------------------------------------------------------
+//
+// remove the pixel numbers in the tile from the pad
+//
+void MagicDomino::RemoveNumbers()
+{
+    for (int i=0; i<6; i++)
+        fText[i]->SetText(0, 0, "");
+}
+
+// ------------------------------------------------------------------------
+//
+// Reset/restart the game
+//
+void MagicDomino::Reset()
+{
     for (UInt_t i=0; i<fNumPixels; i++)
     {
-        MHexagon &h = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
+        fColors[i] = kBackground;
+        (*fGeomCam)[i].ResetBit(kUserBits);
+    }
+
+
 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-        h.SetBit(kNoContextMenu|kCannotPick);
-#endif
-    }
-}
-
-// ------------------------------------------------------------------------
-//
-// remove the pixel numbers in the tile from the pad
-//
-void MagicDomino::RemoveNumbers()
-{
-    for (int i=0; i<6; i++)
-        if (fText[i])
-        {
-            delete fText[i];
-            fText[i] = NULL;
-        }
-}
-
-// ------------------------------------------------------------------------
-//
-// Reset/restart the game
-//
-void MagicDomino::Reset()
-{
-    for (UInt_t i=0; i<fNumPixels; i++)
-    {
-        MHexagon &h = (*this)[i];
-        h.SetFillColor(kBackground);
-        h.ResetBit(kUserBits);
-    }
-
-
-#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-    fDrawingPad->SetBit(kNoContextMenu);
     SetBit(kNoContextMenu);
 #endif
@@ -205,5 +167,5 @@
 
 
-    fDrawingPad->SetFillColor(22);
+    gPad->SetFillColor(22);
 
     fNumPixel = -1;
@@ -218,5 +180,10 @@
 void MagicDomino::Init()
 {
-    memset(fText, 0, sizeof(fText));
+    for (int i=0; i<6; i++)
+    {
+        fText[i] = new TText(0, 0, "");
+        fText[i]->SetTextFont(122);
+        fText[i]->SetTextAlign(22);   // centered/centered
+    }
 
     //
@@ -260,11 +227,4 @@
 
     RemoveNumbers();
-
-    if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)
-    {
-        fDrawingPad->RecursiveRemove(this);
-        delete fDrawingPad;
-    }
-
 }
 
@@ -277,40 +237,22 @@
 void MagicDomino::Paint(Option_t *opt)
 {
-    const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC());
-    const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC());
-
-    //
-    // Check for a change in width or height, and make sure, that the
-    // first call also sets the range
-    //
-    if (w*fH == h*fW && fW && fH)
-        return;
-
-    //
-    // Calculate aspect ratio (5/4=1.25 recommended)
-    //
-    const Double_t ratio = (Double_t)w/h;
-
-    Float_t x;
-    Float_t y;
-
-    if (ratio>1.0)
-    {
-        x = fRange*(ratio*2-1);
-        y = fRange;
-    }
-    else
-    {
-        x = fRange;
-        y = fRange/ratio;
-    }
-
-    fH = h;
-    fW = w;
-
-    //
-    // Set new range
-    //
-    fDrawingPad->Range(-fRange, -y, x, y);
+    const Float_t r = fGeomCam->GetMaxRadius();
+
+    MH::SetPadRange(-r, -r, r, r*1.1);
+
+    TAttLine line;
+    TAttFill fill;
+
+    // FIXME:
+    for (UInt_t i=0; i<fNumPixels; i++)
+    {
+        const MGeom &pix = (*fGeomCam)[i];
+
+        fill.SetFillColor(fColors[i]);
+        pix.PaintPrimitive(line, fill);
+    }
+
+    for (int i=0; i<6; i++)
+        fText[i]->Paint();
 }
 
@@ -327,9 +269,7 @@
     // if no canvas is yet existing to draw into, create a new one
     //
-    /*TCanvas *c =*/ new TCanvas("MagicDomino", "Magic Domino Next Neighbours", 0, 0, 800, 800);
-    //c->ToggleEventStatus();
-
-    fDrawingPad = gPad;
-    fDrawingPad->SetBorderMode(0);
+    new TCanvas("MagicDomino", "Magic Domino Next Neighbours", 0, 0, 800, 800);
+
+    gPad->SetBorderMode(0);
 
     //
@@ -343,13 +283,4 @@
     //
     Reset();
-    DrawHexagons();
-
-    /*
-     TPave *p = new TPave(-0.66*fRange, 0.895*fRange, 0.66*fRange, 0.995*fRange, 4, "br");
-     p->ConvertNDCtoPad();
-     p->SetFillColor(12);
-     p->SetBit(kCanDelete);
-     p->Draw();
-     */
 
     fDomino.SetTextAlign(23);   // centered/bottom
@@ -408,8 +339,8 @@
     if (fNumPixel>=0)
     {
-        const MGeomPix &pix=(*fGeomCam)[fNumPixel];
-        (*this)[fNumPixel].ResetBit(kIsTile);
+        MGeom &pix=(*fGeomCam)[fNumPixel];
+        pix.ResetBit(kIsTile);
         for (int i=0; i<pix.GetNumNeighbors(); i++)
-            (*this)[pix.GetNeighbor(i)].ResetBit(kIsTile);
+            (*fGeomCam)[pix.GetNeighbor(i)].ResetBit(kIsTile);
 
         fPoints += pix.GetNumNeighbors();
@@ -425,5 +356,5 @@
     Update();
 
-    fDrawingPad->Update();
+    gPad->Update();
 }
 
@@ -444,9 +375,9 @@
 
     Int_t cnt=0;
-    const MGeomPix &pix1=(*fGeomCam)[fNumPixel];
+    const MGeom &pix1=(*fGeomCam)[fNumPixel];
     for (int i=0; i<pix1.GetNumNeighbors(); i++)
     {
         const Int_t idx1 = pix1.GetNeighbor(i);
-        const MGeomPix &pix2 = (*fGeomCam)[idx1];
+        const MGeom &pix2 = (*fGeomCam)[idx1];
 
         Byte_t ignored = 0;
@@ -454,8 +385,8 @@
         for (int j=0; j<pix2.GetNumNeighbors(); j++)
         {
-            const Int_t    idx2 = pix2.GetNeighbor(j);
-            const MHexagon &hex = (*this)[idx2];
-
-            if (hex.TestBit(kIsTile) || hex.GetFillColor()==kBackground)
+            const Int_t idx2 = pix2.GetNeighbor(j);
+            const MGeom &hex = (*fGeomCam)[idx2];
+
+            if (hex.TestBit(kIsTile) || fColors[idx2]==kBackground)
             {
                 ignored++;
@@ -463,5 +394,5 @@
             }
 
-            if (hex.GetFillColor()==(*this)[idx1].GetFillColor())
+            if (fColors[idx2]==fColors[idx1])
                 found++;
         }
@@ -487,13 +418,12 @@
     fDomino.SetTextColor(kBlue);
 
-    fDrawingPad->SetFillColor(kRed);
+    gPad->SetFillColor(kRed);
 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
     fDone->SetBit(kNoContextMenu|kCannotPick);
-    fDrawingPad->ResetBit(kNoContextMenu);
     ResetBit(kNoContextMenu);
 #endif
 
-    fDrawingPad->Modified();
-    fDrawingPad->Update();
+    gPad->Modified();
+    gPad->Update();
 }
 
@@ -572,6 +502,6 @@
     Update();
 
-    fDrawingPad->Modified();
-    fDrawingPad->Update();
+    gPad->Modified();
+    gPad->Update();
 }
 
@@ -585,17 +515,15 @@
         return;
 
-    MagicDomino &This = *this;
-
     RemoveNumbers();
 
-    const MGeomPix &pix1=(*fGeomCam)[fNumPixel];
-    This[fNumPixel].SetFillColor(fOldColors[6]);
-    This[fNumPixel].ResetBit(kIsTile);
+    MGeom &pix1=(*fGeomCam)[fNumPixel];
+    fColors[fNumPixel] = fOldColors[6];
+    pix1.ResetBit(kIsTile);
     for (int i=0; i<pix1.GetNumNeighbors(); i++)
     {
         Int_t idx = pix1.GetNeighbor(i);
 
-        This[idx].SetFillColor(fOldColors[i]);
-        This[idx].ResetBit(kIsTile);
+        fColors[idx] = fOldColors[i];
+        (*fGeomCam)[idx].ResetBit(kIsTile);
     }
 }
@@ -609,6 +537,4 @@
     if (fNumPixel<0)
         return;
-
-    MagicDomino &This = *this;
 
     Int_t indices[6];
@@ -617,13 +543,13 @@
     RemoveNumbers();
 
-    const MGeomPix &pix2=(*fGeomCam)[fNumPixel];
-    fOldColors[6] = This[fNumPixel].GetFillColor();
-    This[fNumPixel].SetFillColor(kBlack);
-    This[fNumPixel].SetBit(kIsTile);
+    MGeom &pix2=(*fGeomCam)[fNumPixel];
+    fOldColors[6] = fColors[fNumPixel];
+    fColors[fNumPixel] = kBlack;
+    pix2.SetBit(kIsTile);
     for (int i=0; i<pix2.GetNumNeighbors(); i++)
     {
         Int_t idx = pix2.GetNeighbor(i);
 
-        fOldColors[i] = This[idx].GetFillColor();
+        fOldColors[i] = fColors[idx];
 
         int j=0;
@@ -631,15 +557,14 @@
             j++;
 
-        This[idx].SetFillColor(fNewColors[(j+fPosition)%6]);
-        This[idx].SetBit(kIsTile);
+        MGeom &pix = (*fGeomCam)[idx];
+
+        fColors[idx] = fNewColors[(j+fPosition)%6];
+        pix.SetBit(kIsTile);
 
         TString num;
         num += idx;
 
-        fText[i] = new TText(This[idx].GetX(), This[idx].GetY(), num);
-        fText[i]->SetTextSize(0.3*This[idx].GetD()/fGeomCam->GetMaxRadius());
-        fText[i]->SetTextFont(122);
-        fText[i]->SetTextAlign(22);   // centered/centered
-        fText[i]->Draw();
+        fText[i]->SetText(pix.GetX(), pix.GetY(), num);
+        fText[i]->SetTextSize(0.3*pix.GetT()/fGeomCam->GetMaxRadius());
     }
 }
@@ -659,5 +584,5 @@
     Update();
 
-    fDrawingPad->Update();
+    gPad->Update();
 }
 
@@ -668,5 +593,5 @@
 Short_t MagicDomino::AnalysePixel(Int_t dir)
 {
-    const MGeomPix &pix=(*fGeomCam)[fNumPixel<0?0:fNumPixel];
+    const MGeom &pix=(*fGeomCam)[fNumPixel<0?0:fNumPixel];
 
     Double_t fAngle[6] = { -10, -10, -10, -10, -10, -10 };
@@ -674,5 +599,5 @@
     for (int i=0; i<pix.GetNumNeighbors(); i++)
     {
-        MGeomPix &next = (*fGeomCam)[pix.GetNeighbor(i)];
+        MGeom &next = (*fGeomCam)[pix.GetNeighbor(i)];
         fAngle[i] = atan2(next.GetY()-pix.GetY(), next.GetX()-pix.GetX());
     }
@@ -714,5 +639,5 @@
 void MagicDomino::GetSortedNeighbors(Int_t indices[6])
 {
-    const MGeomPix &pix=(*fGeomCam)[fNumPixel<0?0:fNumPixel];
+    const MGeom &pix=(*fGeomCam)[fNumPixel<0?0:fNumPixel];
 
     Double_t fAngle[6] = { -10, -10, -10, -10, -10, -10 };
@@ -720,5 +645,5 @@
     for (int i=0; i<pix.GetNumNeighbors(); i++)
     {
-        MGeomPix &next = (*fGeomCam)[pix.GetNeighbor(i)];
+        MGeom &next = (*fGeomCam)[pix.GetNeighbor(i)];
         fAngle[i] = atan2(next.GetY()-pix.GetY(), next.GetX()-pix.GetX());
     }
Index: trunk/MagicSoft/Mars/mtools/MagicDomino.h
===================================================================
--- trunk/MagicSoft/Mars/mtools/MagicDomino.h	(revision 9368)
+++ trunk/MagicSoft/Mars/mtools/MagicDomino.h	(revision 9369)
@@ -11,4 +11,7 @@
 #ifndef ROOT_TClonesArray
 #include <TClonesArray.h>
+#endif
+#ifndef ROOT_TArrayI
+#include <TArrayI.h>
 #endif
 
@@ -59,11 +62,5 @@
     TText    *fDone;            // game over text
 
-    UInt_t    fW;               // Width of canvas
-    UInt_t    fH;               // Height of canvas
-
-    TClonesArray *fPixels;      // array of all hexagons
-    TVirtualPad  *fDrawingPad;  // pad in which we are drawing
-
-    MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
+    TArrayI fColors;
 
     Bool_t  CheckTile();
@@ -77,5 +74,4 @@
     void    Done();
     void    RemoveNumbers();
-    void    DrawHexagons();
     void    SetNewCamera(MGeomCam *);
     void    ChangePixel(Int_t add);
Index: trunk/MagicSoft/Mars/mtools/MagicJam.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MagicJam.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mtools/MagicJam.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
@@ -141,6 +141,9 @@
             Float_t x0 = TMath::Odd(y) ? x-0.25 : x+0.25;
 
-            cam[x + y*fWidth].Set(x0-dx, (y-dy)*0.866, 1);
-        }
+            cam.SetAt(x + y*fWidth, MGeomPix(x0-dx, (y-dy)*0.866, 1));
+        }
+
+
+    cam.InitGeometry();
 
     SetGeometry(cam);
@@ -442,8 +445,8 @@
 
         TVirtualPad *p = dynamic_cast<TVirtualPad*>(o);
-        if (p && p->GetPad(1))
-        {
-            p->GetPad(1)->Modified();
-            p->GetPad(1)->Update();
+        if (p)
+        {
+            p->Modified();
+            p->Update();
         }
     }
@@ -508,5 +511,5 @@
     const Int_t newval = fBinEntries[idx+1]+1;
 
-    const MGeomPix &gpix = (*fGeomCam)[idx];
+    const MGeom &gpix = (*fGeomCam)[idx];
     const Int_t n = gpix.GetNumNeighbors();
 
@@ -721,5 +724,5 @@
         dy += y;
 
-        cam[i].Set(dx, dy*0.866);
+        cam.SetAt(i, MGeomPix(dx, dy*0.866));
     }
 
Index: trunk/MagicSoft/Mars/mtools/MagicReversi.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MagicReversi.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mtools/MagicReversi.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
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz 03/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Thomas Bretz,  3/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2003
+!   Copyright: CheObs Software Development, 2000-2009
 !
 !
@@ -62,5 +62,5 @@
 #include <TInterpreter.h>
 
-#include "MHexagon.h"
+#include "MH.h"
 
 #include "MGeomPix.h"
@@ -88,5 +88,4 @@
         return;
 
-    fPixels->Delete();
     fText->Delete();
     fFlags->Delete();
@@ -94,5 +93,4 @@
     delete fText;
     delete fFlags;
-    delete fPixels;
 
     delete fGeomCam;
@@ -113,5 +111,4 @@
 
     Reset();
-    DrawHexagons();
 }
 
@@ -119,10 +116,4 @@
 {
     Free();
-
-    //
-    //  Reset the display geometry
-    //
-    fW=0;
-    fH=0;
 
     //
@@ -144,22 +135,17 @@
     fText   = new TClonesArray("TText",    fNumPixels);
     fFlags  = new TClonesArray("TMarker",  fNumPixels);
-    fPixels = new TClonesArray("MHexagon", fNumPixels);
+    fColors.Set(fNumPixels);
 
     for (UInt_t i=0; i<fNumPixels; i++)
     {
-        MHexagon &h = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
-#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-        h.SetBit(kNoContextMenu|kCannotPick);
-#endif
+        const MGeom &pix = (*fGeomCam)[i];
 
         TText &t = *new ((*fText)[i]) TText;
         t.SetTextFont(122);
         t.SetTextAlign(22);   // centered/centered
-        t.SetTextSize(0.3*h.GetD()/fRange);
+        t.SetTextSize(0.3*pix.GetT()/fRange);
 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
         t.SetBit(kNoContextMenu|kCannotPick);
 #endif
-
-        const MGeomPix &pix = (*fGeomCam)[i];
 
         TMarker &m = *new ((*fFlags)[i]) TMarker(pix.GetX(), pix.GetY(), kOpenStar);
@@ -170,4 +156,5 @@
 }
 
+/*
 // ------------------------------------------------------------------------
 //
@@ -180,4 +167,5 @@
         (*this)[i].Draw();
 }
+*/
 
 void MagicReversi::Init()
@@ -201,5 +189,5 @@
 //
 MagicReversi::MagicReversi()
-    : fGeomCam(NULL), fDone(NULL), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
+    : fGeomCam(NULL), fDone(NULL)
 {
     SetNewCamera(new MGeomCamMagic);
@@ -209,5 +197,5 @@
 
 MagicReversi::MagicReversi(const MGeomCam &geom)
-    : fGeomCam(NULL), fDone(NULL), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
+    : fGeomCam(NULL), fDone(NULL)
 {
     SetNewCamera(static_cast<MGeomCam*>(geom.Clone()));
@@ -229,10 +217,4 @@
     if (fDone)
         delete fDone;
-
-    if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)
-    {
-        fDrawingPad->RecursiveRemove(this);
-        delete fDrawingPad;
-    }
 }
 
@@ -245,48 +227,29 @@
 void MagicReversi::Paint(Option_t *opt)
 {
-    const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC());
-    const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC());
-
-    //
-    // Check for a change in width or height, and make sure, that the
-    // first call also sets the range
-    //
-    if (w*fH == h*fW && fW && fH)
-        return;
-
-    //
-    // Calculate aspect ratio (5/4=1.25 recommended)
-    //
-    const Double_t ratio = (Double_t)w/h;
-
-    Float_t x;
-    Float_t y;
-
-    if (ratio>1.0)
-    {
-        x = fRange*(ratio*2-1);
-        y = fRange;
-    }
-    else
-    {
-        x = fRange;
-        y = fRange/ratio;
-    }
-
-    fH = h;
-    fW = w;
-
-    //
-    // Set new range
-    //
-    fDrawingPad->Range(-fRange, -y, x, y);
-
-    //
-    // Adopt absolute sized of markers to relative range
-    //
+    const Float_t r = fGeomCam->GetMaxRadius();
+
+    MH::SetPadRange(-r, -r, r, r*1.1);
+
+    TAttLine line;
+    TAttFill fill;
+
+    // FIXME:
     for (UInt_t i=0; i<fNumPixels; i++)
     {
-        Float_t r = (*this)[i].GetD()*gPad->XtoAbsPixel(1)/325;
+        const MGeom &pix = (*fGeomCam)[i];
+
+        fill.SetFillColor(fColors[i]);
+        pix.PaintPrimitive(line, fill);
+
+        //
+        // Adopt absolute sized of markers to relative range
+        //
+        Float_t r = (*fGeomCam)[i].GetT()*gPad->XtoAbsPixel(1)/325;
         GetFlag(i)->SetMarkerSize(20.0*r/fRange);
+
+        if (pix.TestBit(kHasFlag))
+            GetFlag(i)->Paint();
+
+        GetText(i)->Paint();
     }
 }
@@ -301,24 +264,11 @@
 void MagicReversi::Draw(Option_t *option)
 {
-    // root 3.02:
-    // gPad->SetFixedAspectRatio()
-
-    if (fDrawingPad)
-        return;
-
     //
     // if no canvas is yet existing to draw into, create a new one
     //
     if (!gPad)
-    {
-        /*TCanvas *c =*/ new TCanvas("MagicReversi", "Magic Reversi", 0, 0, 800, 800);
-        //c->ToggleEventStatus();
-        fIsAllocated = kTRUE;
-    }
-    else
-        fIsAllocated = kFALSE;
-
-    fDrawingPad = gPad;
-    fDrawingPad->SetBorderMode(0);
+        new TCanvas("MagicReversi", "Magic Reversi", 0, 0, 800, 800);
+
+    gPad->SetBorderMode(0);
 
     //
@@ -347,5 +297,4 @@
     //
     Reset();
-    DrawHexagons();
 }
 
@@ -411,11 +360,9 @@
     for (UInt_t i=0; i<fNumPixels; i++)
     {
-        Remove(GetText(i));
-        Remove(GetFlag(i));
-
-        (*this)[i].SetFillColor(kEmpty);
+        fColors[i] = kEmpty;
         (*fGeomCam)[i].ResetBit(kUserBits);
 
         GetFlag(i)->SetMarkerColor(kBlack);
+        GetText(i)->SetText(0, 0, "");
     }
 
@@ -427,5 +374,5 @@
     for (int i=1; i<5*fNumUsers; i++)
     {
-        (*this)[i-1].SetFillColor(i%fNumUsers+kRed);
+        fColors[i-1] = i%fNumUsers+kRed;
         fUsrPts[i%fNumUsers]++;
     }
@@ -433,8 +380,7 @@
     Update();
 
-    fDrawingPad->SetFillColor(22);
+    gPad->SetFillColor(22);
 
 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-    fDrawingPad->SetBit(kNoContextMenu);
     SetBit(kNoContextMenu);
 #endif
@@ -468,15 +414,9 @@
     fDone->Draw();
 
-    fDrawingPad->SetFillColor(winner+kRed);
+    gPad->SetFillColor(winner+kRed);
 
 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-    fDrawingPad->ResetBit(kNoContextMenu);
     ResetBit(kNoContextMenu);
 #endif
-}
-
-void MagicReversi::Remove(TObject *obj)
-{
-    fDrawingPad->RecursiveRemove(obj);
 }
 
@@ -495,8 +435,8 @@
         {
             idx = fGeomCam->GetNeighbor(idx, dir);
-            if (idx<0 || (*this)[idx].GetFillColor()==kEmpty)
+            if (idx<0 || fColors[idx]==kEmpty)
                 break;
 
-            if ((*this)[idx].GetFillColor()==col)
+            if (fColors[idx]==col)
             {
                 if (length!=0)
@@ -523,8 +463,8 @@
                 idx = fGeomCam->GetNeighbor(idx, dir);
 
-                fUsrPts[(*this)[idx].GetFillColor()-kRed]--;
+                fUsrPts[fColors[idx]-kRed]--;
                 fUsrPts[fNumUser]++;
 
-                (*this)[idx].SetFillColor(col);
+                fColors[idx] = col;
             }
     }
@@ -536,5 +476,5 @@
 {
     for (unsigned int i=0; i<fNumPixels; i++)
-        if ((*this)[i].GetFillColor()==kEmpty && Flip(i, kFALSE))
+        if (fColors[i]==kEmpty && Flip(i, kFALSE))
             return kTRUE;
     return kFALSE;
@@ -557,6 +497,6 @@
     {
         Done();
-        fDrawingPad->Modified();
-        fDrawingPad->Update();
+        gPad->Modified();
+        gPad->Update();
         return;
     }
@@ -564,5 +504,5 @@
     UInt_t idx;
     for (idx=0; idx<fNumPixels; idx++)
-        if ((*fPixels)[idx]->DistancetoPrimitive(px, py)==0)
+        if ((*fGeomCam)[idx].DistancetoPrimitive(px, py)<=0)
             break;
 
@@ -570,5 +510,5 @@
         return;
 
-    if (event==kButton1Down && (*this)[idx].GetFillColor()==kEmpty)
+    if (event==kButton1Down && fColors[idx]==kEmpty)
     {
         if (!Flip(idx, kTRUE))
@@ -577,5 +517,5 @@
         fUsrPts[fNumUser]++;
 
-        (*this)[idx].SetFillColor(kRed+fNumUser);
+        fColors[idx] = kRed+fNumUser;
 
         Int_t start = fNumUser;
@@ -600,4 +540,4 @@
     }
 
-    fDrawingPad->Modified();
-}
+    gPad->Modified();
+}
Index: trunk/MagicSoft/Mars/mtools/MagicReversi.h
===================================================================
--- trunk/MagicSoft/Mars/mtools/MagicReversi.h	(revision 9368)
+++ trunk/MagicSoft/Mars/mtools/MagicReversi.h	(revision 9369)
@@ -7,4 +7,7 @@
 #ifndef ROOT_TClonesArray
 #include <TClonesArray.h>
+#endif
+#ifndef ROOT_TArrayI
+#include <TArrayI.h>
 #endif
 
@@ -24,15 +27,11 @@
     Float_t        fRange;         // the range in millimeters of the present geometry
 
-    TClonesArray  *fPixels;        // array of all hexagons
     TClonesArray  *fText;          // array of all texts
     TClonesArray  *fFlags;         // array of all texts
 
+    TArrayI fColors;
+
     TText         *fDone;          // TText showing the 'Game over'
     TText         *fUsrTxt[6];     // TText showing the numbers of pixels and bombs
-
-    UInt_t         fW;             // Width of canvas
-    UInt_t         fH;             // Height of canvas
-    TVirtualPad   *fDrawingPad;    // pad in which we are drawing
-    Bool_t         fIsAllocated;
 
     Int_t          fNumUsers;
@@ -49,14 +48,10 @@
     };
 
-    MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
-
     TText   *GetText(Int_t i) { return (TText*)fText->At(i); }
     TMarker *GetFlag(Int_t i) { return (TMarker*)fFlags->At(i); }
 
-    void  Remove(TObject *);
     void  Done();
     void  Update();
     void  SetNewCamera(MGeomCam *);
-    void  DrawHexagons();
     void  Free();
     void  Init();
Index: trunk/MagicSoft/Mars/mtools/MagicShow.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MagicShow.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mtools/MagicShow.cc	(revision 9369)
@@ -64,5 +64,5 @@
 #include <TInterpreter.h>
 
-#include "MHexagon.h"
+#include "MH.h"
 
 #include "MGeomPix.h"
@@ -83,25 +83,5 @@
         return;
 
-    fPixels->Delete();
-
-    delete fPixels;
-
     delete fGeomCam;
-}
-
-// ------------------------------------------------------------------------
-//
-// Draw all pixels of the camera
-//  (means apend all pixelobjects to the current pad)
-//
-void MagicShow::DrawHexagons()
-{
-    for (UInt_t i=0; i<fNumPixels; i++)
-    {
-        MHexagon &h = (*this)[i];
-
-        h.SetFillColor(kBackground);
-        h.Draw();
-    }
 }
 
@@ -123,5 +103,11 @@
     ct1 = !ct1;
 
-    DrawHexagons();
+    Update();
+
+    fColors.Reset();
+
+    // FIXME: Reset all texts
+
+    AppendPad();
 }
 
@@ -133,10 +119,4 @@
 {
     Free();
-
-    //
-    //  Reset the display geometry
-    //
-    fW=0;
-    fH=0;
 
     //
@@ -151,24 +131,19 @@
     fRange     = fGeomCam->GetMaxRadius();
 
-    fNumPixel  = fNumPixels-1;
-
-    //
-    // Construct all hexagons. Use new-operator with placement
-    //
-    fPixels = new TClonesArray("MHexagon", fNumPixels);
-
-    for (UInt_t i=0; i<fNumPixels; i++)
-    {
-        MHexagon &h = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
-#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-        h.SetBit(kNoContextMenu|kCannotPick);
-#endif
-    }
+    fNumPixel  = 0;//fNumPixels-1;
+
+    fColors.Set(fNumPixels);
+
+    for (int i=0; i<6; i++)
+    {
+        fText[i] = new TText(0, 0, "");
+        fText[i]->SetTextFont(122);
+        fText[i]->SetTextAlign(22);   // centered/centered
+    }
+
 }
 
 void MagicShow::Init()
 {
-    memset(fText, 0, sizeof(fText));
-
     //
     // Make sure, that the object is destroyed when the canvas/pad is
@@ -189,5 +164,5 @@
 //
 MagicShow::MagicShow()
-    : fTimer(this, 250, kTRUE), fGeomCam(NULL), fNumPixel(-1), fAuto(kTRUE), fW(0), fH(0)
+    : fTimer(this, 250, kTRUE), fGeomCam(NULL), fNumPixel(-1), fAuto(kTRUE)
 {
     SetNewCamera(new MGeomCamMagic);
@@ -200,5 +175,5 @@
 //
 MagicShow::MagicShow(const MGeomCam &geom)
-    : fTimer(this, 250, kTRUE), fGeomCam(NULL), fNumPixel(-1), fAuto(kTRUE), fW(0), fH(0)
+    : fTimer(this, 250, kTRUE), fGeomCam(NULL), fNumPixel(-1), fAuto(kTRUE)
 {
     SetNewCamera(static_cast<MGeomCam*>(geom.Clone()));
@@ -215,12 +190,5 @@
 
     for (int i=0; i<6; i++)
-        if (fText[i])
-            delete fText[i];
-
-    if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)
-    {
-        fDrawingPad->RecursiveRemove(this);
-        delete fDrawingPad;
-    }
+        delete fText[i];
 }
 
@@ -233,40 +201,22 @@
 void MagicShow::Paint(Option_t *opt)
 {
-    const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC());
-    const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC());
-
-    //
-    // Check for a change in width or height, and make sure, that the
-    // first call also sets the range
-    //
-    if (w*fH == h*fW && fW && fH)
-        return;
-
-    //
-    // Calculate aspect ratio (5/4=1.25 recommended)
-    //
-    const Double_t ratio = (Double_t)w/h;
-
-    Float_t x;
-    Float_t y;
-
-    if (ratio>1.0)
-    {
-        x = fRange*(ratio*2-1);
-        y = fRange;
-    }
-    else
-    {
-        x = fRange;
-        y = fRange/ratio;
-    }
-
-    fH = h;
-    fW = w;
-
-    //
-    // Set new range
-    //
-    fDrawingPad->Range(-fRange, -y, x, y);
+    const Float_t r = fGeomCam->GetMaxRadius();
+
+    MH::SetPadRange(-r, -r, r, r*1.1);
+
+    TAttLine line;
+    TAttFill fill;
+
+    // FIXME:
+    for (UInt_t i=0; i<fNumPixels; i++)
+    {
+        const MGeom &pix = (*fGeomCam)[i];
+
+        fill.SetFillColor(fColors[i]);
+        pix.PaintPrimitive(line, fill);
+    }
+
+    for (int i=0; i<6; i++)
+        fText[i]->Paint();
 }
 
@@ -283,10 +233,8 @@
     // if no canvas is yet existing to draw into, create a new one
     //
-    /*TCanvas *c =*/ new TCanvas("MagicShow", "Magic Show Next Neighbours", 0, 0, 800, 800);
-    //c->ToggleEventStatus();
-
-    fDrawingPad = gPad;
-    fDrawingPad->SetBorderMode(0);
-    fDrawingPad->SetFillColor(22);
+    new TCanvas("MagicShow", "Magic Show Next Neighbours", 0, 0, 800, 800);
+
+    gPad->SetBorderMode(0);
+    gPad->SetFillColor(22);
 
     //
@@ -295,9 +243,4 @@
     //
     AppendPad(option);
-
-    //
-    // Reset the game pad
-    //
-    DrawHexagons();
 
     fShow.SetTextAlign(23);   // centered/bottom
@@ -339,5 +282,5 @@
         fAuto = !fAuto;
         Update();
-        fDrawingPad->Update();
+        gPad->Update();
         return;
 
@@ -382,16 +325,14 @@
 void MagicShow::ChangePixel(Int_t add)
 {
-    MagicShow &This = *this;
-
-    const MGeomPix &pix1=(*fGeomCam)[fNumPixel];
-    This[fNumPixel].SetFillColor(kBackground);
+    const MGeom &pix1=(*fGeomCam)[fNumPixel];
+
+    fColors[fNumPixel] = kBackground;
     for (int i=0; i<pix1.GetNumNeighbors(); i++)
     {
-        This[pix1.GetNeighbor(i)].SetFillColor(kBackground);
-        if (!fText[i])
+        fColors[pix1.GetNeighbor(i)] = kBackground;
+        if (TString(fText[i]->GetTitle()).IsNull())
             continue;
 
-        delete fText[i];
-        fText[i] = NULL;
+        fText[i]->SetText(0, 0, "");
     }
 
@@ -403,25 +344,26 @@
         fNumPixel = fNumPixels-1;
 
-    const MGeomPix &pix2=(*fGeomCam)[fNumPixel];
-    This[fNumPixel].SetFillColor(kBlue);
+    const MGeom &pix2=(*fGeomCam)[fNumPixel];
+
+    fColors[fNumPixel] = kBlue;
+
     for (int i=0; i<pix2.GetNumNeighbors(); i++)
     {
         Int_t idx = pix2.GetNeighbor(i);
 
-        This[idx].SetFillColor(kMagenta);
+        fColors[idx] = kMagenta;
 
         TString num;
         num += idx;
 
-        fText[i] = new TText(This[idx].GetX(), This[idx].GetY(), num);
-        fText[i]->SetTextSize(0.3*This[idx].GetD()/fGeomCam->GetMaxRadius());
-        fText[i]->SetTextFont(122);
-        fText[i]->SetTextAlign(22);   // centered/centered
-        fText[i]->Draw();
+        const MGeom &pix=(*fGeomCam)[idx];
+
+        fText[i]->SetText(pix.GetX(), pix.GetY(), num);
+        fText[i]->SetTextSize(0.3*pix.GetT()/fGeomCam->GetMaxRadius());
     }
 
     Update();
 
-    fDrawingPad->Update();
+    gPad->Update();
 }
 
Index: trunk/MagicSoft/Mars/mtools/MagicShow.h
===================================================================
--- trunk/MagicSoft/Mars/mtools/MagicShow.h	(revision 9368)
+++ trunk/MagicSoft/Mars/mtools/MagicShow.h	(revision 9369)
@@ -14,4 +14,7 @@
 #ifndef ROOT_TClonesArray
 #include <TClonesArray.h>
+#endif
+#ifndef ROOT_TArrayI
+#include <TArrayI.h>
 #endif
 
@@ -45,15 +48,8 @@
     TText    *fText[6];         // ttext showing the pixel numbers of the neighbors
 
-    UInt_t    fW;               // Width of canvas
-    UInt_t    fH;               // Height of canvas
-
-    TClonesArray *fPixels;      // array of all hexagons
-    TVirtualPad  *fDrawingPad;  // pad in which we are drawing
-
-    MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
+    TArrayI fColors;
 
     void   Update();
     void   Free();
-    void   DrawHexagons();
     void   SetNewCamera(MGeomCam *);
     void   ChangePixel(Int_t add);
Index: trunk/MagicSoft/Mars/mtools/MagicSnake.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MagicSnake.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mtools/MagicSnake.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
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz 07/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Thomas Bretz,  7/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2002
+!   Copyright: CheObs Software Development, 2000-2009
 !
 !
@@ -63,5 +63,5 @@
 #include <TInterpreter.h>
 
-#include "MHexagon.h"
+#include "MH.h"
 
 #include "MGeomPix.h"
@@ -78,22 +78,7 @@
         return;
 
-    fPixels->Delete();
-
-    delete fPixels;
-
     delete fGeomCam;
 
     delete fArray;
-}
-
-// ------------------------------------------------------------------------
-//
-// Draw all pixels of the camera
-//  (means apend all pixelobjects to the current pad)
-//
-void MagicSnake::DrawHexagons()
-{
-    for (UInt_t i=0; i<fNumPixels; i++)
-        (*this)[i].Draw();
 }
 
@@ -115,5 +100,5 @@
 
     Reset();
-    DrawHexagons();
+    AppendPad();
 }
 
@@ -121,10 +106,4 @@
 {
     Free();
-
-    //
-    //  Reset the display geometry
-    //
-    fW=0;
-    fH=0;
 
     //
@@ -139,16 +118,5 @@
     fRange     = fGeomCam->GetMaxRadius();
 
-    //
-    // Construct all hexagons. Use new-operator with placement
-    //
-    fPixels = new TClonesArray("MHexagon", fNumPixels);
-
-    for (UInt_t i=0; i<fNumPixels; i++)
-    {
-        MHexagon &h = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
-#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-        h.SetBit(kNoContextMenu|kCannotPick);
-#endif
-    }
+    fColors.Set(fNumPixels);
 }
 
@@ -175,5 +143,5 @@
 //
 MagicSnake::MagicSnake()
-    : fTimer(this, 500, kTRUE), fGeomCam(NULL), fDone(NULL), fPaused(NULL), fW(0), fH(0)
+    : fTimer(this, 500, kTRUE), fGeomCam(NULL), fDone(NULL), fPaused(NULL)
 {
     SetNewCamera(new MGeomCamMagic);
@@ -186,5 +154,5 @@
 //
 MagicSnake::MagicSnake(const MGeomCam &geom)
-    : fTimer(this, 500, kTRUE), fGeomCam(NULL), fDone(NULL), fPaused(NULL), fW(0), fH(0)
+    : fTimer(this, 500, kTRUE), fGeomCam(NULL), fDone(NULL), fPaused(NULL)
 {
     SetNewCamera(static_cast<MGeomCam*>(geom.Clone()));
@@ -203,8 +171,7 @@
 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
         fPaused->SetBit(kNoContextMenu|kCannotPick);
-        fDrawingPad->ResetBit(kNoContextMenu);
         ResetBit(kNoContextMenu);
 #endif
-        fDrawingPad->Update();
+        //fDrawingPad->Update();
     }
 
@@ -215,5 +182,5 @@
     {
 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-        fDrawingPad->SetBit(kNoContextMenu);
+        //fDrawingPad->SetBit(kNoContextMenu);
         SetBit(kNoContextMenu);
 #endif
@@ -222,7 +189,5 @@
         return;
 
-    Remove(fPaused);
-
-    fDrawingPad->Update();
+    //fDrawingPad->Update();
 
     delete fPaused;
@@ -241,10 +206,10 @@
     if (fDone)
         delete fDone;
-
+/*
     if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)
     {
         fDrawingPad->RecursiveRemove(this);
         delete fDrawingPad;
-    }
+    }*/
 }
 
@@ -257,40 +222,18 @@
 void MagicSnake::Paint(Option_t *opt)
 {
-    const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC());
-    const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC());
-
-    //
-    // Check for a change in width or height, and make sure, that the
-    // first call also sets the range
-    //
-    if (w*fH == h*fW && fW && fH)
-        return;
-
-    //
-    // Calculate aspect ratio (5/4=1.25 recommended)
-    //
-    const Double_t ratio = (Double_t)w/h;
-
-    Float_t x;
-    Float_t y;
-
-    if (ratio>1.0)
-    {
-        x = fRange*(ratio*2-1);
-        y = fRange;
-    }
-    else
-    {
-        x = fRange;
-        y = fRange/ratio;
-    }
-
-    fH = h;
-    fW = w;
-
-    //
-    // Set new range
-    //
-    fDrawingPad->Range(-fRange, -y, x, y);
+    const Float_t r = fGeomCam->GetMaxRadius();
+
+    MH::SetPadRange(-r, -r, r, r*1.1);
+
+    TAttLine line;
+    TAttFill fill;
+
+    for (UInt_t i=0; i<fNumPixels; i++)
+    {
+        const MGeom &pix = (*fGeomCam)[i];
+
+        fill.SetFillColor(fColors[i]);
+        pix.PaintPrimitive(line, fill);
+    }
 }
 
@@ -307,9 +250,8 @@
     // if no canvas is yet existing to draw into, create a new one
     //
-    /*TCanvas *c =*/ new TCanvas("MagicSnake", "Magic Snake", 0, 0, 800, 800);
-    //c->ToggleEventStatus();
-
-    fDrawingPad = gPad;
-    fDrawingPad->SetBorderMode(0);
+    new TCanvas("MagicSnake", "Magic Snake", 0, 0, 800, 800);
+
+    //fDrawingPad = gPad;
+    gPad->SetBorderMode(0);
 
     //
@@ -323,5 +265,4 @@
     //
     Reset();
-    DrawHexagons();
 
     fShow.SetTextAlign(23);   // centered/bottom
@@ -355,5 +296,5 @@
     for (UInt_t i=0; i<fNumPixels; i++)
     {
-        (*this)[i].SetFillColor(kBackground);
+        fColors[i] = kBackground;
         (*fGeomCam)[i].ResetBit(kUserBits);
     }
@@ -372,8 +313,11 @@
 
         (*fGeomCam)[idx].SetBit(kHasBomb);
-        (*this)[idx].SetFillColor(kRed);
+        fColors[idx] = kRed;
     }
 
     fNumFood = fNumPixels/6;
+    // FIXME. gROOT->GetColor doesn't allow more than 100 colors!
+    if (fNumFood>46)
+        fNumFood=46;
 
     fArray = new Int_t[fNumFood+3];
@@ -395,5 +339,5 @@
 
         (*fGeomCam)[idx].SetBit(kHasFood);
-        (*this)[idx].SetFillColor(kGreen);
+        fColors[idx] = kGreen;
     }
 
@@ -409,11 +353,11 @@
         fTransport[i] = idx;
         (*fGeomCam)[idx].SetBit(kHasTransport);
-        (*this)[idx].SetFillColor(kYellow);
-    }
-
-    fDrawingPad->SetFillColor(22);
+        fColors[idx] = kYellow;
+    }
+
+    gPad->SetFillColor(22);
 
 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-    fDrawingPad->SetBit(kNoContextMenu);
+    //fDrawingPad->SetBit(kNoContextMenu);
     SetBit(kNoContextMenu);
 #endif
@@ -435,15 +379,9 @@
     fDone->SetTextSize(0.05); // white
     fDone->Draw();
-    fDrawingPad->SetFillColor(col);
+    gPad->SetFillColor(col);
 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
     fDone->SetBit(kNoContextMenu|kCannotPick);
-    fDrawingPad->ResetBit(kNoContextMenu);
     ResetBit(kNoContextMenu);
 #endif
-}
-
-void MagicSnake::Remove(TObject *obj)
-{
-    fDrawingPad->RecursiveRemove(obj);
 }
 
@@ -500,5 +438,5 @@
     if ((*fGeomCam)[newpix].TestBit(kHasTransport))
     {
-        (*this)[fArray[0]].SetFillColor(kBackground);
+        fColors[fArray[0]] = kBackground;
         (*fGeomCam)[fArray[0]].ResetBit(kHasWorm);
 
@@ -513,11 +451,13 @@
     if (!(*fGeomCam)[newpix].TestBit(kHasFood))
     {
-        MGeomPix &pix = (*fGeomCam)[fArray[0]];
+        MGeom &pix = (*fGeomCam)[fArray[0]];
 
         if (!pix.TestBit(kHasTransport))
+        {
             if (pix.TestBit(kHasDoor))
-                (*this)[fArray[0]].SetFillColor(kMagenta);
+                fColors[fArray[0]] = kMagenta;
             else
-                (*this)[fArray[0]].SetFillColor(kBackground);
+                fColors[fArray[0]] = kBackground;
+        }
 
         pix.ResetBit(kHasWorm);
@@ -538,5 +478,5 @@
             for (int i=1; i<7; i++)
             {
-                (*this)[i].SetFillColor(kMagenta);
+                fColors[i] = kMagenta;
                 (*fGeomCam)[i].SetBit(kHasDoor);
             }
@@ -552,5 +492,5 @@
         const Int_t idx = fArray[i];
 
-        MGeomPix &pix = (*fGeomCam)[idx];
+        MGeom &pix = (*fGeomCam)[idx];
 
         if (pix.TestBit(kHasTransport))
@@ -559,6 +499,5 @@
         pix.SetBit(kHasWorm);
 
-        Int_t color = 51+fLength-i;
-        (*this)[idx].SetFillColor(color);
+        fColors[idx] = 51+fLength-i;
     }
 }
@@ -568,5 +507,5 @@
     const Int_t first = fArray[fLength-1];
 
-    const MGeomPix &pix=(*fGeomCam)[first];
+    const MGeom &pix=(*fGeomCam)[first];
 
     Double_t dx = pix.GetX();
@@ -577,5 +516,5 @@
     {
         const Int_t     idx  = pix.GetNeighbor(i);
-        const MGeomPix &next = (*fGeomCam)[idx];
+        const MGeom &next = (*fGeomCam)[idx];
 
         const Double_t x = next.GetX();
@@ -596,5 +535,5 @@
         return -1;
 
-    const MGeomPix &np = (*fGeomCam)[newpix];
+    const MGeom &np = (*fGeomCam)[newpix];
 
     if (fNumFood==0 && np.TestBit(kHasDoor))
@@ -611,5 +550,5 @@
 
 Bool_t MagicSnake::HandleTimer(TTimer *timer)
-{
+{     
     if (fDone || fPaused)
         return kTRUE;
@@ -637,10 +576,6 @@
     Update();
 
-    //cout << "Update " << flush;
-
-    fDrawingPad->Modified();
-    fDrawingPad->Update();
-
-    //cout << "Done." << endl;
+    gPad->Modified();
+    gPad->Update();
 
     return kTRUE;
Index: trunk/MagicSoft/Mars/mtools/MagicSnake.h
===================================================================
--- trunk/MagicSoft/Mars/mtools/MagicSnake.h	(revision 9368)
+++ trunk/MagicSoft/Mars/mtools/MagicSnake.h	(revision 9369)
@@ -14,4 +14,7 @@
 #ifndef ROOT_TClonesArray
 #include <TClonesArray.h>
+#endif
+#ifndef ROOT_TArrayI
+#include <TArrayI.h>
 #endif
 
@@ -60,17 +63,12 @@
     Float_t   fRange;           // the range in millimeters of the present geometry
 
+    TArrayI fColors;
+
     TText    *fDone;            // TText showing the 'Game over'
     TText    *fPaused;          // TText showing the 'Game over'
     TText     fShow;            // TText showing the numbers of pixels and bombs
 
-    UInt_t    fW;               // Width of canvas
-    UInt_t    fH;               // Height of canvas
-
-    TClonesArray  *fPixels;     // array of all hexagons
     TVirtualPad   *fDrawingPad; // pad in which we are drawing
 
-    MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
-
-    void   Remove(TObject *);
     void   Done(TString, Int_t col);
     void   Step(Int_t newpix);
Index: trunk/MagicSoft/Mars/mtools/MineSweeper.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MineSweeper.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mtools/MineSweeper.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
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz 07/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2002
+!   Author(s): Thomas Bretz,  7/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: CheObs Software Development, 2000-2009
 !
 !
@@ -57,5 +57,5 @@
 #include <TInterpreter.h>
 
-#include "MHexagon.h"
+#include "MH.h"
 
 #include "MGeomPix.h"
@@ -82,5 +82,4 @@
         return;
 
-    fPixels->Delete();
     fText->Delete();
     fFlags->Delete();
@@ -88,5 +87,4 @@
     delete fText;
     delete fFlags;
-    delete fPixels;
 
     delete fGeomCam;
@@ -107,5 +105,5 @@
 
     Reset();
-    DrawHexagons();
+    AppendPad();
 }
 
@@ -113,10 +111,4 @@
 {
     Free();
-
-    //
-    //  Reset the display geometry
-    //
-    fW=0;
-    fH=0;
 
     //
@@ -138,23 +130,19 @@
     fText   = new TClonesArray("TText",    fNumPixels);
     fFlags  = new TClonesArray("TMarker",  fNumPixels);
-    fPixels = new TClonesArray("MHexagon", fNumPixels);
+    fColors.Set(fNumPixels);
+    //fPixels = new TClonesArray("MHexagon", fNumPixels);
 
     for (UInt_t i=0; i<fNumPixels; i++)
     {
-        MHexagon &h = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
-#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-        h.SetBit(kNoContextMenu|kCannotPick);
-#endif
+        const MGeom &pix = (*fGeomCam)[i];
 
         TText &t = *new ((*fText)[i]) TText;
         t.SetTextFont(122);
         t.SetTextAlign(22);   // centered/centered
-        t.SetTextSize(0.3*h.GetD()/fRange);
+        t.SetTextSize(0.3*pix.GetT()/fRange);
 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
         t.SetBit(kNoContextMenu|kCannotPick);
 #endif
 
-        const MGeomPix &pix = (*fGeomCam)[i];
-
         TMarker &m = *new ((*fFlags)[i]) TMarker(pix.GetX(), pix.GetY(), kOpenStar);
 #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
@@ -162,15 +150,4 @@
 #endif
     }
-}
-
-// ------------------------------------------------------------------------
-//
-// Draw all pixels of the camera
-//  (means apend all pixelobjects to the current pad)
-//
-void MineSweeper::DrawHexagons()
-{
-    for (UInt_t i=0; i<fNumPixels; i++)
-        (*this)[i].Draw();
 }
 
@@ -193,5 +170,5 @@
 //
 MineSweeper::MineSweeper()
-    : fGeomCam(NULL), fDone(NULL), fShow(NULL), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
+    : fGeomCam(NULL), fDone(NULL), fShow(NULL)
 {
     SetNewCamera(new MGeomCamMagic);
@@ -200,5 +177,5 @@
 
 MineSweeper::MineSweeper(const MGeomCam &geom)
-    : fGeomCam(NULL), fDone(NULL), fShow(NULL), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
+    : fGeomCam(NULL), fDone(NULL), fShow(NULL)
 {
     SetNewCamera(static_cast<MGeomCam*>(geom.Clone()));
@@ -218,10 +195,4 @@
     if (fDone)
         delete fDone;
-
-    if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)
-    {
-        fDrawingPad->RecursiveRemove(this);
-        delete fDrawingPad;
-    }
 }
 
@@ -234,48 +205,29 @@
 void MineSweeper::Paint(Option_t *opt)
 {
-    const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC());
-    const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC());
-
-    //
-    // Check for a change in width or height, and make sure, that the
-    // first call also sets the range
-    //
-    if (w*fH == h*fW && fW && fH)
-        return;
-
-    //
-    // Calculate aspect ratio (5/4=1.25 recommended)
-    //
-    const Double_t ratio = (Double_t)w/h;
-
-    Float_t x;
-    Float_t y;
-
-    if (ratio>1.0)
-    {
-        x = fRange*(ratio*2-1);
-        y = fRange;
-    }
-    else
-    {
-        x = fRange;
-        y = fRange/ratio;
-    }
-
-    fH = h;
-    fW = w;
-
-    //
-    // Set new range
-    //
-    fDrawingPad->Range(-fRange, -y, x, y);
-
-    //
-    // Adopt absolute sized of markers to relative range
-    //
+    const Float_t r = fGeomCam->GetMaxRadius();
+
+    MH::SetPadRange(-r, -r, r, r*1.1);
+
+    TAttLine line;
+    TAttFill fill;
+
+    // FIXME:
     for (UInt_t i=0; i<fNumPixels; i++)
     {
-        Float_t r = (*this)[i].GetD()*gPad->XtoAbsPixel(1)/325;
+        const MGeom &pix = (*fGeomCam)[i];
+
+        fill.SetFillColor(fColors[i]);
+        pix.PaintPrimitive(line, fill);
+
+        //
+        // Adopt absolute sized of markers to relative range
+        //
+        Float_t r = (*fGeomCam)[i].GetT()*gPad->XtoAbsPixel(1)/325;
         GetFlag(i)->SetMarkerSize(20.0*r/fRange);
+
+        if (pix.TestBit(kHasFlag))
+            GetFlag(i)->Paint();
+
+        GetText(i)->Paint();
     }
 }
@@ -293,21 +245,11 @@
     // gPad->SetFixedAspectRatio()
 
-    if (fDrawingPad)
-        return;
-
     //
     // if no canvas is yet existing to draw into, create a new one
     //
     if (!gPad)
-    {
-        /*TCanvas *c =*/ new TCanvas("MineSweeper", "Magic Mine Sweeper", 0, 0, 800, 800);
-        //c->ToggleEventStatus();
-        fIsAllocated = kTRUE;
-    }
-    else
-        fIsAllocated = kFALSE;
-
-    fDrawingPad = gPad;
-    fDrawingPad->SetBorderMode(0);
+        new TCanvas("MineSweeper", "Magic Mine Sweeper", 0, 0, 800, 800);
+
+    gPad->SetBorderMode(0);
 
     //
@@ -330,5 +272,4 @@
     //
     Reset();
-    DrawHexagons();
 }
 
@@ -357,11 +298,9 @@
     for (UInt_t i=0; i<fNumPixels; i++)
     {
-        Remove(GetText(i));
-        Remove(GetFlag(i));
-
-        (*this)[i].SetFillColor(kHidden);
+        fColors[i] = kHidden;
         (*fGeomCam)[i].ResetBit(kUserBits);
 
         GetFlag(i)->SetMarkerColor(kBlack);
+        GetText(i)->SetText(0, 0, "");
     }
     Update(fNumBombs);
@@ -378,8 +317,8 @@
     }
 
-    fDrawingPad->SetFillColor(22);
-
-#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-    fDrawingPad->SetBit(kNoContextMenu);
+    gPad->SetFillColor(22);
+
+#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
+    gPad->SetBit(kNoContextMenu);
     SetBit(kNoContextMenu);
 #endif
@@ -391,5 +330,5 @@
         if ((*fGeomCam)[j].TestBit(kHasBomb))
         {
-            (*this)[j].SetFillColor(kBlack);
+            fColors[j] = kBlack;
             GetFlag(j)->SetMarkerColor(kWhite);
         }
@@ -404,8 +343,8 @@
     fDone->Draw();
 
-    fDrawingPad->SetFillColor(col);
-
-#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-    fDrawingPad->ResetBit(kNoContextMenu);
+    gPad->SetFillColor(col);
+
+#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
+    gPad->ResetBit(kNoContextMenu);
     ResetBit(kNoContextMenu);
 #endif
@@ -419,11 +358,8 @@
 void MineSweeper::OpenHexagon(Int_t idx)
 {
-    MGeomPix &pix=(*fGeomCam)[idx];
+    MGeom &pix=(*fGeomCam)[idx];
 
     if (pix.TestBit(kIsVisible))
         return;
-
-    if (pix.TestBit(kHasFlag))
-        Remove(GetFlag(idx));
 
     pix.SetBit(kIsVisible);
@@ -435,23 +371,18 @@
             cnt++;
 
-    (*this)[idx].SetFillColor(fColorBombs[cnt]);
-
+    fColors[idx] = fColorBombs[cnt];
+
+    TString str;
     if (cnt)
-    {
-        TText *txt = GetText(idx);
-        TString str;
         str += cnt;
-        txt->SetText(pix.GetX(), pix.GetY(), str);
-        txt->Draw();
-        return;
-    }
+
+    TText *txt = GetText(idx);
+    txt->SetText(pix.GetX(), pix.GetY(), str);
+
+    if (cnt)
+        return;
 
     for (int j=0; j<pix.GetNumNeighbors(); j++)
         OpenHexagon(pix.GetNeighbor(j));
-}
-
-void MineSweeper::Remove(TObject *obj)
-{
-    fDrawingPad->RecursiveRemove(obj);
 }
 
@@ -479,5 +410,5 @@
     UInt_t idx;
     for (idx=0; idx<fNumPixels; idx++)
-        if ((*fPixels)[idx]->DistancetoPrimitive(px, py)==0)
+        if ((*fGeomCam)[idx].DistancetoPrimitive(px, py)<=0)
             break;
 
@@ -485,5 +416,5 @@
         return;
 
-    MGeomPix &pix=(*fGeomCam)[idx];
+    MGeom &pix=(*fGeomCam)[idx];
 
     if (event==kButton1Double)
@@ -496,12 +427,5 @@
 
     if (event==kButton1Down && !pix.TestBit(kIsVisible))
-    {
-        if (pix.TestBit(kHasFlag))
-            Remove(GetFlag(idx));
-        else
-            GetFlag(idx)->Draw();
-
         pix.InvertBit(kHasFlag);
-    }
 
     UInt_t vis=fNumBombs;
@@ -520,5 +444,5 @@
         Done("Great! Congratulations, you did it!", kGreen);
 
-    fDrawingPad->Modified();
+    gPad->Modified();
 
     /*
Index: trunk/MagicSoft/Mars/mtools/MineSweeper.h
===================================================================
--- trunk/MagicSoft/Mars/mtools/MineSweeper.h	(revision 9368)
+++ trunk/MagicSoft/Mars/mtools/MineSweeper.h	(revision 9369)
@@ -8,4 +8,7 @@
 #include <TClonesArray.h>
 #endif
+#ifndef ROOT_TArrayI
+#include <TArrayI.h>
+#endif
 
 class TText;
@@ -13,4 +16,5 @@
 class TVirtualPad;
 
+class MGeom;
 class MGeomCam;
 class MHexagon;
@@ -27,15 +31,11 @@
     Float_t        fRange;         // the range in millimeters of the present geometry
 
-    TClonesArray  *fPixels;        // array of all hexagons
     TClonesArray  *fText;          // array of all texts
     TClonesArray  *fFlags;         // array of all texts
 
+    TArrayI fColors;
+
     TText         *fDone;          // TText showing the 'Game over'
     TText         *fShow;          // TText showing the numbers of pixels and bombs
-
-    UInt_t         fW;             // Width of canvas
-    UInt_t         fH;             // Height of canvas
-    TVirtualPad   *fDrawingPad;    // pad in which we are drawing
-    Bool_t         fIsAllocated;
 
     enum
@@ -48,15 +48,12 @@
     };
 
-    MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
-
     TText   *GetText(Int_t i) { return (TText*)fText->At(i); }
     TMarker *GetFlag(Int_t i) { return (TMarker*)fFlags->At(i); }
 
-    void  Remove(TObject *);
     void  OpenHexagon(Int_t idx);
     void  Done(TString, Int_t);
     void  Update(Int_t);
     void  SetNewCamera(MGeomCam *);
-    void  DrawHexagons();
+    void  PaintPrimitives();
     void  Free();
     void  Init();
Index: trunk/MagicSoft/include-Classes/MMcFormat/MMcTrigHeader.hxx
===================================================================
--- trunk/MagicSoft/include-Classes/MMcFormat/MMcTrigHeader.hxx	(revision 9368)
+++ trunk/MagicSoft/include-Classes/MMcFormat/MMcTrigHeader.hxx	(revision 9369)
@@ -66,5 +66,5 @@
   void SetTrigPattern (UInt_t upi, UInt_t loi){
 
-    if (upi==loi==0) {
+    if (upi==0 && loi==0) {
       fTrigPattern[0]= (UInt_t) fThreshold[0];
       fTrigPattern[1]= (UInt_t) (100*fMultiplicity+fTopology);
