1 /* 2 * ThinXYPlaneMsSim_Test.java 3 * 4 * Created on July 24, 2007, 10:13 PM 5 * 6 * $Id: ThinXYPlaneMsSim_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.SimInteractor; 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 17 /** 18 * 19 * @author Norman Graf 20 */ 21 public class ThinXYPlaneMsSim_Test extends TestCase 22 { 23 private boolean debug; 24 /** Creates a new instance of ThinXYPlaneMsSim_Test */ 25 public void testThinXYPlaneMsSim() 26 { 27 String component = "ThinXYPlaneMsSim"; 28 String ok_prefix = component + " (I): "; 29 String error_prefix = component + " test (E): "; 30 31 if(debug) System.out.println( ok_prefix 32 + "---------- Testing component " + component 33 + ". ----------" ); 34 35 // Assign track parameter indices. 36 37 int IV = SurfXYPlane.IV; 38 int IZ = SurfXYPlane.IZ; 39 int IDVDU = SurfXYPlane.IDVDU; 40 int IDZDU = SurfXYPlane.IDZDU; 41 int IQP = SurfXYPlane.IQP; 42 43 //******************************************************************** 44 45 double radLength = 0.001; 46 ThinXYPlaneMsSim scatterIt = new ThinXYPlaneMsSim(radLength); 47 48 Assert.assertTrue(scatterIt.radLength() == radLength); 49 50 SurfXYPlane xyp = new SurfXYPlane(20.,0.); 51 double[] pars = {1., 2., 3., 4., 5. }; 52 TrackVector tv = new TrackVector(pars); 53 VTrack vtrk = new VTrack(xyp, tv); 54 55 // Give the track 1GeV 56 TrackVector trv = vtrk.vector(); 57 trv.set(IQP, 1.0); 58 vtrk.setVector( trv ); 59 scatterIt.interact( vtrk ); 60 TrackVector scattered = new TrackVector( vtrk.vector() ); 61 Assert.assertTrue( scattered.get(IV) == trv.get(IV) ); 62 Assert.assertTrue( scattered.get(IZ) == trv.get(IZ) ); 63 Assert.assertTrue( scattered.get(IDVDU) != trv.get(IDVDU) ); 64 Assert.assertTrue( scattered.get(IDZDU) != trv.get(IDZDU) ); 65 Assert.assertTrue( scattered.get(IQP) != trv.get(IQP) ); 66 if(debug) System.out.println( "before interaction " + trv ); 67 if(debug) System.out.println( "after interaction " + scattered ); 68 69 70 TrackVector tvec = new TrackVector(); 71 tvec.set(IV, 1.0); 72 tvec.set(IZ, 2.0); 73 tvec.set(IDVDU, 3.0); 74 tvec.set(IDZDU, 4.0); 75 tvec.set(IQP, 5.0); 76 SurfXYPlane szp = new SurfXYPlane(6.0,1.); 77 VTrack t = new VTrack(szp.newPureSurface(),tvec); 78 if(debug) System.out.println( "Track before interacting... " + tvec ); 79 scatterIt.interact( t ); 80 TrackVector trv1 = new TrackVector( t.vector() ); 81 if(debug) System.out.println( "Track after interacting... " + trv1 ); 82 83 tvec.set(IV, 7.25001); 84 tvec.set(IZ, 83.571); 85 tvec.set(IDVDU, 0.0220818); 86 tvec.set(IDZDU, 0.586898); 87 tvec.set(IQP, -0.0116488); 88 89 SurfXYPlane szp2 = new SurfXYPlane(35.0,2.15); 90 VTrack t2 = new VTrack(szp2.newPureSurface(),tvec); 91 if(debug) System.out.println( "Track before interacting... " + tvec ); 92 scatterIt.interact( t2 ); 93 TrackVector trv2 = new TrackVector( t2.vector() ); 94 if(debug) System.out.println( "Track after interacting... " + trv2 ); 95 96 97 //******************************************************************** 98 if(debug) System.out.println(ok_prefix + "Testing clone"); 99 VTrack t3 = new VTrack(t2); 100 VTrack t4 = new VTrack(t2); 101 t3.setForward(); 102 t4.setForward(); 103 Assert.assertTrue(t3.equals(t4)); 104 // clone 105 SimInteractor scatterIt2 = scatterIt.newCopy(); 106 // assert they are not the same object 107 Assert.assertTrue( scatterIt2!=scatterIt ); 108 // scatter both tracks 109 scatterIt2.interact(t4); 110 scatterIt.interact(t3); 111 // assert that the newly scattered tracks are not equal 112 // since scattering is stochastic and we have different random 113 // number generators 114 Assert.assertTrue( t3.notEquals(t4) ); 115 // assert they're different from the original track 116 Assert.assertTrue( t3.notEquals(t2) ); 117 Assert.assertTrue( t4.notEquals(t2) ); 118 119 //******************************************************************** 120 121 if(debug) System.out.println( ok_prefix 122 + "------------- All tests passed. -------------" ); 123 124 //******************************************************************** 125 126 } 127 128 }