diff --git a/Framework/Algorithms/src/CalculateAsymmetry.cpp b/Framework/Algorithms/src/CalculateAsymmetry.cpp index e609f3a3f86f2b0a6eb73864945961fc0e2ab94a..ea2dee11bc3f97c3201f43bb58980dff794a2dc5 100644 --- a/Framework/Algorithms/src/CalculateAsymmetry.cpp +++ b/Framework/Algorithms/src/CalculateAsymmetry.cpp @@ -50,6 +50,7 @@ void CalculateAsymmetry::init() { "FittingFunction", "name = GausOsc, A = 10.0, Sigma = 0.2, Frequency = 1.0, Phi = 0.0", "The additional fitting functions to be used."); + } /** Executes the algorithm @@ -206,6 +207,7 @@ double CalculateAsymmetry::getNormConstant(API::MatrixWorkspace_sptr ws, fit->setProperty("EndX", endX); fit->execute(); + std::string fitStatus = fit->getProperty("OutputStatus"); API::IFunction_sptr result = fit->getProperty("Function"); std::vector<std::string> paramnames = result->getParameterNames(); diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h index ed00cca0ebcd5612a9b6b659767af38ccb46f0c5..aae00617ac6af97c63185ef6fca55a78c05a145f 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FitPropertyBrowser.h @@ -484,6 +484,9 @@ protected: QSignalMapper *m_fitMapper; QMenu *m_fitMenu; + /// Should the data be normalised before fitting? + bool m_shouldBeNormalised; + private: /// load and save function void loadFunction(const QString &funcString); @@ -596,8 +599,6 @@ private: /// store current workspace name std::string m_storedWorkspaceName; - /// Should the data be normalised before fitting? - bool m_shouldBeNormalised; friend class PropertyHandler; friend class CreateAttributeProperty; diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MuonFitPropertyBrowser.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MuonFitPropertyBrowser.h index ffdc87f15f3954e670c9d09286f824310bc76a35..89241e35a3189b4063128293738dc0e428f33597 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MuonFitPropertyBrowser.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MuonFitPropertyBrowser.h @@ -94,12 +94,14 @@ public: /// Whether a guess is plotted or not bool hasGuess() const override; + void TFAsymmFit(int maxIterations); + public slots: /// Perform the fit algorithm void fit() override; /// Open sequential fit dialog void sequentialFit() override; - + void executeMuonFitMenu(const QString &item); signals: /// Emitted when sequential fit is requested by user void sequentialFitRequested(); @@ -128,6 +130,7 @@ private: QAction *m_fitActiontest; /// Create new fit menu QPushButton *MuonFitPropertyBrowser::createMuonFitMenuButton(QWidget *w); + /// Get the registered function names void populateFunctionNames() override; /// Check if the workspace can be used in the fit diff --git a/MantidQt/MantidWidgets/src/MuonFitPropertyBrowser.cpp b/MantidQt/MantidWidgets/src/MuonFitPropertyBrowser.cpp index 76551011b0f70e4394cc21236973be31d79d00df..b994afb23ffeba9ec3ef6ebe02f4d3274e4fbe5d 100644 --- a/MantidQt/MantidWidgets/src/MuonFitPropertyBrowser.cpp +++ b/MantidQt/MantidWidgets/src/MuonFitPropertyBrowser.cpp @@ -185,7 +185,15 @@ void MuonFitPropertyBrowser::init() { parentLayout->setContentsMargins(0, 0, 0, 0); } } - +// Set up the execution of the muon fit menu +void MuonFitPropertyBrowser::executeMuonFitMenu(const QString &item) { + if (item == "TFAsymm") { + TFAsymmFit(1000); + } + else { + FitPropertyBrowser::executeFitMenu(item); + } +} /** * @brief Initialise the layout. * This initialization includes: @@ -211,7 +219,7 @@ QPushButton *MuonFitPropertyBrowser::createMuonFitMenuButton(QWidget *w) { m_fitMapper->setMapping(m_fitActionSeqFit, "SeqFit"); m_fitMapper->setMapping(m_fitActionUndoFit, "UndoFit"); m_fitMapper->setMapping(m_fitActionEvaluate, "Evaluate"); - m_fitMapper->setMapping(m_fitActiontest, "Fit"); + m_fitMapper->setMapping(m_fitActiontest, "TFAsymm"); connect(m_fitActionFit, SIGNAL(triggered()), m_fitMapper, SLOT(map())); connect(m_fitActionSeqFit, SIGNAL(triggered()), m_fitMapper, SLOT(map())); @@ -220,14 +228,14 @@ QPushButton *MuonFitPropertyBrowser::createMuonFitMenuButton(QWidget *w) { connect(m_fitActiontest, SIGNAL(triggered()), m_fitMapper, SLOT(map())); connect(m_fitMapper, SIGNAL(mapped(const QString &)), this, - SLOT(executeFitMenu(const QString &))); + SLOT(executeMuonFitMenu(const QString &))); m_fitMenu->addAction(m_fitActionFit); m_fitMenu->addAction(m_fitActionSeqFit); m_fitMenu->addAction(m_fitActionEvaluate); m_fitMenu->addSeparator(); m_fitMenu->addAction(m_fitActionUndoFit); m_fitMenu->addSeparator(); - m_fitMenu->addAction(m_fitActiontest); + m_fitMenu->addAction(m_fitActiontest); btnFit->setMenu(m_fitMenu); return btnFit; } @@ -341,6 +349,85 @@ void MuonFitPropertyBrowser::populateFunctionNames() { } } +//#include "../FitDialog.h" +/** +* Creates an instance of Fit algorithm, sets its properties and launches it. +*/ +void MuonFitPropertyBrowser::TFAsymmFit(int maxIterations) { + const std::string wsName = workspaceName(); + + if (wsName.empty()) { + QMessageBox::critical(this, "Mantid - Error", "Workspace name is not set"); + return; + } + + const auto ws = getWorkspace(); + if (!ws) { + return; + } + + try { + m_initialParameters.resize(compositeFunction()->nParams()); + for (size_t i = 0; i < compositeFunction()->nParams(); i++) { + m_initialParameters[i] = compositeFunction()->getParameter(i); + } + m_fitActionUndoFit->setEnabled(true); + + //Calculate the asymmetry + + std::string funStr = getFittingFunction()->asString(); + + Mantid::API::IAlgorithm_sptr asymmAlg = + Mantid::API::AlgorithmManager::Instance().create("CalculateAsymmetry"); + asymmAlg->initialize(); + asymmAlg->setPropertyValue("FittingFunction", funStr); + + asymmAlg->setProperty("InputWorkspace", ws);// try the raw workspace.... + //asymmAlg->setProperty("Spectra", workspaceIndex()); + asymmAlg->setProperty("StartX", startX()); + asymmAlg->setProperty("EndX", endX()); + asymmAlg->setPropertyValue("OutputWorkspace", "mooo");// outputName()); + observeFinish(asymmAlg); + asymmAlg->executeAsync(); + auto tmpWS = asymmAlg->getPropertyValue("OutputWorkSpace"); + + // calculate the fit + + Mantid::API::IAlgorithm_sptr alg = + Mantid::API::AlgorithmManager::Instance().create("Fit"); + alg->initialize(); + if (isHistogramFit()) { + alg->setProperty("EvaluationType", "Histogram"); + } + alg->setPropertyValue("Function", funStr); + alg->setProperty("InputWorkspace",tmpWS );// try the raw workspace.... + alg->setProperty("WorkspaceIndex", workspaceIndex()); + alg->setProperty("StartX", startX()); + alg->setProperty("EndX", endX()); + alg->setPropertyValue("Output", "boo");// outputName()); + alg->setPropertyValue("Minimizer", minimizer(true)); + alg->setProperty("IgnoreInvalidData", ignoreInvalidData()); + alg->setPropertyValue("CostFunction", costFunction()); + alg->setProperty("MaxIterations", maxIterations); + alg->setProperty("PeakRadius", getPeakRadius()); + if (!isHistogramFit()) { + alg->setProperty("Normalise", m_shouldBeNormalised); + // Always output each composite function but not necessarily plot it + alg->setProperty("OutputCompositeMembers", true); + if (alg->existsProperty("ConvolveMembers")) { + alg->setProperty("ConvolveMembers", convolveMembers()); + } + } + observeFinish(alg); + alg->executeAsync(); + + } + catch (const std::exception &e) { + QString msg = "Fit algorithm failed.\n\n" + QString(e.what()) + "\n"; + QMessageBox::critical(this, "Mantid - Error", msg); + } +} + /** * Requests checks and updates prior to running a fit */ @@ -639,16 +726,14 @@ void MuonFitPropertyBrowser::setMultiFittingMode(bool enabled) { void MuonFitPropertyBrowser::setTFAsymmMode(bool enabled) { // First, clear whatever model is currently set this->clear(); - - // Show or hide "Function" and "Data" sections - //m_browser->setItemVisible(m_functionsGroup, !enabled); - m_browser->setItemVisible(m_settingsGroup, !enabled); - // Show or hide additional widgets - /*for (int i = 0; i < m_widgetSplitter->count(); ++i) { - if (auto *widget = m_widgetSplitter->widget(i)) { - widget->setVisible(enabled); - } - }*/ + // Show or hide the TFAsymmetry fit + if (enabled) { + m_fitMenu->addAction(m_fitActiontest); + } + else { + m_fitMenu->removeAction(m_fitActiontest); + + } } /** * The pre-fit checks have been successfully completed. Continue by emitting a