Index: /trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc	(revision 1048)
+++ /trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc	(revision 1049)
@@ -17,5 +17,5 @@
 !
 !   Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
-!   Author(s): Thomas Bretz  12/2000 (tbretz@uni-sw.gwdg.de)
+!   Author(s): Thomas Bretz    12/2000 (tbretz@uni-sw.gwdg.de)
 !
 !   Copyright: MAGIC Software Development, 2000-2001
@@ -31,8 +31,6 @@
 //  Please look at the three CleanSteps and Process                        //
 //                                                                         //
-//   FIXME: MImgCleanStd is rather slow at the moment because it loops     //
-//          unnecessarily over all pixels in all its loops (s.MHillas)     //
-//          The speed could be improved very much by using Hash-Tables     //
-//          (linked lists, see THashTable and THashList, too)              //
+//   FIXME: MImgCleanStd is not yet completely optimized for speed.        //
+//          Maybe we don't have to loop over all pixels all the time...    //
 //                                                                         //
 //  Input Containers:                                                      //
@@ -94,5 +92,5 @@
 
         // COBB: '<=' to skip entry=noise=0
-        if (entry <= fCleanLvl1 * noise )
+        if (entry <= fCleanLvl1 * noise)
             pix.SetPixelUnused();
     }
@@ -108,4 +106,18 @@
     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.
+    //
+    Byte_t ispixused[577];
+
+    for (Int_t i=0; i<entries; i++)
+    {
+        MCerPhotPix &pix = (*fEvt)[i];
+        ispixused[pix.GetPixId()] = pix.IsPixelUsed();
+    }
+
     for (Int_t i=0; i<entries; i++)
     {
@@ -133,15 +145,17 @@
         const Int_t     nnmax = gpix.GetNumNeighbors();
 
-        Int_t cnt = 0;
+        Bool_t cnt = kFALSE;
         for (Int_t j=0; j<nnmax; j++)
         {
-            const Int_t id2 = gpix.GetNeighbor(j); //GetNN(id, in) ;
-
-            if (id2 < 0)
+            const Int_t id2 = gpix.GetNeighbor(j);
+
+            if (!ispixused[id2])
                 continue;
 
-            if (fEvt->IsPixelUsed(id2))
-                cnt++;
+            cnt = kTRUE;
+            break;
         }
+        if (cnt)
+            continue;
 
         //
@@ -149,6 +163,5 @@
         // set this pixel to 'unused', too.
         //
-        if (cnt==0)
-            pix.SetPixelUnused();
+        pix.SetPixelUnused();
     }
 
@@ -213,13 +226,9 @@
             const Int_t id2 = gpix.GetNeighbor(j);
 
-            if (id2 <0)
-                continue;
-
             if (!fEvt->IsPixelCore(id2))
                 continue;
 
             pix.SetPixelUsed();
-
-            break ;
+            break;
         }
     }
