Index: /trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 2637)
+++ /trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 2638)
@@ -73,4 +73,7 @@
 #pragma link C++ class MExtractSignal+;
 
+#pragma link C++ class MArrivalTime+;
+#pragma link C++ class MArrivalTimeCalc+;
+
 
 #endif
Index: /trunk/MagicSoft/Mars/manalysis/MArrivalTime.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MArrivalTime.cc	(revision 2638)
+++ /trunk/MagicSoft/Mars/manalysis/MArrivalTime.cc	(revision 2638)
@@ -0,0 +1,155 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Sebastian Raducci, 12/2003 <mailto:raducci@fisica.uniud.it>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MArrivalTime
+//
+// P R E L I M I N A R Y
+// Do not use this container. It has yet to be defined.
+/////////////////////////////////////////////////////////////////////////////
+#include "MArrivalTime.h"
+
+#include "MGeomCam.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MRawEvtPixelIter.h"
+#include "MRawEvtData.h"
+
+ClassImp(MArrivalTime);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Creates an object containing the arrival time for each pixel in the event
+//
+MArrivalTime::MArrivalTime(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MArrivalTime";
+    fTitle = title ? title : "Photons arrival times Information";
+}
+
+//
+// Calculates the arrival time for each pixel (for now, simply by finding the peak)
+//
+
+void MArrivalTime::Calc(const MRawEvtData &evt, const MGeomCam &geom)
+{
+    const Int_t n = geom.GetNumPixels();
+
+    fData.Set(n);
+    fData.Reset();
+
+    MRawEvtPixelIter pixel((MRawEvtData*)&evt);
+
+    Int_t saturatedpixels = 0;
+
+    while ( pixel.Next() )
+    {
+        const UInt_t idx = pixel.GetPixelId();
+
+        Byte_t *ptr = pixel.GetHiGainSamples();
+
+	Int_t n = evt.GetNumHiGainSamples();
+
+        Int_t i;
+
+        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;
+               }
+        }
+
+	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;
+
+
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Returns the arrival time value (for now, it's the FADC slice number).
+//
+
+Bool_t MArrivalTime::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
+{
+    if (idx<0 || idx>=fData.GetSize())
+        return kFALSE;
+
+    val = fData[idx];
+    return kTRUE;
+}
+
+void MArrivalTime::DrawPixelContent(Int_t num) const
+{
+    *fLog << warn << "MArrivalTime::DrawPixelContent - not available." << endl;
+}
Index: /trunk/MagicSoft/Mars/manalysis/MArrivalTime.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MArrivalTime.h	(revision 2638)
+++ /trunk/MagicSoft/Mars/manalysis/MArrivalTime.h	(revision 2638)
@@ -0,0 +1,38 @@
+#ifndef MARS_MArrivalTime
+#define MARS_MArrivalTime
+
+#ifndef ROOT_TArrayD
+#include <TArrayD.h>
+#endif
+#ifndef MARS_MCamEvent
+#include "MCamEvent.h"
+#endif
+
+class MGeomCam;
+class MRawEvtData;
+class MRawEvtPixelIter;
+
+class MArrivalTime : public MCamEvent
+{
+private:
+    TArrayD fData;  // Stores the arrival times
+
+public:
+    MArrivalTime(const char *name=NULL, const char *title=NULL);
+    ~MArrivalTime() { }
+
+    UInt_t GetNumPixels() const { return fData.GetSize(); }
+
+    void Calc(const MRawEvtData &evt, const MGeomCam &geom); // Calculates arrival times
+
+    const TArrayD &GetData() const { return fData; }
+
+    Double_t operator[](int i) { return fData[i]; }
+
+    Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
+    void DrawPixelContent(Int_t num) const;
+
+    ClassDef(MArrivalTime, 2)    // class for an event containing the arrival times
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.cc	(revision 2638)
+++ /trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.cc	(revision 2638)
@@ -0,0 +1,135 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Sebastian Raducci 12/2003 <mailto:raducci@fisica.uniud.it>
+!
+!   Copyright: MAGIC Software Development, 2002-2003
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+//   MArrivalTimeCalc
+//
+//   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. 
+//
+// Input Containers:
+//   MRawEvtData
+//
+// Output Containers:
+//   MArrivalTime
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "MArrivalTime.h"
+#include "MArrivalTimeCalc.h"
+
+#include "MParList.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MGeomCam.h"
+#include "MMcRunHeader.hxx"
+
+#include "MRawRunHeader.h"
+#include "MRawEvtData.h"       // MRawEvtData::GetNumPixels
+#include "MCameraData.h"
+#include "MRawEvtPixelIter.h"
+
+ClassImp(MArrivalTimeCalc);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MArrivalTimeCalc::MArrivalTimeCalc(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MArrivalTimeCalc";
+    fTitle = title ? title : "Calculate photons arrival time";
+
+    AddToBranchList("MRawEvtData.fHiGainPixId");
+    AddToBranchList("MRawEvtData.fLoGainPixId");
+    AddToBranchList("MRawEvtData.fHiGainFadcSamples");
+    AddToBranchList("MRawEvtData.fLoGainFadcSamples");
+
+}
+
+// --------------------------------------------------------------------------
+//
+// The PreProcess searches for the following input containers:
+//  - MRawRunHeader
+//  - MRawEvtData
+//  - MArrivalTime
+//  - MGeomCam
+//
+// The following output containers are also searched and created if
+// they were not found:
+//  - MArrivalTime
+//
+Int_t MArrivalTimeCalc::PreProcess(MParList *pList)
+{
+    fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
+    if (!fRunHeader)
+    {
+        *fLog << err << "MRawRunHeader not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
+    if (!fRawEvt)
+    {
+        *fLog << err << "MRawEvtData not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
+    if (!fGeom)
+    {
+        *fLog << err << "MGeomCam not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fArrTime = (MArrivalTime*)pList->FindCreateObj(AddSerialNumber("MArrivalTime"));
+    if (!fArrTime)
+        return kFALSE;
+
+    return kTRUE;
+}
+
+
+// --------------------------------------------------------------------------
+// Evaluation of the mean arrival times (for now it stands for the maximum in slices units)
+// per pixel and store them in the MArrivalTime container.
+//
+Int_t MArrivalTimeCalc::Process()
+{
+    MRawEvtPixelIter pixel(fRawEvt);
+
+    fArrTime->Calc((const MRawEvtData&) *fRawEvt,(const MGeomCam&) *fGeom);
+
+    fArrTime->SetReadyToSave();
+
+    return kTRUE;
+}
Index: /trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.h	(revision 2638)
+++ /trunk/MagicSoft/Mars/manalysis/MArrivalTimeCalc.h	(revision 2638)
@@ -0,0 +1,52 @@
+#ifndef MARS_MArrivalTimeCalc
+#define MARS_MArrivalTimeCalc
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// 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.                //
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MRawEvtData;
+class MCameraData;
+class MRawRunHeader;
+class MGeomCam;
+class MArrivalTime;
+
+class MArrivalTimeCalc : public MTask
+{
+    MRawEvtData    *fRawEvt;     // raw event data (time slices)
+    MCameraData    *fCamData;    // Cerenkov Photon Event used for calculation
+    MRawRunHeader  *fRunHeader;  // RunHeader information
+    MGeomCam       *fGeom;       // Geometry information
+    MArrivalTime   *fArrTime;    // Container with the photons arrival times
+
+    Bool_t          fEnableFix;  // fix for a bug in files from older camera versions (<=40)
+    Bool_t          fIsMcFile;
+
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+    Int_t PostProcess() {return kTRUE;}
+    Bool_t ReInit(MParList *pList) {
+        return kTRUE;
+    }
+
+public:
+    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
+};
+
+
+#endif
Index: /trunk/MagicSoft/Mars/mmain/MEventDisplay.cc
===================================================================
--- /trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 2637)
+++ /trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 2638)
@@ -69,4 +69,5 @@
 #include "MHillasSrcCalc.h"      // MHillasSrcCalc
 #include "MBlindPixelCalc.h"     // MBlindPixelCalc
+#include "MArrivalTimeCalc.h"    // MArrivalTimeCalc
 #include "MFillH.h"              // MFillH
 
@@ -80,4 +81,6 @@
 #include "MHCamera.h"            // MHCamera
 #include "MRawEvtData.h"         // MRawEvtData
+#include "MArrivalTime.h"        // MArrivalTime
+
 
 ClassImp(MEventDisplay);
@@ -171,4 +174,6 @@
     MHEvent *evt5 = new MHEvent(MHEvent::kEvtRelativeSignal);
     MHEvent *evt6 = new MHEvent(MHEvent::kEvtCleaningLevels);
+    MHEvent *evt7 = new MHEvent(MHEvent::kEvtSignal);
+
     evt1->SetName("Signal");
     evt2->SetName("Cleaned");
@@ -177,4 +182,6 @@
     evt5->SetName("Signal/PedRMS");
     evt6->SetName("CleanLevels");
+    evt7->SetName("ArrivalTime");
+
     plist->AddToList(evt1);
     plist->AddToList(evt2);
@@ -183,4 +190,6 @@
     plist->AddToList(evt5);
     plist->AddToList(evt6);
+    plist->AddToList(evt7);
+
 
     MMcPedestalCopy   *pcopy = new MMcPedestalCopy;
@@ -198,4 +207,7 @@
     MHillasCalc       *hcalc = new MHillasCalc;
     MHillasSrcCalc    *scalc = new MHillasSrcCalc;
+    MArrivalTimeCalc  *tcalc = new MArrivalTimeCalc;
+    MFillH            *fill7 = new MFillH(evt7, "MArrivalTime",  "MFillH7");
+
 
     MFilter *f1=new MFDataMember("MRawRunHeader.fRunType", '>', 255.5);
@@ -221,4 +233,7 @@
     tlist->AddToList(hcalc);
     tlist->AddToList(scalc);
+    tlist->AddToList(tcalc);
+    tlist->AddToList(fill7);
+
 
     //
