diff --git a/Framework/Algorithms/inc/MantidAlgorithms/FindPeakBackground.h b/Framework/Algorithms/inc/MantidAlgorithms/FindPeakBackground.h index 6f382560479139a4430a16651a297b1dae98763a..d00abf1a413b285fb346ba20cbd0eca089904440 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/FindPeakBackground.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/FindPeakBackground.h @@ -75,7 +75,7 @@ private: void createOutputWorkspaces(); /// set histogram data to find background - void setHistogram(const HistogramData::Histogram &histogram); + // void setHistogram(const HistogramData::Histogram &histogram); /// set sigma constant void setSigma(const double &sigma); @@ -86,12 +86,15 @@ private: /// set fit window void setFitWindow(const std::vector<double> &window); - int findBackground(const size_t &l0, const size_t &n, + int findBackground(const HistogramData::Histogram &histogram, + const size_t &l0, const size_t &n, std::vector<size_t> &peak_min_max_indexes, std::vector<double> &bkgd3); + /// Histogram cannot be defined due to lack of default constructor. shared_ptr + /// will do the copy /// histogram data to find peak background - boost::shared_ptr<const HistogramData::Histogram> m_histogram; + /// boost::shared_ptr<const HistogramData::Histogram> m_histogram; // HistogramData::Histogram& m_histogram; /// fit window @@ -102,7 +105,9 @@ private: double m_sigmaConstant; /// output workspace (table of result) API::ITableWorkspace_sptr m_outPeakTableWS; - + /// Input workspace + API::MatrixWorkspace_const_sptr m_inputWS; + /// workspace index size_t m_inputWSIndex; // /// find background (main algorithm) @@ -111,7 +116,8 @@ private: // /// get result // void getBackgroundResult(); - void findWindowIndex(size_t &l0, size_t &n); + void findWindowIndex(const HistogramData::Histogram &histogram, size_t &l0, + size_t &n); struct cont_peak { size_t start; diff --git a/Framework/Algorithms/src/FindPeakBackground.cpp b/Framework/Algorithms/src/FindPeakBackground.cpp index 5cfe82d7857224243f21c3b642d9c2c77201c0fc..9e1c90721556860370f8fe332c285a10bc0d5cd4 100644 --- a/Framework/Algorithms/src/FindPeakBackground.cpp +++ b/Framework/Algorithms/src/FindPeakBackground.cpp @@ -64,9 +64,10 @@ void FindPeakBackground::init() { "quadratic terms."); } -void FindPeakBackground::findWindowIndex(size_t &l0, size_t &n) { - auto &inpX = m_histogram->x(); - auto &inpY = m_histogram->y(); +void FindPeakBackground::findWindowIndex( + const HistogramData::Histogram &histogram, size_t &l0, size_t &n) { + auto &inpX = histogram.x(); + auto &inpY = histogram.y(); size_t sizey = inpY.size(); // inpWS->y(inpwsindex).size(); // determine the fit window with their index in X (or Y) @@ -87,9 +88,10 @@ void FindPeakBackground::findWindowIndex(size_t &l0, size_t &n) { void FindPeakBackground::exec() { // Get input and validate processInputProperties(); + auto histogram = m_inputWS->histogram(m_inputWSIndex); size_t l0, n; - findWindowIndex(l0, n); + findWindowIndex(histogram, l0, n); // m_vecFitWindows won't be used again form this point till end. @@ -101,7 +103,7 @@ void FindPeakBackground::exec() { std::vector<size_t> peak_min_max_indexes; std::vector<double> bkgd3; - int goodfit = findBackground(l0, n, peak_min_max_indexes, bkgd3); + int goodfit = findBackground(histogram, l0, n, peak_min_max_indexes, bkgd3); if (goodfit > 0) { size_t min_peak = peak_min_max_indexes[0]; @@ -121,10 +123,11 @@ void FindPeakBackground::exec() { } int FindPeakBackground::findBackground( - const size_t &l0, const size_t &n, - std::vector<size_t> &peak_min_max_indexes, std::vector<double> &bkgd3) { - auto &inpX = m_histogram->x(); - auto &inpY = m_histogram->y(); + const HistogramData::Histogram &histogram, const size_t &l0, + const size_t &n, std::vector<size_t> &peak_min_max_indexes, + std::vector<double> &bkgd3) { + auto &inpX = histogram.x(); + auto &inpY = histogram.y(); size_t sizex = inpX.size(); // inpWS->x(inpwsindex).size(); size_t sizey = inpY.size(); // inpWS->y(inpwsindex).size(); @@ -411,28 +414,27 @@ double FindPeakBackground::moment4(MantidVec &X, size_t n, double mean) { //---------------------------------------------------------------------------------------------- void FindPeakBackground::processInputProperties() { // process input workspace and workspace index - MatrixWorkspace_const_sptr inpWS = getProperty("InputWorkspace"); + m_inputWS = getProperty("InputWorkspace"); int inpwsindex = getProperty("WorkspaceIndex"); if (isEmpty(inpwsindex)) { // Default - if (inpWS->getNumberHistograms() == 1) { + if (m_inputWS->getNumberHistograms() == 1) { inpwsindex = 0; } else { throw runtime_error("WorkspaceIndex must be given. "); } } else if (inpwsindex < 0 || - inpwsindex >= static_cast<int>(inpWS->getNumberHistograms())) { + inpwsindex >= static_cast<int>(m_inputWS->getNumberHistograms())) { stringstream errss; - errss << "Input workspace " << inpWS->getName() << " has " - << inpWS->getNumberHistograms() << " spectra. Input workspace index " - << inpwsindex << " is out of boundary. "; + errss << "Input workspace " << m_inputWS->getName() << " has " + << m_inputWS->getNumberHistograms() + << " spectra. Input workspace index " << inpwsindex + << " is out of boundary. "; throw runtime_error(errss.str()); } m_inputWSIndex = static_cast<size_t>(inpwsindex); - setHistogram(inpWS->histogram(inpwsindex)); - std::vector<double> fitwindow = getProperty("FitWindow"); setFitWindow(fitwindow); @@ -450,12 +452,6 @@ void FindPeakBackground::processInputProperties() { setSigma(k); } -/// set histogram data to find background -void FindPeakBackground::setHistogram( - const HistogramData::Histogram &histogram) { - m_histogram = boost::make_shared<HistogramData::Histogram>(histogram); -} - /// set sigma constant void FindPeakBackground::setSigma(const double &sigma) { m_sigmaConstant = sigma; @@ -473,12 +469,7 @@ void FindPeakBackground::setBackgroundOrder(size_t order) { */ void FindPeakBackground::setFitWindow(const std::vector<double> &fitwindow) { // validate input - if (m_vecFitWindows.size() == 0) { - m_vecFitWindows.resize(2); - m_vecFitWindows[0] = m_histogram->y().front(); - m_vecFitWindows[1] = m_histogram->y().back(); - } else if (m_vecFitWindows.size() != 2 || - m_vecFitWindows[0] >= m_vecFitWindows[1]) { + if ((fitwindow.size() == 2) && fitwindow[0] >= fitwindow[1]) { throw std::invalid_argument("Fit window has either wrong item number or " "window value is not in ascending order."); }