CbmRoot
Loading...
Searching...
No Matches
_GTestCbmEvent.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 "CbmDefs.h"
6#include "CbmEvent.h"
7#include "CbmMatch.h"
8#include "CbmVertex.h"
9
10#include <TMatrixTSym.h>
11
12#include <vector>
13
14#include <gtest/gtest-spi.h>
15#include <gtest/gtest.h>
16
17#include "compareVertex.h"
18
19void compareEventDataMembers(CbmEvent& test, int32_t evnumber, double starttime, double endtime, int32_t numobjects,
20 CbmMatch* match, CbmVertex* vertex)
21{
22 int32_t retValInt {-111};
23 double retValDouble {-111.};
24
25 retValInt = test.GetNumber();
26 EXPECT_EQ(evnumber, retValInt);
27
28 retValDouble = test.GetStartTime();
29 EXPECT_EQ(starttime, retValDouble);
30
31 retValDouble = test.GetEndTime();
32 EXPECT_EQ(endtime, retValDouble);
33
34 retValInt = test.GetNofData();
35 EXPECT_EQ(numobjects, retValInt);
36
37 EXPECT_EQ(match, test.GetMatch());
38
39 if (!vertex) {
40 double val[6] = {0., 0., 0., 0., 0., 0.};
41 compareVertexDataMembers(*(test.GetVertex()), 0., 0., 0., 0., 0, 0, val);
42 }
43 else {
44 double val[6] = {vertex->GetCovariance(0, 0), vertex->GetCovariance(0, 1), vertex->GetCovariance(0, 2),
45 vertex->GetCovariance(1, 1), vertex->GetCovariance(1, 2), vertex->GetCovariance(2, 2)};
46 compareVertexDataMembers(*(test.GetVertex()), vertex->GetX(), vertex->GetY(), vertex->GetZ(), vertex->GetChi2(),
47 vertex->GetNDF(), vertex->GetNTracks(), val);
48 }
49}
50
51void compareEventMap(CbmEvent& test, int32_t numobjects, int32_t numobjectstype, ECbmDataType type,
52 std::vector<uint32_t> indices)
53{
54 int32_t retValInt {-111};
55 uint32_t retValUInt {111};
56
57 retValInt = test.GetNofData();
58 EXPECT_EQ(numobjects, retValInt);
59
60 retValInt = test.GetNofData(type);
61 EXPECT_EQ(numobjectstype, retValInt);
62
63 if (numobjectstype > 0) {
64 for (int32_t i = 0; i < numobjectstype; ++i) {
65 retValUInt = test.GetIndex(type, i);
66 EXPECT_EQ(indices[i], retValUInt);
67 }
68 }
69}
70
71
72TEST(_GTestCbmEvent, CheckDefaultConstructor)
73{
74 CbmEvent test;
75 {
76 SCOPED_TRACE("CheckDefaultConstructor");
77 }
78}
79
80TEST(_GTestCbmEvent, CheckStandardConstructor)
81{
82 CbmEvent test {-111};
83 {
84 SCOPED_TRACE("CheckStandardConstructor");
85 compareEventDataMembers(test, -111, 0., 0., 0, nullptr, nullptr);
86 }
87}
88
89
90TEST(_GTestCbmEvent, CheckSettersAndGetters)
91{
92 CbmEvent test {-111, 1., 2.};
93 {
94 SCOPED_TRACE("CheckSettersAndGetters: Initial Test");
95 compareEventDataMembers(test, -111, 1., 2., 0, nullptr, nullptr);
96 }
97
98 test.SetStartTime(-23.);
99 {
100 SCOPED_TRACE("CheckSettersAndGetters: SetStartTime");
101 compareEventDataMembers(test, -111, -23., 2., 0, nullptr, nullptr);
102 }
103
104 test.SetEndTime(-45.);
105 {
106 SCOPED_TRACE("CheckSettersAndGetters: SetEndTime");
107 compareEventDataMembers(test, -111, -23., -45., 0, nullptr, nullptr);
108 }
109
110 CbmMatch* testMatch = new CbmMatch();
111 test.SetMatch(testMatch);
112 {
113 SCOPED_TRACE("CheckSettersAndGetters: SetMatch");
114 compareEventDataMembers(test, -111, -23., -45., 0, testMatch, nullptr);
115 }
116}
117
118TEST(_GTestCbmEvent, CheckAddData)
119{
120 CbmEvent test {-111, 1., 2.};
121 {
122 SCOPED_TRACE("CheckAddData: Initial Test");
123 compareEventDataMembers(test, -111, 1., 2., 0, nullptr, nullptr);
124 }
125
126 std::vector<uint32_t> mctrack;
127 std::vector<uint32_t> stspoint;
128 std::vector<uint32_t> stsdigi;
129 std::vector<uint32_t> stscluster;
130 std::vector<uint32_t> stshit;
131 std::vector<uint32_t> ststrack;
132
133
134 mctrack.push_back(11);
135 test.AddData(ECbmDataType::kMCTrack, 11);
136 {
137 SCOPED_TRACE("CheckAddData: Add first MCTrack");
138 compareEventDataMembers(test, -111, 1., 2., 1, nullptr, nullptr);
139 compareEventMap(test, 1, 1, ECbmDataType::kMCTrack, mctrack);
140 compareEventMap(test, 1, 0, ECbmDataType::kStsPoint, stspoint);
141 compareEventMap(test, 1, 0, ECbmDataType::kStsDigi, stsdigi);
142 compareEventMap(test, 1, 0, ECbmDataType::kStsCluster, stscluster);
143 compareEventMap(test, 1, 0, ECbmDataType::kStsHit, stshit);
144 compareEventMap(test, 1, 0, ECbmDataType::kStsTrack, ststrack);
145 }
146
147 mctrack.push_back(23);
148 test.AddData(ECbmDataType::kMCTrack, 23);
149 {
150 SCOPED_TRACE("CheckAddData: Add second MCTrack");
151 compareEventDataMembers(test, -111, 1., 2., 2, nullptr, nullptr);
152 compareEventMap(test, 2, 2, ECbmDataType::kMCTrack, mctrack);
153 compareEventMap(test, 2, 0, ECbmDataType::kStsPoint, stspoint);
154 compareEventMap(test, 2, 0, ECbmDataType::kStsDigi, stsdigi);
155 compareEventMap(test, 2, 0, ECbmDataType::kStsCluster, stscluster);
156 compareEventMap(test, 2, 0, ECbmDataType::kStsHit, stshit);
157 compareEventMap(test, 2, 0, ECbmDataType::kStsTrack, ststrack);
158 }
159
160 uint32_t retValUInt = test.GetIndex(ECbmDataType::kMCTrack, 25);
161 EXPECT_EQ(-2, retValUInt);
162
163 stspoint.push_back(1);
164 test.AddData(ECbmDataType::kStsPoint, 1);
165 {
166 SCOPED_TRACE("CheckAddData: Add StsPoint");
167 compareEventDataMembers(test, -111, 1., 2., 3, nullptr, nullptr);
168 compareEventMap(test, 3, 2, ECbmDataType::kMCTrack, mctrack);
169 compareEventMap(test, 3, 1, ECbmDataType::kStsPoint, stspoint);
170 compareEventMap(test, 3, 0, ECbmDataType::kStsDigi, stsdigi);
171 compareEventMap(test, 3, 0, ECbmDataType::kStsCluster, stscluster);
172 compareEventMap(test, 3, 0, ECbmDataType::kStsHit, stshit);
173 compareEventMap(test, 3, 0, ECbmDataType::kStsTrack, ststrack);
174 }
175
176 stsdigi.push_back(2);
177 test.AddData(ECbmDataType::kStsDigi, 2);
178 {
179 SCOPED_TRACE("CheckAddData: Add StsDigi");
180 compareEventDataMembers(test, -111, 1., 2., 4, nullptr, nullptr);
181 compareEventMap(test, 4, 2, ECbmDataType::kMCTrack, mctrack);
182 compareEventMap(test, 4, 1, ECbmDataType::kStsPoint, stspoint);
183 compareEventMap(test, 4, 1, ECbmDataType::kStsDigi, stsdigi);
184 compareEventMap(test, 4, 0, ECbmDataType::kStsCluster, stscluster);
185 compareEventMap(test, 4, 0, ECbmDataType::kStsHit, stshit);
186 compareEventMap(test, 4, 0, ECbmDataType::kStsTrack, ststrack);
187 }
188
189 stscluster.push_back(3);
190 test.AddData(ECbmDataType::kStsCluster, 3);
191 {
192 SCOPED_TRACE("CheckAddData: Add StsCluster");
193 compareEventDataMembers(test, -111, 1., 2., 5, nullptr, nullptr);
194 compareEventMap(test, 5, 2, ECbmDataType::kMCTrack, mctrack);
195 compareEventMap(test, 5, 1, ECbmDataType::kStsPoint, stspoint);
196 compareEventMap(test, 5, 1, ECbmDataType::kStsDigi, stsdigi);
197 compareEventMap(test, 5, 1, ECbmDataType::kStsCluster, stscluster);
198 compareEventMap(test, 5, 0, ECbmDataType::kStsHit, stshit);
199 compareEventMap(test, 5, 0, ECbmDataType::kStsTrack, ststrack);
200 }
201
202 stshit.push_back(4);
203 test.AddData(ECbmDataType::kStsHit, 4);
204 {
205 SCOPED_TRACE("CheckAddData: Add StsHit");
206 compareEventDataMembers(test, -111, 1., 2., 6, nullptr, nullptr);
207 compareEventMap(test, 6, 2, ECbmDataType::kMCTrack, mctrack);
208 compareEventMap(test, 6, 1, ECbmDataType::kStsPoint, stspoint);
209 compareEventMap(test, 6, 1, ECbmDataType::kStsDigi, stsdigi);
210 compareEventMap(test, 6, 1, ECbmDataType::kStsCluster, stscluster);
211 compareEventMap(test, 6, 1, ECbmDataType::kStsHit, stshit);
212 compareEventMap(test, 6, 0, ECbmDataType::kStsTrack, ststrack);
213 }
214
215 ststrack.push_back(5);
216 test.AddData(ECbmDataType::kStsTrack, 5);
217 {
218 SCOPED_TRACE("CheckAddData: Add StsTrack");
219 compareEventDataMembers(test, -111, 1., 2., 7, nullptr, nullptr);
220 compareEventMap(test, 7, 2, ECbmDataType::kMCTrack, mctrack);
221 compareEventMap(test, 7, 1, ECbmDataType::kStsPoint, stspoint);
222 compareEventMap(test, 7, 1, ECbmDataType::kStsDigi, stsdigi);
223 compareEventMap(test, 7, 1, ECbmDataType::kStsCluster, stscluster);
224 compareEventMap(test, 7, 1, ECbmDataType::kStsHit, stshit);
225 compareEventMap(test, 7, 1, ECbmDataType::kStsTrack, ststrack);
226 }
227
228 ststrack.push_back(6);
229 test.AddStsTrack(6);
230 {
231 SCOPED_TRACE("CheckAddData: Add StsTrack via AddStsTrack");
232 compareEventDataMembers(test, -111, 1., 2., 8, nullptr, nullptr);
233 compareEventMap(test, 8, 2, ECbmDataType::kMCTrack, mctrack);
234 compareEventMap(test, 8, 1, ECbmDataType::kStsPoint, stspoint);
235 compareEventMap(test, 8, 1, ECbmDataType::kStsDigi, stsdigi);
236 compareEventMap(test, 8, 1, ECbmDataType::kStsCluster, stscluster);
237 compareEventMap(test, 8, 1, ECbmDataType::kStsHit, stshit);
238 compareEventMap(test, 8, 2, ECbmDataType::kStsTrack, ststrack);
239 }
240
241 retValUInt = test.GetStsTrackIndex(0);
242 EXPECT_EQ(5, retValUInt);
243
244 retValUInt = test.GetStsTrackIndex(1);
245 EXPECT_EQ(6, retValUInt);
246
247 retValUInt = test.GetStsTrackIndex(2);
248 EXPECT_EQ(-2, retValUInt);
249
250 retValUInt = test.GetNofStsTracks();
251 EXPECT_EQ(2, retValUInt);
252
253 ststrack.clear();
254 ststrack.push_back(11);
255 ststrack.push_back(12);
256 ststrack.push_back(13);
257
258 test.SetStsTracks(ststrack);
259 retValUInt = test.GetNofStsTracks();
260 EXPECT_EQ(3, retValUInt);
261 {
262 SCOPED_TRACE("CheckAddData: Add StsTracks via StsStsTrack");
263 compareEventDataMembers(test, -111, 1., 2., 9, nullptr, nullptr);
264 compareEventMap(test, 9, 2, ECbmDataType::kMCTrack, mctrack);
265 compareEventMap(test, 9, 1, ECbmDataType::kStsPoint, stspoint);
266 compareEventMap(test, 9, 1, ECbmDataType::kStsDigi, stsdigi);
267 compareEventMap(test, 9, 1, ECbmDataType::kStsCluster, stscluster);
268 compareEventMap(test, 9, 1, ECbmDataType::kStsHit, stshit);
269 compareEventMap(test, 9, 3, ECbmDataType::kStsTrack, ststrack);
270 }
271
272 EXPECT_STREQ("Event -111 at t = 1 ns. Registered data types: 6, data "
273 "objects: 9, without matches\n -- Data type 0, number "
274 "of data 2\n -- Data type 200, number of data 1\n "
275 " -- Data type 201, number of data 1\n -- Data type "
276 "202, number of data 1\n -- Data type 203, number of "
277 "data 1\n -- Data type 204, number of data 3\n",
278 test.ToString().c_str());
279}
280
281TEST(_GTestCbmEvent, CheckSetVertex)
282{
283
284 TMatrixFSym Cov(3);
285 Cov(0, 0) = 0.; // 0 1 2
286 Cov(0, 1) = 1.; // 1 3 4
287 Cov(0, 2) = 2.; // 2 4 5
288 Cov(1, 0) = 1.;
289 Cov(1, 1) = 3.;
290 Cov(1, 2) = 4.;
291 Cov(2, 0) = 2.;
292 Cov(2, 1) = 4.;
293 Cov(2, 2) = 5.;
294 CbmVertex testVertex {"Vertex", "Vertex", 1., 2., 3., 4., 5, 6, Cov};
295
296 CbmEvent test;
297 test.SetVertex(1., 2., 3., 4., 5, 6, Cov);
298 {
299 SCOPED_TRACE("CheckSetVertex");
300 compareEventDataMembers(test, -1, 0., 0., 0, nullptr, &testVertex);
301 }
302}
ECbmDataType
Definition CbmDefs.h:90
void compareEventDataMembers(CbmEvent &test, int32_t evnumber, double starttime, double endtime, int32_t numobjects, CbmMatch *match, CbmVertex *vertex)
TEST(_GTestCbmEvent, CheckDefaultConstructor)
void compareEventMap(CbmEvent &test, int32_t numobjects, int32_t numobjectstype, ECbmDataType type, std::vector< uint32_t > indices)
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
size_t GetNofData() const
Definition CbmEvent.cxx:53
CbmVertex * GetVertex()
Definition CbmEvent.h:210
void SetVertex(double x, double y, double z, double chi2, int32_t ndf, int32_t nTracks, const TMatrixFSym &covMat)
Definition CbmEvent.cxx:76
int32_t GetNumber() const
Definition CbmEvent.h:121
double GetStartTime() const
Definition CbmEvent.h:140
double GetEndTime() const
Definition CbmEvent.h:134
void SetStartTime(double startTime)
Definition CbmEvent.h:169
CbmMatch * GetMatch() const
Definition CbmEvent.h:98
uint32_t GetIndex(ECbmDataType type, uint32_t iData)
Definition CbmEvent.cxx:42
double GetZ() const
Definition CbmVertex.h:69
double GetChi2() const
Definition CbmVertex.h:70
double GetCovariance(int32_t i, int32_t j) const
int32_t GetNDF() const
Definition CbmVertex.h:71
int32_t GetNTracks() const
Definition CbmVertex.h:72
double GetY() const
Definition CbmVertex.h:68
double GetX() const
Definition CbmVertex.h:67
void compareVertexDataMembers(CbmVertex &test, double x, double y, double z, double chi2, int32_t ndf, int32_t ntracks, double *cov)