View Javadoc

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   * @author Norman A. Graf
11   *
12   * @version $Id:
13   */
14  public class CartesianPointTensorTest extends TestCase
15  {
16      boolean debug = false;
17      public void testCartesianPointTensor()
18      {
19          int np = 10;   // Number of points data.
20          int nt = 5;   // Number of tensors data.
21  
22          double p[][] =
23          {
24              {
25                  0., 0., 0.
26              },
27              {
28                  1., 0., 0.
29              },
30              {
31                  0., 1., 0.
32              },
33              {
34                  0., 0., 1.
35              },
36              {
37                  1., 1., 0.
38              },
39              {
40                  0., 1., 1.
41              },
42              {
43                  1., 0., 1.
44              },
45              {
46                  1., 2., 3.
47              },
48              {
49                  -2., -3., 1.
50              },
51              {
52                  4., -5., 3.
53              }
54          };
55  
56          double t[][][] =
57          {
58              {
59                  {
60                      0., 0., 0.
61                  },
62                  {
63                      0., 0., 0.
64                  },
65                  {
66                      0., 0., 0.
67                  }
68              },
69              {
70                  {
71                      1., 0., 0.
72                  },
73                  {
74                      0., 1., 0.
75                  },
76                  {
77                      0., 0., 1.
78                  }
79              },
80              {
81                  {
82                      1., 1., 1.
83                  },
84                  {
85                      1., 1., 1.
86                  },
87                  {
88                      1., 1., 1.
89                  }
90              },
91              {
92                  {
93                      3., -2., 4.
94                  },
95                  {
96                      -3., 6., -5.
97                  },
98                  {
99                      -1., 2., 1.
100                 }
101             },
102             {
103                 {
104                     -2., 2., -1.
105                 },
106                 {
107                     3., -4., 5.
108                 },
109                 {
110                     1., -5., 3.
111                 }
112             }
113         };
114 
115         // Loop over points.
116 
117         for (int ip = 0; ip < np; ++ip)
118         {
119             // Loop over tensors.
120             for (int it = 0; it < nt; ++it)
121             {
122 
123                 // Construct tensor in Cartesian coordinates.
124 
125                 CartesianPointTensor tensor0 = new CartesianPointTensor(p[ip][0], p[ip][1], p[ip][2],
126                         t[it][0][0], t[it][0][1], t[it][0][2],
127                         t[it][1][0], t[it][1][1], t[it][1][2],
128                         t[it][2][0], t[it][2][1], t[it][2][2]);
129                 if(debug) System.out.println("Cartesian coordinates.");
130                 if(debug) System.out.println(tensor0);
131                 CartesianPoint point0 = new CartesianPoint(p[ip][0], p[ip][1], p[ip][2]);
132                 CartesianPointTensor tensor0a = new CartesianPointTensor(point0,
133                         t[it][0][0], t[it][0][1], t[it][0][2],
134                         t[it][1][0], t[it][1][1], t[it][1][2],
135                         t[it][2][0], t[it][2][1], t[it][2][2]);
136                 Assert.assertTrue(tensor0.equals(tensor0a));
137                 SpacePointTensor tensor0b = new SpacePointTensor(tensor0);
138                 if(debug) System.out.println("tensor0:  \n" + tensor0);
139                 if(debug) System.out.println("tensor0b:  \n" +tensor0b);
140                 Assert.assertTrue(tensor0.equals(tensor0b));
141                 tensor0b = tensor0;
142                 Assert.assertTrue(tensor0.equals(tensor0b));
143 
144                 // Test components.
145 
146                 Assert.assertTrue(myequal(tensor0.t_x_x(), t[it][0][0]));
147                 Assert.assertTrue(myequal(tensor0.t_x_y(), t[it][0][1]));
148                 Assert.assertTrue(myequal(tensor0.t_x_z(), t[it][0][2]));
149                 Assert.assertTrue(myequal(tensor0.t_y_x(), t[it][1][0]));
150                 Assert.assertTrue(myequal(tensor0.t_y_y(), t[it][1][1]));
151                 Assert.assertTrue(myequal(tensor0.t_y_z(), t[it][1][2]));
152                 Assert.assertTrue(myequal(tensor0.t_z_x(), t[it][2][0]));
153                 Assert.assertTrue(myequal(tensor0.t_z_y(), t[it][2][1]));
154                 Assert.assertTrue(myequal(tensor0.t_z_z(), t[it][2][2]));
155 
156             }
157         }
158     }
159 
160     static boolean myequal(double x1, double x2)
161     {
162         return abs(x2 - x1) < 1.e-10;
163     }
164 }