EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TestRootEigenTransformations.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TestRootEigenTransformations.cpp
1 #include <gtest/gtest.h>
2 
3 #include <TVectorD.h>
4 #include <Eigen/Dense>
5 
7 
8 namespace genfit {
9 
10  class RootEigenTransformations : public ::testing::Test {
11  protected:
12  };
13 
14  TEST_F(RootEigenTransformations, VectorTransformation) {
15  TVectorD myTVectorD(5);
16  myTVectorD(0) = 0.5;
17  myTVectorD(0) = 0.4;
18  myTVectorD(0) = 0.3;
19  myTVectorD(0) = 0.2;
20  myTVectorD(0) = 0.1;
21 
22  const auto myEigenVector(rootVectorToEigenVector<5>(myTVectorD));
23  EXPECT_EQ(myTVectorD(0), myEigenVector(0));
24  EXPECT_EQ(myTVectorD(1), myEigenVector(1));
25  EXPECT_EQ(myTVectorD(2), myEigenVector(2));
26  EXPECT_EQ(myTVectorD(3), myEigenVector(3));
27  EXPECT_EQ(myTVectorD(4), myEigenVector(4));
28 
29  const auto myRootVector(eigenVectorToRootVector<5>(myEigenVector));
30  EXPECT_EQ(myTVectorD(0), myRootVector(0));
31  EXPECT_EQ(myTVectorD(1), myRootVector(1));
32  EXPECT_EQ(myTVectorD(2), myRootVector(2));
33  EXPECT_EQ(myTVectorD(3), myRootVector(3));
34  EXPECT_EQ(myTVectorD(4), myRootVector(4));
35  }
36 
37  TEST_F(RootEigenTransformations, SymmetricMatrixTransformation) {
38  TMatrixDSym myTMatrixDSym(5);
39  for (unsigned int row=0; row<5; ++row) {
40  for (unsigned int col=0; col<5; ++col) {
41  myTMatrixDSym(row, col) = row*col; // Put some non-zero value here.
42  }
43  }
44 
45  const auto myEigenMatrix(rootMatrixSymToEigenMatrix<5>(myTMatrixDSym));
46  EXPECT_EQ(myTMatrixDSym(0, 0), myEigenMatrix(0, 0));
47  EXPECT_EQ(myTMatrixDSym(0, 1), myEigenMatrix(0, 1));
48  EXPECT_EQ(myTMatrixDSym(0, 2), myEigenMatrix(0, 2));
49  EXPECT_EQ(myTMatrixDSym(0, 3), myEigenMatrix(0, 3));
50  EXPECT_EQ(myTMatrixDSym(0, 4), myEigenMatrix(0, 4));
51  EXPECT_EQ(myTMatrixDSym(1, 0), myEigenMatrix(1, 0));
52  EXPECT_EQ(myTMatrixDSym(1, 1), myEigenMatrix(1, 1));
53  EXPECT_EQ(myTMatrixDSym(1, 2), myEigenMatrix(1, 2));
54  EXPECT_EQ(myTMatrixDSym(1, 3), myEigenMatrix(1, 3));
55  EXPECT_EQ(myTMatrixDSym(1, 4), myEigenMatrix(1, 4));
56  EXPECT_EQ(myTMatrixDSym(2, 0), myEigenMatrix(2, 0));
57  EXPECT_EQ(myTMatrixDSym(2, 1), myEigenMatrix(2, 1));
58  EXPECT_EQ(myTMatrixDSym(2, 2), myEigenMatrix(2, 2));
59  EXPECT_EQ(myTMatrixDSym(2, 3), myEigenMatrix(2, 3));
60  EXPECT_EQ(myTMatrixDSym(2, 4), myEigenMatrix(2, 4));
61  EXPECT_EQ(myTMatrixDSym(3, 0), myEigenMatrix(3, 0));
62  EXPECT_EQ(myTMatrixDSym(3, 1), myEigenMatrix(3, 1));
63  EXPECT_EQ(myTMatrixDSym(3, 2), myEigenMatrix(3, 2));
64  EXPECT_EQ(myTMatrixDSym(3, 3), myEigenMatrix(3, 3));
65  EXPECT_EQ(myTMatrixDSym(3, 4), myEigenMatrix(3, 4));
66  EXPECT_EQ(myTMatrixDSym(4, 0), myEigenMatrix(4, 0));
67  EXPECT_EQ(myTMatrixDSym(4, 1), myEigenMatrix(4, 1));
68  EXPECT_EQ(myTMatrixDSym(4, 2), myEigenMatrix(4, 2));
69  EXPECT_EQ(myTMatrixDSym(4, 3), myEigenMatrix(4, 3));
70  EXPECT_EQ(myTMatrixDSym(4, 4), myEigenMatrix(4, 4));
71 
72  const auto myRootMatrix(eigenMatrixToRootMatrixSym<5>(myEigenMatrix));
73  EXPECT_EQ(myTMatrixDSym(0, 0), myRootMatrix(0, 0));
74  EXPECT_EQ(myTMatrixDSym(0, 1), myRootMatrix(0, 1));
75  EXPECT_EQ(myTMatrixDSym(0, 2), myRootMatrix(0, 2));
76  EXPECT_EQ(myTMatrixDSym(0, 3), myRootMatrix(0, 3));
77  EXPECT_EQ(myTMatrixDSym(0, 4), myRootMatrix(0, 4));
78  EXPECT_EQ(myTMatrixDSym(1, 0), myRootMatrix(1, 0));
79  EXPECT_EQ(myTMatrixDSym(1, 1), myRootMatrix(1, 1));
80  EXPECT_EQ(myTMatrixDSym(1, 2), myRootMatrix(1, 2));
81  EXPECT_EQ(myTMatrixDSym(1, 3), myRootMatrix(1, 3));
82  EXPECT_EQ(myTMatrixDSym(1, 4), myRootMatrix(1, 4));
83  EXPECT_EQ(myTMatrixDSym(2, 0), myRootMatrix(2, 0));
84  EXPECT_EQ(myTMatrixDSym(2, 1), myRootMatrix(2, 1));
85  EXPECT_EQ(myTMatrixDSym(2, 2), myRootMatrix(2, 2));
86  EXPECT_EQ(myTMatrixDSym(2, 3), myRootMatrix(2, 3));
87  EXPECT_EQ(myTMatrixDSym(2, 4), myRootMatrix(2, 4));
88  EXPECT_EQ(myTMatrixDSym(3, 0), myRootMatrix(3, 0));
89  EXPECT_EQ(myTMatrixDSym(3, 1), myRootMatrix(3, 1));
90  EXPECT_EQ(myTMatrixDSym(3, 2), myRootMatrix(3, 2));
91  EXPECT_EQ(myTMatrixDSym(3, 3), myRootMatrix(3, 3));
92  EXPECT_EQ(myTMatrixDSym(3, 4), myRootMatrix(3, 4));
93  EXPECT_EQ(myTMatrixDSym(4, 0), myRootMatrix(4, 0));
94  EXPECT_EQ(myTMatrixDSym(4, 1), myRootMatrix(4, 1));
95  EXPECT_EQ(myTMatrixDSym(4, 2), myRootMatrix(4, 2));
96  EXPECT_EQ(myTMatrixDSym(4, 3), myRootMatrix(4, 3));
97  EXPECT_EQ(myTMatrixDSym(4, 4), myRootMatrix(4, 4));
98 
99  }
100 
101  TEST_F(RootEigenTransformations, MatrixTransformation) {
102  const unsigned int rows = 7;
103  const unsigned int cols = 5;
104  TMatrixD myTMatrix(rows, cols);
105  for (unsigned int row=0; row<rows; ++row) {
106  for (unsigned int col=0; col<cols; ++col) {
107  myTMatrix(row, col) = (row+1)*(col*col+1); // Put some non-zero value here.
108  }
109  }
110 
111  const auto myEigenMatrix(rootMatrixToEigenMatrix<7, 5>(myTMatrix));
112  EXPECT_EQ(myTMatrix(0, 0), myEigenMatrix(0, 0));
113  EXPECT_EQ(myTMatrix(0, 1), myEigenMatrix(0, 1));
114  EXPECT_EQ(myTMatrix(0, 2), myEigenMatrix(0, 2));
115  EXPECT_EQ(myTMatrix(0, 3), myEigenMatrix(0, 3));
116  EXPECT_EQ(myTMatrix(0, 4), myEigenMatrix(0, 4));
117  EXPECT_EQ(myTMatrix(1, 0), myEigenMatrix(1, 0));
118  EXPECT_EQ(myTMatrix(1, 1), myEigenMatrix(1, 1));
119  EXPECT_EQ(myTMatrix(1, 2), myEigenMatrix(1, 2));
120  EXPECT_EQ(myTMatrix(1, 3), myEigenMatrix(1, 3));
121  EXPECT_EQ(myTMatrix(1, 4), myEigenMatrix(1, 4));
122  EXPECT_EQ(myTMatrix(2, 0), myEigenMatrix(2, 0));
123  EXPECT_EQ(myTMatrix(2, 1), myEigenMatrix(2, 1));
124  EXPECT_EQ(myTMatrix(2, 2), myEigenMatrix(2, 2));
125  EXPECT_EQ(myTMatrix(2, 3), myEigenMatrix(2, 3));
126  EXPECT_EQ(myTMatrix(2, 4), myEigenMatrix(2, 4));
127  EXPECT_EQ(myTMatrix(3, 0), myEigenMatrix(3, 0));
128  EXPECT_EQ(myTMatrix(3, 1), myEigenMatrix(3, 1));
129  EXPECT_EQ(myTMatrix(3, 2), myEigenMatrix(3, 2));
130  EXPECT_EQ(myTMatrix(3, 3), myEigenMatrix(3, 3));
131  EXPECT_EQ(myTMatrix(3, 4), myEigenMatrix(3, 4));
132  EXPECT_EQ(myTMatrix(4, 0), myEigenMatrix(4, 0));
133  EXPECT_EQ(myTMatrix(4, 1), myEigenMatrix(4, 1));
134  EXPECT_EQ(myTMatrix(4, 2), myEigenMatrix(4, 2));
135  EXPECT_EQ(myTMatrix(4, 3), myEigenMatrix(4, 3));
136  EXPECT_EQ(myTMatrix(4, 4), myEigenMatrix(4, 4));
137  EXPECT_EQ(myTMatrix(5, 0), myEigenMatrix(5, 0));
138  EXPECT_EQ(myTMatrix(5, 1), myEigenMatrix(5, 1));
139  EXPECT_EQ(myTMatrix(5, 2), myEigenMatrix(5, 2));
140  EXPECT_EQ(myTMatrix(5, 3), myEigenMatrix(5, 3));
141  EXPECT_EQ(myTMatrix(5, 4), myEigenMatrix(5, 4));
142  EXPECT_EQ(myTMatrix(6, 0), myEigenMatrix(6, 0));
143  EXPECT_EQ(myTMatrix(6, 1), myEigenMatrix(6, 1));
144  EXPECT_EQ(myTMatrix(6, 2), myEigenMatrix(6, 2));
145  EXPECT_EQ(myTMatrix(6, 3), myEigenMatrix(6, 3));
146  EXPECT_EQ(myTMatrix(6, 4), myEigenMatrix(6, 4));
147 
148  const auto myRootMatrix(eigenMatrixToRootMatrix<7, 5>(myEigenMatrix));
149  EXPECT_EQ(myTMatrix(0, 0), myRootMatrix(0, 0));
150  EXPECT_EQ(myTMatrix(0, 1), myRootMatrix(0, 1));
151  EXPECT_EQ(myTMatrix(0, 2), myRootMatrix(0, 2));
152  EXPECT_EQ(myTMatrix(0, 3), myRootMatrix(0, 3));
153  EXPECT_EQ(myTMatrix(0, 4), myRootMatrix(0, 4));
154  EXPECT_EQ(myTMatrix(1, 0), myRootMatrix(1, 0));
155  EXPECT_EQ(myTMatrix(1, 1), myRootMatrix(1, 1));
156  EXPECT_EQ(myTMatrix(1, 2), myRootMatrix(1, 2));
157  EXPECT_EQ(myTMatrix(1, 3), myRootMatrix(1, 3));
158  EXPECT_EQ(myTMatrix(1, 4), myRootMatrix(1, 4));
159  EXPECT_EQ(myTMatrix(2, 0), myRootMatrix(2, 0));
160  EXPECT_EQ(myTMatrix(2, 1), myRootMatrix(2, 1));
161  EXPECT_EQ(myTMatrix(2, 2), myRootMatrix(2, 2));
162  EXPECT_EQ(myTMatrix(2, 3), myRootMatrix(2, 3));
163  EXPECT_EQ(myTMatrix(2, 4), myRootMatrix(2, 4));
164  EXPECT_EQ(myTMatrix(3, 0), myRootMatrix(3, 0));
165  EXPECT_EQ(myTMatrix(3, 1), myRootMatrix(3, 1));
166  EXPECT_EQ(myTMatrix(3, 2), myRootMatrix(3, 2));
167  EXPECT_EQ(myTMatrix(3, 3), myRootMatrix(3, 3));
168  EXPECT_EQ(myTMatrix(3, 4), myRootMatrix(3, 4));
169  EXPECT_EQ(myTMatrix(4, 0), myRootMatrix(4, 0));
170  EXPECT_EQ(myTMatrix(4, 1), myRootMatrix(4, 1));
171  EXPECT_EQ(myTMatrix(4, 2), myRootMatrix(4, 2));
172  EXPECT_EQ(myTMatrix(4, 3), myRootMatrix(4, 3));
173  EXPECT_EQ(myTMatrix(4, 4), myRootMatrix(4, 4));
174  EXPECT_EQ(myTMatrix(5, 0), myRootMatrix(5, 0));
175  EXPECT_EQ(myTMatrix(5, 1), myRootMatrix(5, 1));
176  EXPECT_EQ(myTMatrix(5, 2), myRootMatrix(5, 2));
177  EXPECT_EQ(myTMatrix(5, 3), myRootMatrix(5, 3));
178  EXPECT_EQ(myTMatrix(5, 4), myRootMatrix(5, 4));
179  EXPECT_EQ(myTMatrix(6, 0), myRootMatrix(6, 0));
180  EXPECT_EQ(myTMatrix(6, 1), myRootMatrix(6, 1));
181  EXPECT_EQ(myTMatrix(6, 2), myRootMatrix(6, 2));
182  EXPECT_EQ(myTMatrix(6, 3), myRootMatrix(6, 3));
183  EXPECT_EQ(myTMatrix(6, 4), myRootMatrix(6, 4));
184 
185  }
186 
187 }