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