Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 7610)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 7611)
@@ -18,4 +18,18 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2006/03/15 Stefan Ruegamer
+
+   * manalysis/MCameraData.cc
+     - inserted an image cleaning based on the time information
+     of the shower (CalcCleaningArrivalTime)
+   * manalysis/MCameraData.h
+     - made entry for "CalcCleaningArrivalTime"
+   * mimage/MImgCleanStd.cc
+     - created entries for the new image cleaning named "Time"
+   * mimage/MImgCleanStd.h
+     - inserted entry "kTime"
+
+
 
  2006/03/14 Daniela Dorner
Index: /trunk/MagicSoft/Mars/NEWS
===================================================================
--- /trunk/MagicSoft/Mars/NEWS	(revision 7610)
+++ /trunk/MagicSoft/Mars/NEWS	(revision 7611)
@@ -2,4 +2,13 @@
 
  *** Version  <cvs>
+
+   - star: Added new image cleaning based on the arrival time of the shower.
+     The new cleaning can be accessed using the parameter "Time" instead of
+     the the old one (like "Absolute) in the star.rc-file.
+     Recommended parameters:
+     MImgCleanStd.CleanLevel1:  8.2
+     MImgCleanStd.CleanLevel2:  5
+     MImgCleanStd.CleanRings:   2
+     MImgCleanStd.KeepSinglePixels: No
 
    - star: Simplified the calculation of the effective on time. By letting
Index: /trunk/MagicSoft/Mars/manalysis/MCameraData.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCameraData.cc	(revision 7610)
+++ /trunk/MagicSoft/Mars/manalysis/MCameraData.cc	(revision 7611)
@@ -18,6 +18,7 @@
 !   Author(s): Thomas Bretz, 10/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
 !   Author(s): Hendrik Bartko, 08/2004 <mailto:hbartko@mppmu.mpg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Author(s): Stefan Ruegamer, 03/2006 <mailto:snruegam@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2006
 !
 !
@@ -380,4 +381,88 @@
 }
 
+void MCameraData::CalcCleaningArrivalTime(const MSignalCam &evt, const MGeomCam &geom)
+{
+    const Int_t n = geom.GetNumPixels();
+
+    // Reset arrays
+    fData.Set(n);
+    fData.Reset();
+
+    fValidity.Set(n);
+    fValidity.Reset();
+
+    // check validity of noise
+    const Int_t entries = evt.GetNumPixels();
+    TArrayD u(6), w(6);
+    TArrayI ii(6);
+
+    for (int i=0; i<entries; i++)
+    {
+        if (evt[i].IsPixelUnmapped())
+            continue;
+
+        const Double_t t0 = evt[i].GetArrivalTime();
+        const Double_t s0 = evt[i].GetNumPhotons();
+        const Double_t r0 = geom.GetPixRatio(i);
+        const Double_t x0 = geom[i].GetX();
+        const Double_t y0 = geom[i].GetY();
+
+        const Double_t e0 = s0<0.01 ? 100 : 1./s0;
+
+        const Int_t n2 = geom[i].GetNumNeighbors();
+
+        Int_t cnt2=0;
+        for (int j=0; j<n2; j++)
+        {
+            Int_t idx = geom[i].GetNeighbor(j);
+
+            if (evt[idx].IsPixelUnmapped())
+                continue;
+
+            const Double_t tj = evt[idx].GetArrivalTime()-t0;
+            const Double_t sj = evt[idx].GetNumPhotons();
+            const Double_t rj = geom.GetPixRatio(idx)+r0;
+            const Double_t xj = geom[idx].GetX()-x0;
+            const Double_t yj = geom[idx].GetY()-y0;
+
+            const Double_t d2 = xj*xj+yj*yj;
+
+            const Double_t ej = sj<0.01 ? 100 : 1./sj;
+
+            u[cnt2] =  tj*tj/rj;
+            w[cnt2] =  1./(e0+ej)/d2;         // TYPE I+II
+            cnt2++;
+        }
+
+        TMath::Sort(cnt2, u.GetArray(), ii.GetArray(), kFALSE);
+
+        Double_t sumt = 0;
+        Double_t sumw = 0;
+        for (int j=0; j<TMath::Min(cnt2, 3); j++)
+        {
+            sumt += u[ii[j]]*w[ii[j]];
+            sumw += w[ii[j]];
+        }
+
+        const Double_t wuz = TMath::Sqrt(sumt/sumw);
+
+        if (TMath::IsNaN(wuz))
+            *fLog << warn << "WARNING - MCameraData " << sumt << " " << sumw << endl;
+
+        Double_t val = s0<0 || TMath::IsNaN(wuz) || wuz<1e-200 ? 0 : s0*r0/wuz;
+
+        if ((s0>0 && wuz<1e-200) || val>100)
+            val=100;
+
+        fData[i] = TMath::Log10(val+1)*5;
+
+        if (TMath::IsNaN(fData[i]))
+            //     0                1e-6          0              NaN
+            *fLog << warn << "WARNING - MCameraData " << sumt << " " << sumw << " " << wuz << " " << val << endl;
+
+        fValidity[i] = 1;
+    }
+}
+
 // --------------------------------------------------------------------------
 //
Index: /trunk/MagicSoft/Mars/manalysis/MCameraData.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCameraData.h	(revision 7610)
+++ /trunk/MagicSoft/Mars/manalysis/MCameraData.h	(revision 7611)
@@ -42,4 +42,5 @@
                                  const MGeomCam &geom);
     void CalcCleaningAbsolute(const MSignalCam &evt, const MGeomCam &geom);
+    void CalcCleaningArrivalTime(const MSignalCam &evt, const MGeomCam &geom);
 
     const TArrayD &GetData() const { return fData; }
Index: /trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 7610)
+++ /trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 7611)
@@ -19,6 +19,7 @@
 !   Author(s): Harald Kornmayer, 1/2001
 !   Author(s): Nadia Tonello, 4/2003 <mailto:tonello@mppmu.mpg.de>
+!   Author(s): Stefan Ruegamer, 03/2006 <mailto:snruegam@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2003
+!   Copyright: MAGIC Software Development, 2000-2006
 !
 !
@@ -580,5 +581,5 @@
 
     fPed=0;
-    if (fCleaningMethod!=kAbsolute)
+    if (fCleaningMethod!=kAbsolute && fCleaningMethod!=kTime)
     {
         fPed = (MPedPhotCam*)pList->FindObject(AddSerialNumber(fNamePedPhotCam), "MPedPhotCam");
@@ -622,4 +623,7 @@
         fData->CalcCleaningAbsolute(*fEvt, *fCam);
         break;
+    case kTime:
+        fData->CalcCleaningArrivalTime(*fEvt, *fCam);
+        break;
     default:
         break;
@@ -686,4 +690,8 @@
         *fLog << "absolute";
         break;
+    case kTime:
+        *fLog << "time";
+        break;
+
     }
     *fLog << " cleaning" << endl;
@@ -822,4 +830,5 @@
         case kProbability: out << "Probability"; break;
         case kAbsolute:    out << "Absolute";    break;
+        case kTime    :    out << "Time";        break;
         default:
             break;
@@ -889,4 +898,6 @@
         if (s.BeginsWith("absolute"))
             SetMethod(kAbsolute);
+        if (s.BeginsWith("time"))
+            SetMethod(kTime);
     }
 
Index: /trunk/MagicSoft/Mars/mimage/MImgCleanStd.h
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MImgCleanStd.h	(revision 7610)
+++ /trunk/MagicSoft/Mars/mimage/MImgCleanStd.h	(revision 7611)
@@ -23,5 +23,6 @@
         kDemocratic,
         kProbability,
-        kAbsolute
+        kAbsolute,
+        kTime,
     } CleaningMethod_t;
 
@@ -32,5 +33,5 @@
 
     const MGeomCam     *fCam;  //!
-          MSignalCam  *fEvt;  //!
+          MSignalCam   *fEvt;  //!
           MPedPhotCam  *fPed;  //!
           MCameraData  *fData; //!
