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