Index: /trunk/Mars/mcore/DrsCalib.h
===================================================================
--- /trunk/Mars/mcore/DrsCalib.h	(revision 16842)
+++ /trunk/Mars/mcore/DrsCalib.h	(revision 16843)
@@ -807,15 +807,20 @@
             return -1;
 
-        const int beg = roi>10 ? 10 : 0;
+        // Skip first 10 samples
+        const uint beg = roi>10 ? 10 : 0;
+        const uint end = roi-beg>5 ? roi-5 : roi;
+        const uint len = end-beg;
 
         double max = 0;
-        for (int i=0; i<1440; i++)
+        double patch = 0;
+        for (uint i=0; i<1440; i++)
         {
             const float *vec = data+i*roi;
 
-            int    pos  = beg;
+            uint   pos  = beg;
             double sum  = vec[beg];
             double sum2 = vec[beg]*vec[beg];
-            for (int j=beg+1; j<roi; j++)
+
+            for (uint j=beg+1; j<end; j++)
             {
                 sum  += vec[j];
@@ -825,9 +830,20 @@
                     pos = j;
             }
-            sum  /= roi-beg;
-            sum2 /= roi-beg;
-
-            if (vec[pos]>0)
-                max = vec[pos];
+            sum  /= len;
+            sum2 /= len;
+
+            if (i%9!=8 && vec[pos]>0)
+                patch += vec[pos];
+
+            if (i%9==8)
+            {
+                patch /= 8;
+                if (patch > max)
+                    max = patch;
+                patch = 0;
+            }
+
+            //if (i%9!=8 && vec[pos]>max)
+            //    max = vec[pos];
 
             *(ptr+0*1440+i) = sum;
