8 #include "GaudiKernel/SystemOfUnits.h"
54 for(
int i=0;
i<5;
i++) {
63 m_track.emplace_front(
nullptr,
nullptr,
nullptr, 0, -1);
66 m_track.emplace_back(
nullptr,
nullptr,
nullptr, 0, -1);
113 memcpy(&tmpX[0], &
m_Xk[0],
sizeof(tmpX));
115 for(
int i=0;
i<5;
i++) {
121 memcpy(&tmpG[0][0], &
m_Gk[0][0],
sizeof(tmpG));
125 for(
int i=0;
i<5;
i++) {
126 for(
int j=0;j<5;j++) {
127 m_Gk[
i+5][j+5] = tmpG[
i][j];
128 m_Gk[
i][j] = tmpG[
i+5][j+5];
129 m_Gk[
i][j+5] = tmpG[
i+5][j];
130 m_Gk[
i+5][j] = tmpG[
i][j+5];
137 for(
int i=0;
i<4;
i++) std::cout<<
m_Xk[
i]<<
" ";
141 std::cout<<
"Covariance at last point:"<<std::endl;
143 for(
int i=0;
i<5;
i++) {
144 for(
int j=0;j<5;j++) std::cout<<
m_Gk[
i][j]<<
" ";
145 std::cout<<std::endl;
149 for(
int i=0;
i<4;
i++) std::cout<<
m_Xk[
i+5]<<
" ";
151 std::cout<<std::endl;
153 std::cout<<
"Covariance at the first point:"<<std::endl;
155 for(
int i=0;
i<5;
i++) {
156 for(
int j=0;j<5;j++) std::cout<<
m_Gk[
i+5][j+5]<<
" ";
157 std::cout<<std::endl;
166 const std::string&
n,
169 declareInterface< ITrigInDetTrackFollowingTool >(
this );
178 return StatusCode::SUCCESS;
182 return StatusCode::SUCCESS;
188 double cluster_cov[2];
196 cluster_cov[1] = pPRD->
width().
z();
197 for(
int i=0;
i<2;
i++) cluster_cov[
i] *= cluster_cov[
i]/12.0;
200 double covsum[2][2] = {{ets.
m_Gk[0][0] + cluster_cov[0], ets.
m_Gk[0][1]}, {ets.
m_Gk[0][1], ets.
m_Gk[1][1] + cluster_cov[1]}};
202 double detr = 1/(covsum[0][0]*covsum[1][1] - covsum[0][1]*covsum[1][0]);
204 invcov[0] = detr*covsum[1][1];
205 invcov[1] = -detr*covsum[1][0];
206 invcov[2] = detr*covsum[0][0];
211 return (resid[0]*(resid[0]*invcov[0] + resid[1]*invcov[1]) + resid[1]*(resid[0]*invcov[1] + resid[1]*invcov[2]));
228 invcov = 1/(ets.
m_Gk[0][0] + covX);
244 sincos(
beta, &sinB, &cosB);
246 resid = (meas_x - ets.
m_Xk[0])*cosB + (meas_y - ets.
m_Xk[1])*sinB;
251 double track_cov = cosB*cosB*(ets.
m_Gk[0][0]+e00) + 2*cosB*sinB*(ets.
m_Gk[0][1]+e01) + sinB*sinB*(ets.
m_Gk[1][1]+e11);
253 invcov = 1/track_cov;
256 return (resid * resid * invcov);
264 if(pColl ==
nullptr && pInputHit ==
nullptr)
return nullptr;
268 if(pColl !=
nullptr) {
272 for(
const auto pPRD : *pColl) {
274 double dchi2 =
processHit(pPRD, resid, invcov, ets);
276 if(dchi2 < bestChi2Dist) {
278 bestChi2Dist = dchi2;
283 if(bestHit ==
nullptr)
return bestHit;
287 double dchi2 =
processHit(pPRD, resid, invcov, ets);
291 for(
int i=0;
i<10;
i++) {
292 CHT[
i][0] = ets.
m_Gk[
i][0];
293 CHT[
i][1] = ets.
m_Gk[
i][1];
297 double V[2][2] = {{invcov[0], invcov[1]}, {invcov[1], invcov[2]}};
299 for(
int i=0;
i<10;
i++)
300 for(
int j=0;j<2;j++)
Gain[
i][j] = CHT[
i][0]*V[0][j] + CHT[
i][1]*V[1][j];
302 for(
int i=0;
i<10;
i++) {
305 for(
int j=0;j<=
i;j++) {
311 ets.
AddHit(pPRD, dchi2, 2);
320 if(pColl ==
nullptr && pInputHit ==
nullptr)
return nullptr;
321 double resid, invcov;
324 if(pColl && !pColl->empty()) {
328 for(
const auto pPRD : *pColl) {
330 double dchi2 =
processHit(pPRD, shape, resid, invcov,
H, ets);
332 if(dchi2 < bestChi2Dist) {
334 bestChi2Dist = dchi2;
339 if(bestHit ==
nullptr)
return bestHit;
347 dchi2 =
processHit(pPRD, shape, resid, invcov,
H, ets);
349 double CHT[10],
Gain[10];
351 for(
int i=0;
i<10;
i++) {
353 Gain[
i] = CHT[
i] * invcov;
356 for(
int i=0;
i<10;
i++) {
358 for(
int j=0;j<=
i;j++) {
368 double stripHalfLength = std::sqrt(3*covY);
370 double dY = ets.
m_Xk[1] - stripCentre;
372 if(dY > stripHalfLength) {
373 ets.
m_Xk[1] = stripCentre + stripHalfLength;
376 if(dY < -stripHalfLength) {
377 ets.
m_Xk[1] = stripCentre - stripHalfLength;
382 dchi2 =
processHit(pPRD, shape, resid, invcov,
H, ets);
384 double CHT[10],
Gain[10];
386 for(
int i=0;
i<10;
i++) {
388 Gain[
i] = CHT[
i] * invcov;
391 for(
int i=0;
i<10;
i++) {
393 for(
int j=0;j<=
i;j++) {
400 ets.
AddHit(pPRD, dchi2, 1);
417 double dsp[2] = {
pe[0]-
pb[0],
pe[1]-
pb[1]};
418 double Lsp = std::sqrt(dsp[0]*dsp[0] + dsp[1]*dsp[1]);
419 double cosA = dsp[0]/Lsp;
420 double sinA = dsp[1]/Lsp;
423 double dxm = pm[0] -
pb[0];
424 double dym = pm[1] -
pb[1];
426 double x1 = dxm*cosA + dym*sinA;
427 double m1 = -dxm*sinA + dym*cosA;
429 double a_parab = -2*
m1/(
x1*(Lsp-
x1));
430 double b_parab = -0.5*a_parab*Lsp;
432 double Rx[3] = {0,b_parab,a_parab};
433 double Ry[2] = {
pb[2],tau0};
438 memset(&Cx[0][0],0,
sizeof(Cx));
443 memset(&Cy[0][0],0,
sizeof(Cy));
454 memset(&
Fx[0][0],0,
sizeof(
Fx));
459 memset(&
Fy[0][0],0,
sizeof(
Fy));
466 for(
const auto& sp : seed) {
470 double pk[3] = {sp->globalPosition().x(), sp->globalPosition().y(), sp->globalPosition().z()};
472 double dx = pk[0] -
pb[0];
473 double dy = pk[1] -
pb[1];
475 double dist =
dx*cosA +
dy*sinA;
476 double measx =-
dx*sinA +
dy*cosA;
477 double measy = pk[2];
483 double rk = sp->globalPosition().perp();
497 double Rex[3] = {Rx[0], Rx[1], Rx[2]};
499 Rex[0] +=
Fx[0][1]*Rx[1] +
Fx[0][2]*Rx[2];
500 Rex[1] +=
Fx[1][2]*Rx[2];
502 double Cex[3][3], CFT[3][3];
504 for(
int i=0;
i<3;
i++) {
505 for(
int j=0;j<3;j++) {
507 for(
int m=0;
m<3;
m++) CFT[
i][j] += Cx[
i][
m]*
Fx[j][
m];
510 for(
int i=0;
i<3;
i++) {
511 for(
int j=0;j<3;j++) {
513 for(
int m=0;
m<3;
m++) Cex[
i][j] +=
Fx[
i][
m]*CFT[
m][j];
517 double Rey[2] = {Ry[0], Ry[1]};
519 Rey[0] +=
Fy[0][1]*Ry[1];
523 for(
int i=0;
i<2;
i++) {
524 for(
int j=0;j<2;j++) {
526 for(
int m=0;
m<2;
m++) CFT[
i][j] += Cy[
i][
m]*
Fy[j][
m];
529 for(
int i=0;
i<2;
i++) {
530 for(
int j=0;j<2;j++) {
532 for(
int m=0;
m<2;
m++) Cey[
i][j] +=
Fy[
i][
m]*CFT[
m][j];
538 double CHTx[3] = {Cex[0][0], Cex[0][1], Cex[0][2]};
539 double Dx = 1/(Cex[0][0] + sigma_x2);
541 double resid = measx - Rex[0];
543 double Kx[3] = {Dx*CHTx[0], Dx*CHTx[1], Dx*CHTx[2]};
545 for(
int i=0;
i<3;
i++) Rx[
i] = Rex[
i] + Kx[
i]*resid;
546 for(
int i=0;
i<3;
i++) {
547 for(
int j=0;j<3;j++) {
548 Cx[
i][j] = Cex[
i][j] - Kx[
i]*CHTx[j];
552 double CHTy[2] = {Cey[0][0], Cey[0][1]};
553 double Dy = 1/(Cey[0][0] + sigma_y2);
555 resid = measy - Rey[0];
557 double Ky[2] = {Dy*CHTy[0], Dy*CHTy[1]};
559 for(
int i=0;
i<2;
i++) Ry[
i] = Rey[
i] + Ky[
i]*resid;
560 for(
int i=0;
i<2;
i++) {
561 for(
int j=0;j<2;j++) {
562 Cy[
i][j] = Cey[
i][j] - Ky[
i]*CHTy[j];
579 if(thePlane ==
nullptr)
return nullptr;
583 P0[2] = std::atan2(sinA - Rx[1]*cosA, cosA - Rx[1]*sinA);
584 P0[3] = std::atan2(1, Ry[1]);
585 double coeff = 1.0/(300.0*B0[2]*std::sqrt(1+Ry[1]*Ry[1]));
586 P0[4] = -Rx[2]*coeff;
587 P0[5] = Cx[2][2]*coeff*coeff;
589 return std::make_unique<TrigFTF_ExtendedTrackState>(P0, thePlane);
600 if (!fieldCondObj.isValid()) {
605 fieldCondObj->getInitializedCache (fieldCache);
631 std::vector<const Trk::PrepRawData*> assignedHits(
nModules,
nullptr);
633 std::vector<int> moduleStatus(
nModules, 0);
635 unsigned int seedSize = seed.size();
637 std::vector<unsigned int> seedHashes(seedSize,0);
639 for(
unsigned int spIdx=0;spIdx<seedSize;spIdx++) {
646 int nUnassigned = seedSize;
648 int startModuleIdx = -1;
650 for(
int moduleIdx = 0;moduleIdx<
nModules;moduleIdx++) {
651 unsigned int hash = road.at(moduleIdx)->identifyHash();
652 for(
unsigned int spIdx=0;spIdx<seedSize;spIdx++) {
653 if(seedHashes[spIdx] !=
hash)
continue;
655 assignedHits[moduleIdx] = seed.at(spIdx)->clusterList().first;
656 moduleStatus[moduleIdx] = 1;
658 startModuleIdx = moduleIdx;
662 if(nUnassigned == 0)
break;
665 if(nUnassigned > 0)
return nullptr;
667 std::unique_ptr<TrigFTF_ExtendedTrackState> initialState =
fitTheSeed(seed, fieldCache);
669 if(initialState ==
nullptr)
return nullptr;
675 std::vector<int> moduleIndexSequence(
nModules);
679 for(
int moduleIdx = startModuleIdx + 1;moduleIdx<
nModules;moduleIdx++, modCounter++) {
680 moduleIndexSequence[modCounter] = moduleIdx;
682 for(
int moduleIdx = startModuleIdx;moduleIdx>=0;moduleIdx--, modCounter++) {
683 moduleIndexSequence[modCounter] = moduleIdx;
688 for(
auto const moduleIdx : moduleIndexSequence) {
694 if(moduleStatus[moduleIdx] < 0)
continue;
702 if(moduleIdx == startModuleIdx) {
709 if(pPRD ==
nullptr) {
713 moduleStatus[moduleIdx] = -2;
722 moduleStatus[moduleIdx] = -2;
723 if(pPRD !=
nullptr) {
734 unsigned int nHits = 0;
743 if(pPRD ==
nullptr) {
744 if(p_pixcontainer !=
nullptr) {
745 clustersOnElement = (*p_pixcontainer).indexFindPtr(moduleHash);
746 if(clustersOnElement !=
nullptr) {
747 nHits = clustersOnElement->size();
766 if(pPRD ==
nullptr) {
767 if(p_sctcontainer !=
nullptr) {
768 clustersOnElement = (*p_sctcontainer).indexFindPtr(moduleHash);
769 if(clustersOnElement !=
nullptr) {
770 nHits = clustersOnElement->size();
787 moduleStatus[moduleIdx] = -3;
791 if(pPRD ==
nullptr) {
792 if(selectedHit ==
nullptr) {
794 moduleStatus[moduleIdx] = -4;
797 assignedHits[moduleIdx] = selectedHit;
798 moduleStatus[moduleIdx] = de->
isPixel() ? 2 : 3;
807 double chi2tot = theState.
m_chi2;
823 int ndoftot = theState.
m_ndof;
829 double z0 = theState.
m_Xk[1];
830 double d0 = theState.
m_Xk[0];
832 bool bad_cov =
false;
836 for(
int i=0;
i<5;
i++) {
837 for(
int j=0;j<=
i;j++) {
838 double c = theState.
m_Gk[
i][j];
839 if (
i == j &&
c < 0) {
841 ATH_MSG_DEBUG(
"REGTEST: cov(" <<
i <<
"," <<
i <<
") =" <<
c <<
" < 0, reject track");
844 cov.fillSymmetric(
i,j,
c);
848 if((ndoftot<0) || (fabs(
pt)<100.0) || (std::isnan(
pt)) || bad_cov) {
849 ATH_MSG_DEBUG(
"Track following failed - possibly floating point problem");
857 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> perType;
860 auto pParVec = std::make_unique<Trk::TrackStates>();
862 pParVec->reserve(50);
865 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> rioType(0);
873 if(pPRD ==
nullptr)
continue;
881 if(pPS==
nullptr)
continue;
891 std::unique_ptr<Trk::MeasurementBase> pRIO{};
896 pRIO = std::make_unique<InDet::PixelClusterOnTrack>(pPixel, std::move(locPos),
Amg::MatrixX(
cov),
903 pRIO = std::make_unique<InDet::SCT_ClusterOnTrack>(pStrip, std::move(locPos),
Amg::MatrixX(
cov),
911 for(
int i=0;
i<5;
i++) {
912 for(
int j=0;j<=
i;j++) {
913 pM.fillSymmetric(
i,j,
ha.m_Ck[
idx++]);
923 pParVec->push_back(pTSS);
926 auto pFQ = std::make_unique<Trk::FitQuality>(chi2tot, ndoftot);
942 memcpy(&Re[0], &ETS.
m_Xk[0],
sizeof(Re));
947 memset(&P[0],0,
sizeof(P));
950 double Ax[3] = {Trf(0,0),Trf(1,0),Trf(2,0)};
951 double Ay[3] = {Trf(0,1),Trf(1,1),Trf(2,1)};
954 gP[0] = Trf(0,3) + Ax[0]*Re[0] + Ay[0]*Re[1];
955 gP[1] = Trf(1,3) + Ax[1]*Re[0] + Ay[1]*Re[1];
956 gP[2] = Trf(2,3) + Ax[2]*Re[0] + Ay[2]*Re[1];
961 sincos(Re[2], &sinf, &cosf);
962 sincos(Re[3], &sint, &
cost);
964 double gV[3] = {cosf*sint, sinf*sint,
cost};
966 memset(&Jm[0],0,
sizeof(Jm));
973 for(
int i=0;
i<3;
i++) {
992 memset(&J[0],0,
sizeof(J));
995 memset(&BigP[0],0,
sizeof(BigP));
997 for(
int i=0;
i<7;
i++) BigP[
i] = P[
i];
998 for(
int i=0;
i<35;
i++) BigP[
i+7] = Jm[
i];
1008 const double* Az = Trf.matrix().col(2).data();
1012 double lV = Az[0]*gV[0] + Az[1]*gV[1] + Az[2]*gV[2];
1014 double xOverX0 = 0.0;
1026 double radLength = xOverX0/std::fabs(lV);
1028 double sigmaMS = 13.6 * std::fabs(Re[4]) * std::sqrt(radLength) * (1.0 + 0.038 *
std::log(radLength));
1029 double s2 = sigmaMS * sigmaMS;
1030 double a = 1.0 / sint;
1035 ETS.
m_Gk[2][2] +=
s2 * a2;
1042 ETS.
m_Gk[4][4] += Re[4] * Re[4] * radLength * (0.415 - 0.744 * radLength);
1048 memset(&Be[0][0],0,
sizeof(Be));
1050 for(
int i=0;
i<4;
i++) {
1051 for(
int j=0;j<5;j++) {
1052 for(
int k=0;
k<5;
k++) Be[
i][j] += J[
k+
i*5]*ETS.
m_Gk[
k][j+5];
1055 for(
int j=0;j<5;j++) {
1056 Be[4][j] = ETS.
m_Gk[4][j+5];
1062 memset(&JC[0][0],0,
sizeof(JC));
1063 memset(&Ce[0][0],0,
sizeof(Ce));
1065 for(
int i=0;
i<4;
i++) {
1066 for(
int j=0;j<5;j++) {
1067 for(
int k=0;
k<5;
k++) JC[
i][j] += J[
k+
i*5]*ETS.
m_Gk[
k][j];
1070 for(
int j=0;j<5;j++) {
1071 JC[4][j] = ETS.
m_Gk[4][j];
1074 for(
int i=0;
i<5;
i++) {
1075 for(
int j=0;j<=
i;j++) {
1077 for(
int k=0;
k<5;
k++) Ce[
i][j] += JC[
i][
k]*J[
k+j*5];
1078 Ce[j][
i] = Ce[
i][j];
1081 Ce[
i][4] = Ce[4][
i] = JC[
i][4];
1090 for(
int i=0;
i<5;
i++) {
1092 for(
int j=0;j<5;j++) {
1093 ETS.
m_Gk[
i][j] = Ce[
i][j];
1094 ETS.
m_Gk[
i][j+5] = Be[
i][j];
1095 ETS.
m_Gk[j+5][
i] = Be[
i][j];
1103 const double C = 299.9975;
1104 const double minStep = 100.0;
1105 const double bound_tol = 0.2;
1109 memcpy(&Re[0], &Rk[0],
sizeof(Re));
1113 double Ax[3] = {Trf(0,0),Trf(1,0),Trf(2,0)};
1115 double Ay[3] = {Trf(0,1),Trf(1,1),Trf(2,1)};
1119 gP[0] = Trf(0,3) + Ax[0]*Re[0] + Ay[0]*Re[1];
1120 gP[1] = Trf(1,3) + Ax[1]*Re[0] + Ay[1]*Re[1];
1121 gP[2] = Trf(2,3) + Ax[2]*Re[0] + Ay[2]*Re[1];
1126 sincos(Re[2], &sinf, &cosf);
1127 sincos(Re[3], &sint, &
cost);
1129 double gV[3] = {cosf*sint, sinf*sint,
cost};
1134 double D[4] = {normal[0], normal[1], normal[2], 0.0};
1136 for(
int i=0;
i<3;
i++) D[3] += -normal[
i]*center[
i];
1138 double CQ =
C*Re[4];
1144 double c = D[0]*gP[0] + D[1]*gP[1] + D[2]*gP[2] + D[3];
1145 double b = D[0]*gV[0] + D[1]*gV[1] + D[2]*gV[2];
1146 double a = 0.5*CQ*(gB[0]*(D[1]*gV[2]-D[2]*gV[1]) + gB[1]*(D[2]*gV[0]-D[0]*gV[2]) + gB[2]*(D[0]*gV[1]-D[1]*gV[0]));
1150 bool useExpansion = std::fabs(
ratio)<0.1;
1160 double discr =
b*
b-4.0*
a*
c;
1166 int signb = (
b<0.0)?-1:1;
1167 sl = (-
b + signb*std::sqrt(discr))/(2*
a);
1172 if(std::fabs(sl)>=minStep) {
1173 nStepMax = (
int)(std::fabs(sl)/minStep)+1;
1176 if((nStepMax<0)||(nStepMax>100)) {
1181 double Ac = 0.5*sl*Av;
1182 double DVx = gV[1]*gB[2] - gV[2]*gB[1];
1183 double DVy = gV[2]*gB[0] - gV[0]*gB[2];
1184 double DVz = gV[0]*gB[1] - gV[1]*gB[0];
1186 double E[3] = {gP[0]+gV[0]*sl+Ac*DVx, gP[1]+gV[1]*sl+Ac*DVy, gP[2]+gV[2]*sl+Ac*DVz};
1189 for(
int i=0;
i<3;
i++) gP[
i] =
E[
i];
1196 double inv_step = 1/sl;
1198 double dBds[3] = {inv_step*(gBe[0]-gB[0]),inv_step*(gBe[1]-gB[1]),inv_step*(gBe[2]-gB[2])};
1200 int nStep = nStepMax;
1204 c = D[0]*gP[0] + D[1]*gP[1] + D[2]*gP[2] + D[3];
1205 b = D[0]*gV[0] + D[1]*gV[1] + D[2]*gV[2];
1206 a = 0.5*CQ*(gB[0]*(D[1]*gV[2]-D[2]*gV[1])+gB[1]*(D[2]*gV[0]-D[0]*gV[2])+gB[2]*(D[0]*gV[1]-D[1]*gV[0]));
1209 useExpansion = std::fabs(
ratio) < 0.1;
1216 double discr=
b*
b-4.0*
a*
c;
1220 int signb = (
b<0.0)?-1:1;
1221 sl = (-
b+signb*std::sqrt(discr))/(2*
a);
1224 double ds = sl/nStep;
1228 DVx = gV[1]*gB[2] - gV[2]*gB[1];
1229 DVy = gV[2]*gB[0] - gV[0]*gB[2];
1230 DVz = gV[0]*gB[1] - gV[1]*gB[0];
1232 E[0] = gP[0] + gV[0]*
ds + Ac*DVx;
1233 E[1] = gP[1] + gV[1]*
ds + Ac*DVy;
1234 E[2] = gP[2] + gV[2]*
ds + Ac*DVz;
1238 V[0] = gV[0] + Av*DVx;
1239 V[1] = gV[1] + Av*DVy;
1240 V[2] = gV[2] + Av*DVz;
1242 for(
int i=0;
i<3;
i++) {
1243 gV[
i] = V[
i];gP[
i] =
E[
i];
1246 for(
int i=0;
i<3;
i++) gB[
i] += dBds[
i]*
ds;
1256 const double* Ax2 = Trf2.matrix().col(0).data();
1257 const double* Ay2 = Trf2.matrix().col(1).data();
1259 const double d[3] = { gP[0] - Trf2(0, 3), gP[1] - Trf2(1, 3), gP[2] - Trf2(2, 3) };
1261 double locX =
d[0] * Ax2[0] +
d[1] * Ax2[1] +
d[2] * Ax2[2];
1262 double locY =
d[0] * Ay2[0] +
d[1] * Ay2[1] +
d[2] * Ay2[2];
1265 if(!pDE)
return false;
1281 Step = -(P[0]*P[3] + P[1]*P[4])/(1 - P[5]*P[5]);
1290 for(
int i=0;
i<3;
i++) D += -normal[
i]*center[
i];
1295 for(
int i=0;
i<3;
i++) {
1296 a += normal[
i]*P[
i+3];
1297 Sum += normal[
i]*P[
i];
1299 if(
a==0.0)
return Step;
1308 const double coeff = 299.7;
1309 const double min_step = 3.0;
1310 const double const_field_step = 30.0;
1311 const double maxPath = 3000.0;
1312 const double minQp = 0.01;
1313 const double minRad = 300.0;
1315 const int maxIter = 10;
1317 double exStep = 0.0;
1319 if(std::fabs(P[6]) > minQp)
return -1;
1323 if(Step > 1e7)
return -2;
1325 double absStep = fabs(Step);
1327 if(absStep <= min_step) {
1328 for(
int i=0;
i<3;
i++) P[
i] += Step*P[
i+3];
1333 if(fabs(P[6]*Step) > minRad) {
1334 Step = (Step > 0.0 ? minRad : -minRad)/fabs(P[6]);
1343 memcpy(&
Y[0], P,
sizeof(
Y));
1349 for(
int i=0;
i<3;
i++)
B[
i] *= coeff;
1352 if(absStep > fabs(exStep))
1356 for(
int iter=0;iter<maxIter;iter++) {
1358 bool useConstField = fabs(Step) < const_field_step;
1360 if(!useConstField) {
1362 for(
int i=0;
i<3;
i++)
B[
i] *= coeff;
1365 double B2[3], B3[3];
1373 double H3mom =
mom*H3;
1374 double H23mom =
mom*H23;
1375 double H4mom =
mom*H4;
1376 double H34mom =
mom*H34;
1386 for(
int i=0;
i<3;
i++) Y2[
i] =
Y[
i] + H3*
Y[
i+3];
1387 for(
int i=3;
i<6;
i++) Y2[
i] =
Y[
i] + H3mom*YB[
i-3];
1396 for(
int i=0;
i<3;
i++) B2[
i] *= coeff;
1404 for(
int i=0;
i<3;
i++) Y3[
i] =
Y[
i] + H23*Y2[
i+3];
1405 for(
int i=3;
i<6;
i++) Y3[
i] =
Y[
i] + H23mom*YB2[
i-3];
1414 for(
int i=0;
i<3;
i++) B3[
i] *= coeff;
1420 for(
int i=3;
i<6;
i++) Y1[
i-3] =
Y[
i-3] + H4*(
Y[
i] + 3*Y3[
i]);
1421 for(
int i=0;
i<3;
i++) Y1[
i+3] =
Y[
i+3] + H4mom*(YB[
i] + 3*YB3[
i]);
1423 if(fabs(Y1[5])>1)
return -10;
1429 double J1C[9], L2C[9], J2C[9], L3C[9], J3C[9];
1435 if(!useConstField) {
1436 for(
int i=0;
i<3;
i++) CqBH3[
i] = H3mom*
B[
i];
1437 for(
int i=0;
i<3;
i++) CqB2H23[
i] = H23mom*B2[
i];
1438 for(
int i=0;
i<3;
i++) CqB3H34[
i] = H34mom*B3[
i];
1441 for(
int i=0;
i<3;
i++) CqBH3[
i] = H3mom*
B[
i];
1442 for(
int i=0;
i<3;
i++) CqB2H23[
i] = H23mom*
B[
i];
1443 for(
int i=0;
i<3;
i++) CqB3H34[
i] = H34mom*
B[
i];
1454 L2C[0] = J[17] + J1C[0];
1455 L2C[1] = J[18] + J1C[1];
1456 L2C[2] = J[19] + J1C[2];
1458 L2C[3] = J[24] + J1C[3];
1459 L2C[4] = J[25] + J1C[4];
1460 L2C[5] = J[26] + J1C[5];
1462 L2C[6] = J[31] + J1C[6];
1463 L2C[7] = J[32] + J1C[7];
1464 L2C[8] = J[33] + J1C[8];
1470 J2C[6] += H23*YB2[0];
1471 J2C[7] += H23*YB2[1];
1472 J2C[8] += H23*YB2[2];
1474 L3C[0] = J[17] + J2C[0];
1475 L3C[1] = J[18] + J2C[1];
1476 L3C[2] = J[19] + J2C[2];
1478 L3C[3] = J[24] + J2C[3];
1479 L3C[4] = J[25] + J2C[4];
1480 L3C[5] = J[26] + J2C[5];
1482 L3C[6] = J[31] + J2C[6];
1483 L3C[7] = J[32] + J2C[7];
1484 L3C[8] = J[33] + J2C[8];
1490 J3C[6] += H34*YB3[0];
1491 J3C[7] += H34*YB3[1];
1492 J3C[8] += H34*YB3[2];
1494 for(
int i=0;
i<9;
i++) J1C[
i] = 0.75*J1C[
i] + J3C[
i];
1496 for(
int i=0;
i<9;
i++) J2C[
i] *= H34;
1538 if(fabs(P[7]) > maxPath)
return -3;
1540 double norm = 1/std::sqrt(Y1[3]*Y1[3]+Y1[4]*Y1[4]+Y1[5]*Y1[5]);
1546 if(newStep > 1e7)
return -4;
1548 double absNewStep = fabs(newStep);
1550 if(absNewStep <= min_step) {
1553 if(!useConstField) {
1561 for(
int i=0;
i<3;
i++) {
1563 P[
i] = Y1[
i] + newStep*Y1[
i+3];
1570 double absStep = fabs(Step);
1572 if(Step*newStep < 0.0) {
1573 if(++nFlips > 2)
return -5;
1574 Step = absNewStep < absStep ? newStep : -Step;
1577 if(absNewStep < absStep) Step = newStep;
1580 for(
int i=0;
i<6;
i++)
Y[
i] = Y1[
i];
1588 A[0] = -
B[1]*V[2] +
B[2]*V[1];
1589 A[1] =
B[0]*V[2] -
B[2]*V[0];
1590 A[2] = -
B[0]*V[1] +
B[1]*V[0];