Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JRegressor.hh
Go to the documentation of this file.
1 #ifndef __JFIT__JREGRESSOR__
2 #define __JFIT__JREGRESSOR__
3 
4 #include "Jeep/JMessage.hh"
5 
6 
7 /**
8  * \file
9  * General purpose data regression method.
10  * \author mdejong
11  */
12 namespace JFIT {}
13 namespace JPP { using namespace JFIT; }
14 
15 namespace JFIT {
16 
17  using JEEP::JMessage;
18 
19 
20  /**
21  * Abstract minimiser.
22  * This "minimiser" can be used to determine the chi2 of the data for a given model value.
23  */
24  template<class JModel_t>
26  public JMessage< JAbstractMinimiser<JModel_t> >
27  {
28  /**
29  * Default constructor.
30  */
32  {}
33 
34 
35  /**
36  * Get chi2.
37  *
38  * \param fit fit function
39  * \param __begin begin of data
40  * \param __end end of data
41  * \return chi2
42  */
43  template<class JFunction_t, class T>
44  double operator()(const JFunction_t& fit, T __begin, T __end)
45  {
46  double chi2 = 0.0;
47 
48  for (T i = __begin; i != __end; ++i) {
49  chi2 += fit(value, *i);
50  }
51 
52  return chi2;
53  }
54 
55  JModel_t value; //!< model value
56  };
57 
58 
59  /**
60  * Template definition of a data regressor of given model.
61  *
62  * The first template argument refers to the model that should be fitted to the data and
63  * the second to the type of minimiser.
64  */
65  template<class JModel_t, template<class> class JMinimiser_t = JAbstractMinimiser>
66  struct JRegressor;
67 
68 
69  /**
70  * Abstract class for global fit method.
71  */
72  template<class JModel_t, template<class> class JMinimiser_t = JAbstractMinimiser>
74  public JMinimiser_t<JModel_t>
75  {
76  typedef JMinimiser_t<JModel_t> minimiser_type;
78 
79 
80  /**
81  * Global fit.
82  *
83  * \param value start value
84  * \param __begin begin of data set
85  * \param __end end of data set
86  * \return chi2
87  */
88  template<class T>
89  double operator()(const JModel_t& value, T __begin, T __end)
90  {
91  static_cast<minimiser_type&>(*this).value = value;
92 
93  return static_cast<minimiser_type&>(*this)(static_cast<regressor_type&>(*this), __begin, __end);
94  }
95 
96 
97  /**
98  * Global fit.
99  *
100  * \param value start value
101  * \param __begin1 begin of first data set
102  * \param __end1 end of first data set
103  * \param __begin2 begin of second data set
104  * \param __end2 end of second data set
105  * \return chi2
106  */
107  template<class T1, class T2>
108  double operator()(const JModel_t& value,
109  T1 __begin1, T1 __end1,
110  T2 __begin2, T2 __end2)
111  {
112  static_cast<minimiser_type&>(*this).value = value;
113 
114  return static_cast<minimiser_type&>(*this)(static_cast<regressor_type&>(*this), __begin1, __end1, __begin2, __end2);
115  }
116  };
117 }
118 
119 #endif
Template definition of a data regressor of given model.
Definition: JRegressor.hh:66
JMinimiser_t< JModel_t > minimiser_type
Definition: JRegressor.hh:76
Abstract minimiser.
Definition: JRegressor.hh:25
double operator()(const JModel_t &value, T1 __begin1, T1 __end1, T2 __begin2, T2 __end2)
Global fit.
Definition: JRegressor.hh:108
double operator()(const JModel_t &value, T __begin, T __end)
Global fit.
Definition: JRegressor.hh:89
double operator()(const JFunction_t &fit, T __begin, T __end)
Get chi2.
Definition: JRegressor.hh:44
JRegressor< JModel_t, JMinimiser_t > regressor_type
Definition: JRegressor.hh:77
Regressor function object for JPoint4D fit using JSimplex minimiser.
JModel_t value
Definition: JSimplex.hh:227
General purpose messaging.
JAbstractMinimiser()
Default constructor.
Definition: JRegressor.hh:31
JModel_t value
model value
Definition: JRegressor.hh:55
Abstract class for global fit method.
Definition: JRegressor.hh:73
Auxiliary class for handling debug parameter within a class.
Definition: JMessage.hh:42