Index: trunk/MagicSoft/Mars/Makefile.rules
===================================================================
--- trunk/MagicSoft/Mars/Makefile.rules	(revision 9367)
+++ trunk/MagicSoft/Mars/Makefile.rules	(revision 9368)
@@ -37,8 +37,8 @@
 	-c $(INCLUDES) $(DEFINES) $(HEADERS) $(CINT)Incl.h $(CINT)LinkDef.h 
 
-%.d:	
+%.d:
 	@echo " - Generating dependencies" $@
-	$(ROOTSYS)/bin/rmkdepend -f- -Y -w 3000 -- $(INCLUDES) -- $(SRCFILES) -- $(PROGRAMS:=.cc) 2> /dev/null | \
-         sed 's/^\(.*\).o:/$@ \1.o:/' > $@
+	rmkdepend -f- -Y -w 3000 -- $(INCLUDES) -- $(SRCFILES) -- $(PROGRAMS:=.cc) 2> /dev/null | \
+        sed 's/^\(.*\).o:/$@ \1.o:/' > $@
 	echo "$@: Makefile" >> $@
 
@@ -104,5 +104,5 @@
 
 diff:
-	@cvs diff | grep -v "^? " > mars.diff
+	@cvs -d diff | grep -v "^? " > mars.diff
 
 zdiff:
Index: trunk/MagicSoft/Mars/ceres.rc
===================================================================
--- trunk/MagicSoft/Mars/ceres.rc	(revision 9367)
+++ trunk/MagicSoft/Mars/ceres.rc	(revision 9368)
@@ -117,4 +117,7 @@
 MSimBundlePhotons.FileName: mreflector/dwarf-apdmap.txt
 
+# Set the APD type (1: 30x30 <default>, 2: 60x60)
+#MSimAPD.Type: 1
+
 # --- MAGIC ---
 #MGeomCam.Constructor:   MGeomCamMagic(17.0)
Index: trunk/MagicSoft/Mars/mgeom/MGeom.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeom.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mgeom/MGeom.cc	(revision 9368)
@@ -0,0 +1,194 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2009
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// MGeom
+//
+// This container stores the geometry (position) information of
+// a single pixel together with the information about next neighbors.
+//
+//
+// Version 1:
+// ----------
+//  - first implementation (previously part of MGeomPix)
+//
+////////////////////////////////////////////////////////////////////////////
+#include "MGeom.h"
+
+#include <TMath.h>
+#include <TVector2.h>
+#include <TVirtualPad.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MGeomCam.h"
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Initializes one pixel
+//
+MGeom::MGeom(Float_t x, Float_t y, UInt_t s, UInt_t a)
+    : fX(x), fY(y), fA(0), fSector(s), fAidx(a), fUserBits(0)
+{
+    //  default constructor
+    SetNeighbors();
+}
+
+// --------------------------------------------------------------------------
+//
+// Return position as TVector2(fX, fY)
+//
+TVector2 MGeom::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 MGeom::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;
+
+    // FIXME
+    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 MGeom::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 MGeom::Print(Option_t *opt) const
+{
+    //   information about a pixel
+    gLog << all << MParContainer::GetDescriptor(*this) << ":  x/y=" << fX << "/" << fY << "mm ";
+    gLog << "A= " << fA << "mm² (";
+    for (int i=0; i<fNumNeighbors; i++)
+        gLog << fNeighbors[i] << (i<fNumNeighbors-1?",":"");
+    gLog << ")";
+}
+
+
+// ------------------------------------------------------------------------
+//
+// Return distance of center to coordinate origin: hypot(fX,fY)
+//
+Float_t MGeom::GetDist() const
+{
+    return TMath::Hypot(fX, fY);
+}
+
+// ------------------------------------------------------------------------
+//
+// Return distance of center to center of pix: hypot(fX-pix.fX,fY-pix.fY)
+//
+Float_t MGeom::GetDist(const MGeom &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 MGeom::GetAngle(const MGeom &pix) const
+{
+    return TMath::ATan2(fX - pix.GetX(), fY - pix.GetY());
+}
+
+// ------------------------------------------------------------------------
+//
+// Return the direction of the pixel pix w.r.t. this pixel.
+// Remark: This function assumes a simple geometry.
+//
+Int_t MGeom::GetDirection(const MGeom &pix) const
+{
+    const Double_t phi = GetAngle(pix)*TMath::RadToDeg();
+
+    if (phi<-165) return kTop;
+    if (phi<-105) return kRightTop;
+    if (phi< -75) return kRight;
+    if (phi< -15) return kRightBottom;
+    if (phi<  15) return kBottom;
+    if (phi<  75) return kLeftBottom;
+    if (phi< 105) return kLeft;
+    if (phi< 165) return kLeftTop;
+
+    return kTop;
+}
+
+// ------------------------------------------------------------------------
+//
+// This implementation is based on the use of DistanceToPrimitive
+// (capital T) which should be implemented in user coordinates.
+//
+Int_t MGeom::DistancetoPrimitive(Int_t px, Int_t py)
+{
+    const Double_t x = gPad->AbsPixeltoX(px);
+    const Double_t y = gPad->AbsPixeltoY(py);
+
+    return TMath::Nint(DistanceToPrimitive(x, y));
+}
Index: trunk/MagicSoft/Mars/mgeom/MGeom.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeom.h	(revision 9368)
+++ trunk/MagicSoft/Mars/mgeom/MGeom.h	(revision 9368)
@@ -0,0 +1,109 @@
+#ifndef MARS_MGeom
+#define MARS_MGeom
+
+#ifndef ROOT_TObject
+#include <TObject.h>
+#endif
+
+class MGeomCam;
+
+class TAttLine;
+class TAttFill;
+class TVector2;
+
+class MGeom : public TObject
+{
+public:
+    enum {
+        kRightTop,
+        kRight,
+        kRightBottom,
+        kLeftBottom,
+        kLeft,
+        kLeftTop,
+        kTop,
+        kBottom
+    };
+
+private:
+    enum {
+        kIsInOutermostRing = 0,
+        kIsInOuterRing     = 1,
+    };
+
+protected:
+    Float_t fX;            // [mm]   the x coordinate of the center
+    Float_t fY;            // [mm]   the y coordinate of the center
+    Float_t fA;            // [mm^2] Area of the pixel
+
+    UInt_t fSector;        // Number of sector the pixels corresponds to
+    UInt_t fAidx;          // Area index of the pixel
+
+private:
+    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)
+
+    Byte_t fUserBits;
+
+public:
+    MGeom(Float_t x=0, Float_t y=0, UInt_t s=0, UInt_t aidx=0);
+
+    void Copy(TObject &obj) const
+    {
+        MGeom &pix = (MGeom&)obj;
+        pix.fX = fX;
+        pix.fY = fY;
+        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];
+
+        TObject::Copy(obj);
+    }
+
+    void Print(Option_t *opt=NULL) const;
+
+    void Set(Float_t x, Float_t y, UInt_t s=0, UInt_t aidx=0) { fX=x; fY=y; 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; }
+
+    virtual Float_t GetT() const = 0;    // Maximum elongation
+
+    UInt_t  GetSector() const { return fSector; }
+
+    TVector2 GetP() const;
+
+    Float_t GetDist() const;
+    Float_t GetDist(const MGeom &pix) const;
+    Float_t GetAngle(const MGeom &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); }
+
+    virtual Bool_t IsInside(Float_t px, Float_t py) const = 0;
+    Int_t  GetDirection(const MGeom &pix) const;
+
+    virtual Float_t DistanceToPrimitive(Float_t px, Float_t py) const = 0;
+    Int_t DistancetoPrimitive(Int_t px, Int_t py);
+
+    virtual void PaintPrimitive(const TAttLine &line, const TAttFill &fill, Double_t scalexy=1, Double_t scaled=1) const = 0;
+
+    ClassDef(MGeom, 1) // Geometry class describing the basics of a pixel
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mgeom/MGeomRectangle.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomRectangle.cc	(revision 9368)
+++ trunk/MagicSoft/Mars/mgeom/MGeomRectangle.cc	(revision 9368)
@@ -0,0 +1,118 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 3/2009 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2009
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// MGeomRectangle
+//
+// This container describes the geometry of a rectangualr shaped pixel
+//
+////////////////////////////////////////////////////////////////////////////
+#include "MGeomRectangle.h"
+
+#include <TBox.h>
+#include <TMath.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MGeomRectangle);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Initializes one pixel
+//
+MGeomRectangle::MGeomRectangle(Float_t x, Float_t y, Float_t w, Float_t h, UInt_t s, UInt_t a)
+    : MGeom(x, y, s, a)
+{
+    //  default constructor
+    SetSize(w, h);
+    SetNeighbors();
+}
+
+// ------------------------------------------------------------------------
+//
+// compute the distance of a point (px,py) to the Hexagon center in
+// MGeomPix coordinates. Return kTRUE if inside.
+//
+Bool_t MGeomRectangle::IsInside(Float_t px, Float_t py) const
+{
+    if (TMath::Abs(px-fX)>fW/2)
+        return kFALSE;
+
+    if (TMath::Abs(py-fY)>fH/2)
+        return kFALSE;
+
+    return kTRUE;
+}
+
+// ------------------------------------------------------------------------
+//
+// compute the distance of a point (px,py) to the Hexagon center in world
+// coordinates. Return -1 if inside.
+//
+Float_t MGeomRectangle::DistanceToPrimitive(Float_t px, Float_t py) const
+{
+    return IsInside(px, py) ? -1 : 9999999;
+}
+
+// ------------------------------------------------------------------------
+//
+// Implementation of PaintPrimitive drwaing a rectangular pixel
+//
+void MGeomRectangle::PaintPrimitive(const TAttLine &line, const TAttFill &fill, Double_t scalexy, Double_t scaled) const
+{
+    const Double_t w = fW*scaled/2;
+    const Double_t h = fH*scaled/2;
+    const Double_t x = fX*scalexy;
+    const Double_t y = fY*scalexy;
+
+    TBox box;
+
+    fill.Copy(box);
+    line.Copy(box);
+
+    box.PaintBox(x-w, y-h, x+w, y+h, "l");
+}
+
+// ------------------------------------------------------------------------
+//
+// Return the distance of the two opposite edges.
+//
+Float_t MGeomRectangle::GetT() const
+{
+    return TMath::Hypot(fW, fH);
+}
+
+// --------------------------------------------------------------------------
+//
+// Print the geometry information of one pixel.
+//
+void MGeomRectangle::Print(Option_t *opt) const
+{
+    MGeom::Print(opt);
+    gLog << " w=" << fW << "mm h=" << fH << "mm" << endl;
+}
Index: trunk/MagicSoft/Mars/mgeom/MGeomRectangle.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomRectangle.h	(revision 9368)
+++ trunk/MagicSoft/Mars/mgeom/MGeomRectangle.h	(revision 9368)
@@ -0,0 +1,43 @@
+#ifndef MARS_MGeomRectangle
+#define MARS_MGeomRectangle
+
+#ifndef MARS_MGeom
+#include "MGeom.h"
+#endif
+
+class MGeomRectangle : public MGeom
+{
+private:
+    Float_t fW;
+    Float_t fH;
+
+public:
+    MGeomRectangle(Float_t x=0, Float_t y=0, Float_t w=1, Float_t h=1, UInt_t s=0, UInt_t aidx=0);
+
+    void Copy(TObject &obj) const
+    {
+        MGeomRectangle &pix = (MGeomRectangle&)obj;
+
+        pix.fW = fW;
+        pix.fH = fH;
+
+        MGeom::Copy(obj);
+        TObject::Copy(obj);
+    }
+
+    void    SetSize(Float_t w, Float_t h=-1) { fW=w; fH=h<0?fW:h; fA=fW*fH; }
+
+    Float_t GetW() const { return fW; }
+    Float_t GetH() const { return fH; }
+    Float_t GetT() const;
+
+    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;
+
+    ClassDef(MGeomRectangle, 1) // Geometry class describing the rectangular geometry of one pixel
+};
+
+#endif
