diff --git a/Framework/Algorithms/src/Rebin2D.cpp b/Framework/Algorithms/src/Rebin2D.cpp index 0a90a5c2db3107ee2fda0e1657f121a61ce74815..61de05ec1e77fdadf41bcabe5aa8e8e82cef975e 100644 --- a/Framework/Algorithms/src/Rebin2D.cpp +++ b/Framework/Algorithms/src/Rebin2D.cpp @@ -84,7 +84,7 @@ void Rebin2D::exec() { "If it is a spectra axis try running ConvertSpectrumAxis first."); } - const auto &oldXEdges = inputWS->x(0); + const auto &oldXEdges = inputWS->binEdges(0); const size_t numXBins = inputWS->blocksize(); const size_t numYBins = inputWS->getNumberHistograms(); // This will convert plain NumericAxis to bin edges while diff --git a/Framework/Algorithms/test/Rebin2DTest.h b/Framework/Algorithms/test/Rebin2DTest.h index 37ce0b6b3feb2f0670707f3eaad93756eef964b5..3d458558e089b177118982efacd355e7f27a64e7 100644 --- a/Framework/Algorithms/test/Rebin2DTest.h +++ b/Framework/Algorithms/test/Rebin2DTest.h @@ -9,10 +9,11 @@ #include "MantidAPI/BinEdgeAxis.h" #include "MantidAlgorithms/Rebin2D.h" #include "MantidDataObjects/RebinnedOutput.h" +#include "MantidHistogramData/Histogram.h" +#include "MantidKernel/Timer.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h" #include <cxxtest/TestSuite.h> - -#include "MantidKernel/Timer.h" +//#include "../../TestHelpers/src/WorkspaceCreationHelper.cpp" using Mantid::Algorithms::Rebin2D; using namespace Mantid::API; @@ -26,7 +27,8 @@ namespace { /// Return the input workspace. All Y values are 2 and E values sqrt(2) MatrixWorkspace_sptr makeInputWS(const bool distribution, const bool perf_test = false, - const bool small_bins = false) { + const bool small_bins = false, + const bool isHisto = true) { size_t nhist(0), nbins(0); double x0(0.0), deltax(0.0); @@ -46,20 +48,31 @@ MatrixWorkspace_sptr makeInputWS(const bool distribution, } } - MatrixWorkspace_sptr ws = WorkspaceCreationHelper::create2DWorkspaceBinned( - int(nhist), int(nbins), x0, deltax); - - // We need something other than a spectrum axis, call this one theta - auto thetaAxis = std::make_unique<BinEdgeAxis>(nhist + 1); - for (size_t i = 0; i < nhist + 1; ++i) { - thetaAxis->setValue(i, -0.5 + static_cast<double>(i)); - } - ws->replaceAxis(1, std::move(thetaAxis)); + MatrixWorkspace_sptr ws; - if (distribution) { - Mantid::API::WorkspaceHelpers::makeDistribution(ws); + if (isHisto) { + ws = WorkspaceCreationHelper::create2DWorkspaceBinned( + int(nhist), int(nbins), x0, deltax); + // We need something other than a spectrum axis, call this one theta + auto thetaAxis = std::make_unique<BinEdgeAxis>(nhist + 1); + for (size_t i = 0; i < nhist + 1; ++i) { + thetaAxis->setValue(i, -0.5 + static_cast<double>(i)); + } + ws->replaceAxis(1, std::move(thetaAxis)); + if (distribution) { + Mantid::API::WorkspaceHelpers::makeDistribution(ws); + } + } else { + // create histograms with points (which cannot be a distirbution) + ws = WorkspaceCreationHelper::create2DWorkspacePoints( + int(nhist), int(nbins), x0 + 0.5, deltax); + // convert axis from spectrum to theta + auto thetaAxis = std::make_unique<NumericAxis>(nhist); + for (size_t i = 0; i < nhist; ++i) { + thetaAxis->setValue(i, static_cast<double>(i)); + } + ws->replaceAxis(1, std::move(thetaAxis)); } - return ws; } @@ -185,6 +198,32 @@ public: } } + void test_BothAxes_PointData() { + MatrixWorkspace_sptr inputWS = + makeInputWS(false, false, false, false); // 10 spectra, 10 points + MatrixWorkspace_sptr outputWS = + runAlgorithm(inputWS, "5.,1.8,15", "-0.5,2.5,9.5"); + TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 4); + TS_ASSERT_EQUALS(outputWS->blocksize(), 6); + + double errors[6] = {3., 3., 3., 3., 3., 2.236067977}; + const double epsilon(1e-08); + for (size_t i = 0; i < outputWS->getNumberHistograms(); ++i) { + const auto &y = outputWS->y(i); + const auto &e = outputWS->e(i); + const size_t numBins = y.size(); + for (size_t j = 0; j < numBins; ++j) { + if (j < 5) { + TS_ASSERT_DELTA(y[j], 9, epsilon); + } else { + // Last bin + TS_ASSERT_DELTA(y[j], 5, epsilon); + } + TS_ASSERT_DELTA(e[j], errors[j], epsilon); + } + } + } + void test_Zero_Area_Bins_NoFractionalBinning() { MatrixWorkspace_sptr inputWS = makeInputWS(false); const auto nhist = inputWS->getNumberHistograms(); diff --git a/Framework/DataObjects/src/FractionalRebinning.cpp b/Framework/DataObjects/src/FractionalRebinning.cpp index 2405f3065c2565da0936f750b5a815deefbb13d6..f2b3a3057f17e6c3d99d866a7de22f40250d598c 100644 --- a/Framework/DataObjects/src/FractionalRebinning.cpp +++ b/Framework/DataObjects/src/FractionalRebinning.cpp @@ -608,7 +608,7 @@ void rebinToFractionalOutput(const Quadrilateral &inputQ, RebinnedOutput &outputWS, const std::vector<double> &verticalAxis, const RebinnedOutput_const_sptr &inputRB) { - const auto &inX = inputWS->x(i); + const auto &inX = inputWS->binEdges(i); const auto &inY = inputWS->y(i); const auto &inE = inputWS->e(i); double signal = inY[j]; diff --git a/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h b/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h index c29db328bbca07fd7c836c162ef3dd269817bdde..a8abc58fef0ec1027c9db75b8a9ce2fdbdbe6d21 100644 --- a/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h +++ b/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h @@ -170,6 +170,13 @@ Mantid::DataObjects::Workspace2D_sptr create2DWorkspaceBinned(size_t nhist, size_t numVals, double x0 = 0.0, double deltax = 1.0); +/** Create a 2D workspace with this many point-histograms and bins. + * Filled with Y = 2.0 and E = M_SQRT2 + */ +Mantid::DataObjects::Workspace2D_sptr +create2DWorkspacePoints(size_t nhist, size_t numVals, double x0 = 0.0, + double deltax = 1.0); + /** Create a 2D workspace with this many histograms and bins. The bins are * assumed to be non-uniform and given by the input array * Filled with Y = 2.0 and E = sqrt(2.0)w diff --git a/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp b/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp index 6e7439322ede08228bedeaffdc2aa6b14c414268..9e491ac2393c303fd0fa23b3f602a466bcb1b3e4 100644 --- a/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp +++ b/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp @@ -322,6 +322,17 @@ Workspace2D_sptr create2DWorkspaceBinned(size_t nhist, size_t numVals, return create<Workspace2D>(nhist, Histogram(x, y, e)); } +/** Create a 2D workspace with this many point-histograms and bins. + * Filled with Y = 2.0 and E = M_SQRT2w + */ +Workspace2D_sptr create2DWorkspacePoints(size_t nhist, size_t numVals, + double x0, double deltax) { + Points x(numVals, LinearGenerator(x0, deltax)); + Counts y(numVals, 2); + CountStandardDeviations e(numVals, M_SQRT2); + return create<Workspace2D>(nhist, Histogram(x, y, e)); +} + /** Create a 2D workspace with this many histograms and bins. The bins are * assumed to be non-uniform and given by the input array * Filled with Y = 2.0 and E = M_SQRT2w