1 /* 2 * PropXYXYBV_Test.java 3 * 4 * Created on July 24, 2007, 10:21 PM 5 * 6 * $Id: PropXYXYBV_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.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 PropXYXYBV_Test extends TestCase 25 { 26 private boolean debug; 27 /** Creates a new instance of PropXYXYBV_Test */ 28 public void testPropXYXYBV() 29 { 30 String ok_prefix = "PropXYXYBV (I): "; 31 String error_prefix = "PropXYXYBV test (E): "; 32 33 if(debug) System.out.println( ok_prefix 34 + "-------- Testing component PropXYXYBV. --------"); 35 36 if(debug) System.out.println( ok_prefix + "Test constructor." ); 37 PropXYXYBV prop = new PropXYXYBV(2.0); 38 if(debug) System.out.println( prop ); 39 40 //******************************************************************** 41 // Check that if planes are not parallel the propagatiopn fails 42 { 43 if(debug) System.out.println( ok_prefix + "Check that only tracks on right surfaces are being propagated " ); 44 45 PropStat pstat = new PropStat(); 46 47 SurfXYPlane sxyp1 = new SurfXYPlane(10.,0.); 48 SurfXYPlane sxyp2 = new SurfXYPlane(12.,0.); 49 SurfXYPlane sxyp1np = new SurfXYPlane(10.,0.1); 50 SurfXYPlane sxyp2np = new SurfXYPlane(12.,0.1); 51 52 TrackVector vec1 = new TrackVector(); 53 54 vec1.set(SurfXYPlane.IV , -2.); // v 55 vec1.set(SurfXYPlane.IZ , 3.); // z 56 vec1.set(SurfXYPlane.IDVDU , 1.5); // dv/du 57 vec1.set(SurfXYPlane.IDZDU , 2.3); // dz/du 58 vec1.set(SurfXYPlane.IQP , 0.05); // q/p 59 60 VTrack trv1 = new VTrack(sxyp1.newPureSurface(),vec1); 61 trv1.setForward(); 62 63 pstat = prop.vecDirProp(trv1,sxyp2,PropDir.FORWARD); 64 Assert.assertTrue( pstat.success() ); 65 66 trv1.setVector(vec1); 67 trv1.setSurface( sxyp1.newPureSurface()); 68 trv1.setForward(); 69 70 pstat = prop.vecDirProp(trv1,sxyp2np,PropDir.FORWARD); 71 Assert.assertTrue( !pstat.success() ); 72 73 trv1.setVector(vec1); 74 trv1.setSurface( sxyp1np.newPureSurface()); 75 trv1.setForward(); 76 77 pstat = prop.vecDirProp(trv1,sxyp2,PropDir.FORWARD); 78 Assert.assertTrue( !pstat.success() ); 79 80 trv1.setVector(vec1); 81 trv1.setSurface( sxyp1np.newPureSurface()); 82 trv1.setForward(); 83 84 pstat = prop.vecDirProp(trv1,sxyp2np,PropDir.FORWARD); 85 Assert.assertTrue( !pstat.success() ); 86 87 88 } 89 90 //******************************************************************** 91 92 // Here we propagate some tracks both forward and backward and then 93 // each back to the original track. We check that the returned 94 // track parameters match those of the original track. 95 if(debug) System.out.println( ok_prefix + "Check reversibility." ); 96 97 double u1[] ={10., 10., 10., 10., 10., 10.}; 98 double u2[] ={12., 12., 12., 12., 12., 12.}; 99 double phi1[]={ 0., 0., 0. , 0., 0., 0.}; 100 double phi2[]={ 0., 0., 0., 0., 0., 0.}; 101 int sign_du[]={ 1, -1, -1, 1, 1, 1 }; 102 double v[] ={ -2., 2., 40., 40., -2., -2. }; 103 double z[] ={ 3., 3., 3., 3., 3., 3. }; 104 double dvdu[]={-1.5, -1.5, 1.5, 1.5, -1.5, 0. }; 105 double dzdu[]={ 2.3, -2.3, -2.3, 2.3, 0., 2.3 }; 106 double qp[] ={ 0.05, -0.05, 0.05, -0.05, 0.05, 0.05 }; 107 108 double maxdiff = 1.e-9; 109 int ntrk = 6; 110 int i; 111 for ( i=0; i<ntrk; ++i ) 112 { 113 if(debug) System.out.println( "********** Propagate track " + i + ". **********" ); 114 PropStat pstat = new PropStat(); 115 SurfXYPlane sxyp1 = new SurfXYPlane(u1[i],phi1[i]); 116 SurfXYPlane sxyp2 = new SurfXYPlane(u2[i],phi2[i]); 117 TrackVector vec1 = new TrackVector(); 118 vec1.set(SurfXYPlane.IV , v[i]); // v 119 vec1.set(SurfXYPlane.IZ , z[i]); // z 120 vec1.set(SurfXYPlane.IDVDU , dvdu[i]); // dv/du 121 vec1.set(SurfXYPlane.IDZDU , dzdu[i]); // dz/du 122 vec1.set(SurfXYPlane.IQP , qp[i]); // q/p 123 VTrack trv1 = new VTrack( sxyp1.newPureSurface(),vec1); 124 if(sign_du[i]==1) trv1.setForward(); 125 else trv1.setBackward(); 126 if(debug) System.out.println( " starting: " + trv1 ); 127 128 VTrack trv2f = new VTrack(trv1); 129 pstat = prop.vecDirProp(trv2f,sxyp2,PropDir.FORWARD); 130 if(debug) System.out.println( pstat ); 131 Assert.assertTrue( pstat.forward() ); 132 if(debug) System.out.println( " forward: " + trv2f ); 133 Assert.assertTrue(check_dv(trv1,trv2f)>=0.); 134 135 VTrack trv2b = new VTrack(trv1); 136 pstat = prop.vecDirProp(trv2b,sxyp2,PropDir.BACKWARD); 137 if(debug) System.out.println( pstat ); 138 Assert.assertTrue( pstat.backward() ); 139 if(debug) System.out.println( " backward: " + trv2b ); 140 Assert.assertTrue(check_dv(trv1,trv2b)<=0.); 141 142 VTrack trv2fb = new VTrack(trv2f); 143 pstat = prop.vecDirProp(trv2fb,sxyp1,PropDir.BACKWARD); 144 if(debug) System.out.println( pstat ); 145 Assert.assertTrue( pstat.backward() ); 146 if(debug) System.out.println( " f return: " + trv2fb ); 147 Assert.assertTrue(check_dv(trv2f,trv2fb)<=0.); 148 149 VTrack trv2bf = new VTrack(trv2b); 150 pstat = prop.vecDirProp(trv2bf,sxyp1,PropDir.FORWARD); 151 if(debug) System.out.println( pstat ); 152 Assert.assertTrue( pstat.forward() ); 153 if(debug) System.out.println( " b return: " + trv2bf ); 154 Assert.assertTrue(check_dv(trv2b,trv2bf)>=0.); 155 156 double difff = 157 sxyp1.vecDiff(trv2fb.vector(),trv1.vector()).amax(); 158 double diffb = 159 sxyp1.vecDiff(trv2bf.vector(),trv1.vector()).amax(); 160 if(debug) System.out.println( "diffs: " + difff + ' ' + diffb ); 161 Assert.assertTrue( difff < maxdiff || diffb < maxdiff ); 162 // Assert.assertTrue( diffb < maxdiff ); 163 164 } 165 166 //******************************************************************** 167 168 // Repeat the above with errors. 169 if(debug) System.out.println( ok_prefix + "Check reversibility with errors." ); 170 double evv[] = { 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 }; 171 double evz[] = { 0.01, -0.01, 0.01, -0.01, 0.01, -0.01 }; 172 double ezz[] = { 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, }; 173 double evdv[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004 }; 174 double ezdv[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004 }; 175 double edvdv[] = { 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 }; 176 double evdz[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004 }; 177 double edvdz[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004 }; 178 double ezdz[] = { 0.04, -0.04, 0.04, -0.04, 0.04, -0.04 }; 179 double edzdz[] = { 0.02, 0.02, 0.02, 0.02, 0.02, 0.02 }; 180 double evqp[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004 }; 181 double ezqp[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004 }; 182 double edvqp[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004 }; 183 double edzqp[] = { 0.004, -0.004, 0.004, -0.004, 0.004, -0.004 }; 184 double eqpqp[] = { 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 }; 185 186 maxdiff = 1.e-6; 187 188 for ( i=0; i<ntrk; ++i ) 189 { 190 if(debug) System.out.println( "********** Propagate track " + i + ". **********" ); 191 PropStat pstat = new PropStat(); 192 SurfXYPlane sxyp1 = new SurfXYPlane(u1[i],phi1[i]); 193 SurfXYPlane sxyp2 = new SurfXYPlane(u2[i],phi2[i]); 194 TrackVector vec1 = new TrackVector(); 195 vec1.set(SurfXYPlane.IV , v[i]); // v 196 vec1.set(SurfXYPlane.IZ , z[i]); // z 197 vec1.set(SurfXYPlane.IDVDU , dvdu[i]); // dv/du 198 vec1.set(SurfXYPlane.IDZDU , dzdu[i]); // dz/du 199 vec1.set(SurfXYPlane.IQP , qp[i]); // q/p 200 201 TrackError err1 = new TrackError(); 202 err1.set(SurfXYPlane.IV,SurfXYPlane.IV , evv[i]); 203 err1.set(SurfXYPlane.IV,SurfXYPlane.IZ , evz[i]); 204 err1.set(SurfXYPlane.IZ,SurfXYPlane.IZ , ezz[i]); 205 err1.set(SurfXYPlane.IV,SurfXYPlane.IDVDU , evdv[i]); 206 err1.set(SurfXYPlane.IZ,SurfXYPlane.IDVDU , ezdv[i]); 207 err1.set(SurfXYPlane.IDVDU,SurfXYPlane.IDVDU , edvdv[i]); 208 err1.set(SurfXYPlane.IV,SurfXYPlane.IDZDU , evdz[i]); 209 err1.set(SurfXYPlane.IZ,SurfXYPlane.IDZDU , ezdz[i]); 210 err1.set(SurfXYPlane.IDVDU,SurfXYPlane.IDZDU , edvdz[i]); 211 err1.set(SurfXYPlane.IDZDU,SurfXYPlane.IDZDU , edzdz[i]); 212 err1.set(SurfXYPlane.IV,SurfXYPlane.IQP , evqp[i]); 213 err1.set(SurfXYPlane.IZ,SurfXYPlane.IQP , ezqp[i]); 214 err1.set(SurfXYPlane.IDVDU,SurfXYPlane.IQP , edvqp[i]); 215 err1.set(SurfXYPlane.IDZDU,SurfXYPlane.IQP , edzqp[i]); 216 err1.set(SurfXYPlane.IQP,SurfXYPlane.IQP , eqpqp[i]); 217 ETrack trv1 = new ETrack( sxyp1.newPureSurface(),vec1,err1); 218 if(sign_du[i]==1) trv1.setForward(); 219 else trv1.setBackward(); 220 if(debug) System.out.println( " starting: " + trv1 ); 221 222 ETrack trv2f = new ETrack(trv1); 223 pstat = prop.errDirProp(trv2f,sxyp2,PropDir.FORWARD); 224 Assert.assertTrue( pstat.forward() ); 225 if(debug) System.out.println( " forward: " + trv2f ); 226 ETrack trv2b = new ETrack(trv1); 227 pstat = prop.errDirProp(trv2b,sxyp2,PropDir.BACKWARD); 228 Assert.assertTrue( pstat.backward() ); 229 if(debug) System.out.println( " backward: " + trv2b ); 230 ETrack trv2fb = new ETrack(trv2f); 231 pstat = prop.errDirProp(trv2fb,sxyp1,PropDir.BACKWARD); 232 Assert.assertTrue( pstat.backward() ); 233 if(debug) System.out.println( " f return: " + trv2fb ); 234 ETrack trv2bf = new ETrack(trv2b); 235 pstat = prop.errDirProp(trv2bf,sxyp1,PropDir.FORWARD); 236 Assert.assertTrue( pstat.forward() ); 237 if(debug) System.out.println( " b return: " + trv2bf ); 238 double difff = 239 sxyp1.vecDiff(trv2fb.vector(),trv1.vector()).amax(); 240 double diffb = 241 sxyp1.vecDiff(trv2bf.vector(),trv1.vector()).amax(); 242 243 244 TrackError dfb = trv2fb.error().minus(trv1.error()); 245 TrackError dbf = trv2bf.error().minus(trv1.error()); 246 double edifff = dfb.amax(); 247 double ediffb = dbf.amax(); 248 249 if(debug) System.out.println( "vec diffs: " + difff + ' ' + diffb ); 250 if(debug) System.out.println( "err diffs: " + edifff + ' ' + ediffb ); 251 252 Assert.assertTrue( (difff < maxdiff && edifff < maxdiff) || 253 (diffb < maxdiff && ediffb < maxdiff) ); 254 255 } 256 257 258 //******************************************************************** 259 260 if(debug) System.out.println( ok_prefix + "Test Nearest Propagation" ); 261 262 PropStat pstat = new PropStat(); 263 SurfXYPlane sxyp1 = new SurfXYPlane(2.,0.); 264 SurfXYPlane sxyp2 = new SurfXYPlane(3.,0.); 265 266 TrackVector vec1 = new TrackVector(); 267 268 vec1.set(SurfXYPlane.IV , 1.); // v 269 vec1.set(SurfXYPlane.IZ , 1.); // z 270 vec1.set(SurfXYPlane.IDVDU , 1.); // dv/du 271 vec1.set(SurfXYPlane.IDZDU , 1.); // dz/du 272 vec1.set(SurfXYPlane.IQP , 0.01); // q/p 273 274 VTrack trv1 = new VTrack( sxyp1.newPureSurface(),vec1); 275 trv1.setForward(); 276 277 if(debug) System.out.println( " starting: " + trv1 ); 278 VTrack trv2n = new VTrack(trv1); 279 pstat = prop.vecDirProp(trv2n,sxyp2,PropDir.NEAREST); 280 Assert.assertTrue( pstat.forward() ); 281 if(debug) System.out.println( " nearest: " + trv2n ); 282 283 trv1.setBackward(); 284 285 if(debug) System.out.println( " starting: " + trv1 ); 286 trv2n = new VTrack(trv1); 287 pstat = prop.vecDirProp(trv2n,sxyp2,PropDir.NEAREST); 288 Assert.assertTrue( pstat.backward() ); 289 if(debug) System.out.println( " nearest: " + trv2n ); 290 291 //******************************************************************** 292 293 if(debug) System.out.println( ok_prefix + "Test cloning." ); 294 Assert.assertTrue( prop.newPropagator() != null); 295 296 //******************************************************************** 297 298 if(debug) System.out.println( ok_prefix + "Test the field." ); 299 Assert.assertTrue( prop.bField() == 2.0 ); 300 301 302 if(debug) System.out.println( ok_prefix 303 + "------------- All tests passed. -------------" ); 304 //******************************************************************** 305 306 } 307 //********************************************************************** 308 //Checker of correct v propagation 309 310 static double check_dv(VTrack trv1, VTrack trv2) 311 { 312 double v1 = trv1.vector().get(SurfXYPlane.IV); 313 double v2 = trv2.vector().get(SurfXYPlane.IV); 314 double dvdu = trv1.vector().get(SurfXYPlane.IDVDU); 315 int sign_du = (trv1.isForward())?1:-1; 316 return (v2-v1)*dvdu*sign_du; 317 } 318 }