27 #include "TDatabasePDG.h" 35 #include <type_traits> 39 #define MINSTEP 0.001 // minimum step [cm] for Runge Kutta and iteration to POCA 43 const TMatrixT<Double_t>* cov,
44 const TMatrixT<double>* aux)
46 if (aux != NULL) {
fCacheSpu = (*aux)(0, 0); }
49 throw GFException(
"RKTrackRep::setData() called with a reference plane not the same as the " 50 "one the last extrapolate(plane,state,cov) was made",
65 throw GFException(
"RKTrackRep::getAuxInfo() trying to get auxillary information with planes " 66 "mismatch (Information returned does not belong to requested plane)",
95 const TVector3& poserr,
96 const TVector3& momerr,
120 TVector3
w = u.Cross(v);
123 double pw = mom.Mag();
125 fCov[3][3] = poserr.X() * poserr.X() * u.X() * u.X() + poserr.Y() * poserr.Y() * u.Y() * u.Y() +
126 poserr.Z() * poserr.Z() * u.Z() * u.Z();
127 fCov[4][4] = poserr.X() * poserr.X() * v.X() * v.X() + poserr.Y() * poserr.Y() * v.Y() * v.Y() +
128 poserr.Z() * poserr.Z() * v.Z() * v.Z();
131 (mom.X() * mom.X() * momerr.X() * momerr.X() + mom.Y() * mom.Y() * momerr.Y() * momerr.Y() +
132 mom.Z() * mom.Z() * momerr.Z() * momerr.Z());
133 fCov[1][1] = pow((u.X() / pw - w.X() * pu / (pw * pw)), 2.) * momerr.X() * momerr.X() +
134 pow((u.Y() / pw - w.Y() * pu / (pw * pw)), 2.) * momerr.Y() * momerr.Y() +
135 pow((u.Z() / pw - w.Z() * pu / (pw * pw)), 2.) * momerr.Z() * momerr.Z();
136 fCov[2][2] = pow((v.X() / pw - w.X() * pv / (pw * pw)), 2.) * momerr.X() * momerr.X() +
137 pow((v.Y() / pw - w.Y() * pv / (pw * pw)), 2.) * momerr.Y() * momerr.Y() +
138 pow((v.Z() / pw - w.Z() * pv / (pw * pw)), 2.) * momerr.Z() * momerr.Z();
151 double pw = mom.Mag();
165 TVector3
w = u.Cross(v);
171 fCov[3][3] = poserr.X() * poserr.X() * u.X() * u.X() + poserr.Y() * poserr.Y() * u.Y() * u.Y() +
172 poserr.Z() * poserr.Z() * u.Z() * u.Z();
173 fCov[4][4] = poserr.X() * poserr.X() * v.X() * v.X() + poserr.Y() * poserr.Y() * v.Y() * v.Y() +
174 poserr.Z() * poserr.Z() * v.Z() * v.Z();
177 (mom.X() * mom.X() * momerr.X() * momerr.X() + mom.Y() * mom.Y() * momerr.Y() * momerr.Y() +
178 mom.Z() * mom.Z() * momerr.Z() * momerr.Z());
179 fCov[1][1] = pow((u.X() / pw - w.X() * pu / (pw * pw)), 2.) * momerr.X() * momerr.X() +
180 pow((u.Y() / pw - w.Y() * pu / (pw * pw)), 2.) * momerr.Y() * momerr.Y() +
181 pow((u.Z() / pw - w.Z() * pu / (pw * pw)), 2.) * momerr.Z() * momerr.Z();
182 fCov[2][2] = pow((v.X() / pw - w.X() * pv / (pw * pw)), 2.) * momerr.X() * momerr.X() +
183 pow((v.Y() / pw - w.Y() * pv / (pw * pw)), 2.) * momerr.Y() * momerr.Y() +
184 pow((v.Z() / pw - w.Z() * pv / (pw * pw)), 2.) * momerr.Z() * momerr.Z();
210 TVector3
w = u.Cross(v);
213 double pw = mom.Mag();
215 static const TVector3 stdPosErr(1., 1., 1.);
216 static const TVector3 stdMomErr(1., 1., 1.);
218 fCov[3][3] = stdPosErr.X() * stdPosErr.X() * u.X() * u.X() +
219 stdPosErr.Y() * stdPosErr.Y() * u.Y() * u.Y() +
220 stdPosErr.Z() * stdPosErr.Z() * u.Z() * u.Z();
221 fCov[4][4] = stdPosErr.X() * stdPosErr.X() * v.X() * v.X() +
222 stdPosErr.Y() * stdPosErr.Y() * v.Y() * v.Y() +
223 stdPosErr.Z() * stdPosErr.Z() * v.Z() * v.Z();
225 (mom.X() * mom.X() * stdMomErr.X() * stdMomErr.X() +
226 mom.Y() * mom.Y() * stdMomErr.Y() * stdMomErr.Y() +
227 mom.Z() * mom.Z() * stdMomErr.Z() * stdMomErr.Z());
228 fCov[1][1] = pow((u.X() / pw - w.X() * pu / (pw * pw)), 2.) * stdMomErr.X() * stdMomErr.X() +
229 pow((u.Y() / pw - w.Y() * pu / (pw * pw)), 2.) * stdMomErr.Y() * stdMomErr.Y() +
230 pow((u.Z() / pw - w.Z() * pu / (pw * pw)), 2.) * stdMomErr.Z() * stdMomErr.Z();
231 fCov[2][2] = pow((v.X() / pw - w.X() * pv / (pw * pw)), 2.) * stdMomErr.X() * stdMomErr.X() +
232 pow((v.Y() / pw - w.Y() * pv / (pw * pw)), 2.) * stdMomErr.Y() * stdMomErr.Y() +
233 pow((v.Z() / pw - w.Z() * pv / (pw * pw)), 2.) * stdMomErr.Z() * stdMomErr.Z();
247 TVector3
w = u.Cross(v);
263 static const TVector3 stdPosErr2(1., 1., 1.);
264 static const TVector3 stdMomErr2(1., 1., 1.);
266 fCov[3][3] = stdPosErr2.X() * stdPosErr2.X() * u.X() * u.X() +
267 stdPosErr2.Y() * stdPosErr2.Y() * u.Y() * u.Y() +
268 stdPosErr2.Z() * stdPosErr2.Z() * u.Z() * u.Z();
269 fCov[4][4] = stdPosErr2.X() * stdPosErr2.X() * v.X() * v.X() +
270 stdPosErr2.Y() * stdPosErr2.Y() * v.Y() * v.Y() +
271 stdPosErr2.Z() * stdPosErr2.Z() * v.Z() * v.Z();
273 (mom.X() * mom.X() * stdMomErr2.X() * stdMomErr2.X() +
274 mom.Y() * mom.Y() * stdMomErr2.Y() * stdMomErr2.Y() +
275 mom.Z() * mom.Z() * stdMomErr2.Z() * stdMomErr2.Z());
276 fCov[1][1] = pow((u.X() / pw - w.X() * pu / (pw * pw)), 2.) * stdMomErr2.X() * stdMomErr2.X() +
277 pow((u.Y() / pw - w.Y() * pu / (pw * pw)), 2.) * stdMomErr2.Y() * stdMomErr2.Y() +
278 pow((u.Z() / pw - w.Z() * pu / (pw * pw)), 2.) * stdMomErr2.Z() * stdMomErr2.Z();
279 fCov[2][2] = pow((v.X() / pw - w.X() * pv / (pw * pw)), 2.) * stdMomErr2.X() * stdMomErr2.X() +
280 pow((v.Y() / pw - w.Y() * pv / (pw * pw)), 2.) * stdMomErr2.Y() * stdMomErr2.Y() +
281 pow((v.Z() / pw - w.Z() * pv / (pw * pw)), 2.) * stdMomErr2.Z() * stdMomErr2.Z();
287 TParticlePDG*
part = TDatabasePDG::Instance()->GetParticle(
fPdg);
289 std::cerr <<
"RKTrackRep::setPDG particle " << i <<
" not known to TDatabasePDG -> abort" 293 fMass = part->Mass();
294 fCharge = part->Charge() / (3.);
305 TMatrixT<Double_t> s(5, 1);
307 return pl.
getO() + s[3][0] * pl.
getU() + s[4][0] * pl.
getV();
314 TMatrixT<Double_t> statePred(
fState);
324 retmom.SetMag(1. / fabs(statePred[0][0]));
334 retmom.SetMag(1. / fabs(statePred[0][0]));
340 TMatrixT<Double_t> statePred(
fState);
348 mom.SetMag(1. / fabs(statePred[0][0]));
349 pos = pl.
getO() + (statePred[3][0] * pl.
getU()) + (statePred[4][0] * pl.
getV());
355 static const int maxIt(30);
360 TVector3
w = u.Cross(v);
365 TVector3 point = o +
fState[3][0] * u +
fState[4][0] * v;
367 TMatrixT<Double_t> state7(7, 1);
368 state7[0][0] = point.X();
369 state7[1][0] = point.Y();
370 state7[2][0] = point.Z();
371 state7[3][0] = pTilde.X();
372 state7[4][0] = pTilde.Y();
373 state7[5][0] = pTilde.Z();
374 state7[6][0] =
fState[0][0];
376 double coveredDistance(0.);
382 pl.
setON(pos, TVector3(state7[3][0], state7[4][0], state7[5][0]));
383 coveredDistance = this->
Extrap(pl, &state7);
385 if (fabs(coveredDistance) <
MINSTEP)
break;
386 if (++iterations == maxIt) {
387 throw GFException(
"RKTrackRep::extrapolateToPoint==> extrapolation to point failed, maximum " 388 "number of iterations reached",
394 poca.SetXYZ(state7[0][0], state7[1][0], state7[2][0]);
395 dirInPoca.SetXYZ(state7[3][0], state7[4][0], state7[5][0]);
399 const TVector3& extr2,
400 const TVector3& point)
const 403 TVector3 theWire = extr2 - extr1;
404 if (theWire.Mag() < 1.E-8) {
405 throw GFException(
"RKTrackRep::poca2Line(): try to find poca between line and point, but the " 406 "line is really just a point",
411 double t = 1. / (theWire * theWire) * (point * theWire + extr1 * extr1 - extr1 * extr2);
412 return (extr1 + t * theWire);
416 const TVector3& point2,
419 TVector3& poca_onwire)
421 static const int maxIt(30);
426 TVector3
w = u.Cross(v);
431 TVector3 point = o +
fState[3][0] * u +
fState[4][0] * v;
433 TMatrixT<Double_t> state7(7, 1);
434 state7[0][0] = point.X();
435 state7[1][0] = point.Y();
436 state7[2][0] = point.Z();
437 state7[3][0] = pTilde.X();
438 state7[4][0] = pTilde.Y();
439 state7[5][0] = pTilde.Z();
440 state7[6][0] =
fState[0][0];
442 double coveredDistance(0.);
449 TVector3 currentDir(state7[3][0], state7[4][0], state7[5][0]);
450 pl.
setU(currentDir.Cross(point2 - point1));
451 pl.
setV(point2 - point1);
452 coveredDistance = this->
Extrap(pl, &state7);
454 if (fabs(coveredDistance) <
MINSTEP)
break;
455 if (++iterations == maxIt) {
457 "RKTrackRep extrapolation to point failed, maximum number of iterations reached",
463 poca.SetXYZ(state7[0][0], state7[1][0], state7[2][0]);
464 dirInPoca.SetXYZ(state7[3][0], state7[4][0], state7[5][0]);
465 poca_onwire =
poca2Line(point1, point2, poca);
469 TMatrixT<Double_t>& statePred,
470 TMatrixT<Double_t>& covPred)
473 TMatrixT<Double_t> cov7x7(7, 7);
474 TMatrixT<Double_t> J_pM(7, 5);
479 TVector3
w = u.Cross(v);
480 std::ostream* pOut =
nullptr;
490 double pTildeMag = pTilde.Mag();
495 J_pM[3][1] =
fSpu / pTildeMag * (u.X() - pTilde.X() / (pTildeMag * pTildeMag) * u * pTilde);
496 J_pM[4][1] =
fSpu / pTildeMag * (u.Y() - pTilde.Y() / (pTildeMag * pTildeMag) * u * pTilde);
497 J_pM[5][1] =
fSpu / pTildeMag * (u.Z() - pTilde.Z() / (pTildeMag * pTildeMag) * u * pTilde);
499 J_pM[3][2] =
fSpu / pTildeMag * (v.X() - pTilde.X() / (pTildeMag * pTildeMag) * v * pTilde);
500 J_pM[4][2] =
fSpu / pTildeMag * (v.Y() - pTilde.Y() / (pTildeMag * pTildeMag) * v * pTilde);
501 J_pM[5][2] =
fSpu / pTildeMag * (v.Z() - pTilde.Z() / (pTildeMag * pTildeMag) * v * pTilde);
505 TMatrixT<Double_t> J_pM_transp(J_pM);
508 cov7x7 = J_pM * (
fCov * J_pM_transp);
509 if (cov7x7[0][0] >= 1000. || cov7x7[0][0] < 1.
E-50) {
511 (*pOut) <<
"RKTrackRep::extrapolate(): cov7x7[0][0] is crazy. Rescale off-diags. Try again. " 512 "fCov, cov7x7 were: " 518 cov7x7 = J_pM * (
fCov * J_pM_transp);
520 (*pOut) <<
"New cov7x7 and fCov are ... " << std::endl;
527 TMatrixT<Double_t> state7(7, 1);
528 state7[0][0] = pos.X();
529 state7[1][0] = pos.Y();
530 state7[2][0] = pos.Z();
531 state7[3][0] = pTilde.X() / pTildeMag;
533 state7[4][0] = pTilde.Y() / pTildeMag;
535 state7[5][0] = pTilde.Z() / pTildeMag;
537 state7[6][0] =
fState[0][0];
539 double coveredDistance = this->
Extrap(pl, &state7, &cov7x7);
541 TVector3 O = pl.
getO();
542 TVector3 U = pl.
getU();
543 TVector3 V = pl.
getV();
546 double X = state7[0][0];
547 double Y = state7[1][0];
548 double Z = state7[2][0];
549 double AX = state7[3][0];
550 double AY = state7[4][0];
551 double AZ = state7[5][0];
552 double QOP = state7[6][0];
553 TVector3 A(AX, AY, AZ);
554 TVector3
Point(X, Y, Z);
555 TMatrixT<Double_t> J_Mp(5, 7);
561 J_Mp[1][3] = (U.X() * (AtW)-W.X() * (A * U)) / (AtW * AtW);
562 J_Mp[1][4] = (U.Y() * (AtW)-W.Y() * (A * U)) / (AtW * AtW);
563 J_Mp[1][5] = (U.Z() * (AtW)-W.Z() * (A * U)) / (AtW * AtW);
565 J_Mp[2][3] = (V.X() * (AtW)-W.X() * (A * V)) / (AtW * AtW);
566 J_Mp[2][4] = (V.Y() * (AtW)-W.Y() * (A * V)) / (AtW * AtW);
567 J_Mp[2][5] = (V.Z() * (AtW)-W.Z() * (A * V)) / (AtW * AtW);
577 TMatrixT<Double_t> J_Mp_transp(J_Mp);
580 covPred.ResizeTo(5, 5);
581 covPred = J_Mp * (cov7x7 * J_Mp_transp);
583 statePred.ResizeTo(5, 1);
584 statePred[0][0] = QOP;
585 statePred[1][0] = (A * U) / (A * W);
586 statePred[2][0] = (A * V) / (A * W);
587 statePred[3][0] = (Point - O) * U;
588 statePred[4][0] = (Point - O) * V;
593 return coveredDistance;
602 TVector3
w = u.Cross(v);
605 double pTildeMag = pTilde.Mag();
609 TMatrixT<Double_t> state7(7, 1);
610 state7[0][0] = pos.X();
611 state7[1][0] = pos.Y();
612 state7[2][0] = pos.Z();
613 state7[3][0] = pTilde.X() / pTildeMag;
614 state7[4][0] = pTilde.Y() / pTildeMag;
615 state7[5][0] = pTilde.Z() / pTildeMag;
616 state7[6][0] =
fState[0][0];
618 TVector3 O = pl.
getO();
619 TVector3 U = pl.
getU();
620 TVector3 V = pl.
getV();
623 double coveredDistance = this->
Extrap(pl, &state7);
625 double X = state7[0][0];
626 double Y = state7[1][0];
627 double Z = state7[2][0];
628 double AX = state7[3][0];
629 double AY = state7[4][0];
630 double AZ = state7[5][0];
631 double QOP = state7[6][0];
632 TVector3 A(AX, AY, AZ);
633 TVector3
Point(X, Y, Z);
635 statePred.ResizeTo(5, 1);
636 statePred[0][0] = QOP;
637 statePred[1][0] = (A * U) / (A * W);
638 statePred[2][0] = (A * V) / (A * W);
639 statePred[3][0] = (Point - O) * U;
640 statePred[4][0] = (Point - O) * V;
642 return coveredDistance;
684 double& coveredDistance,
685 std::vector<TVector3>& points,
686 std::vector<double>& pointPaths,
691 static const double EC = .000149896229;
692 static const double DLT = .0002;
693 static const double DLT32 = DLT / 32.;
694 static const double P3 = 1. / 3.;
695 static const double Smax = 100.0;
696 static const double Wmax = 3000.;
698 static const double Pmin = 1.E-11;
700 static const int ND = 56;
701 static const int ND1 = ND - 7;
704 double SA[3] = {0., 0., 0.};
705 double Pinv = P[6] * EC;
709 bool stopBecauseOfMaterial =
715 if (fabs(
fCharge / P[6]) < Pmin) {
716 std::cerr <<
"RKTrackRep::RKutta ==> momentum too low: " << fabs(
fCharge / P[6]) * 1000.
717 <<
" MeV" << std::endl;
722 TVector3 O = plane.
getO();
739 double Step, An, Dist, Dis, S, Sl = 0;
741 points.push_back(TVector3(R[0], R[1], R[2]));
742 pointPaths.push_back(0.);
744 An = A[0] * SU[0] + A[1] * SU[1] + A[2] * SU[2];
748 std::cerr <<
"RKTrackRep::RKutta ==> cannot propagate perpendicular to plane " << std::endl;
752 TVector3(R[0], R[1], R[2]),
753 TVector3(A[0], A[1], A[2]))) {
754 Dist = SU[3] - R[0] * SU[0] - R[1] * SU[1] -
759 if ((O.X() - R[0]) * A[0] + (O.Y() - R[1]) * A[1] + (O.Z() - R[2]) * A[2] >
762 sqrt((R[0] - O.X()) *
764 (R[1] - O.Y()) * (R[1] - O.Y()) +
765 (R[2] - O.Z()) * (R[2] - O.Z()));
768 Dist = -1. * sqrt((R[0] - O.X()) * (R[0] - O.X()) + (R[1] - O.Y()) * (R[1] - O.Y()) +
769 (R[2] - O.Z()) * (R[2] - O.Z()));
774 if (fabs(Step) > Wmax) {
776 std::cerr <<
"RKTrackRep::RKutta ==> Too long extrapolation requested : " << Step <<
" cm !" 778 std::cerr <<
"X = " << R[0] <<
" Y = " << R[1] <<
" Z = " << R[2] <<
" COSx = " << A[0]
779 <<
" COSy = " << A[1] <<
" COSz = " << A[2] << std::endl;
780 std::cout <<
"Destination X = " << SU[0] * SU[3] << std::endl;
782 mf::LogInfo(
"RKTrackRep::RKutta(): ") <<
"Throw cet exception here, ... ";
783 throw GFException(
"RKTrackRep::RKutta(): Runge Kutta propagation failed", __LINE__, __FILE__)
792 Step > Smax ? S = Smax : Step < -Smax ? S = -Smax : S = Step;
800 if (S < 0) Ssign = -1;
802 while (fabs(Step) >
MINSTEP && !stopBecauseOfMaterial) {
828 if (S > stepperLen) {
830 stopBecauseOfMaterial =
true;
832 else if (S < -stepperLen) {
834 stopBecauseOfMaterial =
true;
837 double H0[12], H1[12], H2[12],
r[3];
838 double S3 = P3 * S, S4 = .25 * S, PS2 = Pinv * S;
846 TVector3 pos(r[0], r[1], r[2]);
848 H0[0] = PS2 * H0vect.X();
849 H0[1] = PS2 * H0vect.Y();
850 H0[2] = PS2 * H0vect.Z();
851 double A0 = A[1] * H0[2] - A[2] * H0[1], B0 = A[2] * H0[0] - A[0] * H0[2],
852 C0 = A[0] * H0[1] - A[1] * H0[0];
853 double A2 = A[0] + A0, B2 = A[1] + B0, C2 = A[2] + C0;
854 double A1 = A2 + A[0], B1 = B2 + A[1], C1 = C2 + A[2];
862 pos.SetXYZ(r[0], r[1], r[2]);
864 H1[0] = H1vect.X() * PS2;
865 H1[1] = H1vect.Y() * PS2;
868 double A3, B3, C3, A4, B4, C4, A5, B5, C5;
869 A3 = B2 * H1[2] - C2 * H1[1] + A[0];
870 B3 = C2 * H1[0] - A2 * H1[2] + A[1];
871 C3 = A2 * H1[1] - B2 * H1[0] + A[2];
872 A4 = B3 * H1[2] - C3 * H1[1] + A[0];
873 B4 = C3 * H1[0] - A3 * H1[2] + A[1];
874 C4 = A3 * H1[1] - B3 * H1[0] + A[2];
882 r[0] = R[0] + S * A4;
883 r[1] = R[1] + S * B4;
884 r[2] = R[2] + S * C4;
885 pos.SetXYZ(r[0], r[1], r[2]);
887 H2[0] = H2vect.X() * PS2;
888 H2[1] = H2vect.Y() * PS2;
889 H2[2] = H2vect.Z() * PS2;
890 double A6 = B5 * H2[2] - C5 * H2[1], B6 = C5 * H2[0] - A5 * H2[2],
891 C6 = A5 * H2[1] - B5 * H2[0];
897 fabs((A1 + A6) - (A3 + A4)) + fabs((B1 + B6) - (B3 + B4)) +
904 stopBecauseOfMaterial =
false;
912 for (
int i = 7; i != ND;
916 double* dA = &P[i + 3];
919 double dA0 = H0[2] * dA[1] - H0[1] * dA[2];
920 double dB0 = H0[0] * dA[2] - H0[2] * dA[0];
921 double dC0 = H0[1] * dA[0] - H0[0] * dA[1];
929 double dA2 = dA0 + dA[0];
930 double dB2 = dB0 + dA[1];
931 double dC2 = dC0 + dA[2];
934 double dA3 = dA[0] + dB2 * H1[2] - dC2 * H1[1];
936 dA[1] + dC2 * H1[0] - dA2 * H1[2];
937 double dC3 = dA[2] + dA2 * H1[1] - dB2 * H1[0];
945 double dA4 = dA[0] + dB3 * H1[2] - dC3 * H1[1];
947 dA[1] + dC3 * H1[0] - dA3 * H1[2];
948 double dC4 = dA[2] + dA3 * H1[1] - dB3 * H1[0];
957 double dA5 = dA4 + dA4 - dA[0];
958 double dB5 = dB4 + dB4 - dA[1];
959 double dC5 = dC4 + dC4 - dA[2];
961 double dA6 = dB5 * H2[2] - dC5 * H2[1];
962 double dB6 = dC5 * H2[0] - dA5 * H2[2];
963 double dC6 = dA5 * H2[1] - dB5 * H2[0];
971 dR[0] += (dA2 + dA3 + dA4) * S3;
972 dA[0] = (dA0 + dA3 + dA3 + dA5 + dA6) *
974 dR[1] += (dB2 + dB3 + dB4) * S3;
976 (dB0 + dB3 + dB3 + dB5 + dB6) *
978 dR[2] += (dC2 + dC3 + dC4) * S3;
979 dA[2] = (dC0 + dC3 + dC3 + dC5 + dC6) * P3;
984 if ((Way += fabs(S)) > Wmax) {
985 std::cerr <<
"PaAlgo::RKutta ==> Trajectory is longer than length limit : " << Way <<
" cm !" 986 <<
" p/q = " << 1. / P[6] <<
" GeV" << std::endl;
993 R[0] += (A2 + A3 + A4) * S3;
994 A[0] += (SA[0] = (A0 + A3 + A3 + A5 + A6) * P3 -
996 R[1] += (B2 + B3 + B4) * S3;
998 (SA[1] = (B0 + B3 + B3 + B5 + B6) * P3 -
1000 R[2] += (C2 + C3 + C4) * S3;
1001 A[2] += (SA[2] = (C0 + C3 + C3 + C5 + C6) * P3 - A[2]);
1006 if (Ssign * S < 0.) {
1007 pointPaths.at(pointPaths.size() - 1) += S;
1008 points.erase(points.end());
1011 pointPaths.push_back(S);
1014 points.push_back(TVector3(R[0], R[1], R[2]));
1016 double CBA = 1. / sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
1022 if (fabs(Way2) > Wmax) {
1030 An = A[0] * SU[0] + A[1] * SU[1] + A[2] * SU[2];
1032 if (plane.
inActive(TVector3(R[0], R[1], R[2]), TVector3(A[0], A[1], A[2]))) {
1033 Dis = SU[3] - R[0] * SU[0] - R[1] * SU[1] - R[2] * SU[2];
1037 if ((O.X() - R[0]) * A[0] + (O.Y() - R[1]) * A[1] + (O.Z() - R[2]) * A[2] > 0) {
1038 Dis = sqrt((R[0] - O.X()) * (R[0] - O.X()) + (R[1] - O.Y()) * (R[1] - O.Y()) +
1039 (R[2] - O.Z()) * (R[2] - O.Z()));
1042 Dis = -1. * sqrt((R[0] - O.X()) * (R[0] - O.X()) + (R[1] - O.Y()) * (R[1] - O.Y()) +
1043 (R[2] - O.Z()) * (R[2] - O.Z()));
1049 if (Dis * Dist > 0 && fabs(Dis) > fabs(Dist)) {
1060 if (S * Step < 0. || fabs(S) > fabs(Step))
1062 else if (EST < DLT32 && fabs(2. * S) <= Smax)
1071 if (!stopBecauseOfMaterial) {
1072 if (Sl != 0) Sl = 1. / Sl;
1073 A[0] += (SA[0] *= Sl) * Step;
1077 A[2] += (SA[2] *= Sl) * Step;
1084 P[1] = R[1] + Step * (A[1] - .5 * Step * SA[1]);
1085 P[2] = R[2] + Step * (A[2] - .5 * Step * SA[2]);
1087 points.push_back(TVector3(P[0], P[1], P[2]));
1088 pointPaths.push_back(Step);
1091 double CBA = 1. / sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
1100 An = A[0] * SU[0] + A[1] * SU[1] + A[2] * SU[2];
1102 fabs(An) < 1.E-6 ? An = 1. / An : An = 0;
1104 if (calcCov && !stopBecauseOfMaterial) {
1105 for (
int i = 7; i != ND; i += 7) {
1107 double* dA = &P[i + 3];
1108 S = (dR[0] * SU[0] + dR[1] * SU[1] + dR[2] * SU[2]) * An;
1120 std::cerr <<
"RKTrackRep::RKutta ==> Do not get closer. Path = " << Way <<
" cm" 1121 <<
" p/q = " << 1. / P[6] <<
" GeV" << std::endl;
1126 if (!stopBecauseOfMaterial)
1127 coveredDistance = Way2 + Step;
1129 coveredDistance = Way2;
1135 TMatrixT<Double_t>* state,
1136 TMatrixT<Double_t>* cov)
const 1139 static const int maxNumIt(2000);
1142 if (cov == NULL) calcCov =
false;
1145 if (calcCov)
std::fill(P, P + std::extent<decltype(P)>::
value, 0);
1148 for (
int i = 0; i < 7; ++i) {
1149 P[i] = (*state)[i][0];
1152 TMatrixT<Double_t> jac(7, 7);
1153 TMatrixT<Double_t> jacT(7, 7);
1154 TMatrixT<Double_t> oldCov(7, 7);
1155 if (calcCov) oldCov = (*cov);
1156 double coveredDistance(0.);
1157 double sumDistance(0.);
1160 if (numIt++ > maxNumIt) {
1162 "RKTrackRep::Extrap ==> maximum number of iterations exceeded", __LINE__, __FILE__)
1167 memset(&P[7], 0x00, 49 *
sizeof(
double));
1168 for (
int i = 0; i < 6; ++i) {
1169 P[(i + 1) * 7 + i] = 1.;
1171 P[55] = (*state)[6][0];
1176 TVector3 Pvect(P[0], P[1], P[2]);
1177 TVector3 Avect(P[3], P[4], P[5]);
1187 TVector3 directionBefore(P[3], P[4], P[5]);
1188 directionBefore.SetMag(1.);
1191 std::vector<TVector3> points;
1192 std::vector<double> pointPaths;
1203 mf::LogInfo(
"RKTrackRep::RKutta(): ") <<
"Throw cet exception here, ... ";
1204 throw GFException(
"RKTrackRep::RKutta(): Runge Kutta propagation failed", __LINE__, __FILE__)
1208 TVector3 directionAfter(P[3], P[4], P[5]);
1209 directionAfter.SetMag(1.);
1211 sumDistance += coveredDistance;
1214 std::vector<TVector3> pointsFilt(1, points.at(0));
1215 std::vector<double> pointPathsFilt(1, 0.);
1217 for (
unsigned int i = 1; i < points.size(); ++i) {
1218 if (pointPaths.at(i) * coveredDistance > 0.) {
1219 pointsFilt.push_back(points.at(i));
1220 pointPathsFilt.push_back(pointPaths.at(i));
1223 pointsFilt.back() = points.at(i);
1224 pointPathsFilt.back() += pointPaths.at(i);
1227 int position = pointsFilt.size() - 1;
1228 if (fabs(pointPathsFilt.back()) <
MINSTEP && position > 1) {
1229 pointsFilt.at(position - 1) = pointsFilt.at(position);
1230 pointsFilt.pop_back();
1231 pointPathsFilt.at(position - 1) += pointPathsFilt.at(position);
1232 pointPathsFilt.pop_back();
1237 double checkSum(0.);
1238 for (
unsigned int i = 0; i < pointPathsFilt.size(); ++i) {
1239 checkSum += pointPathsFilt.at(i);
1242 if (fabs(checkSum - coveredDistance) > 1.
E-7) {
1244 "RKTrackRep::Extrap ==> fabs(checkSum-coveredDistance)>1.E-7", __LINE__, __FILE__)
1249 for (
int i = 0; i < 7; ++i) {
1250 for (
int j = 0; j < 7; ++j) {
1252 jac[i][j] = P[(i + 1) * 7 + j];
1254 jac[i][j] = P[(i + 1) * 7 + j] / P[6];
1261 TMatrixT<Double_t>
noise(7, 7);
1287 if (fabs(P[6]) > 1.
E-10) {
1293 *cov = jacT * ((oldCov)*jac) +
noise;
1298 if (plane.
inActive(TVector3(P[0], P[1], P[2]), TVector3(P[3], P[4], P[5]))) {
1302 (*state)[0][0] = P[0];
1303 (*state)[1][0] = P[1];
1304 (*state)[2][0] = P[2];
1305 (*state)[3][0] = P[3];
1306 (*state)[4][0] = P[4];
1307 (*state)[5][0] = P[5];
1308 (*state)[6][0] = P[6];
1316 for (
int i = 0; i <
fCov.GetNrows(); ++i) {
1317 for (
int j = 0; j <
fCov.GetNcols(); ++j) {
1322 if (
fCov[i][j] <= 0.0)
fCov[i][j] = 0.01;
int fPdg
PDG particle code.
const TMatrixT< double > * getAuxInfo(const GFDetPlane &pl)
void setON(const TVector3 &o, const TVector3 &n)
void setU(const TVector3 &u)
static GFMaterialEffects * getInstance()
TVector3 getPosError() const
void extrapolateToLine(const TVector3 &point1, const TVector3 &point2, TVector3 &poca, TVector3 &dirInPoca, TVector3 &poca_onwire)
This method extrapolates to the point of closest approach to a line.
TVector3 getPosSeed() const
get the seed value for track: pos
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
TVector3 dist(const TVector3 &point) const
double fMass
Mass (in GeV)
void setO(const TVector3 &o)
double extrapolate(const GFDetPlane &, TMatrixT< Double_t > &statePred, TMatrixT< Double_t > &covPred)
returns the tracklength spanned in this extrapolation
TVector3 getDirSeed() const
get the seed value for track: direction
void setData(const TMatrixT< double > &st, const GFDetPlane &pl, const TMatrixT< double > *cov=NULL, const TMatrixT< double > *aux=NULL)
Sets state, plane and (optionally) covariance.
Base Class for genfit track representations. Defines interface for track parameterizations.
TVector3 getNormal() const
TMatrixT< double > fAuxInfo
TMatrixT< Double_t > fCov
The covariance matrix.
void setV(const TVector3 &v)
double distance(TVector3 &) const
virtual void setData(const TMatrixT< Double_t > &st, const GFDetPlane &pl, const TMatrixT< Double_t > *cov=NULL)
void rescaleCovOffDiags()
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
TMatrixT< Double_t > fLastState
int getPdgCode() const
get the PDG code
void extrapolateToPoint(const TVector3 &pos, TVector3 &poca, TVector3 &dirInPoca)
This method is to extrapolate the track to point of closest approach to a point in space...
static TVector3 getFieldVal(const TVector3 &x)
void setPDG(int)
Set PDG particle code.
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
double effects(const std::vector< TVector3 > &points, const std::vector< double > &pointPaths, const double &mom, const int &pdg, const bool &doNoise=false, TMatrixT< Double_t > *noise=NULL, const TMatrixT< Double_t > *jacobian=NULL, const TVector3 *directionBefore=NULL, const TVector3 *directionAfter=NULL)
Calculates energy loss in the travelled path, optional calculation of noise matrix.
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
double Extrap(const GFDetPlane &plane, TMatrixT< Double_t > *state, TMatrixT< Double_t > *cov=NULL) const
Handles propagation and material effects.
void setNormal(TVector3 n)
void PrintROOTobject(std::ostream &, const ROOTOBJ &)
Small utility functions which print some ROOT objects into an output stream.
GFException & setFatal(bool b=true)
set fatal flag. if this is true, the fit stops for this current track repr.
TVector3 getMomLast(const GFDetPlane &)
TVector3 getDirError() const
get the seed value for track: error on direction (standard deviation)
TMatrixT< Double_t > fState
The vector of track parameters.
bool inActive(const TVector3 &point, const TVector3 &dir) const
intersect in the active area? C.f. GFAbsFinitePlane
void getPosMom(const GFDetPlane &, TVector3 &pos, TVector3 &mom)
Gets position and momentum in the plane by exrapolating or not.
bool RKutta(const GFDetPlane &plane, double *P, double &coveredDistance, std::vector< TVector3 > &points, std::vector< double > &pointLengths, const double &maxLen=-1, bool calcCov=true) const
Contains all material effects.
TVector3 poca2Line(const TVector3 &extr1, const TVector3 &extr2, const TVector3 &point) const
double stepper(const double &maxDist, const double &posx, const double &posy, const double &posz, const double &dirx, const double &diry, const double &dirz, const double &mom, const int &pdg)
Returns maximum length so that a specified momentum loss will not be exceeded.