View Javadoc

1   package org.lcsim.recon.tracking.gtrbase;
2   
3   import org.lcsim.recon.tracking.trfbase.ETrack;
4   import org.lcsim.recon.tracking.trfbase.TrackVector;
5   import org.lcsim.recon.tracking.trfbase.TrackError;
6   import org.lcsim.recon.tracking.trfbase.Cluster;
7   import org.lcsim.recon.tracking.trfbase.Miss;
8   
9   /**
10   * This class represents the state of a reconstructed track at one
11   * point along its trajectory.  It consists of
12   *<p>
13   * <li>1. the relative path distance s
14   * <li>2. a fit at a surface (ETrack)
15   * <li>3. the fit status (invalid, optimal, ...)
16   * <li>4. a chi-square for that fit
17   * <li>5. smoothing data           * not yet implemented
18   * <li>6. an optional cluster
19   * <li>7. an optional Miss
20   *<p>
21   * The fit at any surface should be an optimal one accounting for
22   * all the preceeding and following clusters.  It is *not* a
23   * partial fit including only the preceeding clusters.
24   *<p>
25   * In principle one can obtain an optimal fit for any point outside
26   * the first or last cluster and immediately between any intermediate
27   * adjacent clusters for which smoothing is defined.
28   *
29   *@author Norman A. Graf
30   *@version 1.0
31   *
32   */
33  
34  
35  public class GTrackState implements Comparable
36  {
37      
38      
39      // The path distance.
40      private double _s;
41      
42      // The track.
43      private ETrack _tre;
44      
45      // The fit status.
46      private FitStatus _fit_status;
47      
48      // Chi-square.
49      private double _chi_square;
50      
51      // Optional smoothing data.
52      //  private Smooth _smooth;
53      
54      // Optional cluster.
55      private Cluster _clu;
56      
57      // Optional miss.
58      private Miss _miss;
59      
60      
61      /**
62       *Construct a default instance.
63       * This  leaves the state invalid.
64       *
65       */
66      public GTrackState()
67      {
68          _s = 0.0;
69          _tre = new ETrack();
70          _fit_status = FitStatus.BADSTATE;
71          _chi_square = 0.0;
72          _clu = null;
73          _miss = null;
74      }
75      
76      /**
77       *Construct an instance from the path distance only.
78       * Fit is set invalid and no cluster or miss is assigned.
79       * This is useful for searching sets using s as a comparator.
80       *
81       * @param   s The path distance to this state.
82       */
83      public  GTrackState(double s)
84      {
85          _s = s;
86          _tre = new ETrack();
87          _fit_status = FitStatus.INVALID;
88          _chi_square = 0.0;
89          _clu = null;
90          _miss = null;
91      }
92      
93      /**
94       * Construct an instance from the path distance and the track fit.
95       * No cluster or miss.
96       *
97       * @param   s    The path distance to this state.
98       * @param   tre  The fit ETRack.
99       * @param   fit_status The fit status.
100      * @param   chi_square The chi-square of the fit.
101      */
102     public GTrackState(double s, ETrack tre, FitStatus fit_status,
103     double chi_square)
104     {
105         _s = s;
106         _tre = new ETrack(tre);
107         _fit_status = fit_status;
108         _chi_square = chi_square;
109         _clu = null;
110         _miss = null;
111     }
112   
113     /**
114      *Construct an instance from the path distance, the track fit and a cluster.
115      *
116      * @param   s      The path distance to this state.
117      * @param   tre    The fit ETRack.
118      * @param   fit_status The fit status.
119      * @param   chi_square The chi-square of the fit.
120      * @param   clu   The cluster associated with this track state.
121      */
122     public GTrackState(double s, ETrack tre, FitStatus fit_status,
123     double chi_square, Cluster clu)
124     {
125         _s = s;
126         _tre = new ETrack(tre);
127         _fit_status = fit_status;
128         _chi_square = chi_square;
129         _clu = clu;
130         _miss = null;
131     }
132    
133     /**
134      *Construct an instance from the path distance, the track fit and a miss.
135      *
136      * @param   s      The path distance to this state.
137      * @param   tre    The fit ETRack.
138      * @param   fit_status The fit status.
139      * @param   chi_square The chi-square of the fit.
140      * @param   miss The miss associated with this track state.
141      */
142     public GTrackState(double s, ETrack tre, FitStatus fit_status,
143     double chi_square, Miss miss)
144     {
145         _s = s;
146         _tre = new ETrack(tre);
147         _fit_status = fit_status;
148         _chi_square = chi_square;
149         _clu = null;
150         _miss = miss;
151     }
152    
153     /**
154      *Construct an instance replicating the GTrackState (copy constructor).
155      *
156      * @param   gts The GTrackState to replicate.
157      */
158     public GTrackState( GTrackState gts)
159     {
160         _s= gts._s;
161         _tre = new ETrack(gts._tre);
162         _fit_status = gts._fit_status;
163         _chi_square = gts._chi_square;
164         _miss = gts._miss;
165     }
166     
167     /**
168      * Drop the fit from the state.
169      * The fit, error and chi-square are zeroed.
170      * The fit status is set INVALID.
171      *
172      */
173     public void dropFit()
174     {
175         TrackVector vec = new TrackVector();
176         for(int i = 0; i<5; ++i) vec.set(i,0.0);
177         TrackError err = new TrackError();
178         for(int i = 0; i<5; ++i)
179         {
180             for(int j = 0; j<5; ++j)
181             {
182                 err.set(i, j, 0.0);
183             }
184         }
185         _tre = new ETrack(_tre.surface(), vec, err);
186         _chi_square = 0.0;
187         _fit_status = FitStatus.INVALID;
188     }
189    
190     /**
191      * Return if this state is valid.
192      * 
193      *
194      * @return true if the track is valid.
195      */
196     public boolean isValid()
197     {
198         return _fit_status != FitStatus.BADSTATE;
199     }
200   
201     /**
202      *Return whether the state is valid and has a valid fit.
203      *
204      * @return true if the track and fit is valid.
205      */
206     public boolean hasValidFit()
207     {
208         return isValid() && _fit_status != FitStatus.INVALID;
209     }
210     
211     /**
212      *Return the path distance to this state.
213      *
214      * @return The path distance.
215      */
216     public double s()
217     {
218         return _s;
219     }
220  
221     /**
222      *Return the track t this state.
223      *
224      * @return The ETrack representing the fit at this state.
225      */
226     public  ETrack track()
227     {
228         return _tre;
229     }
230    
231     /**
232      * Return the fit status.
233      * For most applications, anything but OPTIMAL is suspect.
234      *
235      * @return The status of the fit at this state.
236      */
237     public FitStatus fitStatus()
238     {
239         return _fit_status;
240     }
241     
242     /**
243      *Return the chi-square of the fit.
244      *
245      * @return The fit chi-square.
246      */
247     public double chiSquared()
248     {
249         return _chi_square;
250     }
251    
252     /**
253      * Return the cluster
254      *
255      * @return The cluster associated with this state.
256      */
257     public Cluster cluster()
258     {
259         return _clu;
260     }
261    
262     /**
263      *Return the miss.
264      *
265      * @return The miss associated with this state.
266      */
267     public  Miss miss()
268     {
269         return _miss;
270     }
271    
272     /**
273      *Test equality.
274      * Requires complete match.
275      *
276      * @param   gts The GTrackState to test.
277      * @return true if the states are equal.
278      */
279     public boolean equals( GTrackState gts)
280     {
281         if ( _s != gts.s() ) return false;
282         if ( _fit_status != gts.fitStatus() ) return false;
283         if ( _fit_status != FitStatus.INVALID )
284         {
285             if ( !_tre.equals(gts.track()) ) return false;
286             if ( _chi_square != gts.chiSquared() ) return false;
287         }
288         if ( _clu == null && gts._clu != null) return false;
289         if ( _clu != null && gts._clu == null) return false;
290         if ( _clu != null && gts._clu != null)
291         {
292             if ( !_clu.equals(gts.cluster()) ) return false;
293         }
294         if ( _miss == null && gts._miss != null) return false;
295         if ( _miss != null && gts._miss == null) return false;
296         if ( _miss != null && gts._miss != null)
297         {
298             if ( !_miss.equals(gts.miss()) ) return false;
299         }
300         return true;
301     }
302   
303     /**
304      * Test nequality.
305      *
306      * @param   gts The GTrackState to test.
307      * @return true if the states are not equal.
308      */
309     public  boolean notEquals( GTrackState gts)
310     {
311         return ! (equals(gts));
312     }
313     
314 
315     /**
316      *output stream
317      *
318      * @return A String representation of this instance.
319      */
320     public String toString()
321     {
322         StringBuffer sb = new StringBuffer("GTrackState: \n");
323         if ( isValid() )
324         {
325             sb.append( "Path distance is " + _s + ".\n" );
326             sb.append( track() + "\n");
327             sb.append( "Fit status is " + fitStatus() + ".\n");
328             sb.append( "Chi-square is " + chiSquared() + ".\n" );
329             if ( cluster()!=null ) sb.append( cluster() + "\n");
330             else sb.append( "No cluster defined.\n" );
331             if ( miss()!=null ) sb.append( miss() + "\n");
332             else sb.append( "No miss defined." );
333         }
334         else
335         {
336             sb.append("Invalid state.");
337         }
338         return sb.toString();
339     }
340    
341    /**
342      * Comparable interface
343      * @param o Object to compare to.
344      * @return -1 if less, 0 if equal, 1 if greater.
345      */ 
346     public int compareTo( Object o )
347     {
348         // Make sure o is GTrackState
349         double s = ( (GTrackState) o).s();
350         // Sort on path length
351         //
352         return( _s < s ? -1 : ( _s == s ? 0 : 1 ));
353     }
354     
355 }
356 
357 
358 
359