View Javadoc

1   package org.lcsim.detector.solids;
2   
3   import static org.lcsim.units.clhep.SystemOfUnits.m;
4   import junit.framework.TestCase;
5   
6   import org.lcsim.detector.DetectorElement;
7   import org.lcsim.detector.IPhysicalVolume;
8   import org.lcsim.detector.IPhysicalVolumeNavigator;
9   import org.lcsim.detector.IRotation3D;
10  import org.lcsim.detector.ITransform3D;
11  import org.lcsim.detector.ITranslation3D;
12  import org.lcsim.detector.LogicalVolume;
13  import org.lcsim.detector.PhysicalVolume;
14  import org.lcsim.detector.PhysicalVolumeNavigatorStore;
15  import org.lcsim.detector.RotationGeant;
16  import org.lcsim.detector.Transform3D;
17  import org.lcsim.detector.Translation3D;
18  import org.lcsim.detector.converter.heprep.DetectorElementToHepRepConverter;
19  import org.lcsim.detector.material.IMaterial;
20  import org.lcsim.detector.material.MaterialElement;
21  import org.lcsim.util.test.TestUtil.TestOutputFile;
22  
23  /**
24   * Test that writes out the HepRep for a {@link org.lcsim.detector.solids.Trap} solid.
25   *
26   * @author Jeremy McCormick <jeremym@slac.stanford.edu>
27   * @version $Id: TrapTest.java,v 1.3 2008/03/26 22:02:27 tknelson Exp $
28   */
29  
30  public class TrapTest
31          extends TestCase
32  {
33      private static IMaterial dummymat = new MaterialElement("dummymat",1,1,1.0);
34      IPhysicalVolumeNavigator nav;
35      IPhysicalVolume world;
36      
37      public void testTrd() throws Exception
38      {
39          createGeometry();
40          DetectorElementToHepRepConverter.writeHepRep(new TestOutputFile("TrapTest.heprep").getAbsolutePath());
41      }
42      
43      public IPhysicalVolume createGeometry()
44      {
45          world = createWorld();
46          nav = PhysicalVolumeNavigatorStore.getInstance().createDefault(world);
47          createSolids(world);
48          return world;
49      }
50      
51      public final void createSolids(IPhysicalVolume mom)
52      {
53  //		double dx1 = 30;
54  //		double dx2 = 40;
55  //		double dy1 = 40;
56  //		double dx3 = 10;
57  //		double dx4 = 14;
58  //		double dy2 = 16;
59  //		double dz = 60;
60  //		double theta = Math.toRadians(20);
61  //		double phi = Math.toRadians(5);
62  //		double alph1 = Math.toRadians(10);
63  //		double alph2 = alph1;
64          
65          double dx1 = 100;
66          double dx2 = 100;
67          double dy1 = 10;
68          double dx3 = 50;
69          double dx4 = 50;
70          double dy2 = 10;
71          double dz = 200;
72          double theta = Math.toRadians(-15);
73          double phi = Math.toRadians(0);
74          double alph1 = Math.toRadians(0);
75          double alph2 = alph1;
76          
77          
78          // Unrotated
79          IRotation3D rotation = new RotationGeant(0,0,0);
80          ITranslation3D translation = new Translation3D(0,0,0);
81          ITransform3D transform = new Transform3D(translation,rotation);
82          
83          Trap trap = new Trap("trap",dz,theta,phi,dy1,dx1,dx2,alph1,dy2,dx3,dx4,alph2);
84          LogicalVolume lvTest = new LogicalVolume("lvtrap",trap,dummymat);
85          new PhysicalVolume(
86                  transform,
87                  "pvtrap",
88                  lvTest,
89                  mom.getLogicalVolume(),
90                  0);
91          new DetectorElement("detrap",null,"/pvtrap");
92          
93          
94          // X rotation
95          rotation = new RotationGeant(Math.PI/2,0,0);
96          translation = new Translation3D(200,0,0);
97          transform = new Transform3D(translation,rotation);
98          
99          new PhysicalVolume(
100                 transform,
101                 "pvtrap_x",
102                 lvTest,
103                 mom.getLogicalVolume(),
104                 0);
105         new DetectorElement("detrap_x",null,"/pvtrap_x");
106         
107         // X and Y rotations
108         rotation = new RotationGeant(Math.PI/2,Math.PI/2,0);
109         translation = new Translation3D(400,0,0);
110         transform = new Transform3D(translation,rotation);
111         
112         new PhysicalVolume(
113                 transform,
114                 "pvtrap_xy",
115                 lvTest,
116                 mom.getLogicalVolume(),
117                 0);
118         new DetectorElement("detrap_xy",null,"/pvtrap_xy");
119         
120         // X, Y, Z rotations
121         rotation = new RotationGeant(Math.PI/2,Math.PI/2,Math.PI/2);
122         translation = new Translation3D(600,0,0);
123         transform = new Transform3D(translation,rotation);
124         
125         new PhysicalVolume(
126                 transform,
127                 "pvtrap_xyz",
128                 lvTest,
129                 mom.getLogicalVolume(),
130                 0);
131         new DetectorElement("detrap_xyz",null,"/pvtrap_xyz");
132 
133     }
134     
135     public final IPhysicalVolume createWorld()
136     {
137         Box boxWorld = new Box(
138                 "world_box",
139                 10.0*m,
140                 10.0*m,
141                 10.0*m);
142         
143         LogicalVolume lvWorld =
144                 new LogicalVolume(
145                 "world",
146                 boxWorld,
147                 dummymat);
148         
149         IPhysicalVolume pvTop =
150                 new PhysicalVolume(
151                 null,
152                 "world",
153                 lvWorld,
154                 null,
155                 0);
156         
157         return pvTop;
158     }
159 }