View Javadoc

1   package org.lcsim.recon.tracking.trfbase;
2   
3   import org.lcsim.recon.tracking.spacegeom.SpacePoint;
4   import org.lcsim.recon.tracking.spacegeom.SpacePath;
5   
6   /**
7    * A Track vector without error.
8    *<p>
9    * Data includes a surface _srf, a 5-vector _vec and a direction.
10   *<p>
11   * The direction attribute is initially set undefined and may be defined
12   * with methods set_backward() or set_forward().  However, the actual
13   * direction of the track as returned by is_valid(), is_forward() and
14   * is_backward() is obtained by asking the surface.  The direction
15   * attribute is used only if the surface returns undefined.
16   *
17   * @author Norman A. Graf
18   * @version 1.0
19   */
20  
21  public class VTrack
22  {
23      
24      // set surface from clone
25      // direction attribute is not set undefined
26      //private void set_surface_from_clone(Surface srf);
27      
28      // Surface
29      // null indicates track in invalid state of default constructor.
30      Surface _srf;
31      
32      // Track 5-vector.
33      TrackVector _vec;
34      
35      // Direction of the track relative to the surface.
36      // This is needed because track parameters may be ambiguous.
37      TrackSurfaceDirection _dir;
38      
39      // Direction of the track in time
40      // Default is forward in time
41      //used for interactions such as energy loss
42      boolean _forward;
43      
44      // methods
45      
46      //
47      
48      /**
49       *Default constructor.
50       *Leaves track in invalid state.
51       *
52       */
53      public VTrack()
54      {
55          _dir = TrackSurfaceDirection.TSD_UNDEFINED;
56          _forward = true;
57      }
58      
59      //
60      
61      /**
62       *construct a track vector from a surface
63       *
64       * @param srf  Surface
65       */
66      public VTrack( Surface srf)
67      {
68          _srf = srf;
69          _dir = TrackSurfaceDirection.TSD_UNDEFINED;
70          _vec = new TrackVector();
71          _forward = true;
72      }
73      
74      //
75      
76      /**
77       *constructor from a surface and a vector
78       *
79       * @param srf  Surface  at which track is defined
80       * @param  vec TrackVector  of track parameters
81       */
82      public VTrack( Surface srf,  TrackVector vec)
83      {
84          _srf = srf;
85          _vec = new TrackVector(vec);
86          _dir = TrackSurfaceDirection.TSD_UNDEFINED;
87          _forward = true;
88      }
89      
90      //
91      
92      /**
93       *constructor from a surface, vector and direction
94       *
95       * @param  srf Surface  at which track is defined
96       * @param  vec TrackVector  of track parameters
97       * @param  dir TrackSurfaceDirection  of direction
98       */
99      public VTrack( Surface srf,  TrackVector vec,
100             TrackSurfaceDirection dir)
101     {
102         _srf = srf;
103         _vec = new TrackVector(vec);
104         _dir = dir;
105         _forward = true;
106     }
107     
108     //
109     
110     /**
111      *copy constructor
112      *
113      * @param  trv VTrack  to copy
114      */
115     public VTrack( VTrack trv)
116     {
117         _srf = trv._srf;
118         _vec = new TrackVector(trv._vec);
119         _dir = trv._dir;
120         _forward = trv._forward;
121     }
122     
123     //
124     
125     /**
126      *Return true if track is valid.
127      * To be valid, the surface and direction must be defined.
128      *
129      * @return  true if track surface and direction are defined
130      */
131     public boolean isValid()
132     {
133         // check surface is defined
134         if ( _srf == null ) return false;
135         // check direction is defined
136         if ( _srf.direction(_vec) == TrackSurfaceDirection.TSD_UNDEFINED  &&
137                 _dir ==  TrackSurfaceDirection.TSD_UNDEFINED ) return false;
138         return true;
139     }
140     
141     //
142     
143     /**
144      *set surface
145      * direction attribute is set undefined
146      *
147      * @param  srf Surface  at which track will be defined
148      */
149     public void setSurface( Surface srf)
150     {
151         _srf = srf;
152         _dir = TrackSurfaceDirection.TSD_UNDEFINED;
153     }
154     
155     //
156     
157     /**
158      *get surface
159      *
160      * @return Surface at which track is defined
161      */
162     public  Surface surface( )
163     {
164         return _srf;
165     }
166     
167     //
168     
169     /**
170      * set track vector
171      * direction attribute is set undefined
172      *
173      * @param  vec TrackVector  containing track parameters
174      */
175     public void setVector( TrackVector vec)
176     {
177         _vec = new TrackVector(vec);
178         _dir = TrackSurfaceDirection.TSD_UNDEFINED;
179     }
180     
181     //
182     
183     /**
184      *set vector and keep the current direction
185      *
186      * @param vec  TrackVector   containing track parameters
187      */
188     public void setVectorAndKeepDirection( TrackVector vec)
189     {
190         _vec = new TrackVector(vec);
191     }
192     
193     //
194     
195     /**
196      * get track vector
197      *
198      * @return   TrackVector  containing track parameters
199      */
200     public  TrackVector vector()
201     {
202         return new TrackVector(_vec);
203     }
204     
205     //
206     
207     /**
208      *return a component of the vector
209      *
210      * @param   i track component to return
211      * @return  the value of the track vector component i
212      */
213     public double vector(int i)
214     {
215         if( !(i>=0 && i<5) )
216         {
217             throw new IllegalArgumentException("VTrack index must be within [0,4]!");
218         }
219         return _vec.vector()[i];
220     }
221     
222     //
223     
224     /**
225      *set direction forward
226      *
227      */
228     public void setForward()
229     {
230         _dir = TrackSurfaceDirection.TSD_FORWARD;
231     }
232     
233     //
234     
235     /**
236      *set direction backward
237      *
238      */
239     public void setBackward()
240     {
241         _dir = TrackSurfaceDirection.TSD_BACKWARD;
242     }
243     
244     //
245     
246     
247     /**
248      *is track direction same as surface
249      * surface direction takes priority over local value
250      *
251      * @return true if track direction is forward
252      */
253     public boolean isForward()
254     {
255         TrackSurfaceDirection dir =  _srf.direction(_vec);
256         if( dir.equals(TrackSurfaceDirection.TSD_FORWARD) ) return true;
257         if( dir.equals(TrackSurfaceDirection.TSD_BACKWARD) )return false;
258         if ( dir.equals(TrackSurfaceDirection.TSD_UNDEFINED) )  return _dir.equals(TrackSurfaceDirection.TSD_FORWARD);
259         return false;
260     }
261     
262     //cng
263     // Method to
264     
265     /**
266      *set the pure track direction forwards
267      *
268      */
269     public void setTrackForward()
270     {
271         _forward = true;
272     }
273     
274     //
275     
276     /**
277      *return the pure track direction
278      *
279      * @return true if the pure track direction is forward
280      */
281     public boolean isTrackForward()
282     {
283         return _forward;
284     }
285     
286     //
287     
288     
289     /**
290      *is track direction opposite that of surface?
291      * surface direction takes priority over local value
292      *
293      * @return true if track direction is opposite that of Surface
294      */
295     public boolean isBackward()
296     {
297         TrackSurfaceDirection dir =  _srf.direction(_vec);
298         if(dir == TrackSurfaceDirection.TSD_FORWARD) return false;
299         if(dir == TrackSurfaceDirection.TSD_BACKWARD)return true;
300         if (dir == TrackSurfaceDirection.TSD_UNDEFINED)  return _dir == TrackSurfaceDirection.TSD_BACKWARD;
301         return false;
302     }
303     
304     //cng
305     //
306     
307     /**
308      *set the pure track direction backwards
309      *
310      */
311     public void setTrackBackward()
312     {
313         _forward = false;
314     }
315     //
316     
317     /**
318      *return the pure track direction
319      *
320      * @return  true if pure track direction is backward
321      */
322     public boolean isTrackBackward()
323     {
324         return !_forward;
325     }
326     
327     
328     //
329     
330     /**
331      * return the track position
332      *
333      * @return the SpacePoint position of the track on the Surface
334      */
335     public SpacePoint spacePoint()
336     {
337         return surface().spacePoint(vector());
338     }
339     
340     //
341     
342     /**
343      * the track position and direction
344      *
345      * @return get the SpaceVector position and direction of the track on the Surface
346      */
347     public SpacePath spacePath()
348     {
349         return surface().spacePath(vector(),_dir);
350     }
351     
352     //
353     
354     /**
355      *Return q/p in 1/GeV/c.
356      *
357      * @return the track charge over momentum
358      */
359     public double qOverP()
360     {
361         return surface().qOverP(vector());
362     }
363     
364     
365     /**
366      * String representation of the VTrack
367      *
368      * @return String representation of the VTrack
369      */
370     public String toString()
371     {
372         String className = getClass().getName();
373         int lastDot = className.lastIndexOf('.');
374         if(lastDot!=-1)className = className.substring(lastDot+1);
375         
376         return className+" at "+_srf+" with track parameters: \n"+_vec+" travelling in direction "+_dir+" forward: "+_forward+"\n";
377     }
378     
379     //
380     
381     /**
382      *Equality
383      *
384      * @param  vtrk VTrack  to compare with
385      * @return  true if this equals vtrk
386      */
387     public boolean equals(VTrack vtrk)
388     {
389         if( !surface().equals(vtrk.surface()) ) return false;
390         if( !vector().equals(vtrk.vector()) ) return false;
391         if( isForward() && vtrk.isForward() ) return true;
392         if(isBackward() && vtrk.isBackward() ) return true;
393         return false;
394     }
395     
396     //
397     
398     /** Inequality
399      *
400      * @return true if this does not equal vtrk
401      * @param vtrk VTrack to compare
402      */
403     public boolean notEquals(VTrack vtrk)
404     {
405         return !equals(vtrk);
406     }
407 }
408