Commit 506f5d05 authored by Alice Russell's avatar Alice Russell
Browse files

Re #28255 Change initial values of a and b for IkedaCarpenter

This commit changes the initial values set for alpha0, alpha1 and beta0 in the ikedacarpenter function to depend on the x units so the initial plot guess is reasonable.
It also adds a check so that when a peak function is added the width of the function is within the fitting region.
parent 54ce079f
......@@ -43,6 +43,9 @@ public:
/// Returns the integral intensity of the peak
double intensity() const override;
void setMatrixWorkspace(std::shared_ptr<const API::MatrixWorkspace> workspace,
size_t wi, double startX, double endX) override;
protected:
void functionLocal(double *out, const double *xValues,
const size_t nData) const override;
......
......@@ -410,6 +410,22 @@ double IkedaCarpenterPV::intensity() const {
return result.result;
}
void IkedaCarpenterPV::setMatrixWorkspace(
std::shared_ptr<const API::MatrixWorkspace> workspace, size_t wi,
double startX, double endX) {
if (workspace) {
// convert inital parameters that depend on x axis to correct units so
// inital guess is reasonable
auto tof = Mantid::Kernel::UnitFactory::Instance().create("TOF");
const auto scaleFactor = convertValue(1, tof, workspace, wi);
setParameter("Alpha0", getParameter("Alpha0") / scaleFactor);
setParameter("Alpha1", getParameter("Alpha1") / scaleFactor);
setParameter("Beta0", getParameter("Beta0") / scaleFactor);
}
IFunctionMW::setMatrixWorkspace(workspace, wi, startX, endX);
}
} // namespace Functions
} // namespace CurveFitting
} // namespace Mantid
......@@ -1376,8 +1376,8 @@ public:
TS_ASSERT_EQUALS(fitStatus, "success");
IFunction_sptr func = fit.getProperty("Function");
TS_ASSERT_DELTA(func->getParameter("TOF_h"), 55175.79, 1.0E-8);
TS_ASSERT_DELTA(func->getParameter("Height"), 96000, 100);
TS_ASSERT_DELTA(func->getParameter("X0"), 55175.79, 1.0E-8);
TS_ASSERT_DELTA(func->getParameter("Intensity"), 96000, 100);
}
void test_function_Gaussian_LMMinimizer() {
......
......@@ -507,6 +507,9 @@ class FitPropertyBrowser(FitPropertyBrowserBase):
for prefix in self.getPeakPrefixes():
c, h, w = self.getPeakCentreOf(prefix), self.getPeakHeightOf(
prefix), self.getPeakFwhmOf(prefix)
if w > (self.endX() - self.startX()):
w = (self.endX() - self.startX())/20.
self.setPeakFwhmOf(prefix, w)
if prefix in peaks:
self.tool.update_peak(peaks[prefix], c, h, w)
del peaks[prefix]
......@@ -532,8 +535,8 @@ class FitPropertyBrowser(FitPropertyBrowserBase):
self.peak_ids.update(peak_ids)
for prefix, c, h, w in peak_updates:
self.setPeakCentreOf(prefix, c)
self.setPeakHeightOf(prefix, h)
self.setPeakFwhmOf(prefix, w)
self.setPeakHeightOf(prefix, h)
self.update_guess()
@Slot(str)
......
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