Jpp  15.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JLegendreEstimator.hh
Go to the documentation of this file.
1 #ifndef __JFIT__JLEGENDREESTIMATOR__
2 #define __JFIT__JLEGENDREESTIMATOR__
3 
4 #include "JMath/JLegendre.hh"
5 #include "JMath/JZero.hh"
6 #include "JMath/JMatrixNS.hh"
7 #include "JFit/JEstimator.hh"
8 
9 
10 /**
11  * \file
12  * Linear fit of JMATH::JLegendre.
13  * \author mdejong
14  */
15 namespace JFIT {}
16 namespace JPP { using namespace JFIT; }
17 
18 namespace JFIT {
19 
20  using JMATH::JLegendre;
21 
22  /**
23  * Linear fit of Legendre polynomial.
24  */
25  template<class JOrdinate_t, size_t N>
26  class JEstimator< JLegendre<JOrdinate_t, N> > :
27  public JLegendre<JOrdinate_t, N>
28  {
29  public:
30  typedef JOrdinate_t ordinate_type;
31 
32 
33  /**
34  * Constructor.
35  *
36  * The template argument <tt>T</tt> refers to an iterator of a data structure which should have the following member methods:
37  * - double %getX(); //
38  * - ordinate_type %getY(); //
39  * where <tt>ordinate_type</tt> refers to the first template atgument of class JLegendre.
40  *
41  * \param __begin begin of data
42  * \param __end end of data
43  */
44  template<class T>
45  JEstimator(T __begin, T __end)
46  {
47  using namespace std;
48  using namespace JPP;
49 
50  if (distance(__begin, __end) >= NUMBER_OF_PARAMETERS) {
51 
52  vector<ordinate_type> Y(NUMBER_OF_PARAMETERS, getZero<ordinate_type>());
53  vector<double> h(NUMBER_OF_PARAMETERS, getZero<double>());
54 
55  V.resize(NUMBER_OF_PARAMETERS);
56  V.reset();
57 
58  T i = __begin;
59 
60  this->xmin = i->getX(); advance(i, distance(__begin, __end) - 1);
61  this->xmax = i->getX();
62 
63  for (i = __begin; i != __end; ++i) {
64 
65  const double z = this->getX(i->getX());
66 
67  for (size_t n = 0; n <= N; ++n) {
68  h[n] = legendre(n, z);
69  }
70 
71  for (size_t row = 0; row <= N; ++row) {
72 
73  V(row, row) += h[row] * h[row];
74  Y[row] += h[row] * i->getY();
75 
76  for (size_t col = 0; col != row; ++col) {
77  V(row, col) += h[row] * h[col];
78  }
79  }
80  }
81 
82  for (size_t row = 0; row <= N; ++row) {
83  for (size_t col = 0; col != row; ++col) {
84  V(col, row) = V(row, col);
85  }
86  }
87 
88  V.invert();
89 
90  for (size_t row = 0; row <= N; ++row) {
91 
92  (*this)[row] = zero;
93 
94  for (size_t col = 0; col <= N; ++col) {
95  (*this)[row] += V(row, col) * Y[col];
96  }
97  }
98 
99  } else {
100  throw JValueOutOfRange("JEstimator<JLegendre>::JEstimator(): Not enough data points.");
101  }
102  }
103 
104 
105  static const int NUMBER_OF_PARAMETERS = N + 1; //!< number of parameters of fit
106  JMATH::JMatrixNS V; //!< co-variance matrix of fit parameters
107  };
108 }
109 
110 #endif
Linear fit methods.
double getZero< double >()
Get zero value for double.
Definition: JZero.hh:60
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
Template definition of linear fit.
Definition: JEstimator.hh:25
Definition of zero value for any class.
const int n
Definition: JPolint.hh:660
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Template definition for function evaluation of Legendre polynome.
Definition: JLegendre.hh:213
N x N symmetric matrix.
Definition: JMatrixNS.hh:27
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
double legendre(const unsigned int n, const double x)
Legendre polynome.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
JMATH::JMatrixNS V
co-variance matrix of fit parameters