View Javadoc

1   package org.lcsim.detector.solids;
2   
3   import hep.physics.vec.Hep3Vector;
4   
5   import static java.lang.Math.abs;
6   import static org.lcsim.detector.solids.Inside.INSIDE;
7   import static org.lcsim.detector.solids.Inside.OUTSIDE;
8   import static org.lcsim.detector.solids.Inside.SURFACE;
9   import static org.lcsim.detector.solids.Tolerance.TOLERANCE;
10  import static java.lang.Math.sqrt;
11  
12  /**
13   *
14   * @author Tim Nelson <tknelson@slac.stanford.edu>
15   * @author Jeremy McCormick <jeremym@slac.stanford.edu>
16   * @version $Id: Tube.java,v 1.8 2009/03/18 02:51:54 jeremy Exp $
17   */
18  public class Tube
19  extends AbstractSolid
20  {
21  	private double innerRadius, outerRadius, zHalfLength;
22  	
23      public Tube(String name, double innerRadius, double outerRadius, double zHalfLength)
24      {
25      	super(name);
26      	this.innerRadius = innerRadius;
27      	this.outerRadius = outerRadius;
28      	this.zHalfLength = zHalfLength;    	
29      }
30      
31      /** 
32  	 * @see org.lcsim.detector.solids.ITube#getInnerRadius()
33  	 */
34      public double getInnerRadius()
35      {
36      	return innerRadius;
37      }
38      
39      /** 
40  	 * @see org.lcsim.detector.solids.ITube#getOuterRadius()
41  	 */
42      public double getOuterRadius()
43      {
44      	return outerRadius;
45      }
46      
47      /** 
48  	 * @see org.lcsim.detector.solids.ITube#getZHalfLength()
49  	 */
50      public double getZHalfLength()
51      {
52      	return zHalfLength;
53      }
54          
55      public double getCubicVolume()
56      {
57          return Math.PI * (outerRadius * outerRadius - 
58          		innerRadius * innerRadius) * (zHalfLength * 2);
59      }
60      
61      public Inside inside(Hep3Vector p)
62      {
63      	Inside inside = OUTSIDE;
64      	
65          double r_xy = sqrt(p.x()*p.x() + p.y()*p.y());
66          
67          // Inside.
68          if ( r_xy > innerRadius - TOLERANCE*0.5 && 
69               r_xy < outerRadius + TOLERANCE*0.5 && 
70          	 abs(p.z()) < zHalfLength + TOLERANCE*0.5)
71          {
72          	inside = INSIDE;
73          }
74          else
75          {
76          	// Inner surface.
77          	if (r_xy >= innerRadius - TOLERANCE*0.5
78          			&& r_xy <= innerRadius + TOLERANCE*0.5
79          			&& abs(p.z()) <= zHalfLength + TOLERANCE*0.5)        		
80          	{
81          		inside = SURFACE;
82          	}
83          	// Outer surface.
84          	else if (r_xy >= outerRadius - TOLERANCE*0.5
85          			&& r_xy <= outerRadius + TOLERANCE*0.5
86          			&& abs(p.z()) <= zHalfLength + TOLERANCE*0.5)
87          	{
88          		inside = SURFACE;
89          	}
90          	// Z plane.
91          	else if (abs(p.z()) >= zHalfLength - TOLERANCE*0.5 &&
92          			abs(p.z()) <= zHalfLength + TOLERANCE*0.5 &&
93          			r_xy >= innerRadius - TOLERANCE*0.5 && 
94                      r_xy <= outerRadius + TOLERANCE*0.5)
95          	{
96          		inside = SURFACE;
97          	}
98          }
99          
100         return inside;
101     }  
102     
103     public String toString()
104     {
105         return this.getClass().getSimpleName()+" "+name+" : innerRadius= "+innerRadius+ " outerRadius= "+outerRadius+" zHalfLength= "+zHalfLength;
106     }
107 }