View Javadoc

1   /*
2    * ClusterFindCyl2D_Test.java
3    *
4    * Created on July 24, 2007, 8:59 PM
5    *
6    * $Id: ClusterFindCyl2D_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.List;
12  import junit.framework.TestCase;
13  import org.lcsim.recon.tracking.trfbase.Cluster;
14  import org.lcsim.recon.tracking.trfbase.ETrack;
15  import org.lcsim.recon.tracking.trfbase.TrackError;
16  import org.lcsim.recon.tracking.trfbase.TrackVector;
17  import org.lcsim.recon.tracking.trfutil.Assert;
18  import org.lcsim.recon.tracking.trfutil.TRFMath;
19  
20  /**
21   *
22   * @author Norman Graf
23   */
24  public class ClusterFindCyl2D_Test extends TestCase
25  {
26      private boolean debug;
27      /** Creates a new instance of ClusterFindCyl2D_Test */
28      public void testClusterFindCyl2D()
29      {
30          String component = "ClusterFindCyl2D";
31          String ok_prefix = component + " (I): ";
32          String error_prefix = component + " test (E): ";
33          
34          if(debug) System.out.println( ok_prefix
35                  + "-------- Testing component " + component
36                  + ". --------" );
37          
38          //********************************************************************
39          
40          if(debug) System.out.println( ok_prefix + "Test constructor." );
41          double r1 = 10.0;
42          ClusterFindCyl2D find1 = new ClusterFindCyl2D(r1,10.0);
43          if(debug) System.out.println( find1 );
44          
45          //********************************************************************
46          
47          if(debug) System.out.println( ok_prefix + "Check the surface." );
48          SurfCylinder srf1 = new SurfCylinder(r1);
49          Assert.assertTrue( srf1.equals(find1.surface()) );
50          
51          //********************************************************************
52          
53          if(debug) System.out.println( ok_prefix + "Add clusters to finder." );
54          Cluster clu11 = new ClusCylPhiZ2D(r1,1.23,0.02, 0.0, 0.1, 0.0);   // should fail nearby phi
55          Cluster clu12 = new ClusCylPhiZ2D(r1,5.29,0.02, 0.0, 0.1, 0.0);   // should fail nearby phi
56          Cluster clu13 = new ClusCylPhiZ2D(r1,2.38+TRFMath.TWOPI,0.02, 0.0, 0.1, 0.0);
57          Cluster clu14 = new ClusCylPhiZ2D(r1,2.36,0.02, 0.5, 0.1, 0.0);   // should fail nearby z
58          Cluster clu15 = new ClusCylPhiZ2D(r1,2.34,0.02, 0.0, 0.1, 0.0);
59          find1.addCluster(clu11);
60          find1.addCluster(clu12);
61          find1.addCluster(clu13);
62          find1.addCluster(clu14);
63          int stat = find1.addCluster(clu15);
64          if(debug) System.out.println( find1 );
65          Assert.assertTrue( stat == 0 );
66          if(debug) System.out.println("size= "+find1.clusters().size());
67          Assert.assertTrue( find1.clusters().size() == 5 );
68          
69          //********************************************************************
70          
71          if(debug) System.out.println( ok_prefix + "Find nearby clusters." );
72          TrackVector vec = new TrackVector();
73          vec.set(0, 2.36);
74          TrackError err = new TrackError();
75          err.set(0,0 , 0.0001);
76          err.set(1,1 , 0.01);
77          err.set(2,2 , 0.01);
78          err.set(3,3 , 0.01);
79          err.set(4,4 , 0.01);
80          ETrack tre1 = new ETrack( srf1.newPureSurface(), vec, err );
81          if(debug) System.out.println( tre1 );
82          List nearby_clusters = find1.clusters(tre1);
83          if(debug) System.out.println(nearby_clusters.size());
84          Assert.assertTrue( nearby_clusters.size() == 2 );
85          if(debug) System.out.println( nearby_clusters.get(0) );
86          if(debug) System.out.println( nearby_clusters.get(nearby_clusters.size()-1) );
87          Assert.assertTrue( nearby_clusters.get(0).equals(clu15) );
88          Assert.assertTrue( nearby_clusters.get(nearby_clusters.size()-1).equals(clu13) );
89          
90          //********************************************************************
91          
92          if(debug) System.out.println( ok_prefix + "Drop clusters." );
93          find1.dropClusters();
94          Assert.assertTrue( find1.clusters().size() == 0 );
95          Assert.assertTrue( find1.clusters(tre1).size() == 0 );
96          
97          //********************************************************************
98          
99          if(debug) System.out.println( ok_prefix + "Find a single cluster." );
100         find1.addCluster(clu13);
101         Assert.assertTrue( find1.clusters().size() == 1 );
102         Assert.assertTrue( find1.clusters(tre1).size() == 1 );
103         
104         
105         
106         if(debug) System.out.println( ok_prefix
107                 + "------------- All tests passed. -------------" );
108         
109         //********************************************************************
110         
111     }
112     
113 }