View Javadoc

1   package org.lcsim.recon.tracking.trfcyl;
2   import org.lcsim.recon.tracking.spacegeom.SpacePoint;
3   import org.lcsim.recon.tracking.spacegeom.CylindricalPoint;
4   import org.lcsim.recon.tracking.spacegeom.SpacePath;
5   import org.lcsim.recon.tracking.spacegeom.CylindricalPath;
6   import org.lcsim.recon.tracking.trfutil.TRFMath;
7   import org.lcsim.recon.tracking.trfutil.Assert;
8   
9   import org.lcsim.recon.tracking.trfbase.Surface;
10  import org.lcsim.recon.tracking.trfbase.VTrack;
11  import org.lcsim.recon.tracking.trfbase.CrossStat;
12  import org.lcsim.recon.tracking.trfbase.PureStat;
13  import org.lcsim.recon.tracking.trfbase.TrackSurfaceDirection;
14  import org.lcsim.recon.tracking.trfbase.TrackVector;
15  
16  /**
17   * Defines the pure suface corresponding to a cylinder with axis
18   * along the z-axis.
19   *It inherits directly from the trfbase class Surface and is a pure surface.
20   *<p>
21   * The corresponding track parameters are:
22   * <li> r (cm) is fixed
23   * <li> 0 - phi
24   * <li> 1 - z (cm)
25   * <li> 2 - alpha = phi_dir - phi; tan(alpha) = r*dphi/dr
26   * <li> 3 - tan(lambda) = dz/dsT
27   * <li> 4 - q/pT (1/GeV/c) (pT is component of p parallel to cylinder)
28   *<p>
29   * The curvature is signed pointing along +z (i.e. phi_dir
30   * is increasing if curvature is positive).
31   * sin(lambda) = dz/ds;
32   *<p>
33   * This class serves as a base class for bounded cylinders.
34   *
35   *@author Norman A. Graf
36   *@version 1.0
37   *
38   */
39  
40  public class SurfCylinder extends Surface
41  {
42      
43      // static methods
44      
45      //
46      
47      /**
48       *Return a String representation of the class' type name.
49       *Included for completeness with the C++ version.
50       *
51       * @return   A String representation of the class' type name.
52       */
53      public static String typeName()
54      { return "SurfCylinder"; }
55      
56      
57      /**
58       *Return a String representation of the class' type name.
59       *Included for completeness with the C++ version.
60       *
61       * @return   A String representation of the class' type name.
62       */
63      public static String staticType()
64      { return typeName(); }
65      
66      // I think I need to handle the enums this way here. It's not typesafe, but
67      // the argument checker in Java will return a run-time Exception
68      // if the values are out of range.
69      
70      // Surface parameters.
71      public static final int RADIUS = 0;
72      
73      // Track parameters.
74      public static final int IPHI=0;
75      public static final int IZ = 1;
76      public static final int IALF=2;
77      public static final int ITLM=3;
78      public static final int IQPT=4;
79      
80      // protected (package) attributes
81      
82      protected double _radius;
83      
84      // Return true if two surfaces have the same pure surface.
85      // Argument may be safely downcast.
86      protected boolean safePureEqual( Surface srf)
87      {
88          return _radius == ((SurfCylinder) srf)._radius;
89      }
90      
91      // Return true if two pure surfaces are ordered.
92      // We order in r.
93      // Argument may be safely downcast.
94      protected boolean safePureLessThan( Surface srf)
95      {
96          return _radius < ((SurfCylinder) srf)._radius;
97      }
98      
99      //
100     
101     /**
102      *Construct an instance specifying the cylinder radius.
103      *
104      * @param   radius The radius of the cylindrical surface.
105      */
106     public SurfCylinder(double radius)
107     {
108         _radius = radius;
109     }
110     
111     //
112     
113     /**
114      * Construct an instance duplicating the SurfCylinder (copy constructor).
115      * @param srf The SurfCylinder to replicate.
116      */
117     public SurfCylinder( SurfCylinder srf)
118     {
119         _radius = srf._radius;
120     }
121     
122     //
123     
124     /**
125      *Return a String representation of the class'  type name.
126      *Included for completeness with the C++ version.
127      *
128      * @return   A String representation of the class' the type name.
129      */
130     public String pureType()
131     {
132         return staticType();
133     }
134     
135     //  public SurfCylinder new_pure_surface()
136     
137     /**
138      * Return a copy of the underlying pure Surface.
139      *
140      * @return The underlying SurfCylinder.
141      */
142     public Surface newPureSurface()
143     {
144         return new SurfCylinder(_radius);
145     }
146     
147     
148     /**
149      * Return a copy of the underlying Surface.
150      *
151      * @return The underlying SurfCylinder.
152      */
153     public Surface newSurface()
154     {
155         return new SurfCylinder(_radius);
156     }
157     
158     //
159     
160     /**
161      *Find the crossing status for a track vector without error.
162      *
163      * @param   trv The VTrack to test.
164      * @return The crossing status.
165      */
166     public CrossStat pureStatus( VTrack trv)
167     {
168         // If the track surface is the same as this, return at.
169         Surface srf = trv.surface();
170         // Still need some infrastructure here...
171         if ( srf.equals(this) || pureEqual(srf) ) return new CrossStat(PureStat.AT);
172         // Otherwise extract the space point and set flags using r.
173         double rtrk = trv.spacePoint().rxy();
174         double rsrf = _radius;
175         double prec = CrossStat.staticPrecision();
176         if ( Math.abs(rtrk-rsrf) < prec ) return new CrossStat(PureStat.ON);
177         if ( rtrk > rsrf ) return new CrossStat(PureStat.OUTSIDE);
178         return new CrossStat(PureStat.INSIDE);
179     }
180     
181     //
182     
183     /**
184      *Return the surface parameter.
185      *
186      * @param   ipar The surface parameter index. There is only one for a SurfCylinder, which is the radius.
187      * @return The radius for this SurfCylinder.
188      */
189     public double parameter(int ipar)
190     {
191         if( ipar != RADIUS)
192         {
193             throw new IllegalArgumentException("Wrong SurfCylinder surface parameter!");
194         }
195         if ( ipar == RADIUS ) return _radius;
196         return 0.0;
197     }
198     
199     //
200     
201     /**
202      *Return the radius.
203      *
204      * @return The radius of this SurfCylinder.
205      */
206     public double radius()
207     { return _radius; }
208     
209     
210     //
211     
212     /**
213      *Return the space point for a track vector.
214      *
215      * @param   vec The TrackVector at this Surface.
216      * @return The SpacePoint for the track vec on this Surface.
217      */
218     public SpacePoint spacePoint( TrackVector vec)
219     {
220         return new CylindricalPoint( _radius, vec.vector()[0], vec.vector()[1] );
221     }
222     
223     //
224     
225     
226     /**
227      *Return the space vector for a track vector.
228      *     dr/ds = cos(lambda)*cos(alpha)
229      * r*dphi/ds = cos(lambda)*sin(alpha)
230      *     dz/ds = sin(lambda)
231      *
232      * @param   vec The TrackVector at this Surface.
233      * @param   dir The direction for this track on this surface.
234      * @return The SpacePath for this track on this surface.
235      */
236     public SpacePath spacePath( TrackVector vec, TrackSurfaceDirection dir)
237     {
238         double r = _radius;
239         double phi = vec.vector()[0];
240         double z = vec.vector()[1];
241         double alf = vec.vector()[2];
242         double tlam = vec.vector()[3];
243         double salf = Math.sin(alf);
244         double calf = Math.cos(alf);
245         double slam = tlam/Math.sqrt(1.0+tlam*tlam);
246         double clam = 1.0;
247         if ( tlam != 0.0 ) clam = slam/tlam;
248         double dr_ds = clam*calf;
249         double r_dphi_ds = clam*salf;
250         double dz_ds = slam;
251         return new CylindricalPath(r, phi, z, dr_ds, r_dphi_ds, dz_ds);
252     }
253     
254     //
255     
256     /**
257      *Return the signed inverse momentum, q/p.
258      *
259      * @param   vec The TrackVector on this Surface.
260      * @return The signed inverse momentum for track vec.
261      */
262     public double qOverP( TrackVector vec)
263     {
264         double tlam = vec.vector()[ITLM];
265         double clam = 1.0/Math.sqrt(1.0+tlam*tlam);
266         //assert( clam != 0.0 );
267         return vec.vector()[IQPT]*clam;
268     }
269     
270     //
271     
272     /**
273      *Return the direction.
274      * Forward is radially outward.
275      *
276      * @param   vec The TrackVector on this Surface.
277      * @return The direction of trackvec on this surface.
278      */
279     public TrackSurfaceDirection direction( TrackVector vec)
280     {
281         double aalf = Math.abs( TRFMath.fmod2( vec.get(IALF), TRFMath.TWOPI ) );
282         Assert.assertTrue( aalf <= Math.PI );
283         if ( aalf <= TRFMath.PI2 ) return TrackSurfaceDirection.TSD_FORWARD;
284         else return TrackSurfaceDirection.TSD_BACKWARD;
285     }
286     
287     
288     /**
289      *output stream
290      *
291      * @return The String representation of this instance.
292      */
293     public String toString()
294     {
295         return super.toString() + ": radius= "+_radius;
296     }
297     
298     
299     /**
300      * Return the vector difference of two tracks on this surface.
301      *
302      * @param   vec1 The first TrackVector.
303      * @param   vec2 The second TrackVector.
304      * @return The difference TrackVector.
305      */
306     public TrackVector vecDiff( TrackVector vec1,
307             TrackVector vec2)
308     {
309         TrackVector diff = new TrackVector(vec1);
310         diff = diff.minus(vec2);
311         double tmp = TRFMath.fmod2( diff.get(SurfCylinder.IPHI), TRFMath.TWOPI );
312         diff.set(SurfCylinder.IPHI, tmp);
313         return diff;
314     }
315     
316     
317 }