From 2f581e7126ea40c196aeb8d0c11b0889cd0de3bf Mon Sep 17 00:00:00 2001 From: Anthony Lim <anthony.lim@stfc.ac.uk> Date: Tue, 19 Jun 2018 12:16:17 +0100 Subject: [PATCH] refs #21718 muon anlysis TF plot updates --- .../Muon/MuonAnalysis.cpp | 59 ++++++++++++++++++- qt/scientific_interfaces/Muon/MuonAnalysis.h | 5 ++ .../Common/MuonFitPropertyBrowser.h | 4 +- .../common/src/MuonFitPropertyBrowser.cpp | 50 +++++++++++++--- 4 files changed, 109 insertions(+), 9 deletions(-) diff --git a/qt/scientific_interfaces/Muon/MuonAnalysis.cpp b/qt/scientific_interfaces/Muon/MuonAnalysis.cpp index 3bead796222..7a4a592d47f 100644 --- a/qt/scientific_interfaces/Muon/MuonAnalysis.cpp +++ b/qt/scientific_interfaces/Muon/MuonAnalysis.cpp @@ -2035,6 +2035,59 @@ void MuonAnalysis::selectMultiPeak(const QString &wsName) { selectMultiPeak(wsName, boost::optional<QString>()); } +/** +* Enable PP tool for the plot of the given WS. Does not update data selector +* @param wsName Name of the WS which plot PP tool will be attached to. +* @param filePath :: [input] Optional path to file that is actually used. This +* is for "load current run" where the data file has a temporary name like +* MUSRauto_E.tmp +*/ +void MuonAnalysis::selectMultiPeakNoUpdate(const QString &wsName, + const boost::optional<QString> &filePath) { + disableAllTools(); + if (!plotExists(wsName)) { + plotSpectrum(wsName); + setCurrentDataName(wsName); + } + + if (wsName != m_fitDataPresenter->getAssignedFirstRun()) { + // Set the available groups/pairs and periods + const Grouping groups = m_groupingHelper.parseGroupingTable(); + QStringList groupsAndPairs; + groupsAndPairs.reserve( + static_cast<int>(groups.groupNames.size() + groups.pairNames.size())); + std::transform(groups.groupNames.begin(), groups.groupNames.end(), + std::back_inserter(groupsAndPairs), &QString::fromStdString); + std::transform(groups.pairNames.begin(), groups.pairNames.end(), + std::back_inserter(groupsAndPairs), &QString::fromStdString); + setGroupsAndPairs(); + + // Set the selected run, group/pair and period + //m_fitDataPresenter->setAssignedFirstRun(wsName, filePath); + //setChosenGroupAndPeriods(wsName); + } + + QString code; + + code += "g = graph('" + wsName + "-1')\n" + "if g != None:\n" + " g.show()\n" + " g.setFocus()\n" + " selectMultiPeak(g)\n"; + + runPythonCode(code); +} + +/** +* Pass through to selectMultiPeak(wsName, filePath) where filePath is set +* to blank. Enables connection as a slot without Qt understanding. No update +* boost::optional. +* @param wsName Name of the selected workspace +*/ +void MuonAnalysis::selectMultiPeakNoUpdate(const QString &wsName) { + selectMultiPeakNoUpdate(wsName, boost::optional<QString>()); +} + /** * Disable tools for all the graphs within MantidPlot. */ @@ -2620,6 +2673,9 @@ void MuonAnalysis::changeTab(int newTabIndex) { disconnect(m_uiForm.fitBrowser, SIGNAL(workspaceNameChanged(const QString &)), this, SLOT(selectMultiPeak(const QString &))); + disconnect(m_uiForm.fitBrowser, + SIGNAL(TFPlot(const QString &)), this, + SLOT(selectMultiPeakNoUpdate(const QString &))); } if (newTab == m_uiForm.DataAnalysis) // Entering DA tab @@ -2657,7 +2713,8 @@ void MuonAnalysis::changeTab(int newTabIndex) { // to it connect(m_uiForm.fitBrowser, SIGNAL(workspaceNameChanged(const QString &)), this, SLOT(selectMultiPeak(const QString &)), Qt::QueuedConnection); - + connect(m_uiForm.fitBrowser, SIGNAL(TFPlot(const QString &)), + this, SLOT(selectMultiPeakNoUpdate(const QString &)), Qt::QueuedConnection); // repeat setting the fitting ranges as the above code can set them to an // unwanted default value setFittingRanges(xmin, xmax); diff --git a/qt/scientific_interfaces/Muon/MuonAnalysis.h b/qt/scientific_interfaces/Muon/MuonAnalysis.h index abdfd89d39b..38ad81af447 100644 --- a/qt/scientific_interfaces/Muon/MuonAnalysis.h +++ b/qt/scientific_interfaces/Muon/MuonAnalysis.h @@ -209,7 +209,12 @@ private slots: /// Enable PP tool for the plot of the given WS overload to take just a ws void selectMultiPeak(const QString &wsName); + /// Enable PP tool for the plot of the given WS and optional filepath + void selectMultiPeakNoUpdate(const QString &wsName, + const boost::optional<QString> &filePath); + /// Enable PP tool for the plot of the given WS overload to take just a ws + void selectMultiPeakNoUpdate(const QString &wsName); /// Disable tools for all the graphs within MantidPlot void disableAllTools(); diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/MuonFitPropertyBrowser.h b/qt/widgets/common/inc/MantidQtWidgets/Common/MuonFitPropertyBrowser.h index a4108f067c6..3aaf66efbcb 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/MuonFitPropertyBrowser.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/MuonFitPropertyBrowser.h @@ -155,6 +155,7 @@ signals: void reselctGroupClicked(bool enabled); /// Emitted when fit is about to be run void preFitChecksRequested(bool sequential) override; + void TFPlot(QString wsName); protected: void showEvent(QShowEvent *e) override; @@ -200,7 +201,8 @@ private: void addPeriodCheckbox(const QString &name); void updatePeriods(const int j); bool isPeriodValid(const QString &name); - + std::string TFExtension() const; + void updateTFPlot(); /// Splitter for additional widgets and splitter between this and browser QSplitter *m_widgetSplitter, *m_mainSplitter; /// Names of workspaces to fit diff --git a/qt/widgets/common/src/MuonFitPropertyBrowser.cpp b/qt/widgets/common/src/MuonFitPropertyBrowser.cpp index 9b70f839cc1..f4bbf0fc10f 100644 --- a/qt/widgets/common/src/MuonFitPropertyBrowser.cpp +++ b/qt/widgets/common/src/MuonFitPropertyBrowser.cpp @@ -450,7 +450,9 @@ void MuonFitPropertyBrowser::enumChanged(QtProperty *prop) { m_boolManager->setValue(iter.value(), selectedGroup == iter.key()); } } - + //update plot for TF Asymm mode + updateTFPlot(); + } else { FitPropertyBrowser::enumChanged(prop); } @@ -736,6 +738,7 @@ void MuonFitPropertyBrowser::doTFAsymmFit() { } for (int i = 1; i < nWorkspaces; i++) { std::string suffix = boost::lexical_cast<std::string>(i); + alg->setPropertyValue("InputWorkspace_" + suffix, m_workspacesToFit[i]); alg->setProperty("WorkspaceIndex_" + suffix, workspaceIndex()); alg->setProperty("StartX_" + suffix, startX()); @@ -988,10 +991,15 @@ void MuonFitPropertyBrowser::runFit() { alg->setProperty("Function", boost::dynamic_pointer_cast<IFunction>( m_compositeFunction->getFunction(0))); } - if (rawData()) - alg->setPropertyValue("InputWorkspace", wsName + "_Raw"); - else - alg->setPropertyValue("InputWorkspace", wsName); + std::string tmpWSName = wsName; + if (rawData()) { + tmpWSName += "_Raw"; + } + if (m_boolManager->value(m_TFAsymmMode) && tmpWSName.find("_unNorm")) { + tmpWSName += TFExtension(); + } + + alg->setPropertyValue("InputWorkspace", tmpWSName); alg->setProperty("WorkspaceIndex", workspaceIndex()); alg->setProperty("StartX", startX()); alg->setProperty("EndX", endX()); @@ -1001,10 +1009,12 @@ void MuonFitPropertyBrowser::runFit() { // If we are doing a simultaneous fit, set this up here const int nWorkspaces = static_cast<int>(m_workspacesToFit.size()); if (nWorkspaces > 1) { - alg->setPropertyValue("InputWorkspace", m_workspacesToFit[0]); + std::string extension = TFExtension(); + + alg->setPropertyValue("InputWorkspace", m_workspacesToFit[0]+extension); for (int i = 1; i < nWorkspaces; i++) { std::string suffix = boost::lexical_cast<std::string>(i); - alg->setPropertyValue("InputWorkspace_" + suffix, m_workspacesToFit[i]); + alg->setPropertyValue("InputWorkspace_" + suffix, m_workspacesToFit[i]+extension); alg->setProperty("WorkspaceIndex_" + suffix, workspaceIndex()); alg->setProperty("StartX_" + suffix, startX()); alg->setProperty("EndX_" + suffix, endX()); @@ -1022,6 +1032,12 @@ void MuonFitPropertyBrowser::runFit() { } } +std::string MuonFitPropertyBrowser :: TFExtension() const{ + const std::string UNNORM = "_unNorm"; + return (m_boolManager->value(m_TFAsymmMode)) ? UNNORM : ""; + +} + /** * Show sequential fit dialog. */ @@ -1120,6 +1136,7 @@ void MuonFitPropertyBrowser::finishAfterSimultaneousFit( f0Row << "f0=" + fitAlg->getPropertyValue("InputWorkspace") << 0.0 << 0.0; for (int i = 1; i < nWorkspaces; i++) { const std::string suffix = boost::lexical_cast<std::string>(i); + const auto wsName = fitAlg->getPropertyValue("InputWorkspace_" + suffix); Mantid::API::TableRow row = paramTable->appendRow(); @@ -1194,6 +1211,7 @@ std::string MuonFitPropertyBrowser::outputName() const { return SIMULTANEOUS_PREFIX + m_simultaneousLabel; } else { // use parent class behaviour + return FitPropertyBrowser::outputName(); } } @@ -1334,6 +1352,9 @@ void MuonFitPropertyBrowser::setTFAsymmMode(bool enabled) { FitPropertyBrowser::addFunction(func->asString()); } + updateTFPlot(); + //m_enumManager->setValue(m_workspace,j); + } // Show or hide the TFAsymmetry fit if (enabled) { @@ -1349,6 +1370,21 @@ void MuonFitPropertyBrowser::setTFAsymmMode(bool enabled) { } + +/** +* Makes sure we have the TF plot in TFAsymm mode +*/ +void MuonFitPropertyBrowser::updateTFPlot(){ + //update plot + int j = m_enumManager->value(m_workspace); + std::string option = m_workspaceNames[j].toStdString(); + if (m_boolManager->value(m_TFAsymmMode) && option.find("unNorm")==std::string::npos) { + option += TFExtension(); + } + // update plot + emit TFPlot(QString::fromStdString(option)); +} + /** * Adds an extra widget in between the fit buttons and the browser * @param widget :: [input] Pointer to widget to add -- GitLab