1 /* 2 * SurfXYPlane_Test.java 3 * 4 * Created on July 24, 2007, 10:36 PM 5 * 6 * $Id: SurfXYPlane_Test.java,v 1.1.1.1 2010/04/08 20:38:00 jeremy Exp $ 7 */ 8 9 package org.lcsim.recon.tracking.trfxyp; 10 11 import junit.framework.TestCase; 12 import org.lcsim.recon.tracking.spacegeom.SpacePath; 13 import org.lcsim.recon.tracking.spacegeom.SpacePoint; 14 import org.lcsim.recon.tracking.trfbase.CrossStat; 15 import org.lcsim.recon.tracking.trfbase.TrackVector; 16 import org.lcsim.recon.tracking.trfbase.VTrack; 17 import org.lcsim.recon.tracking.trfutil.Assert; 18 19 /** 20 * 21 * @author Norman Graf 22 */ 23 public class SurfXYPlane_Test extends TestCase 24 { 25 private boolean debug; 26 27 // comparison of doubles 28 static boolean myequal(double x1, double x2) 29 { 30 double small = 1.e-12; 31 if ( Math.abs(x1-x2) < small ) return true; 32 System.out.println( "myequal: difference too large:" ); 33 System.out.println( "value 1: " + x1 ); 34 System.out.println( "value 2: " + x2 ); 35 System.out.println( " diff: " + (x1-x2) ); 36 System.out.println( "maxdiff: " + small ); 37 return false; 38 } 39 /** Creates a new instance of SurfXYPlane_Test */ 40 public void testSurfXYPlane() 41 { 42 String ok_prefix = "SurfXYPlane test (I): "; 43 String error_prefix = "SurfXYPlane test (E): "; 44 45 if(debug) System.out.println( ok_prefix 46 + "------ Testing component SurfXYPlane. ------" ); 47 48 //******************************************************************** 49 50 if(debug) System.out.println( ok_prefix + "Test constructor and get_parameter." ); 51 double dist = 12.34; 52 double phi = Math.PI/3.; 53 SurfXYPlane sxyp1 = new SurfXYPlane(dist,phi); 54 if(debug) System.out.println( sxyp1 ); 55 if ( sxyp1.parameter(SurfXYPlane.NORMPHI) != phi ) 56 { 57 if(debug) System.out.println( error_prefix + "Incorrect phi of normal" ); 58 System.exit(1); 59 } 60 if ( sxyp1.parameter(SurfXYPlane.DISTNORM) != dist ) 61 { 62 if(debug) System.out.println( error_prefix + "Incorrect normal value" ); 63 System.exit(2); 64 } 65 66 //******************************************************************** 67 68 if(debug) System.out.println( ok_prefix + "Test copy constructor." ); 69 70 SurfXYPlane sxypc = new SurfXYPlane(sxyp1); 71 Assert.assertTrue( sxypc.equals(sxyp1) ); 72 73 74 //******************************************************************** 75 76 if(debug) System.out.println( ok_prefix + "Test type." ); 77 if(debug) System.out.println( SurfXYPlane.staticType() ); 78 if(debug) System.out.println( sxyp1.type() ); 79 Assert.assertTrue( sxyp1.type() != null ); 80 Assert.assertTrue( sxyp1.type().equals(SurfXYPlane.staticType()) ); 81 82 //******************************************************************** 83 84 if(debug) System.out.println( ok_prefix + "Test equality." ); 85 SurfXYPlane sxyp2 = new SurfXYPlane(12.34,Math.PI/3.); 86 SurfXYPlane sxyp3= new SurfXYPlane(24.68,Math.PI/3.); 87 SurfXYPlane sxyp4= new SurfXYPlane(12.34,Math.PI/5.); 88 if ( !sxyp1.boundEqual(sxyp2) || !sxyp1.pureEqual(sxyp2) ) 89 { 90 if(debug) System.out.println( error_prefix + "Equality failed." ); 91 System.exit(3); 92 } 93 if ( sxyp1.boundEqual(sxyp4) || sxyp1.pureEqual(sxyp4) ) 94 { 95 if(debug) System.out.println( error_prefix + "Inequality failed on phi" ); 96 System.exit(4); 97 } 98 if ( sxyp1.boundEqual(sxyp3) || sxyp1.pureEqual(sxyp3) ) 99 { 100 if(debug) System.out.println( error_prefix + "Inequality failed on normal" ); 101 System.exit(5); 102 } 103 104 //******************************************************************** 105 106 if(debug) System.out.println( ok_prefix + "Test comparison." ); 107 { 108 SurfXYPlane lt= new SurfXYPlane(10.,Math.PI/3.); 109 SurfXYPlane ltp= new SurfXYPlane(10.,Math.PI/6.); 110 SurfXYPlane gt= new SurfXYPlane(11.,Math.PI/2.); 111 SurfXYPlane gtd= new SurfXYPlane(11,Math.PI/3.); 112 SurfXYPlane gtdp= new SurfXYPlane(11,Math.PI/6.); 113 Assert.assertTrue(lt.pureLessThan(gt)); 114 Assert.assertTrue(!gt.pureLessThan(lt)); 115 Assert.assertTrue(ltp.pureLessThan(lt)); 116 Assert.assertTrue(!lt.pureLessThan(ltp)); 117 Assert.assertTrue(lt.pureLessThan(gtd)); 118 Assert.assertTrue(!gtd.pureLessThan(lt)); 119 Assert.assertTrue(lt.pureLessThan(gtdp)); 120 Assert.assertTrue(!gtdp.pureLessThan(lt)); 121 Assert.assertTrue(!lt.pureLessThan(lt)); 122 } 123 124 //******************************************************************** 125 126 if(debug) System.out.println( ok_prefix + "Test virtual constructor." ); 127 SurfXYPlane psxyp5 = (SurfXYPlane)sxyp1.newPureSurface(); 128 if ( !sxyp1.equals(psxyp5) ) 129 { 130 if(debug) System.out.println( error_prefix + "Virtual construction failed." ); 131 System.exit(6); 132 } 133 134 //******************************************************************** 135 136 if(debug) System.out.println( ok_prefix + "Test crossing status." ); 137 TrackVector tvec = new TrackVector(); 138 tvec.set(SurfXYPlane.IV, 1.0); 139 tvec.set(SurfXYPlane.IZ, 2.0); 140 tvec.set(SurfXYPlane.IDVDU, 3.0); 141 tvec.set(SurfXYPlane.IDZDU, 4.0); 142 tvec.set(SurfXYPlane.IQP, 5.0); 143 SurfXYPlane sfin= new SurfXYPlane(1.0,Math.PI/5.); 144 SurfXYPlane sfout = new SurfXYPlane(60.0,Math.PI/5.); 145 VTrack ton = new VTrack( sxyp1.newPureSurface(), tvec ); 146 ton.setForward(); 147 VTrack tin= new VTrack( sfin.newPureSurface() , tvec ); 148 tin.setForward(); 149 VTrack tout= new VTrack( sfout.newPureSurface() , tvec ); 150 tout.setForward(); 151 CrossStat xs1 = sxyp1.pureStatus(ton); 152 if(debug) System.out.println( xs1 ); 153 Assert.assertTrue( xs1.at() && xs1.on() && !xs1.inside() && !xs1.outside() 154 && !xs1.inBounds() && ! xs1.outOfBounds() ); 155 CrossStat xs2 = sxyp1.pureStatus(tin); 156 Assert.assertTrue( !xs2.at() && !xs2.on() && xs2.inside() && !xs2.outside() 157 && !xs2.inBounds() && ! xs2.outOfBounds() ); 158 CrossStat xs3 = sxyp1.pureStatus(tout); 159 if(debug) System.out.println( xs3 ); 160 Assert.assertTrue( !xs3.at() && !xs3.on() && !xs3.inside() && xs3.outside() 161 && !xs3.inBounds() && ! xs3.outOfBounds() ); 162 163 //******************************************************************** 164 165 if(debug) System.out.println( ok_prefix + "Test vector difference." ); 166 TrackVector tvec2 = new TrackVector(); 167 tvec2.set(SurfXYPlane.IV, 1.1); 168 tvec2.set(SurfXYPlane.IZ, 2.2); 169 tvec2.set(SurfXYPlane.IDVDU, 3.3); 170 tvec2.set(SurfXYPlane.IDZDU, 4.4); 171 tvec2.set(SurfXYPlane.IQP, 5.5); 172 TrackVector diff = sxyp1.vecDiff(tvec2,tvec); 173 if(debug) System.out.println( tvec2 ); 174 if(debug) System.out.println( tvec ); 175 if(debug) System.out.println( diff ); 176 TrackVector ediff = new TrackVector(); 177 ediff.set(SurfXYPlane.IV, 0.1); 178 ediff.set(SurfXYPlane.IZ, 0.2); 179 ediff.set(SurfXYPlane.IDVDU, 0.3); 180 ediff.set(SurfXYPlane.IDZDU, 0.4); 181 ediff.set(SurfXYPlane.IQP, 0.5); 182 TrackVector zero = diff.minus(ediff); 183 if(debug) System.out.println( ediff ); 184 if(debug) System.out.println( zero ); 185 if ( zero.amax() > 1.e-10 ) 186 { 187 if(debug) System.out.println( error_prefix + "Incorrect difference." ); 188 System.exit(9); 189 } 190 191 //******************************************************************** 192 193 if(debug) System.out.println( ok_prefix + "Test space point." ); 194 SpacePoint spt = ton.spacePoint(); 195 if(debug) System.out.println( spt ); 196 double csin = Math.sin(Math.PI/3.); 197 Assert.assertTrue( myequal(spt.x(), 12.34/2.-csin) ); 198 Assert.assertTrue( myequal(spt.y(), 12.34*csin+0.5) ); 199 Assert.assertTrue( spt.z() == 2.0 ); 200 201 //******************************************************************** 202 203 if(debug) System.out.println( ok_prefix + "Test space vector." ); 204 SpacePath svec = ton.spacePath(); 205 if(debug) System.out.println( svec ); 206 double ds = 1./Math.sqrt(26.); 207 Assert.assertTrue( myequal(svec.x(), 12.34/2.-csin) ); 208 Assert.assertTrue( myequal(svec.y(), 12.34*csin+0.5) ); 209 Assert.assertTrue( svec.z() == 2.0 ); 210 Assert.assertTrue( myequal( svec.dz(), 4.*ds) ); 211 Assert.assertTrue( myequal( svec.dy(), ds*csin+3.*ds/2. ) ); 212 Assert.assertTrue( myequal( svec.dx(), ds/2.-3.*ds*csin ) ); 213 214 ton.setBackward(); 215 SpacePath bsvec = ton.spacePath(); 216 if(debug) System.out.println( bsvec ); 217 218 ds = -1./Math.sqrt(26.); 219 220 Assert.assertTrue( myequal(bsvec.x(), 12.34/2.-csin) ); 221 Assert.assertTrue( myequal(bsvec.y(), 12.34*csin+0.5) ); 222 Assert.assertTrue( bsvec.z() == 2.0 ); 223 Assert.assertTrue( myequal( bsvec.dz(), 4.*ds) ); 224 Assert.assertTrue( myequal( bsvec.dy(), ds*csin+3.*ds/2. ) ); 225 Assert.assertTrue( myequal( bsvec.dx(), ds/2.-3.*ds*csin ) ); 226 227 if(debug) System.out.println( ok_prefix 228 + "------------- All tests passed. -------------" ); 229 230 //******************************************************************** 231 } 232 233 }