1 /* 2 * SurfCylinder_Test.java 3 * 4 * Created on July 24, 2007, 7:58 PM 5 * 6 * $Id: SurfCylinder_Test.java,v 1.1.1.1 2010/04/08 20:38:00 jeremy Exp $ 7 */ 8 9 package org.lcsim.recon.tracking.trfcyl; 10 11 import junit.framework.TestCase; 12 import org.lcsim.recon.tracking.trfbase.CrossStat; 13 import org.lcsim.recon.tracking.trfbase.TrackVector; 14 import org.lcsim.recon.tracking.trfbase.VTrack; 15 import org.lcsim.recon.tracking.trfutil.Assert; 16 import org.lcsim.recon.tracking.trfutil.TRFMath; 17 import org.lcsim.recon.tracking.spacegeom.SpacePath; 18 import org.lcsim.recon.tracking.spacegeom.SpacePoint; 19 20 /** 21 * 22 * @author Norman Graf 23 */ 24 public class SurfCylinder_Test extends TestCase 25 { 26 private boolean debug; 27 /** Creates a new instance of SurfCylinder_Test */ 28 public void testSurfCylinder() 29 { 30 String ok_prefix = "SurfCylinder test (I): "; 31 String error_prefix = "SurfCylinder test (E): "; 32 33 if(debug) System.out.println(ok_prefix 34 + "------ Testing component SurfCylinder. ------"); 35 36 if(debug) System.out.println(ok_prefix + "Check indices."); 37 Assert.assertTrue( SurfCylinder.RADIUS == 0 ); 38 Assert.assertTrue( SurfCylinder.IPHI == 0 ); 39 Assert.assertTrue( SurfCylinder.IZ == 1 ); 40 Assert.assertTrue( SurfCylinder.IALF == 2 ); 41 Assert.assertTrue( SurfCylinder.ITLM == 3 ); 42 Assert.assertTrue( SurfCylinder.IQPT == 4 ); 43 44 //******************************************************************** 45 46 if(debug) System.out.println(ok_prefix + "Test constructor and get_parameter."); 47 double r1 = 12.34; 48 SurfCylinder scy1 = new SurfCylinder(r1); 49 if(debug) System.out.println(scy1); 50 if ( scy1.parameter(SurfCylinder.RADIUS) != r1 ) 51 { 52 if(debug) System.out.println(error_prefix + "Incorrect radius."); 53 System.exit(1); 54 } 55 56 //******************************************************************** 57 58 if(debug) System.out.println(ok_prefix + "Test type."); 59 if(debug) System.out.println(SurfCylinder.staticType()); 60 if(debug) System.out.println(scy1.type()); 61 Assert.assertTrue( scy1.type() != null); 62 Assert.assertTrue( scy1.type().equals(SurfCylinder.staticType()) ); 63 64 //******************************************************************** 65 66 if(debug) System.out.println(ok_prefix + "Test equality and ordering."); 67 SurfCylinder scy2 = new SurfCylinder(12.34); 68 SurfCylinder scy3 = new SurfCylinder(24.68); 69 Assert.assertTrue( scy1.boundEqual(scy2) ); 70 Assert.assertTrue( scy1.pureEqual(scy2) ); 71 Assert.assertTrue( ! scy1.boundEqual(scy3) ); 72 Assert.assertTrue( ! scy1.pureEqual(scy3) ); 73 Assert.assertTrue( scy2.pureLessThan(scy3) ); 74 Assert.assertTrue( ! scy3.pureLessThan(scy2) ); 75 76 //******************************************************************** 77 78 if(debug) System.out.println(ok_prefix + "Test virtual constructor."); 79 SurfCylinder scy4 = (SurfCylinder) scy1.newPureSurface(); 80 if ( !scy1.equals(scy4) ) 81 { 82 if(debug) System.out.println(error_prefix + "Virtual construction failed."); 83 System.exit(5); 84 } 85 86 //******************************************************************** 87 88 if(debug) System.out.println(ok_prefix + "Test crossing status."); 89 TrackVector tvec = new TrackVector(); 90 tvec.set(SurfCylinder.IPHI,1.0); 91 tvec.set(SurfCylinder.IZ,2.0); 92 tvec.set(SurfCylinder.IALF,3.0); 93 tvec.set(SurfCylinder.ITLM,4.0); 94 tvec.set(SurfCylinder.IQPT,5.0); 95 SurfCylinder scin = new SurfCylinder(6.0); 96 SurfCylinder sout = new SurfCylinder(56.0); 97 VTrack ton = new VTrack( scy1.newPureSurface(), tvec ); 98 VTrack tin = new VTrack( scin.newPureSurface(), tvec ); 99 VTrack tout = new VTrack( sout.newPureSurface(), tvec ); 100 CrossStat xs1 = scy1.pureStatus(ton); 101 if(debug) System.out.println(xs1); 102 103 Assert.assertTrue( xs1.at() && xs1.on() && !xs1.inside() && !xs1.outside() 104 && !xs1.inBounds() && ! xs1.outOfBounds() ); 105 CrossStat xs2 = scy1.pureStatus(tin); 106 Assert.assertTrue( !xs2.at() && !xs2.on() && xs2.inside() && !xs2.outside() 107 && !xs2.inBounds() && ! xs2.outOfBounds() ); 108 CrossStat xs3 = scy1.pureStatus(tout); 109 if(debug) System.out.println(xs3); 110 Assert.assertTrue( !xs3.at() && !xs3.on() && !xs3.inside() && xs3.outside() 111 && !xs3.inBounds() && ! xs3.outOfBounds() ); 112 113 //******************************************************************** 114 115 if(debug) System.out.println(ok_prefix + "Test vector difference."); 116 TrackVector tvec2 = new TrackVector(); 117 tvec2.set(0,1.1 + 2.0*TRFMath.TWOPI); 118 tvec2.set(1,2.2); 119 tvec2.set(2,3.3); 120 tvec2.set(3,4.4); 121 tvec2.set(4,5.5); 122 TrackVector diff = scy1.vecDiff(tvec2,tvec); 123 if(debug) System.out.println(tvec2); 124 if(debug) System.out.println(tvec); 125 if(debug) System.out.println(diff); 126 TrackVector ediff = new TrackVector(); 127 ediff.set(0,0.1); 128 ediff.set(1,0.2); 129 ediff.set(2,0.3); 130 ediff.set(3,0.4); 131 ediff.set(4,0.5); 132 TrackVector zero = diff.minus(ediff); 133 if(debug) System.out.println(ediff); 134 if(debug) System.out.println(zero); 135 136 if ( zero.amax() > 1.e-10 ) 137 { 138 if(debug) System.out.println(error_prefix + "Incorrect difference."); 139 System.exit(9); 140 } 141 142 143 //******************************************************************** 144 145 if(debug) System.out.println(ok_prefix + "Test space point."); 146 SpacePoint spt = ton.spacePoint(); 147 if(debug) System.out.println(spt); 148 Assert.assertTrue( spt.rxy() == 12.34 ); 149 Assert.assertTrue( spt.phi() == 1.0 ); 150 Assert.assertTrue( spt.z() == 2.0 ); 151 152 //******************************************************************** 153 154 if(debug) System.out.println(ok_prefix + "Test space vector."); 155 SpacePath svec = ton.spacePath(); 156 double lam = Math.atan(4.0); 157 if(debug) System.out.println(svec); 158 if(debug) System.out.println("svec.rxy()= "+svec.rxy()); 159 Assert.assertTrue( svec.rxy() == 12.34 ); 160 Assert.assertTrue( svec.phi() == 1.0 ); 161 Assert.assertTrue( svec.z() == 2.0 ); 162 Assert.assertTrue( myequal( svec.drxy(), Math.cos(lam)*Math.cos(3.0), debug ) ); 163 Assert.assertTrue( myequal( svec.rxy_dphi(), Math.cos(lam)*Math.sin(3.0), debug ) ); 164 Assert.assertTrue( myequal( svec.dz(), Math.sin(lam), debug ) ); 165 166 //******************************************************************** 167 168 if(debug) System.out.println(ok_prefix + "Test new surface."); 169 if(debug) System.out.println(scy1.newSurface()); 170 Assert.assertTrue(scy1.newSurface()!=scy1); 171 Assert.assertTrue(scy1.newSurface().equals(scy1)); 172 //******************************************************************** 173 174 if(debug) System.out.println(ok_prefix 175 + "------------- All tests passed. -------------"); 176 177 //******************************************************************** 178 } 179 // comparison of doubles 180 public static boolean myequal(double x1, double x2, boolean debug) 181 { 182 double small = 1.e-12; 183 if ( Math.abs(x1-x2) < small ) return true; 184 if(debug) System.out.println("myequal: difference too large:"); 185 if(debug) System.out.println("value 1: " + x1); 186 if(debug) System.out.println("value 2: " + x2); 187 if(debug) System.out.println(" diff: " + (x1-x2)); 188 if(debug) System.out.println("maxdiff: " + small); 189 return false; 190 } 191 }