CbmRoot
Loading...
Searching...
No Matches
CbmRichRingFitterEllipseTau.cxx
Go to the documentation of this file.
1/* Copyright (C) 2009-2016 UGiessen/JINR-LIT, Giessen/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Alexander Ayriyan, Semen Lebedev [committer] */
4
12// GMij are indices for a 5x5 matrix.
13#define GM00 0
14#define GM01 1
15#define GM02 2
16#define GM03 3
17#define GM04 4
18
19#define GM10 5
20#define GM11 6
21#define GM12 7
22#define GM13 8
23#define GM14 9
24
25#define GM20 10
26#define GM21 11
27#define GM22 12
28#define GM23 13
29#define GM24 14
30
31#define GM30 15
32#define GM31 16
33#define GM32 17
34#define GM33 18
35#define GM34 19
36
37#define GM40 20
38#define GM41 21
39#define GM42 22
40#define GM43 23
41#define GM44 24
42
43
44// Aij are indices for a 6x6 matrix.
45
46#define GA00 0
47#define GA01 1
48#define GA02 2
49#define GA03 3
50#define GA04 4
51#define GA05 5
52
53#define GA10 6
54#define GA11 7
55#define GA12 8
56#define GA13 9
57#define GA14 10
58#define GA15 11
59
60#define GA20 12
61#define GA21 13
62#define GA22 14
63#define GA23 15
64#define GA24 16
65#define GA25 17
66
67#define GA30 18
68#define GA31 19
69#define GA32 20
70#define GA33 21
71#define GA34 22
72#define GA35 23
73
74#define GA40 24
75#define GA41 25
76#define GA42 26
77#define GA43 27
78#define GA44 28
79#define GA45 29
80
81#define GA50 30
82#define GA51 31
83#define GA52 32
84#define GA53 33
85#define GA54 34
86#define GA55 35
87
89
90
91using std::cout;
92using std::endl;
93
95
97
99{
100 int nofHits = ring->GetNofHits();
101
102 if (nofHits <= 5) {
103 ring->SetXYABP(-1., -1., -1., -1., -1.);
104 ring->SetRadius(-1.);
105 return;
106 }
107
108 if (nofHits >= MAX_NOF_HITS_IN_RING) {
109 cout << "-E- CbmRichRingFitterEllipseTau::DoFit(), too many hits in the ring:" << nofHits << endl;
110 ring->SetXYABP(-1., -1., -1., -1., -1.);
111 ring->SetRadius(-1.);
112 return;
113 }
114
115 //for (int i = 0; i < nofHits; i++) {
116 // CbmRichHit* hit = (CbmRichHit*) fHitsArray->At(ring->GetHit(i));
117 // fX.push_back(hit->GetX());
118 // fY.push_back(hit->GetY());
119 //}
120
121 InitMatrices(ring);
122 Taubin();
123 TransformEllipse(ring);
124 CalcChi2(ring);
125}
126
128{
129 // TMatrixD PQ(5,5); // fPQ = P^(-1) * Q
130
131 Inv5x5();
132 Double_t PQa[25];
133 AMultB(fP, 25, 5, fQ, 25, 5, PQa); //PQ = fP*fQ;
134 TMatrixD PQ(5, 5, PQa);
135
136 // Double_t PQa2[5][5];
137 // Double_t d[5];
138 // Double_t v[5][5];
139 // for(Int_t i = 0; i<5; i++){
140 // for (Int_t j = 0; j<5;j++){
141 // PQa2[i][j] = PQa[5*i+j];
142 // cout << PQa2[i][j] << " ";
143 // }
144 // cout << endl;
145 // }
146 // cout << endl << endl;
147 //
148 // Jacobi(PQa2, d, v);
149 // Eigsrt(d, v);
150
151 TMatrixDEigen eig(PQ);
152 TMatrixD evc = eig.GetEigenVectors();
153
154 Double_t AlgParF = 0.;
155 AlgParF -= evc(0, 0) * fM[GA05];
156 fAlgPar[0] = evc(0, 0);
157
158 AlgParF -= evc(1, 0) * fM[GA15];
159 fAlgPar[1] = evc(1, 0);
160
161 AlgParF -= evc(2, 0) * fM[GA25];
162 fAlgPar[2] = evc(2, 0);
163
164 AlgParF -= evc(3, 0) * fM[GA35];
165 fAlgPar[3] = evc(3, 0);
166
167 AlgParF -= evc(4, 0) * fM[GA45];
168 fAlgPar[4] = evc(4, 0);
169
170 fAlgPar[5] = AlgParF;
171}
172
174{
175 const unsigned int numHits = ring->GetNofHits();
176 const unsigned int numHits2 = 2 * numHits;
177 const unsigned int numHits3 = 3 * numHits;
178 const unsigned int numHits4 = 4 * numHits;
179 const unsigned int numHits5 = 5 * numHits;
180 const unsigned int numHits6 = 6 * numHits;
181 const double oneOverNumHits = 1. / numHits;
182 unsigned int i6;
183 for (unsigned int i = 0; i < numHits; i++) {
184 double x = ring->GetHit(i).fX;
185 double y = ring->GetHit(i).fY;
186 i6 = i * 6;
187 fZ[i6] = fZT[i] = x * x;
188 fZ[i6 + 1] = fZT[i + numHits] = x * y;
189 fZ[i6 + 2] = fZT[i + numHits2] = y * y;
190 fZ[i6 + 3] = fZT[i + numHits3] = x;
191 fZ[i6 + 4] = fZT[i + numHits4] = y;
192 fZ[i6 + 5] = fZT[i + numHits5] = 1.;
193 }
194 AMultB(fZT, numHits6, numHits, fZ, numHits6, 6, fM);
195 for (unsigned int i = 0; i < numHits6; i++)
196 fM[i] = oneOverNumHits * fM[i];
197
198 for (int i = 0; i < 25; i++)
199 fP[i] = 0.;
200
201 fP[GM00] = fM[GA00] - fM[GA05] * fM[GA05];
202 fP[GM01] = fP[GM10] = fM[GA01] - fM[GA05] * fM[GA15];
203 fP[GM02] = fP[GM20] = fM[GA02] - fM[GA05] * fM[GA25];
204 fP[GM03] = fP[GM30] = fM[GA03] - fM[GA05] * fM[GA35];
205 fP[GM04] = fP[GM40] = fM[GA04] - fM[GA05] * fM[GA45];
206
207 fP[GM11] = fM[GA11] - fM[GA15] * fM[GA15];
208 fP[GM12] = fP[GM21] = fM[GA12] - fM[GA15] * fM[GA25];
209 fP[GM13] = fP[GM31] = fM[GA13] - fM[GA15] * fM[GA35];
210 fP[GM14] = fP[GM41] = fM[GA14] - fM[GA15] * fM[GA45];
211
212 fP[GM22] = fM[GA22] - fM[GA25] * fM[GA25];
213 fP[GM23] = fP[GM32] = fM[GA23] - fM[GA25] * fM[GA35];
214 fP[GM24] = fP[GM42] = fM[GA24] - fM[GA25] * fM[GA45];
215
216 fP[GM33] = fM[GA33] - fM[GA35] * fM[GA35];
217 fP[GM34] = fP[GM43] = fM[GA34] - fM[GA35] * fM[GA45];
218
219 fP[GM44] = fM[GA44] - fM[GA45] * fM[GA45];
220
221
222 for (int i = 0; i < 25; i++)
223 fQ[i] = 0.;
224 fQ[GM00] = 4. * fM[GA50];
225 fQ[GM01] = fQ[GM10] = 2. * fM[GA51];
226 fQ[GM03] = fQ[GM30] = 2. * fM[GA53];
227 fQ[GM11] = fM[GA50] + fM[GA52];
228 fQ[GM12] = fQ[GM21] = 2. * fM[GA51];
229 fQ[GM13] = fQ[GM31] = fM[GA54];
230 fQ[GM14] = fQ[GM41] = fM[GA53];
231 fQ[GM22] = 4. * fM[GA52];
232 fQ[GM24] = fQ[GM42] = 2. * fM[GA54];
233 fQ[GM33] = fQ[GM44] = 1.;
234}
235
237{
238 double Pxx = fAlgPar[0];
239 double Pxy = fAlgPar[1];
240 double Pyy = fAlgPar[2];
241 double Px = fAlgPar[3];
242 double Py = fAlgPar[4];
243 double P = fAlgPar[5];
244 CalcChi2(Pxx, Pxy, Pyy, Px, Py, P, ring);
245 ring->SetABCDEF(Pxx, Pxy, Pyy, Px, Py, P);
246
247 double alpha;
248 double QQx, QQy, Qxx, Qyy, Qx, Qy, Q;
249 double cosa, sina, cca, ssa, sin2a;
250 double xc, yc;
251 if (fabs(Pxx - Pyy) > 0.1e-10) {
252 alpha = atan(Pxy / (Pxx - Pyy));
253 alpha = alpha / 2.0;
254 }
255 else
256 alpha = 1.57079633;
257
258 cosa = cos(alpha);
259 sina = sin(alpha);
260 cca = cosa * cosa;
261 ssa = sina * sina;
262 sin2a = sin(2. * alpha);
263 Pxy = Pxy * sin2a / 2.;
264 Qx = Px * cosa + Py * sina;
265 Qy = -Px * sina + Py * cosa;
266 QQx = Qx * Qx;
267 QQy = Qy * Qy;
268 Qxx = 1. / (Pxx * cca + Pxy + Pyy * ssa);
269 Qyy = 1. / (Pxx * ssa - Pxy + Pyy * cca);
270 Q = -P + Qxx * QQx / 4. + Qyy * QQy / 4.;
271 xc = Qx * Qxx;
272 yc = Qy * Qyy;
273
274 double axisA = TMath::Sqrt(Q * Qxx);
275 double axisB = TMath::Sqrt(Q * Qyy);
276 double centerX = -xc * cosa / 2. + yc * sina / 2.;
277 double centerY = -xc * sina / 2. - yc * cosa / 2.;
278
279 ring->SetXYABP(centerX, centerY, axisA, axisB, alpha);
280 ring->SetRadius((axisA + axisB) / 2.);
281
282 if (ring->GetAaxis() < ring->GetBaxis()) {
283 double tmp = ring->GetAaxis();
284 ring->SetAaxis(ring->GetBaxis());
285 ring->SetBaxis(tmp);
286
287 tmp = ring->GetPhi();
288 if (ring->GetPhi() <= 0)
289 ring->SetPhi(ring->GetPhi() + 1.57079633);
290 else
291 ring->SetPhi(ring->GetPhi() - 1.57079633);
292 }
293}
294
296{
297 // Find all NECESSARY 2x2 dets: (30 of them)
298 const double det2_23_01 = fP[GM20] * fP[GM31] - fP[GM21] * fP[GM30];
299 const double det2_23_02 = fP[GM20] * fP[GM32] - fP[GM22] * fP[GM30];
300 const double det2_23_03 = fP[GM20] * fP[GM33] - fP[GM23] * fP[GM30];
301 const double det2_23_04 = fP[GM20] * fP[GM34] - fP[GM24] * fP[GM30];
302 const double det2_23_12 = fP[GM21] * fP[GM32] - fP[GM22] * fP[GM31];
303 const double det2_23_13 = fP[GM21] * fP[GM33] - fP[GM23] * fP[GM31];
304 const double det2_23_14 = fP[GM21] * fP[GM34] - fP[GM24] * fP[GM31];
305 const double det2_23_23 = fP[GM22] * fP[GM33] - fP[GM23] * fP[GM32];
306 const double det2_23_24 = fP[GM22] * fP[GM34] - fP[GM24] * fP[GM32];
307 const double det2_23_34 = fP[GM23] * fP[GM34] - fP[GM24] * fP[GM33];
308 const double det2_24_01 = fP[GM20] * fP[GM41] - fP[GM21] * fP[GM40];
309 const double det2_24_02 = fP[GM20] * fP[GM42] - fP[GM22] * fP[GM40];
310 const double det2_24_03 = fP[GM20] * fP[GM43] - fP[GM23] * fP[GM40];
311 const double det2_24_04 = fP[GM20] * fP[GM44] - fP[GM24] * fP[GM40];
312 const double det2_24_12 = fP[GM21] * fP[GM42] - fP[GM22] * fP[GM41];
313 const double det2_24_13 = fP[GM21] * fP[GM43] - fP[GM23] * fP[GM41];
314 const double det2_24_14 = fP[GM21] * fP[GM44] - fP[GM24] * fP[GM41];
315 const double det2_24_23 = fP[GM22] * fP[GM43] - fP[GM23] * fP[GM42];
316 const double det2_24_24 = fP[GM22] * fP[GM44] - fP[GM24] * fP[GM42];
317 const double det2_24_34 = fP[GM23] * fP[GM44] - fP[GM24] * fP[GM43];
318 const double det2_34_01 = fP[GM30] * fP[GM41] - fP[GM31] * fP[GM40];
319 const double det2_34_02 = fP[GM30] * fP[GM42] - fP[GM32] * fP[GM40];
320 const double det2_34_03 = fP[GM30] * fP[GM43] - fP[GM33] * fP[GM40];
321 const double det2_34_04 = fP[GM30] * fP[GM44] - fP[GM34] * fP[GM40];
322 const double det2_34_12 = fP[GM31] * fP[GM42] - fP[GM32] * fP[GM41];
323 const double det2_34_13 = fP[GM31] * fP[GM43] - fP[GM33] * fP[GM41];
324 const double det2_34_14 = fP[GM31] * fP[GM44] - fP[GM34] * fP[GM41];
325 const double det2_34_23 = fP[GM32] * fP[GM43] - fP[GM33] * fP[GM42];
326 const double det2_34_24 = fP[GM32] * fP[GM44] - fP[GM34] * fP[GM42];
327 const double det2_34_34 = fP[GM33] * fP[GM44] - fP[GM34] * fP[GM43];
328
329 // Find all NECESSARY 3x3 dets: (40 of them)
330 const double det3_123_012 = fP[GM10] * det2_23_12 - fP[GM11] * det2_23_02 + fP[GM12] * det2_23_01;
331 const double det3_123_013 = fP[GM10] * det2_23_13 - fP[GM11] * det2_23_03 + fP[GM13] * det2_23_01;
332 const double det3_123_014 = fP[GM10] * det2_23_14 - fP[GM11] * det2_23_04 + fP[GM14] * det2_23_01;
333 const double det3_123_023 = fP[GM10] * det2_23_23 - fP[GM12] * det2_23_03 + fP[GM13] * det2_23_02;
334 const double det3_123_024 = fP[GM10] * det2_23_24 - fP[GM12] * det2_23_04 + fP[GM14] * det2_23_02;
335 const double det3_123_034 = fP[GM10] * det2_23_34 - fP[GM13] * det2_23_04 + fP[GM14] * det2_23_03;
336 const double det3_123_123 = fP[GM11] * det2_23_23 - fP[GM12] * det2_23_13 + fP[GM13] * det2_23_12;
337 const double det3_123_124 = fP[GM11] * det2_23_24 - fP[GM12] * det2_23_14 + fP[GM14] * det2_23_12;
338 const double det3_123_134 = fP[GM11] * det2_23_34 - fP[GM13] * det2_23_14 + fP[GM14] * det2_23_13;
339 const double det3_123_234 = fP[GM12] * det2_23_34 - fP[GM13] * det2_23_24 + fP[GM14] * det2_23_23;
340 const double det3_124_012 = fP[GM10] * det2_24_12 - fP[GM11] * det2_24_02 + fP[GM12] * det2_24_01;
341 const double det3_124_013 = fP[GM10] * det2_24_13 - fP[GM11] * det2_24_03 + fP[GM13] * det2_24_01;
342 const double det3_124_014 = fP[GM10] * det2_24_14 - fP[GM11] * det2_24_04 + fP[GM14] * det2_24_01;
343 const double det3_124_023 = fP[GM10] * det2_24_23 - fP[GM12] * det2_24_03 + fP[GM13] * det2_24_02;
344 const double det3_124_024 = fP[GM10] * det2_24_24 - fP[GM12] * det2_24_04 + fP[GM14] * det2_24_02;
345 const double det3_124_034 = fP[GM10] * det2_24_34 - fP[GM13] * det2_24_04 + fP[GM14] * det2_24_03;
346 const double det3_124_123 = fP[GM11] * det2_24_23 - fP[GM12] * det2_24_13 + fP[GM13] * det2_24_12;
347 const double det3_124_124 = fP[GM11] * det2_24_24 - fP[GM12] * det2_24_14 + fP[GM14] * det2_24_12;
348 const double det3_124_134 = fP[GM11] * det2_24_34 - fP[GM13] * det2_24_14 + fP[GM14] * det2_24_13;
349 const double det3_124_234 = fP[GM12] * det2_24_34 - fP[GM13] * det2_24_24 + fP[GM14] * det2_24_23;
350 const double det3_134_012 = fP[GM10] * det2_34_12 - fP[GM11] * det2_34_02 + fP[GM12] * det2_34_01;
351 const double det3_134_013 = fP[GM10] * det2_34_13 - fP[GM11] * det2_34_03 + fP[GM13] * det2_34_01;
352 const double det3_134_014 = fP[GM10] * det2_34_14 - fP[GM11] * det2_34_04 + fP[GM14] * det2_34_01;
353 const double det3_134_023 = fP[GM10] * det2_34_23 - fP[GM12] * det2_34_03 + fP[GM13] * det2_34_02;
354 const double det3_134_024 = fP[GM10] * det2_34_24 - fP[GM12] * det2_34_04 + fP[GM14] * det2_34_02;
355 const double det3_134_034 = fP[GM10] * det2_34_34 - fP[GM13] * det2_34_04 + fP[GM14] * det2_34_03;
356 const double det3_134_123 = fP[GM11] * det2_34_23 - fP[GM12] * det2_34_13 + fP[GM13] * det2_34_12;
357 const double det3_134_124 = fP[GM11] * det2_34_24 - fP[GM12] * det2_34_14 + fP[GM14] * det2_34_12;
358 const double det3_134_134 = fP[GM11] * det2_34_34 - fP[GM13] * det2_34_14 + fP[GM14] * det2_34_13;
359 const double det3_134_234 = fP[GM12] * det2_34_34 - fP[GM13] * det2_34_24 + fP[GM14] * det2_34_23;
360 const double det3_234_012 = fP[GM20] * det2_34_12 - fP[GM21] * det2_34_02 + fP[GM22] * det2_34_01;
361 const double det3_234_013 = fP[GM20] * det2_34_13 - fP[GM21] * det2_34_03 + fP[GM23] * det2_34_01;
362 const double det3_234_014 = fP[GM20] * det2_34_14 - fP[GM21] * det2_34_04 + fP[GM24] * det2_34_01;
363 const double det3_234_023 = fP[GM20] * det2_34_23 - fP[GM22] * det2_34_03 + fP[GM23] * det2_34_02;
364 const double det3_234_024 = fP[GM20] * det2_34_24 - fP[GM22] * det2_34_04 + fP[GM24] * det2_34_02;
365 const double det3_234_034 = fP[GM20] * det2_34_34 - fP[GM23] * det2_34_04 + fP[GM24] * det2_34_03;
366 const double det3_234_123 = fP[GM21] * det2_34_23 - fP[GM22] * det2_34_13 + fP[GM23] * det2_34_12;
367 const double det3_234_124 = fP[GM21] * det2_34_24 - fP[GM22] * det2_34_14 + fP[GM24] * det2_34_12;
368 const double det3_234_134 = fP[GM21] * det2_34_34 - fP[GM23] * det2_34_14 + fP[GM24] * det2_34_13;
369 const double det3_234_234 = fP[GM22] * det2_34_34 - fP[GM23] * det2_34_24 + fP[GM24] * det2_34_23;
370
371 // Find all NECESSARY 4x4 dets: (25 of them)
372 const double det4_0123_0123 =
373 fP[GM00] * det3_123_123 - fP[GM01] * det3_123_023 + fP[GM02] * det3_123_013 - fP[GM03] * det3_123_012;
374 const double det4_0123_0124 =
375 fP[GM00] * det3_123_124 - fP[GM01] * det3_123_024 + fP[GM02] * det3_123_014 - fP[GM04] * det3_123_012;
376 const double det4_0123_0134 =
377 fP[GM00] * det3_123_134 - fP[GM01] * det3_123_034 + fP[GM03] * det3_123_014 - fP[GM04] * det3_123_013;
378 const double det4_0123_0234 =
379 fP[GM00] * det3_123_234 - fP[GM02] * det3_123_034 + fP[GM03] * det3_123_024 - fP[GM04] * det3_123_023;
380 const double det4_0123_1234 =
381 fP[GM01] * det3_123_234 - fP[GM02] * det3_123_134 + fP[GM03] * det3_123_124 - fP[GM04] * det3_123_123;
382 const double det4_0124_0123 =
383 fP[GM00] * det3_124_123 - fP[GM01] * det3_124_023 + fP[GM02] * det3_124_013 - fP[GM03] * det3_124_012;
384 const double det4_0124_0124 =
385 fP[GM00] * det3_124_124 - fP[GM01] * det3_124_024 + fP[GM02] * det3_124_014 - fP[GM04] * det3_124_012;
386 const double det4_0124_0134 =
387 fP[GM00] * det3_124_134 - fP[GM01] * det3_124_034 + fP[GM03] * det3_124_014 - fP[GM04] * det3_124_013;
388 const double det4_0124_0234 =
389 fP[GM00] * det3_124_234 - fP[GM02] * det3_124_034 + fP[GM03] * det3_124_024 - fP[GM04] * det3_124_023;
390 const double det4_0124_1234 =
391 fP[GM01] * det3_124_234 - fP[GM02] * det3_124_134 + fP[GM03] * det3_124_124 - fP[GM04] * det3_124_123;
392 const double det4_0134_0123 =
393 fP[GM00] * det3_134_123 - fP[GM01] * det3_134_023 + fP[GM02] * det3_134_013 - fP[GM03] * det3_134_012;
394 const double det4_0134_0124 =
395 fP[GM00] * det3_134_124 - fP[GM01] * det3_134_024 + fP[GM02] * det3_134_014 - fP[GM04] * det3_134_012;
396 const double det4_0134_0134 =
397 fP[GM00] * det3_134_134 - fP[GM01] * det3_134_034 + fP[GM03] * det3_134_014 - fP[GM04] * det3_134_013;
398 const double det4_0134_0234 =
399 fP[GM00] * det3_134_234 - fP[GM02] * det3_134_034 + fP[GM03] * det3_134_024 - fP[GM04] * det3_134_023;
400 const double det4_0134_1234 =
401 fP[GM01] * det3_134_234 - fP[GM02] * det3_134_134 + fP[GM03] * det3_134_124 - fP[GM04] * det3_134_123;
402 const double det4_0234_0123 =
403 fP[GM00] * det3_234_123 - fP[GM01] * det3_234_023 + fP[GM02] * det3_234_013 - fP[GM03] * det3_234_012;
404 const double det4_0234_0124 =
405 fP[GM00] * det3_234_124 - fP[GM01] * det3_234_024 + fP[GM02] * det3_234_014 - fP[GM04] * det3_234_012;
406 const double det4_0234_0134 =
407 fP[GM00] * det3_234_134 - fP[GM01] * det3_234_034 + fP[GM03] * det3_234_014 - fP[GM04] * det3_234_013;
408 const double det4_0234_0234 =
409 fP[GM00] * det3_234_234 - fP[GM02] * det3_234_034 + fP[GM03] * det3_234_024 - fP[GM04] * det3_234_023;
410 const double det4_0234_1234 =
411 fP[GM01] * det3_234_234 - fP[GM02] * det3_234_134 + fP[GM03] * det3_234_124 - fP[GM04] * det3_234_123;
412 const double det4_1234_0123 =
413 fP[GM10] * det3_234_123 - fP[GM11] * det3_234_023 + fP[GM12] * det3_234_013 - fP[GM13] * det3_234_012;
414 const double det4_1234_0124 =
415 fP[GM10] * det3_234_124 - fP[GM11] * det3_234_024 + fP[GM12] * det3_234_014 - fP[GM14] * det3_234_012;
416 const double det4_1234_0134 =
417 fP[GM10] * det3_234_134 - fP[GM11] * det3_234_034 + fP[GM13] * det3_234_014 - fP[GM14] * det3_234_013;
418 const double det4_1234_0234 =
419 fP[GM10] * det3_234_234 - fP[GM12] * det3_234_034 + fP[GM13] * det3_234_024 - fP[GM14] * det3_234_023;
420 const double det4_1234_1234 =
421 fP[GM11] * det3_234_234 - fP[GM12] * det3_234_134 + fP[GM13] * det3_234_124 - fP[GM14] * det3_234_123;
422
423 // Find the 5x5 det:
424 const double det = fP[GM00] * det4_1234_1234 - fP[GM01] * det4_1234_0234 + fP[GM02] * det4_1234_0134
425 - fP[GM03] * det4_1234_0124 + fP[GM04] * det4_1234_0123;
426 // if (determ)
427 // *determ = det;
428 //
429 // if (det == 0) {
430 // Error("Inv5x5", "matrix is singular");
431 // return kFALSE;
432 // }
433 const double oneOverDet = 1.0 / det;
434 const double mn1OverDet = -oneOverDet;
435
436 fP[GM00] = det4_1234_1234 * oneOverDet;
437 fP[GM01] = det4_0234_1234 * mn1OverDet;
438 fP[GM02] = det4_0134_1234 * oneOverDet;
439 fP[GM03] = det4_0124_1234 * mn1OverDet;
440 fP[GM04] = det4_0123_1234 * oneOverDet;
441
442 fP[GM10] = det4_1234_0234 * mn1OverDet;
443 fP[GM11] = det4_0234_0234 * oneOverDet;
444 fP[GM12] = det4_0134_0234 * mn1OverDet;
445 fP[GM13] = det4_0124_0234 * oneOverDet;
446 fP[GM14] = det4_0123_0234 * mn1OverDet;
447
448 fP[GM20] = det4_1234_0134 * oneOverDet;
449 fP[GM21] = det4_0234_0134 * mn1OverDet;
450 fP[GM22] = det4_0134_0134 * oneOverDet;
451 fP[GM23] = det4_0124_0134 * mn1OverDet;
452 fP[GM24] = det4_0123_0134 * oneOverDet;
453
454 fP[GM30] = det4_1234_0124 * mn1OverDet;
455 fP[GM31] = det4_0234_0124 * oneOverDet;
456 fP[GM32] = det4_0134_0124 * mn1OverDet;
457 fP[GM33] = det4_0124_0124 * oneOverDet;
458 fP[GM34] = det4_0123_0124 * mn1OverDet;
459
460 fP[GM40] = det4_1234_0123 * oneOverDet;
461 fP[GM41] = det4_0234_0123 * mn1OverDet;
462 fP[GM42] = det4_0134_0123 * oneOverDet;
463 fP[GM43] = det4_0124_0123 * mn1OverDet;
464 fP[GM44] = det4_0123_0123 * oneOverDet;
465}
466
467void CbmRichRingFitterEllipseTau::AMultB(const double* const ap, int na, int ncolsa, const double* const bp, int nb,
468 int ncolsb, double* cp)
469{
470 // Elementary routine to calculate matrix multiplication A*B
471
472 const double* arp0 = ap; // Pointer to A[i,0];
473 while (arp0 < ap + na) {
474 for (const double* bcp = bp; bcp < bp + ncolsb;) { // Pointer to the j-th column of B, Start bcp = B[0,0]
475 const double* arp = arp0; // Pointer to the i-th row of A, reset to A[i,0]
476 double cij = 0;
477 while (bcp < bp + nb) { // Scan the i-th row of A and
478 cij += *arp++ * *bcp; // the j-th col of B
479 bcp += ncolsb;
480 }
481 *cp++ = cij;
482 bcp -= nb - 1; // Set bcp to the (j+1)-th col
483 }
484 arp0 += ncolsa; // Set ap to the (i+1)-th row
485 }
486}
487
488#define ROTATE(a, i, j, k, l) \
489 g = a[i][j]; \
490 h = a[k][l]; \
491 a[i][j] = g - s * (h + g * tau); \
492 a[k][l] = h + s * (g - h * tau)
493#define MAXSWEEP 50
494void CbmRichRingFitterEllipseTau::Jacobi(double a[5][5], double d[5], double v[5][5])
495{
496 double tresh, theta, tau, t, sm, s, h, g, c;
497
498 double b[5], z[5];
499 unsigned int ip, iq, i, j;
500 for (ip = 0; ip < 5; ip++) {
501 for (iq = 0; iq < 5; iq++)
502 v[ip][iq] = 0.;
503 v[ip][ip] = 1.;
504 }
505
506 for (ip = 0; ip < 5; ip++) {
507 b[ip] = a[ip][ip];
508 z[ip] = 0.;
509 }
510
511 int nrot = 0;
512
513 for (i = 1; i <= MAXSWEEP; i++) {
514
515 for (sm = 0., ip = 0; ip < 5; ip++)
516 for (iq = ip + 1; iq < 5; iq++)
517 sm += fabs(a[ip][iq]);
518 if (sm == 0.) {
519 return;
520 }
521
522 tresh = (i < 4 ? 0.2 * sm / (5 * 5) : 0.);
523
524 for (ip = 0; ip < 4; ip++)
525 for (iq = ip + 1; iq < 5; iq++) {
526
527 g = 100. * fabs(a[ip][iq]);
528 if (i > 4 && (float) fabs(d[ip] + g) == (float) fabs(d[ip]) && (float) fabs(d[iq] + g) == (float) fabs(d[iq]))
529 a[ip][iq] = 0.;
530
531 else if (fabs(a[ip][iq]) > tresh) {
532 h = d[ip] - d[iq];
533
534 if ((float) (fabs(h) + g) == (float) fabs(h))
535 t = a[ip][iq] / h;
536 else {
537 theta = 0.5 * h / a[ip][iq];
538 t = 1. / (fabs(theta) + sqrt(1. + theta * theta));
539 if (theta < 0.) t = -t;
540 }
541 c = 1. / sqrt(1 + t * t);
542 s = t * c;
543 tau = s / (1. + c);
544 h = t * a[ip][iq];
545 z[ip] -= h;
546 z[iq] += h;
547 d[ip] -= h;
548 d[iq] += h;
549 a[ip][iq] = 0.;
550 for (j = 0; j < ip; j++) {
551 ROTATE(a, j, ip, j, iq);
552 }
553 for (j = ip + 1; j < iq; j++) {
554 ROTATE(a, ip, j, iq, j);
555 }
556 for (j = iq + 1; j < 5; j++) {
557 ROTATE(a, ip, j, j, iq);
558 }
559 for (j = 0; j < 5; j++) {
560 ROTATE(v, j, ip, j, iq);
561 }
562 ++nrot;
563 }
564 }
565 for (ip = 0; ip < 5; ip++) {
566 b[ip] += z[ip];
567 d[ip] = b[ip];
568 z[ip] = 0.;
569 }
570 } //i rot
571}
572
573void CbmRichRingFitterEllipseTau::Eigsrt(double d[5], double v[5][5])
574{
575 double p;
576 int i, k, j;
577 for (i = 0; i < 5; i++) {
578 p = d[k = i];
579 for (j = i + 1; j < 5; j++)
580 if (d[j] >= p) p = d[k = j];
581 if (k != i) {
582 d[k] = d[i];
583 d[i] = p;
584 for (j = 0; j < 5; j++) {
585 p = v[j][i];
586 v[j][i] = v[j][k];
587 v[j][k] = p;
588 }
589 }
590 }
591}
#define ROTATE(a, i, j, k, l)
Here the ring is fitted with Taubin algorithm from A. Ayriyan, G. Ososkov, N. Chernov.
friend fvec sqrt(const fvec &a)
friend fvec cos(const fvec &a)
friend fvec sin(const fvec &a)
fscal v[fmask::Size]
Definition KfSimdPseudo.h:4
static const int MAX_NOF_HITS_IN_RING
virtual void CalcChi2(CbmRichRingLight *ring)
Calculate chi2 of the ellipse fit.
CbmRichRingFitterEllipseTau()
Default constructor.
virtual void DoFit(CbmRichRingLight *ring)
Inherited from CbmRichRingFitterBase.
void AMultB(const double *const ap, int na, int ncolsa, const double *const bp, int nb, int ncolsb, double *cp)
Matrices multiplication.
void TransformEllipse(CbmRichRingLight *ring)
Transform fitted curve to ellipse parameters.
double fZT[MAX_NOF_HITS_IN_RING *6]
double fZ[MAX_NOF_HITS_IN_RING *6]
void Jacobi(double a[5][5], double d[5], double v[5][5])
Jacobi method.
void Eigsrt(double d[5], double v[5][5])
Find eigenvalues.
void InitMatrices(CbmRichRingLight *ring)
Initialize all matrices.
void SetXYABP(float x, float y, float a, float b, float p)
Set all 5 ellipse parameters.
void SetRadius(float r)
float GetAaxis() const
void SetABCDEF(float a, float b, float c, float d, float e, float f)
Set all 6 parameters of curve equation Axx+Bxy+Cyy+Dx+Ey+F.
void SetPhi(double phi)
void SetBaxis(double b)
float GetPhi() const
void SetAaxis(double a)
int GetNofHits() const
Return number of hits in ring.
float GetBaxis() const
CbmRichHitLight GetHit(int ind)
Return hit by the index.
Data class with information on a STS local track.