16#include "MantidAlgorithms/DllConfig.h"
25namespace HistogramData {
32namespace FitPeaksAlgorithm {
42 double getCost(
size_t ipeak)
const;
47 void setRecord(
size_t ipeak,
const double cost,
const double peak_position,
const FitFunction &fit_functions);
48 void setBadRecord(
size_t ipeak,
const double peak_position);
70 const std::string
name()
const override {
return "FitPeaks"; }
73 const std::string
summary()
const override {
return "Fit one or multiple peaks in all spectra of a given workspace"; }
76 int version()
const override {
return (1); }
79 const std::string
category()
const override {
return "Optimization"; }
81 std::map<std::string, std::string> validateInputs()
override;
92 void processInputPeakCenters();
94 void processInputPeakTolerance();
96 void processInputFunctions();
98 void processInputFitRanges();
101 void generateFittedParametersValueWorkspaces();
103 void generateOutputPeakPositionWS();
105 void generateCalculatedPeaksWS();
109 void convertParametersNameToIndex();
112 std::vector<double> getExpectedPeakPositions(
size_t wi);
113 std::pair<double, double> getPeakFitWindow(
size_t wi,
size_t ipeak);
116 std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> fitPeaks();
119 void fitSpectrumPeaks(
size_t wi,
const std::vector<double> &expected_peak_centers,
120 const std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> &fit_result,
121 std::vector<std::vector<double>> &lastGoodPeakParameters);
124 bool fitBackground(
const size_t &ws_index,
const std::pair<double, double> &fit_window,
128 double fitIndividualPeak(
size_t wi,
const API::IAlgorithm_sptr &fitter,
const double expected_peak_center,
129 const std::pair<double, double> &fitwindow,
const bool estimate_peak_width,
135 size_t wsindex,
const std::pair<double, double> &peak_range,
const double &expected_peak_center,
136 bool estimate_peak_width,
bool estimate_background);
139 const std::pair<double, double> &vec_xmin,
const std::pair<double, double> &vec_xmax);
142 double fitFunctionHighBackground(
const API::IAlgorithm_sptr &fit,
const std::pair<double, double> &fit_window,
143 const size_t &ws_index,
const double &expected_peak_center,
bool observe_peak_shape,
148 const std::vector<std::string> ¶m_names,
bool with_chi2);
151 void getRangeData(
size_t iws,
const std::pair<double, double> &fit_window, std::vector<double> &vec_x,
152 std::vector<double> &vec_y, std::vector<double> &vec_e);
156 std::vector<double> &vec_y);
159 const std::vector<double> &vec_e);
164 bool processSinglePeakFitResult(
size_t wsindex,
size_t peakindex,
const double cost,
165 const std::vector<double> &expected_peak_positions,
167 const std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> &fit_result);
170 void calculateFittedPeaks(std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> fit_results);
176 void processOutputs(std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> fit_result_vec);
179 void writeFitResult(
size_t wi,
const std::vector<double> &expected_positions,
180 const std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> &fit_result);
184 bool isObservablePeakProfile(
const std::string &peakprofile);
Base class from which all concrete algorithm classes should be derived.
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
double getParameterValue(size_t ipeak, size_t iparam) const
get the fitted value of a particular parameter
std::vector< double > m_costs
void setFunctionParameters(size_t ipeak, std::vector< double > ¶m_values)
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
bool m_partialWindowSpectra
std::vector< double > m_peakPosTolerances
API::IPeakFunction_sptr m_peakFunction
Peak profile name.
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
double m_peakWidthPercentage
flag to estimate peak width from
API::IBackgroundFunction_sptr m_bkgdFunction
Background function.
int version() const override
Algorithm's version.
size_t m_startWorkspaceIndex
start index
bool m_calculateWindowInstrument
flag to calcualte peak fit window from instrument resolution
const std::string summary() const override
Summary of algorithms purpose.
const std::string category() const override
Algorithm's category for identification.
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.
size_t m_stopWorkspaceIndex
stop index (workspace index of the last spectrum included)
std::vector< std::string > m_peakParamNames
input peak parameters' names
const std::string name() const override
Algorithm's name.
bool m_uniformPeakPositions
API::ITableWorkspace_sptr m_fittedParamTable
output analysis workspaces table workspace for fitted parameters
DataObjects::EventWorkspace_const_sptr m_inputEventWS
event workspace for input
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.
std::vector< std::vector< double > > m_peakWindowVector
peak windows
API::MatrixWorkspace_sptr m_inputMatrixWS
mandatory input and output workspaces
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
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
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 ITableWorkspace > ITableWorkspace_const_sptr
shared pointer to Mantid::API::ITableWorkspace (const version)
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< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
Helper class which provides the Collimation Length for SANS instruments.
API::IPeakFunction_sptr peakfunction
API::IBackgroundFunction_sptr bkgdfunction