View Javadoc

1   /*
2    * ThinCylMsSim_Test.java
3    *
4    * Created on July 24, 2007, 7:55 PM
5    *
6    * $Id: ThinCylMsSim_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.SimInteractor;
13  import org.lcsim.recon.tracking.trfbase.TrackVector;
14  import org.lcsim.recon.tracking.trfbase.VTrack;
15  import org.lcsim.recon.tracking.trfutil.Assert;
16  
17  /**
18   *
19   * @author Norman Graf
20   */
21  public class ThinCylMsSim_Test extends TestCase
22  {
23      private boolean debug;
24      /** Creates a new instance of ThinCylMsSim_Test */
25      public void testThinCylMsSim()
26      {
27          String component = "ThinCylMsSim";
28          String ok_prefix = component + " (I): ";
29          String error_prefix = component + " test (E): ";
30          
31          if(debug) System.out.println( ok_prefix
32                  + "---------- Testing component " + component
33                  + ". ----------" );
34          if(debug) System.out.println( ok_prefix + "Test constructor." );
35          ThinCylMsSim scatterIt = new ThinCylMsSim(0.001);
36          if(debug) System.out.println(scatterIt);
37          
38          Assert.assertTrue(scatterIt.radLength() == 0.001);
39          
40          SurfCylinder cyl = new SurfCylinder(20.);
41          double[] pars = {1., 2., 3., 4., 5. };
42          TrackVector tv = new TrackVector(pars);
43          VTrack vtrk = new VTrack(cyl, tv);
44          // Give the track 1GeV
45          if(debug) System.out.println("\n Original VTrack: "+vtrk);
46          TrackVector trv = new TrackVector( vtrk.vector() );
47          trv.set(SurfCylinder.IQPT,1.0);
48          vtrk.setVector( trv );
49          if(debug) System.out.println("\n Modified VTrack: "+vtrk);
50          scatterIt.interact( vtrk );
51          if(debug) System.out.println("\n Interacted VTrack: "+vtrk);
52          if(debug) System.out.println("\n Original TrackVector trv: "+trv);
53          TrackVector scattered = new TrackVector( vtrk.vector() );
54          Assert.assertTrue( scattered.get(SurfCylinder.IPHI) == trv.get(SurfCylinder.IPHI) );
55          Assert.assertTrue( scattered.get(SurfCylinder.IZ) == trv.get(SurfCylinder.IZ) );
56          Assert.assertTrue( scattered.get(SurfCylinder.IALF) != trv.get(SurfCylinder.IALF) );
57          Assert.assertTrue( scattered.get(SurfCylinder.ITLM) != trv.get(SurfCylinder.ITLM) );
58          Assert.assertTrue( scattered.get(SurfCylinder.IQPT) != trv.get(SurfCylinder.IQPT) );
59          if(debug) System.out.println( "before interaction " + trv );
60          if(debug) System.out.println( "after interaction " + scattered );
61          
62          //cng
63          TrackVector tvec = new TrackVector();
64          tvec.set(SurfCylinder.IPHI,1.0);
65          tvec.set(SurfCylinder.IZ, 2.0);
66          tvec.set(SurfCylinder.IALF,3.0);
67          tvec.set(SurfCylinder.ITLM,4.0);
68          tvec.set(SurfCylinder.IQPT,5.0);
69          SurfCylinder scyl = new SurfCylinder(6.0);
70          VTrack t = new VTrack(scyl.newPureSurface(),tvec);
71          if(debug) System.out.println( "Track before interacting... " + t );
72          scatterIt.interact( t );
73          if(debug) System.out.println( "Track after interacting... " + t );
74          //cng
75          
76          
77          tvec.set(SurfCylinder.IPHI,7.25001);
78          tvec.set(SurfCylinder.IZ,83.571);
79          tvec.set(SurfCylinder.IALF,0.0220818);
80          tvec.set(SurfCylinder.ITLM,0.586898);
81          tvec.set(SurfCylinder.IQPT,-0.0116488);
82          
83          
84          SurfCylinder scyl2 = new SurfCylinder(35.0);
85          VTrack t2 = new VTrack(scyl2.newPureSurface(),tvec);
86          if(debug) System.out.println( "Track before interacting... " + t2 );
87          scatterIt.interact( t2 );
88          if(debug) System.out.println( "Track after interacting... " + t2 );
89          
90          //********************************************************************
91          if(debug) System.out.println(ok_prefix + "Testing clone");
92          VTrack trv1 = new VTrack(t2);
93          VTrack trv2 = new VTrack(t2);
94          Assert.assertTrue(trv1.equals(trv2));
95          // clone
96          SimInteractor scatterIt2 = scatterIt.newCopy();
97          // assert they are not the same object
98          Assert.assertTrue( scatterIt2!=scatterIt );
99          // scatter both tracks
100         scatterIt2.interact(trv2);
101         scatterIt.interact(trv1);
102         // assert that the newly scattered tracks are not equal
103         // since scattering is stochastic and we have different random
104         // number generators
105         Assert.assertTrue( trv1.notEquals(trv2) );
106         // assert they're different from the original track
107         Assert.assertTrue( trv1.notEquals(t2) );
108         Assert.assertTrue( trv2.notEquals(t2) );
109         
110         //********************************************************************
111         
112         if(debug) System.out.println( ok_prefix + "Test constructor from ThinCylMs." );
113         ThinCylMs scatter = new ThinCylMs(1.0);
114         ThinCylMsSim simscatter = new ThinCylMsSim(scatter);
115         Assert.assertTrue(scatter.radLength()==simscatter.radLength());
116         
117         
118         
119         if(debug) System.out.println( ok_prefix
120                 + "------------- All tests passed. -------------" );
121         
122         //********************************************************************
123                 
124     }
125     
126 }