1 package org.lcsim.recon.tracking.trffit;
2 import org.lcsim.recon.tracking.trfbase.Propagator;
3 import org.lcsim.recon.tracking.trfbase.PropDir;
4 import org.lcsim.recon.tracking.trfbase.PropStat;
5 import org.lcsim.recon.tracking.trfbase.Hit;
6 import java.util.*;
7
8 /**
9 * Full track fit using Kalman filter. The propagator is specified
10 * when the fitter is constructed. The starting surface, vector and
11 * error matrix are taken from the input track. Errors should be
12 * increased appropriately if the fitter is applied repeatedly to
13 * a single track.
14 *
15 *@author Norman A. Graf
16 *@version 1.0
17 *
18 **/
19 public class FullFitKalman extends FullFitter
20 {
21
22 // static methods
23
24 //
25
26 /**
27 *Return a String representation of the class' the type name.
28 *Included for completeness with the C++ version.
29 *
30 * @return A String representation of the class' the type name.
31 */
32 public static String typeName()
33 { return "FullFitKalman"; }
34
35 //
36
37 /**
38 *Return a String representation of the class' the type name.
39 *Included for completeness with the C++ version.
40 *
41 * @return A String representation of the class' the type name.
42 */
43 public static String staticType()
44 { return typeName(); }
45
46 // The propagator.
47 private Propagator _pprop;
48
49 // The add fitter.
50 private AddFitKalman _addfit;
51
52 //
53
54 /**
55 *Construct an instance specifying a propagator.
56 *
57 * @param prop The Propagator to be used during the fit.
58 */
59 public FullFitKalman(Propagator prop)
60 {
61 _pprop = prop;
62 _addfit = new AddFitKalman();
63 }
64
65 //
66
67 /**
68 *Return a String representation of the class' type name.
69 *Included for completeness with the C++ version.
70 *
71 * @return A String representation of the class' the type name.
72 */
73 public String type()
74 { return staticType(); }
75
76 //
77
78 /**
79 *Return the propagator.
80 *
81 * @return The Propagator used in the fit.
82 */
83 public Propagator propagator()
84 { return _pprop; }
85
86 //
87
88 /**
89 *Fit the specified track.
90 *
91 * @param trh The HTrack to fit.
92 * @return 0 if successful.
93 */
94 public int fit(HTrack trh)
95 {
96 // Copy the hits from the track.
97 List hits = trh.hits();
98 //System.out.println("Hits has "+hits.size()+" elements");
99 // Delete the list of hits from the track.
100 while ( trh.hits().size()>0 ) trh.dropHit();
101 //System.out.println("Hits has "+hits.size()+" elements");
102
103 // Set direction to be nearest.
104 PropDir dir = PropDir.NEAREST;
105
106 // Loop over hits and fit.
107 int icount = 0;
108 for ( Iterator ihit=hits.iterator(); ihit.hasNext(); )
109 {
110
111 // Extract the next hit pointer.
112 Hit hit = (Hit)ihit.next();
113 //System.out.println("Hit "+icount+" is: \n"+hit);
114 // propagate to the surface
115 PropStat pstat = trh.propagate(_pprop,hit.surface(),dir);
116 if ( ! pstat.success() ) return icount;
117
118 // fit track
119 //System.out.println("trh= \n"+trh+", hit= \n"+hit);
120 //System.out.println("_addfit= "+_addfit);
121 int fstat = _addfit.addHit(trh,hit);
122 if ( fstat>0 ) return 10000 + 1000*fstat + icount;
123
124 }
125 return 0;
126
127 }
128
129
130 /**
131 *output stream
132 *
133 * @return The String representation of this instance.
134 */
135 public String toString()
136 {
137 return getClass().getName();
138 }
139
140 }