CbmRoot
_GTestCbmVertex.cxx
Go to the documentation of this file.
1 #include "CbmVertex.h"
2 
3 #include <FairLogger.h>
4 
5 #include <TMatrixTSym.h>
6 #include <TVector3.h>
7 
8 #include <gtest/gtest-spi.h>
9 #include <gtest/gtest.h>
10 
11 #include <regex>
12 
13 #include "../compareVertex.h"
14 
15 TEST(_GTestCbmVertex, CheckDefaultConstructor) {
16  CbmVertex test;
17  Double_t val[6] = {0., 0., 0., 0., 0., 0.};
18  {
19  SCOPED_TRACE("CheckDefaultConstructor");
20  compareVertexDataMembers(test, 0., 0., 0., 0., 0, 0, val);
21  }
22 }
23 
24 TEST(_GTestCbmVertex, CheckStandardConstructor) {
25  CbmVertex test {"Vertex", "Vertex"};
26  Double_t val[6] = {0., 0., 0., 0., 0., 0.};
27  {
28  SCOPED_TRACE("CheckStandardConstructor");
29  compareVertexDataMembers(test, 0., 0., 0., 0., 0, 0, val);
30  }
31 }
32 
33 TEST(_GTestCbmVertex, CheckConstructorAllArguments) {
34  TMatrixFSym Cov(3);
35  Cov(0, 0) = 0.; // 0 1 2
36  Cov(0, 1) = 1.; // 1 3 4
37  Cov(0, 2) = 2.; // 2 4 5
38  Cov(1, 0) = 1.;
39  Cov(1, 1) = 3.;
40  Cov(1, 2) = 4.;
41  Cov(2, 0) = 2.;
42  Cov(2, 1) = 4.;
43  Cov(2, 2) = 5.;
44 
45  Double_t val[6] = {0., 1., 2., 3., 4., 5.};
46  CbmVertex test {"Vertex", "Vertex", 1., 2., 3., 4., 5, 6, Cov};
47  {
48  SCOPED_TRACE("CheckConstructorAllArguments");
49  compareVertexDataMembers(test, 1., 2., 3., 4., 5, 6, val);
50  }
51 
52  // In case a matrix of wrong dimension is passed all data members are initialized, except the cov matrix
53  // where all elements are set to 0.
54  // Additionally an error message is printed
55  TMatrixFSym CovWrong(2);
56  CovWrong(0, 0) = 0.; // 0 1
57  CovWrong(0, 1) = 1.; // 1 2
58  CovWrong(1, 0) = 1.;
59  CovWrong(1, 1) = 2.;
60 
61  Double_t val1[6] = {0., 0., 0., 0., 0., 0.};
62 
63  testing::internal::CaptureStdout();
64  CbmVertex test1 {"Vertex", "Vertex", 1., 2., 3., 4., 5, 6, CovWrong};
65  std::string output = testing::internal::GetCapturedStdout();
66 
67  std::regex f("\\[ERROR(.*)\\](.*)(Wrong dimension of passed covariance "
68  "matrix\\. Clear the covariance matrix)(.*)\\n");
69  bool retval = std::regex_match(output, f);
70  if (!retval) {
71  std::cout << " Actual: " << output << std::endl;
72  std::cout << "Expected: "
73  << "\\[ERROR\\](.*)(Wrong dimension of passed covariance "
74  "matrix\\. Clear the covariance matrix)(.*)\\n"
75  << std::endl;
76  }
77  EXPECT_TRUE(retval);
78 
79  {
80  SCOPED_TRACE("CheckConstructorAllArgumentsWrongCovMatrix");
81  compareVertexDataMembers(test1, 1., 2., 3., 4., 5, 6, val1);
82  }
83 }
84 
85 TEST(_GTestCbmVertex, CheckReset) {
86  TMatrixFSym Cov(3);
87  Cov(0, 0) = 0.;
88  Cov(0, 1) = 1.;
89  Cov(0, 2) = 2.;
90  Cov(1, 0) = 1.;
91  Cov(1, 1) = 3.;
92  Cov(1, 2) = 4.;
93  Cov(2, 0) = 2.;
94  Cov(2, 1) = 4.;
95  Cov(2, 2) = 5.;
96 
97  Double_t val[6] = {0., 1., 2., 3., 4., 5.};
98  CbmVertex test {"Vertex", "Vertex", 1., 2., 3., 4., 5, 6, Cov};
99  {
100  SCOPED_TRACE("CheckReset: Initial Test");
101  compareVertexDataMembers(test, 1., 2., 3., 4., 5, 6, val);
102  }
103 
104  Double_t val1[6] = {0., 0., 0., 0., 0., 0.};
105  test.Reset();
106  {
107  SCOPED_TRACE("CheckReset: Check after reset");
108  compareVertexDataMembers(test, 0., 0., 0., 0., 0, 0, val1);
109  }
110 }
111 
112 TEST(_GTestCbmVertex, CheckGetPosition) {
113  TMatrixFSym Cov(3);
114  Cov(0, 0) = 0.;
115  Cov(0, 1) = 1.;
116  Cov(0, 2) = 2.;
117  Cov(1, 0) = 1.;
118  Cov(1, 1) = 3.;
119  Cov(1, 2) = 4.;
120  Cov(2, 0) = 2.;
121  Cov(2, 1) = 4.;
122  Cov(2, 2) = 5.;
123 
124  Double_t val[6] = {0., 1., 2., 3., 4., 5.};
125  CbmVertex test {"Vertex", "Vertex", 1., 2., 3., 4., 5, 6, Cov};
126  {
127  SCOPED_TRACE("CheckGetPosition: Initial Test");
128  compareVertexDataMembers(test, 1., 2., 3., 4., 5, 6, val);
129  }
130 
131  TVector3 testVect;
132 
133  test.Position(testVect);
134  {
135  SCOPED_TRACE("CheckGetPosition: Check after Position");
136  compareVertexDataMembers(test, 1., 2., 3., 4., 5, 6, val);
137  }
138  EXPECT_FLOAT_EQ(1., testVect.X());
139  EXPECT_FLOAT_EQ(2., testVect.Y());
140  EXPECT_FLOAT_EQ(3., testVect.Z());
141 }
142 
143 
144 TEST(_GTestCbmVertex, CheckGetCovMatrix) {
145  TMatrixFSym Cov(3);
146  Cov(0, 0) = 0.;
147  Cov(0, 1) = 1.;
148  Cov(0, 2) = 2.;
149  Cov(1, 0) = 1.;
150  Cov(1, 1) = 3.;
151  Cov(1, 2) = 4.;
152  Cov(2, 0) = 2.;
153  Cov(2, 1) = 4.;
154  Cov(2, 2) = 5.;
155 
156  Double_t val[6] = {0., 1., 2., 3., 4., 5.};
157  CbmVertex test {"Vertex", "Vertex", 1., 2., 3., 4., 5, 6, Cov};
158  {
159  SCOPED_TRACE("CheckGetCovMatrix: Initial Test");
160  compareVertexDataMembers(test, 1., 2., 3., 4., 5, 6, val);
161  }
162 
163  TMatrixFSym testCov(3);
164 
165  test.CovMatrix(testCov);
166  {
167  SCOPED_TRACE("CheckGetCovMatrix: Check after Position");
168  compareVertexDataMembers(test, 1., 2., 3., 4., 5, 6, val);
169  }
170  for (Int_t i = 0; i < 3; ++i) {
171  for (Int_t j = 0; j < 3; ++j) {
172  Double_t origVal = Cov[i][j];
173  Double_t testVal = testCov[i][j];
174  EXPECT_FLOAT_EQ(testVal, origVal);
175  }
176  }
177 }
178 
179 
180 TEST(_GTestCbmVertex, CheckSetVertex) {
181 
182  CbmVertex test;
183  Double_t val[6] = {0., 0., 0., 0., 0., 0.};
184  {
185  SCOPED_TRACE("CheckSetVertex: Initial Test");
186  compareVertexDataMembers(test, 0., 0., 0., 0., 0, 0, val);
187  }
188 
189  TMatrixFSym Cov(3);
190  Cov(0, 0) = 0.;
191  Cov(0, 1) = 1.;
192  Cov(0, 2) = 2.;
193  Cov(1, 0) = 1.;
194  Cov(1, 1) = 3.;
195  Cov(1, 2) = 4.;
196  Cov(2, 0) = 2.;
197  Cov(2, 1) = 4.;
198  Cov(2, 2) = 5.;
199 
200  Double_t val1[6] = {0., 1., 2., 3., 4., 5.};
201  test.SetVertex(1., 2., 3., 4., 5, 6, Cov);
202  {
203  SCOPED_TRACE("CheckSetVertex: After call of SetVertex");
204  compareVertexDataMembers(test, 1., 2., 3., 4., 5, 6, val1);
205  }
206 
207  // In case a matrix of wrong dimension is passed all data members are initialized, except the cov matrix
208  // where all elements are set to 0.
209  // Additionally an error message is printed
210  TMatrixFSym CovWrong(2);
211  CovWrong(0, 0) = 0.; // 0 1
212  CovWrong(0, 1) = 1.; // 1 2
213  CovWrong(1, 0) = 1.;
214  CovWrong(1, 1) = 2.;
215 
216  Double_t val2[6] = {0., 0., 0., 0., 0., 0.};
217 
218  testing::internal::CaptureStdout();
219  test.SetVertex(-1., -2., -3., -4., -5, -6, CovWrong);
220  std::string output = testing::internal::GetCapturedStdout();
221 
222  std::regex f("\\[ERROR(.*)\\](.*)(Wrong dimension of passed covariance "
223  "matrix\\. Clear the covariance matrix)(.*)\\n");
224  bool retval = std::regex_match(output, f);
225  if (!retval) {
226  std::cout << " Actual: " << output << std::endl;
227  std::cout << "Expected: "
228  << "\\[ERROR\\](.*)(Wrong dimension of passed covariance "
229  "matrix\\. Clear the covariance matrix)(.*)\\n"
230  << std::endl;
231  }
232  EXPECT_TRUE(retval);
233 
234  {
235  SCOPED_TRACE("CheckSetVertex: Check after SetVertex with wrong cov matrix");
236  compareVertexDataMembers(test, -1., -2., -3., -4., -5, -6, val2);
237  }
238 }
239 
240 TEST(_GTestCbmVertex, CheckPrint) {
241  TMatrixFSym Cov(3);
242  Cov(0, 0) = 0.;
243  Cov(0, 1) = 1.;
244  Cov(0, 2) = 2.;
245  Cov(1, 0) = 1.;
246  Cov(1, 1) = 3.;
247  Cov(1, 2) = 4.;
248  Cov(2, 0) = 2.;
249  Cov(2, 1) = 4.;
250  Cov(2, 2) = 5.;
251 
252  Double_t val[6] = {0., 1., 2., 3., 4., 5.};
253  CbmVertex test {"Vertex", "Vertex", 1., 2., 3., 4., 5, 6, Cov};
254  {
255  SCOPED_TRACE("CheckSetVertex: Initial Test");
256  compareVertexDataMembers(test, 1., 2., 3., 4., 5, 6, val);
257  }
258 
259  EXPECT_STREQ("Vertex: position (1.0000, 2.0000, 3.0000) cm, chi2/ndf = "
260  "0.8000, tracks used: 6",
261  test.ToString().c_str());
262 
263 
264  CbmVertex test1 {"Vertex", "Vertex", 1., 2., 3., 4., 0, 6, Cov};
265  {
266  SCOPED_TRACE("CheckSetVertex: Initial Test");
267  compareVertexDataMembers(test1, 1., 2., 3., 4., 0, 6, val);
268  }
269 
270  EXPECT_STREQ("Vertex: position (1.0000, 2.0000, 3.0000) cm, chi2/ndf = "
271  "0.0000, tracks used: 6",
272  test1.ToString().c_str());
273 }
CbmVertex::SetVertex
void SetVertex(Double_t x, Double_t y, Double_t z, Double_t chi2, Int_t ndf, Int_t nTracks, const TMatrixFSym &covMat)
Definition: CbmVertex.cxx:129
CbmVertex.h
f
float f
Definition: L1/vectors/P4_F32vec4.h:24
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
val2
InOutStructure val2
Definition: _GTestCbmDefs.cxx:91
TEST
TEST(_GTestCbmVertex, CheckDefaultConstructor)
Definition: _GTestCbmVertex.cxx:15
CbmVertex
Definition: CbmVertex.h:26
val1
InOutStructure val1
Definition: _GTestCbmDefs.cxx:90
compareVertexDataMembers
void compareVertexDataMembers(CbmVertex &test, Double_t x, Double_t y, Double_t z, Double_t chi2, Int_t ndf, Int_t ntracks, Double_t *cov)
Definition: compareVertex.h:1