Fix histogram resampling output bin positions
[alexxy/gromacs.git] / src / gromacs / analysisdata / modules / histogram.cpp
index 24f67024a74217c8391166d56b187ce72c51080b..d9e3501f41cd0feb5f790575b24bc8420125739f 100644 (file)
@@ -286,7 +286,7 @@ AbstractAverageHistogram::resampleDoubleBinWidth(bool bIntegerBins) const
 
     AverageHistogramPointer dest(
             new StaticAverageHistogram(
-                    histogramFromBins(xstart(), nbins, 2*xstep())
+                    histogramFromBins(settings().firstEdge(), nbins, 2*xstep())
                         .integerBins(bIntegerBins)));
     dest->setColumnCount(columnCount());
     dest->allocateValues();
@@ -333,6 +333,7 @@ AbstractAverageHistogram::clone() const
 {
     AverageHistogramPointer dest(new StaticAverageHistogram());
     copyContents(this, dest.get());
+    dest->settings_ = settings_;
     return dest;
 }
 
@@ -354,6 +355,24 @@ AbstractAverageHistogram::normalizeProbability()
     }
 }
 
+void
+AbstractAverageHistogram::makeCumulative()
+{
+    for (int c = 0; c < columnCount(); ++c)
+    {
+        double sum = 0;
+        for (int i = 0; i < rowCount(); ++i)
+        {
+            sum += value(i, c).value();
+            // Clear the error, as we don't cumulate that.
+            value(i, c).clear();
+            value(i, c).setValue(sum);
+        }
+    }
+    setXAxis(settings().firstEdge() + settings().binWidth(),
+             settings().binWidth());
+}
+
 
 void
 AbstractAverageHistogram::scaleSingle(int index, real factor)