Commit 928e7358 authored by Robert Applin's avatar Robert Applin
Browse files

Refs #28842. Tidy up changes in model.

parent 34dfb93e
......@@ -8,9 +8,11 @@
#include "DllOption.h"
#include "MantidAPI/IFunction.h"
#include "MantidAPI/MatrixWorkspace.h"
#include <map>
#include <string>
#include <utility>
using namespace Mantid::API;
namespace MantidQt {
namespace MantidWidgets {
......@@ -30,6 +32,9 @@ public:
virtual bool hasEstimate() const;
private:
IFunction_sptr calculateEstimate(MatrixWorkspace_sptr &workspace,
const std::pair<double, double> &range);
IFunction_sptr m_estimateFunction;
};
......
......@@ -10,7 +10,6 @@
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/CompositeFunction.h"
#include "MantidAPI/FunctionFactory.h"
#include "MantidAPI/MatrixWorkspace.h"
#include <algorithm>
#include <numeric>
......@@ -117,18 +116,7 @@ IFunction_sptr PlotFitAnalysisPaneModel::calculateEstimate(
if (ads.doesExist(workspaceName)) {
auto workspace = ads.retrieveWS<MatrixWorkspace>(workspaceName);
workspace = cropWorkspace(workspace, range.first, range.second);
workspace = convertToPointData(workspace);
const auto xData = workspace->readX(0);
const auto yData = workspace->readY(0);
const auto background = std::accumulate(yData.begin(), yData.end(), 0.0) /
static_cast<double>(yData.size());
m_estimateFunction =
createCompositeFunction(createFlatBackground(background),
createGaussian(xData, yData, background));
m_estimateFunction = calculateEstimate(workspace, range);
return m_estimateFunction;
} else {
m_estimateFunction = nullptr;
......@@ -136,6 +124,21 @@ IFunction_sptr PlotFitAnalysisPaneModel::calculateEstimate(
}
}
IFunction_sptr PlotFitAnalysisPaneModel::calculateEstimate(
MatrixWorkspace_sptr &workspace, const std::pair<double, double> &range) {
workspace = cropWorkspace(workspace, range.first, range.second);
workspace = convertToPointData(workspace);
const auto xData = workspace->readX(0);
const auto yData = workspace->readY(0);
const auto background = std::accumulate(yData.begin(), yData.end(), 0.0) /
static_cast<double>(yData.size());
return createCompositeFunction(createFlatBackground(background),
createGaussian(xData, yData, background));
}
bool PlotFitAnalysisPaneModel::hasEstimate() const {
return m_estimateFunction != nullptr;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment