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