diff --git a/Framework/Algorithms/inc/MantidAlgorithms/FindPeakBackground.h b/Framework/Algorithms/inc/MantidAlgorithms/FindPeakBackground.h index 223b3dfc24bbddc5251e3a3f19404f3fd6b7de9d..08ba5769e14e780d249275bff6075e95cdebcf97 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/FindPeakBackground.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/FindPeakBackground.h @@ -5,6 +5,12 @@ #include "MantidKernel/cow_ptr.h" namespace Mantid { + +namespace HistogramData { +class HistogramX; +class HistogramY; +} + namespace Algorithms { /** FindPeakBackground : Calculate Zscore for a Matrix Workspace @@ -53,7 +59,8 @@ private: /// Implement abstract Algorithm methods void exec() override; double moment4(MantidVec &X, size_t n, double mean); - void estimateBackground(const MantidVec &X, const MantidVec &Y, + void estimateBackground(const HistogramData::HistogramX &X, + const HistogramData::HistogramY &Y, const size_t i_min, const size_t i_max, const size_t p_min, const size_t p_max, const bool hasPeak, double &out_bg0, double &out_bg1, diff --git a/Framework/Algorithms/src/FindPeakBackground.cpp b/Framework/Algorithms/src/FindPeakBackground.cpp index e73aef39c2364960a35b084e675e29d018f9667d..5c6a28cadb9923b189b94ecc02f16ae641049f24 100644 --- a/Framework/Algorithms/src/FindPeakBackground.cpp +++ b/Framework/Algorithms/src/FindPeakBackground.cpp @@ -1,14 +1,14 @@ #include "MantidAlgorithms/FindPeakBackground.h" -#include "MantidAlgorithms/FindPeaks.h" -#include "MantidAPI/WorkspaceProperty.h" #include "MantidAPI/MatrixWorkspace.h" +#include "MantidAPI/TableRow.h" #include "MantidAPI/WorkspaceFactory.h" -#include "MantidKernel/ArrayProperty.h" -#include "MantidKernel/Statistics.h" +#include "MantidAPI/WorkspaceProperty.h" +#include "MantidAlgorithms/FindPeaks.h" +#include "MantidDataObjects/TableWorkspace.h" #include "MantidDataObjects/Workspace2D.h" +#include "MantidKernel/ArrayProperty.h" #include "MantidKernel/ListValidator.h" -#include "MantidDataObjects/TableWorkspace.h" -#include "MantidAPI/TableRow.h" +#include "MantidKernel/Statistics.h" #include <sstream> @@ -17,6 +17,8 @@ using namespace Mantid::API; using namespace Mantid::Kernel; using namespace Mantid::DataObjects; using namespace std; +using Mantid::HistogramData::HistogramX; +using Mantid::HistogramData::HistogramY; namespace Mantid { namespace Algorithms { @@ -90,16 +92,16 @@ void FindPeakBackground::exec() { } // Generate output - const MantidVec &inpX = inpWS->readX(inpwsindex); - size_t sizex = inpWS->readX(inpwsindex).size(); - size_t sizey = inpWS->readY(inpwsindex).size(); + auto &inpX = inpWS->x(inpwsindex); + size_t sizex = inpWS->x(inpwsindex).size(); + size_t sizey = inpWS->x(inpwsindex).size(); size_t n = sizey; size_t l0 = 0; if (m_vecFitWindows.size() > 1) { Mantid::Algorithms::FindPeaks fp; - l0 = fp.getVectorIndex(inpX, m_vecFitWindows[0]); - n = fp.getVectorIndex(inpX, m_vecFitWindows[1]); + l0 = fp.getIndex(inpX, m_vecFitWindows[0]); + n = fp.getIndex(inpX, m_vecFitWindows[1]); if (n < sizey) n++; } @@ -122,7 +124,7 @@ void FindPeakBackground::exec() { // Find background - const MantidVec &inpY = inpWS->readY(inpwsindex); + auto &inpY = inpWS->y(inpwsindex); double Ymean, Yvariance, Ysigma; MantidVec maskedY; @@ -244,7 +246,7 @@ void FindPeakBackground::exec() { * @param out_bg2 :: a2 = 0 */ void FindPeakBackground::estimateBackground( - const MantidVec &X, const MantidVec &Y, const size_t i_min, + const HistogramX &X, const HistogramY &Y, const size_t i_min, const size_t i_max, const size_t p_min, const size_t p_max, const bool hasPeak, double &out_bg0, double &out_bg1, double &out_bg2) { // Validate input diff --git a/Framework/Algorithms/test/FindPeakBackgroundTest.h b/Framework/Algorithms/test/FindPeakBackgroundTest.h index 47f45e6d5ae2035a67bdec6becae945ca4a2bb35..6a384cbedbf42e18d3789073e74cd66dcc5df0cc 100644 --- a/Framework/Algorithms/test/FindPeakBackgroundTest.h +++ b/Framework/Algorithms/test/FindPeakBackgroundTest.h @@ -9,6 +9,7 @@ #include "MantidAPI/ITableWorkspace.h" #include "MantidDataObjects/Workspace2D.h" +#include <numeric> #include <cmath> using namespace Mantid; @@ -70,21 +71,16 @@ public: const size_t size = 20; - std::array<double, size> data = {{1, 2, 1, 1, 9, 11, 13, 20, 24, 32, 28, 48, - 42, 77, 67, 33, 27, 20, 9, 2}}; + std::array<double, size> data = {{1, 2, 1, 1, 9, 11, 13, 20, 24, 32, + 28, 48, 42, 77, 67, 33, 27, 20, 9, 2}}; MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>( WorkspaceFactory::Instance().create("Workspace2D", 1, size, size)); - MantidVec &vecX = ws->dataX(0); - MantidVec &vecY = ws->dataY(0); - MantidVec &vecE = ws->dataE(0); - - for (size_t i = 0; i < data.size(); ++i) { - vecX[i] = static_cast<double>(i); - vecY[i] = data[i]; - vecE[i] = sqrt(data[i]); - } + ws->mutableY(0).assign(data.begin(), data.end()); + std::iota(ws->mutableX(0).begin(), ws->mutableX(0).end(), 0); + std::transform(ws->y(0).cbegin(), ws->y(0).cend(), ws->mutableE(0).begin(), + [](const double &y) { return sqrt(y); }); return ws; } @@ -184,52 +180,23 @@ public: /** Generate a workspace with 2 spectra for test */ MatrixWorkspace_sptr generate2SpectraTestWorkspace() { - vector<double> data; - data.push_back(1); - data.push_back(2); - data.push_back(1); - data.push_back(1); - data.push_back(9); - data.push_back(11); - data.push_back(13); - data.push_back(20); - data.push_back(24); - data.push_back(32); - data.push_back(28); - data.push_back(48); - data.push_back(42); - data.push_back(77); - data.push_back(67); - data.push_back(33); - data.push_back(27); - data.push_back(20); - data.push_back(9); - data.push_back(2); + vector<double> data{1, 2, 1, 1, 9, 11, 13, 20, 24, 32, + 28, 48, 42, 77, 67, 33, 27, 20, 9, 2}; MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>( WorkspaceFactory::Instance().create("Workspace2D", 2, data.size(), data.size())); // Workspace index = 0 - MantidVec &vecX = ws->dataX(0); - MantidVec &vecY = ws->dataY(0); - MantidVec &vecE = ws->dataE(0); - for (size_t i = 0; i < data.size(); ++i) { - vecX[i] = static_cast<double>(i); - vecY[i] = 0.0; - vecE[i] = 1.0; - } + ws->mutableY(0).assign(data.size(), 0.0); + ws->mutableE(0).assign(data.size(), 1.0); + std::iota(ws->mutableX(0).begin(), ws->mutableX(0).end(), 0); // Workspace index = 1 - MantidVec &vecX1 = ws->dataX(1); - MantidVec &vecY1 = ws->dataY(1); - MantidVec &vecE1 = ws->dataE(1); - for (size_t i = 0; i < data.size(); ++i) { - vecX1[i] = static_cast<double>(i); - vecY1[i] = data[i]; - vecE1[i] = sqrt(data[i]); - } - + ws->mutableY(1).assign(data.cbegin(), data.cend()); + std::iota(ws->mutableX(1).begin(), ws->mutableX(1).end(), 0); + std::transform(ws->y(1).cbegin(), ws->y(1).cend(), ws->mutableE(1).begin(), + [](const double &y) { return sqrt(y); }); return ws; } };