23#ifndef GPUCA_GPUCODE_DEVICE
27#ifndef GPUCA_ALIGPUCODE
28#include <fmt/printf.h>
35template <
typename value_T>
37 : mX{0.f}, mAlpha{0.f}, mP{0.f}
48 value_t radPos2 = xyz[0] * xyz[0] + xyz[1] * xyz[1];
50 if (sectorAlpha || radPos2 < 1) {
51 alp = gpu::CAMath::ATan2(pxpypz[1], pxpypz[0]);
53 alp = gpu::CAMath::ATan2(xyz[1], xyz[0]);
56 alp = math_utils::detail::angle2Alpha<value_t>(alp);
60 math_utils::detail::sincos(alp, sn, cs);
62 if (cs * pxpypz[0] + sn * pxpypz[1] < 0) {
63 LOG(
debug) <<
"alpha from phiPos() will invalidate this track parameters, overriding to alpha from phi()";
64 alp = gpu::CAMath::ATan2(pxpypz[1], pxpypz[0]);
66 alp = math_utils::detail::angle2Alpha<value_t>(alp);
68 math_utils::detail::sincos(alp, sn, cs);
72 if (gpu::CAMath::Abs(sn) < 2 * kSafe) {
74 alp += alp < constants::math::PIHalf ? 2 * kSafe : -2 * kSafe;
76 alp += alp > -constants::math::PIHalf ? -2 * kSafe : 2 * kSafe;
78 math_utils::detail::sincos(alp, sn, cs);
79 }
else if (gpu::CAMath::Abs(cs) < 2 * kSafe) {
81 alp += alp > constants::math::PIHalf ? 2 * kSafe : -2 * kSafe;
83 alp += alp > -constants::math::PIHalf ? 2 * kSafe : -2 * kSafe;
85 math_utils::detail::sincos(alp, sn, cs);
88 dim3_t ver{xyz[0], xyz[1], xyz[2]};
89 dim3_t mom{pxpypz[0], pxpypz[1], pxpypz[2]};
92 math_utils::detail::rotateZ<value_t>(ver, -alp);
93 math_utils::detail::rotateZ<value_t>(mom, -alp);
95 value_t ptI = 1.f / gpu::CAMath::Sqrt(mom[0] * mom[0] + mom[1] * mom[1]);
100 mP[
kSnp] = mom[1] * ptI;
101 mP[
kTgl] = mom[2] * ptI;
102 mAbsCharge = gpu::CAMath::Abs(
charge);
106 if (gpu::CAMath::Abs(1 - getSnp()) < kSafe) {
107 mP[
kSnp] = 1.f - kSafe;
108 }
else if (gpu::CAMath::Abs(-1 - getSnp()) < kSafe) {
109 mP[
kSnp] = -1.f + kSafe;
115template <
typename value_T>
119 if (gpu::CAMath::Abs(getQ2Pt()) < constants::math::Almost0 || gpu::CAMath::Abs(getSnp()) > constants::math::Almost1) {
123 value_t r = gpu::CAMath::Sqrt((1.f - getSnp()) * (1.f + getSnp()));
124 math_utils::detail::sincos(getAlpha(), sn, cs);
125 pxyz[0] = pt * (
r * cs - getSnp() * sn);
126 pxyz[1] = pt * (getSnp() * cs +
r * sn);
127 pxyz[2] = pt * getTgl();
132template <
typename value_T>
138 if (gpu::CAMath::Abs(snp) > constants::math::Almost1) {
141 value_t &sn = posdirp[7], &cs = posdirp[8];
142 value_t csp = gpu::CAMath::Sqrt((1.f - snp) * (1.f + snp));
143 value_t cstht = gpu::CAMath::Sqrt(1.f + getTgl() * getTgl());
145 math_utils::detail::sincos(getAlpha(), sn, cs);
146 posdirp[0] =
getX() * cs -
getY() * sn;
147 posdirp[1] =
getX() * sn +
getY() * cs;
149 posdirp[3] = (csp * cs - snp * sn) * csthti;
150 posdirp[4] = (snp * cs + csp * sn) * csthti;
151 posdirp[5] = getTgl() * csthti;
152 posdirp[6] = cstht / ptI;
157template <
typename value_T>
161 if (gpu::CAMath::Abs(getSnp()) > constants::math::Almost1) {
162 LOGP(
debug,
"Precondition is not satisfied: |sin(phi)|>1 ! {:f}", getSnp());
166 math_utils::detail::bringToPMPi<value_t>(
alpha);
169 math_utils::detail::sincos(
alpha - getAlpha(), sa, ca);
170 value_t snp = getSnp(), csp = gpu::CAMath::Sqrt((1.f - snp) * (1.f + snp));
173 if ((csp * ca + snp * sa) < 0) {
178 value_t tmp = snp * ca - csp * sa;
179 if (gpu::CAMath::Abs(tmp) > constants::math::Almost1) {
180 LOGP(
debug,
"Rotation failed: new snp {:.2f}", tmp);
185 mX = xold * ca + yold * sa;
186 mP[
kY] = -xold * sa + yold * ca;
192template <
typename value_T>
202 if (gpu::CAMath::Abs(dx) < constants::math::Almost0) {
206 if (gpu::CAMath::Abs(dx) > 1e5 || gpu::CAMath::Abs(
getY()) > 1e5 || gpu::CAMath::Abs(getZ()) > 1e5) {
207 LOG(warning) <<
"Anomalous track, traget X:" << xk;
212 return propagateParamTo(xk, 0.);
217 if (gpu::CAMath::Abs(
f1) > constants::math::Almost1 || gpu::CAMath::Abs(
f2) > constants::math::Almost1) {
220 value_t r1 = gpu::CAMath::Sqrt((1.f -
f1) * (1.f +
f1));
221 if (gpu::CAMath::Abs(r1) < constants::math::Almost0) {
224 value_t r2 = gpu::CAMath::Sqrt((1.f -
f2) * (1.f +
f2));
225 if (gpu::CAMath::Abs(r2) < constants::math::Almost0) {
229 value_t step = (gpu::CAMath::Abs(x2r) < 0.05f) ? dx * gpu::CAMath::Abs(r2 +
f2 * dy2dx)
230 : 2.f * CAMath::ASin(0.5f * dx * gpu::CAMath::Sqrt(1.f + dy2dx * dy2dx) * crv) / crv;
231 step *= gpu::CAMath::Sqrt(1.f + getTgl() * getTgl());
234 std::array<value_t, 9> vecLab{0.f};
235 if (!getPosDirGlo(vecLab)) {
241 value_t bt = gpu::CAMath::Sqrt(bxy2);
242 value_t cosphi = 1.f, sinphi = 0.f;
243 if (bt > constants::math::Almost0) {
247 value_t bb = gpu::CAMath::Sqrt(bxy2 +
b[2] *
b[2]);
248 value_t costet = 1.f, sintet = 0.f;
249 if (
bb > constants::math::Almost0) {
253 std::array<value_t, 7>
vect{costet * cosphi * vecLab[0] + costet * sinphi * vecLab[1] - sintet * vecLab[2],
254 -sinphi * vecLab[0] + cosphi * vecLab[1],
255 sintet * cosphi * vecLab[0] + sintet * sinphi * vecLab[1] + costet * vecLab[2],
256 costet * cosphi * vecLab[3] + costet * sinphi * vecLab[4] - sintet * vecLab[5],
257 -sinphi * vecLab[3] + cosphi * vecLab[4],
258 sintet * cosphi * vecLab[3] + sintet * sinphi * vecLab[4] + costet * vecLab[5],
266 vecLab[0] = cosphi * costet *
vect[0] - sinphi *
vect[1] + cosphi * sintet *
vect[2];
267 vecLab[1] = sinphi * costet *
vect[0] + cosphi *
vect[1] + sinphi * sintet *
vect[2];
268 vecLab[2] = -sintet *
vect[0] + costet *
vect[2];
270 vecLab[3] = cosphi * costet *
vect[3] - sinphi *
vect[4] + cosphi * sintet *
vect[5];
271 vecLab[4] = sinphi * costet *
vect[3] + cosphi *
vect[4] + sinphi * sintet *
vect[5];
272 vecLab[5] = -sintet *
vect[3] + costet *
vect[5];
275 value_t sinalp = -vecLab[7], cosalp = vecLab[8];
276 value_t t = cosalp * vecLab[0] - sinalp * vecLab[1];
277 vecLab[1] = sinalp * vecLab[0] + cosalp * vecLab[1];
279 t = cosalp * vecLab[3] - sinalp * vecLab[4];
280 vecLab[4] = sinalp * vecLab[3] + cosalp * vecLab[4];
284 value_t x = vecLab[0],
y = vecLab[1],
z = vecLab[2];
285 if (gpu::CAMath::Abs(dx) > constants::math::Almost0) {
286 if (gpu::CAMath::Abs(vecLab[3]) < constants::math::Almost0) {
291 y += vecLab[4] / vecLab[3] * dx;
292 z += vecLab[5] / vecLab[3] * dx;
296 t = 1.f / gpu::CAMath::Sqrt(vecLab[3] * vecLab[3] + vecLab[4] * vecLab[4]);
300 mP[
kSnp] = vecLab[4] * t;
301 mP[
kTgl] = vecLab[5] * t;
302 mP[
kQ2Pt] = q * t / vecLab[6];
308template <
typename value_T>
317 if (gpu::CAMath::Abs(dx) < constants::math::Almost0) {
320 value_t crv = (gpu::CAMath::Abs(
b) < constants::math::Almost0) ? 0.f : getCurvature(
b);
323 if ((gpu::CAMath::Abs(
f1) > constants::math::Almost1) || (gpu::CAMath::Abs(
f2) > constants::math::Almost1)) {
326 value_t r1 = gpu::CAMath::Sqrt((1.f -
f1) * (1.f +
f1));
327 if (gpu::CAMath::Abs(r1) < constants::math::Almost0) {
330 value_t r2 = gpu::CAMath::Sqrt((1.f -
f2) * (1.f +
f2));
331 if (gpu::CAMath::Abs(r2) < constants::math::Almost0) {
334 double dy2dx = (
f1 +
f2) / (r1 + r2);
335 bool arcz = gpu::CAMath::Abs(x2r) > 0.05f;
345 auto arg = r1 *
f2 - r2 *
f1;
346 if (gpu::CAMath::Abs(arg) > constants::math::Almost1) {
349 value_t rot = CAMath::ASin(arg);
352 rot = constants::math::PI - rot;
354 rot = -constants::math::PI - rot;
357 mP[
kZ] += getTgl() / crv * rot;
359 mP[
kZ] += dx * (r2 +
f2 * dy2dx) * getTgl();
362 mP[
kY] += dx * dy2dx;
368template <
typename value_T>
372 value_t sn, cs, alp = getAlpha();
373 math_utils::detail::sincos(alp, sn, cs);
374 value_t x =
getX(),
y =
getY(), snp = getSnp(), csp = gpu::CAMath::Sqrt((1.f - snp) * (1.f + snp));
375 value_t xv = vtx.X() * cs + vtx.Y() * sn, yv = -vtx.X() * sn + vtx.Y() * cs, zv = vtx.Z();
379 value_t d = gpu::CAMath::Abs(
x * snp -
y * csp);
388 value_t tgfv = -(crv *
x - snp) / (crv *
y + csp);
389 sn = tgfv / gpu::CAMath::Sqrt(1.f + tgfv * tgfv);
390 cs = gpu::CAMath::Sqrt((1.f - sn) * (1.f + sn));
391 cs = (gpu::CAMath::Abs(tgfv) > constants::math::Almost0) ? sn / tgfv : constants::math::
Almost1;
393 x = xv * cs + yv * sn;
394 yv = -xv * sn + yv * cs;
398 alp += gpu::CAMath::ASin(sn);
399 if (!tmpT.rotateParam(alp) || !tmpT.propagateParamTo(xv,
b)) {
400#ifndef GPUCA_ALIGPUCODE
401 LOG(
debug) <<
"failed to propagate to alpha=" << alp <<
" X=" << xv <<
" for vertex "
402 << vtx.X() <<
' ' << vtx.Y() <<
' ' << vtx.Z() <<
" | Track is: " << tmpT.asString();
404 LOG(
debug) <<
"failed to propagate to alpha=" << alp <<
" X=" << xv <<
" for vertex " << vtx.X() <<
' ' << vtx.Y() <<
' ' << vtx.Z();
414 (*dca)[0] =
getY() - yv;
415 (*dca)[1] = getZ() - zv;
421template <
typename value_T>
430 if (gpu::CAMath::Abs(dx) < constants::math::Almost0) {
436 if ((gpu::CAMath::Abs(
f1) > constants::math::Almost1) || (gpu::CAMath::Abs(
f2) > constants::math::Almost1)) {
439 value_t r1 = gpu::CAMath::Sqrt((1.f -
f1) * (1.f +
f1));
440 if (gpu::CAMath::Abs(r1) < constants::math::Almost0) {
443 value_t r2 = gpu::CAMath::Sqrt((1.f -
f2) * (1.f +
f2));
444 if (gpu::CAMath::Abs(r2) < constants::math::Almost0) {
447 double dy2dx = (
f1 +
f2) / (r1 + r2);
449 if (gpu::CAMath::Abs(x2r) < 0.05f) {
450 z += dx * (r2 +
f2 * dy2dx) * getTgl();
463 rot = constants::math::PI - rot;
465 rot = -constants::math::PI - rot;
468 z += getTgl() / crv * rot;
474template <
typename value_T>
479 mAlpha += constants::math::PI;
480 math_utils::detail::bringToPMPi<value_t>(mAlpha);
489template <
typename value_T>
494 return getYZAt(xk,
b,
y,
z) ?
z : -9999.f;
498template <
typename value_T>
503 return getYZAt(xk,
b,
y,
z) ?
y : -9999.f;
507template <
typename value_T>
512 if (gpu::CAMath::Abs(dx) < constants::math::Almost0) {
515 value_t crv = (gpu::CAMath::Abs(
b) < constants::math::Almost0) ? 0.f : getCurvature(
b);
517 return mP[
kSnp] + x2r;
521template <
typename value_T>
526 if (gpu::CAMath::Abs(dx) < constants::math::Almost0) {
529 value_t crv = (gpu::CAMath::Abs(
b) < constants::math::Almost0) ? 0.f : getCurvature(
b);
533 if (gpu::CAMath::Abs(snp) < constants::math::Almost1) {
534 phi = gpu::CAMath::ASin(snp) + getAlpha();
535 math_utils::detail::bringTo02Pi<value_t>(phi);
541template <
typename value_T>
546 auto y = getYAt(xk,
b);
548 phi = gpu::CAMath::ATan2(
y, xk) + getAlpha();
549 math_utils::detail::bringTo02Pi<value_t>(phi);
555template <
typename value_T>
559 math_utils::detail::bringToPMPi<value_t>(
alpha);
561 math_utils::detail::sincos(
alpha - getAlpha(), sa, ca);
562 value_t snp = getSnp(), csp = gpu::CAMath::Sqrt((1.f - snp) * (1.f + snp));
564 if ((csp * ca + snp * sa) < 0.) {
568 value_t tmp = snp * ca - csp * sa;
569 if (gpu::CAMath::Abs(tmp) > constants::math::Almost1) {
570 LOGP(
debug,
"Rotation failed: new snp {:.2f}", tmp);
575 value_t crv = (gpu::CAMath::Abs(
b) < constants::math::Almost0) ? 0.f : getCurvature(
b);
580#ifndef GPUCA_ALIGPUCODE
582template <
typename value_T>
586 return fmt::format(
"X:{:+.4e} Alp:{:+.3e} Par: {:+.4e} {:+.4e} {:+.4e} {:+.4e} {:+.4e} |Q|:{:d} {:s}",
587 getX(), getAlpha(),
getY(), getZ(), getSnp(), getTgl(), getQ2Pt(), getAbsCharge(), getPID().
getName());
591template <
typename value_T>
595 auto _Alpha = getAlpha();
598 auto _Snp = getSnp();
599 auto _Tgl = getTgl();
600 float _Q2Pt = getQ2Pt();
601 float _AbsCharge = getAbsCharge();
603 return fmt::format(
"X:{:x} Alp:{:x} Par: {:x} {:x} {:x} {:x} {:x} |Q|:{:x} {:s}\n",
604 reinterpret_cast<const unsigned int&
>(_X),
605 reinterpret_cast<const unsigned int&
>(_Alpha),
606 reinterpret_cast<const unsigned int&
>(_Y),
607 reinterpret_cast<const unsigned int&
>(_Z),
608 reinterpret_cast<const unsigned int&
>(_Snp),
609 reinterpret_cast<const unsigned int&
>(_Tgl),
610 reinterpret_cast<const unsigned int&
>(_Q2Pt),
611 reinterpret_cast<const unsigned int&
>(_AbsCharge),
617template <
typename value_T>
621#ifndef GPUCA_ALIGPUCODE
623#elif !defined(GPUCA_GPUCODE_DEVICE) || (!defined(__OPENCL__) && defined(GPUCA_GPU_DEBUG_PRINT))
624 printf(
"X:%+.4e Alp:%+.3e Par: %+.4e %+.4e %+.4e %+.4e %+.4e |Q|:%d %s\n",
625 getX(), getAlpha(),
getY(), getZ(), getSnp(), getTgl(), getQ2Pt(), getAbsCharge(), getPID().
getName());
630template <
typename value_T>
634#ifndef GPUCA_ALIGPUCODE
635 printf(
"%s\n", asStringHexadecimal().c_str());
636#elif !defined(GPUCA_GPUCODE_DEVICE) || (!defined(__OPENCL__) && defined(GPUCA_GPU_DEBUG_PRINT))
637 printf(
"X:%x Alp:%x Par: %x %x %x %x %x |Q|:%x %s\n",
638 gpu::CAMath::Float2UIntReint(
getX()),
639 gpu::CAMath::Float2UIntReint(getAlpha()),
640 gpu::CAMath::Float2UIntReint(
getY()),
641 gpu::CAMath::Float2UIntReint(getZ()),
642 gpu::CAMath::Float2UIntReint(getSnp()),
643 gpu::CAMath::Float2UIntReint(getTgl()),
644 gpu::CAMath::Float2UIntReint(getQ2Pt()),
645 gpu::CAMath::Float2UIntReint(getAbsCharge()),
651template <
typename value_T>
662 const double fy = mP[0], sn = mP[2];
665 if (gpu::CAMath::Abs(getSnp()) > constants::math::Almost1) {
668 auto crv = getCurvature(bz);
669 while (gpu::CAMath::Abs(crv) > constants::math::Almost0) {
672 getCircleParamsLoc(bz, circle);
673 if (circle.rC == 0.) {
677 value_t r0 = gpu::CAMath::Sqrt(circle.getCenterD2());
678 if (r0 <= constants::math::Almost0) {
681 double tR2r0 = 1.,
g = 0., tmp = 0.;
682 if (gpu::CAMath::Abs(circle.rC - r0) > kEps) {
683 tR2r0 = circle.rC / r0;
684 g = 0.5f * (
r *
r / (r0 * circle.rC) - tR2r0 - 1.f / tR2r0);
685 tmp = 1.f +
g * tR2r0;
688 g = 0.5 *
r *
r / (r0 * circle.rC) - 1.;
689 tmp = 0.5 *
r *
r / (r0 * r0);
691 auto det = (1. -
g) * (1. +
g);
695 det = gpu::CAMath::Sqrt(det);
702 auto y = circle.yC * tmp;
703 if (gpu::CAMath::Abs(circle.yC) > constants::math::Almost0) {
704 auto dfx = tR2r0 * gpu::CAMath::Abs(circle.yC) * det;
705 auto dfy = tR2r0 * circle.xC * (circle.yC > 0. ? det : -det);
707 auto delta = (
x - mX) * dfx - (
y - fy) * dfy;
708 x += delta < 0. ? dfx : -dfx;
715 if (gpu::CAMath::Abs(dfeps) < kEps && gpu::CAMath::Abs(mX * mX + fy * fy -
r *
r) < kEps) {
723 }
else if (dxm < -kEps) {
733 if (gpu::CAMath::Abs(dfeps) < kEps && gpu::CAMath::Abs(mX * mX + fy * fy -
r *
r) < kEps) {
755 if (gpu::CAMath::Abs(sn) >= constants::math::Almost1) {
756 double det = (
r - mX) * (
r + mX);
764 det = gpu::CAMath::Sqrt(det);
780 }
else if (fy > det) {
784 }
else if (gpu::CAMath::Abs(sn) <= constants::math::Almost0) {
785 double det = (
r - fy) * (
r + fy);
789 det = gpu::CAMath::Sqrt(det);
791 x = mX > 0. ? det : -det;
797 x = (mX < -det) ? -det : det;
803 x = mX > det ? det : -det;
807 auto cs = gpu::CAMath::Sqrt((1. - sn) * (1. + sn));
808 auto xsyc = mX * sn - fy * cs;
809 auto det = (
r - xsyc) * (
r + xsyc);
813 det = gpu::CAMath::Sqrt(det);
814 auto xcys = mX * cs + fy * sn;
817 t += t > 0. ? -det : det;
818 }
else if (dir > 0) {
838template <
typename value_T>
849 constexpr value_t kMinP = 0.01f;
851 auto m = getPID().getMass();
852 if (
m > 0 && xrho != 0.f) {
855 value_t csp2 = (1.f - getSnp()) * (1.f + getSnp());
856 value_t cst2I = (1.f + getTgl() * getTgl());
860 int charge2 = getAbsCharge() * getAbsCharge();
861 value_t p = getP(),
p0 =
p,
p2 =
p *
p, e2 =
p2 + getPID().getMass2(), massInv = 1. /
m,
bg =
p * massInv;
862 value_t e = gpu::CAMath::Sqrt(e2), ekin = e -
m,
dedx = getdEdxBBOpt(
bg);
863#ifdef _BB_NONCONST_CORR_
877#ifdef _BB_NONCONST_CORR_
878 dedxDer = getBetheBlochSolidDerivativeApprox(dedx1,
bg);
885#ifdef _BB_NONCONST_CORR_
890 auto corrC = (gpu::CAMath::Exp(dedxDer) - 1.) / dedxDer;
896 p = gpu::CAMath::Sqrt(e * e - getPID().getMass2());
903#ifdef _BB_NONCONST_CORR_
904 dedxDer = getBetheBlochSolidDerivativeApprox(
dedx,
bg);
908#ifdef _BB_NONCONST_CORR_
919 setQ2Pt(getQ2Pt() * p0 / p);
926template <
typename value_T>
931 math_utils::detail::sincos(-mAlpha, sn, cs);
932 value_t sn2 = sn * sn, cs2 = cs * cs, sncs = sn * cs;
933 value_t dsxysncs = 2. *
v.getSigmaXY() * sncs;
934 return {{
v.getX() * sn +
v.getY() * cs,
v.getZ()},
935 {
v.getSigmaX2() * sn2 + dsxysncs +
v.getSigmaY2() * cs2, (sn + cs) *
v.getSigmaYZ(),
v.getSigmaZ2()}};
939template <
typename value_T>
944 return ttmp.propagateParamToDCA({xmv, ymv, zmv},
b, &dca) ? dca[0] : -9999.;
948template <
typename value_T>
953 return ttmp.propagateParamToDCA({xmv, ymv, zmv},
b, &dca) ? dca[1] : -9999.;
958#if !defined(GPUCA_GPUCODE) || defined(GPUCA_GPUCODE_DEVICE)
std::string getName(const TDataMember *dm, int index, int size)
std::string asString(TDataMember const &dm, char *pointer)
std::string asStringHexadecimal()
std::string asString() const
GLfloat GLfloat GLfloat alpha
GLboolean GLboolean GLboolean b
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLdouble GLdouble GLdouble z
typename trackParam_t::dim3_t dim3_t
typename trackParam_t::dim2_t dim2_t
typename trackParam_t::value_t value_t
double * getX(double *xyDxy, int N)
double * getY(double *xyDxy, int N)
value_T std::array< value_T, 7 > & vect
GPUd() value_T BetheBlochSolid(value_T bg
constexpr float DefaultDCA
constexpr int MaxELossIter
constexpr float ELoss2EKinThreshInv
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"