Belle II Software development
SphericityEigenvalues.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9
10#include <analysis/ContinuumSuppression/SphericityEigenvalues.h>
11#include <framework/logging/Logger.h>
12#include <Eigen/Core>
13#include <Eigen/Eigenvalues>
14
15using namespace Belle2;
16
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}
94
std::vector< ROOT::Math::PxPyPzEVector > m_momenta
The particles' momenta.
void calculateEigenvalues()
Calculates eigenvalues and eigenvectors.
ROOT::Math::XYZVector m_eVector[3]
The eigenvectors.
double m_lambda[3]
The eigenvalues.
Abstract base class for different kinds of events.