Index: /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.cc
===================================================================
--- /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.cc	(revision 3881)
+++ /trunk/MagicSoft/Mars/msignal/MExtractFixedWindow.cc	(revision 3882)
@@ -36,4 +36,6 @@
 #include <fstream>
 
+#include "MLog.h"
+#include "MLogManip.h"
 
 ClassImp(MExtractFixedWindow);
@@ -49,4 +51,7 @@
 // Default constructor. 
 //
+// Calls: 
+// - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast)
+//
 MExtractFixedWindow::MExtractFixedWindow(const char *name, const char *title)
 {
@@ -57,12 +62,87 @@
   SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
 
-  fNumHiGainSamples = (Float_t)(fHiGainLast-fHiGainFirst) + 1.;
-  fNumLoGainSamples = (Float_t)(fLoGainLast-fLoGainFirst) + 1.;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// SetRange: 
+//
+// Checks: 
+// - if the window defined by (fHiGainLast-fHiGainFirst-1) are odd, subtract one
+// - if the window defined by (fLoGainLast-fLoGainFirst-1) are odd, subtract one
+// - if the Hi Gain window is smaller than 2, set fHiGainLast to fHiGainFirst+1
+// - if the Lo Gain window is smaller than 2, set fLoGainLast to fLoGainFirst+1
+// 
+// Calls:
+// - MExtractor::SetRange(hifirst,hilast,lofirst,lolast);
+// 
+// Sets:
+// - fNumHiGainSamples to: (Float_t)(fHiGainLast-fHiGainFirst+1)
+// - fNumLoGainSamples to: (Float_t)(fLoGainLast-fLoGainFirst+1)
+// - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples)
+// - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples)  
+//  
+void MExtractFixedWindow::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast)
+{
+
+  const Byte_t windowhi = hilast-hifirst+1;
+  const Byte_t windowlo = lolast-lofirst+1;
+  
+  const Byte_t whieven = windowhi & ~1;
+  const Byte_t wloeven = windowlo & ~1;
+
+  if (whieven != windowhi)
+    {
+      *fLog << warn << GetDescriptor() 
+            << Form("%s%2i%s%2i",": Hi Gain window size has to be even, set last slice from "
+                    ,(int)hilast," to ",(int)(hilast-1)) << endl;
+      hilast -= 1;
+    }
+  
+  if (wloeven != windowlo)
+    {
+      *fLog << warn << GetDescriptor() 
+            << Form("%s%2i%s%2i",": Lo Gain window size has to be even, set last slice from "
+                    ,(int)lolast," to ",(int)(lolast-1)) << endl;
+      lolast -= 1;
+    }
+  
+  if (whieven<2) 
+    {
+      *fLog << warn << GetDescriptor() 
+            << Form("%s%2i%s%2i",": Hi Gain window is smaller than 2 FADC sampes, set last slice from" 
+                    ,(int)hilast," to ",(int)(hifirst+1)) << endl;
+      hilast = hifirst+1;
+    }
+  
+  if (wloeven<2) 
+    {
+      *fLog << warn << GetDescriptor() 
+            << Form("%s%2i%s%2i",": Lo Gain window is smaller than 2 FADC sampes, set last slice from" 
+                    ,(int)lolast," to ",(int)(lofirst+1)) << endl;
+      lolast = lofirst+1;        
+    }
+
+
+  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);
-}
-
-
+  fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);  
+  
+}
+
+
+// --------------------------------------------------------------------------
+//
+// FindSignalHiGain:
+//
+// - Loop from ptr to (ptr+fHiGainLast-fHiGainFirst)
+// - Sum up contents of *ptr
+// - If *ptr is greater than fSaturationLimit, raise sat by 1
+// 
 void MExtractFixedWindow::FindSignalHiGain(Byte_t *ptr, Int_t &sum, Byte_t &sat) const
 {
@@ -82,4 +162,12 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// FindSignalLoGain:
+//
+// - Loop from ptr to (ptr+fLoGainLast-fLoGainFirst)
+// - Sum up contents of *ptr
+// - If *ptr is greater than fSaturationLimit, raise sat by 1
+// 
 void MExtractFixedWindow::FindSignalLoGain(Byte_t *ptr, Int_t &sum, Byte_t &sat) const
 {
