Belle II Software development
SphericityEigenvalues Class Reference

Class to calculate the Sphericity tensor eigenvalues and eigenvectors starting from an array of 3-momenta The tensor itself is not stored, only its eigenvalues and eigenvectors are. More...

#include <SphericityEigenvalues.h>

Public Member Functions

 SphericityEigenvalues (const std::vector< ROOT::Math::PxPyPzEVector > &momenta)
 Constructor with an array of 4-momenta.
 
 ~SphericityEigenvalues ()
 Default destructor.
 
void setMomenta (const std::vector< ROOT::Math::PxPyPzEVector > &momenta)
 Sets the list of momenta to be used in the calculation overwriting the previous values.
 
void calculateEigenvalues ()
 Calculates eigenvalues and eigenvectors.
 
double getEigenvalue (short i) const
 Returns the i-th Eigenvalue.
 
ROOT::Math::XYZVector getEigenvector (short i) const
 Returns the i-th Eigenvector.
 

Private Attributes

double m_lambda [3] = {0.}
 The eigenvalues.
 
ROOT::Math::XYZVector m_eVector [3]
 The eigenvectors.
 
std::vector< ROOT::Math::PxPyPzEVector > m_momenta
 The particles' momenta.
 

Detailed Description

Class to calculate the Sphericity tensor eigenvalues and eigenvectors starting from an array of 3-momenta The tensor itself is not stored, only its eigenvalues and eigenvectors are.

Definition at line 25 of file SphericityEigenvalues.h.

Constructor & Destructor Documentation

◆ SphericityEigenvalues()

SphericityEigenvalues ( const std::vector< ROOT::Math::PxPyPzEVector > &  momenta)
inlineexplicit

Constructor with an array of 4-momenta.

Definition at line 31 of file SphericityEigenvalues.h.

32 {
33 m_momenta.clear();
34 m_momenta = momenta;
35 }
std::vector< ROOT::Math::PxPyPzEVector > m_momenta
The particles' momenta.

◆ ~SphericityEigenvalues()

~SphericityEigenvalues ( )
inline

Default destructor.

Definition at line 40 of file SphericityEigenvalues.h.

40{};

Member Function Documentation

◆ calculateEigenvalues()

void calculateEigenvalues ( )

Calculates eigenvalues and eigenvectors.

Definition at line 17 of file SphericityEigenvalues.cc.

18{
19 Eigen::Matrix3f sphericityTensor;
20
21 // elements of the matrix, in rows
22 // n = r*3+c, using all 0-based indexes:
23 // 00 = 0
24 // 01 = 1
25 // 10 = 3
26 // 12 = 5
27 // 22 = 8
28 // etc...
29 // diagonal = 0, 4, 8
30 double elements[9] = {0.};
31
32 // normalization
33 double norm = 0;
34
35
36 if (m_momenta.size() < 2) {
37 B2WARNING("The particle list has less than 2 elements. The sphericity matrix will not be calculated");
38 return;
39 }
40
41 for (const auto& p : m_momenta) {
42 elements[0] += p.X() * p.X(); // diag
43 elements[1] += p.X() * p.Y();
44 elements[2] += p.X() * p.Z();
45
46 elements[3] += p.Y() * p.X();
47 elements[4] += p.Y() * p.Y(); // diag
48 elements[5] += p.Y() * p.Z();
49
50 elements[6] += p.Z() * p.X();
51 elements[7] += p.Z() * p.Y();
52 elements[8] += p.Z() * p.Z(); // diag
53 norm += p.P2();
54 }
55
56 for (short i = 0; i < 3; i++) {
57 for (short j = 0; j < 3; j++) {
58 sphericityTensor(i, j) = elements[i * 3 + j] / norm;
59 }
60 }
61
62 auto eigenVals = sphericityTensor.eigenvalues();
63 Eigen::ComplexEigenSolver<Eigen::MatrixXcf> ces(sphericityTensor);
64
65 // unfortunately Eigen does not provide the eigenvalues in
66 // any specific order, so we have to sort them and keep also the correct eigenvector-eigenvalue
67 // associations...
68
69 short order[3] = {0, 1, 2};
70
71 std::vector<float> tmpLambda;
72 for (short i = 0; i < 3; i++) {
73 tmpLambda.push_back(eigenVals[i].real());
74 }
75
76 // position of the largest Eigenvalue
77 order[0] = std::distance(tmpLambda.begin(), std::max_element(tmpLambda.begin(), tmpLambda.end()));
78 // position of the smallest Eigenvalue
79 order[2] = std::distance(tmpLambda.begin(), std::min_element(tmpLambda.begin(), tmpLambda.end()));
80 // position of the middle eigenvalue
81 order[1] = (short)(3.1 - (order[0] + order[2]));
82
83 for (short i = 0; i < 3; i++) {
84 short n = order[i];
85 m_lambda[i] = eigenVals[n].real();
86 auto eigenVector = ces.eigenvectors().col(n);
87 m_eVector[i].SetX(eigenVector[0].real());
88 m_eVector[i].SetY(eigenVector[1].real());
89 m_eVector[i].SetZ(eigenVector[2].real());
90 }
91
92 return;
93}
ROOT::Math::XYZVector m_eVector[3]
The eigenvectors.
double m_lambda[3]
The eigenvalues.

◆ getEigenvalue()

double getEigenvalue ( short  i) const
inline

Returns the i-th Eigenvalue.

Definition at line 63 of file SphericityEigenvalues.h.

64 {
65 return (i < 0 || i > 3) ? 0. : m_lambda[i];
66 }

◆ getEigenvector()

ROOT::Math::XYZVector getEigenvector ( short  i) const
inline

Returns the i-th Eigenvector.

Definition at line 71 of file SphericityEigenvalues.h.

72 {
73 ROOT::Math::XYZVector nullVector(0., 0., 0.);
74 return (i < 0 || i > 3) ? nullVector : m_eVector[i];
75 }

◆ setMomenta()

void setMomenta ( const std::vector< ROOT::Math::PxPyPzEVector > &  momenta)
inline

Sets the list of momenta to be used in the calculation overwriting the previous values.

Definition at line 47 of file SphericityEigenvalues.h.

48 {
49 m_momenta.clear();
50 m_momenta = momenta;
51 }

Member Data Documentation

◆ m_eVector

ROOT::Math::XYZVector m_eVector[3]
private

The eigenvectors.

Definition at line 80 of file SphericityEigenvalues.h.

◆ m_lambda

double m_lambda[3] = {0.}
private

The eigenvalues.

Definition at line 79 of file SphericityEigenvalues.h.

◆ m_momenta

std::vector<ROOT::Math::PxPyPzEVector> m_momenta
private

The particles' momenta.

Definition at line 81 of file SphericityEigenvalues.h.


The documentation for this class was generated from the following files: