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;
121 void init()
override;
123 void exec()
override;
126 void processInputs();
128 void processInputPeakCenters();
130 void processInputPeakTolerance();
132 void processInputFunctions();
134 void processInputFitRanges();
137 void generateFittedParametersValueWorkspaces();
139 void generateOutputPeakPositionWS();
141 void generateCalculatedPeaksWS();
145 void convertParametersNameToIndex();
148 std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> fitPeaks();
151 void fitSpectrumPeaks(
size_t wi,
const std::vector<double> &expected_peak_centers,
152 const std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> &fit_result,
153 std::vector<std::vector<double>> &lastGoodPeakParameters,
154 const std::shared_ptr<FitPeaksAlgorithm::PeakFitPreCheckResult> &pre_check_result);
157 bool fitBackground(
const size_t &ws_index,
const std::pair<double, double> &fit_window,
161 double fitIndividualPeak(
size_t wi,
const API::IAlgorithm_sptr &fitter,
const double expected_peak_center,
162 const std::pair<double, double> &fitwindow,
const bool estimate_peak_width,
164 const std::shared_ptr<FitPeaksAlgorithm::PeakFitPreCheckResult> &pre_check_result);
169 size_t wsindex,
const std::pair<double, double> &peak_range,
const double &expected_peak_center,
170 bool estimate_peak_width,
bool estimate_background);
173 const std::pair<double, double> &vec_xmin,
const std::pair<double, double> &vec_xmax);
176 double fitFunctionHighBackground(
const API::IAlgorithm_sptr &fit,
const std::pair<double, double> &fit_window,
177 const size_t &ws_index,
const double &expected_peak_center,
bool observe_peak_shape,
182 const std::vector<std::string> ¶m_names,
bool with_chi2);
185 void histRangeToIndexBounds(
size_t iws,
const std::pair<double, double> &range,
size_t &left_index,
186 size_t &right_index);
189 size_t histRangeToDataPointCount(
size_t iws,
const std::pair<double, double> &range);
192 void getRangeData(
size_t iws,
const std::pair<double, double> &range, std::vector<double> &vec_x,
193 std::vector<double> &vec_y, std::vector<double> &vec_e);
196 double numberCounts(
size_t iws);
199 double numberCounts(
size_t iws,
const std::pair<double, double> &range);
202 double calculateSignalToNoiseRatio(
size_t iws,
const std::pair<double, double> &range,
206 const std::vector<double> &vec_e);
211 bool processSinglePeakFitResult(
size_t wsindex,
size_t peakindex,
const double cost,
212 const std::vector<double> &expected_peak_positions,
214 const std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> &fit_result);
217 void calculateFittedPeaks(
const std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> &fit_results);
219 double calculateSignalToSigmaRatio(
const size_t &iws,
const std::pair<double, double> &peakWindow,
226 void processOutputs(std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> fit_result_vec);
229 void writeFitResult(
size_t wi,
const std::vector<double> &expected_positions,
230 const std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> &fit_result);
234 bool isObservablePeakProfile(
const std::string &peakprofile);
237 void logNoOffset(
const size_t &priority,
const std::string &msg);
289 std::function<std::pair<double, double>(std::size_t
const &, std::size_t
const &)>
m_getPeakFitWindow;
290 void checkWorkspaceIndices(std::size_t
const &);
291 void checkPeakIndices(std::size_t
const &, std::size_t
const &);
292 void checkPeakWindowEdgeOrder(
double const &,
double const &);
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
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.
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