1 /* 2 * HitCylPhiZ_Test.java 3 * 4 * Created on July 24, 2007, 8:38 PM 5 * 6 * $Id: HitCylPhiZ_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 java.util.ArrayList; 12 import java.util.List; 13 import junit.framework.TestCase; 14 import org.lcsim.recon.tracking.trfbase.ETrack; 15 import org.lcsim.recon.tracking.trfbase.Hit; 16 import org.lcsim.recon.tracking.trfbase.HitDerivative; 17 import org.lcsim.recon.tracking.trfbase.TrackError; 18 import org.lcsim.recon.tracking.trfbase.TrackVector; 19 import org.lcsim.recon.tracking.trfutil.Assert; 20 import org.lcsim.recon.tracking.trfutil.TRFMath; 21 22 /** 23 * 24 * @author Norman Graf 25 */ 26 public class HitCylPhiZ_Test extends TestCase 27 { 28 private boolean debug; 29 /** Creates a new instance of HitCylPhiZ_Test */ 30 public void testHitCylPhiZ() 31 { 32 String component = "HitCylPhiZ"; 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 if(debug) System.out.println( ok_prefix + "Test cluster constructors." ); 41 double r1 = 10.0; 42 double phiz1 = 1.0; 43 double dphiz1 = 0.01; 44 SurfCylinder scy1 = new SurfCylinder(r1); 45 ClusCylPhiZ hcp1 = new ClusCylPhiZ(r1,phiz1,dphiz1,stereo); 46 if(debug) System.out.println( hcp1 ); 47 double r2 = 20.0; 48 double phiz2 = 2.0; 49 double dphiz2 = 0.02; 50 ClusCylPhiZ hcp2 = new ClusCylPhiZ(r2,phiz2,dphiz2,stereo); 51 52 //******************************************************************** 53 54 if(debug) System.out.println( ok_prefix + "Test cluster type ID." ); 55 if(debug) System.out.println( hcp1.type() ); 56 if(debug) System.out.println( hcp2.type() ); 57 Assert.assertTrue( hcp1.type() != null ); 58 Assert.assertTrue( hcp1.type().equals(hcp2.type() )); 59 60 //******************************************************************** 61 62 if(debug) System.out.println( ok_prefix + "Test cluster accessors." ); 63 if(debug) System.out.println( hcp1 ); 64 if(debug) System.out.println( hcp1.surface() ); 65 if(debug) System.out.println( hcp1.phiZ() ); 66 if(debug) System.out.println( hcp1.dPhiZ() ); 67 if(debug) System.out.println( hcp1.stereo() ); 68 Assert.assertTrue( hcp1.surface().equals(scy1) ); 69 Assert.assertTrue( hcp1.phiZ() == phiz1 ); 70 Assert.assertTrue( hcp1.dPhiZ() == dphiz1 ); 71 Assert.assertTrue( hcp1.stereo() == stereo ); 72 73 //******************************************************************** 74 75 if(debug) System.out.println( ok_prefix + "Generate a hit." ); 76 TrackVector vec = new TrackVector(); 77 TrackError err = new TrackError(); 78 HitDerivative der_expect = new HitDerivative(1); 79 der_expect.set(0,0, 1.0); 80 der_expect.set(0,1, stereo); 81 vec.set(0, 1.1); 82 vec.set(1, 40.0); 83 err.set(0,0, 0.04); 84 ETrack tre1 = new ETrack( scy1.newPureSurface(), vec, err ); 85 // Cluster clu1 = new ClusterCylPhiZ(hcp1); 86 List tclus11 = hcp1.predict(tre1,hcp1); 87 Assert.assertTrue( tclus11.size() == 1 ); 88 Hit pre11 = (Hit) tclus11.get(0); 89 double maxdiff = 1.e-12; 90 if(debug) System.out.println( pre11.size() ); 91 Assert.assertTrue( pre11.size() == 1); 92 if(debug) System.out.println( pre11.measuredVector() ); 93 Assert.assertTrue( TRFMath.isEqual(pre11.measuredVector().get(0),phiz1) ); 94 if(debug) System.out.println( pre11.measuredError() ); 95 Assert.assertTrue( TRFMath.isEqual( pre11.measuredError().get(0,0), dphiz1*dphiz1 ) ); 96 if(debug) System.out.println( pre11.predictedVector() ); 97 Assert.assertTrue( TRFMath.isEqual( pre11.predictedVector().get(0), calc_phiz(vec) ) ); 98 if(debug) System.out.println( pre11.predictedError() ); 99 Assert.assertTrue( TRFMath.isEqual( pre11.predictedError().get(0,0), calc_ephiz(err) ) ); 100 if(debug) System.out.println( pre11.dHitdTrack() ); 101 Assert.assertTrue( pre11.dHitdTrack().equals(der_expect ) ); 102 if(debug) System.out.println( pre11.differenceVector() ); 103 Assert.assertTrue( Math.abs(pre11.differenceVector().get(0) - 104 calc_phiz(vec) + phiz1) < maxdiff ); 105 106 //******************************************************************** 107 108 if(debug) System.out.println( ok_prefix + "Generate hit for a different track." 109 ); 110 vec.set(0, 1.2); 111 ETrack tre2 = new ETrack( scy1.newPureSurface(), vec, err ); 112 List tclus12 = hcp1.predict(tre2,hcp1); 113 Assert.assertTrue( tclus12.size() == 1 ); 114 Hit pre12 = (Hit) tclus12.get(0); 115 if(debug) System.out.println( pre12.size() ); 116 Assert.assertTrue( pre12.size() == 1); 117 if(debug) System.out.println( pre12.measuredVector() ); 118 Assert.assertTrue( TRFMath.isEqual( pre12.measuredVector().get(0), phiz1 ) ); 119 if(debug) System.out.println( pre12.measuredError() ); 120 Assert.assertTrue( TRFMath.isEqual( pre12.measuredError().get(0,0), dphiz1*dphiz1 ) ); 121 if(debug) System.out.println( pre12.predictedVector() ); 122 Assert.assertTrue( TRFMath.isEqual( pre12.predictedVector().get(0), calc_phiz(vec) ) ); 123 if(debug) System.out.println( pre12.predictedError() ); 124 Assert.assertTrue( TRFMath.isEqual( pre12.predictedError().get(0,0), calc_ephiz(err) ) ); 125 if(debug) System.out.println( pre12.dHitdTrack() ); 126 Assert.assertTrue( pre12.dHitdTrack().equals(der_expect ) ); 127 if(debug) System.out.println( pre12.differenceVector() ); 128 Assert.assertTrue( Math.abs(pre12.differenceVector().get(0) - 129 calc_phiz(vec) + phiz1) < maxdiff ); 130 131 // same cluster ==> same hit (even though track changes) 132 Assert.assertTrue( pre11.equals(pre11) ); 133 Assert.assertTrue( ! ( pre11.notEquals(pre11) ) ); 134 Assert.assertTrue( pre11.equals(pre12) ); 135 136 //******************************************************************** 137 138 if(debug) System.out.println( ok_prefix + "Generate hit for a different cluster." 139 ); 140 List tclus22 = hcp2.predict(tre2,hcp2); 141 Assert.assertTrue( tclus22.size() == 1 ); 142 Hit pre22 = (Hit) tclus22.get(0); 143 if(debug) System.out.println( pre22.size() ); 144 Assert.assertTrue( pre22.size() == 1 ); 145 if(debug) System.out.println( pre22.measuredVector() ); 146 Assert.assertTrue( TRFMath.isEqual( pre22.measuredVector().get(0), phiz2 ) ); 147 if(debug) System.out.println( pre22.measuredError() ); 148 Assert.assertTrue( TRFMath.isEqual( pre22.measuredError().get(0,0), dphiz2*dphiz2 ) ); 149 if(debug) System.out.println( pre22.predictedVector() ); 150 Assert.assertTrue( TRFMath.isEqual( pre22.predictedVector().get(0), calc_phiz(vec) ) ); 151 if(debug) System.out.println( pre22.predictedError() ); 152 Assert.assertTrue( TRFMath.isEqual( pre22.predictedError().get(0,0), calc_ephiz(err) ) ); 153 if(debug) System.out.println( pre22.dHitdTrack() ); 154 Assert.assertTrue( pre22.dHitdTrack().equals(der_expect ) ); 155 if(debug) System.out.println( pre22.differenceVector() ); 156 Assert.assertTrue( Math.abs(pre22.differenceVector().get(0) - 157 calc_phiz(vec) + phiz2) < maxdiff ); 158 159 // different cluster ==> different hit 160 Assert.assertTrue( pre22.notEquals(pre11) ); 161 Assert.assertTrue( ! ( pre22.equals(pre11) ) ); 162 Assert.assertTrue( pre22.notEquals(pre12) ); 163 164 //******************************************************************** 165 166 if(debug) System.out.println( ok_prefix + "Update hit." ); 167 if(debug) System.out.println( pre11 ); 168 pre11.update(tre2); 169 if(debug) System.out.println( pre11 ); 170 Assert.assertTrue( pre11.size() == 1); 171 if(debug) System.out.println( pre11.measuredVector() ); 172 Assert.assertTrue( TRFMath.isEqual( pre11.measuredVector().get(0), phiz1 ) ); 173 if(debug) System.out.println( pre11.measuredError() ); 174 Assert.assertTrue( TRFMath.isEqual( pre11.measuredError().get(0,0), dphiz1*dphiz1 ) ); 175 if(debug) System.out.println( pre11.predictedVector() ); 176 Assert.assertTrue( TRFMath.isEqual( pre11.predictedVector().get(0), calc_phiz(vec) ) ); 177 if(debug) System.out.println( pre11.predictedError() ); 178 Assert.assertTrue( TRFMath.isEqual( pre11.predictedError().get(0,0), calc_ephiz(err) ) ); 179 if(debug) System.out.println( pre11.dHitdTrack() ); 180 Assert.assertTrue( pre11.dHitdTrack().equals(der_expect) ); 181 if(debug) System.out.println( pre11.differenceVector() ); 182 Assert.assertTrue( Math.abs(pre11.differenceVector().get(0) - 183 calc_phiz(vec) + phiz1) < maxdiff ); 184 185 //******************************************************************** 186 187 if(debug) System.out.println( ok_prefix + "Check hit type and equality." ); 188 if(debug) System.out.println( HitCylPhiZ.staticType() ); 189 if(debug) System.out.println( pre11.type() ); 190 if(debug) System.out.println( pre12.type() ); 191 Assert.assertTrue( pre11.type() != null ); 192 Assert.assertTrue( pre11.type().equals(HitCylPhiZ.staticType()) ); 193 Assert.assertTrue( pre11.type().equals(pre12.type()) ); 194 195 //******************************************************************** 196 197 if(debug) System.out.println( ok_prefix + "Check MC ID's." ); 198 Assert.assertTrue( hcp1.mcIds().size() == 0 ); 199 List ids = new ArrayList(); 200 ids.add( new Integer(1)); 201 ids.add( new Integer(22)); 202 ids.add( new Integer(333)); 203 ClusCylPhiZ hcp3 = new ClusCylPhiZ(r2,phiz2,dphiz2,stereo,ids); 204 205 { 206 int[] oids = hcp3.mcIdArray(); 207 Assert.assertTrue( oids.length == 3 ); 208 Assert.assertTrue( oids[0] == 1 ); 209 Assert.assertTrue( oids[1] == 22 ); 210 Assert.assertTrue( oids[2] == 333 ); 211 } 212 213 { 214 List thits31 = hcp3.predict(tre1,hcp3); 215 Assert.assertTrue( thits31.size() == 1 ); 216 Hit hit = (Hit)thits31.get(0); 217 List oids = hit.mcIds(); 218 219 Assert.assertTrue( ((Integer) oids.get(0)).intValue() == 1 ); 220 Assert.assertTrue( ((Integer) oids.get(1)).intValue() == 22 ); 221 Assert.assertTrue( ((Integer) oids.get(2)).intValue() == 333 ); 222 } 223 { 224 List oids = hcp3.mcIds(); 225 Assert.assertTrue( oids.size() == 3 ); 226 Assert.assertTrue( ((Integer) oids.get(0)).intValue() == 1 ); 227 Assert.assertTrue( ((Integer) oids.get(1)).intValue() == 22 ); 228 Assert.assertTrue( ((Integer) oids.get(2)).intValue() == 333 ); 229 } 230 231 int mcid = 137; 232 ClusCylPhiZ clus1 = new ClusCylPhiZ(r2,phiz2,dphiz2,stereo,mcid); 233 Assert.assertTrue( clus1.mcIds().size() == 1 ); 234 Assert.assertTrue( clus1.mcIdArray()[0] == mcid ); 235 236 237 //******************************************************************** 238 239 if(debug) System.out.println( ok_prefix 240 + "------------- All tests passed. -------------" ); 241 242 //******************************************************************** 243 } 244 static double stereo = 0.001; 245 246 // calculate phiz from a track vector 247 static double calc_phiz(TrackVector vec) 248 { 249 return vec.get(0) + stereo*vec.get(1); 250 } 251 252 // calculate ephiz from error matrix 253 static double calc_ephiz(TrackError err) 254 { 255 return err.get(0,0) + 2.0*stereo*err.get(0,1) + stereo*stereo*err.get(1,1); 256 } 257 }