View Javadoc

1   package org.lcsim.geometry.subdetector;
2   
3   import hep.graphics.heprep.HepRep;
4   import hep.graphics.heprep.HepRepFactory;
5   import hep.graphics.heprep.HepRepInstance;
6   import hep.graphics.heprep.HepRepInstanceTree;
7   import hep.graphics.heprep.HepRepType;
8   import hep.graphics.heprep.HepRepTypeTree;
9   import hep.physics.vec.BasicHep3Vector;
10  import hep.physics.vec.Hep3Vector;
11  
12  import org.jdom.Element;
13  import org.jdom.JDOMException;
14  import org.lcsim.detector.ITransform3D;
15  import org.lcsim.detector.RotationGeant;
16  import org.lcsim.detector.Transform3D;
17  import org.lcsim.detector.Translation3D;
18  
19  /**
20   * 
21   * @author Jeremy McCormick
22   * @version $Id: TubeSegment.java,v 1.4 2010/12/03 01:21:39 jeremy Exp $
23   */
24  
25  public class TubeSegment extends AbstractSubdetector
26  {
27      double rmin, rmax, zhalf;
28      ITransform3D trans;
29  
30      public TubeSegment( Element node ) throws JDOMException
31      {
32          super( node );
33          Element tubs = node.getChild( "tubs" );
34  
35          rmin = tubs.getAttribute( "rmin" ).getDoubleValue();
36          rmax = tubs.getAttribute( "rmax" ).getDoubleValue();
37          zhalf = tubs.getAttribute( "zhalf" ).getDoubleValue();
38  
39          Element pos = node.getChild( "position" );
40          double x, y, z;
41          x = y = z = 0;
42          if ( pos != null )
43          {
44              try
45              {
46                  x = pos.getAttribute( "x" ).getDoubleValue();
47              }
48              catch ( Exception ex )
49              {
50              }
51              try
52              {
53                  y = pos.getAttribute( "y" ).getDoubleValue();
54              }
55              catch ( Exception ex )
56              {
57              }
58              try
59              {
60                  z = pos.getAttribute( "z" ).getDoubleValue();
61              }
62              catch ( Exception ex )
63              {
64              }
65          }
66  
67          Element rot = node.getChild( "rotation" );
68          double rx, ry, rz;
69          rx = ry = rz = 0;
70          if ( rot != null )
71          {
72              try
73              {
74                  rx = rot.getAttribute( "x" ).getDoubleValue();
75              }
76              catch ( Exception ex )
77              {
78              }
79              try
80              {
81                  ry = rot.getAttribute( "y" ).getDoubleValue();
82              }
83              catch ( Exception ex )
84              {
85              }
86              try
87              {
88                  rz = rot.getAttribute( "z" ).getDoubleValue();
89              }
90              catch ( Exception ex )
91              {
92              }
93          }
94  
95          trans = new Transform3D( new Translation3D( x, y, z ), new RotationGeant( rx, ry, rz ) );
96      }
97  
98      public void appendHepRep( HepRepFactory factory, HepRep heprep )
99      {
100         HepRepInstanceTree instanceTree = heprep.getInstanceTreeTop( "Detector", "1.0" );
101         HepRepTypeTree typeTree = heprep.getTypeTree( "DetectorType", "1.0" );
102 
103         HepRepType barrel = typeTree.getType( "Barrel" );
104 
105         HepRepType type = factory.createHepRepType( barrel, getName() );
106         
107         type.addAttValue( "drawAs", "Cylinder" );
108         type.addAttValue( "color", getVisAttributes().getColor() );
109 
110         double zmin = -zhalf;
111         double zmax = zhalf;
112 
113         Hep3Vector point1 = trans.transformed( new BasicHep3Vector( 0, 0, zmin ) );
114         Hep3Vector point2 = trans.transformed( new BasicHep3Vector( 0, 0, zmax ) );
115 
116         HepRepInstance instance = factory.createHepRepInstance( instanceTree, type );
117         instance.addAttValue( "radius", rmin );
118         factory.createHepRepPoint( instance, point1.x(), point1.y(), point1.z() );
119         factory.createHepRepPoint( instance, point2.x(), point2.y(), point2.z() );
120 
121         HepRepInstance instance2 = factory.createHepRepInstance( instanceTree, type );
122         instance2.addAttValue( "radius", rmax );
123         factory.createHepRepPoint( instance2, point1.x(), point1.y(), point1.z() );
124         factory.createHepRepPoint( instance2, point2.x(), point2.y(), point2.z() );
125     }
126 
127     public final double getInnerRadius()
128     {
129         return rmin;
130     }
131 
132     public final double getOuterRadius()
133     {
134         return rmax;
135     }
136 
137     public final double getZHalfLength()
138     {
139         return zhalf;
140     }
141 
142     public ITransform3D getTransform()
143     {
144         return trans;
145     }
146 }