15#include <boost/numeric/conversion/cast.hpp>
24using namespace Kernel;
48 "The input workspace used in the fit. Ignored if 'InputWorkspaces' "
49 "property is provided.");
51 "List of the workspaces used in the fit.");
53 "The result group workspace produced in a QENS fit.");
54 declareProperty(
"RenameConvolvedMembers",
false,
55 "If true, renames the n-th 'Convolution' member, to the n-th "
56 "supplied name in the ConvolvedMembers property.");
58 "A list of the names of the members which were convolved "
59 "before being output by the fit routine. These must be "
60 "provided in the same order as originally provided to the "
63 "The output workspace group, containing the fit members.");
67 std::map<std::string, std::string> errors;
68 std::vector<std::string> workspaceNames =
getProperty(
"InputWorkspaces");
71 if (workspaceNames.empty() && !inputWorkspace)
72 errors[
"InputWorkspace"] =
"Neither the InputWorkspace or InputWorkspaces "
73 "property have been defined.";
80 MatrixWorkspace_sptr initialWS = std::dynamic_pointer_cast<MatrixWorkspace>(resultWS->getItem(0));
81 const auto qValues =
getQValues(inputWorkspaces);
84 bool renameConvolved =
getProperty(
"RenameConvolvedMembers");
90 for (
auto i = 1u; i < resultWS->size(); ++i)
91 appendToMembers(std::dynamic_pointer_cast<MatrixWorkspace>(resultWS->getItem(i)), memberWorkspaces);
94 std::string outputWSName =
getProperty(
"OutputWorkspace");
95 auto workspaceNames =
addMembersToADS(members, memberWorkspaces, outputWSName);
100 const std::vector<std::string> workspaceNames =
getProperty(
"InputWorkspaces");
101 std::vector<MatrixWorkspace_sptr> workspaces;
103 if (!workspaceNames.empty()) {
104 workspaces.reserve(workspaceNames.size());
106 std::transform(workspaceNames.cbegin(), workspaceNames.cend(), std::back_inserter(workspaces),
107 [&ADS](
const auto &
name) { return ADS.retrieveWS<MatrixWorkspace>(name); });
109 workspaces.emplace_back(
getProperty(
"InputWorkspace"));
120 std::vector<double> qValues;
122 for (
const auto &
workspace : workspaces) {
124 getQs->setProperty(
"InputWorkspace",
workspace);
125 getQs->executeAsChildAlg();
126 const std::vector<double> values = getQs->getProperty(
"Qvalues");
127 qValues.insert(std::end(qValues), std::begin(values), std::end(values));
141 size_t axisIndex)
const {
142 auto axis =
workspace->getAxis(axisIndex);
143 std::vector<std::string> labels;
144 labels.reserve(axis->length());
146 for (
auto i = 0u; i < axis->length(); ++i)
147 labels.emplace_back(axis->label(i));
160 const std::vector<std::string> &newNames)
const {
161 std::vector<std::string> newMembers;
162 newMembers.reserve(members.size());
165 for (
const auto &member : members) {
166 if (member ==
"Convolution" &&
index < newNames.size())
167 newMembers.emplace_back(newNames[
index++]);
169 newMembers.emplace_back(member);
183 extractAlg->setProperty(
"InputWorkspace", inputWS);
184 extractAlg->setProperty(
"OutputWorkspace",
"__extracted");
185 extractAlg->setProperty(
"StartWorkspaceIndex", boost::numeric_cast<int>(spectrum));
186 extractAlg->setProperty(
"EndWorkspaceIndex", boost::numeric_cast<int>(spectrum));
187 extractAlg->executeAsChildAlg();
188 return extractAlg->getProperty(
"OutputWorkspace");
201 appendAlg->setProperty(
"InputWorkspace1", inputWS);
202 appendAlg->setProperty(
"InputWorkspace2", spectraWorkspace);
203 appendAlg->setProperty(
"OutputWorkspace", inputWS);
204 appendAlg->executeAsChildAlg();
205 return appendAlg->getProperty(
"OutputWorkspace");
216 groupAlg->setProperty(
"InputWorkspaces", workspaceNames);
217 groupAlg->setProperty(
"OutputWorkspace",
"__grouped");
219 return groupAlg->getProperty(
"OutputWorkspace");
231 const std::vector<std::string> &members) {
232 std::vector<MatrixWorkspace_sptr> memberWorkspaces;
233 memberWorkspaces.reserve(members.size());
234 for (
auto i = 0u; i < members.size(); ++i)
236 return memberWorkspaces;
247 std::vector<Mantid::API::MatrixWorkspace_sptr> &members) {
248 for (
auto i = 0u; i < members.size(); ++i)
261 const std::vector<double> &values,
size_t axisIndex)
const {
263 for (
auto i = 0u; i < values.size(); ++i)
264 qAxis.setValue(i, values[i]);
267 workspace->replaceAxis(axisIndex, std::make_unique<NumericAxis>(qAxis));
268 workspace->setYUnitLabel(
"MomentumTransfer");
282std::vector<std::string>
284 const std::vector<Mantid::API::MatrixWorkspace_sptr> &memberWorkspaces,
285 const std::string &outputWSName) {
286 std::unordered_map<std::string, size_t> nameCounts;
287 std::vector<std::string> workspaceNames;
288 workspaceNames.reserve(members.size());
290 for (
auto i = 0u; i < members.size(); ++i) {
291 std::string
count =
"";
293 if (nameCounts.find(members[i]) == nameCounts.end())
294 nameCounts[members[i]] = 1;
298 const auto name = outputWSName +
"_" + members[i] +
count;
300 workspaceNames.emplace_back(
name);
302 return workspaceNames;
#define DECLARE_ALGORITHM(classname)
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1) override
Create a Child Algorithm.
Kernel::IPropertyManager::TypedValue getProperty(const std::string &name) const override
Get the property held by this object.
Class to represent a numeric axis of a workspace.
A property class for workspaces.
Support for a property that holds an array of values.
The Logger class is in charge of the publishing messages from the framework through various channels.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
@ Output
An output workspace.