Index: trunk/MagicSoft/Mars/mimage/MHillas.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHillas.cc	(revision 2849)
+++ trunk/MagicSoft/Mars/mimage/MHillas.cc	(revision 3183)
@@ -188,10 +188,8 @@
 Int_t MHillas::Calc(const MGeomCam &geom, const MCerPhotEvt &evt)
 {
-    const UInt_t npixevt = evt.GetNumPixels();
-
-    //
-    // sanity check
-    //
-    if (npixevt < 3)
+    //
+    // sanity check 1
+    //
+    if (evt.GetNumPixels()<3)
         return 1;
 
@@ -209,16 +207,13 @@
     fSize  = 0;
 
-    Int_t numused = 0;
-
-    for (UInt_t i=0; i<npixevt; i++)
+    MCerPhotPix *pix = 0;
+
+    TIter Next(evt);
+    UInt_t numused = 0;
+    while ((pix=(MCerPhotPix*)Next()))
     {
-        const MCerPhotPix &pix = evt[i];
-
-        if (!pix.IsPixelUsed())
-            continue;
-
-        const MGeomPix &gpix = geom[pix.GetPixId()];
-
-        const Float_t nphot = pix.GetNumPhotons();
+        const MGeomPix &gpix = geom[pix->GetPixId()];
+
+        const Float_t nphot = pix->GetNumPhotons();
 
         fSize  += nphot;		             // [counter]
@@ -230,5 +225,5 @@
 
     //
-    // sanity checks
+    // sanity check 2
     //
     if (fSize==0)
@@ -238,4 +233,7 @@
     fMeanY /= fSize;                                 // [mm]
 
+    //
+    // sanity check 3
+    //
     if (numused<3)
         return 3;
@@ -254,17 +252,13 @@
     Double_t corryy=0;                               // [m^2]
 
-    for (UInt_t i=0; i<npixevt; i++)
+    Next.Reset();
+    while ((pix=(MCerPhotPix*)Next()))
     {
-        const MCerPhotPix &pix = evt[i];
-
-        if (!pix.IsPixelUsed())
-            continue;
-
-        const MGeomPix &gpix = geom[pix.GetPixId()];
+        const MGeomPix &gpix = geom[pix->GetPixId()];
 
         const Float_t dx = gpix.GetX() - fMeanX;     // [mm]
         const Float_t dy = gpix.GetY() - fMeanY;     // [mm]
 
-        const Float_t nphot = pix.GetNumPhotons();   // [#phot]
+        const Float_t nphot = pix->GetNumPhotons();  // [#phot]
 
         corrxx += nphot * dx*dx;                     // [mm^2]
@@ -297,18 +291,18 @@
     const Double_t d0    = corryy - corrxx;
     const Double_t d1    = corrxy*2;
-    const Double_t d2    = d0 + sqrt(d0*d0 + d1*d1);
+    const Double_t d2    = d0 + TMath::Sqrt(d0*d0 + d1*d1);
     const Double_t tand  = d2 / d1;
     const Double_t tand2 = tand*tand;
 
-    fDelta = atan(tand);
+    fDelta = TMath::ATan(tand);
 
     const Double_t s2 = tand2+1;
-    const Double_t s  = sqrt(s2);
+    const Double_t s  = TMath::Sqrt(s2);
 
     fCosDelta =  1.0/s;   // need these in derived classes
     fSinDelta = tand/s;   // like MHillasExt
 
-    Double_t axis1 = (tand2*corryy + d2 + corrxx)/s2/fSize;
-    Double_t axis2 = (tand2*corrxx - d2 + corryy)/s2/fSize;
+    const Double_t axis1 = (tand2*corryy + d2 + corrxx)/s2/fSize;
+    const Double_t axis2 = (tand2*corrxx - d2 + corryy)/s2/fSize;
 
     //
@@ -320,6 +314,6 @@
     // very small numbers can get negative by rounding
     //
-    fLength = axis1<0 ? 0 : sqrt(axis1);  // [mm]
-    fWidth  = axis2<0 ? 0 : sqrt(axis2);  // [mm]
+    fLength = axis1<0 ? 0 : TMath::Sqrt(axis1);  // [mm]
+    fWidth  = axis2<0 ? 0 : TMath::Sqrt(axis2);  // [mm]
 
     SetReadyToSave();
Index: trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 2849)
+++ trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 3183)
@@ -329,5 +329,4 @@
 void MImgCleanStd::CleanStep1()
 {
-    const Int_t entries = fEvt->GetNumPixels();
     const TArrayD &data = fData->GetData();
 
@@ -335,12 +334,12 @@
     // check the number of all pixels against the noise level and
     // set them to 'unused' state if necessary
-    // 
-    for (Int_t i=0; i<entries; i++ )
-    {
-        MCerPhotPix &pix = (*fEvt)[i];
-
-        if (data[pix.GetPixId()] <= fCleanLvl1)
-            pix.SetPixelUnused();
-    }
+    //
+    MCerPhotPix *pix;
+
+    // Loop over all pixels
+    MCerPhotEvtIter Next(fEvt, kFALSE);
+    while ((pix=static_cast<MCerPhotPix*>(Next())))
+        if (data[pix->GetPixId()] <= fCleanLvl1)
+            pix->SetPixelUnused();
 }
 
@@ -351,40 +350,14 @@
 //  neighbors).
 //
-//  Takes the maximum pixel id from CleanStep1 as an argument
-//
 void MImgCleanStd::CleanStep2()
 {
-    const Int_t entries = fEvt->GetNumPixels();
-
-    //
-    // In the worst case we have to loop 6 times 577 times, to
-    // catch the behaviour of all next neighbors. Here we can gain
-    // much by using an array instead of checking through all pixels
-    // (MCerPhotEvt::IsPixelUsed) all the time.
-    //
-    // We allocate the array ourself because the TArrays always do
-    // range check which slows down the access to the array
-    // by 25-50%
-    //
-    Byte_t *ispixused = new Byte_t[fCam->GetNumPixels()];
-    memset(ispixused, 0, sizeof(Byte_t)*fCam->GetNumPixels());
-
-    for (Int_t i=0; i<entries; i++)
-    {
-        const MCerPhotPix &pix = (*fEvt)[i];
-        ispixused[pix.GetPixId()] = pix.IsPixelUsed() ? 1 : 0 ;
-   }
-
-    for (Int_t i=0; i<entries; i++)
-    {
-        // get entry i from list
-        MCerPhotPix &pix = (*fEvt)[i];
-
-	// get pixel id of this entry
-        const Int_t idx = pix.GetPixId();
-
-	// check if pixel is in use, if not goto next pixel in list
-	if (ispixused[idx] == 0)
-            continue;
+    MCerPhotPix *pix;
+
+    // Loop over used pixels only
+    TIter Next(*fEvt);
+    while ((pix=static_cast<MCerPhotPix*>(Next())))
+    {
+        // get pixel id of this entry
+        const Int_t idx = pix->GetPixId();
  
         // check for 'used' neighbors of this pixel
@@ -400,5 +373,5 @@
 
 	    // when you find an used neighbor, break the loop
-            if (ispixused[idx2] == 1)
+            if (fEvt->IsPixelUsed(idx2))
             {
                 hasNeighbor = kTRUE;
@@ -408,19 +381,13 @@
 
 	if (hasNeighbor == kFALSE)
-            pix.SetPixelUnused();
-    }
-
-    delete ispixused;
+            pix->SetPixelUnused();
+    }
 
     //
     // now we declare all pixels that survive as CorePixels
     //
-    for (Int_t i=0; i<entries; i++)
-    {
-        MCerPhotPix &pix = (*fEvt)[i];
-
-        if (pix.IsPixelUsed())
-            pix.SetPixelCore();
-    }
+    Next.Reset();
+    while ((pix=static_cast<MCerPhotPix*>(Next())))
+        pix->SetPixelCore();
 } 
 
@@ -440,5 +407,5 @@
         const Int_t idx2 = gpix.GetNeighbor(j);
 
-	if (!fEvt->GetPixById(idx2) || !fEvt->IsPixelCore(idx2))
+	if (!fEvt->IsPixelCore(idx2))
             continue;
 
@@ -459,7 +426,10 @@
 void MImgCleanStd::CleanStep4(UShort_t r, MCerPhotPix &pix)
 {
-  // Skip events that have already a defined status;
-	if( pix.GetRing()!= 0)
-	  return;
+    //
+    // Skip events that have already a defined status;
+    //
+    if (pix.GetRing() != 0)
+        return;
+
     //
     // check if the pixel's next neighbor is a used pixel.
@@ -478,7 +448,6 @@
 
         MCerPhotPix *npix = fEvt->GetPixById(idx2);
-
         if (!npix || !npix->IsPixelUsed() || npix->GetRing()>r-1 ) 
-	continue;
+            continue;
 
         pix.SetRing(r);
@@ -495,29 +464,27 @@
 void MImgCleanStd::CleanStep3()
 {
-    const Int_t entries = fEvt->GetNumPixels();
     const TArrayD &data = fData->GetData();
 
     for (UShort_t r=1; r<fCleanRings+1; r++)
     {
-        for (Int_t i=0; i<entries; i++)
+        MCerPhotPix *pix;
+
+        // Loop over all pixels
+        MCerPhotEvtIter NextAll(fEvt, kFALSE);
+        while ((pix=static_cast<MCerPhotPix*>(NextAll())))
         {
-            //
-            // get pixel as entry il from list
-            //
-            MCerPhotPix &pix = (*fEvt)[i];
-
             //
             // if pixel is a core pixel go to the next pixel
             //
-            if (pix.IsPixelCore())
+            if (pix->IsPixelCore())
                 continue;
 
-            if (data[pix.GetPixId()] <= fCleanLvl2)
+            if (data[pix->GetPixId()] <= fCleanLvl2)
                 continue;
 
             if (r==1)
-                CleanStep3b(pix);
+                CleanStep3b(*pix);
             else
-                CleanStep4(r, pix);
+                CleanStep4(r, *pix);
         }
     }
Index: trunk/MagicSoft/Mars/mimage/MNewImagePar.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MNewImagePar.cc	(revision 2849)
+++ trunk/MagicSoft/Mars/mimage/MNewImagePar.cc	(revision 3183)
@@ -18,5 +18,5 @@
 !   Author(s): Wolfgang Wittek 03/2003 <mailto:wittek@mppmu.mpg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2003
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
@@ -31,8 +31,10 @@
 // fLeakage1 ratio: (photons in most outer ring of pixels) over fSize
 // fLeakage2 ratio: (photons in the 2 outer rings of pixels) over fSize
+// fNumSaturatedPixels: number of pixels in which at least one slice
+//                      of the low gain FADC was saturated.
 //
 // Version 2:
-// Added fNumSaturatedPixels: number of pixels in which at least one slice
-// of the low gain FADC was saturated.
+// ----------
+//  - added fNumSaturatedPixels
 // 
 /////////////////////////////////////////////////////////////////////////////
@@ -106,9 +108,18 @@
         const MCerPhotPix &pix = evt[i];
 
+        // count saturated pixels
 	if (pix.IsPixelSaturated())
-	  fNumSaturatedPixels++;
+            fNumSaturatedPixels++;
 
+        // skip unused pixels
         if (!pix.IsPixelUsed())
             continue;
+
+        // count used and core pixels
+        if (pix.IsPixelCore())
+            fNumCorePixels++;
+
+        // count used pixels
+        fNumUsedPixels++;
 
         const Int_t pixid = pix.GetPixId();
@@ -125,12 +136,4 @@
         if (gpix.IsInOuterRing())
            edgepix2 += nphot;
-
-        //
-        // count used and core pixels
-        //
-        if (pix.IsPixelCore())
-            fNumCorePixels++;
-
-        fNumUsedPixels++;
 
         //
@@ -172,3 +175,4 @@
     *fLog << " - Used Pixels    [#]   = " << fNumUsedPixels << " Pixels" << endl;
     *fLog << " - Core Pixels    [#]   = " << fNumCorePixels << " Pixels" << endl;
+    *fLog << " - Sat. Pixels    [#]   = " << fNumSaturatedPixels << " Pixels" << endl;
 }
Index: trunk/MagicSoft/Mars/mimage/MNewImagePar.h
===================================================================
--- trunk/MagicSoft/Mars/mimage/MNewImagePar.h	(revision 2849)
+++ trunk/MagicSoft/Mars/mimage/MNewImagePar.h	(revision 3183)
@@ -13,14 +13,13 @@
 {
 private:
-    Float_t fLeakage1;      // (photons in most outer ring of pixels) over fSize
-    Float_t fLeakage2;      // (photons in the 2 outer rings of pixels) over fSize
+    Float_t fLeakage1;           // (photons in most outer ring of pixels) over fSize
+    Float_t fLeakage2;           // (photons in the 2 outer rings of pixels) over fSize
 
-    Float_t fConc;          // [ratio] concentration ratio: sum of the two highest pixels / fSize
-    Float_t fConc1;         // [ratio] concentration ratio: sum of the highest pixel / fSize
+    Float_t fConc;               // [ratio] concentration ratio: sum of the two highest pixels / fSize
+    Float_t fConc1;              // [ratio] concentration ratio: sum of the highest pixel / fSize
 
-    Short_t fNumUsedPixels; // Number of pixels which survived the image cleaning
-    Short_t fNumCorePixels; // number of core pixels
-
-    Short_t fNumSaturatedPixels; // number of saturated pixels
+    Short_t fNumUsedPixels;      // Number of pixels which survived the image cleaning
+    Short_t fNumCorePixels;      // number of core pixels
+    Short_t fNumSaturatedPixels; // number of pixels with saturating lo-gains
 
 public:
@@ -29,12 +28,12 @@
     void Reset();
 
-    Float_t GetLeakage1() const    { return fLeakage1; }
-    Float_t GetLeakage2() const    { return fLeakage2; }
+    Float_t GetLeakage1() const { return fLeakage1; }
+    Float_t GetLeakage2() const { return fLeakage2; }
 
-    Float_t GetConc() const        { return fConc; }
-    Float_t GetConc1() const       { return fConc1; }
+    Float_t GetConc() const  { return fConc;  }
+    Float_t GetConc1() const { return fConc1; }
 
-    Int_t GetNumUsedPixels() const { return fNumUsedPixels; }
-    Int_t GetNumCorePixels() const { return fNumCorePixels; }
+    Short_t GetNumUsedPixels() const { return fNumUsedPixels; }
+    Short_t GetNumCorePixels() const { return fNumCorePixels; }
 
     Short_t GetNumSaturatedPixels() const { return fNumSaturatedPixels; }
@@ -49,29 +48,2 @@
 
 #endif
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
