View Javadoc

1   package org.lcsim.spacegeom;
2   // CartesianPathTest.cpp
3   
4   // Test the SpacePath class.
5   
6   import junit.framework.TestCase;
7   
8   import org.lcsim.spacegeom.CartesianPath;
9   import org.lcsim.spacegeom.CylindricalPath;
10  import org.lcsim.spacegeom.SpacePath;
11  import org.lcsim.spacegeom.SphericalPath;
12  
13  public class SphericalPathTest extends TestCase
14  {
15      //**********************************************************************
16      boolean debug = false;
17      private static final boolean myequal(double x1, double x2)
18      {
19          return Math.abs(x2-x1) < 1.e-10;
20      }
21      
22      //**********************************************************************
23      
24      public void testSphericalPath()
25      {
26          
27          String name = "SphericalPath";
28          String ok_prefix = name + " test (I): ";
29          String error_prefix = name + " test (E): ";
30          
31          if (debug) System.out.println( ok_prefix
32                  + "------- Testing component " + name + ". -------" );
33          
34          double x = 1.23;
35          double y = 2.46;
36          double z = 3.69;
37          double dx = 0.23;
38          double dy = 0.45;
39          double dz = 0.67;
40          
41          //**********************************************************************
42          
43          if (debug) System.out.println( ok_prefix + "Testing constructors." );
44          // Create a space path element
45          CartesianPath cart = new CartesianPath(x,y,z,dx,dy,dz);
46          if (debug) System.out.println( cart );
47          
48          // Create in cylindrical coordinates.
49          CylindricalPath cyl = new CylindricalPath( cart.getStartPoint().rxy(), cart.getStartPoint().phi(), cart.getStartPoint().z(),
50                  cart.drxy(), cart.rxy_dphi(), cart.dz() );
51          if (debug) System.out.println( cyl );
52          
53          // Create in spherical coordinates.
54          SphericalPath sph = new SphericalPath( cyl.getStartPoint().rxyz(), cyl.getStartPoint().phi(), cyl.getStartPoint().theta(),
55                  cyl.drxyz(), cyl.rxyz_dtheta(), cyl.rxy_dphi() );
56          if (debug) System.out.println( sph );
57          
58          assertTrue( myequal(sph.getStartPoint().x(),x) );
59          assertTrue( myequal(sph.getStartPoint().y(),y) );
60          assertTrue( myequal(sph.getStartPoint().z(),z) );
61          assertTrue( myequal(sph.dx(),dx) );
62          assertTrue( myequal(sph.dy(),dy) );
63          assertTrue( myequal(sph.dz(),dz) );
64          
65          //**********************************************************************
66          
67          if (debug) System.out.println( ok_prefix + "Testing assignment." );
68          
69          SpacePath dpth = new SpacePath();
70          if (debug) System.out.println( dpth );
71          assertTrue( dpth.magnitude() == 0.0 );
72          dpth = sph;
73          if (debug) System.out.println( dpth );
74          assertTrue( myequal(dpth.getStartPoint().x(),x) );
75          assertTrue( myequal(dpth.getStartPoint().y(),y) );
76          assertTrue( myequal(dpth.getStartPoint().z(),z) );
77          assertTrue( myequal(dpth.dx(),dx) );
78          assertTrue( myequal(dpth.dy(),dy) );
79          assertTrue( myequal(dpth.dz(),dz) );
80          
81          //**********************************************************************
82          
83          if (debug) System.out.println( ok_prefix + "Testing normalizations." );
84          double n0 = dx*dx + dy*dy + dz*dz;
85          if (debug) System.out.println( n0 );
86          double ncart = dpth.dx()*dpth.dx() +
87                  dpth.dy()*dpth.dy() +
88                  dpth.dz()*dpth.dz();
89          if (debug) System.out.println( ncart );
90          double ncyl = dpth.drxy()*dpth.drxy() +
91                   // FIXME dpth.rxy_dphi()*dpth.rxy_dphi() +
92                   dpth.dz()*dpth.dz();
93          if (debug) System.out.println( ncyl );
94          double nsph = dpth.drxyz()*dpth.drxyz();
95                  // FIXME dpth.rxy_dphi()*dpth.rxy_dphi() + dpth.rxyz_dtheta()*dpth.rxyz_dtheta();
96          if (debug) System.out.println( nsph );
97          assertTrue( myequal(ncart,n0) );
98          assertTrue( myequal(ncyl,n0) );
99          assertTrue( myequal(nsph,n0) );
100         assertTrue( myequal( Math.sqrt(n0), dpth.magnitude() ) );
101         
102         //**********************************************************************
103         
104         if (debug) System.out.println( ok_prefix
105                 + "------------- All tests passed. ------------" );
106         
107     }
108 }