MultiPeakFit Class Reference

`#include <MultiPeakFit.h>`

Inheritance diagram for MultiPeakFit:

## Public Types

enum | PeakProfile { Gauss, Lorentz }
Public Types inherited from Fit
enum | Algorithm { ScaledLevenbergMarquardt, UnscaledLevenbergMarquardt, NelderMeadSimplex }
typedef int(* | fit_function) (const gsl_vector *, void *, gsl_vector *)
typedef int(* | fit_function_df) (const gsl_vector *, void *, gsl_matrix *)
typedef int(* | fit_function_fdf) (const gsl_vector *, void *, gsl_vector *, gsl_matrix *)
typedef double(* | fit_function_simplex) (const gsl_vector *, void *)
enum | FitType { BuiltIn = 0, Plugin = 1, User = 2 }
enum | WeightingMethod { NoWeighting, Instrumental, Statistical, Dataset, Direct }

## Public Member Functions

void | enablePeakCurves (bool on)
virtual double | eval (double *par, double x)
| Calculates the data for the output fit curve. More...
double | evalPeak (double *par, double x, int peak)
void | guessInitialValues ()
| Used by the GaussFit and LorentzFit derived classes to calculate initial values for the parameters. More...
| MultiPeakFit (ApplicationWindow *parent, QwtPlotCurve *c, PeakProfile profile=Gauss, int peaks=1)
| MultiPeakFit (ApplicationWindow *parent, Graph *g=0, PeakProfile profile=Gauss, int peaks=1)
| MultiPeakFit (ApplicationWindow *parent, Table *t, const QString &xCol, const QString &yCol, int startRow=0, int endRow=-1, PeakProfile profile=Gauss, int peaks=1)
int | peaks ()
PeakProfile | profile ()
void | setNumPeaks (int n)
void | setPeakCurvesColor (int colorIndex)
void | setPeakCurvesColor (const QColor &color)
Public Member Functions inherited from Fit
double | adjustedRSquare ()
| Returns adjusted R^2. More...
double | chiSquare ()
| Returns the sum of squares of the residuals from the best-fit line. More...
Matrix * | covarianceMatrix (const QString &matrixName)
double * | errors ()
| Returns a vector with the standard deviations of the results. More...
QString | fileName ()
| Fit (ApplicationWindow *parent, QwtPlotCurve *c)
| Fit (ApplicationWindow *parent, Graph *g=0, const QString &name=QString())
| Fit (ApplicationWindow *parent, Table *t, const QString &name=QString())
virtual void | fit ()
| Actually does the fit. Should be reimplemented in derived classes. More...
QString | formula ()
void | generateFunction (bool yes, int points=100)
| Specifies weather the result of the fit is a function curve. More...
double | initialGuess (int parIndex)
double | lcl (int parIndex, double confidenceLevel)
| Lower Confidence Limit. More...
virtual QString | legendInfo ()
| Output string added to the plot as a new legend. More...
bool | load (const QString &fileName)
int | numParameters ()
QStringList | parameterNames ()
Table * | parametersTable (const QString &tableName)
double * | residuals ()
| Returns a vector with the fit residuals. More...
QString | resultFormula ()
double * | results ()
| Returns a vector with the fit results. More...
double | rmse ()
| Returns the Root Mean Squared Error. More...
double | rSquare ()
| Returns R^2. More...
double | rss ()
| Returns the Residual Sum of Squares. More...
virtual bool | run ()
| Actually does the job. Should be reimplemented in derived classes. More...
bool | save (const QString &fileName)
void | scaleErrors (bool yes=true)
| Specifies wheather the errors must be scaled with sqrt(chi_2/dof) More...
void | setAlgorithm (Algorithm s)
void | setDataCurve (QwtPlotCurve *curve, double start, double end)
bool | setDataFromTable (Table *t, const QString &xColName, const QString &yColName, int from=1, int to=-1, bool sort=false)
void | setFileName (const QString &fn)
virtual bool | setFormula (const QString &, bool=true)
void | setInitialGuess (int parIndex, double val)
void | setInitialGuesses (double *x_init)
void | setParameterExplanations (const QStringList &lst)
void | setParameterRange (int parIndex, double left, double right)
virtual bool | setParametersList (const QStringList &)
void | setType (FitType t)
bool | setWeightingData (WeightingMethod w, const QString &colName=QString::null)
| Sets the data set to be used for weighting. More...
void | showConfidenceLimits (double confidenceLevel)
void | showPredictionLimits (double confidenceLevel)
QwtPlotCurve * | showResiduals ()
| Plot residuals and display data values in a column. More...
FitType | type ()
double | ucl (int parIndex, double confidenceLevel)
| Upper Confidence Limit. More...
void | writeParametersToTable (Table *t, bool append=false)
| ~Fit ()
Public Member Functions inherited from Filter
int | dataSize ()
| Returns the size of the input data set. More...
virtual void | enableGraphicsDisplay (bool on=true, Graph *g=0)
bool | error ()
| Filter (ApplicationWindow *parent, Table *t=0, const QString &name=QString())
| Filter (ApplicationWindow *parent, Graph *g=0, const QString &name=QString())
| Filter (ApplicationWindow *parent, Matrix *m, const QString &name=QString())
| Filter (ApplicationWindow *parent, QwtPlotCurve *c)
Graph * | outputGraph ()
| Returns a pointer to the graph where the result curve should be displayed. More...
QwtPlotCurve * | resultCurve ()
| Returns a pointer to the plot curve created to display the results. More...
Table * | resultTable ()
| Returns a pointer to the table created to display the results. More...
void | setColor (int colorId)
| Obsolete: sets the color of the output fit curve. More...
void | setColor (const QColor &color)
| Sets the color of the output fit curve. More...
void | setColor (const QString &colorName)
| Sets the color of the output fit curve. Provided for convenience. To be used in scripts only! More...
bool | setDataFromCurve (QwtPlotCurve *c)
bool | setDataFromCurve (QwtPlotCurve *c, double from, double to)
bool | setDataFromCurve (const QString &curveTitle, Graph *g=0)
bool | setDataFromCurve (const QString &curveTitle, double from, double to, Graph *g=0)
void | setError (bool on=true)
void | setInterval (double from, double to)
| Changes the data range if the source curve was already assigned. Provided for convenience. More...
void | setMaximumIterations (int iter)
| Sets the maximum number of iterations to be performed during an iterative session. More...
void | setOutputPoints (int points)
| Sets the number of points in the output curve. More...
void | setOutputPrecision (int digits)
| Sets the precision used for the output. More...
void | setSortData (bool on=true)
void | setTolerance (double eps)
| Sets the tolerance used by the GSL routines. More...
void | setUpdateOutputGraph (bool update=true)
virtual void | showLegend ()
| Adds a new legend to the plot. Calls virtual legendInfo() More...
double * | x ()
| Returns the x values of the input data set. More...
double * | y ()
| Returns the y values of the input data set. More...
| ~Filter ()

## Static Public Member Functions

static QStringList | generateExplanationList (int order)
static QString | generateFormula (int order, PeakProfile profile)
static QStringList | generateParameterList (int order)

## Private Member Functions

void | customizeFitResults ()
| Customs and stores the fit results according to the derived class specifications. Used by exponential fits. More...
void | generateFitCurve ()
| Adds the result curve to the plot. More...
void | init (int)
void | insertPeakFunctionCurve (int peak)
| Inserts a peak function curve into the plot. More...
QString | logFitInfo (int iterations, int status)
| Output string added to the result log. More...

## Static Private Member Functions

static QString | peakFormula (int peakIndex, PeakProfile profile)

## Private Attributes

int | d_peaks
| Number of peaks. More...
QColor | d_peaks_color
| Color for the peak curves. More...
PeakProfile | d_profile
| The peak profile. More...
bool | generate_peak_curves
| Tells weather the peak curves should be displayed together with the best line fit. More...

## Additional Inherited Members

Protected Member Functions inherited from Fit
virtual void | calculateFitCurveData (double *X, double *Y)
| Calculates the data for the output fit curve and store itin the X an Y vectors. More...
virtual void | freeMemory ()
| Frees all the arrays with size d_n. Used when changing the source data sets. More...
void | freeWorkspace ()
| Frees the memory allocated for the fit workspace. More...
void | initWorkspace (int par)
| Allocates the memory for the fit workspace. More...
virtual FunctionCurve * | insertFitFunctionCurve (const QString &name, int penWidth=1, bool updateData=true)
| Adds the result curve as a FunctionCurve to the plot, if d_gen_function = true. More...
Protected Member Functions inherited from Filter
QwtPlotCurve * | addResultCurve (double *x, double *y)
| Adds the result curve to the target output plot window. Creates a hidden table and frees the input data from memory. More...
virtual void | calculateOutputData (double *X, double *Y)
| Calculates the data for the output curve and store it in the X an Y vectors. More...
MultiLayer * | createOutputGraph ()
virtual int | curveData (QwtPlotCurve *c, double start, double end, double **x, double **y)
int | curveIndex (const QString &curveTitle, Graph *g)
| Performs checks and returns the index of the source data curve if OK, -1 otherwise. More...
int | curveRange (QwtPlotCurve *c, double start, double end, int *iStart, int *iEnd)
void | init ()
virtual QString | logInfo ()
| Output string added to the log pannel of the application. More...
void | memoryErrorMessage ()
virtual void | output ()
| Performs the data analysis and takes care of the output. More...
virtual int | sortedCurveData (QwtPlotCurve *c, double start, double end, double **x, double **y)
| Same as curveData, but sorts the points by their x value. More...
Protected Attributes inherited from Fit
double | chi_2
| The sum of squares of the residuals from the best-fit line. More...
gsl_matrix * | covar
| Covariance matrix. More...
double | d_adjusted_r_square
| Adjusted R^2. More...
Matrix * | d_cov_matrix
| Matrix window used for the output of covariance matrix. More...
fit_function_df | d_df
double * | d_errors
| Stores standard deviations of the result parameters. More...
fit_function | d_f
fit_function_fdf | d_fdf
QString | d_file_name
| Path of the XML file where the user stores the fit model. More...
FitType | d_fit_type
QString | d_formula
| The fit formula given on input. More...
fit_function_simplex | d_fsimplex
bool | d_gen_function
| Specifies weather the result curve is a FunctionCurve or a normal curve with the same x values as the fit data. More...
int | d_p
| Number of fit parameters. More...
QStringList | d_param_explain
| Stores a list of short explanations for the significance of the fit parameters. More...
gsl_vector * | d_param_init
| Initial guesses for the fit parameters. More...
QStringList | d_param_names
| Names of the fit parameters. More...
double * | d_param_range_left
| Stores the left limits of the research interval for the result parameters. More...
double * | d_param_range_right
| Stores the right limits of the research interval for the result parameters. More...
QPointer< Table > | d_param_table
| Table window used for the output of fit parameters. More...
double * | d_residuals
| Stores fit residuals. More...
QString | d_result_formula
| The result fit formula, where the fit parameters are replaced with the calculated values. More...
double * | d_results
| Stores the result parameters. More...
double | d_rss
| Residual sum of squares. More...
bool | d_scale_errors
| Specifies wheather the errors must be scaled with sqrt(chi_2/dof) More...
Algorithm | d_solver
| Algorithm type. More...
double * | d_w
| weighting data set used for the fit More...
WeightingMethod | d_weighting
| The kind of weighting to be performed on the data. More...
bool | is_non_linear
| Tells whether the fitter uses non-linear/simplex fitting with an initial parameters set, that must be freed in the destructor. More...
QString | weighting_dataset
| The name of the weighting dataset. More...
Protected Attributes inherited from Filter
QwtPlotCurve * | d_curve
| The curve to be analysed. More...
QColor | d_curveColor
| Color index of the result curve. More...
QString | d_explanation
| String explaining the operation in the comment of the result table and in the project explorer. More...
double | d_from
| Data interval. More...
Graph * | d_graph
| The source graph with the curve to be analyzed. More...
bool | d_graphics_display
| Specifies if the filter should display a result curve. More...
bool | d_init_err
| Error flag telling if something went wrong during the initialization phase. More...
Matrix * | d_matrix
int | d_max_iterations
| Maximum number of iterations per fit. More...
int | d_min_points
| Minimum number of data points necessary to perform the operation. More...
int | d_n
| Size of the data arrays. More...
Graph * | d_output_graph
| The graph where the result curve should be displayed. More...
int | d_points
| Number of result points to de calculated and displayed in the output curve. More...
int | d_prec
| Precision (number of significant digits) used for the results output. More...
QwtPlotCurve * | d_result_curve
| The resulting curve. More...
Table * | d_result_table
| The table displaying the results of the filtering operation (not alvays valid!) More...
bool | d_sort_data
| Specifies if the filter needs sorted data as input. More...
Table * | d_table
| A table source of data. More...
double | d_to
double | d_tolerance
| GSL Tolerance, if ever needed... More...
bool | d_update_output_graph
| Specifies if the filter should update the output graph. More...
double * | d_x
| x data set to be analysed More...
double * | d_y
| y data set to be analysed More...
QString | d_y_col_name

## Member Enumeration Documentation

enum MultiPeakFit::PeakProfile

Enumerator
Gauss |
Lorentz |

## Constructor & Destructor Documentation

MultiPeakFit::MultiPeakFit | ( | ApplicationWindow * | parent,
|  | QwtPlotCurve * | c,
|  | PeakProfile | profile = `Gauss`,
|  | int | peaks = `1`
| ) |  |

References Fit::init().

MultiPeakFit::MultiPeakFit | ( | ApplicationWindow * | parent,
|  | Graph * | g = `0`,
|  | PeakProfile | profile = `Gauss`,
|  | int | peaks = `1`
| ) |  |

References Fit::init().

MultiPeakFit::MultiPeakFit | ( | ApplicationWindow * | parent,
|  | Table * | t,
|  | const QString & | xCol,
|  | const QString & | yCol,
|  | int | startRow = `0`,
|  | int | endRow = `-1`,
|  | PeakProfile | profile = `Gauss`,
|  | int | peaks = `1`
| ) |  |

References Fit::init().

## Member Function Documentation

void MultiPeakFit::customizeFitResults | ( |  | ) |

private virtual

Customs and stores the fit results according to the derived class specifications. Used by exponential fits.

Reimplemented from Fit.

References d_peaks, and Fit::d_results.

Referenced by generateFitCurve().

void MultiPeakFit::enablePeakCurves | ( | bool | on | ) |

inline

References generate_peak_curves.

Referenced by FitDialog::initBuiltInFunctions(), and MultiPeakFitTool::MultiPeakFitTool().

double MultiPeakFit::eval | ( | double * | ,
|  | double |
| ) |  |

virtual

Calculates the data for the output fit curve.

Reimplemented from Fit.

References Fit::d_p, d_peaks, evalPeak(), and Filter::y().

double MultiPeakFit::evalPeak | ( | double * | par,
|  | double | x,
|  | int | peak
| ) |  |

References d_profile, and Gauss.

Referenced by eval().

QStringList MultiPeakFit::generateExplanationList | ( | int | order | ) |

static

References peaks().

Referenced by setNumPeaks().

void MultiPeakFit::generateFitCurve | ( |  | ) |

private virtual

Adds the result curve to the plot.

Reimplemented from Fit.

References Graph::addFitCurve(), Filter::createOutputGraph(), customizeFitResults(), Filter::d_curve, Filter::d_curveColor, Filter::d_explanation, Fit::d_gen_function, Filter::d_graphics_display, Filter::d_n, Filter::d_output_graph, Fit::d_p, d_peaks, d_peaks_color, Filter::d_points, Filter::d_prec, d_profile, Filter::d_result_table, Fit::d_results, Filter::d_x, Filter::d_y_col_name, Gauss, generate_peak_curves, ApplicationWindow::generateUniqueName(), Fit::insertFitFunctionCurve(), insertPeakFunctionCurve(), Graph::insertPlotItem(), Graph::Line, Filter::memoryErrorMessage(), ApplicationWindow::newHiddenTable(), Table::setHeader(), and Table::setText().

QString MultiPeakFit::generateFormula | ( | int | order,
|  | PeakProfile | profile
| ) |  |

static

References Fit::formula(), Gauss, Lorentz, peakFormula(), and peaks().

Referenced by setNumPeaks().

QStringList MultiPeakFit::generateParameterList | ( | int | order | ) |

static

References peaks().

Referenced by setNumPeaks().

void MultiPeakFit::guessInitialValues | ( |  | ) |

virtual

Used by the GaussFit and LorentzFit derived classes to calculate initial values for the parameters.

Reimplemented from Fit.

References Filter::d_n, Fit::d_param_init, d_peaks, d_profile, Filter::d_x, Filter::d_y, and Lorentz.

void MultiPeakFit::init | ( | int | peaks | ) |

private

References Fit::d_df, Fit::d_f, Fit::d_fdf, Fit::d_fsimplex, d_peaks_color, d_profile, Gauss, gauss_multi_peak_d(), gauss_multi_peak_df(), gauss_multi_peak_f(), gauss_multi_peak_fdf(), generate_peak_curves, lorentz_multi_peak_d(), lorentz_multi_peak_df(), lorentz_multi_peak_f(), lorentz_multi_peak_fdf(), and setNumPeaks().

void MultiPeakFit::insertPeakFunctionCurve | ( | int | peak | ) |

private

Inserts a peak function curve into the plot.

References Graph::addFitCurve(), Graph::curveNamesList(), Filter::d_curve, Filter::d_from, Filter::d_output_graph, Fit::d_p, Fit::d_param_names, d_peaks_color, Filter::d_points, d_profile, Fit::d_results, Filter::d_to, Graph::insertPlotItem(), Graph::Line, FunctionCurve::loadData(), FunctionCurve::Normal, peakFormula(), FunctionCurve::setConstant(), FunctionCurve::setFormula(), and FunctionCurve::setRange().

Referenced by generateFitCurve().

QString MultiPeakFit::logFitInfo | ( | int | iterations,
|  | int | status
| ) |  |

private virtual

Output string added to the result log.

Reimplemented from Fit.

References d_peaks, Filter::d_prec, d_profile, Fit::d_results, Fit::logFitInfo(), and Lorentz.

QString MultiPeakFit::peakFormula | ( | int | peakIndex,
|  | PeakProfile | profile
| ) |  |

static private

References Fit::formula(), Gauss, and Lorentz.

Referenced by generateFormula(), and insertPeakFunctionCurve().

int MultiPeakFit::peaks | ( |  | ) |

inline

References d_peaks.

Referenced by generateExplanationList(), generateFormula(), and generateParameterList().

PeakProfile MultiPeakFit::profile | ( |  | ) |

inline

References d_profile.

void MultiPeakFit::setNumPeaks | ( | int | n | ) |

References Filter::d_explanation, Fit::d_formula, Fit::d_p, Fit::d_param_explain, Fit::d_param_names, d_peaks, d_profile, Fit::freeWorkspace(), Gauss, generateExplanationList(), generateFormula(), generateParameterList(), and Fit::initWorkspace().

Referenced by init().

void MultiPeakFit::setPeakCurvesColor | ( | int | colorIndex | ) |

References d_peaks_color, and ColorBox::defaultColor().

Referenced by FitDialog::initBuiltInFunctions(), and MultiPeakFitTool::MultiPeakFitTool().

void MultiPeakFit::setPeakCurvesColor | ( | const QColor & | color | ) |

inline

References d_peaks_color.

## Member Data Documentation

int MultiPeakFit::d_peaks

private

Number of peaks.

Referenced by customizeFitResults(), eval(), generateFitCurve(), guessInitialValues(), logFitInfo(), peaks(), and setNumPeaks().

QColor MultiPeakFit::d_peaks_color

private

Color for the peak curves.

Referenced by generateFitCurve(), init(), insertPeakFunctionCurve(), and setPeakCurvesColor().

PeakProfile MultiPeakFit::d_profile

private

The peak profile.

Referenced by evalPeak(), generateFitCurve(), guessInitialValues(), init(), insertPeakFunctionCurve(), logFitInfo(), profile(), and setNumPeaks().

bool MultiPeakFit::generate_peak_curves

private

Tells weather the peak curves should be displayed together with the best line fit.

Referenced by enablePeakCurves(), generateFitCurve(), and init().

The documentation for this class was generated from the following files:

- qtiplot/src/analysis/MultiPeakFit.h
- qtiplot/src/analysis/MultiPeakFit.cpp