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 TrackDerivative
41 {
42 private Matrix _mat;
43 private int _size;
44
45
46
47
48
49
50 public TrackDerivative( )
51 {
52 _size = 5;
53 Matrix tmp = Matrix.identity(5,5);
54 _mat = tmp;
55 }
56
57
58
59
60
61
62
63
64 public TrackDerivative(double[][] mat)
65 {
66 _size = mat.length;
67 for (int i = 0; i < _size; i++)
68 {
69 if (mat[i].length != _size)
70 {
71 throw new IllegalArgumentException("All rows must have the same length.");
72 }
73 }
74 _mat = new Matrix(mat, _size, _size);
75
76 }
77
78
79
80
81
82
83
84
85 public TrackDerivative(Matrix mat)
86 {
87 _size = mat.getColumnDimension();
88 if( _size!= mat.getRowDimension()) throw new IllegalArgumentException("Matrix must be square!");
89 if( _size != 5) throw new IllegalArgumentException("Matrix must be 5x5!");
90 _mat = mat.copy();
91 }
92
93
94
95
96
97
98
99
100 public TrackDerivative( TrackDerivative td)
101 {
102 _size = td._size;
103 _mat = td._mat.copy();
104 }
105
106
107
108
109
110
111
112
113 public double[][] matrix()
114 {
115 return _mat.getArrayCopy();
116 }
117
118
119
120
121
122
123
124 public String toString()
125 {
126 String className = getClass().getName();
127 int lastDot = className.lastIndexOf('.');
128 if(lastDot!=-1)className = className.substring(lastDot+1);
129
130 StringBuffer sb = new StringBuffer(className+"\n");
131 for(int i=0; i<_size; ++i)
132 {
133 for(int j = 0; j<_size; ++j)
134 {
135 sb.append(_mat.get(i,j)).append(" ");
136 }
137 sb.append("\n");
138 }
139 return sb.append("\n").toString();
140 }
141
142
143
144
145
146
147
148 public Matrix getMatrix()
149 {
150 return _mat.copy();
151 }
152
153
154
155
156
157
158
159
160
161 public void set(int i, int j, double val)
162 {
163 _mat.set(i,j,val);
164 }
165
166
167
168
169
170
171
172 public void set(TrackDerivative td)
173 {
174 for (int i = 0 ; i < _size ; ++i )
175 {
176 for (int j = 0 ; j < _size ;++j )
177 {
178 set(i,j,td.get(i,j));
179 }
180 }
181 }
182
183
184
185
186
187
188
189
190
191 public double get(int i, int j)
192 {
193 return _mat.get(i, j);
194 }
195
196
197
198
199
200
201 public void setIdentity()
202 {
203 _mat = Matrix.identity(_size, _size);
204 }
205
206
207
208
209
210
211
212
213 public TrackDerivative times(TrackDerivative td)
214 {
215 return new TrackDerivative(_mat.times(td._mat));
216 }
217
218
219
220
221
222
223
224
225 public double amax()
226 {
227 double[][] tmp = matrix();
228 double amax = Math.abs(tmp[0][0]);
229 for(int i = 0; i<5; ++i)
230 {
231 for(int j = 0; j<5; ++j)
232 {
233 if( Math.abs(tmp[i][j])>amax) amax = Math.abs(tmp[i][j]);
234 }
235 }
236 return amax;
237 }
238
239
240
241
242
243
244
245 public double max()
246 {
247 double[][] tmp = matrix();
248 double max = tmp[0][0];
249 for(int i = 0; i<5; ++i)
250 {
251 for(int j = 0; j<5; ++j)
252 {
253 if( tmp[i][j]>max) max = tmp[i][j];
254 }
255 }
256 return max;
257 }
258
259
260
261
262
263
264
265 public double min()
266 {
267 double[][] tmp = matrix();
268 double min = tmp[0][0];
269 for(int i = 0; i<5; ++i)
270 {
271 for(int j = 0; j<5; ++j)
272 {
273 if( tmp[i][j]<min) min = tmp[i][j];
274 }
275 }
276 return min;
277 }
278
279
280
281
282
283
284
285 public double amin()
286 {
287 double[][] tmp = matrix();
288 double amin = Math.abs(tmp[0][0]);
289 for(int i = 0; i<5; ++i)
290 {
291 for(int j = 0; j<5; ++j)
292 {
293 if( Math.abs(tmp[i][j])<amin) amin = Math.abs(tmp[i][j]);
294 }
295 }
296 return amin;
297 }
298
299
300
301
302
303
304
305
306
307 public TrackDerivative minus(TrackDerivative td)
308 {
309 return new TrackDerivative(getMatrix().minus(td.getMatrix()));
310 }
311
312
313
314
315
316
317
318
319 public TrackDerivative plus(TrackDerivative td)
320 {
321 return new TrackDerivative(getMatrix().plus(td.getMatrix()));
322 }
323
324
325
326
327
328
329
330 public boolean equals( TrackDerivative td)
331 {
332 if( _size != td._size ) return false;
333 for (int i = 0 ;i < _size ; ++i )
334 {
335 for (int j = 0; j < _size ; ++j )
336 {
337 if( _mat.get(i,j) != td._mat.get(i,j) ) return false;
338 }
339 }
340 return true;
341 }
342
343
344
345
346
347
348
349 public boolean notEquals(TrackDerivative td)
350 {
351 return !equals(td);
352 }
353
354
355
356
357
358
359
360 public boolean isEqual( TrackDerivative td)
361 {
362 if( _size != td._size ) return false;
363 for (int i = 0 ;i < _size ; ++i )
364 {
365 for (int j = 0; j < _size ; ++j )
366 {
367 if( ! TRFMath.isEqual(_mat.get(i,j),td._mat.get(i,j) ) ) return false;
368 }
369 }
370 return true;
371 }
372
373
374
375
376
377
378 public void transpose()
379 {
380 _mat = _mat.transpose();
381 }
382
383 }