Index: trunk/FACT++/src/ratescan.cc
===================================================================
--- trunk/FACT++/src/ratescan.cc	(revision 13741)
+++ trunk/FACT++/src/ratescan.cc	(revision 13742)
@@ -68,6 +68,6 @@
     DimDescribedService fDimProc;
 
-    int fSeconds;
-    int fSecondsMax;
+    int fCounter;
+    int fCounterMax;
 
     int fThreshold;
@@ -75,4 +75,5 @@
     int fThresholdMax;
     int fThresholdStep;
+    int fThresholdStepDyn;
 
     double fRate;
@@ -159,8 +160,8 @@
             const FTM::DimTriggerRates &sdata = *static_cast<FTM::DimTriggerRates*>(curr->getData());
 
-            if (++fSeconds<0)
-                return;
-
-            if (fSeconds==0)
+            if (++fCounter<0)
+                return;
+
+            if (fCounter==0)
             {
                 fRate = 0;
@@ -197,5 +198,5 @@
             reference *= sdata.fElapsedTime;
 
-            if ((reference==0 || sqrt(reference)>fResolution*reference) && fSeconds<fSecondsMax)
+            if ((reference==0 || sqrt(reference)>fResolution*reference) && fCounter<fCounterMax)
             {
                 ostringstream out;
@@ -208,5 +209,5 @@
             }
 
-            const double   time = sdata.fElapsedTime*fSeconds;
+            const double   time = sdata.fElapsedTime*fCounter;
             const uint32_t th   = fThreshold;
 
@@ -216,9 +217,9 @@
             data[3] = time;         // total elapsed time
             data[4] = fOnTime/time; // relative on time
-            data[5] = fRate/fSeconds;
+            data[5] = fRate/fCounter;
             for (int i=0; i<40; i++)
-                data[i+6] = fRateBoard[i]/fSeconds;
+                data[i+6] = fRateBoard[i]/fCounter;
             for (int i=0; i<160; i++)
-                data[i+46] = fRatePatch[i]/fSeconds;
+                data[i+46] = fRatePatch[i]/fCounter;
 
             ostringstream sout1, sout2, sout3;
@@ -240,5 +241,5 @@
             fThreshold += fThresholdStep;
 
-            if (fSeconds>=fSecondsMax)
+            if (fCounter>=fCounterMax)
             {
                 Message("Rate scan stopped due to timeout.");
@@ -254,6 +255,15 @@
             }
 
-            //fSeconds = -2;  // FIXME: In principle one missed report is enough
-            fSeconds = -1; 
+            // Does this need to be shifted upwards?
+            if (fCounter>1 && fThresholdStepDyn>0)
+            {
+                //const double scale = fCounter/reference/fResolution/fResolution;
+                //const double step  = floor(scale*fThresholdStepDyn);
+
+                fThresholdStep = fCounter*fThresholStepDyn;
+            }
+
+            //fCounter = -2;  // FIXME: In principle one missed report is enough
+            fCounter = -1; 
 
             const int32_t cmd[2] = { -1, fThreshold };
@@ -293,7 +303,11 @@
         fCommand = "FTM_CONTROL/"+command;
 
+        const int32_t step = evt.Get<int32_t>(8);
+
         fThresholdMin  = evt.Get<uint32_t>();
         fThresholdMax  = evt.Get<uint32_t>(4);
-        fThresholdStep = evt.Get<uint32_t>(8);
+        fThresholdStep = abs(step);
+
+        fThresholdStepDyn = step<0 ? -step : 0;
 
         UpdateProc();
@@ -325,5 +339,5 @@
 
         fThreshold = fThresholdMin;
-        fSeconds = -2;
+        fCounter = -2;
 
         ostringstream msg;
@@ -527,5 +541,5 @@
     int EvalOptions(Configuration &conf)
     {
-        fSecondsMax = conf.Get<uint16_t>("max-wait");
+        fCounterMax = conf.Get<uint16_t>("max-wait");
         fResolution = conf.Get<double>("resolution");
 
