00001
00008 #ifndef SPLINE_BSPLINE_HH
00009 #define SPLINE_BSPLINE_HH
00010
00011 #include "Spline/DataPoint.hh"
00012 #include "Spline/Matrix.hh"
00013
00014 #include <gsl/gsl_bspline.h>
00015 #include <gsl/gsl_multifit.h>
00016
00017 #include <ostream>
00018 #include <vector>
00019
00020 namespace Spline{
00021
00022 using std::vector;
00023
00024 class BSpline{
00025
00026 public:
00027
00033 BSpline(size_t degree = 4);
00034
00039 void setKnotVector(const vector<double> &knots);
00040
00051 void setNCoefficientsUniform(size_t nCoeffs, double min, double max);
00052
00056 size_t nCoefficients()const;
00057
00068 double basisFunction(size_t index, double affine)const;
00069
00078 vector<double> basisFunctions(double affine)const;
00079
00083 void fitLeastSquares(const DataSet &data);
00084
00088 void fitLeastSquares(const DataSet &data, const DataSet &signalTemplate);
00089
00093 double chi2()const;
00094
00098 double chi2_dof()const;
00099
00107 DataPoint evaluate(double affine)const;
00108
00109
00113 const vector<double> &knots()const;
00114
00118 const vector<double> &coefficients()const;
00119
00125 double signalCoefficientSize()const;
00126
00132 const Matrix<double> &covarianceMatrix()const;
00133
00141 const PointSet &controlPoints()const;
00142
00143 private:
00144
00145 size_t m_nCoeffs;
00146 size_t m_nBreakPoints;
00147 size_t m_degree;
00148
00149 bool m_canEvaluate;
00150
00151 vector<double> m_knots;
00152
00153 gsl_vector *m_gslCoefficients;
00154 gsl_matrix *m_covarianceMatrix;
00155
00156 gsl_vector *_basisFuncCoeffs()const;
00157 mutable gsl_vector *m_basisFuncCoeffs;
00158
00159 bool m_haveSignalTemplate;
00160
00161
00162 vector<double> m_coefficients;
00163
00164 Matrix<double> m_covariance;
00165
00166 mutable PointSet m_controlPoints;
00167
00168 double m_chi2;
00169 double m_chi2_dof;
00170
00171 gsl_bspline_workspace *m_bSplineWorkspace;
00172
00173 };
00174 }
00175
00176 #endif
00177