Index: trunk/MagicSoft/Mars/manalysis/MArrivalTime.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MArrivalTime.cc	(revision 2749)
+++ trunk/MagicSoft/Mars/manalysis/MArrivalTime.cc	(revision 2752)
@@ -27,6 +27,6 @@
 // MArrivalTime
 //
-// P R E L I M I N A R Y
-// Do not use this container. It has yet to be defined.
+// Times are calculated using the TSpline5 Root Class
+// 
 /////////////////////////////////////////////////////////////////////////////
 #include "MArrivalTime.h"
@@ -55,5 +55,8 @@
 
 //
-// Calculates the arrival time for each pixel (for now, simply by finding the peak)
+// Calculates the arrival time for each pixel 
+// Possible Methods 
+// Case 1: Spline5 (From TSpline5 Root Class)
+// 
 //
 
@@ -66,71 +69,71 @@
 
     MRawEvtPixelIter pixel((MRawEvtData*)&evt);
-
-    Int_t saturatedpixels = 0;
-
+   
     while ( pixel.Next() )
     {
-        const UInt_t idx = pixel.GetPixelId();
+	const UInt_t idx = pixel.GetPixelId();
 
-        Byte_t *ptr = pixel.GetHiGainSamples();
+//If pixel has saturated and hasn't lo gains we return -1
 
-	Int_t n = evt.GetNumHiGainSamples();
+        if (pixel.GetMaxHiGainSample() == 0xff)
+        {   
+            if (!pixel.HasLoGain())        
+	    {
+                fData[idx]=-1.0;
+            }
+            else //Calculate time using Lo Gains
+            {
+		Byte_t *ptr = pixel.GetLoGainSamples();
 
-        Int_t i;
+		Int_t nSlice = evt.GetNumLoGainSamples();
+//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 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;
+            }
+	}
+        else //Calculate time using Hi Gains
+        {
+	    Byte_t *ptr = pixel.GetHiGainSamples();
 
-        Double_t arrtime = 0;
-
-	Double_t maxsign = 0;
-
-        for (i=0; i<n; i++)
-        {
-            if (ptr[i]==0xff)
-                break;
-            if (ptr[i]>maxsign)
-               { 
-                maxsign = ptr[i];
-	        arrtime = i+1;
-               }
+	    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);
+	    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;
         }
-
-	Bool_t saturatedlg = kFALSE;
-
-        if (i!=n)
-        {
-	    arrtime = 0;
-	    maxsign = 0;
-
-            ptr = pixel.GetLoGainSamples();
-            if (ptr==NULL)
-            {
-             *fLog << warn << "WARNING - Pixel #" << idx 
-                   << " saturated but has no low gains... skipping!" << endl;
-             return;
-            }
-
-            for (i=0; i<n; i++)
-            {
-                if (ptr[i]==0xff)
-                    saturatedlg = kTRUE;
-
-	    	if (ptr[i]>maxsign)
-                   {
-                    maxsign = ptr[i];
-		    arrtime = i+1;
-		   }
-            }
-        }
-
-        fData[idx]=arrtime;
-
-	if (saturatedlg)
-	  saturatedpixels++;
     }
-
-    if (saturatedpixels>0)
-        *fLog << warn << "WARNING: " << saturatedpixels 
-              << " pixel(s) had saturating low gains..." << endl;
-
-
 }
 
@@ -138,5 +141,5 @@
 // --------------------------------------------------------------------------
 //
-// Returns the arrival time value (for now, it's the FADC slice number).
+// Returns the arrival time value
 //
 
Index: trunk/MagicSoft/Mars/manalysis/MArrivalTime.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MArrivalTime.h	(revision 2749)
+++ trunk/MagicSoft/Mars/manalysis/MArrivalTime.h	(revision 2752)
@@ -2,6 +2,9 @@
 #define MARS_MArrivalTime
 
-#ifndef ROOT_TArrayD
-#include <TArrayD.h>
+#ifndef ROOT_TArrayF
+#include <TArrayF.h>
+#endif
+#ifndef ROOT_TSpline
+#include <TSpline.h>
 #endif
 #ifndef MARS_MCamEvent
@@ -16,5 +19,5 @@
 {
 private:
-    TArrayD fData;  // Stores the arrival times
+    TArrayF fData;  // Stores the arrival times
 
 public:
@@ -26,5 +29,5 @@
     void Calc(const MRawEvtData &evt, const MGeomCam &geom); // Calculates arrival times
 
-    const TArrayD &GetData() const { return fData; }
+    const TArrayF &GetData() const { return fData; }
 
     Double_t operator[](int i) { return fData[i]; }
Index: trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.cc	(revision 2749)
+++ trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.cc	(revision 2752)
@@ -28,8 +28,6 @@
 //
 //   This is a task that calculates the arrival times of photons. 
-//   For now, it returns the number of time slice containig the maximum value.
-//
-//   P R E L I M I N A R Y
-//   Other more sophisticated methods have to be implemented. 
+//   It returns the absolute maximum of the spline that interpolates
+//   the FADC slices 
 //
 // Input Containers:
@@ -37,9 +35,9 @@
 //
 // Output Containers:
-//   //MArrivalTime
+//   MArrivalTime
 //   MRawEvtData
 //////////////////////////////////////////////////////////////////////////////
 
-//#include "MArrivalTime.h"
+#include "MArrivalTime.h"
 #include "MArrivalTimeCalc.h"
 
@@ -65,4 +63,5 @@
 // Default constructor.
 //
+
 MArrivalTimeCalc::MArrivalTimeCalc(const char *name, const char *title)
 {
@@ -70,8 +69,8 @@
     fTitle = title ? title : "Calculate photons arrival time";
 
-    AddToBranchList("MRawEvtData.fHiGainPixId");
-    AddToBranchList("MRawEvtData.fLoGainPixId");
-    AddToBranchList("MRawEvtData.fHiGainFadcSamples");
-    AddToBranchList("MRawEvtData.fLoGainFadcSamples");
+//    AddToBranchList("MRawEvtData.fHiGainPixId");
+//    AddToBranchList("MRawEvtData.fLoGainPixId");
+//    AddToBranchList("MRawEvtData.fHiGainFadcSamples");
+//    AddToBranchList("MRawEvtData.fLoGainFadcSamples");
 
 }
@@ -82,10 +81,10 @@
 //  - MRawRunHeader
 //  - MRawEvtData
-//  //- MArrivalTime
+//  - MArrivalTime
 //  - MGeomCam
 //
 // The following output containers are also searched and created if
 // they were not found:
-//  //- MArrivalTime
+//  - MArrivalTime
 //  - MRawEvtData
 //
@@ -114,8 +113,8 @@
     }
 
-/*    fArrTime = (MArrivalTime*)pList->FindCreateObj(AddSerialNumber("MArrivalTime"));
+    fArrTime = (MArrivalTime*)pList->FindCreateObj(AddSerialNumber("MArrivalTime"));
     if (!fArrTime)
         return kFALSE;
-*/
+
     return kTRUE;
 }
@@ -123,5 +122,5 @@
 
 // --------------------------------------------------------------------------
-// Evaluation of the mean arrival times (for now it stands for the maximum in slices units)
+// Evaluation of the mean arrival times (spline interpolation)
 // per pixel and store them in the MArrivalTime container.
 //
@@ -130,8 +129,8 @@
     MRawEvtPixelIter pixel(fRawEvt);
 
-  //fArrTime->Calc((const MRawEvtData&) *fRawEvt,(const MGeomCam&) *fGeom);
-  //fArrTime->SetReadyToSave();
+    fArrTime->Calc((const MRawEvtData&) *fRawEvt,(const MGeomCam&) *fGeom);
+    fArrTime->SetReadyToSave();
 
-  //while (pixel.Next()){;}
+    while (pixel.Next()){;}
    
     return kTRUE;
Index: trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.h	(revision 2749)
+++ trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.h	(revision 2752)
@@ -6,7 +6,7 @@
 // MArrivalTimeCalc                                                        //
 //                                                                         //
-// Evaluates the number of time slice into which the signal reaches a max. //
-// P R E L I M I N A R Y                                                   //
-// Other more sophisticated methods have to be implemented.                //
+// Evaluates the Arrival Times                                             //
+//                                                                         //
+//                                                                         //
 /////////////////////////////////////////////////////////////////////////////
 
@@ -27,5 +27,5 @@
     MRawRunHeader  *fRunHeader;  // RunHeader information
     MGeomCam       *fGeom;       // Geometry information
-//  MArrivalTime   *fArrTime;    // Container with the photons arrival times
+    MArrivalTime   *fArrTime;    // Container with the photons arrival times
 
     Bool_t          fEnableFix;  // fix for a bug in files from older camera versions (<=40)
@@ -42,9 +42,7 @@
     MArrivalTimeCalc(const char *name=NULL, const char *title=NULL);
 
-    // FIXME: The array size should be checked!
-
     ~MArrivalTimeCalc(){}
 
-    ClassDef(MArrivalTimeCalc, 0)   // Task to calculate cerenkov photons from raw data
+    ClassDef(MArrivalTimeCalc, 0)   // Task to calculate Arrival Times from raw data
 };
 
