Mantid
Loading...
Searching...
No Matches
PlotPeakByLogValue.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
8#include <algorithm>
9#include <boost/algorithm/string/replace.hpp>
10#include <boost/lexical_cast.hpp>
11#include <cmath>
12#include <fstream>
13#include <sstream>
14#include <vector>
15
24#include "MantidAPI/IFunction.h"
26#include "MantidAPI/Progress.h"
27#include "MantidAPI/Run.h"
28#include "MantidAPI/TableRow.h"
37
38namespace {
39Mantid::Kernel::Logger g_log("PlotPeakByLogValue");
40}
41
43
44using namespace Kernel;
45using namespace API;
46
47// Register the class into the algorithm factory
48DECLARE_ALGORITHM(PlotPeakByLogValue)
49
50
53void PlotPeakByLogValue::init() {
54 declareProperty("Input", "", std::make_shared<MandatoryValidator<std::string>>(),
55 "A list of sources of data to fit. \n"
56 "Sources can be either workspace names or file names followed optionally "
57 "by a list of spectra/workspace-indices \n"
58 "or values using the notation described in the description section of "
59 "the help page.");
60
61 declareProperty("Spectrum", 1,
62 "Set a spectrum to fit. \n"
63 "However, if spectra lists (or workspace-indices/values "
64 "lists) are specified in the Input parameter string these "
65 "take precedence.");
66 declareProperty("WorkspaceIndex", 0,
67 "Set a workspace-index to fit (alternative option to Spectrum). "
68 "However, if spectra lists (or workspace-indices/values lists) are "
69 "specified in the Input parameter string, \n"
70 "or the Spectrum parameter integer, these take precedence.");
71 declareProperty(std::make_unique<WorkspaceProperty<ITableWorkspace>>("OutputWorkspace", "", Direction::Output),
72 "The output TableWorkspace");
73 declareProperty(std::make_unique<API::FunctionProperty>("Function", Direction::InOut),
74 "Parameters defining the fitting function and its initial values");
75 declareProperty("LogValue", "",
76 "Name of the log value to plot the "
77 "parameters against. Default: use spectra "
78 "numbers.");
79 declareProperty(std::make_unique<ArrayProperty<double>>("StartX"), "A value of x in, or on the low x "
80 "boundary of, the first bin to "
81 "include in\n"
82 "the fit (default lowest value of x)");
83 declareProperty(std::make_unique<ArrayProperty<double>>("EndX"), "A value in, or on the high x boundary "
84 "of, the last bin the fitting range\n"
85 "(default the highest value of x)");
86
87 std::vector<std::string> fitOptions{"Sequential", "Individual"};
88 declareProperty("FitType", "Sequential", std::make_shared<StringListValidator>(fitOptions),
89 "Defines the way of setting initial values. \n"
90 "If set to 'Sequential' every next fit starts with "
91 "parameters returned by the previous fit. \n"
92 "If set to 'Individual' each fit starts with the same "
93 "initial values defined in the Function property.");
94
95 declareProperty("PassWSIndexToFunction", false,
96 "For each spectrum in Input pass its workspace index to all "
97 "functions that"
98 "have attribute WorkspaceIndex.");
99
100 declareProperty("Minimizer", "Levenberg-Marquardt",
101 "Minimizer to use for fitting. Minimizers available are "
102 "'Levenberg-Marquardt', 'Simplex', 'FABADA',\n"
103 "'Conjugate gradient (Fletcher-Reeves imp.)', 'Conjugate "
104 "gradient (Polak-Ribiere imp.)' and 'BFGS'");
105
106 std::vector<std::string> costFuncOptions = CostFunctionFactory::Instance().getKeys();
107 declareProperty("CostFunction", "Least squares", std::make_shared<StringListValidator>(costFuncOptions),
108 "Cost functions to use for fitting. Cost functions available "
109 "are 'Least squares' and 'Ignore positive peaks'",
111
112 declareProperty("MaxIterations", 500,
113 "Stop after this number of iterations if a good fit is not "
114 "found");
115 declareProperty("PeakRadius", 0,
116 "A value of the peak radius the peak functions should use. A "
117 "peak radius defines an interval on the x axis around the "
118 "centre of the peak where its values are calculated. Values "
119 "outside the interval are not calculated and assumed zeros."
120 "Numerically the radius is a whole number of peak widths "
121 "(FWHM) that fit into the interval on each side from the "
122 "centre. The default value of 0 means the whole x axis.");
123
124 declareProperty("CreateOutput", false,
125 "Set to true to create output "
126 "workspaces with the results of the "
127 "fit(default is false).");
128
129 declareProperty("OutputCompositeMembers", false,
130 "If true and CreateOutput is true then the value of each "
131 "member of a Composite Function is also output.");
132
133 declareProperty(std::make_unique<Kernel::PropertyWithValue<bool>>("ConvolveMembers", false),
134 "If true and OutputCompositeMembers is true members of any "
135 "Convolution are output convolved\n"
136 "with corresponding resolution");
137
138 std::array<std::string, 2> evaluationTypes = {{"CentrePoint", "Histogram"}};
139 declareProperty("EvaluationType", "CentrePoint",
141 "The way the function is evaluated: CentrePoint or Histogram.", Kernel::Direction::Input);
142
143 declareProperty(std::make_unique<ArrayProperty<double>>("Exclude", ""),
144 "A list of pairs of real numbers, defining the regions to "
145 "exclude from the fit for all spectra.");
146
147 declareProperty(std::make_unique<ArrayProperty<std::string>>("ExcludeMultiple", ""),
148 "A list of Exclusion ranges, defining the regions to "
149 "exclude from the fit for each spectra. Must have the "
150 "same number of sets as the number of the spectra.");
151
152 declareProperty("IgnoreInvalidData", false, "Flag to ignore infinities, NaNs and data with zero errors.");
153
154 declareProperty("OutputFitStatus", false,
155 "Flag to output fit status information which consists of the fit "
156 "OutputStatus and the OutputChiSquared");
157}
158
159std::map<std::string, std::string> PlotPeakByLogValue::validateInputs() {
160 std::map<std::string, std::string> errors;
161 std::string inputList = getPropertyValue("Input");
162 int default_wi = getProperty("WorkspaceIndex");
163 int default_spec = getProperty("Spectrum");
164 const std::vector<InputSpectraToFit> wsNames = makeNames(inputList, default_wi, default_spec);
165 std::vector<std::string> excludeList = getProperty("ExcludeMultiple");
166 if (!excludeList.empty() && excludeList.size() != wsNames.size()) {
167 errors["ExcludeMultiple"] = "ExcludeMultiple must be the same size has the number of spectra.";
168 }
169 return errors;
170}
171
175void PlotPeakByLogValue::exec() {
176
177 // Create a list of the input workspace
178 std::string inputList = getPropertyValue("Input");
179 int default_wi = getProperty("WorkspaceIndex");
180 int default_spec = getProperty("Spectrum");
181 const std::vector<InputSpectraToFit> wsNames = makeNames(inputList, default_wi, default_spec);
182
183 std::string logName = getProperty("LogValue");
184 bool individual = getPropertyValue("FitType") == "Individual";
185 bool passWSIndexToFunction = getProperty("PassWSIndexToFunction");
186 bool createFitOutput = getProperty("CreateOutput");
187 bool outputCompositeMembers = getProperty("OutputCompositeMembers");
188 bool outputConvolvedMembers = getProperty("ConvolveMembers");
189 bool outputFitStatus = getProperty("OutputFitStatus");
190 m_baseName = getPropertyValue("OutputWorkspace");
191 std::vector<double> startX = getProperty("StartX");
192 std::vector<double> endX = getProperty("EndX");
193 std::vector<std::string> exclude = getExclude(wsNames.size());
194
195 bool isDataName = false; // if true first output column is of type string and
196 // is the data source name
197 // Create an instance of the fitting function to obtain the names of fitting
198 // parameters
199 IFunction_sptr inputFunction = getProperty("Function");
200 if (!inputFunction) {
201 throw std::invalid_argument("Fitting function failed to initialize");
202 }
203 bool isMultiDomainFunction = std::dynamic_pointer_cast<MultiDomainFunction>(inputFunction) != nullptr;
204
205 IFunction_sptr ifunSingle = isMultiDomainFunction ? inputFunction->getFunction(0) : inputFunction;
206
207 // for inidividual fittings store the initial parameters
208 std::vector<double> initialParams(ifunSingle->nParams());
209 if (individual) {
210 for (size_t i = 0; i < initialParams.size(); ++i) {
211 initialParams[i] = ifunSingle->getParameter(i);
212 }
213 }
214 ITableWorkspace_sptr result = createResultsTable(logName, ifunSingle, isDataName);
215
216 std::vector<MatrixWorkspace_sptr> fitWorkspaces;
217 std::vector<ITableWorkspace_sptr> parameterWorkspaces;
218 std::vector<ITableWorkspace_sptr> covarianceWorkspaces;
219 if (createFitOutput) {
220 covarianceWorkspaces.reserve(wsNames.size());
221 fitWorkspaces.reserve(wsNames.size());
222 parameterWorkspaces.reserve(wsNames.size());
223 }
224
225 std::vector<std::string> fitStatus;
226 std::vector<double> fitChiSquared;
227 if (outputFitStatus) {
228 declareProperty(std::make_unique<ArrayProperty<std::string>>("OutputStatus", Direction::Output));
229 declareProperty(std::make_unique<ArrayProperty<double>>("OutputChiSquared", Direction::Output));
230 fitStatus.reserve(wsNames.size());
231 fitChiSquared.reserve(wsNames.size());
232 }
233
234 double dProg = 1. / static_cast<double>(wsNames.size());
235 double Prog = 0.;
236 for (int i = 0; i < static_cast<int>(wsNames.size()); ++i) {
237 InputSpectraToFit data = wsNames[i];
238
239 if (!data.ws) {
240 g_log.warning() << "Cannot access workspace " << data.name << '\n';
241 continue;
242 }
243
244 if (data.i < 0) {
245 g_log.warning() << "Zero spectra selected for fitting in workspace " << wsNames[i].name << '\n';
246 continue;
247 }
248
249 IFunction_sptr ifun =
250 setupFunction(individual, passWSIndexToFunction, inputFunction, initialParams, isMultiDomainFunction, i, data);
251 std::shared_ptr<Algorithm> fit;
252 if (startX.size() == 0) {
253 fit = runSingleFit(createFitOutput, outputCompositeMembers, outputConvolvedMembers, ifun, data, EMPTY_DBL(),
254 EMPTY_DBL(), exclude[i]);
255 } else if (startX.size() == 1) {
256 fit = runSingleFit(createFitOutput, outputCompositeMembers, outputConvolvedMembers, ifun, data, startX[0],
257 endX[0], exclude[i]);
258 } else {
259 fit = runSingleFit(createFitOutput, outputCompositeMembers, outputConvolvedMembers, ifun, data, startX[i],
260 endX[i], exclude[i]);
261 }
262
263 ifun = fit->getProperty("Function");
264 double chi2 = fit->getProperty("OutputChi2overDoF");
265
266 if (createFitOutput) {
267 MatrixWorkspace_sptr outputFitWorkspace = fit->getProperty("OutputWorkspace");
268 ITableWorkspace_sptr outputParamWorkspace = fit->getProperty("OutputParameters");
269 ITableWorkspace_sptr outputCovarianceWorkspace = fit->getProperty("OutputNormalisedCovarianceMatrix");
270 fitWorkspaces.emplace_back(outputFitWorkspace);
271 parameterWorkspaces.emplace_back(outputParamWorkspace);
272 covarianceWorkspaces.emplace_back(outputCovarianceWorkspace);
273 }
274 if (outputFitStatus) {
275 fitStatus.push_back(fit->getProperty("OutputStatus"));
276 fitChiSquared.push_back(chi2);
277 }
278
279 g_log.debug() << "Fit result " << fit->getPropertyValue("OutputStatus") << ' ' << chi2 << '\n';
280
281 // Find the log value: it is either a log-file value or
282 // simply the workspace number
283 double logValue = calculateLogValue(logName, data);
284 appendTableRow(isDataName, result, ifun, data, logValue, chi2);
285
286 Prog += dProg;
287 std::string current = std::to_string(i);
288 progress(Prog, ("Fitting Workspace: (" + current + ") - "));
290 }
291
292 if (outputFitStatus) {
293 setProperty("OutputStatus", fitStatus);
294 setProperty("OutputChiSquared", fitChiSquared);
295 }
296
297 finaliseOutputWorkspaces(createFitOutput, fitWorkspaces, parameterWorkspaces, covarianceWorkspaces);
298}
299
300IFunction_sptr PlotPeakByLogValue::setupFunction(bool individual, bool passWSIndexToFunction,
301 const IFunction_sptr &inputFunction,
302 const std::vector<double> &initialParams, bool isMultiDomainFunction,
303 int i, const InputSpectraToFit &data) const {
304 IFunction_sptr ifun;
305 if (isMultiDomainFunction) {
306 ifun = inputFunction->getFunction(i);
307 if (!individual && i != 0) {
308 IFunction_sptr prevFunction = inputFunction->getFunction(i - 1);
309 for (size_t k = 0; k < ifun->nParams(); ++k) {
310 ifun->setParameter(k, prevFunction->getParameter(k));
311 }
312 }
313
314 } else {
315 ifun = inputFunction;
316 }
317 if (passWSIndexToFunction) {
318 this->setWorkspaceIndexAttribute(ifun, data.i);
319 }
320
321 if (individual && !isMultiDomainFunction) {
322 for (size_t k = 0; k < initialParams.size(); ++k) {
323 ifun->setParameter(k, initialParams[k]);
324 }
325 }
326 return ifun;
327}
328
329void PlotPeakByLogValue::finaliseOutputWorkspaces(bool createFitOutput,
330 const std::vector<MatrixWorkspace_sptr> &fitWorkspaces,
331 const std::vector<ITableWorkspace_sptr> &parameterWorkspaces,
332 const std::vector<ITableWorkspace_sptr> &covarianceWorkspaces) {
333 if (createFitOutput) {
334 // collect output of fit for each spectrum into workspace groups
335 WorkspaceGroup_sptr covarianceGroup = std::make_shared<WorkspaceGroup>();
336 for (auto const &workspace : covarianceWorkspaces)
337 covarianceGroup->addWorkspace(workspace);
338 AnalysisDataService::Instance().addOrReplace(this->m_baseName + "_NormalisedCovarianceMatrices", covarianceGroup);
339
340 WorkspaceGroup_sptr parameterGroup = std::make_shared<WorkspaceGroup>();
341 for (auto const &workspace : parameterWorkspaces)
342 parameterGroup->addWorkspace(workspace);
343 AnalysisDataService::Instance().addOrReplace(this->m_baseName + "_Parameters", parameterGroup);
344
345 WorkspaceGroup_sptr fitGroup = std::make_shared<WorkspaceGroup>();
346 for (auto const &workspace : fitWorkspaces)
347 fitGroup->addWorkspace(workspace);
348 AnalysisDataService::Instance().addOrReplace(this->m_baseName + "_Workspaces", fitGroup);
349 }
350
351 for (auto &minimizerWorkspace : this->m_minimizerWorkspaces) {
352 const std::string paramName = minimizerWorkspace.first;
353 auto groupAlg = this->createChildAlgorithm("GroupWorkspaces");
354 groupAlg->initialize();
355 groupAlg->setProperty("InputWorkspaces", minimizerWorkspace.second);
356 groupAlg->setProperty("OutputWorkspace", this->m_baseName + "_" + paramName);
357 groupAlg->execute();
358 }
359}
360
361void PlotPeakByLogValue::appendTableRow(
362 bool isDataName, ITableWorkspace_sptr &result, const IFunction_sptr &ifun, const InputSpectraToFit &data,
363 double logValue, double chi2) const { // Extract the fitted parameters and put them into the result table
364 TableRow row = result->appendRow();
365 if (isDataName) {
366 row << data.name;
367 } else {
368 row << logValue;
369 }
370
371 auto p = std::dynamic_pointer_cast<API::CompositeFunction>(ifun);
372 if (p) {
373 for (size_t i = 0; i < p->nFunctions(); ++i) {
374 auto f = ifun->getFunction(i);
375 for (size_t j = 0; j < f->nParams(); ++j) {
376 row << p->getParameter(i, j) << p->getError(i, j);
377 }
378
379 /* Output integrated intensity */
380 auto intensity_handle = std::dynamic_pointer_cast<API::IPeakFunction>(f);
381 if (intensity_handle) {
382 row << intensity_handle->intensity() << intensity_handle->intensityError();
383 }
384 }
385 }
386
387 else {
388 for (size_t iPar = 0; iPar < ifun->nParams(); ++iPar) {
389 row << ifun->getParameter(iPar) << ifun->getError(iPar);
390 }
391
392 /* Output integrated intensity */
393 auto intensity_handle = std::dynamic_pointer_cast<API::IPeakFunction>(ifun);
394 if (intensity_handle) {
395 row << intensity_handle->intensity() << intensity_handle->intensityError();
396 }
397 }
398
399 row << chi2;
400}
401
402ITableWorkspace_sptr PlotPeakByLogValue::createResultsTable(const std::string &logName,
403 const IFunction_sptr &ifunSingle, bool &isDataName) {
404 ITableWorkspace_sptr result = WorkspaceFactory::Instance().createTable("TableWorkspace");
405 if (logName == "SourceName") {
406 result->addColumn("str", "SourceName");
407 isDataName = true;
408 } else if (logName.empty()) {
409 auto col = result->addColumn("double", "axis-1");
410 col->setPlotType(1); // X-values inplots
411 } else {
412 auto col = result->addColumn("double", logName);
413 col->setPlotType(1); // X-values inplots
414 }
415
416 auto p = std::dynamic_pointer_cast<API::CompositeFunction>(ifunSingle);
417 if (p) {
418 for (size_t i = 0; i < p->nFunctions(); ++i) {
419 auto f = ifunSingle->getFunction(i);
420 for (size_t j = 0; j < f->nParams(); ++j) {
421 result->addColumn("double", p->parameterName(i, j));
422 result->addColumn("double", p->parameterName(i, j) + "_Err");
423 }
424
425 auto intensity_handle = std::dynamic_pointer_cast<API::IPeakFunction>(f);
426 if (intensity_handle) {
427 result->addColumn("double", "f" + std::to_string(i) + ".Integrated Intensity");
428 result->addColumn("double", "f" + std::to_string(i) + ".Integrated Intensity_Err");
429 }
430 }
431 }
432
433 else {
434 for (size_t iPar = 0; iPar < ifunSingle->nParams(); ++iPar) {
435 result->addColumn("double", ifunSingle->parameterName(iPar));
436 result->addColumn("double", ifunSingle->parameterName(iPar) + "_Err");
437 }
438
439 auto intensity_handle = std::dynamic_pointer_cast<API::IPeakFunction>(ifunSingle);
440 if (intensity_handle) {
441 result->addColumn("double", "Integrated Intensity");
442 result->addColumn("double", "Integrated Intensity_Err");
443 }
444 }
445
446 result->addColumn("double", "Chi_squared");
447
448 this->setProperty("OutputWorkspace", result);
449 return result;
450}
451
452std::shared_ptr<Algorithm> PlotPeakByLogValue::runSingleFit(bool createFitOutput, bool outputCompositeMembers,
453 bool outputConvolvedMembers, const IFunction_sptr &ifun,
454 const InputSpectraToFit &data, double startX, double endX,
455 const std::string &exclude) {
456 g_log.debug() << "Fitting " << data.ws->getName() << " index " << data.i << " with \n";
457 g_log.debug() << ifun->asString() << '\n';
458
459 const std::string spectrum_index = std::to_string(data.i);
460 std::string wsBaseName;
461
462 if (createFitOutput)
463 wsBaseName = data.name + "_" + spectrum_index;
464 bool histogramFit = this->getPropertyValue("EvaluationType") == "Histogram";
465 bool ignoreInvalidData = this->getProperty("IgnoreInvalidData");
466
467 // Fit the function
468 auto fit = this->createChildAlgorithm("Fit");
469 fit->initialize();
470 fit->setPropertyValue("EvaluationType", this->getPropertyValue("EvaluationType"));
471 fit->setProperty("Function", ifun);
472 fit->setProperty("InputWorkspace", data.ws);
473 fit->setProperty("WorkspaceIndex", data.i);
474 fit->setProperty("StartX", startX);
475 fit->setProperty("EndX", endX);
476 fit->setProperty("IgnoreInvalidData", ignoreInvalidData);
477 fit->setPropertyValue("Minimizer", this->getMinimizerString(data.name, spectrum_index));
478 fit->setPropertyValue("CostFunction", this->getPropertyValue("CostFunction"));
479 fit->setPropertyValue("MaxIterations", this->getPropertyValue("MaxIterations"));
480 fit->setPropertyValue("PeakRadius", this->getPropertyValue("PeakRadius"));
481 fit->setProperty("CalcErrors", true);
482 fit->setProperty("CreateOutput", createFitOutput);
483 if (!histogramFit) {
484 fit->setProperty("OutputCompositeMembers", outputCompositeMembers);
485 fit->setProperty("ConvolveMembers", outputConvolvedMembers);
486 fit->setProperty("Exclude", exclude);
487 }
488 fit->setProperty("Output", wsBaseName);
489 fit->setRethrows(true);
490 fit->execute();
491 return fit;
492}
493
494double PlotPeakByLogValue::calculateLogValue(const std::string &logName, const InputSpectraToFit &data) {
495 double logValue = 0;
496 if (logName.empty() || logName == "axis-1") {
497 API::Axis *axis = data.ws->getAxis(1);
498 if (dynamic_cast<BinEdgeAxis *>(axis)) {
499 double lowerEdge((*axis)(data.i));
500 double upperEdge((*axis)(data.i + 1));
501 logValue = lowerEdge + (upperEdge - lowerEdge) / 2;
502 } else
503 logValue = (*axis)(data.i);
504 } else if (logName != "SourceName") {
505 Kernel::Property *prop = data.ws->run().getLogData(logName);
506 if (!prop) {
507 throw std::invalid_argument("Log value " + logName + " does not exist");
508 }
509 auto *logp = dynamic_cast<TimeSeriesProperty<double> *>(prop);
510 if (!logp) {
511 throw std::runtime_error("Failed to cast " + logName + " to TimeSeriesProperty");
512 }
513 logValue = logp->lastValue();
514 }
515 return logValue;
516}
517
518void PlotPeakByLogValue::setWorkspaceIndexAttribute(const IFunction_sptr &fun, int wsIndex) const {
519 const std::string attName = "WorkspaceIndex";
520 if (fun->hasAttribute(attName)) {
521 fun->setAttributeValue(attName, wsIndex);
522 }
523
524 API::CompositeFunction_sptr cf = std::dynamic_pointer_cast<API::CompositeFunction>(fun);
525 if (cf) {
526 for (size_t i = 0; i < cf->nFunctions(); ++i) {
527 setWorkspaceIndexAttribute(cf->getFunction(i), wsIndex);
528 }
529 }
530}
531
532std::string PlotPeakByLogValue::getMinimizerString(const std::string &wsName, const std::string &wsIndex) {
533 std::string format = getPropertyValue("Minimizer");
534 std::string wsBaseName = wsName + "_" + wsIndex;
535 boost::replace_all(format, "$wsname", wsName);
536 boost::replace_all(format, "$wsindex", wsIndex);
537 boost::replace_all(format, "$basename", wsBaseName);
538 boost::replace_all(format, "$outputname", m_baseName);
539
540 auto minimizer = FuncMinimizerFactory::Instance().createMinimizer(format);
541 auto minimizerProps = minimizer->getProperties();
542 for (auto &minimizerProp : minimizerProps) {
543 auto *wsProp = dynamic_cast<Mantid::API::WorkspaceProperty<> *>(minimizerProp);
544 if (wsProp) {
545 const std::string &wsPropValue = minimizerProp->value();
546 if (!wsPropValue.empty()) {
547 const std::string &wsPropName = minimizerProp->name();
548 m_minimizerWorkspaces[wsPropName].emplace_back(wsPropValue);
549 }
550 }
551 }
552
553 return format;
554}
555
556std::vector<std::string> PlotPeakByLogValue::getExclude(const size_t numSpectra) {
557 std::string exclude = getPropertyValue("Exclude");
558 std::vector<std::string> excludeList = getProperty("ExcludeMultiple");
559 if (excludeList.empty()) {
560 std::vector<std::string> excludeVector;
561 excludeVector.reserve(numSpectra);
562 for (size_t i = 0; i < numSpectra; i++) {
563 excludeVector.emplace_back(exclude);
564 }
565 return excludeVector;
566 } else {
567 return excludeList;
568 }
569}
570
571} // namespace Mantid::CurveFitting::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
virtual 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)
Create a Child Algorithm.
Definition: Algorithm.cpp:842
Kernel::Logger & g_log
Definition: Algorithm.h:451
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Definition: Algorithm.cpp:231
void interruption_point()
This is called during long-running operations, and check if the algorithm has requested that it be ca...
Definition: Algorithm.cpp:1687
Class to represent the axis of a workspace.
Definition: Axis.h:30
Stores numeric values that are assumed to be bin edge values.
Definition: BinEdgeAxis.h:20
TableRow represents a row in a TableWorkspace.
Definition: TableRow.h:39
A property class for workspaces.
std::string value() const override
Returns the value of the property as a string.
Takes a workspace group and fits the same spectrum in all workspaces with the same function.
std::map< std::string, std::vector< std::string > > m_minimizerWorkspaces
Record of workspaces output by the minimizer.
API::IFunction_sptr setupFunction(bool individual, bool passWSIndexToFunction, const API::IFunction_sptr &inputFunction, const std::vector< double > &initialParams, bool isMultiDomainFunction, int i, const InputSpectraToFit &data) const
std::string m_baseName
Base name of output workspace.
double calculateLogValue(const std::string &logName, const InputSpectraToFit &data)
void finaliseOutputWorkspaces(bool createFitOutput, const std::vector< API::MatrixWorkspace_sptr > &fitWorkspaces, const std::vector< API::ITableWorkspace_sptr > &parameterWorkspaces, const std::vector< API::ITableWorkspace_sptr > &covarianceWorkspaces)
std::string getMinimizerString(const std::string &wsName, const std::string &wsIndex)
Create a minimizer string based on template string provided.
API::ITableWorkspace_sptr createResultsTable(const std::string &logName, const API::IFunction_sptr &ifunSingle, bool &isDataName)
std::shared_ptr< Algorithm > runSingleFit(bool createFitOutput, bool outputCompositeMembers, bool outputConvolvedMembers, const API::IFunction_sptr &ifun, const InputSpectraToFit &data, double startX, double endX, const std::string &exclude)
void setWorkspaceIndexAttribute(const API::IFunction_sptr &fun, int wsIndex) const
Set any WorkspaceIndex attributes in the fitting function.
std::vector< std::string > getExclude(const size_t numSpectra)
Create a vector of linked exclude starts and ends.
void appendTableRow(bool isDataName, API::ITableWorkspace_sptr &result, const API::IFunction_sptr &ifun, const InputSpectraToFit &data, double logValue, double chi2) const
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
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...
Definition: ListValidator.h:29
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
void debug(const std::string &msg)
Logs at debug level.
Definition: Logger.cpp:114
void warning(const std::string &msg)
Logs at warning level.
Definition: Logger.cpp:86
Validator to check that a property is not left empty.
The concrete, templated class for properties.
Base class for properties.
Definition: Property.h:94
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
A specialised Property class for holding a series of time-value pairs.
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< CompositeFunction > CompositeFunction_sptr
shared pointer to the composite function base class
MANTID_CURVEFITTING_DLL std::vector< InputSpectraToFit > makeNames(const std::string &inputList, int default_wi, int default_spec)
Create a list of input workspace names.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition: IValidator.h:26
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
Definition: EmptyValues.h:43
std::string to_string(const wide_integer< Bits, Signed > &n)
API::MatrixWorkspace_sptr ws
shared pointer to the workspace
@ InOut
Both an input & output workspace.
Definition: Property.h:55
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54