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);
106 const std::string
name()
const override {
return "FitPeaks"; }
109 const std::string
summary()
const override {
return "Fit one or multiple peaks in all spectra of a given workspace"; }
115 const std::string
category()
const override {
return "Optimization"; }
117 std::map<std::string, std::string> validateInputs()
override;
122 static bool fitStatusIsConverged(
const std::string &fitStatus,
const bool strict);
126 void init()
override;
128 void exec()
override;
131 void processInputs();
133 void processInputPeakCenters();
135 void processInputPeakTolerance();
137 void processInputFunctions();
139 void processInputFitRanges();
142 void generateFittedParametersValueWorkspaces();
144 void generateOutputPeakPositionWS();
146 void generateCalculatedPeaksWS();
150 void convertParametersNameToIndex();
153 std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> fitPeaks();
156 void fitSpectrumPeaks(
size_t wi,
const std::vector<double> &expected_peak_centers,
157 const std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> &fit_result,
158 std::vector<std::vector<double>> &lastGoodPeakParameters,
159 std::vector<size_t> &lastGoodPeakSpectra,
160 const std::shared_ptr<FitPeaksAlgorithm::PeakFitPreCheckResult> &pre_check_result);
163 bool fitBackground(
const size_t &ws_index,
const std::pair<double, double> &fit_window,
167 double fitIndividualPeak(
size_t wi,
const API::IAlgorithm_sptr &fitter,
const double expected_peak_center,
168 const double peak_pos_tolerance,
const std::pair<double, double> &fitwindow,
171 const std::shared_ptr<FitPeaksAlgorithm::PeakFitPreCheckResult> &pre_check_result);
176 size_t wsindex,
const std::pair<double, double> &peak_range,
const double &expected_peak_center,
177 const double peak_pos_tolerance,
bool estimate_peak_width,
bool estimate_background);
186 const std::pair<double, double> &peak_range);
189 const std::pair<double, double> &vec_xmin,
const std::pair<double, double> &vec_xmax);
192 double fitFunctionHighBackground(
const API::IAlgorithm_sptr &fit,
const std::pair<double, double> &fit_window,
193 const size_t &ws_index,
const double &expected_peak_center,
194 const double peak_pos_tolerance,
bool observe_peak_shape,
199 const std::vector<std::string> ¶m_names,
bool with_chi2);
202 void histRangeToIndexBounds(
size_t iws,
const std::pair<double, double> &range,
size_t &left_index,
203 size_t &right_index);
206 size_t histRangeToDataPointCount(
size_t iws,
const std::pair<double, double> &range);
209 void getRangeData(
size_t iws,
const std::pair<double, double> &range, std::vector<double> &vec_x,
210 std::vector<double> &vec_y, std::vector<double> &vec_e);
213 double numberCounts(
size_t iws);
216 double numberCounts(
size_t iws,
const std::pair<double, double> &range);
219 double calculateSignalToNoiseRatio(
size_t iws,
const std::pair<double, double> &range,
223 const std::vector<double> &vec_e);
225 bool decideToEstimatePeakParams(
const bool firstPeakInSpectrum,
const size_t wsindex,
229 bool processSinglePeakFitResult(
size_t wsindex,
size_t peakindex,
const double cost,
230 const std::vector<double> &expected_peak_positions,
232 const std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> &fit_result);
235 void calculateFittedPeaks(
const std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> &fit_results);
237 double calculateSignalToSigmaRatio(
const size_t &iws,
const std::pair<double, double> &peakWindow,
244 void processOutputs(std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> fit_result_vec);
247 void writeFitResult(
size_t wi,
const std::vector<double> &expected_positions,
248 const std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> &fit_result);
252 bool isObservablePeakProfile(
const std::string &peakprofile);
255 void logNoOffset(
const size_t &priority,
const std::string &msg);
295 bool m_strictConvergence{
true};
319 std::function<std::pair<double, double>(std::size_t
const &, std::size_t
const &)>
m_getPeakFitWindow;
320 void checkWorkspaceIndices(std::size_t
const &);
321 void checkPeakIndices(std::size_t
const &, std::size_t
const &);
322 void checkPeakWindowEdgeOrder(
double const &,
double const &);
344 bool m_constrainByPositionTolerance{
false};
349 bool m_fractionalPositionTolerance{
false};
354 bool m_calculateUnconstrainedErrors{
false};
Base class from which all concrete algorithm classes should be derived.
size_t m_submitted_spectrum_peaks
void setNumberOfSpectrumPeaksWithLowCount(const size_t n)
std::string getReport() const
size_t m_low_count_individual
PeakFitPreCheckResult & operator+=(const PeakFitPreCheckResult &another)
size_t m_not_enough_datapoints
void setNumberOfSubmittedIndividualPeaks(const size_t n)
void setNumberOfPeaksWithNotEnoughDataPoints(const size_t n)
size_t m_low_count_spectrum
void setNumberOfOutOfRangePeaks(const size_t n)
void setNumberOfPeaksWithLowSignalToNoise(const size_t n)
size_t m_submitted_individual_peaks
void setNumberOfIndividualPeaksWithLowCount(const size_t n)
void setNumberOfSubmittedSpectrumPeaks(const size_t n)
bool isIndividualPeakRejected() const
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_copyLastGoodPeakParameters
std::vector< double > m_peakPosTolerances
tolerances for fitting peak positions
API::IPeakFunction_sptr m_peakFunction
Peak profile name.
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.
bool m_respectFixedPeakParameters
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.
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.
std::size_t m_numSpectraToFit
total number of spectra to be fit
std::vector< std::string > m_peakParamNames
input peak parameters' names
std::size_t m_numPeaksToFit
the number of peaks to fit in all spectra
std::size_t m_startWorkspaceIndex
start index
double m_minPeakTotalCount
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
double m_minSignalToNoiseRatio
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
std::function< std::pair< double, double >(std::size_t const &, std::size_t const &)> m_getPeakFitWindow
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.
std::function< std::vector< double >(std::size_t const &)> m_getExpectedPeakPositions
bool m_rawPeaksTable
flag to show that the pamarameters in table are raw parameters or effective parameters
int m_fitIterations
Fit iterations.
double m_minSignalToSigmaRatio
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
std::size_t m_stopWorkspaceIndex
stop index (workspace index of the last spectrum included)
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