Diana Software
QMathFunction.hh
Go to the documentation of this file.
1 #ifndef _Q_MATH_FUNCTION_
2 #define _Q_MATH_FUNCTION_
9 #include <gsl/gsl_math.h>
10 #include "QDiana.hh"
11 #include "QError.hh"
12 #include <vector>
13 
14 class TF1;
15 
17 
19 {
20  public:
22  #ifndef __CINT__
23  typedef double(*QRoutinePointer)(double,double* params);
24 
26  QMathFunction(QRoutinePointer funcpointer, unsigned int NParameters, double LowBound, double UpBound);
27  #endif
28 
30  QMathFunction(const QMathFunction& func);
31 
33  virtual ~QMathFunction();
34 
36  const QMathFunction& operator=(const QMathFunction& func);
37 
39  void SetParameter(unsigned int p, double val);
40 
42  void SetParameter(unsigned int p, const char* name, double val);
43 
45  void SetParameters(const double* param) {memcpy(fParameters,param,sizeof(double)*fNParameters); }
46 
48  double GetParameter(unsigned int p) const {return fParameters[p]; }
49 
51  const double* GetParameters() const {return fParameters; }
52 
54  size_t GetNParameters() const {return fNParameters; }
55 
57  double Eval(double x) const { return (*fRoutine)(x,fParameters);}
58 
60  double Eval(double x, double* params) const { return (*fRoutine)(x,params);}
61 
63  virtual void Print();
64 
66  void SetVerbose(bool verbose = true) { fVerbose = verbose; }
67 
69  virtual void SetTF1(TF1& tf1);
70 
78  QError GetMinimum(double& min, double &minpos, double epsabs = 0.001, double epsrel = 0.0);
79 
87  QError GetMaximum(double& max, double &maxpos, double epsabs = 0.001, double epsrel = 0.0);
88 
89  protected:
91  gsl_function GetGSLFunction();
92 
94  void SetParName(unsigned int p,const char* name) { if(p < fNParameters) fParNames[p] = name; }
96  #ifndef __CINT__
98  #endif
99 
101  size_t fNParameters;
102 
104  double* fParameters;
105 
107  std::vector<const char*> fParNames;
108 
110  double fLowBound;
112  double fUpBound;
113 
115  bool fVerbose;
116 
117  friend class QMinimizer;
118 };
119 
121 
122 #endif
int maxpos
Definition: CheckOFShape.C:59
double max
Definition: CheckOF.C:53
#define Q_END_NAMESPACE
Definition: QDiana.hh:22
#define Q_BEGIN_NAMESPACE
Definition: QDiana.hh:20
double min(const Diana::QVector &v)
Definition: QVector.cc:878
error class with error type and description
Definition: QError.hh:115
generic C++ interface on static functions
size_t fNParameters
number of parameters
virtual void Print()
print parameters and names if set
QMathFunction(QRoutinePointer funcpointer, unsigned int NParameters, double LowBound, double UpBound)
constructor
gsl_function GetGSLFunction()
return a gsl function
Definition: QMathFunction.cc:8
size_t GetNParameters() const
get number of parameters
const double * GetParameters() const
pointer to array of parameters
bool fVerbose
verbose
const QMathFunction & operator=(const QMathFunction &func)
operator=
QError GetMinimum(double &min, double &minpos, double epsabs=0.001, double epsrel=0.0)
get function minimum
double fUpBound
high function bound
void SetParameter(unsigned int p, double val)
set parameter value
QError GetMaximum(double &max, double &maxpos, double epsabs=0.001, double epsrel=0.0)
get function maximum
double Eval(double x) const
evaluate function
void SetParameters(const double *param)
set all parameters from an array that has to be well sized
virtual ~QMathFunction()
destructor
void SetParName(unsigned int p, const char *name)
set parameter name
std::vector< const char * > fParNames
parameters names
void SetVerbose(bool verbose=true)
set verbose
QRoutinePointer fRoutine
pointer to the underlying static function
double fLowBound
low function bound
double GetParameter(unsigned int p) const
get parameter
double(* QRoutinePointer)(double, double *params)
pointer to function
double * fParameters
array of parameters
double Eval(double x, double *params) const
evaluate function with external parameters
virtual void SetTF1(TF1 &tf1)
set parameters from ROOT TF1
find maximum and minimum of a QMathFunction, the minimum search stops when |a - b| < epsabs + epsrel ...
Definition: QMinimizer.hh:20