View Javadoc

1   package org.lcsim.recon.tracking.trfxyp;
2   
3   import org.lcsim.recon.tracking.trfutil.Assert;
4   import org.lcsim.recon.tracking.trfutil.TRFMath;
5   
6   import org.lcsim.recon.tracking.spacegeom.SpacePoint;
7   import org.lcsim.recon.tracking.spacegeom.SpacePath;
8   import org.lcsim.recon.tracking.spacegeom.CartesianPoint;
9   import org.lcsim.recon.tracking.spacegeom.CartesianPath;
10  
11  import org.lcsim.recon.tracking.trfbase.Surface;
12  
13  import org.lcsim.recon.tracking.trfbase.VTrack;
14  import org.lcsim.recon.tracking.trfbase.TrackVector;
15  import org.lcsim.recon.tracking.trfbase.CrossStat;
16  import org.lcsim.recon.tracking.trfbase.PureStat;
17  import org.lcsim.recon.tracking.trfbase.TrackSurfaceDirection;
18  
19  
20  /**
21   * Defines the pure suface corresponding to a plane parallel to
22   * the z-axis.
23   *
24   * The corresponding track parameters are:
25   * <li>u (cm) is fixed
26   * <li>0 - v (cm)
27   * <li>1 - z (cm)
28   * <li>2 - dv/du
29   * <li>3 - dz/du
30   * <li>4 - q/p   p is momentum of a track, q is its charge
31   *<p>
32   * (u,v,z) forms a right-handed orthogonal coordinate system
33   *<p>
34   * dist is closest distance between the  z-axis and the plane
35   * phi is an angle normal to the plane forms with the x-axis
36   * phi is between 0 and 2*pi
37   * phi  is positive counterclockwise from x to u
38   * This class serves as a base class for bounded cylinders.
39   *<p>
40   * The forward direction for the surface is +u.
41   *
42   *@author Norman A. Graf
43   *@version 1.0
44   *
45   */
46  public class SurfXYPlane extends Surface
47  {
48      
49      
50      
51      // enums identifying surface parameters
52      
53      public static final int NORMPHI = 0;
54      public static final int DISTNORM = 1;
55      // track parameter indices
56      
57      public static final int IV=0;
58      public static final int IZ=1;
59      public static final int IDVDU=2;
60      public static final int IDZDU=3;
61      public static final int IQP=4;
62      
63      
64      
65      
66      /**
67       *Return a String representation of the class' type name.
68       *Included for completeness with the C++ version.
69       *
70       * @return   A String representation of the class' type name.
71       */
72      public static String typeName()
73      { return "SurfXYPlane"; }
74      
75      /**
76       *Return a String representation of the class' type name.
77       *Included for completeness with the C++ version.
78       *
79       * @return   A String representation of the class' type name.
80       */
81      public static String staticType()
82      { return typeName(); }
83      
84      // attributes
85      
86      protected double _normphi;
87      protected double _distnorm;
88      
89      
90      
91      // Return true if two surfaces have the same pure surface.
92      // Argument may be safely downcast.
93      protected boolean safePureEqual( Surface srf)
94      {
95          double s_phi = ((SurfXYPlane ) srf)._normphi;
96          double s_dist= ((SurfXYPlane ) srf)._distnorm;
97          return ( Math.abs(s_phi - _normphi)< 1e-7 && Math.abs(s_dist-_distnorm) < 1e-7);
98      }
99      
100     // Return true if this surface and the argument are in order.
101     // See Surface::pure_less_than() for more information.
102     // Argument may be safely downcast.
103     protected boolean safePureLessThan( Surface srf)
104     {
105         double s_phi = (( SurfXYPlane ) srf)._normphi;
106         double s_dist= ((SurfXYPlane )srf)._distnorm;
107         return   ( _distnorm < s_dist - 1e-7 ) ||
108                 ( Math.abs(_distnorm - s_dist) < 1e-7  && _normphi < s_phi -1e-7 );
109     }
110     
111     
112     
113     /**
114      * Construct an instance from the shortest distance to the plane from the z axis
115      * and the phi angle of the normal to the plane.
116      * @param distnorm The shortest distance to the plane from the z axis.
117      * @param normphi The angle of the normal to the plane with respect to the x axis.
118      */
119     public SurfXYPlane(double distnorm, double normphi)
120     {
121         // Check if phi is between 0 and 2pi
122         Assert.assertTrue( normphi<TRFMath.TWOPI && normphi>=0. );
123         Assert.assertTrue( distnorm >= 0.);
124         _normphi = normphi;
125         _distnorm = distnorm;
126     }
127     
128     /**
129      * Construct an instance duplicating the SurfXYPlane (copy constructor).
130      * @param sxyp The SurfZPlane to replicate.
131      */
132     public SurfXYPlane( SurfXYPlane sxyp)
133     {
134         _normphi = sxyp._normphi;
135         _distnorm = sxyp._distnorm;
136     }
137     
138     /**
139      *Return a String representation of the class'  type name.
140      *Included for completeness with the C++ version.
141      *
142      * @return   A String representation of the class' the type name.
143      */
144     public String pureType()
145     { return  staticType(); }
146     
147     /**
148      * Return a copy of the underlying pure Surface.
149      *
150      * @return The underlying SurfZPlane.
151      */
152     public Surface newPureSurface()
153     {
154         return new SurfXYPlane(_distnorm,_normphi);
155     }
156     
157     /**
158      *Find the crossing status for a track vector without error.
159      *
160      * @param   trv The VTrack to test.
161      * @return The crossing status.
162      */
163     public CrossStat pureStatus(VTrack trv)
164     {
165         // If the track surface is the same as this, return at
166         Surface srf = trv.surface();
167         if ( srf.equals(this) || pureEqual(srf) ) return new CrossStat(PureStat.AT);
168         // Otherwise extract the space point and set flags using u.
169         double xtrk = trv.spacePoint().x();
170         double ytrk = trv.spacePoint().y();
171         double cphi = Math.cos(_normphi);
172         double sphi = Math.sin(_normphi);
173         double utrk = xtrk*cphi + ytrk*sphi;
174         double usrf = _distnorm;
175         double prec = CrossStat.staticPrecision();
176         if ( Math.abs(utrk-usrf) < prec ) return new CrossStat(PureStat.ON);
177         if ( utrk > usrf ) return new CrossStat(PureStat.OUTSIDE);
178         return new CrossStat(PureStat.INSIDE);
179     }
180     
181     /**
182      *Return the surface parameter.
183      *
184      * @param   ipar The surface parameter index.
185      * There are two surface parameters for an XYPlane:
186      *          DISTNORM is the shortest distance to the plane from the z axis.
187      *          NORMPHI is the angle of the normal to the plane with respect to the x axis.
188      * @return  The shortest distance to the plane from the z axis if ipar==DISTNORM.
189      *          The angle of the normal to the plane with respect to the x axis. if ipar==NORMPHI.
190      */
191     public double parameter(int ipar)
192     {
193         if ( ipar == NORMPHI ) return _normphi;
194         if ( ipar == DISTNORM) return _distnorm;
195         return 0.0;
196     }
197     
198     /**
199      * Return the vector difference of two tracks on this surface.
200      *
201      * @param   vec1 The first TrackVector.
202      * @param   vec2 The second TrackVector.
203      * @return The difference TrackVector.
204      */
205     public TrackVector vecDiff(TrackVector vec1,
206             TrackVector vec2)
207     {
208         TrackVector diff = new TrackVector(vec1);
209         diff = diff.minus(vec2);
210         return diff;
211     }
212     
213     /**
214      *Return the space point for a track vector.
215      *
216      * @param   vec The TrackVector at this Surface.
217      * @return The SpacePoint for the track vec on this Surface.
218      */
219     public SpacePoint spacePoint(TrackVector vec)
220     {
221         double u   = _distnorm;
222         double cphi = Math.cos(_normphi);
223         double sphi = Math.sin(_normphi);
224         double x =  u*cphi - vec.get(IV)*sphi;
225         double y =  u*sphi + vec.get(IV)*cphi;
226         return new CartesianPoint( x , y, vec.get(IZ) );
227         
228     }
229     
230     // Return the space vector for a track. (v,z,dv/du,dz/du,q/p)
231     // du/ds = 1/sqrt(1+dv/du**2+dz/du**2)
232     // dv/ds = dv/du*du/ds
233     // dz/ds = dz/du*du/ds
234     // phi is positive counterclockwise from x to u
235     
236     /**
237      *Return the space vector for a track: (v,z,dv/du,dz/du,q/p).
238      *  du/ds = 1/sqrt(1+dv/du**2+dz/du**2)
239      * dv/ds = dv/du*du/ds
240      * dz/ds = dz/du*du/ds
241      * phi is positive counterclockwise from x to u
242      * @param   vec The TrackVector at this Surface.
243      * @param   dir The direction for this track on this surface.
244      * @return The SpacePath for this track on this surface.
245      */
246     public SpacePath spacePath(TrackVector vec,
247             TrackSurfaceDirection dir)
248     {
249         double u     = _distnorm;
250         double v     = vec.get(IV);
251         double z     = vec.get(IZ);
252         double dv_du = vec.get(IDVDU);
253         double dz_du = vec.get(IDZDU);
254         
255         double cphi =  Math.cos(_normphi);
256         double sphi = Math.sin(_normphi);
257         
258         double x =  u*cphi - v*sphi;
259         double y =  u*sphi + v*cphi;
260         
261         double du_ds = 1./Math.sqrt(1.+dv_du*dv_du+dz_du*dz_du);
262         if ( dir.equals(TrackSurfaceDirection.TSD_BACKWARD) ) du_ds *= -1.0;
263         else Assert.assertTrue( dir.equals(TrackSurfaceDirection.TSD_FORWARD) );
264         double dv_ds = dv_du*du_ds;
265         
266         double dz_ds = dz_du*du_ds;
267         double dx_ds =  du_ds*cphi - dv_ds*sphi;
268         double dy_ds =  du_ds*sphi + dv_ds*cphi;
269         
270         return new CartesianPath(x, y, z, dx_ds, dy_ds, dz_ds);
271     }
272     
273     /**
274      *output stream
275      *
276      * @return The String representation of this instance.
277      */
278     public String toString()
279     {
280         return "XY plane at phi = " + _normphi+
281                 " and distance = "+ _distnorm;
282     }
283     
284 }