Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9384)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9385)
@@ -18,4 +18,59 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2009/03/04 Thomas Bretz
+
+   * datacenter/macros/plotdb.C:
+     - updated some binnings
+
+   * mgeom/GeomLinkDef.h:
+     - added MGeomCamMagicII
+
+   * mgeom/MGeom.[h,cc]:
+     - added option to set position
+     - removed DistanceToPrimitive, use IsInside instead
+
+   * mgeom/MGeomCam.[h,cc]:
+     - added a virtual function to CreateNN
+     - added a workaround after reading by calling CreateNN
+       because with the last changes the pixel indices get lost
+
+   * mgeom/MGeomCamCT1.[h,cc]:
+     - now derives from MGeomCamDwarf
+     - accordingly increased version number
+
+   * mgeom/MGeomCamDwarf.[h,cc]:
+     - removed Clone -> now in MGeomCam
+
+   * mgeom/MGeomCamMagic.[h,cc]:
+     - added MGeomCamMagicII <preliminary>
+
+   * mgeom/MGeomCamSquare.[h,cc]:
+     - removed creation of next neighbors -> now automatic
+
+   * mgeom/MGeomPix.[h,cc]:
+     - added rotation angle in terms of cos(phi) and sin(phi)
+     - rotate in PaintPrimitive
+     - adapted IsInside accordingly
+
+   * mgeom/MGeomRectangle.[h,cc]:
+     - if only width is given assume a square
+     - make sure that the box is correctly painted for all root versions
+     - fixed distance to farthest point
+
+   * mgui/MHexagon.[h,cc]:
+     - removed obsolete dependence on MGeomPix
+
+   * mhist/MHCamera.cc, mtools/MagicJam.cc:
+     - replaced DistanceToPrimitive by IsInside
+
+   * mjobs/MJSimulation.cc:
+     - replaced accidental _I_ in file names by _Y_
+
+   * mreport/MReportCC.[h,cc]:
+     - added version >=200809030
+     - improved modularity of code
+
+
+
  2009/03/03 Thomas Bretz
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 9384)
+++ trunk/MagicSoft/Mars/NEWS	(revision 9385)
@@ -34,4 +34,6 @@
 
    * added support for Arehucas Version >= 200812140
+
+   * added support for Arehucas Version >= 200809030
 
  ;mars
Index: trunk/MagicSoft/Mars/datacenter/macros/plotdb.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/plotdb.C	(revision 9384)
+++ trunk/MagicSoft/Mars/datacenter/macros/plotdb.C	(revision 9385)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.54 2009-01-29 09:24:30 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.55 2009-03-04 18:45:26 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -559,5 +559,5 @@
     plot.Plot("Calibration.fArrTimeMeanInner", 0, 40.0, 0.1);
     plot.SetDescription("RMS Arrival Time inner Camera;\\sigma_{T,I} [sl]", "RmsArrTmI");
-    plot.Plot("Calibration.fArrTimeRmsInner",  0, 4.5, 0.01);
+    plot.Plot("Calibration.fArrTimeRmsInner",  0, 6.5, 0.01);
     plot.SetDescription("Number of unsuitable pixels inner Camera;N_{I}", "UnsuitI");
     plot.Plot("Calibration.fUnsuitableInner",  0, 75, 1);
@@ -616,5 +616,5 @@
     plot.Plot("Star.fPSF",                     0,  30, 0.5);
     plot.SetDescription("Muon Calibration Ratio Data/MC;r [1]", "MuonCal");
-    plot.Plot("Star.fRatio",                   0, 200, 0.5);
+    plot.Plot("Star.fRatio",                   50, 150, 0.5);
     plot.SetDescription("Muon Rate after Muon Cuts;R [Hz]");
     plot.Plot("Star.fMuonRate",                0, 2.0, 0.05);
@@ -627,5 +627,5 @@
     plot.Plot("Star.fInhomogeneity",           0, 100, 1);
     plot.SetDescription("Camera Spark Rate;R [Hz]", "Sparks");
-    plot.Plot("Star.fSparkRate",               0.075, 2.425, 0.05);
+    plot.Plot("Star.fSparkRate",               0.075, 7.425, 0.05);
     plot.SetDescription("Relative effective on time;T_{eff}/T_{obs} [ratio]", "RelTime");
     plot.Plot("Star.fEffOnTime/Sequences.fRunTime",    0.006, 1.506, 0.01);
Index: trunk/MagicSoft/Mars/mgeom/GeomLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/GeomLinkDef.h	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/GeomLinkDef.h	(revision 9385)
@@ -18,4 +18,5 @@
 #pragma link C++ class MGeomCamDwarf+;
 #pragma link C++ class MGeomCamMagic+;
+#pragma link C++ class MGeomCamMagicII+;
 #pragma link C++ class MGeomCamSquare+;
 //#pragma link C++ class MGeomCamMagicHG+;
Index: trunk/MagicSoft/Mars/mgeom/MGeom.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeom.cc	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeom.cc	(revision 9385)
@@ -69,4 +69,10 @@
 }
 
+void MGeom::SetP(const TVector2 &v)
+{
+    fX = v.X();
+    fY = v.Y();
+}
+
 // --------------------------------------------------------------------------
 //
@@ -125,5 +131,5 @@
     //   information about a pixel
     gLog << all << MParContainer::GetDescriptor(*this) << ":  x/y=" << fX << "/" << fY << "mm ";
-    gLog << "A= " << fA << "mm² (";
+    gLog << "A= " << fA << "mm" << UTF8::kSquare << " (";
     for (int i=0; i<fNumNeighbors; i++)
         gLog << fNeighbors[i] << (i<fNumNeighbors-1?",":"");
@@ -191,4 +197,5 @@
     const Double_t y = gPad->AbsPixeltoY(py);
 
-    return TMath::Nint(DistanceToPrimitive(x, y));
-}
+    return IsInside(x, y) ? -1 : 999999;
+}
+
Index: trunk/MagicSoft/Mars/mgeom/MGeom.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeom.h	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeom.h	(revision 9385)
@@ -40,5 +40,5 @@
     UInt_t fAidx;          // Area index of the pixel
 
-private:
+protected:
     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)
@@ -68,4 +68,6 @@
 
     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 SetP(Float_t x, Float_t y) { fX=x; fY=y; }
+    void SetP(const TVector2 &v);
 
     void SetNeighbors(Short_t i0=-1, Short_t i1=-1, Short_t i2=-1,
@@ -99,5 +101,4 @@
     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);
 
Index: trunk/MagicSoft/Mars/mgeom/MGeomCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 9385)
@@ -97,4 +97,19 @@
 }
 
+
+// --------------------------------------------------------------------------
+//
+// To make sure that everything is correctly initialized when
+// cloned we call InitGeometry after cloning. This repairs
+// a few I/O problems mainly with files written with older
+// MARS versions (see also StreamerWorkaround)
+//
+TObject *MGeomCam::Clone(const char *newname) const
+{
+    MGeomCam *clone = (MGeomCam*)MParContainer::Clone(newname);
+    clone->InitGeometry();
+    return clone;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -551,4 +566,47 @@
 // --------------------------------------------------------------------------
 //
+//  This fills the next neighbor information from a table into the pixel
+//  objects. An overloaded function must call SortNeighbors()
+//  at the end.
+//
+// All pixel swith a center withing 1.75*GetT() are considered neiighbors,
+// Only six neighbors are allowed.
+//
+void MGeomCam::CreateNN()
+{
+    TArrayI nn(6);
+
+    for (UInt_t i=0; i<GetNumPixels(); i++)
+    {
+        MGeom &pix = (*this)[i];
+
+        Int_t k = 0;
+        nn.Reset(-1);
+
+        for (UInt_t j=0; j<GetNumPixels(); j++)
+        {
+            if (i==j)
+                continue;
+
+            if (pix.GetDist((*this)[j])>pix.GetT()*1.75)
+                continue;
+
+            if (k==6)
+            {
+                *fLog << err << "ERROR - MGeomCam::CreateNN: Pixel " << j << " has too many neighbors." << endl;
+                break;
+            }
+
+            nn[k++] = j;
+        }
+
+        pix.SetNeighbors(nn[0], nn[1], nn[2], nn[3], nn[4], nn[5]);
+    }
+
+    SortNeighbors();
+}
+
+// --------------------------------------------------------------------------
+//
 // This workaround reproduces (as much as possible) the contents
 // of fPixels which got lost writing MGeomCam in which the
@@ -560,10 +618,22 @@
 // MUST call this function after reading.
 //
+// Furthermore since we moved all contents of MGeomPix to its
+// new base class the contents of fNeighbors is not read anymore
+// although all other contents is read correctly. Therefore we have
+// top recreate the neighbor table.
+//
 void MGeomCam::StreamerWorkaround()
 {
-    if (fNumPixels==0 || !fPixels.IsEmpty())
+    if (fNumPixels==0)
         return;
 
-    TObject *cam = (TObject*)IsA()->New();
+
+    if (!fPixels.IsEmpty())
+    {
+        CreateNN();
+        return;
+    }
+
+    const TObject *cam = (TObject*)IsA()->New();
     cam->Copy(*this);
     delete cam;
@@ -592,4 +662,9 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This deletes the pixel i and sets it to a clone of pix.
+// If i>=fNumPixels it is just ignored.
+//
 void MGeomCam::SetAt(UInt_t i, const MGeom &pix)
 {
Index: trunk/MagicSoft/Mars/mgeom/MGeomCam.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCam.h	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCam.h	(revision 9385)
@@ -47,4 +47,8 @@
     void CalcNumAreas();
     void InitOuterRing();
+
+    virtual void CreateNN();
+
+protected:
     void SortNeighbors();
 
@@ -53,4 +57,5 @@
     MGeomCam(const MGeomCam &cam) { cam.Copy(*this); }
 
+    TObject *Clone(const char *name="") const;
     void Copy(TObject &o) const;
 
@@ -65,4 +70,5 @@
     void InitGeometry()
     {
+        CreateNN();
         CalcNumSectors();
         CalcNumAreas();
@@ -70,5 +76,4 @@
         CalcPixRatio();
         InitOuterRing();
-        SortNeighbors();
     }
 
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.cc	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.cc	(revision 9385)
@@ -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-2003
+!   Copyright: MAGIC Software Development, 2000-2009
 !
 !
@@ -32,228 +31,9 @@
 // is calculated (for Algorithm see CreateCam
 //
+// Class Version 2:
+// ----------------
+//  - derived from MGeoMCamDwarf
+//
 ////////////////////////////////////////////////////////////////////////////
+
 #include "MGeomCamCT1.h"
-
-#include <math.h>     // floor
-
-/*
- #include "MLog.h"
- #include "MLogManip.h"
- */
-
-#include "MGeomPix.h"
-
-ClassImp(MGeomCamCT1);
-
-// --------------------------------------------------------------------------
-//
-//  CT1 camera has 127 pixels. For geometry and Next Neighbor info see
-//  CreateCam and CreateNN
-//
-MGeomCamCT1::MGeomCamCT1(const char *name)
-    : MGeomCam(127, 4.88, name, "Geometry information of CT1 camera")
-{
-    CreateCam();
-    CreateNN();
-    InitGeometry();
-} 
-
-// --------------------------------------------------------------------------
-//
-//  Create Next Neighbors: Fill the NN Info into the pixel objects.
-//
-void MGeomCamCT1::CreateNN()
-{ 
-    const Short_t nn[127][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},
-      {  1,   8,  18,  19,  20,  36},
-      {  1,   2,   7,   9,  20,  21},
-      {  2,   8,  10,  21,  22,  23},
-      {  2,   3,   9,  11,  23,  24},  // 10
-      {  3,  10,  12,  24,  25,  26},
-      {  3,   4,  11,  13,  26,  27},
-      {  4,  12,  14,  27,  28,  29},
-      {  4,   5,  13,  15,  29,  30},
-      {  5,  14,  16,  30,  31,  32},
-      {  5,   6,  15,  17,  32,  33},
-      {  6,  16,  18,  33,  34,  35},
-      {  1,   6,   7,  17,  35,  36},
-      {  7,  20,  36,  37,  38,  60},
-      {  7,   8,  19,  21,  38,  39},  // 20
-      {  8,   9,  20,  22,  39,  40},
-      {  9,  21,  23,  40,  41,  42},
-      {  9,  10,  22,  24,  42,  43},
-      { 10,  11,  23,  25,  43,  44},
-      { 11,  24,  26,  44,  45,  46},
-      { 11,  12,  25,  27,  46,  47},
-      { 12,  13,  26,  28,  47,  48},
-      { 13,  27,  29,  48,  49,  50},
-      { 13,  14,  28,  30,  50,  51},
-      { 14,  15,  29,  31,  51,  52},  // 30
-      { 15,  30,  32,  52,  53,  54},
-      { 15,  16,  31,  33,  54,  55},
-      { 16,  17,  32,  34,  55,  56},
-      { 17,  33,  35,  56,  57,  58},
-      { 17,  18,  34,  36,  58,  59},
-      {  7,  18,  19,  35,  59,  60},
-      { 19,  38,  60,  61,  62,  90},
-      { 19,  20,  37,  39,  62,  63},
-      { 20,  21,  38,  40,  63,  64},
-      { 21,  22,  39,  41,  64,  65},  // 40
-      { 22,  40,  42,  65,  66,  67},
-      { 22,  23,  41,  43,  67,  68},
-      { 23,  24,  42,  44,  68,  69},
-      { 24,  25,  43,  45,  69,  70},
-      { 25,  44,  46,  70,  71,  72},
-      { 25,  26,  45,  47,  72,  73},
-      { 26,  27,  46,  48,  73,  74},
-      { 27,  28,  47,  49,  74,  75},
-      { 28,  48,  50,  75,  76,  77},
-      { 28,  29,  49,  51,  77,  78},  // 50
-      { 29,  30,  50,  52,  78,  79},
-      { 30,  31,  51,  53,  79,  80},
-      { 31,  52,  54,  80,  81,  82},
-      { 31,  32,  53,  55,  82,  83},
-      { 32,  33,  54,  56,  83,  84},
-      { 33,  34,  55,  57,  84,  85},
-      { 34,  56,  58,  85,  86,  87},
-      { 34,  35,  57,  59,  87,  88},
-      { 35,  36,  58,  60,  88,  89},
-      { 19,  36,  37,  59,  89,  90},  // 60
-      { 37,  62,  90,  91,  92, 126},
-      { 37,  38,  61,  63,  92,  93},
-      { 38,  39,  62,  64,  93,  94},
-      { 39,  40,  63,  65,  94,  95},
-      { 40,  41,  64,  66,  95,  96},
-      { 41,  65,  67,  96,  97,  98},
-      { 41,  42,  66,  68,  98,  99},
-      { 42,  43,  67,  69,  99, 100},
-      { 43,  44,  68,  70, 100, 101},
-      { 44,  45,  69,  71, 101, 102},  // 70
-      { 45,  70,  72, 102, 103, 104},
-      { 45,  46,  71,  73, 104, 105},
-      { 46,  47,  72,  74, 105, 106},
-      { 47,  48,  73,  75, 106, 107},
-      { 48,  49,  74,  76, 107, 108},
-      { 49,  75,  77, 108, 109, 110},
-      { 49,  50,  76,  78, 110, 111},
-      { 50,  51,  77,  79, 111, 112},
-      { 51,  52,  78,  80, 112, 113},
-      { 52,  53,  79,  81, 113, 114},  // 80
-      { 53,  80,  82, 114, 115, 116},
-      { 53,  54,  81,  83, 116, 117},
-      { 54,  55,  82,  84, 117, 118},
-      { 55,  56,  83,  85, 118, 119},
-      { 56,  57,  84,  86, 119, 120},
-      { 57,  85,  87, 120, 121, 122},
-      { 57,  58,  86,  88, 122, 123},
-      { 58,  59,  87,  89, 123, 124},
-      { 59,  60,  88,  90, 124, 125},
-      { 37,  60,  61,  89, 125, 126},  // 90
-      { 61,  92, 126,  -1,  -1,  -1},
-      { 61,  62,  91,  93,  -1,  -1},
-      { 62,  63,  92,  94,  -1,  -1},
-      { 63,  64,  93,  95,  -1,  -1},
-      { 64,  65,  94,  96,  -1,  -1},
-      { 65,  66,  95,  97,  -1,  -1},
-      { 66,  96,  98,  -1,  -1,  -1},
-      { 66,  67,  97,  99,  -1,  -1},
-      { 67,  68,  98, 100,  -1,  -1},
-      { 68,  69,  99, 101,  -1,  -1},  // 100
-      { 69,  70, 100, 102,  -1,  -1},
-      { 70,  71, 101, 103,  -1,  -1},
-      { 71, 102, 104,  -1,  -1,  -1},
-      { 71,  72, 103, 105,  -1,  -1},
-      { 72,  73, 104, 106,  -1,  -1},
-      { 73,  74, 105, 107,  -1,  -1},
-      { 74,  75, 106, 108,  -1,  -1},
-      { 75,  76, 107, 109,  -1,  -1},
-      { 76, 108, 110,  -1,  -1,  -1},
-      { 76,  77, 109, 111,  -1,  -1},  // 110
-      { 77,  78, 110, 112,  -1,  -1},
-      { 78,  79, 111, 113,  -1,  -1},
-      { 79,  80, 112, 114,  -1,  -1},
-      { 80,  81, 113, 115,  -1,  -1},
-      { 81, 114, 116,  -1,  -1,  -1},
-      { 81,  82, 115, 117,  -1,  -1},
-      { 82,  83, 116, 118,  -1,  -1},
-      { 83,  84, 117, 119,  -1,  -1},
-      { 84,  85, 118, 120,  -1,  -1},
-      { 85,  86, 119, 121,  -1,  -1},  // 120
-      { 86, 120, 122,  -1,  -1,  -1},
-      { 86,  87, 121, 123,  -1,  -1},
-      { 87,  88, 122, 124,  -1,  -1},
-      { 88,  89, 123, 125,  -1,  -1},
-      { 89,  90, 124, 126,  -1,  -1},
-      { 61,  90,  91, 125,  -1,  -1}   // 126
-  };
-
-  for (Int_t i=0; i<127; i++)
-      (*this)[i].SetNeighbors(nn[i][0], nn[i][1], nn[i][2],
-                              nn[i][3], nn[i][4], nn[i][5]);
-}
-
-// --------------------------------------------------------------------------
-//
-//  Calculate the geometry information of CT1 and fill this information
-//  into the pixel objects.
-//
-void MGeomCamCT1::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 = 21;    // units are mm
-    const Float_t kS32  = sqrt(3)/2;
-
-    //
-    //  add the first pixel to the list
-    //
-    Int_t pixnum = 1;
-
-    SetAt(0, MGeomPix(0, 0, diameter));
-
-    for (Int_t ring=1; ring<7; ring++)
-    {
-        //
-        // calc. coords for this ring counting from the
-        // starting number to the ending number
-        //
-        for (int i=0; i<ring; i++)
-            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/MGeomCamCT1.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.h	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.h	(revision 9385)
@@ -2,20 +2,17 @@
 #define MARS_MGeomCamCT1
 
-#ifndef MARS_MGeomCam
-#include "MGeomCam.h"
+#ifndef MARS_MGeomCamDwarf
+#include "MGeomCamDwarf.h"
 #endif
 
-class MGeomCamCT1 : public MGeomCam
+class MGeomCamCT1 : public MGeomCamDwarf
 {
-private:
+public:
+    MGeomCamCT1(const char *name=NULL) : MGeomCamDwarf(6, 21, 4.88, name)
+    {
+        SetTitle("Geometry information of HEGRA CT1 Camera");
+    }
 
-    void CreateCam();
-    void CreateNN();
-
-public:
-
-    MGeomCamCT1(const char *name=NULL);
-
-    ClassDef(MGeomCamCT1, 1)		// Geometry class for the CT1 camera
+    ClassDef(MGeomCamCT1, 2) // Geometry class for the CT1 camera
 };
 
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.cc	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.cc	(revision 9385)
@@ -63,5 +63,4 @@
 {
     CreateCam(21, 9.5);
-    CreateNN();
     InitGeometry();
 }
@@ -77,5 +76,4 @@
 {
     CreateCam(diameter, diameter<=0 ? rad : rad/diameter);
-    CreateNN();
     InitGeometry();
 }
@@ -91,18 +89,5 @@
 {
     CreateCam(diameter, rings);
-    CreateNN();
     InitGeometry();
-}
-
-// --------------------------------------------------------------------------
-//
-//  Create a clone of this container. This is very easy, because we
-//  simply have to create a new object of the same type.
-//
-TObject *MGeomCamDwarf::Clone(const char *newname) const
-{
-    MGeomCam *cam = new MGeomCam(*this);
-    cam->InitGeometry();
-    return cam;
 }
 
@@ -136,5 +121,5 @@
 Double_t MGeomCamDwarf::CalcXY(Int_t dir, Int_t ring, Int_t i, Double_t &x, Double_t &y)
 {
-    const Double_t kSqrt32 = MGeomPix::gsTan60/2;
+    const Double_t kSqrt32 = MGeomPix::gsSin60;
 
     switch (dir)
@@ -308,31 +293,2 @@
     }
 }
-
-// --------------------------------------------------------------------------
-//
-//  This fills the next neighbor information from a table into the pixel
-//  objects.
-//
-void MGeomCamDwarf::CreateNN()
-{
-    TArrayI nn(6);
-
-    for (UInt_t i=0; i<GetNumPixels(); i++)
-    {
-        MGeomPix &pix = static_cast<MGeomPix&>((*this)[i]);
-
-        Int_t k = 0;
-        nn.Reset(-1);
-
-        for (UInt_t j=0; j<GetNumPixels(); j++)
-        {
-            if (i==j)
-                continue;
-
-            if (pix.GetDist((*this)[j])<pix.GetD()*1.5)
-                nn[k++] = j;
-        }
-
-        pix.SetNeighbors(nn[0], nn[1], nn[2], nn[3], nn[4], nn[5]);
-    }
-}
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.h	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.h	(revision 9385)
@@ -18,5 +18,4 @@
     void  CreateCam(Double_t diameter, Double_t rad);
     void  CreateCam(Double_t diameter, Int_t rings);
-    void  CreateNN();
 
 public:
@@ -26,6 +25,4 @@
     MGeomCamDwarf(const char *name=NULL);
 
-    TObject *Clone(const char *newname) const;
-
     Bool_t HitFrame(MQuaternion p, const MQuaternion &u) const;
 
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.cc	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.cc	(revision 9385)
@@ -47,5 +47,4 @@
 {
     CreateCam();
-    CreateNN();
     InitGeometry();
 }
@@ -61,5 +60,4 @@
 {
     CreateCam();
-    CreateNN();
     InitGeometry();
 }
@@ -77,5 +75,4 @@
     // 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);
 
@@ -248,80 +245,5 @@
         -034.641                                                                         // 576
     };
-/*
-    const Float_t dtemp[577] = {
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  //   0
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  //   8
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  //  16
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  //  24
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  //  32
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  //  40
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  //  48
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  //  56
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  //  64
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  //  72
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  //  80
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  //  88
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  //  96
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 104
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 112
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 120
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 128
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 136
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 144
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 152
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 160
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 168
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 176
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 184
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 192
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 200
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 208
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 216
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 224
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 232
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 240
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 248
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 256
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 264
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 272
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 280
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 288
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 296
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 304
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 312
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 320
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 328
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 336
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 344
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 352
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 360
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 368
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 376
-        30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00, 30.00,  // 384
-        30.00, 30.00, 30.00, 30.00, 30.00, 60.00, 60.00, 60.00,  // 392
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 400
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 408
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 416
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 424
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 432
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 440
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 448
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 456
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 464
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 472
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 480
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 488
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 496
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 504
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 512
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 520
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 528
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 536
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 544
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 552
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 560
-        60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00, 60.00,  // 568
-        60.00  };                                                // 576
-*/
+
     const Byte_t sector[577] = {
         0, 1, 2, 3, 4, 5, 6, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
@@ -955,3 +877,66 @@
         (*this)[i].SetNeighbors(nn[i][0], nn[i][1], nn[i][2],
                                 nn[i][3], nn[i][4], nn[i][5]);
+
+    SortNeighbors();
 }
+
+// --------------------------------------------------------------------------
+//
+//  Magic camera has 913 pixels. For geometry and Next Neighbor info see
+//  CreateCam and CreateNN
+//
+MGeomCamMagicII::MGeomCamMagicII(const char *name)
+    : MGeomCamDwarf(475., 30, 17, name)
+{
+    SetTitle("Geometry information of Magic II Camera");
+    Rotate();
+}
+
+// --------------------------------------------------------------------------
+//
+//  Magic II camera has 913 pixels. For geometry and Next Neighbor info see
+//  CreateCam and CreateNN. You can give the distance dist from
+//  the mirror center to the focal plane.
+//
+MGeomCamMagicII::MGeomCamMagicII(Double_t dist, const char *name)
+    : MGeomCamDwarf(475., 30, dist, name)
+{
+    SetTitle("Geometry information of Magic II Camera");
+    Rotate();
+}
+
+// --------------------------------------------------------------------------
+//
+// Rotate all pixels by 30deg
+//
+void MGeomCamMagicII::Rotate()
+{
+    const Double_t phi = 30*TMath::DegToRad();
+
+    const TVector2 v(TMath::Cos(phi), TMath::Sin(phi));
+
+    for (UInt_t i=0; i<GetNumPixels(); i++)
+    {
+        MGeomPix &pix = static_cast<MGeomPix&>(operator[](i));
+
+        pix.SetP(pix.GetP()*v, pix.GetP()^v);
+        pix.SetPhi(phi);
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// 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 MGeomCamMagicII::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.PropagateZ(u, GetCameraDist()*100);
+
+    return TMath::Abs(p.X())<65 && TMath::Abs(p.Y())<65;
+}
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.h	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.h	(revision 9385)
@@ -2,6 +2,6 @@
 #define MARS_MGeomCamMagic
 
-#ifndef MARS_MGeomCam
-#include "MGeomCam.h"
+#ifndef MARS_MGeomCamDwarf
+#include "MGeomCamDwarf.h"
 #endif
 
@@ -21,4 +21,18 @@
 };
 
+class MGeomCamMagicII : public MGeomCamDwarf
+{
+private:
+    void Rotate();
+
+public:
+    MGeomCamMagicII(const char *name=NULL);
+    MGeomCamMagicII(Double_t dist, const char *name=NULL);
+
+    Bool_t HitFrame(MQuaternion p, const MQuaternion &u) const;
+
+    ClassDef(MGeomCamMagicII, 1)		// Geometry class for the Magic camera
+};
+
 #endif
 
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamSquare.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamSquare.cc	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamSquare.cc	(revision 9385)
@@ -89,20 +89,4 @@
     for (Short_t x=0; x<nx; x++)
         for (Short_t y=0; y<ny; y++)
-        {
-            const Short_t idx = x*ny+y;
-
-            SetAt(idx, MGeomRectangle((0.5*nx-x)*diameter, (0.5*ny-y)*diameter, diameter));
-
-            const Short_t n0 = x==nx-1 ? -1 : idx+ny;
-            const Short_t n1 = x==0    ? -1 : idx-ny;
-            const Short_t n2 = y==ny-1 ? -1 : idx+1;
-            const Short_t n3 = y==0    ? -1 : idx-1;
-
-            Short_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]);
-        }
+            SetAt(x*ny+y, MGeomRectangle((0.5*nx-x)*diameter, (0.5*ny-y)*diameter, diameter));
 }
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamSquare.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamSquare.h	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamSquare.h	(revision 9385)
@@ -10,5 +10,4 @@
 private:
     void CreateCam(Short_t x, Short_t y, Double_t diameter);
-    void CreateNN();
 
 public:
Index: trunk/MagicSoft/Mars/mgeom/MGeomPix.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomPix.cc	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeomPix.cc	(revision 9385)
@@ -78,5 +78,6 @@
 // Initializes one pixel
 //
-MGeomPix::MGeomPix(Float_t x, Float_t y, Float_t r, UInt_t s, UInt_t a) : MGeom(x, y, s, a)
+MGeomPix::MGeomPix(Float_t x, Float_t y, Float_t r, UInt_t s, UInt_t a)
+    : MGeom(x, y, s, a), fCosPhi(1), fSinPhi(0)
 {
     SetD(r);
@@ -84,4 +85,10 @@
 }
 
+void MGeomPix::SetPhi(Double_t phi)
+{
+    fCosPhi = TMath::Cos(phi);
+    fSinPhi = TMath::Sin(phi);
+}
+
 // --------------------------------------------------------------------------
 //
@@ -96,25 +103,91 @@
 // ------------------------------------------------------------------------
 //
-// 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!
+// Implementation of PaintPrimitive drwaing a hexagonal pixel
+//
+void MGeomPix::PaintPrimitive(const TAttLine &line, const TAttFill &fill, Double_t scalexy, Double_t scaled) const
+{
+    const_cast<TAttLine&>(line).Modify();  //Change line attributes only if necessary
+    const_cast<TAttFill&>(fill).Modify();  //Change fill area attributes only if necessary
+
+    const Double_t fx       = fX*scalexy;
+    const Double_t fy       = fY*scalexy;
+    const Double_t fd       = fD*scaled;
+
+    const Double_t c        = fd*fCosPhi;
+    const Double_t s        = fd*fSinPhi;
+
+    const Double_t gsCos60c = gsCos60*c;
+    const Double_t gsCos60s = gsCos60*s;
+
+    const Double_t gsSin60c = gsSin60*c/3;
+    const Double_t gsSin60s = gsSin60*s/3;
+
+    const Double_t gsTan30c = gsTan30*c;
+    const Double_t gsTan30s = gsTan30*s;
+
+
+    Double_t x[7] = {
+         gsCos60c-gsSin60s,  -gsTan30s,  -gsCos60c-gsSin60s,
+        -gsCos60c+gsSin60s,   gsTan30s,   gsCos60c+gsSin60s
+    };
+
+    Double_t y[7] = {
+         gsCos60s+gsSin60c,   gsTan30c,  -gsCos60s+gsSin60c,
+        -gsCos60s-gsSin60c,  -gsTan30c,   gsCos60s-gsSin60c,
+    };
+
+    for (Int_t i=0; i<6; i++)
+    {
+        // FIXME: Do not rotate fX/fY.
+        //        Instead implement MGeomCam::Rotate or similar.
+        x[i] += fx;
+        y[i] += fy;
+    }
+
+    x[6] = x[0];
+    y[6] = y[0];
+
+    //
+    //   paint the pixel
+    //
+    if (fill.GetFillColor())
+        gPad->PaintFillArea(6, x, y);
+
+    if (line.GetLineStyle())
+        gPad->PaintPolyLine(7, x, y);
+}
+
+// ------------------------------------------------------------------------
+//
+// 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
+{
+
+    //const Double_t disthex = 999999;//TMath::Sqrt(dx*dx + dy*dy);
+
+    const Double_t dh = fD/2;
 
     //
     //  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;
+    const Double_t dy = py-fY;
+
+    // FIXME: Derotate
+
+    // DX = dx*cos(-phi) - dy*sin(-phi)
+    // DY = dx*sin(-phi) + dy*cos(-phi)
+
+    const Double_t x =  dx*fCosPhi + dy*fSinPhi;
+
+    if (TMath::Abs(x) > dh)
+        return kFALSE; // return disthex
+
+    const Double_t y = -dx*fSinPhi + dy*fCosPhi;
+
+    const Double_t xc = x*gsCos60;  // 1/2
+    const Double_t ys = y*gsSin60;  // sqrt(3)/2
 
     //
@@ -125,71 +198,13 @@
     //
 
-    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;
-}
-
-// ------------------------------------------------------------------------
-//
-// 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;
-
-    //
-    // Now check if point is outside of hexagon; just check x coordinate
-    // in three coordinate systems: the default one, in which two sides of
-    // the hexagon are paralel to the y axis (see camera displays) and two 
-    // 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;
+    if  (TMath::Abs(xc + ys) > dh)
+        return kFALSE; // return disthex
+
+    if  (TMath::Abs(xc - ys) > dh)
+        return kFALSE; // return disthex
+
+    return kTRUE; // return -1
+
+
 }
 
Index: trunk/MagicSoft/Mars/mgeom/MGeomPix.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomPix.h	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeomPix.h	(revision 9385)
@@ -18,4 +18,11 @@
     Float_t fD;            // [mm]   the d coordinate of the pixel (dist between two parallel sides)
 
+    Double_t fCosPhi;
+    Double_t fSinPhi;
+
+    // Store fD*fCosPhi  ???
+    // Store fD*fSinPhi  ???
+    // Store array and check if initialized before needed?
+
 public:
     MGeomPix(Float_t x=0, Float_t y=0, Float_t d=1, UInt_t s=0, UInt_t aidx=0);
@@ -32,4 +39,5 @@
 
     void SetD(Float_t d=1) { fD=d; fA=d*d*gsTan60/2; }
+    void SetPhi(Double_t phi=0);
 
     Float_t GetD() const  { return fD; }         // Distance between two parallel sides
@@ -38,5 +46,4 @@
 
     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;
 
Index: trunk/MagicSoft/Mars/mgeom/MGeomRectangle.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomRectangle.cc	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeomRectangle.cc	(revision 9385)
@@ -34,4 +34,5 @@
 #include <TBox.h>
 #include <TMath.h>
+#include <TVirtualPad.h>
 
 #include "MLog.h"
@@ -50,5 +51,5 @@
 {
     //  default constructor
-    SetSize(w, h);
+    SetSize(w, h<0 ? w : h);
     SetNeighbors();
 }
@@ -72,14 +73,4 @@
 // ------------------------------------------------------------------------
 //
-// 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
 //
@@ -91,10 +82,15 @@
     const Double_t y = fY*scalexy;
 
-    TBox box;
+    const_cast<TAttLine&>(line).Modify();  //Change line attributes only if necessary
+    const_cast<TAttFill&>(fill).Modify();  //Change fill area attributes only if necessary
 
-    fill.Copy(box);
-    line.Copy(box);
-
-    box.PaintBox(x-w, y-h, x+w, y+h, "l");
+#if ROOT_VERSION_CODE < ROOT_VERSION(5,18,00)
+    if (fill.GetFillColor())
+        gPad->PaintBox(x-w, y-h, x+w, y+h);
+    if (line.GetLineStyle())
+        gPad->PaintBox(x-w, y-h, x+w, y+h, "s");
+#else
+    gPad->PaintBox(x-w, y-h, x+w, y+h, "l");
+#endif
 }
 
@@ -105,5 +101,5 @@
 Float_t MGeomRectangle::GetT() const
 {
-    return TMath::Hypot(fW, fH);
+    return TMath::Hypot(fW, fH)/2;
 }
 
Index: trunk/MagicSoft/Mars/mgeom/MGeomRectangle.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomRectangle.h	(revision 9384)
+++ trunk/MagicSoft/Mars/mgeom/MGeomRectangle.h	(revision 9385)
@@ -13,5 +13,5 @@
 
 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);
+    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
@@ -33,5 +33,4 @@
 
     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;
 
Index: trunk/MagicSoft/Mars/mgui/MHexagon.cc
===================================================================
--- trunk/MagicSoft/Mars/mgui/MHexagon.cc	(revision 9384)
+++ trunk/MagicSoft/Mars/mgui/MHexagon.cc	(revision 9385)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MHexagon.cc,v 1.31 2009-01-21 14:34:48 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MHexagon.cc,v 1.32 2009-03-04 18:45:26 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -48,5 +48,4 @@
 
 #include "MMath.h"
-#include "MGeomPix.h"       // GetX
 
 ClassImp(MHexagon);
@@ -75,18 +74,4 @@
 : TAttLine(1, 1, 1), TAttFill(0, 1001), fX(x), fY(y), fD(d), fPhi(phi)
 {
-}
-
-// ------------------------------------------------------------------------
-//
-//    normal constructor for MHexagon
-//
-MHexagon::MHexagon(const MGeomPix &pix)
-: TAttLine(1, 1, 1), TAttFill(0, 1001), fPhi(0)
-{
-    fX = pix.GetX();
-    fY = pix.GetY();
-    fD = pix.GetD();
-
-    // fPhi = pix.GetPhi();
 }
 
Index: trunk/MagicSoft/Mars/mgui/MHexagon.h
===================================================================
--- trunk/MagicSoft/Mars/mgui/MHexagon.h	(revision 9384)
+++ trunk/MagicSoft/Mars/mgui/MHexagon.h	(revision 9385)
@@ -26,5 +26,4 @@
 #endif 
 
-class MGeomPix;
 class TOrdCollection;
 
@@ -51,5 +50,4 @@
     MHexagon();
     MHexagon(Float_t x, Float_t y, Float_t d, Float_t phi=0);
-    MHexagon(const MGeomPix &pix);
     MHexagon(const MHexagon &hexagon);
 
Index: trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 9384)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 9385)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.121 2009-03-03 13:32:00 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.122 2009-03-04 18:45:26 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -307,5 +307,5 @@
     for (Int_t idx=0; idx<fNcells-2; idx++)
     {
-        if ((*fGeomCam)[idx].DistanceToPrimitive(x, y)>0)
+        if (!(*fGeomCam)[idx].IsInside(x, y))
             continue;
 
@@ -979,8 +979,6 @@
         gPad->GetX2()> maxr || gPad->GetY2()>maxr ? 1 : fGeomCam->GetConvMm2Deg();
 
-    TAttLine line;
+    TAttLine line(kBlack, kSolid, 1);
     TAttFill fill;
-    line.SetLineStyle(kSolid);
-    line.SetLineColor(kBlack);
     for (Int_t i=0; i<fNcells-2; i++)
     {
Index: trunk/MagicSoft/Mars/mjobs/MJSimulation.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJSimulation.cc	(revision 9384)
+++ trunk/MagicSoft/Mars/mjobs/MJSimulation.cc	(revision 9385)
@@ -442,5 +442,5 @@
     // FIXME: Pedestal and Calibration runs should get P and C
     const TString rule1(Form("s/cer([0-9]+)/%s\\/00$1_R_MonteCarlo.root/", Esc(fPathOut).Data()));
-    const TString rule2(Form("s/cer([0-9]+)/%s\\/00$1_I_MonteCarlo.root/", Esc(fPathOut).Data()));
+    const TString rule2(Form("s/cer([0-9]+)/%s\\/00$1_Y_MonteCarlo.root/", Esc(fPathOut).Data()));
     const TString rule3(Form("s/cer([0-9]+)/%s\\/00$1_D_MonteCarlo.root/", Esc(fPathOut).Data()));
 
Index: trunk/MagicSoft/Mars/mreport/MReportCC.cc
===================================================================
--- trunk/MagicSoft/Mars/mreport/MReportCC.cc	(revision 9384)
+++ trunk/MagicSoft/Mars/mreport/MReportCC.cc	(revision 9385)
@@ -120,14 +120,35 @@
     str.Remove(0, len);
 
-    if (ver>=200809030)
-    {
-        if (!CheckTag(str, "SCHEDULE "))
-            return kFALSE;
-
-        str = str.Strip(TString::kBoth);
-
-        // [Sourcename] sourcecategory
-        const Ssiz_t pos1 = str.First(' ');
-        if (pos1<0)
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Interprete SCHEDULE section of the CC-REPORT string
+//
+Bool_t MReportCC::InterpreteSchedule(TString &str)
+{
+    if (!CheckTag(str, "SCHEDULE "))
+        return kFALSE;
+
+    str = str.Strip(TString::kBoth);
+
+    // [Sourcename] sourcecategory
+    const Ssiz_t pos1 = str.First(' ');
+    if (pos1<0)
+    {
+        *fLog << warn << "WARNING - Wrong number of arguments (should be 1 or 2)." << endl;
+        return kFALSE;
+    }
+
+    const TString str1 = str(0, pos1);
+
+    str.Remove(0, pos1);
+    str = str.Strip(TString::kBoth);
+
+    if (!str1.IsDigit())
+    {
+        const Ssiz_t pos2 = str.First(' ');
+        if (pos2<0)
         {
             *fLog << warn << "WARNING - Wrong number of arguments (should be 1 or 2)." << endl;
@@ -135,35 +156,39 @@
         }
 
-        const TString str1 = str(0, pos1);
-
-        str.Remove(0, pos1);
-        str = str.Strip(TString::kBoth);
-
-        if (!str1.IsDigit())
+        TString str2 = str(0, pos2);
+
+        str.Remove(0, pos2);
+
+        // Remove a leading minus. The negative numbers are error codes introduced
+        // by Arehucas. It's only meant for the GRB monitor to change the priority
+        // of its alerts.
+        if (str2[0]=='-')
+            str2.Remove(0, 1);
+
+        if (!str2.IsDigit())
         {
-            const Ssiz_t pos2 = str.First(' ');
-            if (pos2<0)
-            {
-                *fLog << warn << "WARNING - Wrong number of arguments (should be 1 or 2)." << endl;
-                return kFALSE;
-            }
-
-            TString str2 = str(0, pos2);
-
-            str.Remove(0, pos2);
-
-            // Remove a leading minus. The negative numbers are error codes introduced
-            // by Arehucas. It's only meant for the GRB monitor to change the priority
-            // of its alerts.
-            if (str2[0]=='-')
-                str2.Remove(0, 1);
-
-            if (!str2.IsDigit())
-            {
-                *fLog << warn << "WARNING - Wrong type of second argument (obs. category): " << str2 << endl;
-                return kFALSE;
-            }
+            *fLog << warn << "WARNING - Wrong type of second argument (obs. category): " << str2 << endl;
+            return kFALSE;
         }
     }
+
+    return kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Interprete the part of the CC-Report with the MII Subsystem status'
+//
+Bool_t MReportCC::InterpreteStatusM2(TString &str)
+{
+    // Status of: DAQ, DominoCalibration, Drive, Starguider, CaCo,
+    //            CaCo2 LID, CaCo sentinel, CaCo LV, CaCo2 HV, AMC, L2T,
+    //            Domino, Readout, REC, DT, Readout cooling, calib
+    //            %05.2f %05.2f Zd [deg], Az [deg]
+
+    // Remove the 18 tokens of the MAGIC II subsystem status
+    for (int i=0; i<19; i++)
+        str.Remove(0, str.First(' ')+1);
 
     return kTRUE;
@@ -185,4 +210,12 @@
     if (!InterpreteCC(str, ver))
         return kCONTINUE;
+
+    if (ver>=200809030)
+        if (!InterpreteSchedule(str))
+            return kCONTINUE;
+
+    if (ver>=200902030)
+        if (!InterpreteStatusM2(str))
+            return kCONTINUE;
 
     if (ver<200805190)
Index: trunk/MagicSoft/Mars/mreport/MReportCC.h
===================================================================
--- trunk/MagicSoft/Mars/mreport/MReportCC.h	(revision 9384)
+++ trunk/MagicSoft/Mars/mreport/MReportCC.h	(revision 9385)
@@ -31,4 +31,6 @@
     Bool_t SetupReading(MParList &plist);
     Bool_t InterpreteCC(TString &str, Int_t ver);
+    Bool_t InterpreteSchedule(TString &str);
+    Bool_t InterpreteStatusM2(TString &str);
 
     // MReport
Index: trunk/MagicSoft/Mars/mtools/MagicJam.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MagicJam.cc	(revision 9384)
+++ trunk/MagicSoft/Mars/mtools/MagicJam.cc	(revision 9385)
@@ -162,8 +162,6 @@
     for (i=0; i<fNcells-2; i++)
     {
-        if ((*fGeomCam)[i].DistanceToPrimitive(px, py)>0)
-            continue;
-
-        return i;
+        if ((*fGeomCam)[i].IsInside(px, py))
+            return i;
     }
     return -1;
