EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TestRKTrackRep.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TestRKTrackRep.cpp
1 #include <gtest/gtest.h>
2 
3 #include <TVector3.h>
4 
5 #include <Exception.h>
6 #include <RKTrackRep.h>
7 #include <ConstField.h>
8 #include <FieldManager.h>
9 #include <StateOnPlane.h>
10 #include <SharedPlanePtr.h>
11 #include <MeasurementOnPlane.h>
12 
13 
14 namespace genfit {
15 
16  class RKTrackRepTests : public ::testing::Test {
17 
18  protected:
19  virtual void SetUp() {
20  const double bFieldZ = 20; // kGauss. Is 1.5T
21  m_constField = new genfit::ConstField(0., 0., bFieldZ);
23  }
24  virtual void TearDown() {
26  }
28  };
29 
31  genfit::RKStep myRKStep;
32 
33  EXPECT_EQ(0, myRKStep.state7_[0]);
34  EXPECT_EQ(0, myRKStep.state7_[1]);
35  EXPECT_EQ(0, myRKStep.state7_[2]);
36  EXPECT_EQ(0, myRKStep.state7_[3]);
37  EXPECT_EQ(0, myRKStep.state7_[4]);
38  EXPECT_EQ(0, myRKStep.state7_[5]);
39  EXPECT_EQ(0, myRKStep.state7_[6]);
40  }
41 
43  genfit::ExtrapStep myExtrapStep;
44 
45  EXPECT_EQ(0, myExtrapStep.jac7_(0, 0));
46  EXPECT_EQ(0, myExtrapStep.jac7_(0, 1));
47  EXPECT_EQ(0, myExtrapStep.jac7_(0, 2));
48  EXPECT_EQ(0, myExtrapStep.jac7_(0, 3));
49  EXPECT_EQ(0, myExtrapStep.jac7_(0, 4));
50  EXPECT_EQ(0, myExtrapStep.jac7_(0, 5));
51  EXPECT_EQ(0, myExtrapStep.jac7_(0, 6));
52 
53  EXPECT_EQ(0, myExtrapStep.jac7_(1, 0));
54  EXPECT_EQ(0, myExtrapStep.jac7_(1, 1));
55  EXPECT_EQ(0, myExtrapStep.jac7_(1, 2));
56  EXPECT_EQ(0, myExtrapStep.jac7_(1, 3));
57  EXPECT_EQ(0, myExtrapStep.jac7_(1, 4));
58  EXPECT_EQ(0, myExtrapStep.jac7_(1, 5));
59  EXPECT_EQ(0, myExtrapStep.jac7_(1, 6));
60 
61  EXPECT_EQ(0, myExtrapStep.jac7_(2, 0));
62  EXPECT_EQ(0, myExtrapStep.jac7_(2, 1));
63  EXPECT_EQ(0, myExtrapStep.jac7_(2, 2));
64  EXPECT_EQ(0, myExtrapStep.jac7_(2, 3));
65  EXPECT_EQ(0, myExtrapStep.jac7_(2, 4));
66  EXPECT_EQ(0, myExtrapStep.jac7_(2, 5));
67  EXPECT_EQ(0, myExtrapStep.jac7_(2, 6));
68 
69  EXPECT_EQ(0, myExtrapStep.jac7_(3, 0));
70  EXPECT_EQ(0, myExtrapStep.jac7_(3, 1));
71  EXPECT_EQ(0, myExtrapStep.jac7_(3, 2));
72  EXPECT_EQ(0, myExtrapStep.jac7_(3, 3));
73  EXPECT_EQ(0, myExtrapStep.jac7_(3, 4));
74  EXPECT_EQ(0, myExtrapStep.jac7_(3, 5));
75  EXPECT_EQ(0, myExtrapStep.jac7_(3, 6));
76 
77  EXPECT_EQ(0, myExtrapStep.jac7_(4, 0));
78  EXPECT_EQ(0, myExtrapStep.jac7_(4, 1));
79  EXPECT_EQ(0, myExtrapStep.jac7_(4, 2));
80  EXPECT_EQ(0, myExtrapStep.jac7_(4, 3));
81  EXPECT_EQ(0, myExtrapStep.jac7_(4, 4));
82  EXPECT_EQ(0, myExtrapStep.jac7_(4, 5));
83  EXPECT_EQ(0, myExtrapStep.jac7_(4, 6));
84 
85  EXPECT_EQ(0, myExtrapStep.jac7_(5, 0));
86  EXPECT_EQ(0, myExtrapStep.jac7_(5, 1));
87  EXPECT_EQ(0, myExtrapStep.jac7_(5, 2));
88  EXPECT_EQ(0, myExtrapStep.jac7_(5, 3));
89  EXPECT_EQ(0, myExtrapStep.jac7_(5, 4));
90  EXPECT_EQ(0, myExtrapStep.jac7_(5, 5));
91  EXPECT_EQ(0, myExtrapStep.jac7_(5, 6));
92 
93  EXPECT_EQ(0, myExtrapStep.jac7_(6, 0));
94  EXPECT_EQ(0, myExtrapStep.jac7_(6, 1));
95  EXPECT_EQ(0, myExtrapStep.jac7_(6, 2));
96  EXPECT_EQ(0, myExtrapStep.jac7_(6, 3));
97  EXPECT_EQ(0, myExtrapStep.jac7_(6, 4));
98  EXPECT_EQ(0, myExtrapStep.jac7_(6, 5));
99  EXPECT_EQ(0, myExtrapStep.jac7_(6, 6));
100 
101  EXPECT_EQ(0, myExtrapStep.noise7_(0, 0));
102  EXPECT_EQ(0, myExtrapStep.noise7_(0, 1));
103  EXPECT_EQ(0, myExtrapStep.noise7_(0, 2));
104  EXPECT_EQ(0, myExtrapStep.noise7_(0, 3));
105  EXPECT_EQ(0, myExtrapStep.noise7_(0, 4));
106  EXPECT_EQ(0, myExtrapStep.noise7_(0, 5));
107  EXPECT_EQ(0, myExtrapStep.noise7_(0, 6));
108 
109  EXPECT_EQ(0, myExtrapStep.noise7_(1, 0));
110  EXPECT_EQ(0, myExtrapStep.noise7_(1, 1));
111  EXPECT_EQ(0, myExtrapStep.noise7_(1, 2));
112  EXPECT_EQ(0, myExtrapStep.noise7_(1, 3));
113  EXPECT_EQ(0, myExtrapStep.noise7_(1, 4));
114  EXPECT_EQ(0, myExtrapStep.noise7_(1, 5));
115  EXPECT_EQ(0, myExtrapStep.noise7_(1, 6));
116 
117  EXPECT_EQ(0, myExtrapStep.noise7_(2, 0));
118  EXPECT_EQ(0, myExtrapStep.noise7_(2, 1));
119  EXPECT_EQ(0, myExtrapStep.noise7_(2, 2));
120  EXPECT_EQ(0, myExtrapStep.noise7_(2, 3));
121  EXPECT_EQ(0, myExtrapStep.noise7_(2, 4));
122  EXPECT_EQ(0, myExtrapStep.noise7_(2, 5));
123  EXPECT_EQ(0, myExtrapStep.noise7_(2, 6));
124 
125  EXPECT_EQ(0, myExtrapStep.noise7_(3, 0));
126  EXPECT_EQ(0, myExtrapStep.noise7_(3, 1));
127  EXPECT_EQ(0, myExtrapStep.noise7_(3, 2));
128  EXPECT_EQ(0, myExtrapStep.noise7_(3, 3));
129  EXPECT_EQ(0, myExtrapStep.noise7_(3, 4));
130  EXPECT_EQ(0, myExtrapStep.noise7_(3, 5));
131  EXPECT_EQ(0, myExtrapStep.noise7_(3, 6));
132 
133  EXPECT_EQ(0, myExtrapStep.noise7_(4, 0));
134  EXPECT_EQ(0, myExtrapStep.noise7_(4, 1));
135  EXPECT_EQ(0, myExtrapStep.noise7_(4, 2));
136  EXPECT_EQ(0, myExtrapStep.noise7_(4, 3));
137  EXPECT_EQ(0, myExtrapStep.noise7_(4, 4));
138  EXPECT_EQ(0, myExtrapStep.noise7_(4, 5));
139  EXPECT_EQ(0, myExtrapStep.noise7_(4, 6));
140 
141  EXPECT_EQ(0, myExtrapStep.noise7_(5, 0));
142  EXPECT_EQ(0, myExtrapStep.noise7_(5, 1));
143  EXPECT_EQ(0, myExtrapStep.noise7_(5, 2));
144  EXPECT_EQ(0, myExtrapStep.noise7_(5, 3));
145  EXPECT_EQ(0, myExtrapStep.noise7_(5, 4));
146  EXPECT_EQ(0, myExtrapStep.noise7_(5, 5));
147  EXPECT_EQ(0, myExtrapStep.noise7_(5, 6));
148 
149  EXPECT_EQ(0, myExtrapStep.noise7_(6, 0));
150  EXPECT_EQ(0, myExtrapStep.noise7_(6, 1));
151  EXPECT_EQ(0, myExtrapStep.noise7_(6, 2));
152  EXPECT_EQ(0, myExtrapStep.noise7_(6, 3));
153  EXPECT_EQ(0, myExtrapStep.noise7_(6, 4));
154  EXPECT_EQ(0, myExtrapStep.noise7_(6, 5));
155  EXPECT_EQ(0, myExtrapStep.noise7_(6, 6));
156  }
157 
159  TEST_F (RKTrackRepTests, RKPropagate01) {
160  genfit::M1x7 myState7;
161  myState7.vals[0] = 0;
162  myState7.vals[1] = 0;
163  myState7.vals[2] = 0;
164  myState7.vals[3] = 0;
165  myState7.vals[4] = 0;
166  myState7.vals[5] = 1;
167  myState7.vals[6] = 1;
168  genfit::M7x7* myJacobian = nullptr;
169  genfit::M1x3 mySA;
170  double myS = 0.5;
171  const bool varField = false;
172  const bool calcOnlyLastRowOfJ = false;
173 
174  genfit::RKTrackRep myRKTrackRep;
175  EXPECT_EQ(10, myRKTrackRep.RKPropagate(myState7, myJacobian, mySA, myS, varField, calcOnlyLastRowOfJ));
176  EXPECT_EQ(0, myState7[0]);
177  EXPECT_EQ(0, myState7[1]);
178  EXPECT_EQ(0.5, myState7[2]);
179  EXPECT_EQ(0, myState7[3]);
180  EXPECT_EQ(0, myState7[4]);
181  EXPECT_EQ(1, myState7[5]);
182  EXPECT_EQ(1, myState7[6]);
183  EXPECT_EQ(0, mySA[0]);
184  EXPECT_EQ(0, mySA[1]);
185  EXPECT_EQ(0, mySA[2]);
186  }
187 
189  TEST_F (RKTrackRepTests, RKPropagate02) {
190  genfit::M1x7 myState7;
191  myState7.vals[0] = 1;
192  myState7.vals[1] = 1;
193  myState7.vals[2] = 1;
194  myState7.vals[3] = 1;
195  myState7.vals[4] = 1;
196  myState7.vals[5] = 1;
197  myState7.vals[6] = 1;
198  genfit::M7x7* myJacobian = nullptr;
199  genfit::M1x3 mySA;
200  double myS = 0.1;
201  const bool varField = false;
202  const bool calcOnlyLastRowOfJ = false;
203 
204  genfit::RKTrackRep myRKTrackRep;
205  EXPECT_FLOAT_EQ(10, myRKTrackRep.RKPropagate(myState7, myJacobian, mySA, myS, varField, calcOnlyLastRowOfJ));
206  EXPECT_FLOAT_EQ(1.1000299732532006, myState7[0]);
207  EXPECT_FLOAT_EQ(1.0999700147633968, myState7[1]);
208  EXPECT_FLOAT_EQ(1.1, myState7[2]);
209  EXPECT_FLOAT_EQ(0.5776963359022331, myState7[3]);
210  EXPECT_FLOAT_EQ(0.5770039949184069, myState7[4]);
211  EXPECT_FLOAT_EQ(0.5773502691896258, myState7[5]);
212  EXPECT_FLOAT_EQ(1, myState7[6]);
213  EXPECT_FLOAT_EQ(0.000599405129044106, mySA[0]);
214  EXPECT_FLOAT_EQ(-0.0005997646311051152, mySA[1]);
215  EXPECT_FLOAT_EQ(0., mySA[2]);
216  }
217 
219  TEST_F (RKTrackRepTests, getState7) {
220  RKTrackRep myRKTrackRep;
221  genfit::M1x7 myState7;
222  myState7.vals[0] = 0;
223  myState7.vals[1] = 0;
224  myState7.vals[2] = 0;
225  myState7.vals[3] = 0;
226  myState7.vals[4] = 0;
227  myState7.vals[5] = 0;
228  myState7.vals[6] = 0;
229 
230  genfit::MeasurementOnPlane myMeasurementOnPlane;
231  EXPECT_THROW(myRKTrackRep.getState7(myMeasurementOnPlane, myState7), genfit::Exception);
232  EXPECT_EQ(0, myState7[0]);
233  EXPECT_EQ(0, myState7[1]);
234  EXPECT_EQ(0, myState7[2]);
235  EXPECT_EQ(0, myState7[3]);
236  EXPECT_EQ(0, myState7[4]);
237  EXPECT_EQ(0, myState7[5]);
238  EXPECT_EQ(0, myState7[6]);
239 
240  TVectorD myState5(5);
241  myState5[0] = -1;
242  myState5[1] = 1;
243  myState5[2] = 1;
244  myState5[3] = 0.1;
245  myState5[4] = 0.1;
246  genfit::SharedPlanePtr mySharedPlanePtr(new genfit::DetPlane(TVector3(0, 0, 1), TVector3(0, 0, 1), nullptr));
247  genfit::StateOnPlane myStateOnPlane(myState5, mySharedPlanePtr, &myRKTrackRep);
248  EXPECT_NO_THROW(myRKTrackRep.getState7(myStateOnPlane, myState7));
249  EXPECT_FLOAT_EQ(-0.1, myState7[0]);
250  EXPECT_FLOAT_EQ(-0.1, myState7[1]);
251  EXPECT_FLOAT_EQ(1, myState7[2]);
252  EXPECT_FLOAT_EQ(-0.57735, myState7[3]);
253  EXPECT_FLOAT_EQ(-0.57735, myState7[4]);
254  EXPECT_FLOAT_EQ(0.57735, myState7[5]);
255  EXPECT_FLOAT_EQ(-1, myState7[6]);
256 
257  }
258 
260  TEST_F (RKTrackRepTests, getState5) {
261  RKTrackRep myRKTrackRep;
262  genfit::M1x7 myState7;
263  // state7 must already lie on plane of state
264  // We take the values from the getState7 test, because we know them.
265  myState7[0] = -0.1;
266  myState7[1] = -0.1;
267  myState7[2] = 1;
268  myState7[3] = -0.57735;
269  myState7[4] = -0.57735;
270  myState7[5] = 0.57735;
271  myState7[6] = -1;
272  TVectorD myState5(5);
273  genfit::SharedPlanePtr mySharedPlanePtr(new genfit::DetPlane(TVector3(0, 0, 1), TVector3(0, 0, 1), nullptr));
274  genfit::StateOnPlane myStateOnPlane(myState5, mySharedPlanePtr, &myRKTrackRep);
275  EXPECT_NO_THROW(myRKTrackRep.getState5(myStateOnPlane, myState7));
276  EXPECT_FLOAT_EQ(-0.1, myState7[0]);
277  EXPECT_FLOAT_EQ(-0.1, myState7[1]);
278  EXPECT_FLOAT_EQ(1, myState7[2]);
279  EXPECT_FLOAT_EQ(-0.57735, myState7[3]);
280  EXPECT_FLOAT_EQ(-0.57735, myState7[4]);
281  EXPECT_FLOAT_EQ(0.57735, myState7[5]);
282  EXPECT_FLOAT_EQ(-1, myState7[6]);
283 
284  EXPECT_EQ(-1, myStateOnPlane.getState()[0]);
285  EXPECT_EQ(1, myStateOnPlane.getState()[1]);
286  EXPECT_EQ(1, myStateOnPlane.getState()[2]);
287  EXPECT_EQ(0.1, myStateOnPlane.getState()[3]);
288  EXPECT_EQ(0.1, myStateOnPlane.getState()[4]);
289  }
290 
292  TEST_F (RKTrackRepTests, calcJ_pM_5x7) {
293  // TODO: Implement
294  }
295 
297  TEST_F (RKTrackRepTests, transformPM6) {
298  // TODO: Implement
299  }
300 
302  TEST_F (RKTrackRepTests, calcJ_Mp_7x5) {
303  // TODO: Implement
304  }
305 
307  TEST_F (RKTrackRepTests, calcForwardJacobianAndNoise) {
308  const TVector3 startPlaneO(0, 0, 1);
309  const TVector3 startPlaneN(0, 0, 1);
310  const TVector3 destPlaneO(0, 0, -1);
311  const TVector3 destPlaneN(0, 0, 1);
312 
313  genfit::RKTrackRep myRKTrackRep;
314  genfit::DetPlane myStartPlane(startPlaneO, startPlaneN);
315  genfit::DetPlane myDestPlane(destPlaneO, destPlaneN);
316  genfit::M1x7 myStartState;
317  genfit::M1x7 myDestState;
318 
319  EXPECT_EQ(0, myRKTrackRep.ExtrapSteps_.size());
320  EXPECT_THROW(myRKTrackRep.calcForwardJacobianAndNoise(myStartState, myStartPlane, myDestState, myDestPlane),
322  }
323 
325  TEST_F (RKTrackRepTests, transformM6P) {
326  // TODO: Implement
327  }
328 
331  // TODO: Implement
332  }
333 
335  TEST_F (RKTrackRepTests, estimateStep) {
336  // TODO: Implement
337  }
338 
341  // TODO: Implement
342  }
343 
346  genfit::RKTrackRep myRKTrackRep;
347  genfit::M1x7 myState7 = {0, 0, 0, 0, 0, 0, 0};
348  EXPECT_EQ(std::numeric_limits<double>::infinity(), myRKTrackRep.momMag(myState7));
349  myState7 = {0, 0, 0, 0, 0, 0, 1};
350  EXPECT_EQ(1.0, myRKTrackRep.momMag(myState7));
351  myState7 = {0, 0, 0, 0, 0, 0, -1};
352  EXPECT_EQ(1.0, myRKTrackRep.momMag(myState7));
353  }
354 
355 }