Index: trunk/MagicSoft/Mars/manalysis/MArrivalTime.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MArrivalTime.cc	(revision 2784)
+++ trunk/MagicSoft/Mars/manalysis/MArrivalTime.cc	(revision 2785)
@@ -55,4 +55,11 @@
 }
 
+// Sets every pixel arrival time to -1
+void MArrivalTime::CleanArray(const MGeomCam &geom)
+{
+    fData.Set(geom.GetNumPixels());
+    fData.Reset(-1.0);
+}
+
 //
 // Calculates the arrival time for each pixel 
@@ -62,81 +69,32 @@
 //
 
-void MArrivalTime::Calc(const MRawEvtData &evt, const MGeomCam &geom)
-{
-    const Int_t n = geom.GetNumPixels();
-
-    fData.Set(n);
-    fData.Reset();
-
-    MRawEvtPixelIter pixel((MRawEvtData*)&evt);
-   
-    while ( pixel.Next() )
-    {
-	const UInt_t idx = pixel.GetPixelId();
-
-//If pixel has saturated and hasn't lo gains we return -1
-
-        if (pixel.GetMaxHiGainSample() == 0xff)
-        {   
-            if (!pixel.HasLoGain())        
-	    {
-                fData[idx]=-1.0;
-            }
-            else //Calculate time using Lo Gains
-            {
-		Byte_t *ptr = pixel.GetLoGainSamples();
-
-		Int_t nSlice = evt.GetNumLoGainSamples();
+void MArrivalTime::Calc(const Byte_t *fadcSamples, const Short_t nSlice,
+              const Short_t idx, const MGeomCam &geom)
+{
+
 //Some casts are needed because TSpline5 constructor accepts only Double_t values
-		Double_t ptr2[nSlice];
-		for (Int_t i = 0; i < nSlice; i++)
-		    ptr2[i]=(Double_t)ptr[i];
-		TSpline5 *spline = new TSpline5("spline",(Double_t) 0,(Double_t)(nSlice - 1),ptr2,nSlice);
+    Double_t ptr[nSlice];
+
+    for (Int_t i = 0; i < nSlice; i++)
+	ptr[i]=(Double_t)fadcSamples[i];
+
+    TSpline5 *spline = new TSpline5("spline",(Double_t) 0,
+				    (Double_t)(nSlice - 1),ptr,nSlice);
 //Now find the maximum evaluating the spline function at every 1/10 time slice
-		Double_t abscissa=0.0;
-		Double_t maxAb=0.0;
-		Double_t maxOrd=0.0;
-		Double_t swap;
-		while (abscissa <= nSlice - 1) 
-		{
-		    swap=spline->Eval(abscissa);
-		    if (swap > maxOrd)
-		    {
-			maxOrd = swap;
-			maxAb  = abscissa;
-		    }
-		    abscissa += 0.1;
-		}
-		fData[idx]=maxAb;
-            }
+    Double_t abscissa=0.0;
+    Double_t maxAb=0.0;
+    Double_t maxOrd=0.0;
+    Double_t swap;
+    while (abscissa <= nSlice - 1) 
+    {
+	swap=spline->Eval(abscissa);
+	if (swap > maxOrd)
+	{
+	    maxOrd = swap;
+	    maxAb  = abscissa;
 	}
-        else //Calculate time using Hi Gains
-        {
-	    Byte_t *ptr = pixel.GetHiGainSamples();
-
-	    Int_t nSlice = evt.GetNumHiGainSamples();
-//Some casts are needed because TSpline5 constructor accepts only Double_t values
-	    Double_t  ptr2[nSlice];
-	    for (Int_t i = 0; i < nSlice; i++)
-		ptr2[i]=(Double_t)ptr[i];
-	    TSpline5 *spline = new TSpline5("spline",(Double_t) 0,(Double_t)(nSlice - 1),ptr2,nSlice);
-//Now find the maximum evaluating the spline function at every 1/10 time slice
-	    Double_t abscissa=0.0;
-	    Double_t maxAb=0.0;
-	    Double_t maxOrd=0.0;
-	    Double_t swap;
-	    while (abscissa <= nSlice - 1) 
-	    {
-		swap=spline->Eval(abscissa);
-		if (swap > maxOrd)
-		{
-		    maxOrd = swap;
-		    maxAb  = abscissa;
-		}
-		abscissa += 0.1;
-	    }
-	    fData[idx]=maxAb;
-        }
-    }
+	abscissa += 0.1;
+    }
+    fData[idx]=maxAb;
 }
 
@@ -157,11 +115,11 @@
 
     fData2.Set(n);
-    fData2.Reset(-1);
+    fData2.Reset(-1.0);
     fData3.Set(n);
-    fData3.Reset(-1);
+    fData3.Reset(-1.0);
     fData4.Set(n);
-    fData4.Reset(-1);
+    fData4.Reset(-1.0);
     fData5.Set(n);
-    fData5.Reset(-1);
+    fData5.Reset(-1.0);
 
     MRawEvtPixelIter pixel((MRawEvtData*)&evt);
@@ -181,5 +139,5 @@
     }
 // End of fakeData preparation
-
+    *fLog << warn << "fin qui bene" << endl;
 // Max dimension of cluster
     Short_t dimCluster;
Index: trunk/MagicSoft/Mars/manalysis/MArrivalTime.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MArrivalTime.h	(revision 2784)
+++ trunk/MagicSoft/Mars/manalysis/MArrivalTime.h	(revision 2785)
@@ -38,9 +38,12 @@
     UInt_t GetNumPixels() const { return fData.GetSize(); }
 
-    void Calc(const MRawEvtData &evt, const MGeomCam &geom); // Calculates arrival times
+    void CleanArray(const MGeomCam &geom); //Sets every arr time to -1
 
-    void  MArrivalTime::EvalClusters(const MRawEvtData &evt, const MGeomCam &geom);
+    void Calc(const Byte_t *fadcSamples, const Short_t nSlice,
+              const Short_t idx, const MGeomCam &geom); // Calculates arrival times
 
-    void MArrivalTime::CheckNeighbours(const MRawEvtData &evt, const MGeomCam &geom,
+    void EvalClusters(const MRawEvtData &evt, const MGeomCam &geom);
+
+    void CheckNeighbours(const MRawEvtData &evt, const MGeomCam &geom,
 				       Short_t idx, Short_t *dimCluster);
 
Index: trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.cc	(revision 2784)
+++ trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.cc	(revision 2785)
@@ -129,9 +129,29 @@
     MRawEvtPixelIter pixel(fRawEvt);
 
-    fArrTime->Calc((const MRawEvtData&) *fRawEvt,(const MGeomCam&) *fGeom);
+// Every pixel is set to -1
+    fArrTime->CleanArray((const MGeomCam&) *fGeom);
+
+    while (pixel.Next())
+    {
+	const UInt_t idx = pixel.GetPixelId();
+// If pixel is saturated we use LoGains
+        if (pixel.GetMaxHiGainSample() == 0xff && pixel.HasLoGain())
+	{
+	    const Byte_t *ptr = pixel.GetLoGainSamples();
+	    const Short_t nSlice = fRawEvt->GetNumLoGainSamples();
+	    fArrTime->Calc(ptr, nSlice, idx, (const MGeomCam&) *fGeom);
+	}
+// Use HiGains
+        else
+	{
+            const Byte_t *ptr = pixel.GetHiGainSamples();
+	    const Short_t nSlice = fRawEvt->GetNumHiGainSamples();
+	    fArrTime->Calc(ptr, nSlice, idx, (const MGeomCam&) *fGeom);
+	}
+// If pixel is saturated and hasn't lo gains we do nothing, it's value remains -1
+    }
+    
     fArrTime->SetReadyToSave();
 
-    while (pixel.Next()){;}
-   
     return kTRUE;
 }
