1 /* 2 * LayerCylinder_Test.java 3 * 4 * Created on July 24, 2007, 8:35 PM 5 * 6 * $Id: LayerCylinder_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.Miss; 14 import org.lcsim.recon.tracking.trfbase.MissTest; 15 import org.lcsim.recon.tracking.trfbase.Surface; 16 import org.lcsim.recon.tracking.trfbase.TrackError; 17 import org.lcsim.recon.tracking.trfbase.TrackVector; 18 import org.lcsim.recon.tracking.trflayer.ClusterFindAll; 19 import org.lcsim.recon.tracking.trflayer.ClusterFindManager; 20 import org.lcsim.recon.tracking.trfutil.Assert; 21 22 /** 23 * 24 * @author Norman Graf 25 */ 26 public class LayerCylinder_Test extends TestCase 27 { 28 private boolean debug; 29 /** Creates a new instance of LayerCylinder_Test */ 30 public void testLayerCylinder() 31 { 32 String component = "LayerCylinder"; 33 String ok_prefix = component + " (I): "; 34 String error_prefix = component + " test (E): "; 35 36 if(debug) System.out.println( ok_prefix 37 + "---------- Testing component " + component 38 + ". ----------" ); 39 40 //******************************************************************** 41 42 if(debug) System.out.println( ok_prefix + "Test constructor." ); 43 Surface srf1 = new SurfCylinder(20.0); 44 ClusterFindManager find1 = new ClusterFindAll( srf1) ; 45 double par1 = 123.; 46 double like1 = 0.246; 47 Miss miss1 = new MissTest(par1,like1); 48 49 Assert.assertTrue( miss1.likelihood() == like1 ); 50 Surface srf2 = new BSurfCylinder(40.0,-50.,50.) ; 51 ClusterFindManager find2 = new ClusterFindAll( srf2) ; 52 LayerCylinder lcy1 = new LayerCylinder( 20.0, -50.0, 50.0, find1, miss1 ); 53 LayerCylinder lcy2= new LayerCylinder( 40.0, -70.0, 70.0, find2 ); 54 if(debug) System.out.println( lcy1 ); 55 56 //******************************************************************** 57 58 if(debug) System.out.println( ok_prefix + "Test type." ); 59 if(debug) System.out.println( lcy1.type() ); 60 if(debug) System.out.println( lcy2.type() ); 61 Assert.assertTrue( lcy1.type() != null); 62 Assert.assertTrue( lcy1.type().equals(LayerCylinder.staticType()) ); 63 Assert.assertTrue( lcy1.type().equals(lcy2.type()) ); 64 65 //******************************************************************** 66 67 if(debug) System.out.println( ok_prefix + "Define a surface and track." ); 68 Surface srf0 = new SurfCylinder(20.0) ; 69 Surface srf4 = new SurfCylinder(5.0) ; 70 TrackVector vec = new TrackVector(); 71 vec.set(0, 1.0); // phi 72 vec.set(1, 5.0); // z 73 vec.set(2, 0.1); // alpha 74 vec.set(3, -0.2); // lambda 75 vec.set(4, 0.002); // q/p 76 TrackError err = new TrackError(); 77 err.set(0,0, 0.01); 78 err.set(1,1, 0.02); 79 err.set(2,2, 0.03); 80 err.set(3,3, 0.04); 81 err.set(4,4, 0.05); 82 ETrack tre0 = new ETrack(srf0,vec,err); 83 ETrack tre = new ETrack(srf4,vec,err); 84 if(debug) System.out.println( tre ); 85 86 //******************************************************************** 87 88 if(debug) System.out.println( ok_prefix + "Test surface." ); 89 Surface srf = (Surface)lcy1.clusterSurfaces().get(0); 90 { 91 Surface srf3 = lcy1.surface(); 92 if(debug) System.out.println( srf3 ); 93 Assert.assertTrue( lcy1.clusterSurfaces().size() == 1 ); 94 Assert.assertTrue( srf3.equals(srf) ); 95 } 96 97 //******************************************************************** 98 99 if(debug) System.out.println( ok_prefix + "Check cluster access" ); 100 Assert.assertTrue( lcy1.hasClusters() ); 101 lcy1.addCluster(new ClusCylPhi(20,1.0,0.1) ); 102 lcy1.addCluster(new ClusCylPhi(20,2.0,0.1) ); 103 lcy1.addCluster(new ClusCylPhi(20,3.0,0.1) ); 104 LayerCylinder lcy1c = new LayerCylinder(lcy1); 105 if(debug) System.out.println( lcy1c.clusters().size() ); 106 Assert.assertTrue( lcy1c.clusters().size() == 3 ); 107 Assert.assertTrue( lcy1c.clusters(srf).size() == 3 ); 108 109 //******************************************************************** 110 /* 111 if(debug) System.out.println( ok_prefix + "Propagate from inside." ); 112 PropCyl prop = new PropCyl(2.0); 113 List ltracks = lcy1.propagate(tre,prop); 114 Assert.assertTrue( ltracks.size() == 1 ); 115 // save a copy of the propagated track 116 LTrack trl1 = (LTrack) ltracks.get(0); 117 ETrack tre1 = trl1.get_track(); 118 LayerStat lstat1 = trl1.get_status(); 119 if(debug) System.out.println( trl1 ); 120 Assert.assertTrue( lstat1.at_exit() ); 121 Assert.assertTrue( lstat1.get_state() == 1 ); 122 ltracks = lcy1.propagate(trl1,prop); 123 Assert.assertTrue( ltracks.size() == 0 ); 124 125 //******************************************************************** 126 127 if(debug) System.out.println( ok_prefix + "Check returned miss." ); 128 Assert.assertTrue( lstat1.get_miss() != 0 ); 129 miss.update(tre1); 130 Assert.assertTrue( lstat1.get_miss().get_likelihood() == 131 miss1.get_likelihood() ); 132 133 //******************************************************************** 134 135 if(debug) System.out.println( ok_prefix + "Check returned clusters." ); 136 Assert.assertTrue( lstat1.has_clusters() ); 137 Assert.assertTrue( lstat1.get_clusters().size() == 3 ); 138 Assert.assertTrue( lstat1.get_clusters(tre).size() == 3 ); 139 140 //******************************************************************** 141 142 if(debug) System.out.println( ok_prefix + "Propagate from outside." ); 143 SurfacePtr psrf2( new SurfCylinder(50.0) ); 144 tre.set_surface(psrf2); 145 if(debug) System.out.println( tre ); 146 ltracks = lcy1.propagate(tre,prop); 147 Assert.assertTrue( ltracks.size() == 1 ); 148 // save a copy of the propagated track 149 const LTrack trl2 = ltracks.front(); 150 const ETrack& tre2 = trl2.get_track(); 151 const LayerStat& lstat2 = trl2.get_status(); 152 if(debug) System.out.println( trl2 ); 153 Assert.assertTrue( lstat2.at_exit() ); 154 Assert.assertTrue( lstat2.get_state() == 1 ); 155 ltracks = lcy1.propagate(trl2,prop); 156 Assert.assertTrue( ltracks.size() == 0 ); 157 158 //******************************************************************** 159 160 if(debug) System.out.println( ok_prefix + "Propagate backward from outside." ); 161 TrackVector vec2 = vec; 162 vec2(2, -3.1; 163 ETrack tre30(psrf2,vec2,err); 164 if(debug) System.out.println( tre30 ); 165 ltracks = lcy1.propagate(tre30,prop); 166 Assert.assertTrue( ltracks.size() == 1 ); 167 // save a copy of the propagated track 168 const LTrack trl3 = ltracks.front(); 169 const ETrack& tre3 = trl3.get_track(); 170 const LayerStat& lstat3 = trl3.get_status(); 171 if(debug) System.out.println( trl3 ); 172 Assert.assertTrue( lstat3.at_exit() ); 173 Assert.assertTrue( lstat3.get_state() == 1 ); 174 ltracks = lcy1.propagate(trl3,prop); 175 Assert.assertTrue( ltracks.size() == 0 ); 176 177 //******************************************************************** 178 179 if(debug) System.out.println( ok_prefix + "Propagate from layer surface." ); 180 SurfacePtr psrf3( new SurfCylinder(20.0) ); 181 tre.set_surface(psrf3); 182 if(debug) System.out.println( tre ); 183 ltracks = lcy1.propagate(tre,prop); 184 Assert.assertTrue( ltracks.size() == 1 ); 185 // save a copy of the propagated track 186 const LTrack trl4 = ltracks.front(); 187 const ETrack& tre4 = trl4.get_track(); 188 const LayerStat& lstat4 = trl4.get_status(); 189 if(debug) System.out.println( trl4 ); 190 Assert.assertTrue( lstat4.at_exit() ); 191 Assert.assertTrue( lstat4.get_state() == 1 ); 192 193 //******************************************************************** 194 195 if(debug) System.out.println( ok_prefix + "Propagate out of bounds." ); 196 tre.set_surface(psrf1); 197 vec.set(1, 300.0; 198 tre.set_vector(vec); 199 if(debug) System.out.println( tre ); 200 ltracks = lcy1.propagate(tre,prop); 201 Assert.assertTrue( ltracks.size() == 1 ); 202 // save a copy of the propagated track 203 const LTrack trl5 = ltracks.front(); 204 const ETrack& tre5 = trl5.get_track(); 205 const LayerStat& lstat5 = trl5.get_status(); 206 if(debug) System.out.println( trl5 ); 207 Assert.assertTrue( lstat5.at_exit() ); 208 Assert.assertTrue( lstat5.get_state() == 1 ); 209 210 //******************************************************************** 211 212 if(debug) System.out.println( ok_prefix + "Drop clusters." ); 213 if(debug) System.out.println( "Before drop: " + lcy1.get_clusters().size() ); 214 Assert.assert ( lcy1.get_clusters().size() == 3 ); 215 lcy1.drop_clusters(); 216 if(debug) System.out.println( "After drop: " + lcy1.get_clusters().size() ); 217 Assert.assert ( lcy1.get_clusters().size() == 0 ); 218 219 //******************************************************************** 220 */ 221 //******************************************************************** 222 /* 223 if(debug) System.out.println( ok_prefix 224 + "------------- All tests passed. -------------" ); 225 */ 226 //******************************************************************** 227 228 } 229 230 }