21#include <boost/cast.hpp>
22#include <boost/regex.hpp>
26#include <unordered_map>
34 return AnalysisDataService::Instance().retrieveWS<
WorkspaceGroup>(workspaceName);
38 return AnalysisDataService::Instance().retrieveWS<
MatrixWorkspace>(workspaceName);
42 auto convSpec = AlgorithmManager::Instance().create(
"ConvertSpectrumAxis");
43 convSpec->setLogging(
false);
44 convSpec->setProperty(
"InputWorkspace", inputWorkspace);
45 convSpec->setProperty(
"OutputWorkspace", outputName);
46 convSpec->setProperty(
"Target",
"ElasticQ");
47 convSpec->setProperty(
"EMode",
"Indirect");
51 return getADSMatrixWorkspace(outputName);
56 AnalysisDataService::Instance().addOrReplace(outputName,
workspace);
57 return std::dynamic_pointer_cast<MatrixWorkspace>(
workspace);
62 auto axis = inputWorkspace->getAxis(1);
63 if (axis->isSpectra())
64 return convertSpectrumAxis(inputWorkspace, outputName);
65 else if (axis->isNumeric()) {
66 if (axis->unit()->unitID() !=
"MomentumTransfer" && doThrow)
67 throw std::runtime_error(
"Input must have axis values of Q");
68 return cloneWorkspace(inputWorkspace, outputName);
70 throw std::runtime_error(
"Input workspace must have either spectra or numeric axis.");
71 return cloneWorkspace(inputWorkspace, outputName);
74struct ElasticQAppender {
75 explicit ElasticQAppender(std::vector<MatrixWorkspace_sptr> &elasticInput)
76 : m_elasticInput(elasticInput), m_converted() {}
79 auto it = m_converted.find(
workspace.get());
80 if (it != m_converted.end())
81 m_elasticInput.emplace_back(it->second);
84 m_elasticInput.emplace_back(elasticQ);
90 std::vector<MatrixWorkspace_sptr> &m_elasticInput;
91 std::unordered_map<MatrixWorkspace *, MatrixWorkspace_sptr> m_converted;
94std::vector<MatrixWorkspace_sptr> convertToElasticQ(
const std::vector<MatrixWorkspace_sptr> &workspaces,
95 const std::string &outputBaseName,
bool doThrow) {
96 std::vector<MatrixWorkspace_sptr> elasticInput;
97 auto appendElasticQWorkspace = ElasticQAppender(elasticInput);
98 appendElasticQWorkspace(workspaces[0], outputBaseName, doThrow);
100 for (
auto i = 1u; i < workspaces.size(); ++i)
101 appendElasticQWorkspace(workspaces[i], outputBaseName, doThrow);
106 for (
auto i = 0u; i < composite->nFunctions(); ++i)
107 names.emplace_back(composite->getFunction(i)->name());
110void extractFunctionNames(
const IFunction_sptr &function, std::vector<std::string> &names) {
111 auto composite = std::dynamic_pointer_cast<CompositeFunction>(function);
113 extractFunctionNames(composite, names);
115 names.emplace_back(function->name());
118void extractConvolvedNames(
const IFunction_sptr &function, std::vector<std::string> &names);
121 for (
auto i = 0u; i < composite->nFunctions(); ++i)
122 extractConvolvedNames(composite->getFunction(i), names);
125void extractConvolvedNames(
const IFunction_sptr &function, std::vector<std::string> &names) {
126 auto composite = std::dynamic_pointer_cast<CompositeFunction>(function);
128 if (composite->name() ==
"Convolution" && composite->nFunctions() > 1 &&
129 composite->getFunction(0)->name() ==
"Resolution")
130 extractFunctionNames(composite->getFunction(1), names);
132 extractConvolvedNames(composite, names);
137 std::ostringstream input;
138 for (
auto i = specMin; i < specMax + 1; ++i)
143std::vector<std::string> extractWorkspaceNames(
const std::string &input) {
144 std::vector<std::string> v;
145 boost::regex reg(
"([^,;]+),");
146 std::for_each(boost::sregex_token_iterator(input.begin(), input.end(), reg, 1), boost::sregex_token_iterator(),
147 [&v](
const std::string &
name) { v.emplace_back(name); });
151std::vector<std::string> getUniqueWorkspaceNames(
const std::string &input) {
152 auto workspaceNames = extractWorkspaceNames(input);
153 std::set<std::string> uniqueNames(workspaceNames.begin(), workspaceNames.end());
154 workspaceNames.assign(uniqueNames.begin(), uniqueNames.end());
155 return workspaceNames;
158std::vector<MatrixWorkspace_sptr> extractWorkspaces(
const std::string &input) {
159 const auto workspaceNames = extractWorkspaceNames(input);
161 std::vector<MatrixWorkspace_sptr> workspaces;
163 std::transform(workspaceNames.begin(), workspaceNames.end(), std::back_inserter(workspaces),
164 [](
const auto &wsName) { return getADSMatrixWorkspace(wsName); });
169std::vector<std::string> getSpectra(
const std::string &input) {
170 std::vector<std::string> spectra;
171 boost::regex reg(
",[i|sp](0|[1-9][0-9]*);?");
172 std::copy(boost::sregex_token_iterator(input.begin(), input.end(), reg, 1), boost::sregex_token_iterator(),
173 std::back_inserter(spectra));
177std::vector<std::string> getSuffices(
const std::string &input) {
178 std::vector<std::string> suffices;
179 boost::regex reg(
",[i|sp](0|[1-9][0-9]*);?");
180 std::copy(boost::sregex_token_iterator(input.begin(), input.end(), reg, 0), boost::sregex_token_iterator(),
181 std::back_inserter(suffices));
185std::string replaceWorkspaces(
const std::string &input,
const std::vector<MatrixWorkspace_sptr> &workspaces) {
186 const auto suffices = getSuffices(input);
187 std::stringstream newInput;
188 for (
auto i = 0u; i < workspaces.size(); ++i)
189 newInput << workspaces[i]->
getName() << suffices[i];
190 return newInput.str();
194 renamer->setProperty(
"InputWorkspace",
workspace);
195 renamer->setProperty(
"OutputWorkspace", newName);
196 renamer->executeAsChildAlg();
199void deleteTemporaries(
const Algorithm_sptr &deleter,
const std::string &base) {
203 while (AnalysisDataService::Instance().doesExist(
name)) {
204 deleter->setProperty(
"Workspace",
name);
205 deleter->executeAsChildAlg();
210std::string shortParameterName(
const std::string &longName) {
211 return longName.substr(longName.rfind(
'.') + 1, longName.size());
215 const auto &first = workspaces.front();
216 return std::any_of(workspaces.cbegin(), workspaces.cend(),
217 [&first](
const auto &
workspace) { return workspace != first; });
220template <
typename F,
typename Renamer>
222 std::unordered_map<std::string, std::size_t> nameCount;
223 for (
auto i = 0u; i < groupWorkspace->size(); ++i) {
227 if (
count == nameCount.end()) {
228 renamer(groupWorkspace->getItem(i),
name);
238 const F &getNameSuffix) {
239 Progress renamerProg(qensFit, 0.98, 1.0, outputGroup->size() + 1);
240 renamerProg.report(
"Renaming group workspaces...");
242 auto getName = [&](std::size_t i) {
return outputBaseName +
"_" + getNameSuffix(i); };
246 renamerProg.report(
"Renamed workspace in group.");
251std::vector<std::size_t> createDatasetGrouping(
const std::vector<MatrixWorkspace_sptr> &workspaces,
252 std::size_t maximum) {
253 std::vector<std::size_t> grouping;
254 grouping.emplace_back(0);
255 for (
auto i = 1u; i < workspaces.size(); ++i) {
256 if (workspaces[i] != workspaces[i - 1])
257 grouping.emplace_back(i);
259 grouping.emplace_back(maximum);
263std::vector<std::size_t> createDatasetGrouping(
const std::vector<MatrixWorkspace_sptr> &workspaces) {
264 return createDatasetGrouping(workspaces, workspaces.size());
275 const std::vector<std::size_t> &grouping) {
276 std::vector<MatrixWorkspace_sptr> results;
277 results.reserve(grouping.size() - 1);
278 for (
auto i = 0u; i < grouping.size() - 1; ++i) {
279 processingAlgorithm.
setProperty(
"StartRowIndex",
static_cast<int>(grouping[i]));
280 processingAlgorithm.
setProperty(
"EndRowIndex",
static_cast<int>(grouping[i + 1]) - 1);
281 processingAlgorithm.
setProperty(
"OutputWorkspace",
"__Result");
283 results.emplace_back(processingAlgorithm.
getProperty(
"OutputWorkspace"));
285 return createGroup(results);
293using namespace Kernel;
302int QENSFitSequential::version()
const {
return 1; }
305const std::string QENSFitSequential::category()
const {
return "Workflow\\MIDAS"; }
308const std::string QENSFitSequential::summary()
const {
return "Performs a sequential fit for QENS data"; }
311const std::vector<std::string> QENSFitSequential::seeAlso()
const {
312 return {
"ConvolutionFitSequential",
"IqtFitSequential",
"PlotPeakByLogValue"};
315void QENSFitSequential::init() {
317 "The input workspace for the fit. This property will be ignored if "
318 "'Input' is provided.");
320 auto boundedV = std::make_shared<BoundedValidator<int>>();
321 boundedV->setLower(0);
323 declareProperty(
"SpecMin", 0, boundedV,
324 "The first spectrum to be used in "
325 "the fit. Spectra values can not be "
326 "negative. This property will be ignored if 'Input' is provided.",
329 declareProperty(
"SpecMax", 0, boundedV,
330 "The final spectrum to be used in "
331 "the fit. Spectra values can not be "
332 "negative. This property will be ignored if 'Input' is provided.",
335 declareProperty(
"Input",
"",
336 "A list of sources of data to fit. \n"
337 "Sources can be either workspace names or file names followed optionally "
338 "by a list of spectra/workspace-indices \n"
339 "or values using the notation described in the description section of "
342 std::vector<std::string> unitOptions = UnitFactory::Instance().getKeys();
343 unitOptions.emplace_back(
"");
344 declareProperty(
"ResultXAxisUnit",
"MomentumTransfer", std::make_shared<StringListValidator>(unitOptions),
345 "The unit to assign to the X Axis of the result workspace, "
346 "defaults to MomentumTransfer");
349 "The output result workspace(s)");
352 "The output parameter workspace");
355 "The output group workspace");
357 declareProperty(std::make_unique<FunctionProperty>(
"Function",
Direction::InOut),
358 "The fitting function, common for all workspaces in the input.");
359 declareProperty(
"LogName",
"axis-1",
360 "Name of the log value to plot the "
361 "parameters against. Default: use spectra "
363 declareProperty(std::make_unique<
ArrayProperty<double>>(
"StartX"),
"A value of x in, or on the low x "
364 "boundary of, the first bin to "
366 "the fit (default lowest value of x)");
367 declareProperty(std::make_unique<
ArrayProperty<double>>(
"EndX"),
"A value in, or on the high x boundary "
368 "of, the last bin the fitting range\n"
369 "(default the highest value of x)");
371 declareProperty(
"PassWSIndexToFunction",
false,
372 "For each spectrum in Input pass its workspace index to all "
374 "have attribute WorkspaceIndex.");
376 declareProperty(
"Minimizer",
"Levenberg-Marquardt",
377 "Minimizer to use for fitting. Minimizers available are "
378 "'Levenberg-Marquardt', 'Simplex', 'FABADA',\n"
379 "'Conjugate gradient (Fletcher-Reeves imp.)', 'Conjugate "
380 "gradient (Polak-Ribiere imp.)' and 'BFGS'");
382 const std::vector<std::string> costFuncOptions = CostFunctionFactory::Instance().getKeys();
383 declareProperty(
"CostFunction",
"Least squares", std::make_shared<StringListValidator>(costFuncOptions),
384 "Cost functions to use for fitting. Cost functions available "
385 "are 'Least squares' and 'Ignore positive peaks'",
388 declareProperty(
"MaxIterations", 500, boundedV,
389 "Stop after this number of iterations if a good fit is not "
391 declareProperty(
"PeakRadius", 0,
392 "A value of the peak radius the peak functions should use. A "
393 "peak radius defines an interval on the x axis around the "
394 "centre of the peak where its values are calculated. Values "
395 "outside the interval are not calculated and assumed zeros."
396 "Numerically the radius is a whole number of peak widths "
397 "(FWHM) that fit into the interval on each side from the "
398 "centre. The default value of 0 means the whole x axis.");
400 declareProperty(
"ExtractMembers",
false,
401 "If true, then each member of the fit will be extracted"
402 ", into their own workspace. These workspaces will have a histogram"
403 " for each spectrum (Q-value) and will be grouped.",
406 declareProperty(
"OutputCompositeMembers",
false,
407 "If true and CreateOutput is true then the value of each "
408 "member of a Composite Function is also output.");
411 "If true and OutputCompositeMembers is true members of any "
412 "Convolution are output convolved\n"
413 "with corresponding resolution");
415 const std::array<std::string, 2> evaluationTypes = {{
"CentrePoint",
"Histogram"}};
416 declareProperty(
"EvaluationType",
"CentrePoint",
420 const std::array<std::string, 2> fitTypes = {{
"Sequential",
"Individual"}};
422 "Defines the way of setting initial values. If set to Sequential every "
423 "next fit starts with parameters returned by the previous fit. If set to "
424 "Individual each fit starts with the same initial values defined in "
425 "the Function property. Allowed values: [Sequential, Individual]",
429 "A list of pairs of real numbers, defining the regions to "
430 "exclude from the fit.");
433 "A list of Exclusion ranges, defining the regions to "
434 "exclude from the fit for each spectra. Must have the "
435 "same number of sets as the number of the spectra.");
437 declareProperty(
"IgnoreInvalidData",
false,
"Flag to ignore infinities, NaNs and data with zero errors.");
439 declareProperty(
"OutputFitStatus",
false,
440 "Flag to output fit status information, which consists of the fit "
441 "OutputStatus and the OutputChiSquared");
444std::map<std::string, std::string> QENSFitSequential::validateInputs() {
445 std::map<std::string, std::string> errors;
450 errors[
"InputWorkspace"] =
"No input string or input workspace was provided.";
454 if (specMin > specMax)
455 errors[
"SpecMin"] =
"SpecMin must be less than or equal to SpecMax.";
460 const auto spectra = getSpectra(inputString);
461 const std::vector<double> startX =
getProperty(
"StartX");
462 const std::vector<double> endX =
getProperty(
"EndX");
463 if (startX.size() != endX.size()) {
464 errors[
"StartX"] =
"StartX have the same size as EndX";
465 }
else if (startX.size() != spectra.size() && startX.size() != 1) {
466 errors[
"StartX"] =
"StartX must be a single value or have a value for each spectra.";
468 for (
size_t i = 0; i < startX.size(); i++) {
469 if (startX[i] >= endX[i]) {
470 errors[
"StartX"] =
"StartX must be less than EndX";
477void QENSFitSequential::exec() {
481 setProperty(
"OutputParameterWorkspace", outputBaseName +
"_Parameters");
484 setProperty(
"OutputWorkspaceGroup", outputBaseName +
"_Workspaces");
489 const auto spectra = getSpectra(inputString);
491 if (workspaces.empty() || spectra.empty() || (workspaces.size() > 1 && workspaces.size() != spectra.size()))
492 throw std::invalid_argument(
"A malformed input string was provided.");
496 const auto groupWs = getADSGroupWorkspace(outputBaseName +
"_Workspaces");
497 AnalysisDataService::Instance().addOrReplace(
getPropertyValue(
"OutputWorkspace"), resultWs);
501 renameWorkspaces(groupWs, spectra, outputBaseName,
"_Workspace", extractWorkspaceNames(inputStringProp));
502 auto inputWorkspaceNames = getUniqueWorkspaceNames(inputStringProp);
503 renameWorkspaces(resultWs, std::vector<std::string>(inputWorkspaceNames.size(),
""), outputBaseName,
"_Result",
504 inputWorkspaceNames);
507 renameWorkspaces(resultWs, std::vector<std::string>({
""}), outputBaseName,
"_Result");
512 const bool doExtractMembers =
getProperty(
"ExtractMembers");
513 if (doExtractMembers)
521 for (
auto results : resultWs->getAllItems()) {
523 std::string resultWsName = results->getName();
524 auto endLoc = resultWsName.find(
"__Result");
525 std::string baseName = resultWsName.erase(endLoc);
526 for (
auto &
workspace : groupWs->getAllItems()) {
527 const std::string wsName =
workspace->getName();
528 if (wsName.find(baseName) != wsName.npos) {
529 copyLogs(std::dynamic_pointer_cast<MatrixWorkspace>(results), groupWs);
537 setProperty(
"OutputWorkspace", resultWs);
538 setProperty(
"OutputParameterWorkspace", parameterWs);
541 for (
auto item : groupWs->getAllItems()) {
542 outGroupWs->addWorkspace(item);
544 setProperty(
"OutputWorkspaceGroup", outGroupWs);
547std::map<std::string, std::string> QENSFitSequential::getAdditionalLogStrings()
const {
548 const bool convolve =
getProperty(
"ConvolveMembers");
549 auto fitProgram =
name();
550 fitProgram = fitProgram.substr(0, fitProgram.rfind(
"Sequential"));
552 auto logs = std::map<std::string, std::string>();
554 logs[
"convolve_members"] = convolve ?
"true" :
"false";
555 logs[
"fit_program"] = fitProgram;
556 logs[
"fit_mode"] =
"Sequential";
560std::map<std::string, std::string> QENSFitSequential::getAdditionalLogNumbers()
const {
561 return std::map<std::string, std::string>();
565 for (
const auto &
workspace : *resultWorkspace)
569void QENSFitSequential::addAdditionalLogs(
const Workspace_sptr &resultWorkspace) {
571 logAdder->setProperty(
"Workspace", resultWorkspace);
572 Progress logAdderProg(
this, 0.99, 1.00, 6);
573 logAdder->setProperty(
"LogType",
"String");
575 logAdder->setProperty(
"LogName", log.first);
576 logAdder->setProperty(
"LogText", log.second);
577 logAdder->executeAsChildAlg();
578 logAdderProg.
report(
"Add text logs");
580 logAdderProg.
report(
"Add number logs");
582 logAdder->setProperty(
"LogName", log.first);
583 logAdder->setProperty(
"LogText", log.second);
584 logAdder->executeAsChildAlg();
585 logAdderProg.
report(
"Add number logs");
591 logAdder->setProperty(
"Workspace", resultWorkspace);
592 Progress logAdderProg(
this, 0.99, 1.00, 6);
593 logAdder->setProperty(
"LogType",
"String");
595 std::vector<double> startX =
getProperty(
"StartX");
596 logAdder->setProperty(
"LogName",
"start_x");
597 if (startX.size() == 1) {
602 logAdder->executeAsChildAlg();
605 logAdder->setProperty(
"LogName",
"end_x");
606 if (endX.size() == 1) {
611 logAdder->executeAsChildAlg();
614std::string QENSFitSequential::getOutputBaseName()
const {
616 const auto position = base.rfind(
"_Result");
622bool QENSFitSequential::throwIfElasticQConversionFails()
const {
return false; }
624bool QENSFitSequential::isFitParameter(
const std::string & )
const {
return true; }
626std::vector<std::string> QENSFitSequential::getFitParameterNames()
const {
628 std::vector<std::string> parameters;
629 parameters.reserve(uniqueParameters.size());
630 std::copy_if(uniqueParameters.begin(), uniqueParameters.end(), std::back_inserter(parameters),
631 [&](
const std::string ¶meter) { return isFitParameter(parameter); });
635std::set<std::string> QENSFitSequential::getUniqueParameterNames()
const {
637 std::set<std::string> nameSet;
638 for (
auto i = 0u; i < function->nParams(); ++i)
639 nameSet.insert(shortParameterName(function->parameterName(i)));
643void QENSFitSequential::deleteTemporaryWorkspaces(
const std::string &outputBaseName) {
645 deleter->setProperty(
"Workspace", outputBaseName +
"_NormalisedCovarianceMatrices");
646 deleter->executeAsChildAlg();
648 deleter->setProperty(
"Workspace", outputBaseName +
"_Parameters");
649 deleter->executeAsChildAlg();
654std::vector<std::size_t>
655QENSFitSequential::getDatasetGrouping(
const std::vector<API::MatrixWorkspace_sptr> &workspaces)
const {
658 return createDatasetGrouping(workspaces,
static_cast<std::size_t
>(maximum + 1));
660 return createDatasetGrouping(workspaces);
664 const std::vector<std::size_t> &grouping) {
665 std::string
const columnX =
getProperty(
"LogName");
666 std::string
const xAxisUnit =
getProperty(
"ResultXAxisUnit");
668 pifp->setAlwaysStoreInADS(
false);
669 pifp->setProperty(
"InputWorkspace", parameterWorkspace);
670 pifp->setProperty(
"ColumnX", columnX);
671 pifp->setProperty(
"XAxisUnit", xAxisUnit);
673 pifp->setProperty(
"IncludeChiSquared",
true);
674 return runParameterProcessingWithGrouping(*pifp, grouping);
678 return parameterTable;
681void QENSFitSequential::renameWorkspaces(
WorkspaceGroup_sptr outputGroup, std::vector<std::string>
const &spectra,
682 std::string
const &outputBaseName, std::string
const &endOfSuffix,
683 std::vector<std::string>
const &inputWorkspaceNames) {
685 const auto getNameSuffix = [&](std::size_t i) {
686 std::string workspaceName = inputWorkspaceNames[i] +
"_" + spectra[i] + endOfSuffix;
687 return workspaceName;
692void QENSFitSequential::renameWorkspaces(
WorkspaceGroup_sptr outputGroup, std::vector<std::string>
const &spectra,
693 std::string
const &outputBaseName, std::string
const &endOfSuffix) {
695 auto getNameSuffix = [&](std::size_t i) {
return spectra[i] + endOfSuffix; };
699void QENSFitSequential::renameGroupWorkspace(std::string
const ¤tName, std::vector<std::string>
const &spectra,
700 std::string
const &outputBaseName, std::string
const &endOfSuffix) {
701 if (AnalysisDataService::Instance().doesExist(currentName)) {
702 auto const group = getADSGroupWorkspace(currentName);
709 const std::vector<double> exclude =
getProperty(
"Exclude");
710 const std::vector<std::string> excludeMultiple =
getProperty(
"ExcludeMultiple");
711 const bool convolveMembers =
getProperty(
"ConvolveMembers");
712 const bool outputCompositeMembers =
getProperty(
"OutputCompositeMembers");
713 const bool passWsIndex =
getProperty(
"PassWSIndexToFunction");
714 const bool ignoreInvalidData =
getProperty(
"IgnoreInvalidData");
715 const bool outputFitStatus =
getProperty(
"OutputFitStatus");
720 plotPeaks->setProperty(
"Input", input);
721 plotPeaks->setProperty(
"OutputWorkspace", output);
722 plotPeaks->setProperty(
"Function", inputFunction);
725 plotPeaks->setProperty(
"Exclude", exclude);
726 plotPeaks->setProperty(
"ExcludeMultiple", excludeMultiple);
727 plotPeaks->setProperty(
"IgnoreInvalidData", ignoreInvalidData);
728 plotPeaks->setProperty(
"FitType",
"Sequential");
729 plotPeaks->setProperty(
"CreateOutput",
true);
730 plotPeaks->setProperty(
"OutputCompositeMembers", outputCompositeMembers);
731 plotPeaks->setProperty(
"ConvolveMembers", convolveMembers);
734 plotPeaks->setProperty(
"PassWSIndexToFunction", passWsIndex);
737 plotPeaks->setProperty(
"EvaluationType",
getPropertyValue(
"EvaluationType"));
740 plotPeaks->setProperty(
"OutputFitStatus", outputFitStatus);
742 plotPeaks->executeAsChildAlg();
744 if (outputFitStatus) {
747 std::vector<std::string> outputStatus = plotPeaks->getProperty(
"OutputStatus");
748 std::vector<double> outputChiSquared = plotPeaks->getProperty(
"OutputChiSquared");
749 setProperty(
"OutputStatus", outputStatus);
750 setProperty(
"OutputChiSquared", outputChiSquared);
753 return plotPeaks->getProperty(
"OutputWorkspace");
756std::string QENSFitSequential::getInputString(
const std::vector<MatrixWorkspace_sptr> &workspaces)
const {
758 if (!inputString.empty())
759 return replaceWorkspaces(inputString, workspaces);
763std::vector<MatrixWorkspace_sptr> QENSFitSequential::getWorkspaces()
const {
765 if (!inputString.empty()) {
766 auto workspaceList = extractWorkspaces(inputString);
767 return workspaceList;
775std::vector<MatrixWorkspace_sptr>
776QENSFitSequential::convertInputToElasticQ(
const std::vector<MatrixWorkspace_sptr> &workspaces)
const {
781 const std::vector<API::MatrixWorkspace_sptr> &workspaces,
782 const std::string &outputWsName) {
783 std::vector<std::string> workspaceNames;
784 std::transform(workspaces.begin(), workspaces.end(), std::back_inserter(workspaceNames),
788 extractAlgorithm->setProperty(
"InputWorkspaces", workspaceNames);
789 extractAlgorithm->execute();
793 std::vector<MatrixWorkspace_sptr>
const &workspaces) {
794 for (
auto const &resultWorkspace : *resultWorkspaces)
795 copyLogs(resultWorkspace, workspaces);
799 std::vector<MatrixWorkspace_sptr>
const &workspaces) {
801 logCopier->setProperty(
"OutputWorkspace", resultWorkspace->getName());
802 for (
auto const &
workspace : workspaces) {
803 logCopier->setProperty(
"InputWorkspace",
workspace);
804 logCopier->executeAsChildAlg();
809 for (
auto const &
workspace : *resultGroup)
815 logCopier->setProperty(
"InputWorkspace", resultWorkspace);
816 logCopier->setProperty(
"OutputWorkspace", resultGroup->getName());
817 logCopier->executeAsChildAlg();
821 const std::string &outputWsName)
const {
822 const bool convolved =
getProperty(
"ConvolveMembers");
823 std::vector<std::string> convolvedMembers;
827 extractConvolvedNames(function, convolvedMembers);
829 auto extractMembersAlg = AlgorithmManager::Instance().create(
"ExtractQENSMembers");
830 extractMembersAlg->setProperty(
"ResultWorkspace", resultGroupWs);
831 extractMembersAlg->setProperty(
"OutputWorkspace", outputWsName);
832 extractMembersAlg->setProperty(
"RenameConvolvedMembers", convolved);
833 extractMembersAlg->setProperty(
"ConvolvedMembers", convolvedMembers);
834 return extractMembersAlg;
837std::string QENSFitSequential::getTemporaryName()
const {
return "__" +
name() +
"_ws"; }
#define DECLARE_ALGORITHM(classname)
IPeaksWorkspace_sptr workspace
void addWorkspace(WorkspaceGroup &self, const boost::python::object &pyobj)
std::string getName(const IMDDimension &self)
Base class from which all concrete algorithm classes should be derived.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
bool execute() override final
The actions to be performed by the algorithm on a dataset.
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.
std::string getPropertyValue(const std::string &name) const override
Get the property held by this object.
Base MatrixWorkspace Abstract Class.
Helper class for reporting progress from algorithms.
Class to hold a set of workspaces.
A property class for workspaces.
QENSFitSequential - Performs a sequential QENS fit.
std::vector< std::size_t > getDatasetGrouping(const std::vector< API::MatrixWorkspace_sptr > &workspaces) const
std::vector< API::MatrixWorkspace_sptr > convertInputToElasticQ(const std::vector< API::MatrixWorkspace_sptr > &workspaces) const
virtual std::map< std::string, std::string > getAdditionalLogNumbers() const
API::IAlgorithm_sptr extractMembersAlgorithm(const API::WorkspaceGroup_sptr &resultGroupWs, const std::string &outputWsName) const
void addFitRangeLogs(const API::Workspace_sptr &resultWorkspace, size_t itter)
void renameWorkspaces(API::WorkspaceGroup_sptr outputGroup, std::vector< std::string > const &spectra, std::string const &outputBaseName, std::string const &endOfSuffix)
std::set< std::string > getUniqueParameterNames() const
std::string getInputString(const std::vector< API::MatrixWorkspace_sptr > &workspaces) const
virtual std::vector< std::string > getFitParameterNames() const
virtual std::vector< API::MatrixWorkspace_sptr > getWorkspaces() const
void renameGroupWorkspace(std::string const ¤tName, std::vector< std::string > const &spectra, std::string const &outputBaseName, std::string const &endOfSuffix)
std::string getTemporaryName() const
void copyLogs(const API::WorkspaceGroup_sptr &resultWorkspaces, std::vector< API::MatrixWorkspace_sptr > const &workspaces)
virtual std::map< std::string, std::string > getAdditionalLogStrings() const
API::WorkspaceGroup_sptr processIndirectFitParameters(const API::ITableWorkspace_sptr ¶meterWorkspace, const std::vector< std::size_t > &grouping)
std::string getOutputBaseName() const
virtual API::ITableWorkspace_sptr processParameterTable(API::ITableWorkspace_sptr parameterTable)
void deleteTemporaryWorkspaces(const std::string &outputBaseName)
const std::string name() const override
Algorithms name for identification.
API::ITableWorkspace_sptr performFit(const std::string &input, const std::string &output)
virtual bool throwIfElasticQConversionFails() const
void addAdditionalLogs(const API::WorkspaceGroup_sptr &resultWorkspace)
void extractMembers(const API::WorkspaceGroup_sptr &resultGroupWs, const std::vector< API::MatrixWorkspace_sptr > &workspaces, const std::string &outputWsName)
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
ListValidator is a validator that requires the value of a property to be one of a defined list of pos...
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
The concrete, templated class for properties.
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
void renameWorkspacesInQENSFit(Algorithm *qensFit, IAlgorithm_sptr renameAlgorithm, const WorkspaceGroup_sptr &outputGroup, std::string const &outputBaseName, std::function< std::string(std::size_t)> const &getNameSuffix)
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
void renameWorkspacesWith(const WorkspaceGroup_sptr &groupWorkspace, std::function< std::string(std::size_t)> const &getName, std::function< void(Workspace_sptr, const std::string &)> const &renamer)
void renameWorkspace(const IAlgorithm_sptr &renamer, const Workspace_sptr &workspace, const std::string &newName)
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
bool containsMultipleData(const std::vector< MatrixWorkspace_sptr > &workspaces)
std::shared_ptr< CompositeFunction > CompositeFunction_sptr
shared pointer to the composite function base class
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ InOut
Both an input & output workspace.
@ Input
An input workspace.
@ Output
An output workspace.