4 #include "FairTrackParam.h"
22 Double_t t = (RCone - rCone) / (ZCone - zCone);
23 Double_t A = (RCone * zCone - rCone * ZCone) / (ZCone - zCone);
24 Double_t x0 =
x[0] -
x[5] *
x[2];
25 Double_t y0 =
x[1] -
x[5] *
x[3];
28 Double_t a = tx * tx + ty * ty - t * t;
29 Double_t b = 2 * (tx * x0 + ty * y0 + t * A);
30 Double_t c = x0 * x0 + y0 * y0 - A * A;
32 if (
fabs(a) < 1.E-4)
return 1;
33 Double_t D = b * b - 4 * a * c;
36 *
z1 = (-b + D) / (2 * a);
37 *
z2 = (-b - D) / (2 * a);
49 for (Int_t
i = 0, n = 0;
i < N;
i++) {
50 for (Int_t j = 0; j < N; j++, ++n) {
52 for (Int_t k = 0; k < N; ++k)
53 A[n] += S[
indexS(
i, k)] * Q[j * N + k];
59 for (Int_t
i = 0;
i < N;
i++) {
60 for (Int_t j = 0; j <=
i; j++) {
63 for (Int_t k = 0; k < N; k++)
64 S_out[n] += Q[
i * N + k] * A[k * N + j];
76 for (Int_t
i = 0, n = 0;
i < N;
i++) {
77 for (Int_t j = 0; j < N; j++, ++n) {
79 for (Int_t k = 0; k < N; ++k)
80 A[n] += S[
indexS(
i, k)] * Q[k * N + j];
84 for (Int_t
i = 0;
i < N;
i++) {
85 for (Int_t j = 0; j <=
i; j++) {
88 for (Int_t k = 0; k < N; k++)
89 S_out[n] += Q[k * N +
i] * A[k * N + j];
98 for (Int_t
i = 0;
i < n; ++
i) {
99 for (Int_t j = 0; j < n; ++j) {
100 Int_t ind =
i * n + j;
102 for (Int_t k = 0; k < n; ++k)
116 for (
i = 0;
i < 4;
i++)
117 for (j = 0; j < 4; j++)
123 for (
i = 0;
i < 4;
i++) {
124 for (j =
i + 1; j < 4; j++)
126 for (l = 0; l < 4; l++)
128 for (l = 0; l < 4; l++)
130 for (l = 0; l < 4; l++)
132 for (l = 0; l < 4; l++)
134 for (l = 0; l < 4; l++)
136 for (l = 0; l < 4; l++)
140 for (j = 4 - 1; j > -1; j--) {
144 for (j =
i + 1; j < 4; j++) {
146 for (k = 0; k < 4; k++) {
147 a[j][k] += a[
i][k] * factor;
148 b[j][k] += b[
i][k] * factor;
152 for (
i = 3;
i > 0;
i--) {
153 for (j =
i - 1; j > -1; j--) {
155 for (k = 0; k < 4; k++) {
156 a[j][k] += a[
i][k] * factor;
157 b[j][k] += b[
i][k] * factor;
163 for (
i = 0;
i < 4;
i++)
164 for (j = 0; j < 4; j++)
176 for (
i = 0;
i < 5;
i++) {
177 for (j = 0; j < 5; j++) {
186 for (
i = 0;
i < 5;
i++) {
187 for (j =
i + 1; j < 5; j++)
189 for (l = 0; l < 5; l++)
191 for (l = 0; l < 5; l++)
193 for (l = 0; l < 5; l++)
195 for (l = 0; l < 5; l++)
197 for (l = 0; l < 5; l++)
199 for (l = 0; l < 5; l++)
204 for (j = 5 - 1; j > -1; j--) {
208 for (j =
i + 1; j < 5; j++) {
210 for (k = 0; k < 5; k++) {
211 a[j][k] += a[
i][k] * factor;
212 b[j][k] += b[
i][k] * factor;
216 for (
i = 4;
i > 0;
i--) {
217 for (j =
i - 1; j > -1; j--) {
219 for (k = 0; k < 5; k++) {
220 a[j][k] += a[
i][k] * factor;
221 b[j][k] += b[
i][k] * factor;
227 for (
i = 0;
i < 5;
i++)
228 for (j = 0; j < 5; j++)
236 const Double_t
ZERO = 1.E-20;
247 Double_t *j1 = A, *jj = A;
248 for (Int_t j = 1; j <= N; j1 += j++, jj += j) {
249 Double_t *ik = j1,
x = 0;
260 for (Int_t step = 1; step <= N - j; ik += ++step) {
262 for (Double_t* jk = j1; jk != jj; sum += *(jk++) * *(ik++))
264 *ik = (*ik - sum) *
x;
268 for (Int_t
i = j;
i < N;
i++)
283 Double_t *ii = A, *ij = A;
284 for (Int_t
i = 1;
i <= N; ij = ii + 1, ii += ++
i) {
286 Double_t
x = -(*ii = 1. / *ii);
289 for (Int_t j = 1; j <
i; jj += ++j, ij++) {
290 Double_t *ik = ij, *kj = jj, sum = 0.;
291 for (Int_t k = j; ik != ii; kj += k++, ik++) {
298 for (Double_t* ik = ij; ik != ii + 1; ik++) {
311 Double_t *ii = A, *ij = A;
312 for (Int_t
i = 1;
i <= N; ii += ++
i) {
314 Double_t *ki = ii, *kj = ij, sum = 0.;
315 for (Int_t k =
i; k <= N; ki += k, kj += k++)
316 sum += (*ki) * (*kj);
318 }
while ((ij++) != ii);
330 Double_t dx =
x - vx;
331 Double_t dy =
y - vy;
332 Double_t c[3] = {0, 0, 0};
343 Double_t
d = c[0] * c[2] - c[1] * c[1];
344 if (
fabs(
d) < 1.e-20)
return 0;
346 fabs(0.5 * (dx * dx * c[0] - 2 * dx * dy * c[1] + dy * dy * c[2]) /
d));
352 FairField* MagneticField
355 const Double_t
c_light = 0.000299792458;
357 Double_t
x = T[0],
y = T[1], tx = T[2], ty = T[3], qp0 = T[4], z = T[5],
363 txtx = tx * tx, tyty = ty * ty, txty = tx * ty;
365 Double_t Ax = txty, Ay = -txtx - 1, Az = ty, Ayy = tx * (txtx * 3 + 3),
366 Ayz = -2 * txty, Azy = Ayz,
367 Ayyy = -(15 * txtx * txtx + 18 * txtx + 3),
369 Bx = tyty + 1, By = -txty, Bz = -tx, Byy = ty * (txtx * 3 + 1),
370 Byz = 2 * txtx + 1, Bzy = txtx - tyty,
371 Byyy = -txty * (txtx * 15 + 9);
373 Double_t t =
c_light *
sqrt(1. + txtx + tyty),
h = t * qp0;
377 Double_t Sx = 0, Sy = 0, Sz = 0, Syy = 0, Syz = 0, Szy = 0, Syyy = 0;
380 Double_t sx = 0, sy = 0, sz = 0, syy = 0, syz = 0, szy = 0, syyy = 0;
382 Double_t r[3] = {
x,
y, z};
385 Int_t n = int(
fabs(vz - z) / 5.);
387 Double_t dz = (vz - z) / n;
390 MagneticField->GetFieldValue(r, B[0]);
394 MagneticField->GetFieldValue(r, B[1]);
398 MagneticField->GetFieldValue(r, B[2]);
400 sx = (B[0][0] + 4 * B[1][0] + B[2][0]) * dz * 2 / 6.;
401 sy = (B[0][1] + 4 * B[1][1] + B[2][1]) * dz * 2 / 6.;
402 sz = (B[0][2] + 4 * B[1][2] + B[2][2]) * dz * 2 / 6.;
404 Sx = (B[0][0] + 2 * B[1][0]) * dz * dz * 4 / 6.;
405 Sy = (B[0][1] + 2 * B[1][1]) * dz * dz * 4 / 6.;
406 Sz = (B[0][2] + 2 * B[1][2]) * dz * dz * 4 / 6.;
408 Double_t c2[3][3] = {{5, -4, -1}, {44, 80, -4}, {11, 44, 5}};
409 Double_t C2[3][3] = {
410 {38, 8, -4}, {148, 208, -20}, {3, 36, 3}};
411 for (Int_t k = 0; k < 3; k++)
412 for (Int_t
m = 0;
m < 3;
m++) {
413 syz += c2[k][
m] * B[k][1] * B[
m][2];
414 Syz += C2[k][
m] * B[k][1] * B[
m][2];
415 szy += c2[k][
m] * B[k][2] * B[
m][1];
416 Szy += C2[k][
m] * B[k][2] * B[
m][1];
419 syz *= dz * dz * 4 / 360.;
420 Syz *= dz * dz * dz * 8 / 2520.;
422 szy *= dz * dz * 4 / 360.;
423 Szy *= dz * dz * dz * 8 / 2520.;
425 syy = (B[0][1] + 4 * B[1][1] + B[2][1]) * dz * 2;
426 syyy = syy * syy * syy / 1296;
427 syy = syy * syy / 72;
430 (B[0][1] * (38 * B[0][1] + 156 * B[1][1] - B[2][1])
431 + B[1][1] * (208 * B[1][1] + 16 * B[2][1]) + B[2][1] * (3 * B[2][1]))
432 * dz * dz * dz * 8 / 2520.;
434 * (B[0][1] * (85 * B[0][1] + 526 * B[1][1] - 7 * B[2][1])
435 + B[1][1] * (1376 * B[1][1] + 84 * B[2][1])
436 + B[2][1] * (19 * B[2][1]))
438 * (B[1][1] * (1376 * B[1][1] + 256 * B[2][1])
439 + B[2][1] * (62 * B[2][1]))
440 + B[2][1] * B[2][1] * (3 * B[2][1]))
441 * dz * dz * dz * dz * 16 / 90720.;
443 x += tx * 2 * dz +
h * (Sx * Ax + Sy * Ay + Sz * Az)
444 +
h *
h * (Syy * Ayy + Syz * Ayz + Szy * Azy)
445 +
h *
h *
h * Syyy * Ayyy;
446 y += ty * 2 * dz +
h * (Sx * Bx + Sy * By + Sz * Bz)
447 +
h *
h * (Syy * Byy + Syz * Byz + Szy * Bzy)
448 +
h *
h *
h * Syyy * Byyy;
449 tx +=
h * (sx * Ax + sy * Ay + sz * Az)
450 +
h *
h * (syy * Ayy + syz * Ayz + szy * Azy)
451 +
h *
h *
h * syyy * Ayyy;
452 ty +=
h * (sx * Bx + sy * By + sz * Bz)
453 +
h *
h * (syy * Byy + syz * Byz + szy * Bzy)
454 +
h *
h *
h * syyy * Byyy;
463 Ayy = tx * (txtx * 3 + 3);
466 Ayyy = -(15 * txtx * txtx + 18 * txtx + 3);
471 Byy = ty * (txtx * 3 + 1);
474 Byyy = -txty * (txtx * 15 + 9);
480 for (Int_t
i = 2;
i < n;
i++) {
482 Double_t B0[3] = {B[0][0], B[0][1], B[0][2]};
494 B[2][0] = B0[0] - 3 * B[0][0] + 3 * B[1][0];
495 B[2][1] = B0[1] - 3 * B[0][1] + 3 * B[1][1];
496 B[2][2] = B0[2] - 3 * B[0][2] + 3 * B[1][2];
498 Double_t Sx_, Sy_, Sz_, Syy_, Syz_, Szy_, Syyy_;
500 Sx_ = (-B[0][0] + 10 * B[1][0] + 3 * B[2][0]) * dz * dz * 4 / 96.;
501 Sy_ = (-B[0][1] + 10 * B[1][1] + 3 * B[2][1]) * dz * dz * 4 / 96.;
502 Sz_ = (-B[0][2] + 10 * B[1][2] + 3 * B[2][2]) * dz * dz * 4 / 96.;
506 Double_t c2[3][3] = {
507 {5, -52, -13}, {-28, 320, 68}, {-37, 332, 125}};
508 Double_t C2[3][3] = {
509 {13, -152, -29}, {-82, 1088, 170}, {-57, 576, 153}};
511 for (Int_t k = 0; k < 3; k++)
512 for (Int_t
m = 0;
m < 3;
m++) {
513 Syz_ += C2[k][
m] * B[k][1] * B[
m][2];
514 Szy_ += C2[k][
m] * B[k][2] * B[
m][1];
518 Syz_ *= dz * dz * dz * 8 / 80640.;
519 Szy_ *= dz * dz * dz * 8 / 80640.;
521 Syy_ = (B[0][1] * (13 * B[0][1] - 234 * B[1][1] - 86 * B[2][1])
522 + B[1][1] * (1088 * B[1][1] + 746 * B[2][1])
523 + B[2][1] * (153 * B[2][1]))
524 * dz * dz * dz * 8 / 80640.;
527 * (B[0][1] * (-43 * B[0][1] + 1118 * B[1][1] + 451 * B[2][1])
528 + B[1][1] * (-9824 * B[1][1] - 7644 * B[2][1])
529 + B[2][1] * (-1669 * B[2][1]))
531 * (B[1][1] * (29344 * B[1][1] + 32672 * B[2][1])
532 + B[2][1] * (13918 * B[2][1]))
533 + B[2][1] * B[2][1] * (2157 * B[2][1]))
534 * dz * dz * dz * dz * 16 / 23224320.;
537 r[0] =
x + tx * dz +
h * (Sx_ * Ax + Sy_ * Ay + Sz_ * Az)
538 +
h *
h * (Syy_ * Ayy + Syz_ * Ayz + Szy_ * Azy)
539 +
h *
h *
h * Syyy_ * Ayyy;
540 r[1] =
y + ty * dz +
h * (Sx_ * Bx + Sy_ * By + Sz_ * Bz)
541 +
h *
h * (Syy_ * Byy + Syz_ * Byz + Szy_ * Bzy)
542 +
h *
h *
h * Syyy_ * Byyy;
563 MagneticField->GetFieldValue(r, B[2]);
565 Double_t sx_, sy_, sz_, syy_, syz_, szy_, syyy_;
567 sx_ = (-B[0][0] + 8 * B[1][0] + 5 * B[2][0]) * dz * 2 / 24.;
568 sy_ = (-B[0][1] + 8 * B[1][1] + 5 * B[2][1]) * dz * 2 / 24.;
569 sz_ = (-B[0][2] + 8 * B[1][2] + 5 * B[2][2]) * dz * 2 / 24.;
571 Sx_ = (-B[0][0] + 10 * B[1][0] + 3 * B[2][0]) * dz * dz * 4 / 96.;
572 Sy_ = (-B[0][1] + 10 * B[1][1] + 3 * B[2][1]) * dz * dz * 4 / 96.;
573 Sz_ = (-B[0][2] + 10 * B[1][2] + 3 * B[2][2]) * dz * dz * 4 / 96.;
575 syz_ = Syz_ = szy_ = Szy_ = 0;
578 for (Int_t k = 0; k < 3; k++)
579 for (Int_t
m = 0;
m < 3;
m++) {
580 syz_ += c2[k][
m] * B[k][1] * B[
m][2];
581 Syz_ += C2[k][
m] * B[k][1] * B[
m][2];
582 szy_ += c2[k][
m] * B[k][2] * B[
m][1];
583 Szy_ += C2[k][
m] * B[k][2] * B[
m][1];
586 syz_ *= dz * dz * 4 / 5760.;
587 Syz_ *= dz * dz * dz * 8 / 80640.;
589 szy_ *= dz * dz * 4 / 5760.;
590 Szy_ *= dz * dz * dz * 8 / 80640.;
592 syy_ = (B[0][1] - 8 * B[1][1] - 5 * B[2][1]) * dz * 2;
593 syyy_ = -syy_ * syy_ * syy_ / 82944;
594 syy_ = syy_ * syy_ / 1152;
596 Syy_ = (B[0][1] * (13 * B[0][1] - 234 * B[1][1] - 86 * B[2][1])
597 + B[1][1] * (1088 * B[1][1] + 746 * B[2][1])
598 + B[2][1] * (153 * B[2][1]))
599 * dz * dz * dz * 8 / 80640.;
602 * (B[0][1] * (-43 * B[0][1] + 1118 * B[1][1] + 451 * B[2][1])
603 + B[1][1] * (-9824 * B[1][1] - 7644 * B[2][1])
604 + B[2][1] * (-1669 * B[2][1]))
606 * (B[1][1] * (29344 * B[1][1] + 32672 * B[2][1])
607 + B[2][1] * (13918 * B[2][1]))
608 + B[2][1] * B[2][1] * (2157 * B[2][1]))
609 * dz * dz * dz * dz * 16 / 23224320.;
611 x += tx * dz +
h * (Sx_ * Ax + Sy_ * Ay + Sz_ * Az)
612 +
h *
h * (Syy_ * Ayy + Syz_ * Ayz + Szy_ * Azy)
613 +
h *
h *
h * Syyy_ * Ayyy;
614 y += ty * dz +
h * (Sx_ * Bx + Sy_ * By + Sz_ * Bz)
615 +
h *
h * (Syy_ * Byy + Syz_ * Byz + Szy_ * Bzy)
616 +
h *
h *
h * Syyy_ * Byyy;
617 tx +=
h * (sx_ * Ax + sy_ * Ay + sz_ * Az)
618 +
h *
h * (syy_ * Ayy + syz_ * Ayz + szy_ * Azy)
619 +
h *
h *
h * syyy_ * Ayyy;
620 ty +=
h * (sx_ * Bx + sy_ * By + sz_ * Bz)
621 +
h *
h * (syy_ * Byy + syz_ * Byz + szy_ * Bzy)
622 +
h *
h *
h * syyy_ * Byyy;
631 Ayy = tx * (txtx * 3 + 3);
634 Ayyy = -(15 * txtx * txtx + 18 * txtx + 3);
639 Byy = ty * (txtx * 3 + 1);
642 Byyy = -txty * (txtx * 15 + 9);
648 Syyy += dz * syyy + Sy_ * syy + Syy_ * sy + Syyy_;
649 Syy += dz * syy + sy * Sy_ + Syy_;
650 Syz += dz * syz + sz * Sy_ + Syz_;
651 Szy += dz * szy + sy * Sz_ + Szy_;
656 syyy += sy_ * syy + syy_ * sy + syyy_;
657 syy += sy * sy_ + syy_;
658 syz += sz * sy_ + syz_;
659 szy += sz * sz_ + szy_;
679 Ayy = tx * (txtx * 3 + 3);
682 Ayyy = -(15 * txtx * txtx + 18 * txtx + 3);
687 Byy = ty * (txtx * 3 + 1);
690 Byyy = -txty * (txtx * 15 + 9);
697 c = (
x - vx) + tx * (vz - z),
698 b = t * (Sx * Ax + Sy * Ay + Sz * Az),
699 a = t * t * (Syy * Ayy + Syz * Ayz + Szy * Azy),
700 d = t * t * t * (Syyy * Ayyy);
702 Double_t C =
d * qp0 * qp0 * qp0 + a * qp0 * qp0 + b * qp0 + c,
703 B = 3 *
d * qp0 * qp0 + 2 * a * qp0 + b, A = 3 *
d + a;
705 Double_t D = B * B - 4 * A * C;
709 Double_t dqp1 = (-B + D) / 2 / A;
710 Double_t dqp2 = (-B - D) / 2 / A;
711 Double_t dqp = (
fabs(dqp1) <
fabs(dqp2)) ? dqp1 : dqp2;
722 Double_t* mthick_out) {
733 Double_t tmin = mz - mthick / 2, tmax = mz + mthick / 2;
734 if (tmin >= Z || z >= tmax)
return 1;
735 if (z <= tmin && tmax <= Z)
738 *mthick_out = mthick;
739 }
else if (z <= tmin && tmin < Z && Z <= tmax)
741 *mz_out = (tmin + Z) / 2;
742 *mthick_out = Z - tmin;
743 }
else if (tmax <= Z && tmin <= z && z < tmax)
745 *mz_out = (tmax + z) / 2;
746 *mthick_out = tmax - z;
747 }
else if (tmin <= z && Z <= tmax)
749 *mz_out = (Z + z) / 2;
764 Bool_t downstream_direction,
773 Double_t t =
sqrt(1. + tx * tx + ty * ty);
774 if (!
finite(t) || t > 1.e4)
return 1;
776 Double_t l = t * Lrl;
779 (l >
exp(-1. / 0.038)) ? F * .0136 * (1 + 0.038 *
log(l)) * qp : 0.;
780 Double_t a = (1. + mass * mass * qp * qp) * s0 * s0 * t * t * l;
782 *Q5 = a * (1. + tx * tx);
784 *Q9 = a * (1. + ty * ty);
788 Double_t L = downstream_direction ? l : -l;
790 if (0 && is_electron)
797 Double_t m_energyLoss = Fe;
799 Double_t corr = (1. -
fabs(qp) * L * m_energyLoss);
800 if (corr > 0.001 *
fabs(qp))
803 *Ecor = 1000. /
fabs(qp);
821 for (Int_t
i = 0, iCov = 0;
i < 5;
i++)
822 for (Int_t j = 0; j <=
i; j++, iCov++)
823 par->SetCovariance(
i, j, C[iCov]);
839 for (Int_t
i = 0, iCov = 0;
i < 5;
i++)
840 for (Int_t j = 0; j <=
i; j++, iCov++)
841 C[iCov] = par->GetCovariance(
i, j);