Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 3101)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 3102)
@@ -4,4 +4,12 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 
+ 2004/02/11: Hendrik Bartko
+   * manalysis/MExtractSignal2 (Signal Extraction with a Sliding Window)
+     - introduced a validity check for the set-function of the window size (even number of slices, WindowSize < NumberSlices)
+   * manalysis/MArrivalTimeCalc2 (Arrival Time Calculation with a Sliding Window)
+     - introduced the calculation of the arrival time as the signal weighted mean of the time slices in the maximum window
+
+
  2004/02/11: Markus Gaug
    * mcalib/MCalibrationCalc.cc
Index: /trunk/MagicSoft/Mars/manalysis/MExtractSignal2.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MExtractSignal2.cc	(revision 3101)
+++ /trunk/MagicSoft/Mars/manalysis/MExtractSignal2.cc	(revision 3102)
@@ -17,4 +17,5 @@
 !
 !   Author(s): Thomas Bretz, 02/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!              Hendrik Bartko, 01/2004 <mailto:hbartko@mppmu.mpg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2004
@@ -27,8 +28,8 @@
 //   MExtractSignal2
 //
-//  Calculate the signal as the fWindow time slices which have the highest
+//  Calculate the signal as the fWindowSize time slices which have the highest
 // integral contents.
 //
-// Calculation of arrival time not yet implemented
+// 
 //
 //////////////////////////////////////////////////////////////////////////////
@@ -49,4 +50,6 @@
 #include "MExtractedSignalPix.h"
 
+//#include "MArrivalTime.h"
+
 ClassImp(MExtractSignal2);
 
@@ -54,7 +57,7 @@
 
 const Byte_t MExtractSignal2::fgSaturationLimit = 254;
-const Byte_t MExtractSignal2::fgFirst  =  2;
+const Byte_t MExtractSignal2::fgFirst  =  0;
 const Byte_t MExtractSignal2::fgLast   = 14;
-const Byte_t MExtractSignal2::fgWindow =  8;
+const Byte_t MExtractSignal2::fgWindowSize = 6;
 
 // --------------------------------------------------------------------------
@@ -74,21 +77,42 @@
 }
 
-void MExtractSignal2::SetRange(Byte_t first, Byte_t last, Byte_t window)
-{
-
-    fNumHiGainSamples = last-first+1;
-    fNumLoGainSamples = last-first+1;
-
-    fHiGainFirst = first;
-    fLoGainFirst = first;
-
-    fWindow     = window & ~1;
-    fWindowSqrt = TMath::Sqrt((Float_t)fWindow);
-
-    if (fWindow==window)
-        return;
-
-    *fLog << warn << "MExtractSignal2::SetRange - Window size set to even " << fWindow << endl;
-}
+void MExtractSignal2::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast, Byte_t windowsize)
+{
+
+    fNumHiGainSamples = hilast-hifirst+1;
+    fNumLoGainSamples = lolast-lofirst+1;
+
+    fHiGainFirst = hifirst;
+    fLoGainFirst = lofirst;
+
+   
+    fWindowSize = windowsize & ~1;
+
+    if (fWindowSize != windowsize)
+      *fLog << warn << "MExtractSignal2::SetRange - window size has to be even, set to: " << int(fWindowSize) << " samples " << endl;
+    
+    if (fWindowSize<2) 
+    {
+      fWindowSize = 2;
+      *fLog << warn << "MExtractSignal2::SetRange - window size set to two samples" << endl;
+    }
+
+    if (fWindowSize > fNumHiGainSamples)
+    {
+      fWindowSize = fNumLoGainSamples & ~1;
+      *fLog << warn << "MExtractSignal2::SetRange - window size set to " << int(fWindowSize) << " samples " << endl;
+    }
+    
+    if (fWindowSize > fNumLoGainSamples)
+    {
+      fWindowSize = fNumLoGainSamples & ~1;
+      *fLog << warn << "MExtractSignal2::SetRange - window size set to " << int(fWindowSize) << " samples " << endl;
+    }
+
+    fWindowSizeSqrt = TMath::Sqrt((Float_t)fWindowSize);
+
+}
+
+
 
 // --------------------------------------------------------------------------
@@ -126,4 +150,9 @@
         return kFALSE;
     }
+/*
+    fArrivalTime = (MArrivalTime*)pList->FindCreateObj(AddSerialNumber("MArrivalTime"));
+    if (!fArrivalTime)
+        return kFALSE;
+ */
     return kTRUE;
 }
@@ -136,9 +165,9 @@
 
     //
-    // Calculate the sum of the first fWindow slices
+    // Calculate the sum of the first fWindowSize slices
     //
     sat = 0;
     Byte_t *p = ptr;
-    while (p<ptr+fWindow)
+    while (p<ptr+fWindowSize)
     {
         sum += *p;
@@ -159,8 +188,8 @@
     // This is fast and accurate (because we are using int's)
     //
-    max=0;
-    for (p=ptr; p+fWindow<end; p++)
-    {
-        sum += *(p+fWindow) - *p;
+    max=sum;
+    for (p=ptr; p+fWindowSize<end; p++)
+    {
+        sum += *(p+fWindowSize) - *p;
         if (sum>max)
             max = sum;
@@ -170,5 +199,5 @@
 // --------------------------------------------------------------------------
 //
-// Calculate the integral of the FADC of fWindow time slices which have the
+// Calculate the integral of the FADC of fWindowSize time slices which have the
 // highest signal
 //
@@ -178,7 +207,5 @@
     fSignals->Clear();
 
-    TString satpixels;
     Int_t sat=0;
-
     while (pixel.Next())
     {
@@ -190,9 +217,6 @@
         FindSignal(pixel.GetLoGainSamples()+fLoGainFirst, fNumLoGainSamples, sumlo, satlo);
         if (satlo)
-          {
             sat++;
-            satpixels += Form("%d%s",pixel.GetPixelId()," ");
-          }
-        
+
         //
         // Take correspodning pedestal
@@ -209,6 +233,6 @@
         // Set extracted signal with pedestal substracted
         //
-        pix.SetExtractedSignal(sumhi - pedes*fWindow, pedrms*fWindowSqrt,
-                               sumlo - pedes*fWindow, pedrms*fWindowSqrt);
+        pix.SetExtractedSignal(sumhi - pedes*fWindowSize, pedrms*fWindowSizeSqrt,
+                               sumlo - pedes*fWindowSize, pedrms*fWindowSizeSqrt);
 
         pix.SetGainSaturation(sathi, sathi, satlo);
@@ -219,5 +243,5 @@
     //
     if (sat)
-      *fLog << warn << "WARNING - Lo Gain saturated in " << sat << " pixels: " << satpixels << endl;
+        *fLog << warn << "WARNING - Lo Gain saturated in " << sat << " pixels." << endl;
 
     fSignals->SetReadyToSave();
