View Javadoc

1   package org.lcsim.recon.tracking.trffit;
2   import org.lcsim.recon.tracking.trfutil.Assert;
3   import org.lcsim.recon.tracking.trfbase.Hit;
4   import org.lcsim.recon.tracking.trfbase.ETrack;
5   import org.lcsim.recon.tracking.trfbase.Surface;
6   import org.lcsim.recon.tracking.trffit.HTrack;
7   /**
8    * Adds a hit prediction to a track, refits the track and uses the
9    * new track parameters to update the hit prediction.
10   *<p>
11   * Two methods are provided: one updates an ETrack and its chi-square
12   * and the other updates an HTrack.
13   *<p>
14   * This base class will always return an error.  Subclasses will typically
15   * implement the ETrack method which is then invoked by the HTrack method
16   * defined here.
17   *
18   *@author Norman A. Graf
19   *@version 1.0
20   *
21   */
22  
23  public class AddFitter
24  {
25      
26      // Static methods.
27      
28      //
29      
30      /**
31       *Return String representation of this class' type name.
32       *Included for completeness with the C++ versin.
33       *
34       * @return String representation of this class' type.
35       */
36      public static String typeName()
37      { return "AddFitter"; }
38      
39      //
40      
41      /**
42       *Return String representation of this class' type name.
43       *Included for completeness with the C++ versin.
44       *
45       * @return String representation of this class' type.
46       */
47      public static String staticType()
48      { return typeName(); }
49      
50      // workaround
51      private double _chsq;
52      
53      // methods
54      
55      //
56      
57      /**
58       *Construct a default instance.
59       *
60       */
61      public AddFitter()
62      {
63          _chsq = 0.;
64      }
65      
66      //
67      
68      /**
69       *Return the generic type.
70       * This is only needed at this level.
71       *
72       * @return String representation of this class' type.
73       */
74      public String genericType()
75      { return staticType(); }
76      
77      //
78      
79      /**
80       *Add a hit and fit with the new hit.
81       * Return status 0 if fit is successful, negative value for a local
82       * error and positive for an error in add_hit_fit.
83       * The default method calls add_hit_fit and return its status.
84       * If the fit is successful, then the track fit is updated and the hit
85       * is added to the end of its list.
86       *
87       * @param   trh The HTrack to which the hit will be added.
88       * @param   hit The Hit to add.
89       * @return 0 if hit update and fit are successful.
90       */
91      public  int addHit(HTrack trh,  Hit hit)
92      {
93          // Fetch the starting fit and chi-square.
94          ETrack tre = trh.newTrack();
95          double chsq = trh.chisquared();
96          
97          // check the track and hit are at the same surface
98          Surface tsrf = tre.surface();
99          Surface hsrf = hit.surface();
100         Assert.assertTrue( tsrf.pureEqual(hsrf) );
101         if ( ! tsrf.pureEqual(hsrf) ) return -1;
102         
103         // Check the track is fully fit before adding hit.
104         // Unless this is the first hit.
105         if ( trh.hits().size() !=0 )
106         {
107             Assert.assertTrue( trh.isFit() );
108             if ( ! trh.isFit() ) return -2;
109         }
110         // Fit with the new point; exit if error occurs.
111         int stat = addHitFit(tre,chsq,hit); //chsq is return argument in c++
112         // need to fix this
113         if ( stat != 0 ) return stat;
114         
115         
116         // Update the track with the new fit and hit.
117         trh.addHit(hit);
118         trh.setFit(tre,_chsq);
119         
120         return 0;
121         
122     }
123     
124     
125     /**
126      *Set the chi-squared for the fit.
127      *
128      * @param   chsq The value of chi-square to set for this fit.
129      */
130     public void setChisquared(double chsq)
131     {
132         _chsq = chsq;
133     }
134     
135     
136     /**
137      *Return the chi-squared for the fit.
138      *
139      * @return  The value of chi-square for this fit.
140      */
141     public double chisquared()
142     {
143         return _chsq;
144     }
145     //
146     
147     
148     /**
149      *Refit a track and update its chi-square by adding the specified hit.
150      * Return status 0 if fit is successful, positive value for error.
151      * This is the method implemented by subclasses.
152      * If the fit fails, the track and chi-square may return any value
153      * and the hit may be updated with any track.
154      * If the fit is successful, the fit track and chi-square are
155      * returned and the hit is updated with the fit track.
156      * Normally this is not invoked directly but is called by add_hit.
157      * The default method here returns an error and throws and AssertException.
158      *
159      * @param   tre The ETrack to which the hit will be added.
160      * @param   chisq The value of chi-square to set for this fit.
161      * @param   phit The Hit to add.
162      * @return 1.
163      */
164     public int addHitFit(ETrack tre, double chisq,  Hit phit)
165     {  Assert.assertTrue( false );
166        return 1;}
167     
168     
169     /**
170      *output stream
171      *
172      * @return AString representation of this object.
173      */
174     public String toString()
175     {
176         return getClass().getName();
177     }
178 }