27#include "MantidHistogramData/EstimatePolynomial.h"
28#include "MantidHistogramData/Histogram.h"
29#include "MantidHistogramData/HistogramBuilder.h"
30#include "MantidHistogramData/HistogramIterator.h"
37#include "boost/algorithm/string.hpp"
38#include "boost/algorithm/string/trim.hpp"
43using namespace Algorithms::PeakParameterHelper;
49using Mantid::HistogramData::Histogram;
56const std::string INPUT_WKSP(
"InputWorkspace");
57const std::string OUTPUT_WKSP(
"OutputWorkspace");
58const std::string START_WKSP_INDEX(
"StartWorkspaceIndex");
59const std::string STOP_WKSP_INDEX(
"StopWorkspaceIndex");
60const std::string PEAK_CENTERS(
"PeakCenters");
61const std::string PEAK_CENTERS_WKSP(
"PeakCentersWorkspace");
62const std::string PEAK_FUNC(
"PeakFunction");
63const std::string BACK_FUNC(
"BackgroundType");
64const std::string FIT_WINDOW_LIST(
"FitWindowBoundaryList");
65const std::string FIT_WINDOW_WKSP(
"FitPeakWindowWorkspace");
66const std::string PEAK_WIDTH_PERCENT(
"PeakWidthPercent");
67const std::string PEAK_PARAM_NAMES(
"PeakParameterNames");
68const std::string PEAK_PARAM_VALUES(
"PeakParameterValues");
69const std::string PEAK_PARAM_TABLE(
"PeakParameterValueTable");
70const std::string FIT_FROM_RIGHT(
"FitFromRight");
71const std::string MINIMIZER(
"Minimizer");
72const std::string COST_FUNC(
"CostFunction");
73const std::string MAX_FIT_ITER(
"MaxFitIterations");
74const std::string BACKGROUND_Z_SCORE(
"FindBackgroundSigma");
75const std::string HIGH_BACKGROUND(
"HighBackground");
76const std::string POSITION_TOL(
"PositionTolerance");
77const std::string PEAK_MIN_HEIGHT(
"MinimumPeakHeight");
78const std::string CONSTRAIN_PEAK_POS(
"ConstrainPeakPositions");
79const std::string OUTPUT_WKSP_MODEL(
"FittedPeaksWorkspace");
80const std::string OUTPUT_WKSP_PARAMS(
"OutputPeakParametersWorkspace");
81const std::string OUTPUT_WKSP_PARAM_ERRS(
"OutputParameterFitErrorsWorkspace");
82const std::string RAW_PARAMS(
"RawPeakParameters");
87namespace FitPeaksAlgorithm {
93 if (num_peaks == 0 || num_params == 0)
94 throw std::runtime_error(
"No peak or no parameter error.");
98 m_costs.resize(num_peaks, DBL_MAX);
101 for (
size_t ipeak = 0; ipeak < num_peaks; ++ipeak) {
148 throw std::runtime_error(
"Peak index is out of range.");
157 size_t peak_num_params = fit_functions.
peakfunction->nParams();
158 for (
size_t ipar = 0; ipar < peak_num_params; ++ipar) {
163 for (
size_t ipar = 0; ipar < fit_functions.
bkgdfunction->nParams(); ++ipar) {
178 throw std::runtime_error(
"Peak index is out of range");
179 if (peak_position >= 0.)
180 throw std::runtime_error(
"Can only set negative postion for bad record");
198 : m_fitPeaksFromRight(true), m_fitIterations(50), m_numPeaksToFit(0), m_minPeakHeight(20.), m_bkgdSimga(1.),
199 m_peakPosTolCase234(false) {}
206 "Name of the input workspace for peak fitting.");
209 "Name of the output workspace containing peak centers for "
211 "The output workspace is point data."
212 "Each workspace index corresponds to a spectrum. "
213 "Each X value ranges from 0 to N-1, where N is the number of "
215 "Each Y value is the peak position obtained by peak fitting. "
216 "Negative value is used for error signals. "
217 "-1 for data is zero; -2 for maximum value is smaller than "
218 "specified minimum value."
219 "and -3 for non-converged fitting.");
224 "Last workspace index to fit (which is included). "
225 "If a value larger than the workspace index of last spectrum, "
226 "then the workspace index of last spectrum is used.");
230 "List of peak centers to fit against.");
233 "MatrixWorkspace containing peak centers");
235 const std::string peakcentergrp(
"Peak Positions");
241 declareProperty(PropertyNames::PEAK_FUNC,
"Gaussian", std::make_shared<StringListValidator>(peakNames),
242 "Use of a BackToBackExponential profile is only reccomended if the "
243 "coeficients to calculate A and B are defined in the instrument "
244 "Parameters.xml file.");
245 const vector<string> bkgdtypes{
"Flat",
"Linear",
"Quadratic"};
246 declareProperty(PropertyNames::BACK_FUNC,
"Linear", std::make_shared<StringListValidator>(bkgdtypes),
247 "Type of Background.");
249 const std::string funcgroup(
"Function Types");
256 "List of left boundaries of the peak fitting window corresponding to "
261 "MatrixWorkspace for of peak windows");
263 auto min = std::make_shared<BoundedValidator<double>>();
267 "The estimated peak width as a "
268 "percentage of the d-spacing "
269 "of the center of the peak. Value must be less than 1.");
271 const std::string fitrangeegrp(
"Peak Range Setup");
278 "List of peak parameters' names");
280 "List of peak parameters' value");
283 "Name of the an optional workspace, whose each column "
284 "corresponds to given peak parameter names"
285 ", and each row corresponds to a subset of spectra.");
287 const std::string startvaluegrp(
"Starting Parameters Setup");
294 "Flag for the order to fit peaks. If true, peaks are fitted "
296 "Otherwise peaks are fitted from leftmost.");
301 "Minimizer to use for fitting.");
303 const std::array<string, 2> costFuncOptions = {{
"Least squares",
"Rwp"}};
307 auto min_max_iter = std::make_shared<BoundedValidator<int>>();
308 min_max_iter->setLower(49);
309 declareProperty(PropertyNames::MAX_FIT_ITER, 50, min_max_iter,
"Maximum number of function fitting iterations.");
311 const std::string optimizergrp(
"Optimization Setup");
317 "Multiplier of standard deviations of the variance for convergence of "
318 "peak elimination. Default is 1.0. ");
321 "Flag whether the data has high background comparing to "
322 "peaks' intensities. "
323 "For example, vanadium peaks usually have high background.");
326 "List of tolerance on fitted peak positions against given peak positions."
327 "If there is only one value given, then ");
330 "Minimum peak height such that all the fitted peaks with "
331 "height under this value will be excluded.");
334 "If true peak position will be constrained by estimated positions "
335 "(highest Y value position) and "
336 "the peak width either estimted by observation or calculate.");
341 "Name of the output matrix workspace with fitted peak. "
342 "This output workspace have the same dimesion as the input workspace."
343 "The Y values belonged to peaks to fit are replaced by fitted value. "
344 "Values of estimated background are used if peak fails to be fit.");
348 "Name of table workspace containing all fitted peak parameters.");
354 "Name of workspace containing all fitted peak parameters' fitting error."
355 "It must be used along with FittedPeaksWorkspace and RawPeakParameters "
359 "false generates table with effective centre/width/height "
360 "parameters. true generates a table with peak function "
363 const std::string addoutgrp(
"Analysis");
374 map<std::string, std::string> issues;
377 bool haveCommonPeakParameters(
false);
378 std::vector<string> suppliedParameterNames =
getProperty(PropertyNames::PEAK_PARAM_NAMES);
379 std::vector<double> peakParamValues =
getProperty(PropertyNames::PEAK_PARAM_VALUES);
380 if ((!suppliedParameterNames.empty()) || (!peakParamValues.empty())) {
381 haveCommonPeakParameters =
true;
382 if (suppliedParameterNames.size() != peakParamValues.size()) {
383 issues[PropertyNames::PEAK_PARAM_NAMES] =
"must have same number of values as PeakParameterValues";
384 issues[PropertyNames::PEAK_PARAM_VALUES] =
"must have same number of values as PeakParameterNames";
389 std::string partablename =
getPropertyValue(PropertyNames::PEAK_PARAM_TABLE);
390 if (!partablename.empty()) {
391 if (haveCommonPeakParameters) {
392 const std::string msg =
"Parameter value table and initial parameter "
393 "name/value vectors cannot be given "
395 issues[PropertyNames::PEAK_PARAM_TABLE] = msg;
396 issues[PropertyNames::PEAK_PARAM_NAMES] = msg;
397 issues[PropertyNames::PEAK_PARAM_VALUES] = msg;
405 if (!suppliedParameterNames.empty()) {
411 std::vector<string> functionParameterNames;
413 functionParameterNames.emplace_back(
m_peakFunction->parameterName(i));
417 for (
const auto &
name : suppliedParameterNames) {
418 if (std::find(functionParameterNames.begin(), functionParameterNames.end(),
name) ==
419 functionParameterNames.end()) {
425 std::string msg =
"Specified invalid parameter for peak function";
426 if (haveCommonPeakParameters)
427 issues[PropertyNames::PEAK_PARAM_NAMES] = msg;
429 issues[PropertyNames::PEAK_PARAM_TABLE] = msg;
434 const std::string error_table_name =
getPropertyValue(PropertyNames::OUTPUT_WKSP_PARAM_ERRS);
435 if (!error_table_name.empty()) {
436 const bool use_raw_params =
getProperty(PropertyNames::RAW_PARAMS);
437 if (!use_raw_params) {
438 issues[PropertyNames::OUTPUT_WKSP_PARAM_ERRS] =
"Cannot be used with " + PropertyNames::RAW_PARAMS +
"=False";
439 issues[PropertyNames::RAW_PARAMS] =
440 "Cannot be False with " + PropertyNames::OUTPUT_WKSP_PARAM_ERRS +
" specified";
479 int start_wi =
getProperty(PropertyNames::START_WKSP_INDEX);
486 int stop_wi =
getProperty(PropertyNames::STOP_WKSP_INDEX);
506 throw std::runtime_error(
"number of peaks to fit is zero.");
512 throw std::runtime_error(
"PeakWidthPercent must be less than 1");
550 std::string bkgdname;
551 if (bkgdfunctiontype ==
"Linear")
552 bkgdname =
"LinearBackground";
553 else if (bkgdfunctiontype ==
"Flat") {
554 g_log.
warning(
"There may be problems with Flat background");
555 bkgdname =
"FlatBackground";
557 bkgdname = bkgdfunctiontype;
568 std::string partablename =
getPropertyValue(PropertyNames::PEAK_PARAM_TABLE);
581 }
else if (peakfunctiontype !=
"Gaussian") {
583 g_log.
warning(
"Neither parameter value table nor initial "
584 "parameter name/value vectors is specified. Fitting might "
585 "not be reliable for peak profile other than Gaussian");
597 std::vector<double> peakwindow =
getProperty(PropertyNames::FIT_WINDOW_LIST);
598 std::string peakwindowname =
getPropertyValue(PropertyNames::FIT_WINDOW_WKSP);
604 if ((!peakwindow.empty()) && peakwindowname.empty()) {
610 throw std::invalid_argument(
"Uniform peak range/window requires uniform peak positions.");
613 throw std::invalid_argument(
"Peak window vector must be twice as large as number of peaks.");
618 std::vector<double> peakranges(2);
619 peakranges[0] = peakwindow[i * 2];
620 peakranges[1] = peakwindow[i * 2 + 1];
627 std::stringstream errss;
628 errss <<
"Peak " << i <<
": user specifies an invalid range and peak center against " << peakranges[0] <<
" < "
630 throw std::invalid_argument(errss.str());
634 }
else if (peakwindow.empty() && peakwindowws !=
nullptr) {
645 throw std::invalid_argument(
"Peak window workspace has unmatched number of spectra");
648 size_t window_index_start(0);
651 size_t center_index_start(0);
659 std::stringstream errss;
660 errss <<
"Peak window workspace index " << wi <<
" has incompatible number of fit windows (x2) "
662 throw std::invalid_argument(errss.str());
667 size_t window_index = window_index_start + wi;
668 size_t center_index = window_index - center_index_start;
672 double left_w_bound = peakWindowX[ipeak * 2];
673 double right_w_bound = peakWindowX[ipeak * 2 + 1];
674 double center = peakCenterX[ipeak];
675 if (!(left_w_bound < center && center < right_w_bound)) {
676 std::stringstream errss;
677 errss <<
"Workspace index " << wi <<
" has incompatible peak window ("
678 << left_w_bound <<
", " << right_w_bound <<
") with " << ipeak <<
"-th expected peak's center "
680 throw std::runtime_error(errss.str());
684 }
else if (peakwindow.empty()) {
690 throw std::invalid_argument(
"Without definition of peak window, the "
691 "input workspace must be in unit of dSpacing "
692 "and Delta(D)/D must be given!");
696 throw std::invalid_argument(
"One and only one of peak window array and "
697 "peak window workspace can be specified.");
717 g_log.
notice(
"Peak centers are not specified by peak center workspace");
719 std::string peakpswsname =
getPropertyValue(PropertyNames::PEAK_CENTERS_WKSP);
725 }
else if (
m_peakCenters.empty() && peakcenterws !=
nullptr) {
736 if (peak_center_ws_spectra_number ==
m_inputMatrixWS->getNumberHistograms()) {
744 g_log.
error() <<
"Peak center workspace has " << peak_center_ws_spectra_number <<
" spectra;"
745 <<
"Input workspace has " <<
m_inputMatrixWS->getNumberHistograms() <<
" spectra;"
747 <<
". They are mismatched to each other.\n";
748 throw std::invalid_argument(
"Input peak center workspace has mismatched "
749 "number of spectra to selected spectra to "
754 std::stringstream errss;
755 errss <<
"One and only one in 'PeakCenters' (vector) and "
756 "'PeakCentersWorkspace' shall be given. "
757 <<
"'PeakCenters' has size " <<
m_peakCenters.size() <<
", and name of peak center workspace "
758 <<
"is " << peakpswsname;
759 throw std::invalid_argument(errss.str());
774 throw std::runtime_error(
"ProcessInputPeakTolerance() must be called after "
775 "ProcessInputPeakCenters()");
792 throw std::runtime_error(
"Number of peak position tolerances and number of "
793 "peaks to fit are inconsistent.");
812 std::map<std::string, size_t> parname_index_map;
813 for (
size_t iparam = 0; iparam <
m_peakFunction->nParams(); ++iparam)
814 parname_index_map.insert(std::make_pair(
m_peakFunction->parameterName(iparam), iparam));
822 auto locator = parname_index_map.find(paramName);
823 if (locator != parname_index_map.end()) {
829 <<
" is not an allowed parameter of peak "
848 std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> fit_result_vector(num_fit_result);
851 size_t chunkSize = num_fit_result / nThreads;
853 PRAGMA_OMP(parallel
for schedule(dynamic, 1) )
854 for (
int ithread = 0; ithread < nThreads; ithread++) {
860 std::vector<std::vector<double>> lastGoodPeakParameters(
m_numPeaksToFit,
863 for (
auto wi = iws_begin; wi < iws_end; ++wi) {
869 std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> fit_result =
870 std::make_shared<FitPeaksAlgorithm::PeakFitResult>(
m_numPeaksToFit, numfuncparams);
872 fitSpectrumPeaks(
static_cast<size_t>(wi), expected_peak_centers, fit_result, lastGoodPeakParameters);
875 writeFitResult(
static_cast<size_t>(wi), expected_peak_centers, fit_result);
884 return fit_result_vector;
889std::vector<std::string> supported_peak_profiles{
"Gaussian",
"Lorentzian",
"PseudoVoigt",
"Voigt",
890 "BackToBackExponential"};
892double numberCounts(
const Histogram &histogram) {
894 for (
const auto &
value : histogram.y())
895 total += std::fabs(
value);
906double numberCounts(
const Histogram &histogram,
const double xmin,
const double xmax) {
907 const auto &vector_x = histogram.points();
910 auto start_iter = vector_x.begin();
911 if (xmin > vector_x.front())
912 start_iter = std::lower_bound(vector_x.begin(), vector_x.end(), xmin);
913 if (start_iter == vector_x.end())
916 auto stop_iter = vector_x.end();
917 if (xmax < vector_x.back())
918 stop_iter = std::lower_bound(start_iter, stop_iter, xmax);
921 size_t start_index =
static_cast<size_t>(start_iter - vector_x.begin());
922 size_t stop_index =
static_cast<size_t>(stop_iter - vector_x.begin());
926 for (
size_t i = start_index; i < stop_index; ++i)
927 total += std::fabs(histogram.y()[i]);
936 const std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> &fit_result,
937 std::vector<std::vector<double>> &lastGoodPeakParameters) {
940 for (
size_t i = 0; i < fit_result->getNumberPeaks(); ++i)
941 fit_result->setBadRecord(i, -1.);
950 std::stringstream errss;
951 errss <<
"The FitPeak algorithm requires the CurveFitting library";
953 throw std::runtime_error(errss.str());
960 peak_fitter->setProperty(
"Minimizer",
m_minimizer);
962 peak_fitter->setProperty(
"CalcErrors",
true);
969 bool neighborPeakSameSpectrum =
false;
973 size_t peak_index(fit_index);
978 for (
size_t i = 0; i < bkgdfunction->nParams(); ++i)
979 bkgdfunction->setParameter(i, 0.);
981 double expected_peak_pos = expected_peak_centers[peak_index];
985 auto peakfunction = std::dynamic_pointer_cast<API::IPeakFunction>(
m_peakFunction->clone());
986 peakfunction->setCentre(expected_peak_pos);
989 std::map<size_t, double> keep_values;
990 for (
size_t ipar = 0; ipar < peakfunction->nParams(); ++ipar) {
991 if (peakfunction->isFixed(ipar)) {
995 keep_values[ipar] = peakfunction->getParameter(ipar);
998 peakfunction->unfix(ipar);
1004 bool samePeakCrossSpectrum = (lastGoodPeakParameters[peak_index].size() >
1005 static_cast<size_t>(std::count_if(lastGoodPeakParameters[peak_index].begin(),
1006 lastGoodPeakParameters[peak_index].end(),
1007 [&](
auto const &val) {
return val <= 1e-10; })));
1012 if (wi > 0 && samePeakCrossSpectrum) {
1015 std::shared_ptr<const Geometry::Detector> pdetector =
1016 std::dynamic_pointer_cast<const Geometry::Detector>(
m_inputMatrixWS->getDetector(wi - 1));
1017 std::shared_ptr<const Geometry::Detector> cdetector =
1018 std::dynamic_pointer_cast<const Geometry::Detector>(
m_inputMatrixWS->getDetector(wi));
1021 if (pdetector && cdetector) {
1022 auto prev_id = pdetector->getID();
1023 auto curr_id = cdetector->getID();
1024 if (prev_id + 1 != curr_id)
1025 samePeakCrossSpectrum =
false;
1027 samePeakCrossSpectrum =
false;
1033 samePeakCrossSpectrum =
false;
1035 }
catch (
const std::runtime_error &) {
1038 samePeakCrossSpectrum =
false;
1042 if (samePeakCrossSpectrum) {
1044 for (
size_t i = 0; i < peakfunction->nParams(); ++i) {
1045 peakfunction->setParameter(i, lastGoodPeakParameters[peak_index][i]);
1047 }
else if (neighborPeakSameSpectrum) {
1049 for (
size_t i = 0; i < peakfunction->nParams(); ++i) {
1050 peakfunction->setParameter(i, lastGoodPeakParameters[prev_peak_index][i]);
1055 peakfunction->setCentre(expected_peak_pos);
1057 for (
const auto &[ipar,
value] : keep_values) {
1058 peakfunction->setParameter(ipar,
value);
1061 double cost(DBL_MAX);
1062 if (expected_peak_pos <= x0 || expected_peak_pos >= xf) {
1064 peakfunction->setIntensity(0);
1067 std::pair<double, double> peak_window_i =
getPeakFitWindow(wi, peak_index);
1074 auto useUserSpecifedIfGiven = !(samePeakCrossSpectrum || neighborPeakSameSpectrum);
1078 g_log.
warning(
"Peak width can be estimated as ZERO. The result can be wrong");
1083 cost =
fitIndividualPeak(wi, peak_fitter, expected_peak_pos, peak_window_i, observe_peak_width, peakfunction,
1097 neighborPeakSameSpectrum =
true;
1098 prev_peak_index = peak_index;
1100 for (
size_t i = 0; i < lastGoodPeakParameters[peak_index].size(); ++i) {
1101 lastGoodPeakParameters[peak_index][i] = peakfunction->getParameter(i);
1126 if (firstPeakInSpectrum) {
1132 peak_function->setParameter(param_index, param_value);
1140 observe_peak_shape =
true;
1143 return observe_peak_shape;
1159 const std::vector<double> &expected_peak_positions,
1161 const std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> &fit_result) {
1163 double postol(DBL_MAX);
1177 throw std::runtime_error(
"Peak tolerance out of index");
1185 bool good_fit(
false);
1186 if ((cost < 0) || (cost >= DBL_MAX - 1.) || std::isnan(cost)) {
1192 }
else if (case23) {
1194 std::pair<double, double> fitwindow =
getPeakFitWindow(wsindex, peakindex);
1195 if (fitwindow.first < fitwindow.second) {
1198 if (peak_pos < fitwindow.first || peak_pos > fitwindow.second) {
1201 g_log.
debug() <<
"Peak position " << peak_pos <<
" is out of fit "
1202 <<
"window boundary " << fitwindow.first <<
", " << fitwindow.second <<
"\n";
1203 }
else if (peak_fwhm > (fitwindow.second - fitwindow.first)) {
1206 g_log.
debug() <<
"Peak position " << peak_pos <<
" has fwhm "
1207 <<
"wider than the fit window " << fitwindow.second - fitwindow.first <<
"\n";
1213 double left_bound(-1);
1215 left_bound = 0.5 * (expected_peak_positions[peakindex] - expected_peak_positions[peakindex - 1]);
1216 double right_bound(-1);
1218 right_bound = 0.5 * (expected_peak_positions[peakindex + 1] - expected_peak_positions[peakindex]);
1220 left_bound = right_bound;
1221 if (right_bound < left_bound)
1222 right_bound = left_bound;
1223 if (left_bound < 0 || right_bound < 0)
1224 throw std::runtime_error(
"Code logic error such that left or right "
1225 "boundary of peak position is negative.");
1226 if (peak_pos < left_bound || peak_pos > right_bound) {
1228 }
else if (peak_fwhm > (right_bound - left_bound)) {
1231 g_log.
debug() <<
"Peak position " << peak_pos <<
" has fwhm "
1232 <<
"wider than the fit window " << right_bound - left_bound <<
"\n";
1237 }
else if (
fabs(fitfunction.
peakfunction->centre() - expected_peak_positions[peakindex]) > postol) {
1241 <<
fabs(fitfunction.
peakfunction->centre() - expected_peak_positions[peakindex])
1242 <<
" is out of range of tolerance: " << postol <<
"\n";
1249 double adjust_cost(cost);
1252 adjust_cost = DBL_MAX;
1256 if (adjust_cost > DBL_MAX - 1) {
1261 fit_result->setRecord(peakindex, adjust_cost, peak_pos, fitfunction);
1275 throw std::runtime_error(
"No parameters");
1287 std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> fit_result_i = fit_results[iws -
m_startWorkspaceIndex];
1290 throw std::runtime_error(
"There is something wroing with PeakFitResult vector!");
1294 const double chi2 = fit_result_i->getCost(ipeak);
1298 for (
size_t iparam = 0; iparam < num_peakfunc_params; ++iparam)
1299 peak_function->setParameter(iparam, fit_result_i->getParameterValue(ipeak, iparam));
1300 for (
size_t iparam = 0; iparam < num_bkgdfunc_params; ++iparam)
1301 bkgd_function->setParameter(iparam, fit_result_i->getParameterValue(ipeak, num_peakfunc_params + iparam));
1304 const auto &vec_x =
m_fittedPeakWS->points(
static_cast<size_t>(iws));
1305 std::pair<double, double> peakwindow =
getPeakFitWindow(
static_cast<size_t>(iws), ipeak);
1306 auto start_x_iter = std::lower_bound(vec_x.begin(), vec_x.end(), peakwindow.first);
1307 auto stop_x_iter = std::lower_bound(vec_x.begin(), vec_x.end(), peakwindow.second);
1309 if (start_x_iter == stop_x_iter)
1310 throw std::runtime_error(
"Range size is zero in calculateFittedPeaks");
1315 comp_func->addFunction(peak_function);
1316 comp_func->addFunction(bkgd_function);
1317 comp_func->function(domain, values);
1320 size_t istart =
static_cast<size_t>(start_x_iter - vec_x.begin());
1321 size_t istop =
static_cast<size_t>(stop_x_iter - vec_x.begin());
1322 for (
size_t yindex = istart; yindex < istop; ++yindex) {
1333double estimateBackgroundParameters(
const Histogram &histogram,
const std::pair<size_t, size_t> &peak_window,
1337 const auto POLYNOMIAL_ORDER = std::min<size_t>(1, bkgd_function->nParams());
1339 if (peak_window.first >= peak_window.second)
1340 throw std::runtime_error(
"Invalid peak window");
1343 const auto nParams = bkgd_function->nParams();
1344 for (
size_t i = 0; i < nParams; ++i)
1345 bkgd_function->setParameter(i, 0.);
1348 const size_t iback_start = peak_window.first + 10;
1349 const size_t iback_stop = peak_window.second - 10;
1351 double chisq{DBL_MAX};
1356 if (iback_start < iback_stop) {
1360 HistogramData::estimateBackground(POLYNOMIAL_ORDER, histogram, peak_window.first, peak_window.second, iback_start,
1361 iback_stop, bkgd_a0, bkgd_a1, bkgd_a2, chisq);
1363 bkgd_function->setParameter(0, bkgd_a0);
1365 bkgd_function->setParameter(1, bkgd_a1);
1380 return (std::find(supported_peak_profiles.begin(), supported_peak_profiles.end(), peakprofile) !=
1381 supported_peak_profiles.end());
1389 constexpr size_t MIN_POINTS{10};
1393 size_t start_index =
findXIndex(points.rawData(), fit_window.first);
1394 size_t expected_peak_index =
findXIndex(points.rawData(), expected_peak_pos, start_index);
1395 size_t stop_index =
findXIndex(points.rawData(), fit_window.second, expected_peak_index);
1398 bool good_fit(
false);
1399 if (expected_peak_index - start_index > MIN_POINTS && stop_index - expected_peak_index > MIN_POINTS) {
1402 const std::pair<double, double> vec_min{fit_window.first, points[expected_peak_index + 5]};
1403 const std::pair<double, double> vec_max{points[expected_peak_index - 5], fit_window.second};
1406 for (
size_t n = 0;
n < bkgd_func->nParams(); ++
n)
1407 bkgd_func->setParameter(
n, 0);
1412 if (chi2 < DBL_MAX - 1) {
1420 g_log.
debug() <<
"Don't know what to do with background fitting with single "
1421 <<
"domain function! " << (expected_peak_index - start_index) <<
" points to the left "
1422 << (stop_index - expected_peak_index) <<
" points to the right\n";
1432 const std::pair<double, double> &fitwindow,
const bool estimate_peak_width,
1435 double cost(DBL_MAX);
1448 estimate_peak_width,
true);
1463 const std::pair<double, double> &peak_range,
const double &expected_peak_center,
1464 bool estimate_peak_width,
bool estimate_background) {
1465 std::stringstream errorid;
1466 errorid <<
"(WorkspaceIndex=" << wsindex <<
" PeakCentre=" << expected_peak_center <<
")";
1469 if (peak_range.first >= peak_range.second) {
1470 std::stringstream msg;
1471 msg <<
"Invalid peak window: xmin>xmax (" << peak_range.first <<
", " << peak_range.second <<
")" << errorid.str();
1472 throw std::runtime_error(msg.str());
1476 const auto &histogram = dataws->histogram(wsindex);
1477 const auto &vector_x = histogram.points();
1478 const auto start_index =
findXIndex(vector_x, peak_range.first);
1479 const auto stop_index =
findXIndex(vector_x, peak_range.second, start_index);
1480 if (start_index == stop_index)
1481 throw std::runtime_error(
"Range size is zero in estimatePeakParameters");
1482 std::pair<size_t, size_t> peak_window = std::make_pair(start_index, stop_index);
1485 if (estimate_background) {
1486 estimateBackgroundParameters(histogram, peak_window, bkgd_function);
1490 peak_function->setCentre(expected_peak_center);
1491 int result =
estimatePeakParameters(histogram, peak_window, peak_function, bkgd_function, estimate_peak_width,
1493 if (result !=
GOOD) {
1494 peak_function->setCentre(expected_peak_center);
1502 comp_func->addFunction(peak_function);
1503 comp_func->addFunction(bkgd_function);
1504 IFunction_sptr fitfunc = std::dynamic_pointer_cast<IFunction>(comp_func);
1507 fit->setProperty(
"Function", fitfunc);
1508 fit->setProperty(
"InputWorkspace", dataws);
1509 fit->setProperty(
"WorkspaceIndex",
static_cast<int>(wsindex));
1511 fit->setProperty(
"StartX", peak_range.first);
1512 fit->setProperty(
"EndX", peak_range.second);
1513 fit->setProperty(
"IgnoreInvalidData",
true);
1517 double peak_center = peak_function->centre();
1518 double peak_width = peak_function->fwhm();
1519 std::stringstream peak_center_constraint;
1520 peak_center_constraint << (peak_center - 0.5 * peak_width) <<
" < f0." << peak_function->getCentreParameterName()
1521 <<
" < " << (peak_center + 0.5 * peak_width);
1524 fit->setProperty(
"Constraints", peak_center_constraint.str());
1528 g_log.
debug() <<
"[E1201] FitSingleDomain Before fitting, Fit function: " << fit->asString() <<
"\n";
1529 errorid <<
" starting function [" << comp_func->asString() <<
"]";
1532 g_log.
debug() <<
"[E1202] FitSingleDomain After fitting, Fit function: " << fit->asString() <<
"\n";
1534 if (!fit->isExecuted()) {
1535 g_log.
warning() <<
"Fitting peak SD (single domain) failed to execute. " + errorid.str();
1538 }
catch (std::invalid_argument &e) {
1539 errorid <<
": " << e.what();
1545 std::string fitStatus = fit->getProperty(
"OutputStatus");
1546 double chi2{std::numeric_limits<double>::max()};
1547 if (fitStatus ==
"success") {
1548 chi2 = fit->getProperty(
"OutputChi2overDoF");
1556 const size_t wsindex,
const std::pair<double, double> &vec_xmin,
1557 const std::pair<double, double> &vec_xmax) {
1563 std::stringstream errss;
1564 errss <<
"The FitPeak algorithm requires the CurveFitting library";
1565 throw std::runtime_error(errss.str());
1570 fit->setProperty(
"CalcErrors",
true);
1574 std::shared_ptr<MultiDomainFunction> md_function = std::make_shared<MultiDomainFunction>();
1577 md_function->addFunction(std::move(fit_function));
1580 md_function->clearDomainIndices();
1581 md_function->setDomainIndices(0, {0, 1});
1584 fit->setProperty(
"Function", std::dynamic_pointer_cast<IFunction>(md_function));
1585 fit->setProperty(
"InputWorkspace", dataws);
1586 fit->setProperty(
"WorkspaceIndex",
static_cast<int>(wsindex));
1587 fit->setProperty(
"StartX", vec_xmin.first);
1588 fit->setProperty(
"EndX", vec_xmax.first);
1589 fit->setProperty(
"InputWorkspace_1", dataws);
1590 fit->setProperty(
"WorkspaceIndex_1",
static_cast<int>(wsindex));
1591 fit->setProperty(
"StartX_1", vec_xmin.second);
1592 fit->setProperty(
"EndX_1", vec_xmax.second);
1594 fit->setProperty(
"IgnoreInvalidData",
true);
1598 if (!fit->isExecuted()) {
1599 throw runtime_error(
"Fit is not executed on multi-domain function/data. ");
1603 std::string fitStatus = fit->getProperty(
"OutputStatus");
1605 double chi2 = DBL_MAX;
1606 if (fitStatus ==
"success") {
1607 chi2 = fit->getProperty(
"OutputChi2overDoF");
1616 const size_t &ws_index,
const double &expected_peak_center,
1626 fitBackground(ws_index, fit_window, expected_peak_center, high_bkgd_function);
1629 std::vector<double> vec_x, vec_y, vec_e;
1630 getRangeData(ws_index, fit_window, vec_x, vec_y, vec_e);
1634 for (
size_t n = 0;
n < bkgdfunc->nParams(); ++
n)
1635 bkgdfunc->setParameter(
n, 0);
1641 fitFunctionSD(fit, peakfunction, bkgdfunc, reduced_bkgd_ws, 0, {vec_x.front(), vec_x.back()}, expected_peak_center,
1642 observe_peak_shape,
false);
1645 bkgdfunc->setParameter(0, bkgdfunc->getParameter(0) + high_bkgd_function->getParameter(0));
1646 bkgdfunc->setParameter(1, bkgdfunc->getParameter(1) +
1647 high_bkgd_function->getParameter(1));
1650 expected_peak_center,
false,
false);
1658 const std::vector<double> &vec_y,
1659 const std::vector<double> &vec_e) {
1660 size_t size = vec_x.size();
1661 size_t ysize = vec_y.size();
1663 HistogramBuilder builder;
1665 builder.setY(ysize);
1668 auto &dataX = matrix_ws->mutableX(0);
1669 auto &dataY = matrix_ws->mutableY(0);
1670 auto &dataE = matrix_ws->mutableE(0);
1672 dataX.assign(vec_x.cbegin(), vec_x.cend());
1673 dataY.assign(vec_y.cbegin(), vec_y.cend());
1674 dataE.assign(vec_e.cbegin(), vec_e.cend());
1688 for (
size_t wi = 0; wi < num_hist; ++wi) {
1708 const std::vector<std::string> ¶m_names,
bool with_chi2) {
1711 table_ws->addColumn(
"int",
"wsindex");
1712 table_ws->addColumn(
"int",
"peakindex");
1713 for (
const auto ¶m_name : param_names)
1714 table_ws->addColumn(
"double", param_name);
1716 table_ws->addColumn(
"double",
"chi2");
1723 newRow << static_cast<int>(iws);
1724 newRow << static_cast<int>(ipeak);
1725 for (
size_t iparam = 0; iparam < numParam; ++iparam)
1746 std::vector<std::string> param_vec;
1750 param_vec.emplace_back(
"centre");
1751 param_vec.emplace_back(
"width");
1752 param_vec.emplace_back(
"height");
1753 param_vec.emplace_back(
"intensity");
1756 for (
size_t iparam = 0; iparam <
m_bkgdFunction->nParams(); ++iparam)
1764 std::string fiterror_table_name =
getPropertyValue(PropertyNames::OUTPUT_WKSP_PARAM_ERRS);
1766 if (fiterror_table_name.empty()) {
1784 std::string fit_ws_name =
getPropertyValue(PropertyNames::OUTPUT_WKSP_MODEL);
1785 if (fit_ws_name.size() == 0) {
1810 g_log.
debug(
"about to calcualte fitted peaks");
1821 std::stringstream errss;
1824 throw std::runtime_error(errss.str());
1851 std::stringstream errss;
1854 throw std::runtime_error(errss.str());
1859 std::stringstream errss;
1860 errss <<
"Peak index " << ipeak <<
" is out of range (" <<
m_numPeaksToFit <<
")";
1861 throw std::runtime_error(errss.str());
1872 left = peak_pos - estimate_peak_width * MAGIC;
1873 right = peak_pos + estimate_peak_width * MAGIC;
1888 throw std::runtime_error(
"Unhandled case for get peak fit window!");
1891 std::stringstream errss;
1892 errss <<
"Peak window is inappropriate for workspace index " << wi <<
" peak " << ipeak <<
": " <<
left
1894 throw std::runtime_error(errss.str());
1904 std::vector<double> &vec_y, std::vector<double> &vec_e) {
1908 size_t left_index =
findXIndex(orig_x, fit_window.first);
1909 size_t right_index =
findXIndex(orig_x, fit_window.second, left_index);
1911 if (left_index >= right_index) {
1912 std::stringstream err_ss;
1913 err_ss <<
"Unable to get subset of histogram from given fit window. "
1914 <<
"Fit window: " << fit_window.first <<
", " << fit_window.second <<
". Vector X's range is "
1915 << orig_x.front() <<
", " << orig_x.back();
1916 throw std::runtime_error(err_ss.str());
1920 size_t num_elements = right_index - left_index;
1921 vec_x.resize(num_elements);
1922 std::copy(orig_x.begin() + left_index, orig_x.begin() + right_index, vec_x.begin());
1925 if (
m_inputMatrixWS->isHistogramData() && right_index == orig_x.size() - 1) {
1927 if (right_index == left_index)
1928 throw std::runtime_error(
"Histogram workspace have same left and right "
1929 "boundary index for Y and E.");
1934 const std::vector<double> orig_y =
m_inputMatrixWS->histogram(iws).y().rawData();
1935 const std::vector<double> orig_e =
m_inputMatrixWS->histogram(iws).e().rawData();
1936 vec_y.resize(num_elements);
1937 vec_e.resize(num_elements);
1938 std::copy(orig_y.begin() + left_index, orig_y.begin() + right_index, vec_y.begin());
1939 std::copy(orig_e.begin() + left_index, orig_e.begin() + right_index, vec_e.begin());
1951 std::vector<double> &vec_y) {
1955 bkgd_func->function(vectorx, vector_bkgd);
1958 for (
size_t i = 0; i < vec_y.size(); ++i) {
1959 (vec_y)[i] -= vector_bkgd[i];
1976 const std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> &fit_result) {
1980 g_log.
error() <<
"workspace index " << wi <<
" is out of output peak position workspace "
1984 throw std::runtime_error(
"Out of boundary to set output peak position workspace");
1989 double exp_peak_pos(expected_positions[ipeak]);
1990 double fitted_peak_pos = fit_result->getPeakPosition(ipeak);
1991 double peak_chi2 = fit_result->getCost(ipeak);
2010 <<
" parameters. Parameter table shall have 3 more "
2011 "columns. But not it has "
2013 throw std::runtime_error(
"Peak parameter vector for one peak has different sizes to output "
2020 std::stringstream err_ss;
2021 err_ss <<
"Peak has 4 effective peak parameters and " <<
m_bkgdFunction->nParams() <<
" background parameters "
2022 <<
". Parameter table shall have 3 more columns. But not it has " <<
m_fittedParamTable->columnCount()
2024 throw std::runtime_error(err_ss.str());
2031 size_t num_peakfunc_params = peak_function->nParams();
2041 for (
size_t iparam = 0; iparam < num_peakfunc_params + num_bkgd_params; ++iparam) {
2042 size_t col_index = iparam + 2;
2044 m_fittedParamTable->cell<
double>(row_index, col_index) = fit_result->getParameterValue(ipeak, iparam);
2047 m_fitErrorTable->cell<
double>(row_index, col_index) = fit_result->getParameterError(ipeak, iparam);
2054 for (
size_t iparam = 0; iparam < num_peakfunc_params; ++iparam)
2055 peak_function->setParameter(iparam, fit_result->getParameterValue(ipeak, iparam));
2064 for (
size_t iparam = 0; iparam < num_bkgd_params; ++iparam)
2066 fit_result->getParameterValue(ipeak, num_peakfunc_params + iparam);
2070 m_fittedParamTable->cell<
double>(row_index, chi2_index) = fit_result->getCost(ipeak);
2078 std::string height_name(
"");
2080 std::vector<std::string> peak_parameters = peak_function->getParameterNames();
2081 for (
const auto &
name : peak_parameters) {
2082 if (
name ==
"Height") {
2083 height_name =
"Height";
2085 }
else if (
name ==
"I") {
2088 }
else if (
name ==
"Intensity") {
2089 height_name =
"Intensity";
2094 if (height_name.empty())
2095 throw std::runtime_error(
"Peak height parameter name cannot be found.");
#define DECLARE_ALGORITHM(classname)
double value
The value of the point.
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_CRITICAL(name)
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PRAGMA_OMP(expression)
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
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.
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
Implements FunctionDomain1D with its own storage in form of a std::vector.
A class to store values calculated by a function.
double getCalculated(size_t i) const
Get i-th calculated value.
An interface to a peak function, which extend the interface of IFunctionWithLocation by adding method...
Helper class for reporting progress from algorithms.
TableRow represents a row in a TableWorkspace.
A property class for workspaces.
size_t m_function_parameters_number
number of function parameters
double getPeakPosition(size_t ipeak) const
size_t getNumberPeaks() const
std::vector< std::vector< double > > m_function_parameters_vector
PeakFitResult(size_t num_peaks, size_t num_params)
Holds all of the fitting information for a single spectrum.
double getParameterValue(size_t ipeak, size_t iparam) const
get the fitted value of a particular parameter
std::vector< double > m_costs
std::vector< std::vector< double > > m_function_errors_vector
fitted peak and background parameters' fitting error
size_t getNumberParameters() const
double getCost(size_t ipeak) const
void setRecord(size_t ipeak, const double cost, const double peak_position, const FitFunction &fit_functions)
set the peak fitting record/parameter for one peak
double getParameterError(size_t ipeak, size_t iparam) const
get the fitting error of a particular parameter
void setBadRecord(size_t ipeak, const double peak_position)
The peak postition should be negative and indicates what went wrong.
std::vector< double > m_fitted_peak_positions
Algorithms::PeakParameterHelper::EstimatePeakWidth m_peakWidthEstimateApproach
Flag for observing peak width: there are 3 states (1) no estimation (2) from 'observation' (3) calcul...
API::MatrixWorkspace_const_sptr m_peakCenterWorkspace
void generateFittedParametersValueWorkspaces()
Generate output workspaces.
void setupParameterTableWorkspace(const API::ITableWorkspace_sptr &table_ws, const std::vector< std::string > ¶m_names, bool with_chi2)
Set up parameter table (parameter value or error)
bool m_partialWindowSpectra
std::vector< double > m_peakPosTolerances
API::IPeakFunction_sptr m_peakFunction
Peak profile name.
bool fitBackground(const size_t &ws_index, const std::pair< double, double > &fit_window, const double &expected_peak_pos, const API::IBackgroundFunction_sptr &bkgd_func)
fit background
void fitSpectrumPeaks(size_t wi, const std::vector< double > &expected_peak_centers, const std::shared_ptr< FitPeaksAlgorithm::PeakFitResult > &fit_result, std::vector< std::vector< double > > &lastGoodPeakParameters)
fit peaks in a same spectrum
double fitFunctionSD(const API::IAlgorithm_sptr &fit, const API::IPeakFunction_sptr &peak_function, const API::IBackgroundFunction_sptr &bkgd_function, const API::MatrixWorkspace_sptr &dataws, size_t wsindex, const std::pair< double, double > &peak_range, const double &expected_peak_center, bool estimate_peak_width, bool estimate_background)
Methods to fit functions (general)
double fitIndividualPeak(size_t wi, const API::IAlgorithm_sptr &fitter, const double expected_peak_center, const std::pair< double, double > &fitwindow, const bool estimate_peak_width, const API::IPeakFunction_sptr &peakfunction, const API::IBackgroundFunction_sptr &bkgdfunc)
Fit an individual peak.
bool m_uniformPeakWindows
API::MatrixWorkspace_sptr m_outputPeakPositionWorkspace
output workspace for peak positions
API::MatrixWorkspace_sptr m_fittedPeakWS
matrix workspace contained calcalated peaks+background from fitted result it has same number of spect...
API::ITableWorkspace_const_sptr m_profileStartingValueTable
table workspace for profile parameters' starting value
std::string m_minimizer
Minimzer.
API::IBackgroundFunction_sptr m_linearBackgroundFunction
Linear background function for high background fitting.
bool m_constrainPeaksPosition
bool m_peakPosTolCase234
peak positon tolerance case b, c and d
std::map< std::string, std::string > validateInputs() override
Validate inputs.
std::vector< double > getExpectedPeakPositions(size_t wi)
methods to retrieve fit range and peak centers
double m_peakWidthPercentage
flag to estimate peak width from
API::IBackgroundFunction_sptr m_bkgdFunction
Background function.
size_t m_startWorkspaceIndex
start index
double fitFunctionHighBackground(const API::IAlgorithm_sptr &fit, const std::pair< double, double > &fit_window, const size_t &ws_index, const double &expected_peak_center, bool observe_peak_shape, const API::IPeakFunction_sptr &peakfunction, const API::IBackgroundFunction_sptr &bkgdfunc)
fit a single peak with high background
bool m_calculateWindowInstrument
flag to calcualte peak fit window from instrument resolution
void processInputPeakCenters()
peak centers
std::vector< std::shared_ptr< FitPeaksAlgorithm::PeakFitResult > > fitPeaks()
suites of method to fit peaks
double m_minPeakHeight
minimum peak height without background and it also serves as the criteria for observed peak parameter
std::string m_costFunction
Cost function.
void processInputFunctions()
process inputs for peak and background functions
void processInputPeakTolerance()
process inputs about fitted peak positions' tolerance
void writeFitResult(size_t wi, const std::vector< double > &expected_positions, const std::shared_ptr< FitPeaksAlgorithm::PeakFitResult > &fit_result)
Write result of peak fit per spectrum to output analysis workspaces.
size_t m_stopWorkspaceIndex
stop index (workspace index of the last spectrum included)
void exec() override
Main exec method.
void init() override
Init.
std::vector< std::string > m_peakParamNames
input peak parameters' names
bool isObservablePeakProfile(const std::string &peakprofile)
check whether FitPeaks supports observation on a certain peak profile's parameters (width!...
void processInputFitRanges()
process inputs for peak fitting range
API::MatrixWorkspace_sptr createMatrixWorkspace(const std::vector< double > &vec_x, const std::vector< double > &vec_y, const std::vector< double > &vec_e)
Create a single spectrum workspace for fitting.
void generateOutputPeakPositionWS()
main method to create output workspaces
void generateCalculatedPeaksWS()
Generate workspace for calculated values.
double fitFunctionMD(API::IFunction_sptr fit_function, const API::MatrixWorkspace_sptr &dataws, const size_t wsindex, const std::pair< double, double > &vec_xmin, const std::pair< double, double > &vec_xmax)
std::string getPeakHeightParameterName(const API::IPeakFunction_const_sptr &peak_function)
Get the parameter name for peak height (I or height or etc)
const std::string name() const override
Algorithm's name.
bool m_uniformPeakPositions
void calculateFittedPeaks(std::vector< std::shared_ptr< FitPeaksAlgorithm::PeakFitResult > > fit_results)
calculate peak+background for fitted
API::ITableWorkspace_sptr m_fittedParamTable
output analysis workspaces table workspace for fitted parameters
bool decideToEstimatePeakParams(const bool firstPeakInSpectrum, const API::IPeakFunction_sptr &peak_function)
Decide whether to estimate peak parameters.
void convertParametersNameToIndex()
Convert peak function's parameter names to parameter index for fast access.
void processOutputs(std::vector< std::shared_ptr< FitPeaksAlgorithm::PeakFitResult > > fit_result_vec)
Set the workspaces and etc to output properties.
bool m_highBackground
flag for high background
std::vector< double > m_initParamValues
input peak parameters' starting values corresponding to above peak parameter names
std::vector< double > m_peakCenters
Designed peak positions and tolerance.
void reduceByBackground(const API::IBackgroundFunction_sptr &bkgd_func, const std::vector< double > &vec_x, std::vector< double > &vec_y)
Reduce background.
std::vector< std::vector< double > > m_peakWindowVector
peak windows
void getRangeData(size_t iws, const std::pair< double, double > &fit_window, std::vector< double > &vec_x, std::vector< double > &vec_y, std::vector< double > &vec_e)
get vector X, Y and E in a given range
API::MatrixWorkspace_sptr m_inputMatrixWS
mandatory input and output workspaces
std::pair< double, double > getPeakFitWindow(size_t wi, size_t ipeak)
get the peak fit window
std::vector< size_t > m_initParamIndexes
input starting parameters' indexes in peak function
bool m_fitPeaksFromRight
Fit from right or left.
bool m_rawPeaksTable
flag to show that the pamarameters in table are raw parameters or effective parameters
void processInputs()
process inputs (main and child algorithms)
int m_fitIterations
Fit iterations.
API::MatrixWorkspace_const_sptr m_peakWindowWorkspace
bool m_uniformProfileStartingValue
flag for profile startng value being uniform or not
API::ITableWorkspace_sptr m_fitErrorTable
table workspace for fitted parameters' fitting error. This is optional
bool m_partialSpectra
flag whether the peak center workspace has only a subset of spectra to fit
bool processSinglePeakFitResult(size_t wsindex, size_t peakindex, const double cost, const std::vector< double > &expected_peak_positions, const FitPeaksAlgorithm::FitFunction &fitfunction, const std::shared_ptr< FitPeaksAlgorithm::PeakFitResult > &fit_result)
Process the result from fitting a single peak.
Support for a property that holds an array of values.
Exception for when an item is not found in a collection.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void setPropertyGroup(const std::string &name, const std::string &group)
Set the group for a given property.
ListValidator is a validator that requires the value of a property to be one of a defined list of pos...
void debug(const std::string &msg)
Logs at debug level.
void notice(const std::string &msg)
Logs at notice level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
StartsWithValidator is a validator that requires the value of a property to start with one of the str...
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< IBackgroundFunction > IBackgroundFunction_sptr
std::shared_ptr< IPeakFunction > IPeakFunction_sptr
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< const IPeakFunction > IPeakFunction_const_sptr
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
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_ALGORITHMS_DLL size_t findXIndex(const vector_like &vecx, const double x, const size_t startindex=0)
Get an index of a value in a sorted vector.
MANTID_ALGORITHMS_DLL int estimatePeakParameters(const HistogramData::Histogram &histogram, const std::pair< size_t, size_t > &peak_window, const API::IPeakFunction_sptr &peakfunction, const API::IBackgroundFunction_sptr &bkgdfunction, bool observe_peak_width, const EstimatePeakWidth peakWidthEstimateApproach, const double peakWidthPercentage, const double minPeakHeight)
Estimate peak parameters by 'observation'.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
Helper class which provides the Collimation Length for SANS instruments.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
API::IPeakFunction_sptr peakfunction
API::IBackgroundFunction_sptr bkgdfunction
@ Input
An input workspace.
@ Output
An output workspace.