diff --git a/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValue.cpp b/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValue.cpp index 48970fc83be56d325c4998573c1945d817a5e979..f53813eb1e64c2296f0e8154677a98e33edd9eab 100644 --- a/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValue.cpp +++ b/Framework/CurveFitting/src/Algorithms/PlotPeakByLogValue.cpp @@ -130,8 +130,14 @@ void PlotPeakByLogValue::init() { "If true and OutputCompositeMembers is true members of any " "Convolution are output convolved\n" "with corresponding resolution"); - declareProperty("HistogramFit", false, - "Flag to perform histogram fitting."); + + std::vector<std::string> evaluationTypes{"CentrePoint", "Histogram"}; + declareProperty( + "EvaluationType", "CentrePoint", + Kernel::IValidator_sptr( + new Kernel::ListValidator<std::string>(evaluationTypes)), + "The way the function is evaluated: CentrePoint or Histogram.", + Kernel::Direction::Input); } /** @@ -270,14 +276,14 @@ void PlotPeakByLogValue::exec() { if (createFitOutput) wsBaseName = wsNames[i].name + "_" + spectrum_index; - bool histogramFit = getProperty("HistogramFit"); + bool histogramFit = getPropertyValue("EvaluationType") == "Histogram"; // Fit the function API::IAlgorithm_sptr fit = AlgorithmManager::Instance().createUnmanaged("Fit"); fit->initialize(); if (histogramFit) { - fit->setProperty("HistogramFit", histogramFit); + fit->setPropertyValue("EvaluationType", getPropertyValue("EvaluationType")); } fit->setProperty("Function", ifun); fit->setProperty("InputWorkspace", data.ws); diff --git a/Framework/CurveFitting/src/HistogramDomainCreator.cpp b/Framework/CurveFitting/src/HistogramDomainCreator.cpp index c75b6aadc4c1d302b26e497cded6be5aea023ae5..e2bd8f1951f34edecb61d8f813632e84f5f8641e 100644 --- a/Framework/CurveFitting/src/HistogramDomainCreator.cpp +++ b/Framework/CurveFitting/src/HistogramDomainCreator.cpp @@ -128,7 +128,7 @@ boost::shared_ptr<API::Workspace> HistogramDomainCreator::createOutputWorkspace( auto &bins = dynamic_cast<FunctionDomain1DHistogram&>(*domain); double left = bins.leftBoundary(); for(size_t iSpec = 1; iSpec < mws.getNumberHistograms(); ++iSpec) { - if (iSpec == 2) continue; + if (iSpec == 2) continue; // skip the diff spectrum auto &x = mws.readX(iSpec); auto &y = mws.dataY(iSpec); auto &e = mws.dataE(iSpec); diff --git a/Framework/CurveFitting/src/IFittingAlgorithm.cpp b/Framework/CurveFitting/src/IFittingAlgorithm.cpp index bec9f27a13aa2123a5aac1fc713c12134714379f..cc4c62d5726631536ff4ac128368153c3889ff03 100644 --- a/Framework/CurveFitting/src/IFittingAlgorithm.cpp +++ b/Framework/CurveFitting/src/IFittingAlgorithm.cpp @@ -43,7 +43,7 @@ IDomainCreator *createDomainCreator(const IFunction *fun, } else if (auto gfun = dynamic_cast<const IFunctionGeneral *>(fun)) { creator = new GeneralDomainCreator(*gfun, *manager, workspacePropertyName); } else { - bool histogramFit = manager->getProperty("HistogramFit"); + bool histogramFit = manager->getPropertyValue("EvaluationType") == "Histogram"; if (histogramFit) { creator = new HistogramDomainCreator(*manager, workspacePropertyName); } else { @@ -72,8 +72,6 @@ void IFittingAlgorithm::init() { "Name of the input Workspace"); declareProperty("IgnoreInvalidData", false, "Flag to ignore infinities, NaNs and data with zero errors."); - declareProperty("HistogramFit", false, - "Flag to perform histogram fitting."); std::vector<std::string> domainTypes{"Simple", "Sequential", "Parallel"}; declareProperty( @@ -83,6 +81,14 @@ void IFittingAlgorithm::init() { "The type of function domain to use: Simple, Sequential, or Parallel.", Kernel::Direction::Input); + std::vector<std::string> evaluationTypes{"CentrePoint", "Histogram"}; + declareProperty( + "EvaluationType", "CentrePoint", + Kernel::IValidator_sptr( + new Kernel::ListValidator<std::string>(evaluationTypes)), + "The way the function is evaluated: CentrePoint or Histogram.", + Kernel::Direction::Input); + initConcrete(); } diff --git a/Framework/CurveFitting/test/Algorithms/PlotPeakByLogValueTest.h b/Framework/CurveFitting/test/Algorithms/PlotPeakByLogValueTest.h index 3864d21f50726448bcbf964e06af8249dbdafea3..3278a514b989c2e46db317efc3bc6067fd235b13 100644 --- a/Framework/CurveFitting/test/Algorithms/PlotPeakByLogValueTest.h +++ b/Framework/CurveFitting/test/Algorithms/PlotPeakByLogValueTest.h @@ -578,7 +578,7 @@ public: std::string fun = "name=FlatBackground,A0=" + std::to_string(fwhms[i]); auto alg = AlgorithmFactory::Instance().create("EvaluateFunction", -1); alg->initialize(); - alg->setProperty("HistogramFit", true); + alg->setProperty("EvaluationType", "Histogram"); alg->setProperty("Function", fun); alg->setProperty("InputWorkspace", ws); alg->setProperty("OutputWorkspace", "out"); @@ -590,7 +590,7 @@ public: PlotPeakByLogValue alg; alg.initialize(); - alg.setProperty("HistogramFit", true); + alg.setProperty("EvaluationType", "Histogram"); alg.setPropertyValue("Input", "InputWS,v1:3"); alg.setPropertyValue("OutputWorkspace", "out"); alg.setProperty("CreateOutput", true); diff --git a/Framework/CurveFitting/test/HistogramDomainCreatorTest.h b/Framework/CurveFitting/test/HistogramDomainCreatorTest.h index 5b7d045543d78ac9571500b8ed3ca511d57a97cc..f4c637ca4bac919456bacca603addc4525608135 100644 --- a/Framework/CurveFitting/test/HistogramDomainCreatorTest.h +++ b/Framework/CurveFitting/test/HistogramDomainCreatorTest.h @@ -140,7 +140,7 @@ public: Fit fit; fit.initialize(); fit.setProperty("Function", "name=Lorentzian,FWHM=0.5"); - fit.setProperty("HistogramFit", true); + fit.setProperty("EvaluationType", "Histogram"); fit.setProperty("InputWorkspace", ws); fit.setProperty("Output", "fit"); fit.execute(); @@ -204,7 +204,7 @@ public: Fit fit; fit.initialize(); fit.setProperty("Function", "name=Gaussian,Height=1,Sigma=0.5"); - fit.setProperty("HistogramFit", true); + fit.setProperty("EvaluationType", "Histogram"); fit.setProperty("InputWorkspace", ws); fit.setProperty("Output", "fit"); fit.execute(); @@ -233,7 +233,7 @@ public: Fit fit; fit.initialize(); fit.setProperty("Function", "name=FlatBackground"); - fit.setProperty("HistogramFit", true); + fit.setProperty("EvaluationType", "Histogram"); fit.setProperty("InputWorkspace", ws); fit.setProperty("Output", "fit"); fit.execute(); @@ -260,7 +260,7 @@ public: Fit fit; fit.initialize(); fit.setProperty("Function", "name=LinearBackground"); - fit.setProperty("HistogramFit", true); + fit.setProperty("EvaluationType", "Histogram"); fit.setProperty("InputWorkspace", ws); fit.setProperty("Output", "fit"); fit.execute(); @@ -288,7 +288,7 @@ public: Fit fit; fit.initialize(); fit.setProperty("Function", "name=LinearBackground;name=Gaussian,Height=1,Sigma=0.3"); - fit.setProperty("HistogramFit", true); + fit.setProperty("EvaluationType", "Histogram"); fit.setProperty("InputWorkspace", ws); fit.setProperty("Output", "fit"); fit.execute(); @@ -328,7 +328,7 @@ public: Fit fit; fit.initialize(); fit.setProperty("Function", "name=FlatBackground"); - fit.setProperty("HistogramFit", true); + fit.setProperty("EvaluationType", "Histogram"); fit.setProperty("InputWorkspace", ws); fit.setProperty("Output", "fit"); fit.execute(); diff --git a/Framework/PythonInterface/mantid/simpleapi.py b/Framework/PythonInterface/mantid/simpleapi.py index 6cd87ff239f955c60149513cb156e0eac36eb179..d9cc9a80b38f9e6962cdb5315ebb4513ec24d310 100644 --- a/Framework/PythonInterface/mantid/simpleapi.py +++ b/Framework/PythonInterface/mantid/simpleapi.py @@ -237,9 +237,9 @@ def fitting_algorithm(f): # Create and execute algm = _create_algorithm_object(function_name) _set_logging_option(algm, kwargs) - if 'HistogramFit' in kwargs: - algm.setProperty('HistogramFit', kwargs['HistogramFit']) - del kwargs['HistogramFit'] + if 'EvaluationType' in kwargs: + algm.setProperty('EvaluationType', kwargs['EvaluationType']) + del kwargs['EvaluationType'] algm.setProperty('Function', Function) # Must be set first if InputWorkspace is not None: algm.setProperty('InputWorkspace', InputWorkspace) diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitOptionsBrowser.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitOptionsBrowser.h index 97b3d258937c84a96494620599c92723ab484d18..0ca9c6f49759c18d65f0dc5ffc6674a66a8622aa 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitOptionsBrowser.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitOptionsBrowser.h @@ -133,8 +133,8 @@ private: QtProperty *m_costFunction; /// MaxIterations property QtProperty *m_maxIterations; - /// HistogramFit property - QtProperty *m_histogramFit; + /// EvaluationType property + QtProperty *m_evaluationType; // Fit properties /// Output property diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h index 45a47e1c50864a2bb08b2c10e70b632e46c82315..59ad768a821143cbbd768ac03ee41c6818c74600 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h @@ -409,7 +409,7 @@ protected: QtProperty *m_yColumn; QtProperty *m_errColumn; QtProperty *m_showParamErrors; - QtProperty *m_histogramFit; + QtProperty *m_evaluationType; QList<QtProperty *> m_minimizerProperties; /// A copy of the edited function @@ -452,6 +452,8 @@ protected: mutable QStringList m_workspaceNames; /// A list of available cost functions mutable QStringList m_costFunctions; + /// A list of possible function evaluation types + mutable QStringList m_evaluationTypes; /// To keep a copy of the initial parameters in case for undo fit std::vector<double> m_initialParameters; diff --git a/MantidQt/MantidWidgets/src/FitOptionsBrowser.cpp b/MantidQt/MantidWidgets/src/FitOptionsBrowser.cpp index bb64169bafe50f55053065ff74a72829c5e811fd..c488a2c59389386126b150754c545847ad621fb4 100644 --- a/MantidQt/MantidWidgets/src/FitOptionsBrowser.cpp +++ b/MantidQt/MantidWidgets/src/FitOptionsBrowser.cpp @@ -189,13 +189,16 @@ void FitOptionsBrowser::createCommonProperties() { &FitOptionsBrowser::setStringEnumProperty); } - // Create HistogramFit property - m_histogramFit = m_boolManager->addProperty("Histogram Fit"); + // Create EvaluationType property + m_evaluationType = m_enumManager->addProperty("Evaluate Function As"); { - m_browser->addProperty(m_histogramFit); - addProperty("HistogramFit", m_histogramFit, - &FitOptionsBrowser::getBoolProperty, - &FitOptionsBrowser::setBoolProperty); + QStringList evaluationTypes; + evaluationTypes << "CentrePoint" << "Histogram"; + m_enumManager->setEnumNames(m_evaluationType, evaluationTypes); + m_browser->addProperty(m_evaluationType); + addProperty("EvaluationType", m_evaluationType, + &FitOptionsBrowser::getStringEnumProperty, + &FitOptionsBrowser::setStringEnumProperty); } } diff --git a/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp b/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp index 26eea71aac9d47fa34a6c7ae057757433c54c593..74f73f9abbfbb2d12d5c8b7d8054c0887d17a697 100644 --- a/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp +++ b/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp @@ -213,9 +213,10 @@ void FitPropertyBrowser::init() { m_boolManager->setValue(m_showParamErrors, showParamErrors); m_parameterManager->setErrorsEnabled(showParamErrors); - m_histogramFit = m_boolManager->addProperty("Histogram fit"); - bool histoFit = settings.value(m_histogramFit->propertyName(), false).toBool(); - m_boolManager->setValue(m_histogramFit, histoFit); + m_evaluationType = m_enumManager->addProperty("Evaluate Function As"); + m_evaluationTypes << "CentrePoint" + << "Histogram"; + m_enumManager->setEnumNames(m_evaluationType, m_evaluationTypes); m_xColumn = m_columnManager->addProperty("XColumn"); m_yColumn = m_columnManager->addProperty("YColumn"); @@ -237,7 +238,7 @@ void FitPropertyBrowser::init() { settingsGroup->addSubProperty(m_plotCompositeMembers); settingsGroup->addSubProperty(m_convolveMembers); settingsGroup->addSubProperty(m_showParamErrors); - settingsGroup->addSubProperty(m_histogramFit); + settingsGroup->addSubProperty(m_evaluationType); /* Create editors and assign them to the managers */ createEditors(w); @@ -1109,7 +1110,8 @@ bool FitPropertyBrowser::convolveMembers() const { /// Get "HistogramFit" option bool FitPropertyBrowser::isHistogramFit() const { - return m_boolManager->value(m_histogramFit); + int i = m_enumManager->value(m_evaluationType); + return m_evaluationTypes[i].toStdString() == "Histogram"; } @@ -1472,7 +1474,9 @@ void FitPropertyBrowser::doFit(int maxIterations) { Mantid::API::IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create("Fit"); alg->initialize(); - alg->setProperty("HistogramFit", isHistogramFit()); + if (isHistogramFit()) { + alg->setProperty("EvaluationType", "Histogram"); + } alg->setPropertyValue("Function", funStr); alg->setProperty("InputWorkspace", ws); alg->setProperty("WorkspaceIndex", workspaceIndex()); diff --git a/MantidQt/MantidWidgets/src/SequentialFitDialog.cpp b/MantidQt/MantidWidgets/src/SequentialFitDialog.cpp index 41f6070ccdc68c406af5c71ccd8263a420c7f255..e671d4881d5493029c12b9cbf025e59c12186afa 100644 --- a/MantidQt/MantidWidgets/src/SequentialFitDialog.cpp +++ b/MantidQt/MantidWidgets/src/SequentialFitDialog.cpp @@ -336,7 +336,9 @@ void SequentialFitDialog::accept() { if (ui.rbIndividual->isChecked()) { alg->setPropertyValue("FitType", "Individual"); } - alg->setProperty("HistogramFit", m_fitBrowser->isHistogramFit()); + if (m_fitBrowser->isHistogramFit()) { + alg->setProperty("EvaluationType", "Histogram"); + } bool passWSIndexToFunction = ui.ckbPassWS->isChecked(); alg->setProperty("PassWSIndexToFunction", passWSIndexToFunction);