Mantid
Loading...
Searching...
No Matches
FitPropertyBrowserFindPeaksExt.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2022 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7
10
14
15#include <QEventLoop>
16#include <QHash>
17#include <QString>
18#include <QStringList>
19
21
22using namespace Mantid::API;
23
24void FindPeakConvolveStrategy::initialise(const std::string &wsName, const int workspaceIndex,
25 const std::string &peakListName, const int FWHM,
27 m_peakListName = peakListName;
28 m_FWHM = FWHM;
29 const double peakExtent{m_FWHM * (6.0 / 2.355)}; // Approx convert from FWHM to peak extent, assuming gaussian
30 QHash<QString, QString> defaultValues;
31 defaultValues["InputWorkspace"] = QString::fromStdString(wsName);
32 defaultValues["OutputWorkspace"] = QString::fromStdString(m_peakListName);
33 defaultValues["StartWorkspaceIndex"] = QString::number(workspaceIndex);
34 defaultValues["EndWorkspaceIndex"] = QString::number(workspaceIndex);
35 defaultValues["EstimatedPeakExtent"] = QString::number(peakExtent);
36 const QStringList enabledParams{"EstimatedPeakExtent"};
37 const QStringList disabledParams{"InputWorkspace", "OutputWorkspace", "StartWorkspaceIndex", "EndWorkspaceIndex"};
38 API::InterfaceManager interfaceMgr;
39 m_dlg = interfaceMgr.createDialogFromName("FindPeaksConvolve", -1, nullptr, false, defaultValues, QString(),
40 enabledParams, disabledParams);
41 m_dlg->setShowKeepOpen(false);
43 m_obs = obs;
45}
46
48 m_dlg->show();
49 QEventLoop loop;
50 connect(m_obs, SIGNAL(algCompletedSignal()), &loop, SLOT(quit()));
51 loop.exec();
52
53 Mantid::API::WorkspaceGroup_sptr groupWs = std::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>(
54 Mantid::API::AnalysisDataService::Instance().retrieve(m_peakListName));
55
57 std::dynamic_pointer_cast<Mantid::API::ITableWorkspace>(groupWs->getItem("PeakCentre"));
58 m_peakCentres = std::make_unique<std::vector<double>>();
59 m_peakCentres->reserve(peakCentreWs->columnCount());
60 for (size_t i{1}; i < peakCentreWs->columnCount(); i++) {
61 m_peakCentres->push_back(peakCentreWs->Double(0, i));
62 }
63
65 std::dynamic_pointer_cast<Mantid::API::ITableWorkspace>(groupWs->getItem("PeakYPosition"));
66 m_peakHeights = std::make_unique<std::vector<double>>();
67 m_peakHeights->reserve(peakHeightWs->columnCount());
68 for (size_t i{1}; i < peakHeightWs->columnCount(); i++) {
69 m_peakHeights->push_back(peakHeightWs->Double(0, i));
70 }
71 m_peakWidths = std::make_unique<std::vector<double>>(m_peakCentres->size(), m_FWHM);
72}
73
75 m_alg->execute();
76 Mantid::API::ITableWorkspace_sptr ws = std::dynamic_pointer_cast<Mantid::API::ITableWorkspace>(
77 Mantid::API::AnalysisDataService::Instance().retrieve(m_peakListName));
78
79 m_peakCentres = std::make_unique<Mantid::API::ColumnVector<double>>(ws->getVector("centre"));
80 m_peakWidths = std::make_unique<Mantid::API::ColumnVector<double>>(ws->getVector("width"));
81 m_peakHeights = std::make_unique<Mantid::API::ColumnVector<double>>(ws->getVector("height"));
82}
83
84void FindPeakDefaultStrategy::initialise(const std::string &wsName, const int workspaceIndex,
85 const std::string &peakListName, const int FWHM,
87 UNUSED_ARG(obs);
88 m_peakListName = peakListName;
89 const QString setting =
90 QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("curvefitting.findPeaksTolerance"));
91 const int Tolerance{setting.isEmpty() ? 4 : setting.toInt()};
92
93 m_alg = Mantid::API::AlgorithmManager::Instance().create("FindPeaks");
94 m_alg->initialize();
95 m_alg->setPropertyValue("InputWorkspace", wsName);
96 m_alg->setProperty("WorkspaceIndex", workspaceIndex);
97 m_alg->setPropertyValue("PeaksList", m_peakListName);
98 m_alg->setProperty("FWHM", FWHM);
99 m_alg->setProperty("Tolerance", Tolerance);
100}
101} // namespace MantidQt::MantidWidgets
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition System.h:48
void disableExitButton()
Disable the exit button.
void setShowKeepOpen(const bool showOption)
Set if the keep open option is shown.
void addAlgorithmObserver(Mantid::API::AlgorithmObserver *observer)
Add an AlgorithmObserver to the algorithm.
This class is responsible for creating the correct dialog for an algorithm.
AlgorithmDialog * createDialogFromName(const QString &algorithmName, const int version=-1, QWidget *parent=nullptr, bool forScript=false, const QHash< QString, QString > &presetValues=(QHash< QString, QString >()), const QString &optionalMsg=QString(), const QStringList &enabled=QStringList(), const QStringList &disabled=QStringList())
Create an algorithm dialog for a given name and version.
void initialise(const std::string &wsName, const int workspaceIndex, const std::string &peakListName, const int FWHM, AlgorithmFinishObserver *obs) override
void initialise(const std::string &wsName, const int workspaceIndex, const std::string &peakListName, const int FWHM, AlgorithmFinishObserver *obs) override
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
constexpr double Tolerance
Standard tolerance value.
Definition Tolerance.h:12