QMathFunction.hh
Go to the documentation of this file.00001 #ifndef _Q_MATH_FUNCTION_
00002 #define _Q_MATH_FUNCTION_
00003
00009 #include <gsl/gsl_math.h>
00010 #include "QCuore.hh"
00011 #include "QError.hh"
00012 #include <vector>
00013
00014 class TF1;
00015
00016 Q_BEGIN_NAMESPACE
00017
00018 class QMathFunction
00019 {
00020 public:
00022 typedef double(*QRoutinePointer)(double,double* params);
00023
00025 QMathFunction(QRoutinePointer funcpointer, unsigned int NParameters, double LowBound, double UpBound);
00026
00028 QMathFunction(const QMathFunction& func);
00029
00031 virtual ~QMathFunction();
00032
00034 const QMathFunction& operator=(const QMathFunction& func);
00035
00037 void SetParameter(unsigned int p, double val);
00038
00040 void SetParameter(unsigned int p, const char* name, double val);
00041
00043 void SetParameters(const double* param) {memcpy(fParameters,param,sizeof(double)*fNParameters); }
00044
00046 double GetParameter(unsigned int p) const {return fParameters[p]; }
00047
00049 const double* GetParameters() const {return fParameters; }
00050
00052 size_t GetNParameters() const {return fNParameters; }
00053
00055 double Eval(double x) const { return (*fRoutine)(x,fParameters);}
00056
00058 double Eval(double x, double* params) const { return (*fRoutine)(x,params);}
00059
00061 virtual void Print();
00062
00064 void SetVerbose(bool verbose = true) { fVerbose = verbose; }
00065
00067 virtual void SetTF1(TF1& tf1);
00068
00076 QError GetMinimum(double& min, double &minpos, double epsabs = 0.001, double epsrel = 0.0);
00077
00085 QError GetMaximum(double& max, double &maxpos, double epsabs = 0.001, double epsrel = 0.0);
00086
00087 protected:
00089 gsl_function GetGSLFunction();
00090
00092 void SetParName(unsigned int p,const char* name) { if(p < fNParameters) fParNames[p] = name; }
00094 QRoutinePointer fRoutine;
00095
00097 size_t fNParameters;
00098
00100 double* fParameters;
00101
00103 std::vector<const char*> fParNames;
00104
00106 double fLowBound;
00108 double fUpBound;
00109
00111 bool fVerbose;
00112
00113 friend class QMinimizer;
00114 };
00115
00116 Q_END_NAMESPACE
00117
00118 #endif