1 package org.lcsim.recon.tracking.trfbase;
2 import Jama.Matrix;
3
4
5
6
7
8
9
10 public class HitError
11 {
12 private Matrix _mat;
13 private int _size;
14
15
16 private HitError( Matrix err )
17 {
18 if(err.getRowDimension() != err.getColumnDimension() )
19 throw new IllegalArgumentException("Error Matrix must be symmetric!");
20 _size = err.getRowDimension();
21 _mat = (Matrix) err.clone();
22 }
23
24
25
26 public HitError()
27 {
28 _size = 0;
29 _mat = new Matrix(_size, _size);
30 }
31
32
33
34
35 public HitError( int size )
36 {
37 _size = size;
38 _mat = new Matrix(_size, _size);
39 }
40
41
42
43
44
45
46
47
48 public HitError( int size, double[] arr )
49 {
50 _size = size;
51 _mat = new Matrix(_size, _size);
52 int i=0;
53 int j=0;
54 int k=0;
55
56 while(k<(_size*_size+_size)/2)
57 {
58 _mat.set(i,j,arr[k]);
59 _mat.set(j,i,arr[k]);
60 k++;
61 for (j = 1; j<=i; ++j)
62 {
63 _mat.set(i,j,arr[k]);
64 _mat.set(j,i,arr[k]);
65 k++;
66 }
67 i++;
68 j=0;
69 }
70 }
71
72
73
74
75
76 public HitError( double e11 )
77 {
78 _size = 1;
79 _mat = new Matrix(_size,_size);
80 _mat.set(0,0,e11);
81 }
82
83
84
85
86
87
88
89 public HitError( double e11, double e12, double e22 )
90 {
91 _size = 2;
92 _mat = new Matrix(_size,_size);
93 _mat.set(0,0,e11);
94 _mat.set(1,0,e12);
95 _mat.set(0,1,e12);
96 _mat.set(1,1,e22);
97 }
98
99
100
101
102
103
104
105
106
107
108 public HitError( double e11, double e21, double e22,
109 double e31, double e32, double e33 )
110 {
111 _size = 3;
112 _mat = new Matrix(_size,_size);
113 _mat.set(0,0,e11);
114 _mat.set(1,0,e21);
115 _mat.set(1,1,e22);
116 _mat.set(2,0,e31);
117 _mat.set(2,1,e32);
118 _mat.set(2,2,e33);
119
120 _mat.set(0,1,e21);
121 _mat.set(0,2,e31);
122 _mat.set(1,2,e32);
123 }
124
125
126
127
128 public HitError( HitDerivative dhit_dtrack,
129 TrackError trkerr )
130 {
131 _size = dhit_dtrack.size();
132 _mat = dhit_dtrack.matrix().times(trkerr.getMatrix().times(dhit_dtrack.matrix().transpose()));
133 }
134
135
136 public HitError( HitError herr )
137 {
138 _size = herr.size();
139 _mat = herr.matrix();
140 }
141
142
143
144
145
146
147
148
149
150
151 public Matrix matrix()
152 {
153 return _mat.copy();
154 }
155
156
157 public int size()
158 {
159 return _size;
160 }
161
162
163 public double get( int i, int j )
164 {
165 return _mat.get(i,j);
166 }
167
168
169
170
171 public void set(int i, int j, double val)
172 {
173 _mat.set(i, j, val);
174 _mat.set(j, i, val);
175 }
176
177
178 public double min( )
179 { return _mat.min(); }
180
181
182 public double max( )
183 { return _mat.max(); }
184
185
186 public double amin( )
187 { return _mat.amin(); }
188
189
190 public double amax( )
191 { return _mat.amax(); }
192
193
194 public int invert()
195 {
196
197
198 _mat.inverse();
199 return 0;
200 }
201
202
203 public HitError plusEquals( HitError herr)
204 {
205 if(_size != herr.size()) throw new IllegalArgumentException("HitVectors have different dimensions!");
206
207 return new HitError( _mat.plusEquals(herr.matrix()) );
208 }
209
210
211
212 public HitError minusEquals( HitError herr)
213 {
214 if(_size != herr.size()) throw new IllegalArgumentException("HitVectors have different dimensions!");
215
216 return new HitError( _mat.minusEquals(herr.matrix()) );
217 }
218
219
220 public HitError
221 plus( HitError he)
222 {
223 return new HitError( _mat.plus(he.matrix()) );
224 }
225
226
227 public HitError
228 minus( HitError he)
229 {
230 return new HitError( _mat.minus(he.matrix()) );
231 }
232
233
234
235 public boolean equals( HitError he)
236 {
237 if ( _size != he.size() ) return false;
238 Matrix tmp = he.matrix();
239 for(int i =0; i<_size; ++i)
240 {
241 for (int j=0; j<_size; ++j)
242 {
243 if(_mat.get(i,j)!=tmp.get(i,j)) return false;
244 }
245 }
246 return true;
247 }
248
249
250 public boolean notEquals( HitError he)
251 {
252 return ! equals(he);
253 }
254
255
256
257
258
259
260
261
262
263 public String toString()
264 {
265 String className = getClass().getName();
266 int lastDot = className.lastIndexOf('.');
267 if(lastDot!=-1)className = className.substring(lastDot+1);
268
269 return className+"\n"+_mat;
270 }
271 }