CbmRoot
Loading...
Searching...
No Matches
_GTestCbmTrdPoint.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer] */
4
5#include "CbmTrdPoint.h"
6
7#include "compareTrdPoint.h"
8#include "gtest/gtest-spi.h"
9#include "gtest/gtest.h"
10
11TEST(_GTestCbmTrdPoint, CheckDefaultConstructor)
12{
13 // Create object
14 CbmTrdPoint test;
15
16 compareTrdPointDataMembers(test, -1, -1, TVector3(0., 0., 0.), TVector3(0., 0., 0.), TVector3(0., 0., 0.),
17 TVector3(0., 0., 0.), 0., 0., 0., 0);
18
19 CbmTrdPoint* test1 = new CbmTrdPoint();
20
21 compareTrdPointDataMembers(*test1, -1, -1, TVector3(0., 0., 0.), TVector3(0., 0., 0.), TVector3(0., 0., 0.),
22 TVector3(0., 0., 0.), 0., 0., 0., 0);
23}
24
25TEST(_GTestCbmTrdPoint, CheckStandardConstructor)
26{
27 int32_t trackid {34};
28 int32_t detid {45};
29 TVector3 posin {-2.1, 6.1, 23.};
30 TVector3 momin {2.5, 4.5, 78.};
31 TVector3 posout {2.1, -6.1, -23.};
32 TVector3 momout {-2.5, -4.5, -78.};
33 double tof {34.56};
34 double length {1.2};
35 double eloss {0.4567};
36 int32_t eventid {0};
37 // Create object
38 CbmTrdPoint test(trackid, detid, posin, momin, posout, momout, tof, length, eloss);
39
40 compareTrdPointDataMembers(test, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
41
42 CbmTrdPoint* test1 = new CbmTrdPoint(trackid, detid, posin, momin, posout, momout, tof, length, eloss);
43
44 compareTrdPointDataMembers(*test1, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
45}
46
47TEST(_GTestCbmTrdPoint, CheckCopyConstructor)
48{
49 int32_t trackid {34};
50 int32_t detid {45};
51 TVector3 posin {-2.1, 6.1, 23.};
52 TVector3 momin {2.5, 4.5, 78.};
53 TVector3 posout {2.1, -6.1, -23.};
54 TVector3 momout {-2.5, -4.5, -78.};
55 double tof {34.56};
56 double length {1.2};
57 double eloss {0.4567};
58 int32_t eventid {0};
59 // Create object
60 CbmTrdPoint test(trackid, detid, posin, momin, posout, momout, tof, length, eloss);
61
62 compareTrdPointDataMembers(test, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
63
64 // Create object by copy constructing
65 // test should be equal to test2 and
66 // test should not be changed
67 CbmTrdPoint test2 {test};
68
69 compareTrdPointDataMembers(test2, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
70
71 // Test if the original object wasn't changed
72 compareTrdPointDataMembers(test, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
73}
74
75TEST(_GTestCbmTrdPoint, CheckCopyAssignmentOperator)
76{
77 int32_t trackid {34};
78 int32_t detid {45};
79 TVector3 posin {-2.1, 6.1, 23.};
80 TVector3 momin {2.5, 4.5, 78.};
81 TVector3 posout {2.1, -6.1, -23.};
82 TVector3 momout {-2.5, -4.5, -78.};
83 double tof {34.56};
84 double length {1.2};
85 double eloss {0.4567};
86 int32_t eventid {0};
87 // Create object
88 CbmTrdPoint test(trackid, detid, posin, momin, posout, momout, tof, length, eloss);
89
90 compareTrdPointDataMembers(test, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
91
92 // Create object by copy constructing
93 // test should be equal to test2 and
94 // test should not be changed
95 CbmTrdPoint test2 {};
96 test2 = test;
97
98 compareTrdPointDataMembers(test2, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
99
100 // Test if the original object wasn't changed
101 compareTrdPointDataMembers(test, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
102}
103
104TEST(_GTestCbmTrdPoint, CheckMoveConstructor)
105{
106 int32_t trackid {34};
107 int32_t detid {45};
108 TVector3 posin {-2.1, 6.1, 23.};
109 TVector3 momin {2.5, 4.5, 78.};
110 TVector3 posout {2.1, -6.1, -23.};
111 TVector3 momout {-2.5, -4.5, -78.};
112 double tof {34.56};
113 double length {1.2};
114 double eloss {0.4567};
115 int32_t eventid {0};
116 // Create object
117 CbmTrdPoint test(trackid, detid, posin, momin, posout, momout, tof, length, eloss);
118
119 compareTrdPointDataMembers(test, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
120
121 // Create object by copy constructing
122 // test should be equal to test2 and
123 // test should not be changed
124 CbmTrdPoint test2 {std::move(test)};
125
126 compareTrdPointDataMembers(test2, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
127
128 // For objects with simple types move fall back to copy so
129 // the original object is kept unchanged
130 compareTrdPointDataMembers(test, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
131}
132
133TEST(_GTestCbmTrdPoint, CheckAssignmentOperator)
134{
135 int32_t trackid {34};
136 int32_t detid {45};
137 TVector3 posin {-2.1, 6.1, 23.};
138 TVector3 momin {2.5, 4.5, 78.};
139 TVector3 posout {2.1, -6.1, -23.};
140 TVector3 momout {-2.5, -4.5, -78.};
141 double tof {34.56};
142 double length {1.2};
143 double eloss {0.4567};
144 int32_t eventid {0};
145 // Create object
146 CbmTrdPoint test(trackid, detid, posin, momin, posout, momout, tof, length, eloss);
147
148 compareTrdPointDataMembers(test, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
149
150 // Create object by copy constructing
151 // test should be equal to test2 and
152 // test should not be changed
153 CbmTrdPoint test2 {};
154 test2 = std::move(test);
155
156 compareTrdPointDataMembers(test2, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
157
158 // For objects with simple types move fall back to copy so
159 // the original object is kept unchanged
160 compareTrdPointDataMembers(test, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
161}
162
163TEST(_GTestCbmTrdPoint, CheckPrint)
164{
165 int32_t trackid {34};
166 int32_t detid {45};
167 TVector3 posin {-2.1, 6.1, 23.};
168 TVector3 momin {2.5, 4.5, 78.};
169 TVector3 posout {2.1, -6.1, -23.};
170 TVector3 momout {-2.5, -4.5, -78.};
171 double tof {34.56};
172 double length {1.2};
173 double eloss {0.4567};
174 int32_t eventid {0};
175 // Create object
176 CbmTrdPoint test(trackid, detid, posin, momin, posout, momout, tof, length, eloss);
177
178 compareTrdPointDataMembers(test, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
179
180 testing::internal::CaptureStdout();
181 test.Print("");
182 std::string output = testing::internal::GetCapturedStdout();
183
184 EXPECT_STREQ("[INFO] TRD point for track 34 in detector 45\n[INFO] "
185 "Position In (-2.1, 6.1, 23) cm\n[INFO] Momentum In (2.5, "
186 "4.5, 78) GeV\n[INFO] Position Out (2.1, -6.1, -23) "
187 "cm\n[INFO] Momentum Out (-2.5, -4.5, -78) GeV\n[INFO] "
188 "Time 34.56 ns, Length 1.2 cm, Energy loss 456700 keV\n",
189 output.c_str());
190}
191
192
193TEST(_GTestCbmTrdPoint, CheckPositionOut)
194{
195 int32_t trackid {34};
196 int32_t detid {45};
197 TVector3 posin {-2.1, 6.1, 23.};
198 TVector3 momin {2.5, 4.5, 78.};
199 TVector3 posout {2.1, -6.1, -23.};
200 TVector3 momout {-2.5, -4.5, -78.};
201 double tof {34.56};
202 double length {1.2};
203 double eloss {0.4567};
204 int32_t eventid {0};
205 // Create object
206 CbmTrdPoint test(trackid, detid, posin, momin, posout, momout, tof, length, eloss);
207
208 compareTrdPointDataMembers(test, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
209
210
211 TVector3 testVect {0., 0., 0.};
212
213 test.PositionOut(testVect);
214
215 EXPECT_FLOAT_EQ(posout.X(), testVect.X());
216 EXPECT_FLOAT_EQ(posout.Y(), testVect.Y());
217 EXPECT_FLOAT_EQ(posout.Z(), testVect.Z());
218}
219
220TEST(_GTestCbmTrdPoint, CheckMomentumOut)
221{
222 int32_t trackid {34};
223 int32_t detid {45};
224 TVector3 posin {-2.1, 6.1, 23.};
225 TVector3 momin {2.5, 4.5, 78.};
226 TVector3 posout {2.1, -6.1, -23.};
227 TVector3 momout {-2.5, -4.5, -78.};
228 double tof {34.56};
229 double length {1.2};
230 double eloss {0.4567};
231 int32_t eventid {0};
232 // Create object
233 CbmTrdPoint test(trackid, detid, posin, momin, posout, momout, tof, length, eloss);
234
235 compareTrdPointDataMembers(test, trackid, detid, posin, momin, posout, momout, tof, length, eloss, eventid);
236
237
238 TVector3 testVect {0., 0., 0.};
239
240 test.MomentumOut(testVect);
241
242 EXPECT_FLOAT_EQ(momout.X(), testVect.X());
243 EXPECT_FLOAT_EQ(momout.Y(), testVect.Y());
244 EXPECT_FLOAT_EQ(momout.Z(), testVect.Z());
245}
TEST(_GTestCbmTrdPoint, CheckDefaultConstructor)
void MomentumOut(TVector3 &mom) const
Definition CbmTrdPoint.h:81
void PositionOut(TVector3 &pos) const
Definition CbmTrdPoint.h:80
virtual void Print(const Option_t *opt) const
Output to screen.
void compareTrdPointDataMembers(CbmTrdPoint &test, int32_t trackID, int32_t detID, TVector3 posin, TVector3 momin, TVector3 posout, TVector3 momout, double tof, double length, double eLoss, int32_t eventid)