Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 2755)
+++ trunk/MagicSoft/Mars/Changelog	(revision 2756)
@@ -10,4 +10,7 @@
        TSpline5 Root Class to interpolate the Fadc Slices. The time is
        the abscissa value of the absolute maximum of the interpolation
+     - added new method to find clusters with similar arrival times.
+       For now it's a preliminary version. It simply search for adiacent
+       pixels having the same arrival time (color).
 
    * manalysis/MArrivalTimeCalc.[h,cc]
Index: trunk/MagicSoft/Mars/manalysis/MArrivalTime.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MArrivalTime.cc	(revision 2755)
+++ trunk/MagicSoft/Mars/manalysis/MArrivalTime.cc	(revision 2756)
@@ -33,4 +33,5 @@
 
 #include "MGeomCam.h"
+#include "MGeomPix.h"
 
 #include "MLog.h"
@@ -140,5 +141,110 @@
 }
 
-
+// -------------------------------------------------------------------------
+//
+// Finds the clusters with similar Arrival Time
+//
+// PRELIMINARY!! For now the Arrival Time is not the one calculated with
+//               the splines, but it's the Max Slice Idx
+//
+// TEST!!        This method is used only for test. Do not use it until
+//               it becomes stable
+//
+
+void MArrivalTime::EvalClusters(const MRawEvtData &evt, const MGeomCam &geom)
+{
+    const Int_t n = geom.GetNumPixels();
+
+    fData2.Set(n);
+    fData2.Reset(-1);
+    fData3.Set(n);
+    fData3.Reset(-1);
+    fData4.Set(n);
+    fData4.Reset(-1);
+    fData5.Set(n);
+    fData5.Reset(-1);
+
+    MRawEvtPixelIter pixel((MRawEvtData*)&evt);
+
+// Array that says if a pixel has been already checked or not
+
+    for (Int_t i = 0; i < n; i++)
+        fPixelChecked[i] = kFALSE;
+
+// This fakeData array will be subsituted with the fData Array.
+    fakeData.Set(n);
+    fakeData.Reset();
+   
+    while ( pixel.Next() )
+    {
+        fakeData[pixel.GetPixelId()]=pixel.GetIdxMaxHiLoGainSample();
+    }
+// End of fakeData preparation
+
+// Max dimension of cluster
+    Short_t dimCluster;
+
+    while ( pixel.Next() )
+    {
+	if (!fPixelChecked[pixel.GetPixelId()])
+	{
+	    dimCluster = 0;
+            fCluster.Set(n);
+            fCluster.Reset(-1);
+            fCluster[dimCluster]=pixel.GetPixelId();
+	    dimCluster++;
+
+	    CheckNeighbours(evt,geom,
+			    pixel.GetPixelId(), &dimCluster);
+
+	    if (dimCluster > 4)
+            {
+		for (Int_t i = 0; i < dimCluster; i++)
+		    fData5[fCluster[i]]=fakeData[fCluster[i]];
+	    }
+	    if (dimCluster > 3)
+            {
+		for (Int_t i = 0; i < dimCluster; i++)
+		    fData4[fCluster[i]]=fakeData[fCluster[i]];
+	    }
+	    if (dimCluster > 2)
+            {
+		for (Int_t i = 0; i < dimCluster; i++)
+		    fData3[fCluster[i]]=fakeData[fCluster[i]];
+	    }
+	    if (dimCluster > 1)
+            {
+		for (Int_t i = 0; i < dimCluster; i++)
+		    fData2[fCluster[i]]=fakeData[fCluster[i]];
+	    }            
+	}
+    }
+
+}
+
+// --------------------------------------------------------------------------
+//
+// Function to check the nearest neighbour pixels arrivaltime
+//
+
+void MArrivalTime::CheckNeighbours(const MRawEvtData &evt, const MGeomCam &geom,
+                                   Short_t idx, Short_t *dimCluster)
+{
+    Byte_t numNeighbors=geom[idx].GetNumNeighbors();
+    fPixelChecked[idx] = kTRUE;
+
+    for (Byte_t i=0x00; i < numNeighbors; i++)
+    {
+	
+	if (!fPixelChecked[geom[idx].GetNeighbor(i)] &&
+            fakeData[idx] == fakeData[geom[idx].GetNeighbor(i)])
+	{    
+	    fCluster[*dimCluster]=geom[idx].GetNeighbor(i);    
+	    *dimCluster++;
+            CheckNeighbours(evt, geom,
+			    geom[idx].GetNeighbor(i), dimCluster);
+	}
+    }
+}
 // --------------------------------------------------------------------------
 //
@@ -151,5 +257,24 @@
         return kFALSE;
 
-    val = fData[idx];
+    switch (type)
+    {
+    case 0:
+    case 1:
+        val = fData[idx];
+        break;
+    case 2:
+        val = fData2[idx];
+        break;
+    case 3:
+        val = fData3[idx];
+        break;
+    case 4:
+        val = fData4[idx];
+        break;
+    case 5:
+        val = fData5[idx];
+        break;
+    }
+
     return kTRUE;
 }
Index: trunk/MagicSoft/Mars/manalysis/MArrivalTime.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MArrivalTime.h	(revision 2755)
+++ trunk/MagicSoft/Mars/manalysis/MArrivalTime.h	(revision 2756)
@@ -4,4 +4,7 @@
 #ifndef ROOT_TArrayF
 #include <TArrayF.h>
+#endif
+#ifndef ROOT_TArrayS
+#include <TArrayS.h>
 #endif
 #ifndef ROOT_TSpline
@@ -12,5 +15,5 @@
 #endif
 
-class MGeomCam;
+class MGeomPix;
 class MRawEvtData;
 class MRawEvtPixelIter;
@@ -20,5 +23,13 @@
 private:
     TArrayF fData;  // Stores the arrival times
+ 
+    TArrayF fData2; // Clusters with at most 2 pix 
+    TArrayF fData3; // Clusters with at most 3 pix                      
+    TArrayF fData4; // Clusters with at most 4 pix                      
+    TArrayF fData5; // Clusters with at most 5 pix 
 
+    Bool_t  *fPixelChecked; // For each pixel says if it's already been checked
+    TArrayS fCluster; // Idxs of the pixels in the current cluster
+    TArrayS fakeData; //Test purpose
 public:
     MArrivalTime(const char *name=NULL, const char *title=NULL);
@@ -28,4 +39,9 @@
 
     void Calc(const MRawEvtData &evt, const MGeomCam &geom); // Calculates arrival times
+
+    void  MArrivalTime::EvalClusters(const MRawEvtData &evt, const MGeomCam &geom);
+
+    void MArrivalTime::CheckNeighbours(const MRawEvtData &evt, const MGeomCam &geom,
+				       Short_t idx, Short_t *dimCluster);
 
     const TArrayF &GetData() const { return fData; }
