Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 2462)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 2463)
@@ -4,4 +4,27 @@
    * mmontecarlo/MMcTimeGenerate.cc:
      - adapted to changes in MTime
+
+   * mgeom/MGeomCam.[h,cc]:
+     - precalculate pix ratio (and square root of it) for faster
+       calculations. This makes sense, because these values are
+       needed at least n times (while n is the number of pixels)
+       per event. Which results in billions of calculations already
+       for some events.
+     - implemented CalcPixRatio to do the precalculation
+     - changed class version of MGeomCam from 1 to 2
+
+   * mgeom/MGeomCamCT1.cc, mgeom/MGeomCamCT1Daniel.cc, 
+     mgeom/MGeomCamECO1000.cc, mgeom/MGeomCamMagic919.cc,
+     mgeom/MGeomCamECO1000HG.cc, mgeom/MGeomCamMagic.cc,
+     mgeom/MGeomCamMagicHG.cc:
+     - implemented CalcPixRatio to do the precalculation
+     - some simple code cleanup (removed obsolete comments, etc)
+   
+   * mgeom/MGeomPix.[h,cc]:
+     - replaces tan(60deg) by a build-in constant (fgTan60)
+     - pre calculate the area of the pixel in the constructor
+       (for speed reasons, see pixratio aboive)
+     - added fA
+     - changed version number from 1 to 2
 
 
Index: /trunk/MagicSoft/Mars/mgeom/MGeomCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 2462)
+++ /trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 2463)
@@ -32,4 +32,15 @@
 // interface of how to acccess the geometry information.
 //
+//
+// Version 1:
+// ----------
+//  - first implementation
+//
+// Version 2:
+// ----------
+//  - added fPixRatio
+//  - added fPixRatioSqrt
+//
+//
 ///////////////////////////////////////////////////////////////////////
 #include "MGeomCam.h"
@@ -59,5 +70,5 @@
 //
 MGeomCam::MGeomCam(UInt_t npix, Float_t dist, const char *name, const char *title)
-    : fNumPixels(npix), fCamDist(dist), fConvMm2Deg(kRad2Deg/(dist*1000)), fPixels(npix)
+    : fNumPixels(npix), fCamDist(dist), fConvMm2Deg(kRad2Deg/(dist*1000)), fPixels(npix), fPixRatio(npix), fPixRatioSqrt(npix)
 {
     fName  = name  ? name  : "MGeomCam";
@@ -87,4 +98,24 @@
 // --------------------------------------------------------------------------
 //
+// Calculate and fill the arrays storing the ratio of the area of a pixel
+// i to the pixel 0 and its square root.
+// The precalculation is done for speed reasons. Having an event the
+// ratio would be calculated at least once for each pixel which is
+// an enormous amount of numerical calculations, which are time
+// consuming and which can be avoided doing the precalculation.
+//
+void MGeomCam::CalcPixRatio()
+{
+    const Double_t a0 = (*this)[0].GetA();
+
+    for (UInt_t i=0; i<fNumPixels; i++)
+    {
+        fPixRatio[i] = a0/(*this)[i].GetA();
+        fPixRatioSqrt[i] = TMath::Sqrt(fPixRatio[i]);
+    }
+}
+
+// --------------------------------------------------------------------------
+//
 //  Set the kIsOuterRing flag for all pixels which have a outermost pixel
 //  as Next Neighbor and don't have the kIsOutermostRing flag itself.
@@ -103,28 +134,27 @@
 {
     fNumSectors = 0;
+
+    for (UInt_t i=0; i<fNumPixels; i++)
+    {
+        const UInt_t s = (*this)[i].GetSector();
+
+        if (s>fNumSectors)
+            fNumSectors = s;
+    }
+
+    fNumSectors++;
+}
+
+// --------------------------------------------------------------------------
+//
+// Calculate the maximum radius of the camera. This is ment for GUI layout.
+//
+void MGeomCam::CalcMaxRadius()
+{
+    fMaxRadius = 0;
 
     for (UInt_t i=0; i<fNumPixels; i++)
     {
         const MGeomPix &pix = (*this)[i];
-        const UInt_t s = pix.GetSector();
-
-        if (s>fNumSectors)
-            fNumSectors = s;
-    }
-
-    fNumSectors++;
-}
-
-// --------------------------------------------------------------------------
-//
-// Calculate the maximum radius of the camera. This is ment for GUI layout.
-//
-void MGeomCam::CalcMaxRadius()
-{
-    fMaxRadius = 0;
-
-    for (UInt_t i=0; i<fNumPixels; i++)
-    {
-        const MGeomPix &pix = (*this)[i];
 
         const Float_t x = pix.GetX();
@@ -147,5 +177,19 @@
 Float_t MGeomCam::GetPixRatio(UInt_t i) const
 {
-    return i<fNumPixels ? (*this)[0].GetA()/(*this)[i].GetA() : 0;
+    // Former: (*this)[0].GetA()/(*this)[i].GetA();
+    // The const_cast is necessary to support older root version
+    return i<fNumPixels ? const_cast<TArrayF&>(fPixRatio)[i] : 0;
+}
+
+// --------------------------------------------------------------------------
+//
+//  returns the square root of the ratio of the area of the pixel with
+//  index 0 to the pixel with the specified index i. 0 Is returned if
+//  the index argument is out of range.
+//
+Float_t MGeomCam::GetPixRatioSqrt(UInt_t i) const
+{
+    // The const_cast is necessary to support older root version
+    return i<fNumPixels ? const_cast<TArrayF&>(fPixRatioSqrt)[i] : 0;
 }
 
Index: /trunk/MagicSoft/Mars/mgeom/MGeomCam.h
===================================================================
--- /trunk/MagicSoft/Mars/mgeom/MGeomCam.h	(revision 2462)
+++ /trunk/MagicSoft/Mars/mgeom/MGeomCam.h	(revision 2463)
@@ -8,4 +8,7 @@
 #include <TObjArray.h>
 #endif
+#ifndef ROOT_TArrayF
+#include <TArrayF.h>
+#endif
 
 class MGeomPix;
@@ -14,15 +17,19 @@
 {
 private:
-    UInt_t    fNumPixels;  // Number of pixels in this camera
-    Float_t   fMaxRadius;  // maximum radius of the camera (eg. for GUI layout)
+    UInt_t    fNumPixels;    // Number of pixels in this camera
+    Float_t   fMaxRadius;    // maximum radius of the camera (eg. for GUI layout)
 
-    Float_t   fCamDist;    // [m] Average distance of the camera from the mirror
-    Float_t   fConvMm2Deg; // conversion factor to convert mm in the camera plain into degrees
+    Float_t   fCamDist;      // [m] Average distance of the camera from the mirror
+    Float_t   fConvMm2Deg;   // conversion factor to convert mm in the camera plain into degrees
 
-    TObjArray fPixels;     // Array of singel pixels storing the geometry
+    TObjArray fPixels;       // Array of singel pixels storing the geometry
 
-    UInt_t    fNumSectors; // Number of sectors
+    TArrayF   fPixRatio;     // Array storing the ratio between size of pixel idx and pixel 0 (for speed reasons)
+    TArrayF   fPixRatioSqrt; // Array storing the square root ratio between size of pixel idx and pixel 0 (for speed reasons)
+
+    UInt_t    fNumSectors;   // Number of sectors
 
 protected:
+    void CalcPixRatio();
     void CalcMaxRadius();
     void CalcNumSectors();
@@ -42,4 +49,5 @@
     UInt_t  GetNumSectors() const { return fNumSectors; }
     Float_t GetPixRatio(UInt_t i) const;
+    Float_t GetPixRatioSqrt(UInt_t i) const;
 
     MGeomPix &operator[](Int_t i);
@@ -48,5 +56,5 @@
     virtual void Print(Option_t *opt=NULL) const;
 
-    ClassDef(MGeomCam, 1)  // Geometry base class for the camera
+    ClassDef(MGeomCam, 2)  // Geometry base class for the camera
 };
 
Index: /trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.cc
===================================================================
--- /trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.cc	(revision 2462)
+++ /trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.cc	(revision 2463)
@@ -58,4 +58,5 @@
     CalcNumSectors();
     CalcMaxRadius();
+    CalcPixRatio();
 } 
 
Index: /trunk/MagicSoft/Mars/mgeom/MGeomCamCT1Daniel.cc
===================================================================
--- /trunk/MagicSoft/Mars/mgeom/MGeomCamCT1Daniel.cc	(revision 2462)
+++ /trunk/MagicSoft/Mars/mgeom/MGeomCamCT1Daniel.cc	(revision 2463)
@@ -46,9 +46,4 @@
 #include <math.h>     // floor
 
-/*
- #include "MLog.h"
- #include "MLogManip.h"
- */
-
 #include "MGeomPix.h"
 
@@ -60,7 +55,4 @@
 //  CreateCam and CreateNN
 //
-//MGeomCamCT1::MGeomCamCT1(const char *name)
-//    : MGeomCam(127, 4.88, name, "Geometry information of CT1 camera")
-// This is the geometry as used by Daniel :
 MGeomCamCT1Daniel::MGeomCamCT1Daniel(const char *name)
     : MGeomCam(127, 4.8129, name, "Geometry information of CT1 camera")
@@ -70,4 +62,5 @@
     CalcNumSectors();
     CalcMaxRadius();
+    CalcPixRatio();
 } 
 
Index: /trunk/MagicSoft/Mars/mgeom/MGeomCamECO1000.cc
===================================================================
--- /trunk/MagicSoft/Mars/mgeom/MGeomCamECO1000.cc	(revision 2462)
+++ /trunk/MagicSoft/Mars/mgeom/MGeomCamECO1000.cc	(revision 2463)
@@ -48,5 +48,5 @@
 //
 MGeomCamECO1000::MGeomCamECO1000(const char *name)
-    : MGeomCam(577, 17, name, "Geometry information of Magic Camera")
+    : MGeomCam(577, 34.5, name, "Geometry information of Magic Camera")
 {
     CreateCam();
@@ -54,4 +54,5 @@
     CalcNumSectors();
     CalcMaxRadius();
+    CalcPixRatio();
 }
 
Index: /trunk/MagicSoft/Mars/mgeom/MGeomCamECO1000HG.cc
===================================================================
--- /trunk/MagicSoft/Mars/mgeom/MGeomCamECO1000HG.cc	(revision 2462)
+++ /trunk/MagicSoft/Mars/mgeom/MGeomCamECO1000HG.cc	(revision 2463)
@@ -58,4 +58,5 @@
     CalcNumSectors();
     CalcMaxRadius();
+    CalcPixRatio();
 }
 
Index: /trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.cc
===================================================================
--- /trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.cc	(revision 2462)
+++ /trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.cc	(revision 2463)
@@ -34,9 +34,4 @@
 #include "MGeomCamMagic.h"
 
-/*
- #include "MLog.h"
- #include "MLogManip.h"
- */
-
 #include "MGeomPix.h"
 
@@ -53,6 +48,8 @@
     CreateCam();
     CreateNN();
+    CalcPixRatio();
     CalcNumSectors();
     CalcMaxRadius();
+    CalcPixRatio();
 }
 
Index: /trunk/MagicSoft/Mars/mgeom/MGeomCamMagic919.cc
===================================================================
--- /trunk/MagicSoft/Mars/mgeom/MGeomCamMagic919.cc	(revision 2462)
+++ /trunk/MagicSoft/Mars/mgeom/MGeomCamMagic919.cc	(revision 2463)
@@ -34,9 +34,4 @@
 #include "MGeomCamMagic919.h"
 
-/*
- #include "MLog.h"
- #include "MLogManip.h"
- */
-
 #include "MGeomPix.h"
 
@@ -55,4 +50,5 @@
     CreateNN();
     CalcMaxRadius();
+    CalcPixRatio();
 }
 
Index: /trunk/MagicSoft/Mars/mgeom/MGeomCamMagicHG.cc
===================================================================
--- /trunk/MagicSoft/Mars/mgeom/MGeomCamMagicHG.cc	(revision 2462)
+++ /trunk/MagicSoft/Mars/mgeom/MGeomCamMagicHG.cc	(revision 2463)
@@ -34,9 +34,4 @@
 #include "MGeomCamMagicHG.h"
 
-/*
- #include "MLog.h"
- #include "MLogManip.h"
- */
-
 #include "MGeomPix.h"
 
@@ -55,4 +50,5 @@
     CalcNumSectors();
     CalcMaxRadius();
+    CalcPixRatio();
 }
 
Index: /trunk/MagicSoft/Mars/mgeom/MGeomCorsikaCT.cc
===================================================================
--- /trunk/MagicSoft/Mars/mgeom/MGeomCorsikaCT.cc	(revision 2462)
+++ /trunk/MagicSoft/Mars/mgeom/MGeomCorsikaCT.cc	(revision 2463)
@@ -66,7 +66,2 @@
 
 }
-
-
-
-
-
Index: /trunk/MagicSoft/Mars/mgeom/MGeomPix.cc
===================================================================
--- /trunk/MagicSoft/Mars/mgeom/MGeomPix.cc	(revision 2462)
+++ /trunk/MagicSoft/Mars/mgeom/MGeomPix.cc	(revision 2463)
@@ -35,4 +35,14 @@
 // MGeomPix.
 //
+//
+// Version 1:
+// ----------
+//  - first implementation
+//
+// Version 2:
+// ----------
+//  - added fA
+//
+//
 // FIXME: According to an agreement we have to change the name 'Id'
 //        to 'idx'
@@ -52,20 +62,14 @@
 using namespace std;
 
+const Float_t MGeomPix::gsTan60 = tan(60/kRad2Deg);
+
 // --------------------------------------------------------------------------
 //
 // Initializes one pixel
 //
-MGeomPix::MGeomPix(Float_t x, Float_t y, Float_t r, UInt_t s) : fX(x), fY(y), fD(r), fSector(s)
+MGeomPix::MGeomPix(Float_t x, Float_t y, Float_t r, UInt_t s)
 {
     //  default constructor
-}
-
-// --------------------------------------------------------------------------
-//
-// Return the area of the pixel. A hexagonal shape is assumed.
-//
-Float_t MGeomPix::GetA() const
-{
-    return fD*fD*tan(60/kRad2Deg);
+    Set(x, y, r, s);
 }
 
@@ -126,4 +130,5 @@
         << "  y= " << fY
         << "  d= " << fD
+        << "  A= " << fA
         << endl ;
 }
Index: /trunk/MagicSoft/Mars/mgeom/MGeomPix.h
===================================================================
--- /trunk/MagicSoft/Mars/mgeom/MGeomPix.h	(revision 2462)
+++ /trunk/MagicSoft/Mars/mgeom/MGeomPix.h	(revision 2463)
@@ -11,19 +11,21 @@
 { 
 private:
+    static const Float_t gsTan60; // tan(60/kRad2Deg);
+
     enum {
         kIsInOutermostRing = BIT(22),
         kIsInOuterRing     = BIT(23),
         kUserBits          = 0x1fc000 // 14-21 are allowed
-
     };
 
-    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 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 fSector;        // Number of sector the pixels corresponds to
 
 public:
@@ -32,5 +34,5 @@
     void Print(Option_t *opt=NULL) const;
 
-    void Set(Float_t x, Float_t y, Float_t d, UInt_t s=0) { fX=x; fY=y; fD=d; fSector=s; }
+    void Set(Float_t x, Float_t y, Float_t d, UInt_t s=0) { fX=x; fY=y; fD=d; fA=d*d*gsTan60; fSector=s; }
 
     void SetNeighbors(Short_t i0=-1, Short_t i1=-1, Short_t i2=-1,
@@ -38,10 +40,4 @@
 
     void CheckOuterRing(const MGeomCam &cam);
-    /*
-     void SetX(Float_t x) { fX = x; }
-     void SetY(Float_t y) { fY = y; }
-     void SetD(Float_t d) { fD = d; }
-     void SetSector(UInt_t s) { fSector = s; }
-     */
 
     Float_t GetX() const  { return fX; }
@@ -50,5 +46,5 @@
     UInt_t  GetSector() const { return fSector; }
 
-    Float_t GetA() const;
+    Float_t GetA() const { return fA; /*fD*fD*gsTan60;*/ }
 
     Byte_t  GetNumNeighbors() const { return fNumNeighbors; }
