1 /* 2 * HTrack_Test.java 3 * 4 * Created on July 24, 2007, 4:46 PM 5 * 6 * $Id: HTrack_Test.java,v 1.1.1.1 2010/04/08 20:38:00 jeremy Exp $ 7 */ 8 9 package org.lcsim.recon.tracking.trffit; 10 11 import java.util.List; 12 import java.util.ListIterator; 13 import junit.framework.TestCase; 14 import org.lcsim.recon.tracking.trfbase.Cluster; 15 import org.lcsim.recon.tracking.trfbase.ClusterTest; 16 import org.lcsim.recon.tracking.trfbase.ETrack; 17 import org.lcsim.recon.tracking.trfbase.Hit; 18 import org.lcsim.recon.tracking.trfbase.SurfTest; 19 import org.lcsim.recon.tracking.trfbase.TrackError; 20 import org.lcsim.recon.tracking.trfbase.TrackVector; 21 import org.lcsim.recon.tracking.trfutil.Assert; 22 23 /** 24 * 25 * @author Norman Graf 26 */ 27 public class HTrack_Test extends TestCase 28 { 29 private boolean debug; 30 /** Creates a new instance of HTrack_Test */ 31 public void testHTrack() 32 { 33 String component = "HTrack"; 34 String ok_prefix = component + " (I): "; 35 String error_prefix = component + " test (E): "; 36 37 if(debug) System.out.println(ok_prefix + "-------- Testing component " + component 38 + ". --------" ); 39 40 41 //******************************************************************** 42 43 if(debug) System.out.println(ok_prefix + "Test constructors" ); 44 ETrack tre = new ETrack( new SurfTest(5) ); 45 if(debug) System.out.println(tre); 46 HTrack trh1 = new HTrack(tre); 47 if(debug) System.out.println(trh1 ); 48 49 //******************************************************************** 50 51 if(debug) System.out.println(ok_prefix + "Test status" ); 52 // Track with good fit and no hits is fit. 53 Assert.assertTrue( trh1.isFit() ); 54 Assert.assertTrue( trh1.hits().size() == 0 ); 55 trh1.unsetFit(); 56 Assert.assertTrue( ! trh1.isFit() ); 57 Assert.assertTrue( ! trh1.isFit() ); 58 trh1.setFit(tre,0.0); 59 Assert.assertTrue( trh1.isFit() ); 60 Assert.assertTrue( trh1.isFit() ); 61 trh1.unsetFit(); 62 Assert.assertTrue( ! trh1.isFit() ); 63 64 //******************************************************************** 65 66 if(debug) System.out.println(ok_prefix + "Add hits." ); 67 SurfTest srf1 = new SurfTest(10); 68 Cluster pclu = new ClusterTest(srf1,10); 69 ETrack tre1 = new ETrack( srf1.newPureSurface() ); 70 List hits = pclu.predict(tre1,pclu); 71 Assert.assertTrue( hits.size() == 10 ); 72 73 74 // ihit iterates over input hits 75 76 ListIterator ihit = hits.listIterator(); 77 trh1.setFit(tre,0.0); 78 //0 79 trh1.addHit( (Hit)ihit.next() ); 80 Assert.assertTrue( ! trh1.isFit() ); 81 //1 82 trh1.addHit( (Hit)ihit.next() ); 83 trh1.setFit(tre,0.0); 84 Assert.assertTrue( trh1.isFit() ); 85 Assert.assertTrue( trh1.isFit() ); 86 trh1.unsetFit(); 87 Assert.assertTrue( ! trh1.isFit() ); 88 Assert.assertTrue( ! trh1.isFit() ); 89 // 2 90 trh1.addHit( (Hit)ihit.next() ); 91 if(debug) System.out.println(trh1 ); 92 // jhit iterates over output hits 93 Assert.assertTrue( trh1.hits().size() == 3 ); 94 95 ihit = hits.listIterator(0); 96 ListIterator jhit = trh1.hits().listIterator(); 97 Assert.assertTrue( ((Hit)ihit.next()).equals( (Hit)jhit.next()) ); 98 // 1 99 Assert.assertTrue(((Hit)ihit.next()).equals( (Hit)jhit.next())); 100 // 2 101 Assert.assertTrue(((Hit)ihit.next()).equals( (Hit)jhit.next())); 102 Assert.assertTrue( trh1.hits().size() == 3 ); 103 104 //******************************************************************** 105 106 if(debug) System.out.println(ok_prefix + "Drop a hit" ); 107 trh1.setFit(tre,0.0); 108 ihit = hits.listIterator(0); 109 trh1.dropHit(); 110 Assert.assertTrue( trh1.hits().size() == 2 ); 111 Assert.assertTrue( ! trh1.isFit() ); 112 jhit = trh1.hits().listIterator(); 113 Assert.assertTrue( ((Hit)ihit.next()).equals( (Hit)jhit.next()) ); 114 // 1 115 Assert.assertTrue( ((Hit)ihit.next()).equals( (Hit)jhit.next()) ); 116 117 //******************************************************************** 118 119 if(debug) System.out.println(ok_prefix + "Set track and chi-square." ); 120 TrackVector vec = new TrackVector(); 121 int i,j; 122 for ( i=0; i<5; ++i ) vec.set(i,1.1*i); 123 TrackError err = new TrackError(); 124 for ( i=0; i<5; ++i ) 125 { 126 for ( j=0; j<=i; ++j ) 127 { 128 double fac; 129 if ( i == j ) fac = 0.1; 130 else fac = 0.01; 131 err.set(i,j, ( i + 0.1*j ) * fac); 132 } 133 } 134 135 ETrack tre2 = new ETrack( srf1.newPureSurface(), vec, err ); 136 double chisq = 12.345; 137 trh1.setFit(tre2,chisq); 138 if(debug) System.out.println(trh1 ); 139 Assert.assertTrue( trh1.isFit() ); 140 Assert.assertTrue( trh1.newTrack().equals(tre2) ); 141 Assert.assertTrue( trh1.isFit() ); 142 Assert.assertTrue( trh1.chisquared() == chisq ); 143 Assert.assertTrue( trh1.isFit() ); 144 145 //******************************************************************** 146 147 if(debug) System.out.println(ok_prefix + "Test copy constructor." ); 148 HTrack trh2 = new HTrack(trh1); 149 if(debug) System.out.println(trh2 ); 150 Assert.assertTrue( trh2.isFit() ); 151 Assert.assertTrue( trh2.newTrack().equals(trh1.newTrack()) ); 152 Assert.assertTrue( trh2.chisquared() == trh1.chisquared() ); 153 Assert.assertTrue( trh2.hits().equals(trh1.hits()) ); 154 155 //******************************************************************** 156 157 if(debug) System.out.println(ok_prefix + "Check equality." ); 158 Assert.assertTrue( trh1.equals(trh1) ); 159 Assert.assertTrue( ! (trh1.notEquals(trh1)) ); 160 161 //******************************************************************** 162 163 if(debug) System.out.println(ok_prefix + "Check Number of measurements." ); 164 if(debug) System.out.println(trh1.numberOfMeasurements() ); 165 Assert.assertTrue( trh1.numberOfMeasurements()==4 ); 166 167 //******************************************************************** 168 169 // HitTest does not set mcids currently. 170 if(debug) System.out.println(ok_prefix + "Check TrackMcHitInfo" ); 171 if(debug) System.out.println(trh1.mcInfo().bestMcId() ); 172 Assert.assertTrue( trh1.mcInfo().bestMcId()==0 ); 173 174 //******************************************************************** 175 176 177 if(debug) System.out.println(ok_prefix + "Drop all hits." ); 178 Assert.assertTrue( trh1.isFit() ); 179 Assert.assertTrue( trh1.hits().size() == 2 ); 180 trh1.dropHits(); 181 Assert.assertTrue( trh1.hits().size() == 0 ); 182 Assert.assertTrue( ! trh1.isFit() ); 183 184 //******************************************************************** 185 186 if(debug) System.out.println(ok_prefix 187 + "------------- All tests passed. -------------" ); 188 } 189 190 }