1 /* 2 * PropCyl_Test.java 3 * 4 * Created on July 24, 2007, 8:33 PM 5 * 6 * $Id: PropCyl_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.ETrack; 13 import org.lcsim.recon.tracking.trfbase.PropDir; 14 import org.lcsim.recon.tracking.trfbase.PropStat; 15 import org.lcsim.recon.tracking.trfbase.TrackError; 16 import org.lcsim.recon.tracking.trfbase.TrackVector; 17 import org.lcsim.recon.tracking.trfbase.VTrack; 18 import org.lcsim.recon.tracking.trfutil.Assert; 19 20 /** 21 * 22 * @author Norman Graf 23 */ 24 public class PropCyl_Test extends TestCase 25 { 26 private boolean debug; 27 /** Creates a new instance of PropCyl_Test */ 28 public void testPropCyl() 29 { 30 String ok_prefix = "PropCyl (I): "; 31 String error_prefix = "PropCyl test (E): "; 32 33 if(debug) System.out.println(ok_prefix + "-------- Testing component PropCyl. --------" ); 34 35 //******************************************************************** 36 37 if(debug) System.out.println(ok_prefix + "Test constructor." ); 38 double bfield = 2.0; 39 PropCyl prop = new PropCyl(bfield); 40 if(debug) System.out.println( prop ); 41 42 //******************************************************************** 43 44 // Here we propagate some tracks both forward and backward and then 45 // each back to the original track. We check that the returned 46 // track parameters match those of the original track. 47 if(debug) System.out.println(ok_prefix + "Check reversibility." ); 48 double r1[] = { 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0 }; 49 double r2[] = { 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0 }; 50 double phi1[] = { 0.0, 1.0, -1.0, 2.0, 2.0, -2.0, 3.0, 0.0 }; 51 double alf1[] = { 0.0, .0001,-.0001, 0.9, -0.9, 0.9, 0.9, 3.0 }; 52 double crv[] = { 0.0, 0.0, 0.0, 0.0, 0.0, -0.05, 0.01, 0.0 }; 53 double z[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 15.0, 0.0 }; 54 double tlm[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.35, 0.0 }; 55 double fbdf[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; 56 double bfdf[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; 57 double maxdiff = 1.e-10; 58 int ntrk = 8; 59 int i; 60 for ( i=0; i<ntrk; ++i ) 61 { 62 if(debug) System.out.println("********** Propagate track " + i + ". **********" ); 63 PropStat pstat; 64 SurfCylinder scy1 = new SurfCylinder(r1[i]); 65 SurfCylinder scy2 = new SurfCylinder(r2[i]); 66 TrackVector vec1 = new TrackVector(); 67 68 vec1.set(0,phi1[i]); // phi 69 vec1.set(1,z[i]); // z 70 vec1.set(2,alf1[i]); // alpha 71 vec1.set(3,tlm[i]); // tlam 72 vec1.set(4,crv[i]); // curv 73 VTrack trv1 = new VTrack(scy1,vec1); 74 if(debug) System.out.println(" starting: " + trv1 ); 75 // 76 // Propagate forward. 77 VTrack trv2f = new VTrack(trv1); 78 pstat = prop.vecDirProp(trv2f,scy2,PropDir.FORWARD); 79 if(debug) System.out.println(" forward: " + trv2f ); 80 if(debug) System.out.println(pstat ); 81 Assert.assertTrue( pstat.forward() ); 82 // 83 // Propagate backward. 84 VTrack trv2b = new VTrack(trv1); 85 pstat = prop.vecDirProp(trv2b,scy2,PropDir.BACKWARD); 86 if(debug) System.out.println(" backward: " + trv2b ); 87 if(debug) System.out.println(pstat ); 88 Assert.assertTrue( pstat.backward() ); 89 // 90 // Propagate forward track backward. 91 VTrack trv2fb = new VTrack(trv2f); 92 pstat = prop.vecDirProp(trv2fb,scy1,PropDir.BACKWARD); 93 if(debug) System.out.println(" f return: " + trv2fb ); 94 if(debug) System.out.println(pstat ); 95 Assert.assertTrue( pstat.backward() ); 96 // 97 // Propagate backward track forward. 98 VTrack trv2bf = new VTrack(trv2b); 99 pstat = prop.vecDirProp(trv2bf,scy1,PropDir.FORWARD); 100 if(debug) System.out.println(" b return: " + trv2bf ); 101 if(debug) System.out.println(pstat ); 102 Assert.assertTrue( pstat.forward() ); 103 // Check the return differences. 104 // At least one of these should be zero. 105 // Not both because we may cross the original surface on one of 106 // the paths out. 107 double difff = 108 scy1.vecDiff(trv2fb.vector(),trv1.vector()).amax(); 109 double diffb = 110 scy1.vecDiff(trv2bf.vector(),trv1.vector()).amax(); 111 if(debug) System.out.println("diffs: " + difff + ' ' + diffb ); 112 Assert.assertTrue( difff<maxdiff || diffb<maxdiff ); 113 // 114 // Check no-move forward propagation to the same surface. 115 VTrack trv1s = new VTrack(trv1); 116 pstat = prop.vecDirProp(trv1s,scy1,PropDir.FORWARD); 117 if(debug) System.out.println(" same f forward: " + trv1s ); 118 if(debug) System.out.println(pstat ); 119 Assert.assertTrue( pstat.same() ); 120 Assert.assertTrue( pstat.pathDistance() == 0 ); 121 // 122 // Check no-move backward propagation to the same surface. 123 trv1s = new VTrack(trv1); 124 pstat = prop.vecDirProp(trv1s,scy1,PropDir.BACKWARD); 125 if(debug) System.out.println(" same f backward: " + trv1s ); 126 if(debug) System.out.println(pstat ); 127 Assert.assertTrue( pstat.same() ); 128 Assert.assertTrue( pstat.pathDistance() == 0 ); 129 // 130 // Check move propagation to the same surface. 131 // 132 // forward 133 int successes = 0; 134 trv1s = new VTrack(trv1); 135 pstat = prop.vecDirProp(trv1s,scy1,PropDir.FORWARD_MOVE); 136 if(debug) System.out.println(" forward move: " + trv1s ); 137 if(debug) System.out.println(pstat ); 138 if ( pstat.forward() ) ++successes; 139 // backward 140 trv1s = trv1; 141 pstat = prop.vecDirProp(trv1s,scy1,PropDir.BACKWARD_MOVE); 142 if(debug) System.out.println(" backward move: " + trv1s ); 143 if(debug) System.out.println(pstat ); 144 if ( pstat.backward() ) ++successes; 145 // One of these should have succeeded. 146 Assert.assertTrue( successes == 1 ); 147 // 148 // nearest 149 trv1s = trv1; 150 pstat = prop.vecDirProp(trv1s,scy1,PropDir.NEAREST_MOVE); 151 if(debug) System.out.println(" nearest move: " + trv1s ); 152 if(debug) System.out.println(pstat ); 153 Assert.assertTrue( pstat.success() ); 154 155 } 156 //******************************************************************** 157 158 // Repeat the above with errors. 159 if(debug) System.out.println(ok_prefix + "Check reversibility with errors." ); 160 double epp[] = { 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 }; 161 double epz[] = { 0.01, -0.01, 0.01, -0.01, 0.01, -0.01, 0.01, 0.01 }; 162 double ezz[] = { 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25 }; 163 double epa[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004, 0.004, 0.004 }; 164 double eza[] = { 0.04, -0.04, 0.04, -0.04, 0.04, -0.04, 0.04, 0.04 }; 165 double eaa[] = { 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 }; 166 double epl[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004, 0.004, 0.004 }; 167 double eal[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004, 0.004, 0.004 }; 168 double ezl[] = { 0.04, -0.04, 0.04, -0.04, 0.04, -0.04, 0.04, 0.04 }; 169 double ell[] = { 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02 }; 170 double epc[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004, 0.004, 0.004 }; 171 double ezc[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004, 0.004, 0.004 }; 172 double eac[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004, 0.004, 0.004 }; 173 double elc[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004, 0.004, 0.004 }; 174 double ecc[] = { 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 }; 175 for ( i=0; i<ntrk; ++i ) 176 { 177 if(debug) System.out.println("********** Propagate track " + i + ". **********" ); 178 PropStat pstat; 179 SurfCylinder scy1 = new SurfCylinder(r1[i]); 180 SurfCylinder scy2 = new SurfCylinder(r2[i]); 181 TrackVector vec1 = new TrackVector(); 182 vec1.set(0,phi1[i]); // phi 183 vec1.set(1,z[i]); // z 184 vec1.set(2,alf1[i]); // alpha 185 vec1.set(3,tlm[i]); // tlam 186 vec1.set(4,crv[i]); // curv 187 TrackError err1 = new TrackError(); 188 err1.set(0,0,epp[i]); 189 err1.set(0,1,epz[i]); 190 err1.set(1,1,ezz[i]); 191 err1.set(0,2,epa[i]); 192 err1.set(1,2,eza[i]); 193 err1.set(2,2,eaa[i]); 194 err1.set(0,3,epl[i]); 195 err1.set(1,3,ezl[i]); 196 err1.set(2,3,eal[i]); 197 err1.set(3,3,ell[i]); 198 err1.set(0,4,epc[i]); 199 err1.set(1,4,ezc[i]); 200 err1.set(2,4,eac[i]); 201 err1.set(3,4,elc[i]); 202 err1.set(4,4,ecc[i]); 203 ETrack trv1 = new ETrack(scy1.newPureSurface(), vec1, err1 ); 204 if(debug) System.out.println(" starting: " + trv1 ); 205 ETrack trv2f = new ETrack(trv1); 206 if(debug) System.out.println("trv2f= "+trv2f); 207 pstat = prop.errDirProp(trv2f,scy2,PropDir.FORWARD); 208 Assert.assertTrue( pstat.forward() ); 209 if(debug) System.out.println(" forward: " + trv2f ); 210 ETrack trv2b = new ETrack(trv1); 211 pstat = prop.errDirProp(trv2b,scy2,PropDir.BACKWARD); 212 Assert.assertTrue( pstat.backward() ); 213 if(debug) System.out.println(" backward: " + trv2b ); 214 ETrack trv2fb = new ETrack(trv2f); 215 if(debug) System.out.println("trv2fb= "+trv2fb+", scy1= "+scy1); 216 pstat = prop.errDirProp(trv2fb,scy1,PropDir.BACKWARD); 217 if(debug) System.out.println("pstat= "+pstat); 218 Assert.assertTrue( pstat.backward() ); 219 if(debug) System.out.println(" f return: " + trv2fb ); 220 ETrack trv2bf = new ETrack(trv2b); 221 pstat = prop.errDirProp(trv2bf,scy1,PropDir.FORWARD); 222 Assert.assertTrue( pstat.forward() ); 223 if(debug) System.out.println(" b return: " + trv2bf ); 224 double difff = 225 scy1.vecDiff(trv2fb.vector(),trv1.vector()).amax(); 226 double diffb = 227 scy1.vecDiff(trv2bf.vector(),trv1.vector()).amax(); 228 if(debug) System.out.println("vec diffs: " + difff + ' ' + diffb ); 229 Assert.assertTrue( difff<maxdiff || diffb<maxdiff ); 230 TrackError dfb = trv2fb.error().minus(trv1.error()); 231 TrackError dbf = trv2bf.error().minus(trv1.error()); 232 double edifff = dfb.amax(); 233 double ediffb = dbf.amax(); 234 if(debug) System.out.println("err diffs: " + edifff + ' ' + ediffb ); 235 Assert.assertTrue( edifff<maxdiff || ediffb<maxdiff ); 236 237 } 238 239 //******************************************************************** 240 241 if(debug) System.out.println(ok_prefix + "Test cloning." ); 242 Assert.assertTrue( prop.newPropagator() != null ); 243 244 //******************************************************************** 245 246 if(debug) System.out.println(ok_prefix + "Test the field." ); 247 Assert.assertTrue( prop.bField() == bfield ); 248 249 250 if(debug) System.out.println(ok_prefix + "------------- All tests passed. -------------" ); 251 //******************************************************************** 252 253 } 254 255 }