1 package org.lcsim.recon.tracking.trfbase;
2
3 import org.lcsim.recon.tracking.trfutil.TRFMath;
4 import Jama.Matrix;
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public class TrackVector
41 {
42 private Matrix _vec;
43 private int _length;
44
45
46
47
48
49
50
51 public TrackVector( )
52 {
53 _length = 5;
54 _vec = new Matrix(_length,1);
55 }
56
57
58
59
60
61
62
63
64 public TrackVector( double[] vec)
65 {
66 _length = vec.length;
67 if(_length!=5.) throw new IllegalArgumentException();
68 _vec = new Matrix(vec, _length);
69 }
70
71
72
73
74
75
76
77
78 public TrackVector( Matrix mat)
79 {
80 if(mat.getRowDimension()!=5 && mat.getColumnDimension() != 1)
81 {
82 throw new IllegalArgumentException("TrackVector Matrix must be 5x1.");
83 }
84 _length = mat.getRowDimension();
85 _vec = new Matrix(mat.getArrayCopy());
86 }
87
88
89
90
91
92
93
94
95 public TrackVector( TrackVector tv)
96 {
97 _length = tv.vector().length;
98 _vec = new Matrix(tv.vector(),_length);
99 }
100
101
102
103
104
105
106
107
108 public double[] vector()
109 {
110 return _vec.getColumnPackedCopy();
111 }
112
113
114
115
116
117
118
119
120 public TrackVector minus( TrackVector tv)
121 {
122 double[] tmp = new double[5];
123 for(int i = 0; i<5; ++i)
124 {
125 tmp[i] = _vec.get(i,0)-tv.get(i);
126 }
127 return new TrackVector(tmp);
128 }
129
130
131
132
133
134
135
136
137 public TrackVector plus( TrackVector tv)
138 {
139 double[] tmp = new double[5];
140 for(int i = 0; i<5; ++i)
141 {
142 tmp[i] = _vec.get(i,0)+tv.get(i);
143 }
144 return new TrackVector(tmp);
145 }
146
147
148
149
150
151
152
153 public String toString()
154 {
155 String className = getClass().getName();
156 int lastDot = className.lastIndexOf('.');
157 if(lastDot!=-1)className = className.substring(lastDot+1);
158
159 StringBuffer sb = new StringBuffer(className+" ");
160 for(int i=0; i<_length; ++i)
161 {
162 sb.append(_vec.get(i,0)).append(" ");
163 }
164 return sb.append("\n").toString();
165 }
166
167
168
169
170
171
172 public Matrix getMatrix()
173 {
174 return _vec.copy();
175 }
176
177
178
179
180
181
182 public Matrix matrix()
183 {
184 return _vec.copy();
185 }
186
187
188
189
190
191
192
193 public void set(int i, double val)
194 {
195 _vec.set(i, 0, val);
196 }
197
198
199
200
201
202
203
204 public double get(int i)
205 {
206 return _vec.get(i,0);
207 }
208
209
210
211
212
213
214
215
216 public boolean equals( TrackVector tv)
217 {
218 for(int i = 0; i<5; ++i)
219 {
220 if( get(i)!=tv.get(i) ) return false;
221 }
222 return true;
223 }
224
225
226
227
228
229
230
231
232 public boolean notEquals(TrackVector tv)
233 {
234 return !equals(tv);
235 }
236
237
238
239
240
241
242
243
244 public boolean isEqual( TrackVector tv)
245 {
246 for(int i = 0; i<5; ++i)
247 {
248 if( !TRFMath.isEqual(get(i),tv.get(i)) ) return false;
249 }
250 return true;
251 }
252
253
254
255
256
257
258
259 public double amax()
260 {
261 double amax = Math.abs(get(0));
262 for (int i = 1; i<5; ++i)
263 {
264 if(Math.abs(get(i))>amax) amax = Math.abs(get(i));
265 }
266 return amax;
267 }
268
269
270
271
272
273
274
275 public double max()
276 {
277 double max = get(0);
278 for (int i = 1; i<5; ++i)
279 {
280 if(get(i)>max) max = get(i);
281 }
282 return max;
283 }
284
285
286
287
288
289
290
291 public double amin()
292 {
293 double amin = Math.abs(get(0));
294 for (int i = 1; i<5; ++i)
295 {
296 if(Math.abs(get(i))<amin) amin = Math.abs(get(i));
297 }
298 return amin;
299 }
300
301
302
303
304
305
306
307 public double min()
308 {
309 double min = get(0);
310 for (int i = 1; i<5; ++i)
311 {
312 if(get(i)<min) min = get(i);
313 }
314 return min;
315 }
316
317
318
319
320
321
322
323
324
325 public static double chisqDiff(TrackVector tv, TrackError te)
326 {
327
328 return (tv._vec.transpose()).times(te.getMatrix()).times(tv._vec).get(0,0);
329 }
330
331 }