/// Fit the data simultaneously. void MultiDatasetFit::fitSimultaneous() { try { m_uiForm.btnFit->setEnabled(false); auto fun = createFunction(); auto fit = Mantid::API::AlgorithmManager::Instance().create("Fit"); fit->initialize(); fit->setProperty("Function", fun); fit->setPropertyValue("InputWorkspace", getWorkspaceName(0).toStdString()); fit->setProperty("WorkspaceIndex", getWorkspaceIndex(0)); auto range = getFittingRange(0); fit->setProperty("StartX", range.first); fit->setProperty("EndX", range.second); int n = getNumberOfSpectra(); for (int ispec = 1; ispec < n; ++ispec) { std::string suffix = boost::lexical_cast<std::string>(ispec); fit->setPropertyValue("InputWorkspace_" + suffix, getWorkspaceName(ispec).toStdString()); fit->setProperty("WorkspaceIndex_" + suffix, getWorkspaceIndex(ispec)); auto range = getFittingRange(ispec); fit->setProperty("StartX_" + suffix, range.first); fit->setProperty("EndX_" + suffix, range.second); } m_fitOptionsBrowser->copyPropertiesToAlgorithm(*fit); m_outputWorkspaceName = m_fitOptionsBrowser->getProperty("Output"); if (m_outputWorkspaceName.isEmpty()) { m_outputWorkspaceName = "out"; fit->setPropertyValue("Output", m_outputWorkspaceName.toStdString()); m_fitOptionsBrowser->setProperty("Output", "out"); } if (n == 1) { m_outputWorkspaceName += "_Workspace"; } else { m_outputWorkspaceName += "_Workspaces"; } removeOldOutput(); m_fitRunner.reset(new API::AlgorithmRunner()); connect(m_fitRunner.get(), SIGNAL(algorithmComplete(bool)), this, SLOT(finishFit(bool)), Qt::QueuedConnection); m_fitRunner->startAlgorithm(fit); } catch (std::exception &e) { QString mess(e.what()); const int maxSize = 500; if (mess.size() > maxSize) { mess = mess.mid(0, maxSize); mess += "..."; } QMessageBox::critical(this, "MantidPlot - Error", QString("Fit failed:\n\n %1").arg(mess)); m_uiForm.btnFit->setEnabled(true); } }
/// Fit the data sets sequentially if there are no global parameters. void MultiDatasetFit::fitSequential() { try { /// disable button to avoid multiple fit click m_uiForm.btnFit->setEnabled(false); std::ostringstream input; int n = getNumberOfSpectra(); for (int ispec = 0; ispec < n; ++ispec) { input << getWorkspaceName(ispec).toStdString() << ",i" << getWorkspaceIndex(ispec) << ";"; } auto fun = m_functionBrowser->getFunction(); auto fit = Mantid::API::AlgorithmManager::Instance().create("PlotPeakByLogValue"); fit->initialize(); fit->setPropertyValue("Function", fun->asString()); fit->setPropertyValue("Input", input.str()); auto range = getFittingRange(0); fit->setProperty("StartX", range.first); fit->setProperty("EndX", range.second); m_fitOptionsBrowser->copyPropertiesToAlgorithm(*fit); m_outputWorkspaceName = m_fitOptionsBrowser->getProperty("OutputWorkspace") + "_Workspaces"; removeOldOutput(); m_fitRunner.reset(new API::AlgorithmRunner()); connect(m_fitRunner.get(), SIGNAL(algorithmComplete(bool)), this, SLOT(finishFit(bool)), Qt::QueuedConnection); m_fitRunner->startAlgorithm(fit); } catch (std::exception &e) { QString mess(e.what()); const int maxSize = 500; if (mess.size() > maxSize) { mess = mess.mid(0, maxSize); mess += "..."; } QMessageBox::critical( this, "MantidPlot - Error", QString("PlotPeakByLogValue failed:\n\n %1").arg(mess)); m_uiForm.btnFit->setEnabled(true); } }
/// Check that the data sets in the table are valid and remove invalid ones. void DataController::checkSpectra() { QList<int> rows; int nrows = getNumberOfSpectra(); auto &ADS = Mantid::API::AnalysisDataService::Instance(); for (int row = 0; row < nrows; ++row) { auto wsName = getWorkspaceName(row).toStdString(); auto i = getWorkspaceIndex(row); if (!ADS.doesExist(wsName)) { rows.push_back(row); continue; } auto ws = ADS.retrieveWS<Mantid::API::MatrixWorkspace>(wsName); if (!ws || i >= static_cast<int>(ws->getNumberHistograms())) { rows.push_back(row); continue; } } removeSpectra(rows); }