1 /* 2 * Hit_Test.java 3 * 4 * Created on July 24, 2007, 12:17 PM 5 * 6 * $Id: Hit_Test.java,v 1.1.1.1 2010/04/08 20:38:00 jeremy Exp $ 7 */ 8 9 package org.lcsim.recon.tracking.trfbase; 10 11 import java.util.Iterator; 12 import java.util.List; 13 import junit.framework.TestCase; 14 import org.lcsim.recon.tracking.trfutil.Assert; 15 16 /** 17 * 18 * @author Norman Graf 19 */ 20 public class Hit_Test extends TestCase 21 { 22 private boolean debug; 23 /** Creates a new instance of Hit_Test */ 24 public void testHit() 25 { 26 String component = "Hit"; 27 String ok_prefix = component + " (I): "; 28 String error_prefix = component + " test (E): "; 29 30 if(debug) System.out.println("-------- Testing component " + component 31 + ". --------" ); 32 33 //******************************************************************** 34 35 if(debug) System.out.println("Test constructors." ); 36 37 SurfTest stest = new SurfTest(1); 38 Cluster ct1 = new ClusterTest(stest,3); 39 40 if(debug) System.out.println( ct1 ); 41 42 //******************************************************************** 43 44 if(debug) System.out.println("Test surface." ); 45 if(debug) System.out.println( stest ); 46 Surface srfchk = ct1.surface(); 47 if(debug) System.out.println( srfchk ); 48 Assert.assertTrue( stest.pureEqual(srfchk) ); 49 50 //******************************************************************** 51 52 if(debug) System.out.println("Fetch hits." ); 53 ETrack tre = new ETrack( stest.newPureSurface() ); 54 //List hits = new ArrayList(); 55 List hits = ct1.predict(tre,ct1); 56 Iterator it = hits.iterator(); 57 if(debug) 58 { 59 while(it.hasNext()) System.out.println( it.next() ); 60 } 61 Assert.assertTrue( hits.size() == 3 ); 62 63 //******************************************************************** 64 65 if(debug) System.out.println("Check hit size." ); 66 Hit hit0 = (Hit)hits.get(0); 67 if(debug) System.out.println( "size = " + hit0.size() ); 68 Assert.assertTrue( hit0.size() == 2 ); 69 70 //******************************************************************** 71 72 if(debug) System.out.println("Check hit." ); 73 Cluster pclus = hit0.cluster(); 74 if(debug) System.out.println( ct1 ); 75 if(debug) System.out.println( pclus ); 76 Assert.assertTrue( ct1==pclus ); 77 78 //******************************************************************** 79 80 if(debug) System.out.println("Check hit surface." ); 81 if(debug) System.out.println( ct1.surface() ); 82 if(debug) System.out.println( hit0.surface() ); 83 Assert.assertTrue( hit0.surface().equals(ct1.surface()) ); 84 85 //******************************************************************** 86 87 if(debug) System.out.println("Check hit data." ); 88 if(debug) System.out.println( hit0.measuredVector() ); 89 Assert.assertTrue( hit0.measuredVector().get(1) == 2.0 ); 90 if(debug) System.out.println( hit0.measuredError() ); 91 Assert.assertTrue( hit0.measuredError().get(1,1) == 4.0 ); 92 if(debug) System.out.println( hit0.predictedVector() ); 93 Assert.assertTrue( hit0.predictedVector().get(1) == 4.0 ); 94 if(debug) System.out.println( hit0.predictedError() ); 95 Assert.assertTrue( hit0.predictedError().get(1,1) == 6.0 ); 96 if(debug) System.out.println( hit0.dHitdTrack() ); 97 Assert.assertTrue( hit0.dHitdTrack().get(1,4) == 14.0 ); 98 if(debug) System.out.println( hit0.differenceVector() ); 99 Assert.assertTrue( hit0.differenceVector().amax() == 2.0 ); 100 101 //******************************************************************** 102 103 if(debug) System.out.println("Test types." ); 104 if(debug) System.out.println( ct1.type() ); 105 Assert.assertTrue( ct1.type() != null ); 106 Cluster ct2 = new ClusterTest(stest,2); 107 if(debug) System.out.println( ct2.type() ); 108 Assert.assertTrue( ct1.type().equals(ct2.type()) ); 109 if(debug) System.out.println( hit0.type() ); 110 Assert.assertTrue( hit0.type() != null ); 111 Assert.assertTrue( !hit0.type().equals(ct1.type()) ); 112 /* ihit = hits.begin(); 113 Hit* phit = (*++ihit).pointer(); 114 if(debug) System.out.println( phit->type() ); 115 Assert.assertTrue( hit0.get_type() == phit->type() ); 116 */ 117 //******************************************************************** 118 119 if(debug) System.out.println("Test equalities." ); 120 // cluster 121 Assert.assertTrue( ct1.equals(ct1) ); 122 Assert.assertTrue( ! ( ct1.notEquals(ct1) ) ); 123 Assert.assertTrue( ! ( ct1.equals(ct2) ) ); 124 Assert.assertTrue( ct1.notEquals(ct2) ); 125 // hit 126 List hits2 = ct2.predict(tre,ct2); 127 Assert.assertTrue( hits2.size() == 2 ); 128 Hit hit2 = (Hit) hits2.get(0); 129 Assert.assertTrue( hit0.equals(hit0) ); 130 Assert.assertTrue( ! ( hit0.notEquals(hit0) ) ); 131 Assert.assertTrue( hit0.notEquals(hit2) ); 132 Assert.assertTrue( ! ( hit0.equals(hit2) ) ); 133 134 //******************************************************************** 135 136 { 137 List oids = ct1.mcIds(); 138 Assert.assertTrue( oids.size() == 0 ); 139 } 140 { 141 List oids = hit0.mcIds(); 142 Assert.assertTrue( oids.size() == 0 ); 143 } 144 145 //******************************************************************** 146 147 if(debug) System.out.println( ok_prefix 148 + "------------- All tests passed. -------------" ); 149 150 //******************************************************************** 151 } 152 153 }