diff --git a/Framework/CurveFitting/src/Algorithms/Fit.cpp b/Framework/CurveFitting/src/Algorithms/Fit.cpp index df0821fab6e03b3ad42437517f753fcdcf1700ac..d36909885d99acdae3998085a46b12f8c51f0df4 100644 --- a/Framework/CurveFitting/src/Algorithms/Fit.cpp +++ b/Framework/CurveFitting/src/Algorithms/Fit.cpp @@ -76,14 +76,6 @@ void Fit::initConcrete() { "CostFunction", "Least squares", costFuncValidator, "The cost function to be used for the fit, default is Least squares", Kernel::Direction::InOut); - declareProperty("PeakRadius", 0, - "A value of the peak radius the peak functions should use. A " - "peak radius defines an interval on the x axis around the " - "centre of the peak where its values are calculated. Values " - "outside the interval are not calculated and assumed zeros." - "Numerically the radius is a whole number of peak widths " - "(FWHM) that fit into the interval on each side from the " - "centre. The default value of 0 means the whole x axis."); declareProperty( "CreateOutput", false, "Set to true to create output workspaces with the results of the fit" @@ -143,41 +135,16 @@ void Fit::execConcrete() { m_function->addConstraints(contstraints); } - // prepare the function for a fit - m_function->setUpForFit(); + auto costFunc = getCostFunctionProperty(); - API::FunctionDomain_sptr domain; - API::FunctionValues_sptr values; - m_domainCreator->createDomain(domain, values); - - // Set peak radius to the values which will be passed to - // all IPeakFunctions - int peakRadius = getProperty("PeakRadius"); - if (auto d1d = dynamic_cast<API::FunctionDomain1D *>(domain.get())) { - if (peakRadius != 0) { - d1d->setPeakRadius(peakRadius); - } - } - - // do something with the function which may depend on workspace - m_domainCreator->initFunction(m_function); + // Try to retrieve optional properties + int intMaxIterations = getProperty("MaxIterations"); + const size_t maxIterations = static_cast<size_t>(intMaxIterations); // get the minimizer std::string minimizerName = getPropertyValue("Minimizer"); API::IFuncMinimizer_sptr minimizer = API::FuncMinimizerFactory::Instance().createMinimizer(minimizerName); - - // Try to retrieve optional properties - int intMaxIterations = getProperty("MaxIterations"); - const size_t maxIterations = static_cast<size_t>(intMaxIterations); - - // get the cost function which must be a CostFuncFitting - boost::shared_ptr<CostFunctions::CostFuncFitting> costFunc = - boost::dynamic_pointer_cast<CostFunctions::CostFuncFitting>( - API::CostFunctionFactory::Instance().create( - getPropertyValue("CostFunction"))); - - costFunc->setFittingFunction(m_function, domain, values); minimizer->initialize(costFunc, maxIterations); const int64_t nsteps = maxIterations * m_function->estimateNoProgressCalls(); @@ -223,7 +190,7 @@ void Fit::execConcrete() { setPropertyValue("OutputStatus", errorString); // degrees of freedom - size_t dof = domain->size() - costFunc->nParams(); + size_t dof = costFunc->getDomain()->size() - costFunc->nParams(); if (dof == 0) dof = 1; double rawcostfuncval = minimizer->costFunctionVal(); @@ -374,8 +341,8 @@ void Fit::execConcrete() { } m_domainCreator->separateCompositeMembersInOutput(unrollComposites, convolveMembers); - m_domainCreator->createOutputWorkspace(baseName, m_function, domain, - values); + m_domainCreator->createOutputWorkspace(baseName, m_function, costFunc->getDomain(), + costFunc->getValues()); } } diff --git a/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValue.cpp b/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValue.cpp index 415298121a8ce27786df0925435175a46418e6e2..1d031da05b1709535dc3af63bb4527fa5ae5ea61 100644 --- a/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValue.cpp +++ b/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValue.cpp @@ -114,6 +114,14 @@ void PlotPeakByLogValue::init() { declareProperty("MaxIterations", 500, "Stop after this number of iterations if a good fit is not " "found"); + declareProperty("PeakRadius", 0, + "A value of the peak radius the peak functions should use. A " + "peak radius defines an interval on the x axis around the " + "centre of the peak where its values are calculated. Values " + "outside the interval are not calculated and assumed zeros." + "Numerically the radius is a whole number of peak widths " + "(FWHM) that fit into the interval on each side from the " + "centre. The default value of 0 means the whole x axis."); declareProperty("CreateOutput", false, "Set to true to create output " "workspaces with the results of the " @@ -292,6 +300,7 @@ void PlotPeakByLogValue::exec() { fit->setPropertyValue("CostFunction", getPropertyValue("CostFunction")); fit->setPropertyValue("MaxIterations", getPropertyValue("MaxIterations")); + fit->setPropertyValue("PeakRadius", getPropertyValue("PeakRadius")); fit->setProperty("CalcErrors", true); fit->setProperty("CreateOutput", createFitOutput); if (!histogramFit) { diff --git a/Framework/CurveFitting/src/IFittingAlgorithm.cpp b/Framework/CurveFitting/src/IFittingAlgorithm.cpp index 60190da0a709a8bd1ba4e02cc30b9f6813c024c8..8125ea664c1fb4a0110e3a59d7611454be5cfb34 100644 --- a/Framework/CurveFitting/src/IFittingAlgorithm.cpp +++ b/Framework/CurveFitting/src/IFittingAlgorithm.cpp @@ -93,6 +93,14 @@ void IFittingAlgorithm::init() { "centre of each bin. If it is \"Histogram\" then function is " "integrated within the bin and the integrals returned.", Kernel::Direction::Input); + declareProperty("PeakRadius", 0, + "A value of the peak radius the peak functions should use. A " + "peak radius defines an interval on the x axis around the " + "centre of the peak where its values are calculated. Values " + "outside the interval are not calculated and assumed zeros." + "Numerically the radius is a whole number of peak widths " + "(FWHM) that fit into the interval on each side from the " + "centre. The default value of 0 means the whole x axis."); initConcrete(); } @@ -300,6 +308,15 @@ IFittingAlgorithm::getCostFunctionProperty() const { API::FunctionValues_sptr values; m_domainCreator->createDomain(domain, values); + // Set peak radius to the values which will be passed to + // all IPeakFunctions + int peakRadius = getProperty("PeakRadius"); + if (auto d1d = dynamic_cast<API::FunctionDomain1D *>(domain.get())) { + if (peakRadius != 0) { + d1d->setPeakRadius(peakRadius); + } + } + // Do something with the function which may depend on workspace. m_domainCreator->initFunction(m_function); diff --git a/Framework/WorkflowAlgorithms/src/ConvolutionFitSequential.cpp b/Framework/WorkflowAlgorithms/src/ConvolutionFitSequential.cpp index 7e05ad35f573b30a148baf169e939bc14f628df5..93801abbccf4470a48dfe2b240a44ff834cf137c 100644 --- a/Framework/WorkflowAlgorithms/src/ConvolutionFitSequential.cpp +++ b/Framework/WorkflowAlgorithms/src/ConvolutionFitSequential.cpp @@ -109,6 +109,14 @@ void ConvolutionFitSequential::init() { declareProperty("MaxIterations", 500, boundedV, "The maximum number of iterations permitted", Direction::Input); + declareProperty("PeakRadius", 0, + "A value of the peak radius the peak functions should use. A " + "peak radius defines an interval on the x axis around the " + "centre of the peak where its values are calculated. Values " + "outside the interval are not calculated and assumed zeros." + "Numerically the radius is a whole number of peak widths " + "(FWHM) that fit into the interval on each side from the " + "centre. The default value of 0 means the whole x axis."); declareProperty(make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output), @@ -131,6 +139,7 @@ void ConvolutionFitSequential::exec() { const bool convolve = getProperty("Convolve"); const int maxIter = getProperty("MaxIterations"); const std::string minimizer = getProperty("Minimizer"); + const int peakRadius = getProperty("PeakRadius"); // Inspect function to obtain fit Type and background const auto functionValues = findValuesFromFunction(function); @@ -207,6 +216,7 @@ void ConvolutionFitSequential::exec() { plotPeaks->setProperty("MaxIterations", maxIter); plotPeaks->setProperty("Minimizer", minimizer); plotPeaks->setProperty("PassWSIndexToFunction", passIndex); + plotPeaks->setProperty("PeakRadius", peakRadius); plotPeaks->executeAsChildAlg(); ITableWorkspace_sptr outputWs = plotPeaks->getProperty("OutputWorkspace"); diff --git a/MantidPlot/src/ConfigDialog.cpp b/MantidPlot/src/ConfigDialog.cpp index 032912b7ef8db18881a14e6f7f740ee2fecf60b7..f30837b4dd25b2f05baa0af6c0b0d6b76363084a 100644 --- a/MantidPlot/src/ConfigDialog.cpp +++ b/MantidPlot/src/ConfigDialog.cpp @@ -1586,11 +1586,6 @@ void ConfigDialog::initCurveFittingTab() { findPeaksTolerance->setMaximum(1000000); grid->addWidget(findPeaksTolerance, 4, 1); - grid->addWidget(new QLabel(tr("Peak Radius (in FWHM)")), 5, 0); - peakRadius = new QSpinBox(); - peakRadius->setMaximum(std::numeric_limits<int>::max()); - grid->addWidget(peakRadius, 5, 1); - grid->addWidget(new QLabel(tr("Double property decimals")), 6, 0); decimals = new QSpinBox(); grid->addWidget(decimals, 6, 1); @@ -1675,15 +1670,6 @@ void ConfigDialog::initCurveFittingTab() { findPeaksTolerance->setValue(4); } - setting = QString::fromStdString( - Mantid::Kernel::ConfigService::Instance().getString( - "curvefitting.peakRadius")); - if (!setting.isEmpty()) { - peakRadius->setValue(setting.toInt()); - } else { - peakRadius->setValue(5); - } - decimals->setValue(app->mantidUI->fitFunctionBrowser()->getDecimals()); } @@ -2806,9 +2792,6 @@ void ConfigDialog::updateCurveFitSettings() { setting = QString::number(findPeaksTolerance->value()).toStdString(); cfgSvc.setString("curvefitting.findPeaksTolerance", setting); - setting = QString::number(peakRadius->value()).toStdString(); - cfgSvc.setString("curvefitting.peakRadius", setting); - app->mantidUI->fitFunctionBrowser()->setDecimals(decimals->value()); } diff --git a/MantidPlot/src/ConfigDialog.h b/MantidPlot/src/ConfigDialog.h index cc14cf626f202a95a2818351ba15c2fdd8fdc002..e795145e2acd681c176c82cdc12d41f23707524f 100644 --- a/MantidPlot/src/ConfigDialog.h +++ b/MantidPlot/src/ConfigDialog.h @@ -219,7 +219,6 @@ private: QLineEdit *functionArguments; QComboBox *defaultPeakShape; QSpinBox *findPeaksFWHM, *findPeaksTolerance; - QSpinBox *peakRadius; QSpinBox *decimals; /// mantid options page QWidget *mantidOptionsPage; diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitOptionsBrowser.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitOptionsBrowser.h index 0ca9c6f49759c18d65f0dc5ffc6674a66a8622aa..952c7bee461b06cdfe4e74a637759aad0d66c18d 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitOptionsBrowser.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitOptionsBrowser.h @@ -135,6 +135,8 @@ private: QtProperty *m_maxIterations; /// EvaluationType property QtProperty *m_evaluationType; + /// Peak radius property + QtProperty *m_peakRadius; // Fit properties /// Output property diff --git a/MantidQt/MantidWidgets/src/FitOptionsBrowser.cpp b/MantidQt/MantidWidgets/src/FitOptionsBrowser.cpp index 1ed2d41fbd275cd37c417f4bac0b3ffd25271413..f7c7ec0deb37e115098b4e08ff954c43ddd45e79 100644 --- a/MantidQt/MantidWidgets/src/FitOptionsBrowser.cpp +++ b/MantidQt/MantidWidgets/src/FitOptionsBrowser.cpp @@ -201,6 +201,16 @@ void FitOptionsBrowser::createCommonProperties() { &FitOptionsBrowser::getStringEnumProperty, &FitOptionsBrowser::setStringEnumProperty); } + // Create PeakRadius property + m_peakRadius = m_intManager->addProperty("Peak Radius"); + { + m_intManager->setValue(m_peakRadius, 0); + m_intManager->setMinimum(m_peakRadius, 0); + m_browser->addProperty(m_peakRadius); + addProperty("PeakRadius", m_peakRadius, + &FitOptionsBrowser::getIntProperty, + &FitOptionsBrowser::setIntProperty); + } } void FitOptionsBrowser::createSimultaneousFitProperties() { diff --git a/Testing/SystemTests/tests/analysis/ISISIndirectInelastic.py b/Testing/SystemTests/tests/analysis/ISISIndirectInelastic.py index 7523cfc37ac82a79add468e9658b29f6b0a570cc..2c56de5abdedd246fd7a825aca98c931a669f77c 100644 --- a/Testing/SystemTests/tests/analysis/ISISIndirectInelastic.py +++ b/Testing/SystemTests/tests/analysis/ISISIndirectInelastic.py @@ -1024,6 +1024,7 @@ class ISISIndirectInelasticConvFit(ISISIndirectInelasticBase): BackgroundType=self.bg, SpecMin=self.spectra_min, SpecMax=self.spectra_max, + PeakRadius=5, OutputWorkspace='result') def _validate_properties(self): diff --git a/docs/source/algorithms/ConvolutionFitSequential-v1.rst b/docs/source/algorithms/ConvolutionFitSequential-v1.rst index 615c0e177f848ee0e63ad5ee31ef4b5d55361c8a..d8d8018e11e9d97d8a09e5289f1cc9fd67bb9eca 100644 --- a/docs/source/algorithms/ConvolutionFitSequential-v1.rst +++ b/docs/source/algorithms/ConvolutionFitSequential-v1.rst @@ -71,7 +71,7 @@ Output: Result has 2 Spectra - Amplitude 0: 4.293 + Amplitude 0: 4.314 Amplitude 1: 4.179 Amplitude 2: 3.979 @@ -79,7 +79,7 @@ Output: X axis at 1: 0.72917 X axis at 2: 0.92340 - Amplitude Err 0: 0.00465 + Amplitude Err 0: 0.00460 Amplitude Err 1: 0.00464 Amplitude Err 2: 0.00504 diff --git a/docs/source/algorithms/TOSCABankCorrection-v1.rst b/docs/source/algorithms/TOSCABankCorrection-v1.rst index 22fee78069ae00a94287f9a423d0964dfdfe89dc..21a1da9a677f5faa15638beb7bb632d46cc22292 100644 --- a/docs/source/algorithms/TOSCABankCorrection-v1.rst +++ b/docs/source/algorithms/TOSCABankCorrection-v1.rst @@ -77,7 +77,7 @@ Output: .. testoutput:: ExTOSCABankCorrectionAutomatic - Target peak centre: 1077 + Target peak centre: 1080 **Example - Manual peak selection.** @@ -95,6 +95,6 @@ Output: .. testoutput:: ExTOSCABankCorrectionManual - Target peak centre: 713 + Target peak centre: 714 .. categories::