View Javadoc

1   /*
2    * HelicalTrackFit.java
3    *
4    * Created on March 25, 2006, 6:11 PM
5    *
6    * $Id: HelicalTrackFit.java,v 1.16 2008/10/13 01:05:58 partridge Exp $
7    */
8   
9   package org.lcsim.fit.helicaltrack;
10  
11  import hep.physics.matrix.SymmetricMatrix;
12  import java.util.Map;
13  import org.lcsim.constants.Constants;
14  
15  /**
16   * Represents the result of a fit to a helical track.
17   * @author Norman Graf
18   * @version 2.0 (modified by R. Partridge)
19   */
20  public class HelicalTrackFit {
21      /**
22       * Index of DCA element in parameter array and covariance matrix.
23       */
24      public static int dcaIndex = 0;
25      /**
26       * Index of phi0 element in parameter array and covariance matrix.
27       */
28      public static int phi0Index = 1;
29      /**
30       * Index of curvature element in the parameter array and covariance matrix.
31       */
32      public static int curvatureIndex = 2;
33      /**
34       * Index of the z0 coordinate in the parameter array and covariance matrix.
35       */
36      public static int z0Index = 3;
37      /**
38       * Index of the slope in the parameter array and covariance matrix.
39       */
40      public static int slopeIndex = 4;
41      // fit independently to a circle in x-y and a line in s-z
42      // first is circle, second is line
43      private double[] _chisq = new double[2];
44      private double _nhchisq;
45      private int[] _ndf = new int[2];
46      private double[] _parameters;
47      private SymmetricMatrix _covmatrix;
48      private Map<HelicalTrackHit, Double> _smap;
49      private Map<HelicalTrackHit, MultipleScatter> _msmap;
50       /**
51       * Doubles used for error variables
52       */
53      //Omega error
54      private double curveerror;
55      //tanl(lambda) error
56      private double slopeerror;
57      //distance of closest approach error
58      private double dcaerror;
59      //azimuthal angle at DCA for momentum error
60      private double phi0error;
61      //z position when the particle is at the dca error
62      private double z0error;
63      
64      /**
65       * Creates a new instance of HelicalTrackFit
66       * @param pars array of helix parameters
67       * @param cov covariance matrix of helix fit
68       * @param chisq chisq of the circle fit (chisq[0]) and s-z fit (chisq[1])
69       * @param ndf dof for the circle fit (ndf[0]) and s-z fit (ndf[1])
70       * @param smap map containing the x-y path lengths
71       * @param msmap map containing the multiple scattering uncertainties
72       */
73      public HelicalTrackFit(double[]pars, SymmetricMatrix cov, double[] chisq, int[] ndf,
74              Map<HelicalTrackHit, Double> smap, Map<HelicalTrackHit, MultipleScatter> msmap) {
75          _parameters = pars;
76          _covmatrix = cov;
77          _chisq = chisq;
78          _nhchisq = 0.;
79          _ndf = ndf;
80          _smap = smap;
81          _msmap = msmap;
82      }
83      
84      /**
85       * Return the helix parameters as an array.
86       * @return helix parameters
87       */
88      public double[] parameters() {
89          return _parameters;
90      }
91      
92      /**
93       * Return the signed helix DCA.
94       * @return DCA
95       */
96      public double dca() {
97          return _parameters[dcaIndex];
98      }
99      
100     /**
101      * Return the azimuthal direction at the DCA
102      * @return azimuthal direction
103      */
104     public double phi0() {
105         return _parameters[phi0Index];
106     }
107     
108     /**
109      * Return the signed helix curvature.
110      * @return helix curvature
111      */
112     public double curvature() {
113         return _parameters[curvatureIndex];
114     }
115     
116     /**
117      * Return the z coordinate for the DCA.
118      * @return z coordinate
119      */
120     public double z0() {
121         return _parameters[z0Index];
122     }
123     
124     /**
125      * Return the helix slope tan(lambda).
126      * @return slope
127      */
128     public double slope() {
129         return _parameters[slopeIndex];
130     }
131     
132     /**
133      * Return the helix covariance matrix.
134      * @return covariance matrix
135      */
136     public SymmetricMatrix covariance() {
137         return _covmatrix;
138     }
139     
140     /**
141      * Return the helix fit chisqs.  chisq[0] is for the circle fit, chisq[1] is
142      * for the s-z fit.
143      * @return chisq array
144      */
145     public double[] chisq() {
146         return _chisq;
147     }
148     
149     /**
150      * Set the chisq for non-holonomic constraints (e.g., pT > xx).
151      * @param nhchisq non-holonomic constraint chisq
152      */
153     public void setnhchisq(double nhchisq) {
154         _nhchisq = nhchisq;
155         return;
156     }
157     
158     /**
159      * Return the non-holenomic constraint chisq.
160      * @return non-holenomic constraint chisq
161      */
162     public double nhchisq() {
163         return _nhchisq;
164     }
165     
166     /**
167      * Return the total chisq: chisq[0] + chisq[1] + nhchisq.
168      * @return total chisq
169      */
170     public double chisqtot() {
171         return _chisq[0]+_chisq[1]+_nhchisq;
172     }
173     
174     /**
175      * Return the degrees of freedom for the fits.  ndf[0] is for the circle fit
176      * and ndf[1] is for the s-z fit.
177      * @return dof array
178      */
179     public int[] ndf() {
180         return _ndf;
181     }
182     
183     /**
184      * Return cos(theta).
185      * @return cos(theta)
186      */
187     public double cth() {
188         return slope() / Math.sqrt(1 + Math.pow(slope(), 2));
189     }
190     
191     /**
192      * Return sin(theta).
193      * @return sin(theta)
194      */
195     public double sth() {
196         return 1. / Math.sqrt(1 + Math.pow(slope(), 2));
197     }
198     
199     /**
200      * Return transverse momentum pT for the helix.
201      * @param bfield magnetic field
202      * @return pT
203      */
204     public double pT(double bfield) {
205         return Constants.fieldConversion * bfield * Math.abs(R());
206     }
207     
208     /**
209      * Return the momentum.
210      * @param bfield magnetic field
211      * @return momentum
212      */
213     public double p(double bfield) {
214         return pT(bfield) / sth();
215     }
216     
217     /**
218      * Return the radius of curvature for the helix.
219      * @return radius of curvature
220      */
221     public double R() {
222         return 1. / curvature();
223     }
224     
225     /**
226      * Return the x coordinate of the helix center/axis.
227      * @return x coordinate of the helix axis
228      */
229     public double xc() {
230         return (R() - dca()) * Math.sin(phi0());
231     }
232     
233     /**
234      * Return the y coordinate of the helix center/axis.
235      * @return y coordinate of the helix axis
236      */
237     public double yc() {
238         return -(R() - dca()) * Math.cos(phi0());
239     }
240     
241     public double x0() {
242         return -dca() * Math.sin(phi0());
243     }
244     
245     public double y0() {
246         return dca() * Math.cos(phi0());
247     }
248     
249     /**
250      * Return a map of x-y path lengths for the hits used in the helix fit.
251      * @return path length map
252      */
253     public Map<HelicalTrackHit, Double> PathMap() {
254         return _smap;
255     }
256     
257     /**
258      * Return a map of the MultipleScatter objects supplied for the fit.
259      * @return map of multiple scattering uncertainties
260      */
261     public Map<HelicalTrackHit, MultipleScatter> ScatterMap() {
262         return _msmap;
263     }
264      /**
265      * Return the error for curvature, omega
266      * @return a double curveerror
267      */
268     public double getCurveError()
269     {
270         curveerror = Math.sqrt(_covmatrix.e(HelicalTrackFit.curvatureIndex, HelicalTrackFit.curvatureIndex));
271         return curveerror;
272     }
273     /**
274      * Return the error for slope dz/ds, tan(lambda)
275      * @return double a slopeerror
276      */
277     public double getSlopeError()
278     {
279         slopeerror = Math.sqrt(_covmatrix.e(HelicalTrackFit.slopeIndex, HelicalTrackFit.slopeIndex));
280         return slopeerror;
281     }
282     /**
283      * Return the error for distance of closest approach, dca
284      * @return a double dcaerror
285      */
286     public double getDcaError()
287     {
288         dcaerror = Math.sqrt(_covmatrix.e(HelicalTrackFit.dcaIndex, HelicalTrackFit.dcaIndex));
289         return dcaerror;
290     }
291     /**
292      * Return the error for phi0, azimuthal angle of the momentum at the DCA ref. point
293      * @return a double phi0error
294      */
295     public double getPhi0Error()
296     {
297         phi0error = Math.sqrt(_covmatrix.e(HelicalTrackFit.phi0Index, HelicalTrackFit.phi0Index));
298         return phi0error;
299     }
300     /**
301      * Return the error for z0, the z position of the particle at the DCA
302      * @return a double z0error
303      */
304     public double getZ0Error()
305     {
306         z0error = Math.sqrt(_covmatrix.e(HelicalTrackFit.z0Index, HelicalTrackFit.z0Index));
307         return z0error;
308     }
309     /**
310      * Create a string with the helix parameters.
311      * @return string containing the helix parameters
312      */
313     public String toString() {
314         StringBuffer sb = new StringBuffer("HelicalTrackFit: \n");
315         sb.append("d0= "+dca()+"\n");
316         sb.append("phi0= "+phi0()+"\n");
317         sb.append("curvature: "+curvature()+"\n");
318         sb.append("z0= "+z0()+"\n");
319         sb.append("tanLambda= "+slope()+"\n");
320         return sb.toString();
321     }
322 }