Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 3924)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 3925)
@@ -31,4 +31,7 @@
        the "low-gain" slices instead. This is necessary for the March 
        data!
+
+   * mjobs/MJCalibration.[h,cc]
+     - accept arrival time extractors deriving from MTimeExtractor
 
 
Index: /trunk/MagicSoft/Mars/macros/calibration.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/calibration.C	(revision 3924)
+++ /trunk/MagicSoft/Mars/macros/calibration.C	(revision 3925)
@@ -57,5 +57,5 @@
 static const TString inpath = "/mnt/Data/rootdata/Miscellaneous/2004_03_03/";
 static const Int_t pedrun  = 20123;
-static const Int_t calrun1 = 20126;
+static const Int_t calrun1 = 20125;
 static const Int_t calrun2 = 0;
 
@@ -63,14 +63,33 @@
 {
 
+
+  //
+  // Choose the signal Extractor:
+  //
   MExtractFixedWindowPeakSearch extractor;
-  //  extractor.SetRange(0,14,0,14);
+  //  MExtractSlidingWindow  extractor;   
+  //  MExtractFixedWindow    extractor;   
 
-  // MExtractSlidingWindow  extractor;   
-  // MExtractFixedWindow    extractor;   
+  //
+  // Set Ranges or Windows
+  //
+  //  extractor.SetRange(2,14,5,14);
+  //  extractor.SetWindows(8,8);
 
+  //
+  // Choose the arrival time Extractor:
+  //
   MExtractTimeHighestIntegral timeext;
+  // MExtractTimeSpline timeext;
+  //
+  // Set Ranges or Windows
+  //
+  // timeext.SetRange(0,14,6,14);
 
-  // MExtractTimeSpline timeext;
-  // timeext.SetRange(0,14,6,14);
+  //
+  // Tell if you want to calibrate times:
+  //
+  Bool_t useTimes = kTRUE;
+  //  Bool_t calibrateTimes = kFALSE;  
 
   MRunIter pruns;
@@ -103,5 +122,5 @@
   // an ascii-file with the corr. pixel numbers (see MBadPixelsCam)
   //
-  //  badcam.AsciiRead("badpixels.dat");
+  badcam.AsciiRead("badpixels.dat");
 
   MJPedestal pedloop;
@@ -133,5 +152,5 @@
   // If you want to calibrate the times as well, choose:
   //
-  calloop.SetRelTimeCalibration();
+  calloop.SetRelTimeCalibration(useTimes);
   calloop.SetExtractor(&extractor);
   calloop.SetTimeExtractor(&timeext);
@@ -162,7 +181,6 @@
   testloop.SetDisplay(display);
   testloop.SetBadPixels(calloop.GetBadPixels());
-  if (!testloop.ProcessD(pedloop.GetPedestalCam(),calloop.GetCalibrationCam(),calloop.GetQECam()))
-    return;
-
+  testloop.ProcessD(pedloop.GetPedestalCam(),calloop.GetCalibrationCam(),calloop.GetQECam());
+  
 }
 
Index: /trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 3924)
+++ /trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 3925)
@@ -113,4 +113,5 @@
 #include "MHCalibrationRelTimeCam.h"
 #include "MCalibrationRelTimeCam.h"
+#include "MCalibrationRelTimeCalc.h"
 
 #include "MReadMarsFile.h"
@@ -775,4 +776,5 @@
 //   13) MCalibrationChargeCalc
 //   14) MFillH("MHCalibrationRelTimeCam",     "MArrivalTimeCam") (only if flag fRelTimes is chosen)
+//   15) MCalibrationRelTimeCalc
 // - Execute MEvtLoop
 // - DisplayResult()
@@ -841,4 +843,5 @@
   MExtractTimeSpline       timespline;
   MCalibrationChargeCalc   calcalc;
+  MCalibrationRelTimeCalc  timecalc;
   
   // 
@@ -902,5 +905,9 @@
 
   if (fRelTimes)
-    tlist.AddToList(&filltme);
+    {
+      tlist.AddToList(&filltme);
+      tlist.AddToList(&timecalc);
+    }
+  
 
   // Create and setup the eventloop
Index: /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.cc	(revision 3924)
+++ /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.cc	(revision 3925)
@@ -16,6 +16,6 @@
    !
    !
-   !   Author(s): Abelardo Moralejo, 4/2004 <mailto:moralejo@pd.infn.it>
-   !              Markus Gaug      , 4/2004 <mailto:markus@ifae.es>
+   !   Author(s): Abelardo Moralejo,04/2004 <mailto:moralejo@pd.infn.it>
+   !              Markus Gaug      ,04/2004 <mailto:markus@ifae.es>
    !   Copyright: MAGIC Software Development, 2000-2004
    !
@@ -75,11 +75,12 @@
 using namespace std;
 
-const Byte_t MExtractFixedWindowPeakSearch::fgHiGainWindowSize     = 6;
-const Byte_t MExtractFixedWindowPeakSearch::fgLoGainWindowSize     = 6;
-const Byte_t MExtractFixedWindowPeakSearch::fgPeakSearchWindowSize = 4;
 const Byte_t MExtractFixedWindowPeakSearch::fgHiGainFirst          = 0;
 const Byte_t MExtractFixedWindowPeakSearch::fgHiGainLast           = 14;
 const Byte_t MExtractFixedWindowPeakSearch::fgLoGainFirst          = 3;
 const Byte_t MExtractFixedWindowPeakSearch::fgLoGainLast           = 14;
+const Byte_t MExtractFixedWindowPeakSearch::fgHiGainWindowSize     = 6;
+const Byte_t MExtractFixedWindowPeakSearch::fgLoGainWindowSize     = 6;
+const Byte_t MExtractFixedWindowPeakSearch::fgPeakSearchWindowSize = 4;
+const Byte_t MExtractFixedWindowPeakSearch::fgOffsetFromPeak       = 2;
 // --------------------------------------------------------------------------
 //
@@ -92,4 +93,5 @@
 //
 // Calls: 
+// - SetOffsetFromPeak()
 // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
 //
@@ -103,4 +105,5 @@
   fTitle = title ? title : "Task to extract the signal from the FADC slices";
 
+  SetOffsetFromPeak();
   SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
 }
@@ -171,4 +174,5 @@
     }
   
+  
   if (fWindowSizeLoGain > availlorange)
     {
@@ -200,5 +204,4 @@
     }
 
-
   fNumHiGainSamples = (Float_t)fWindowSizeHiGain;
   fNumLoGainSamples = (Float_t)fWindowSizeLoGain;
@@ -271,18 +274,31 @@
 // - If *ptr is greater than fSaturationLimit, raise sat by 1
 // 
-void MExtractFixedWindowPeakSearch::FindSignalHiGain(Byte_t *ptr, Int_t &sum, Byte_t &sat) const
-{
+void MExtractFixedWindowPeakSearch::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Int_t &sum, Byte_t &sat) const
+{
+
+  Byte_t *end = ptr + fWindowSizeHiGain-fHiLoLast;
+
   //
   // Calculate the sum of the "window" slices starting in ptr
   //
-  sum = 0;
-  sat = 0;
-  Byte_t *p = ptr;
-
-  while (p<ptr+fWindowSizeHiGain)
-    {
+  while (ptr<end)
+    {
+      sum += *ptr;
+      if (*ptr++ >= fSaturationLimit)
+	sat++;
+    }
+
+  //
+  // If part of the "low-Gain" slices are used, 
+  // repeat steps one and two for the logain part until fHiLoLast
+  //
+  Byte_t *p = logain;
+  end = logain + fHiLoLast;
+  while (p<end)
+    {
+  
       sum += *p;
       if (*p++ >= fSaturationLimit)
-	sat++;
+        sat++;
     }
 
@@ -323,5 +339,5 @@
 // "startslice" will mark the slice at which the highest sum begins for that pixel.
 // Then define the beginning of the integration window for ALL pixels as the slice
-// before that: startslice-1 (this is somehow arbitrary), unless of course startslice=0,
+// before that: startslice-fOffsetFraomPeak, unless of course startslice-fOffsetFromPeak<=0,
 // in which case we start at 0. We will also check that the integration window does not 
 // go beyond the FADC limits.
@@ -348,6 +364,6 @@
 	{
 	  maxsumhi = sumhi;
-	  if (startslice > 0)
-	    hiGainFirst = fHiGainFirst + startslice - 1;
+	  if ((startslice-fOffsetFromPeak) > 0)
+            hiGainFirst = fHiGainFirst + startslice - fOffsetFromPeak;
 	  else
 	    hiGainFirst = fHiGainFirst;
@@ -360,5 +376,6 @@
   // Make sure we will not integrate beyond the hi gain limit:
   if (hiGainFirst+fWindowSizeHiGain > pixel.GetNumHiGainSamples())
-    hiGainFirst = pixel.GetNumHiGainSamples()-fWindowSizeHiGain;
+    fHiLoLast = hiGainFirst+fWindowSizeHiGain - pixel.GetNumHiGainSamples();
+  //    hiGainFirst = pixel.GetNumHiGainSamples()-fWindowSizeHiGain;
 
   // Make sure we will not integrate beyond the lo gain limit:
@@ -375,8 +392,8 @@
       // Find signal in hi- and lo-gain
       //
-      Int_t sumhi;
-      Byte_t sathi;
-
-      FindSignalHiGain(pixel.GetHiGainSamples()+hiGainFirst, sumhi, sathi);
+      Int_t sumhi=0;
+      Byte_t sathi=0;
+
+      FindSignalHiGain(pixel.GetHiGainSamples()+hiGainFirst, pixel.GetLoGainSamples(), sumhi, sathi);
 
       Int_t sumlo=0;
Index: /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.h
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.h	(revision 3924)
+++ /trunk/MagicSoft/Mars/msignal/MExtractFixedWindowPeakSearch.h	(revision 3925)
@@ -14,14 +14,15 @@
   static const Byte_t fgLoGainFirst;
   static const Byte_t fgLoGainLast;
-  static const Byte_t fgHiGainWindowSize;     // The extraction window Hi-Gain
-  static const Byte_t fgLoGainWindowSize;     // The extraction window Lo-Gain
-  static const Byte_t fgPeakSearchWindowSize; // The window in which the global peak is searched for
-
+  static const Byte_t fgHiGainWindowSize;     // Default for fWindowSizeHiGain (now set to: 6)
+  static const Byte_t fgLoGainWindowSize;     // Default for fWindowSizeLoGain (now set to: 6)
+  static const Byte_t fgPeakSearchWindowSize; // Default for fPeakSearchWindowSize (now set to: 4)
+  static const Byte_t fgOffsetFromPeak;       // Default for fOffsetFromPeak   (now set to: 2)
+  
   Byte_t  fWindowSizeHiGain;     // Number of Hi Gain slices in window
   Byte_t  fWindowSizeLoGain;     // Number of Lo Gain slices in window
   Byte_t  fPeakSearchWindowSize; // Size of FADC window in the search for the highest peak of all pixels.
+  Byte_t  fOffsetFromPeak;       // Number of slices to start extraction from global peak
 
-
-  void   FindSignalHiGain(Byte_t *ptr, Int_t &sum, Byte_t &sat) const;
+  void   FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Int_t &sum, Byte_t &sat) const;
   void   FindSignalLoGain(Byte_t *ptr, Int_t &sum, Byte_t &sat) const;  
 
@@ -29,5 +30,5 @@
 
   Int_t  Process();
-
+  
 public:
 
@@ -37,5 +38,6 @@
     void SetWindows(Byte_t windowh=fgHiGainWindowSize, Byte_t windowl=fgLoGainWindowSize, 
 		    Byte_t peaksearchwindow=fgPeakSearchWindowSize);
-
+    void SetOffsetFromPeak(Byte_t offset=fgOffsetFromPeak)    {  fOffsetFromPeak = offset; }
+    
     ClassDef(MExtractFixedWindowPeakSearch, 0) // Signal Extractor for fixed size trigger-corrected extraction window 
 };
Index: /trunk/MagicSoft/Mars/msignal/MExtractPINDiode.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractPINDiode.cc	(revision 3924)
+++ /trunk/MagicSoft/Mars/msignal/MExtractPINDiode.cc	(revision 3925)
@@ -129,4 +129,11 @@
   MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
 
+
+  fNumHiGainSamples = (Float_t)(fHiGainLast-fHiGainFirst+1);
+  fNumLoGainSamples = (Float_t)(fLoGainLast-fLoGainFirst+1);  
+
+  fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples);
+  fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);  
+  
   fNumSamples = fHiGainLast-fHiGainFirst+1+fLoGainLast-fLoGainFirst+1;
   fSqrtSamples = TMath::Sqrt((Float_t)fNumSamples);
Index: /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.cc	(revision 3924)
+++ /trunk/MagicSoft/Mars/msignal/MExtractSlidingWindow.cc	(revision 3925)
@@ -194,5 +194,5 @@
 // - Check if the sum has become bigger and store it in case yes.
 // 
-void MExtractSlidingWindow::FindSignalHiGain(Byte_t *ptr, Int_t &max, Byte_t &sat) const
+void MExtractSlidingWindow::FindSignalHiGain(Byte_t *ptr, Byte_t *logain, Int_t &max, Byte_t &sat) const
 {
     const Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1;
@@ -205,5 +205,6 @@
     sat = 0;
     Byte_t *p = ptr;
-    while (p<ptr+fWindowSizeHiGain)
+    
+    while (p<ptr+fWindowSizeHiGain-fHiLoLast)
     {
         sum += *p;
@@ -218,4 +219,17 @@
         if (*p++ >= fSaturationLimit)
             sat++;
+
+    //
+    // If part of the "low-Gain" slices are used, 
+    // repeat steps one and two for the logain part until fHiLoLast
+    //
+    Byte_t *l = logain;
+    while (l<logain+fHiLoLast)
+      {
+        sum += *l;
+        if (*l++ >= fSaturationLimit)
+            sat++;
+      }
+
 
     //
@@ -225,10 +239,18 @@
     //
     max=sum;
-    for (p=ptr; p+fWindowSizeHiGain<end; p++)
-    {
-        sum += *(p+fWindowSizeHiGain) - *p;
+    for (p=ptr; p+fWindowSizeHiGain-fHiLoLast<end; p++)
+    {
+        sum += *(p+fWindowSizeHiGain-fHiLoLast) - *p;
         if (sum>max)
             max = sum;
     }
+
+    for (l=logain; l<logain+fHiLoLast; l++)
+    {
+        sum += *l - *p++;
+        if (sum>max)
+            max = sum;
+    }
+
 }
 
