ROOT  6.06/09
Reference Guide
FitMethodFunction.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: L. Moneta Thu Aug 16 15:40:28 2007
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2007 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for class FitMethodFunction
12 
13 #ifndef ROOT_Math_FitMethodFunction
14 #define ROOT_Math_FitMethodFunction
15 
16 #ifndef ROOT_Math_IFunction
17 #include "Math/IFunction.h"
18 #endif
19 
20 // #ifndef ROOT_Math_IParamFunctionfwd
21 // #include "Math/IParamFunctionfwd.h"
22 // #endif
23 
24 namespace ROOT {
25 
26  namespace Math {
27 
28 //______________________________________________________________________________________
29 /**
30  FitMethodFunction class
31  Interface for objective functions (like chi2 and likelihood used in the fit)
32  In addition to normal function interface provide interface for calculating each
33  data contrinution to the function which is required by some algorithm (like Fumili)
34 
35  @ingroup FitMethodFunc
36 */
37 template<class FunctionType>
38 class BasicFitMethodFunction : public FunctionType {
39 
40 public:
41 
42 
43  typedef typename FunctionType::BaseFunc BaseFunction;
44 
45  /// enumeration specyfing the possible fit method types
47 
48 
49  BasicFitMethodFunction(int dim, int npoint) :
50  fNDim(dim),
51  fNPoints(npoint),
52  fNCalls(0)
53  {}
54 
55  /**
56  Virtual Destructor (no operations)
57  */
59 
60  /**
61  Number of dimension (parameters) . From IGenMultiFunction interface
62  */
63  virtual unsigned int NDim() const { return fNDim; }
64 
65  /**
66  method returning the data i-th contribution to the fit objective function
67  For example the residual for the least square functions or the pdf element for the
68  likelihood functions.
69  Estimating eventually also the gradient of the data element if the passed pointer is not null
70  */
71  virtual double DataElement(const double *x, unsigned int i, double *g = 0) const = 0;
72 
73 
74  /**
75  return the number of data points used in evaluating the function
76  */
77  virtual unsigned int NPoints() const { return fNPoints; }
78 
79  /**
80  return the type of method, override if needed
81  */
82  virtual Type_t Type() const { return kUndefined; }
83 
84  /**
85  return the total number of function calls (overrided if needed)
86  */
87  virtual unsigned int NCalls() const { return fNCalls; }
88 
89  /**
90  update number of calls
91  */
92  virtual void UpdateNCalls() const { fNCalls++; }
93 
94  /**
95  reset number of function calls
96  */
97  virtual void ResetNCalls() { fNCalls = 0; }
98 
99 
100 
101 public:
102 
103 
104 protected:
105 
106 
107 private:
108 
109  unsigned int fNDim; // function dimension
110  unsigned int fNPoints; // size of the data
111  mutable unsigned int fNCalls; // number of function calls
112 
113 
114 };
115 
116  // define the normal and gradient function
119 
120 
121  // useful template definition to use these interface in
122  // generic programming
123  // (comment them out since they are not used anymore)
124 /*
125  template<class FunType>
126  struct ParamFunctionTrait {
127  typedef IParamMultiFunction PFType;
128  };
129 
130  // specialization for the gradient param functions
131  template<>
132  struct ParamFunctionTrait<ROOT::Math::IMultiGradFunction> {
133  typedef IParamMultiGradFunction PFType;
134  };
135 */
136 
137 
138  } // end namespace Math
139 
140 } // end namespace ROOT
141 
142 
143 
144 
145 
146 
147 #endif /* ROOT_Math_FitMethodFunction */
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
virtual Type_t Type() const
return the type of method, override if needed
virtual ~BasicFitMethodFunction()
Virtual Destructor (no operations)
virtual unsigned int NPoints() const
return the number of data points used in evaluating the function
Double_t x[n]
Definition: legend1.C:17
virtual void ResetNCalls()
reset number of function calls
virtual unsigned int NDim() const
Number of dimension (parameters) .
FunctionType::BaseFunc BaseFunction
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
Definition: Fitter.h:57
Namespace for new Math classes and functions.
BasicFitMethodFunction< ROOT::Math::IMultiGradFunction > FitMethodGradFunction
Definition: Fitter.h:61
virtual void UpdateNCalls() const
update number of calls
BasicFitMethodFunction(int dim, int npoint)
virtual unsigned int NCalls() const
return the total number of function calls (overrided if needed)
Type_t
enumeration specyfing the possible fit method types
virtual double DataElement(const double *x, unsigned int i, double *g=0) const =0
method returning the data i-th contribution to the fit objective function For example the residual fo...
BasicFitMethodFunction< ROOT::Math::IMultiGenFunction > FitMethodFunction
Definition: Fitter.h:57