1 package org.lcsim.recon.tracking.spacegeom;
2
3 import junit.framework.TestCase;
4 import org.lcsim.recon.tracking.trfutil.Assert;
5
6 import static java.lang.Math.abs;
7
8
9
10
11
12
13 public class SphericalPointTensorTest extends TestCase
14 {
15 boolean debug = false;
16 public void testSphericalPointTensor()
17 {
18 int np = 10;
19 int nt = 5;
20
21 double p[][] =
22 {
23 {
24 0., 0., 0.
25 },
26 {
27 1., 0., 0.
28 },
29 {
30 0., 1., 0.
31 },
32 {
33 0., 0., 1.
34 },
35 {
36 1., 1., 0.
37 },
38 {
39 0., 1., 1.
40 },
41 {
42 1., 0., 1.
43 },
44 {
45 1., 2., 3.
46 },
47 {
48 -2., -3., 1.
49 },
50 {
51 4., -5., 3.
52 }
53 };
54
55 double t[][][] =
56 {
57 {
58 {
59 0., 0., 0.
60 },
61 {
62 0., 0., 0.
63 },
64 {
65 0., 0., 0.
66 }
67 },
68 {
69 {
70 1., 0., 0.
71 },
72 {
73 0., 1., 0.
74 },
75 {
76 0., 0., 1.
77 }
78 },
79 {
80 {
81 1., 1., 1.
82 },
83 {
84 1., 1., 1.
85 },
86 {
87 1., 1., 1.
88 }
89 },
90 {
91 {
92 3., -2., 4.
93 },
94 {
95 -3., 6., -5.
96 },
97 {
98 -1., 2., 1.
99 }
100 },
101 {
102 {
103 -2., 2., -1.
104 },
105 {
106 3., -4., 5.
107 },
108 {
109 1., -5., 3.
110 }
111 }
112 };
113
114
115
116 for (int ip = 0; ip < np; ++ip)
117 {
118
119 for (int it = 0; it < nt; ++it)
120 {
121
122
123 SphericalPointTensor tensor2 = new SphericalPointTensor(p[ip][0], p[ip][1], p[ip][2],
124 t[it][0][0], t[it][0][1], t[it][0][2],
125 t[it][1][0], t[it][1][1], t[it][1][2],
126 t[it][2][0], t[it][2][1], t[it][2][2]);
127 if(debug) System.out.println("Spherical coordinates.");
128 if(debug) System.out.println(tensor2);
129 SphericalPoint point2 = new SphericalPoint(p[ip][0], p[ip][1], p[ip][2]);
130 SphericalPointTensor tensor2a = new SphericalPointTensor(point2,
131 t[it][0][0], t[it][0][1], t[it][0][2],
132 t[it][1][0], t[it][1][1], t[it][1][2],
133 t[it][2][0], t[it][2][1], t[it][2][2]);
134 Assert.assertTrue(tensor2.equals(tensor2a));
135 SpacePointTensor tensor2b = new SpacePointTensor(tensor2);
136 Assert.assertTrue(tensor2.equals(tensor2b));
137 SpacePointTensor tensor0b = tensor2;
138 Assert.assertTrue(tensor2.equals(tensor0b));
139
140
141
142 Assert.assertTrue(myequal(tensor2.t_rxyz_rxyz(), t[it][0][0]));
143 Assert.assertTrue(myequal(tensor2.t_rxyz_theta(), t[it][0][1]));
144 Assert.assertTrue(myequal(tensor2.t_rxyz_phi(), t[it][0][2]));
145 Assert.assertTrue(myequal(tensor2.t_theta_rxyz(), t[it][1][0]));
146 Assert.assertTrue(myequal(tensor2.t_theta_theta(), t[it][1][1]));
147 Assert.assertTrue(myequal(tensor2.t_theta_phi(), t[it][1][2]));
148 Assert.assertTrue(myequal(tensor2.t_phi_rxyz(), t[it][2][0]));
149 Assert.assertTrue(myequal(tensor2.t_phi_theta(), t[it][2][1]));
150 Assert.assertTrue(myequal(tensor2.t_phi_phi(), t[it][2][2]));
151
152 }
153 }
154
155
156 }
157 static boolean myequal(double x1, double x2)
158 {
159 return abs(x2 - x1) < 1.e-10;
160 }
161
162 }