Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JSIRENE::JHitInertiaTensor Struct Reference

Class for hit inertia tensor calculations. More...

#include <JEventShapeVariables.hh>

Inheritance diagram for JSIRENE::JHitInertiaTensor:
JMATH::JMatrix3S JMATH::JMatrix3D JMATH::JMath< JMatrix3D > JLANG::JEquals< JFirst_t, JSecond_t >

Public Types

typedef JMatrix3S::eigen_values eigen_values
 

Public Member Functions

 JHitInertiaTensor ()
 Default constructor.
 
 JHitInertiaTensor (std::vector< Hit >::const_iterator __begin, std::vector< Hit >::const_iterator __end, const JPosition3D &reference)
 Constructor.
 
 JHitInertiaTensor (const Evt &event, const JPosition3D &reference)
 Constructor.
 
double getEigenvalueRatio () const
 Get eigenvalue ratio.
 
void invert ()
 Invert matrix.
 
eigen_values getEigenValues (const double epsilon=1e-6) const
 Get eigen values.
 
JMatrix3DsetIdentity ()
 Set to identity matrix.
 
void set (const JMatrix3D &A)
 Set matrix.
 
JMatrix3Dreset ()
 Set matrix to the null matrix.
 
JMatrix3Dtranspose ()
 Transpose.
 
JMatrix3Dnegate ()
 Negate matrix.
 
JMatrix3Dadd (const JMatrix3D &A)
 Matrix addition.
 
JMatrix3Dsub (const JMatrix3D &A)
 Matrix subtraction.
 
JMatrix3Dmul (const double factor)
 Scale matrix.
 
JMatrix3Dmul (const JMatrix3D &A, const JMatrix3D &B)
 Matrix multiplication.
 
JMatrix3Dmul (const JSecond_t &object)
 Multiply with object.
 
JMatrix3Ddiv (const double factor)
 Scale matrix.
 
bool equals (const JMatrix3D &A, const double eps=std::numeric_limits< double >::min()) const
 Equality.
 
bool isIdentity (const double eps=std::numeric_limits< double >::min()) const
 Test identity.
 
double getDeterminant () const
 Get determinant of matrix.
 
void transform (double &__x, double &__y, double &__z) const
 Transform.
 

Static Public Member Functions

static const JMatrix3DgetInstance ()
 Get reference to unique instance of this class object.
 
static const JMatrix3DgetIdentity ()
 Get reference to unique instance of this class object.
 

Public Attributes

double a00
 
double a01
 
double a02
 
double a10
 
double a11
 
double a12
 
double a20
 
double a21
 
double a22
 

Private Attributes

eigen_values lambda
 eigenvalues
 

Detailed Description

Class for hit inertia tensor calculations.


The given methods are inspired by section 5.2.2 of Stephanie Hickford's thesis.

Definition at line 395 of file JEventShapeVariables.hh.

Member Typedef Documentation

◆ eigen_values

Constructor & Destructor Documentation

◆ JHitInertiaTensor() [1/3]

JSIRENE::JHitInertiaTensor::JHitInertiaTensor ( )
inline

Default constructor.

Definition at line 404 of file JEventShapeVariables.hh.

405 {}

◆ JHitInertiaTensor() [2/3]

JSIRENE::JHitInertiaTensor::JHitInertiaTensor ( std::vector< Hit >::const_iterator __begin,
std::vector< Hit >::const_iterator __end,
const JPosition3D & reference )
inline

Constructor.

Parameters
__beginbeginning of hit data
__endend of hit data
referencereference position (e.g. the location of the interaction vertex)

Definition at line 415 of file JEventShapeVariables.hh.

418 {
419 using namespace std;
420 using namespace JPP;
421
422 for (vector<Hit>::const_iterator hit = __begin; hit != __end; ++hit) {
423
424 const JPosition3D D = sqrt(hit->a) * (getPosition(hit->pos) - reference);
425
426 a00 += D.getLengthSquared() - D.getX() * D.getX();
427 a01 += 0.0 - D.getX() * D.getY();
428 a02 += 0.0 - D.getX() * D.getZ();
429
430 a10 += 0.0 - D.getY() * D.getX();
431 a11 += D.getLengthSquared() - D.getY() * D.getY();
432 a12 += 0.0 - D.getY() * D.getZ();
433
434 a20 += 0.0 - D.getZ() * D.getX();
435 a21 += 0.0 - D.getZ() * D.getY();
436 a22 += D.getLengthSquared() - D.getZ() * D.getZ();
437 }
438
440 }
Data structure for position in three dimensions.
double getY() const
Get y position.
Definition JVector3D.hh:104
double getLengthSquared() const
Get length squared.
Definition JVector3D.hh:235
double getZ() const
Get z position.
Definition JVector3D.hh:115
double getX() const
Get x position.
Definition JVector3D.hh:94
eigen_values getEigenValues(const double epsilon=1e-6) const
Get eigen values.
Definition JMatrix3S.hh:227
JPosition3D getPosition(const Vec &pos)
Get position.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
eigen_values lambda
eigenvalues

◆ JHitInertiaTensor() [3/3]

JSIRENE::JHitInertiaTensor::JHitInertiaTensor ( const Evt & event,
const JPosition3D & reference )
inline

Constructor.

Parameters
eventevent
referencereference position (e.g. the location of the interaction vertex)

Definition at line 449 of file JEventShapeVariables.hh.

450 :
451 JHitInertiaTensor(event.hits.begin(), event.hits.end(), reference)
452 {}
std::vector< Hit > hits
list of hits
Definition Evt.hh:38
JHitInertiaTensor()
Default constructor.

Member Function Documentation

◆ getEigenvalueRatio()

double JSIRENE::JHitInertiaTensor::getEigenvalueRatio ( ) const
inline

Get eigenvalue ratio.

Returns
eigenvalue ratio

Definition at line 460 of file JEventShapeVariables.hh.

461 {
462 return lambda[2] / (lambda[0] + lambda[1] + lambda[2]);
463 }

◆ invert()

void JMATH::JMatrix3S::invert ( )
inlineinherited

Invert matrix.

Definition at line 80 of file JMatrix3S.hh.

81 {
82 using std::swap;
83
84 // LDU decomposition
85
86 int p0 = 0; // permute row 0
87 int p1 = 0; // permute row 1
88
89 double val;
90
91 val = a00;
92
93 if (fabs(a10) > fabs(val)) {
94 p0 = 1;
95 val = a10;
96 }
97
98 if (fabs(a20) > fabs(val)) {
99 p0 = 2;
100 val = a20;
101 }
102
103 switch (p0) {
104
105 case 1:
106 swap(a00,a10);
107 swap(a01,a11);
108 swap(a02,a12);
109 break;
110
111 case 2:
112 swap(a00,a20);
113 swap(a01,a21);
114 swap(a02,a22);
115 break;
116 }
117
118 if (val == 0) {
119 throw JDivisionByZero("LDU decomposition zero pivot");
120 }
121
122 a10 /= val;
123 a11 -= a10 * a01;
124 a12 -= a10 * a02;
125
126 a20 /= val;
127 a21 -= a20 * a01;
128 a22 -= a20 * a02;
129
130 val = a11;
131
132 if (fabs(a21) > fabs(val)) {
133 p1 = 2;
134 val = a21;
135 }
136
137 switch (p1) {
138
139 case 2:
140 swap(a10,a20);
141 swap(a11,a21);
142 swap(a12,a22);
143 break;
144 }
145
146 if (val == 0) {
147 throw JDivisionByZero("LDU decomposition zero pivot");
148 }
149
150 a21 /= val;
151 a22 -= a21 * a12;
152
153 // invert D
154
155 if (a22 == 0) {
156 throw JDivisionByZero("D matrix not invertable");
157 }
158
159 a00 = 1.0 / a00;
160 a11 = 1.0 / a11;
161 a22 = 1.0 / a22;
162
163 // invert U
164
165 a01 *= -a00;
166 a01 *= a11;
167
168 a02 *= -a00;
169 a02 -= a01 * a12;
170 a02 *= a22;
171
172 a12 *= -a11;
173 a12 *= a22;
174
175 // invert L
176
177 a21 = -a21;
178 a20 = -a20;
179 a20 -= a21 * a10;
180 a10 = -a10;
181
182 // U^-1 x L^-1
183
184 a00 += a01 * a10 + a02 * a20;
185 a01 += a02 * a21;
186 a10 *= a11;
187 a10 += a12 * a20;
188 a11 += a12 * a21;
189 a20 *= a22;
190 a21 *= a22;
191
192 switch (p1) {
193
194 case 2:
195 swap(a01,a02);
196 swap(a11,a12);
197 swap(a21,a22);
198 break;
199 }
200
201 switch (p0) {
202
203 case 1:
204 swap(a00,a01);
205 swap(a10,a11);
206 swap(a20,a21);
207 break;
208
209 case 2:
210 swap(a00,a02);
211 swap(a10,a12);
212 swap(a20,a22);
213 break;
214 }
215 }
TPaveText * p1

◆ getEigenValues()

eigen_values JMATH::JMatrix3S::getEigenValues ( const double epsilon = 1e-6) const
inlineinherited

Get eigen values.


The eigen values sorted in decreasing order of absolute values.
Algorithm taken from "Eigenvalues of a symmetric 3x3 matrix"
by Oliver K. Smith; see reference.

Parameters
epsilonprecision
Returns
eigen values

Definition at line 227 of file JMatrix3S.hh.

228 {
229 using namespace std;
230
231 eigen_values eigenvalues;
232
233 const double p1 = a01*a01 + a02*a02 + a12*a12;
234
235 if (fabs(p1 - 1.0) > epsilon) {
236
237 const double q = (a00 + a11 + a22) / 3.0;
238 const double p2 = (a00 - q)*(a00 - q) + (a11 - q)*(a11 - q) + (a22 - q)*(a22 - q) + 2*p1;
239 const double p = sqrt(p2 / 6.0);
240
241 JMatrix3S B(*this);
242
243 B.sub(q * JMatrix3D::getIdentity());
244 B.div(p);
245
246 const double r = B.getDeterminant() / 2.0;
247 const double phi = (r < -1.0 ? PI / 3.0 : (r > 1.0 ? 0.0 : acos(r) / 3.0));
248
249 eigenvalues[0] = q + 2*p*cos(phi);
250 eigenvalues[2] = q + 2*p*cos(phi + 2*PI/3.0);
251 eigenvalues[1] = 3 * q - eigenvalues[0] - eigenvalues[2];
252
253 } else {
254
255 eigenvalues = eigen_values{ a00, a11, a12 };
256 }
257
258 // sort absolute values in descending order
259
260 if (fabs(eigenvalues[0]) < fabs(eigenvalues[1])) {
261 swap(eigenvalues[0], eigenvalues[1]);
262 }
263
264 if (fabs(eigenvalues[1]) < fabs(eigenvalues[2])) {
265
266 swap(eigenvalues[1], eigenvalues[2]);
267
268 if (fabs(eigenvalues[0]) < fabs(eigenvalues[1])) {
269 swap(eigenvalues[0], eigenvalues[1]);
270 }
271 }
272
273 return eigenvalues;
274 }
static const JMatrix3D & getIdentity()
Get reference to unique instance of this class object.
std::array< double, 3 > eigen_values
Type definition of Eigen values.
Definition JMatrix3S.hh:36
JMatrix3S()
Default constructor.
Definition JMatrix3S.hh:42

◆ getInstance()

static const JMatrix3D & JMATH::JMatrix3D::getInstance ( )
inlinestaticinherited

Get reference to unique instance of this class object.

Returns
zero matrix

Definition at line 78 of file JMath/JMatrix3D.hh.

79 {
80 static JMatrix3D matrix;
81
82 return matrix;
83 }
JMatrix3D()
Default constructor.

◆ setIdentity()

JMatrix3D & JMATH::JMatrix3D::setIdentity ( )
inlineinherited

Set to identity matrix.

Returns
this matrix

Definition at line 91 of file JMath/JMatrix3D.hh.

92 {
93 a00 = 1.0; a01 = 0.0; a02 = 0.0;
94 a10 = 0.0; a11 = 1.0; a12 = 0.0;
95 a20 = 0.0; a21 = 0.0; a22 = 1.0;
96
97 return *this;
98 }

◆ getIdentity()

static const JMatrix3D & JMATH::JMatrix3D::getIdentity ( )
inlinestaticinherited

Get reference to unique instance of this class object.

Returns
identity matrix

Definition at line 106 of file JMath/JMatrix3D.hh.

107 {
108 static JMatrix3D matrix(JMatrix3D().setIdentity());
109
110 return matrix;
111 }
JMatrix3D & setIdentity()
Set to identity matrix.

◆ set()

void JMATH::JMatrix3D::set ( const JMatrix3D & A)
inlineinherited

Set matrix.

Parameters
Amatrix

Definition at line 119 of file JMath/JMatrix3D.hh.

120 {
121 static_cast<JMatrix3D&>(*this) = A;
122 }

◆ reset()

JMatrix3D & JMATH::JMatrix3D::reset ( )
inlineinherited

Set matrix to the null matrix.

Returns
this matrix

Definition at line 130 of file JMath/JMatrix3D.hh.

131 {
132 *this = JMatrix3D();
133
134 return *this;
135 }

◆ transpose()

JMatrix3D & JMATH::JMatrix3D::transpose ( )
inlineinherited

Transpose.

Returns
this matrix

Definition at line 143 of file JMath/JMatrix3D.hh.

144 {
145 using std::swap;
146
147 swap(a10, a01);
148 swap(a20, a02);
149 swap(a21, a12);
150
151 return *this;
152 }

◆ negate()

JMatrix3D & JMATH::JMatrix3D::negate ( )
inlineinherited

Negate matrix.

Returns
-this matrix

Definition at line 160 of file JMath/JMatrix3D.hh.

161 {
162 a00 = -a00; a01 = -a01; a02 = -a02;
163 a10 = -a10; a11 = -a11; a12 = -a12;
164 a20 = -a20; a21 = -a21; a22 = -a22;
165
166 return *this;
167 }

◆ add()

JMatrix3D & JMATH::JMatrix3D::add ( const JMatrix3D & A)
inlineinherited

Matrix addition.

Parameters
Amatrix
Returns
this matrix + A

Definition at line 176 of file JMath/JMatrix3D.hh.

177 {
178 a00 += A.a00; a01 += A.a01; a02 += A.a02;
179 a10 += A.a10; a11 += A.a11; a12 += A.a12;
180 a20 += A.a20; a21 += A.a21; a22 += A.a22;
181
182 return *this;
183 }

◆ sub()

JMatrix3D & JMATH::JMatrix3D::sub ( const JMatrix3D & A)
inlineinherited

Matrix subtraction.

Parameters
Amatrix
Returns
this matrix - A

Definition at line 192 of file JMath/JMatrix3D.hh.

193 {
194 a00 -= A.a00; a01 -= A.a01; a02 -= A.a02;
195 a10 -= A.a10; a11 -= A.a11; a12 -= A.a12;
196 a20 -= A.a20; a21 -= A.a21; a22 -= A.a22;
197
198 return *this;
199 }

◆ mul() [1/3]

JMatrix3D & JMATH::JMatrix3D::mul ( const double factor)
inlineinherited

Scale matrix.

Parameters
factorfactor
Returns
this matrix * factor

Definition at line 208 of file JMath/JMatrix3D.hh.

209 {
210 a00 *= factor; a01 *= factor; a02 *= factor;
211 a10 *= factor; a11 *= factor; a12 *= factor;
212 a20 *= factor; a21 *= factor; a22 *= factor;
213
214 return *this;
215 }

◆ mul() [2/3]

JMatrix3D & JMATH::JMatrix3D::mul ( const JMatrix3D & A,
const JMatrix3D & B )
inlineinherited

Matrix multiplication.

Parameters
Amatrix
Bmatrix
Returns
this matrix

Definition at line 241 of file JMath/JMatrix3D.hh.

243 {
244 a00 = A.a00 * B.a00 + A.a01 * B.a10 + A.a02 * B.a20;
245 a01 = A.a00 * B.a01 + A.a01 * B.a11 + A.a02 * B.a21;
246 a02 = A.a00 * B.a02 + A.a01 * B.a12 + A.a02 * B.a22;
247
248 a10 = A.a10 * B.a00 + A.a11 * B.a10 + A.a12 * B.a20;
249 a11 = A.a10 * B.a01 + A.a11 * B.a11 + A.a12 * B.a21;
250 a12 = A.a10 * B.a02 + A.a11 * B.a12 + A.a12 * B.a22;
251
252 a20 = A.a20 * B.a00 + A.a21 * B.a10 + A.a22 * B.a20;
253 a21 = A.a20 * B.a01 + A.a21 * B.a11 + A.a22 * B.a21;
254 a22 = A.a20 * B.a02 + A.a21 * B.a12 + A.a22 * B.a22;
255
256 return *this;
257 }

◆ mul() [3/3]

JMatrix3D & JMATH::JMath< JMatrix3D, JSecond_t >::mul ( const JSecond_t & object)
inlineinherited

Multiply with object.

Parameters
objectobject
Returns
result object

Definition at line 354 of file JMath.hh.

355 {
356 return static_cast<JFirst_t&>(*this) = JFirst_t().mul(static_cast<const JFirst_t&>(*this), object);
357 }

◆ div()

JMatrix3D & JMATH::JMatrix3D::div ( const double factor)
inlineinherited

Scale matrix.

Parameters
factorfactor
Returns
this matrix / factor

Definition at line 224 of file JMath/JMatrix3D.hh.

225 {
226 a00 /= factor; a01 /= factor; a02 /= factor;
227 a10 /= factor; a11 /= factor; a12 /= factor;
228 a20 /= factor; a21 /= factor; a22 /= factor;
229
230 return *this;
231 }

◆ equals()

bool JMATH::JMatrix3D::equals ( const JMatrix3D & A,
const double eps = std::numeric_limits<double>::min() ) const
inlineinherited

Equality.

Parameters
Amatrix
epsnumerical precision
Returns
true if matrices identical; else false

Definition at line 267 of file JMath/JMatrix3D.hh.

269 {
270 return (fabs(a00 - A.a00) <= eps &&
271 fabs(a01 - A.a01) <= eps &&
272 fabs(a02 - A.a02) <= eps &&
273 fabs(a10 - A.a10) <= eps &&
274 fabs(a11 - A.a11) <= eps &&
275 fabs(a12 - A.a12) <= eps &&
276 fabs(a20 - A.a20) <= eps &&
277 fabs(a21 - A.a21) <= eps &&
278 fabs(a22 - A.a22) <= eps);
279 }

◆ isIdentity()

bool JMATH::JMatrix3D::isIdentity ( const double eps = std::numeric_limits<double>::min()) const
inlineinherited

Test identity.

Parameters
epsnumerical precision
Returns
true if identity matrix; else false

Definition at line 288 of file JMath/JMatrix3D.hh.

289 {
290 return equals(getIdentity(), eps);
291 }
bool equals(const JMatrix3D &A, const double eps=std::numeric_limits< double >::min()) const
Equality.

◆ getDeterminant()

double JMATH::JMatrix3D::getDeterminant ( ) const
inlineinherited

Get determinant of matrix.

Returns
determinant of matrix

Definition at line 299 of file JMath/JMatrix3D.hh.

300 {
301 double det = 0.0;
302
303 det += a00 * (a11 * a22 - a21 * a12);
304 det -= a01 * (a10 * a22 - a20 * a12);
305 det += a02 * (a10 * a21 - a20 * a11);
306
307 return det;
308 }

◆ transform()

void JMATH::JMatrix3D::transform ( double & __x,
double & __y,
double & __z ) const
inlineinherited

Transform.

Parameters
__xx value
__yy value
__zz value

Definition at line 318 of file JMath/JMatrix3D.hh.

319 {
320 const double x = a00 * __x + a01 * __y + a02 * __z;
321 const double y = a10 * __x + a11 * __y + a12 * __z;
322 const double z = a20 * __x + a21 * __y + a22 * __z;
323
324 __x = x;
325 __y = y;
326 __z = z;
327 }

Member Data Documentation

◆ lambda

eigen_values JSIRENE::JHitInertiaTensor::lambda
private

eigenvalues

Definition at line 467 of file JEventShapeVariables.hh.

◆ a00

double JMATH::JMatrix3D::a00
inherited

Definition at line 385 of file JMath/JMatrix3D.hh.

◆ a01

double JMATH::JMatrix3D::a01
inherited

Definition at line 385 of file JMath/JMatrix3D.hh.

◆ a02

double JMATH::JMatrix3D::a02
inherited

Definition at line 385 of file JMath/JMatrix3D.hh.

◆ a10

double JMATH::JMatrix3D::a10
inherited

Definition at line 386 of file JMath/JMatrix3D.hh.

◆ a11

double JMATH::JMatrix3D::a11
inherited

Definition at line 386 of file JMath/JMatrix3D.hh.

◆ a12

double JMATH::JMatrix3D::a12
inherited

Definition at line 386 of file JMath/JMatrix3D.hh.

◆ a20

double JMATH::JMatrix3D::a20
inherited

Definition at line 387 of file JMath/JMatrix3D.hh.

◆ a21

double JMATH::JMatrix3D::a21
inherited

Definition at line 387 of file JMath/JMatrix3D.hh.

◆ a22

double JMATH::JMatrix3D::a22
inherited

Definition at line 387 of file JMath/JMatrix3D.hh.


The documentation for this struct was generated from the following file: