Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEigenValues2D.hh
Go to the documentation of this file.
1 #ifndef __JEIGENVALUES2D__
2 #define __JEIGENVALUES2D__
3 
4 #include <cmath>
5 
6 #include "TMatrixDSymEigen.h"
7 
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 namespace JGEOMETRY2D {}
17 namespace JPP { using namespace JGEOMETRY2D; }
18 
19 namespace JGEOMETRY2D {
20 
21  /**
22  * Eigen values in 2D.
23  */
25  public JVector2D
26  {
27  public:
28  /**
29  * Constructor.
30  *
31  * \param __begin begin of data
32  * \param __end end of data
33  */
34  template<class T>
35  JEigenValues2D(T __begin,
36  T __end) :
37  JVector2D(),
38  N(0)
39  {
40  const JCenter2D center(__begin, __end);
41 
42  // RMS matrix
43 
44  TMatrixDSym A(2);
45 
46  for (int i = 0; i != 2; ++i) {
47  for (int j = 0; j != 2; ++j) {
48  A(i,j) = 0.0;
49  }
50  }
51 
52  for (T i = __begin; i != __end; ++i) {
53 
54  const double dx = center.getX() - i->getX();
55  const double dy = center.getY() - i->getY();
56 
57  A(0,0) += (dx * dx);
58  A(0,1) += (dx * dy);
59 
60  A(1,1) += (dy * dy);
61  }
62 
63  A(1,0) = A(0,1);
64 
65  const TVectorD V = TMatrixDSymEigen(A).GetEigenValues(); // copy!
66 
67  N = V.GetNoElements();
68 
69  switch (N) {
70 
71  case 2:
72  __y = V[1];
73 
74  case 1:
75  __x = V[0];
76  break;
77 
78  default:
79  break;
80  }
81  }
82 
83 
84  /**
85  * Get number of eigen values.
86  *
87  * \return number of eigen values
88  */
89  int getN() const
90  {
91  return N;
92  }
93 
94 
95  /**
96  * Get number of eigen values with minimal value.
97  *
98  * \param precision minimal value
99  * \return number of eigen values
100  */
101  int getN(double precision) const
102  {
103  int n = 0;
104 
105  if (fabs(getX()) >= precision) ++n;
106  if (fabs(getY()) >= precision) ++n;
107 
108  if (n > N)
109  return N;
110  else
111  return n;
112  }
113 
114 
115  protected:
116  int N;
117  };
118 }
119 
120 #endif
Data structure for vector in two dimensions.
Definition: JVector2D.hh:31
int getN() const
Get number of eigen values.
double getY() const
Get y position.
Definition: JVector2D.hh:73
Eigen values in 2D.
int getN(double precision) const
Get number of eigen values with minimal value.
double getX() const
Get x position.
Definition: JVector2D.hh:62
do set_variable OUTPUT_DIRECTORY $WORKDIR T
alias put_queue eval echo n
Definition: qlib.csh:19
JEigenValues2D(T __begin, T __end)
Constructor.
int j
Definition: JPolint.hh:634
source $JPP_DIR setenv csh $JPP_DIR eval JShellParser o a A