30 #include <type_traits> 32 #include "TGeoManager.h" 33 #include "TDatabasePDG.h" 40 #define MINSTEP 0.001 // minimum step [cm] for Runge Kutta and iteration to POCA 48 throw GFException(
"RKTrackRep::setData() called with a reference plane not the same as the one the last extrapolate(plane,state,cov) was made", __LINE__, __FILE__).
setFatal();
59 throw GFException(
"RKTrackRep::getAuxInfo() trying to get auxillary information with planes mismatch (Information returned does not belong to requested plane)", __LINE__, __FILE__).
setFatal();
86 const TVector3& poserr,
87 const TVector3& momerr,
115 TVector3
w=u.Cross(v);
120 fCov[3][3] = poserr.X()*poserr.X() * u.X()*u.X() +
121 poserr.Y()*poserr.Y() * u.Y()*u.Y() +
122 poserr.Z()*poserr.Z() * u.Z()*u.Z();
123 fCov[4][4] = poserr.X()*poserr.X() * v.X()*v.X() +
124 poserr.Y()*poserr.Y() * v.Y()*v.Y() +
125 poserr.Z()*poserr.Z() * v.Z()*v.Z();
127 (mom.X()*mom.X() * momerr.X()*momerr.X()+
128 mom.Y()*mom.Y() * momerr.Y()*momerr.Y()+
129 mom.Z()*mom.Z() * momerr.Z()*momerr.Z());
130 fCov[1][1] = pow((u.X()/pw - w.X()*pu/(pw*pw)),2.)*momerr.X()*momerr.X() +
131 pow((u.Y()/pw - w.Y()*pu/(pw*pw)),2.)*momerr.Y()*momerr.Y() +
132 pow((u.Z()/pw - w.Z()*pu/(pw*pw)),2.)*momerr.Z()*momerr.Z();
133 fCov[2][2] = pow((v.X()/pw - w.X()*pv/(pw*pw)),2.)*momerr.X()*momerr.X() +
134 pow((v.Y()/pw - w.Y()*pv/(pw*pw)),2.)*momerr.Y()*momerr.Y() +
135 pow((v.Z()/pw - w.Z()*pv/(pw*pw)),2.)*momerr.Z()*momerr.Z();
167 TVector3
w=u.Cross(v);
173 fCov[3][3] = poserr.X()*poserr.X() * u.X()*u.X() +
174 poserr.Y()*poserr.Y() * u.Y()*u.Y() +
175 poserr.Z()*poserr.Z() * u.Z()*u.Z();
176 fCov[4][4] = poserr.X()*poserr.X() * v.X()*v.X() +
177 poserr.Y()*poserr.Y() * v.Y()*v.Y() +
178 poserr.Z()*poserr.Z() * v.Z()*v.Z();
180 (mom.X()*mom.X() * momerr.X()*momerr.X()+
181 mom.Y()*mom.Y() * momerr.Y()*momerr.Y()+
182 mom.Z()*mom.Z() * momerr.Z()*momerr.Z());
183 fCov[1][1] = pow((u.X()/pw - w.X()*pu/(pw*pw)),2.)*momerr.X()*momerr.X() +
184 pow((u.Y()/pw - w.Y()*pu/(pw*pw)),2.)*momerr.Y()*momerr.Y() +
185 pow((u.Z()/pw - w.Z()*pu/(pw*pw)),2.)*momerr.Z()*momerr.Z();
186 fCov[2][2] = pow((v.X()/pw - w.X()*pv/(pw*pw)),2.)*momerr.X()*momerr.X() +
187 pow((v.Y()/pw - w.Y()*pv/(pw*pw)),2.)*momerr.Y()*momerr.Y() +
188 pow((v.Z()/pw - w.Z()*pv/(pw*pw)),2.)*momerr.Z()*momerr.Z();
194 const int& PDGCode) :
219 TVector3
w=u.Cross(v);
224 static const TVector3 stdPosErr(1.,1.,1.);
225 static const TVector3 stdMomErr(1.,1.,1.);
227 fCov[3][3] = stdPosErr.X()*stdPosErr.X() * u.X()*u.X() +
228 stdPosErr.Y()*stdPosErr.Y() * u.Y()*u.Y() +
229 stdPosErr.Z()*stdPosErr.Z() * u.Z()*u.Z();
230 fCov[4][4] = stdPosErr.X()*stdPosErr.X() * v.X()*v.X() +
231 stdPosErr.Y()*stdPosErr.Y() * v.Y()*v.Y() +
232 stdPosErr.Z()*stdPosErr.Z() * v.Z()*v.Z();
234 (mom.X()*mom.X() * stdMomErr.X()*stdMomErr.X()+
235 mom.Y()*mom.Y() * stdMomErr.Y()*stdMomErr.Y()+
236 mom.Z()*mom.Z() * stdMomErr.Z()*stdMomErr.Z());
237 fCov[1][1] = pow((u.X()/pw - w.X()*pu/(pw*pw)),2.)*stdMomErr.X()*stdMomErr.X() +
238 pow((u.Y()/pw - w.Y()*pu/(pw*pw)),2.)*stdMomErr.Y()*stdMomErr.Y() +
239 pow((u.Z()/pw - w.Z()*pu/(pw*pw)),2.)*stdMomErr.Z()*stdMomErr.Z();
240 fCov[2][2] = pow((v.X()/pw - w.X()*pv/(pw*pw)),2.)*stdMomErr.X()*stdMomErr.X() +
241 pow((v.Y()/pw - w.Y()*pv/(pw*pw)),2.)*stdMomErr.Y()*stdMomErr.Y() +
242 pow((v.Z()/pw - w.Z()*pv/(pw*pw)),2.)*stdMomErr.Z()*stdMomErr.Z();
248 const int& PDGCode) :
261 TVector3
w=u.Cross(v);
277 static const TVector3 stdPosErr2(1.,1.,1.);
278 static const TVector3 stdMomErr2(1.,1.,1.);
280 fCov[3][3] = stdPosErr2.X()*stdPosErr2.X() * u.X()*u.X() +
281 stdPosErr2.Y()*stdPosErr2.Y() * u.Y()*u.Y() +
282 stdPosErr2.Z()*stdPosErr2.Z() * u.Z()*u.Z();
283 fCov[4][4] = stdPosErr2.X()*stdPosErr2.X() * v.X()*v.X() +
284 stdPosErr2.Y()*stdPosErr2.Y() * v.Y()*v.Y() +
285 stdPosErr2.Z()*stdPosErr2.Z() * v.Z()*v.Z();
287 (mom.X()*mom.X() * stdMomErr2.X()*stdMomErr2.X()+
288 mom.Y()*mom.Y() * stdMomErr2.Y()*stdMomErr2.Y()+
289 mom.Z()*mom.Z() * stdMomErr2.Z()*stdMomErr2.Z());
290 fCov[1][1] = pow((u.X()/pw - w.X()*pu/(pw*pw)),2.)*stdMomErr2.X()*stdMomErr2.X() +
291 pow((u.Y()/pw - w.Y()*pu/(pw*pw)),2.)*stdMomErr2.Y()*stdMomErr2.Y() +
292 pow((u.Z()/pw - w.Z()*pu/(pw*pw)),2.)*stdMomErr2.Z()*stdMomErr2.Z();
293 fCov[2][2] = pow((v.X()/pw - w.X()*pv/(pw*pw)),2.)*stdMomErr2.X()*stdMomErr2.X() +
294 pow((v.Y()/pw - w.Y()*pv/(pw*pw)),2.)*stdMomErr2.Y()*stdMomErr2.Y() +
295 pow((v.Z()/pw - w.Z()*pv/(pw*pw)),2.)*stdMomErr2.Z()*stdMomErr2.Z();
302 TParticlePDG *
part = TDatabasePDG::Instance()->GetParticle(
fPdg);
304 std::cerr <<
"RKTrackRep::setPDG particle " << i
305 <<
" not known to TDatabasePDG -> abort" << std::endl;
308 fMass = part->Mass();
316 TMatrixT<Double_t>
s(5,1);
325 TMatrixT<Double_t> statePred(
fState);
334 retmom.SetMag(1./fabs(statePred[0][0]));
343 retmom.SetMag(1./fabs(statePred[0][0]));
350 TMatrixT<Double_t> statePred(
fState);
358 mom.SetMag(1./fabs(statePred[0][0]));
359 pos = pl.
getO()+(statePred[3][0]*pl.
getU())+(statePred[4][0]*pl.
getV());
368 TVector3& dirInPoca){
370 static const int maxIt(30);
375 TVector3
w=u.Cross(v);
382 TMatrixT<Double_t> state7(7,1);
383 state7[0][0] = point.X();
384 state7[1][0] = point.Y();
385 state7[2][0] = point.Z();
386 state7[3][0] = pTilde.X();
387 state7[4][0] = pTilde.Y();
388 state7[5][0] = pTilde.Z();
389 state7[6][0] =
fState[0][0];
391 double coveredDistance(0.);
397 pl.
setON(pos,TVector3(state7[3][0],state7[4][0],state7[5][0]));
398 coveredDistance = this->
Extrap(pl,&state7);
400 if(fabs(coveredDistance)<
MINSTEP)
break;
401 if(++iterations == maxIt) {
402 throw GFException(
"RKTrackRep::extrapolateToPoint==> extrapolation to point failed, maximum number of iterations reached",__LINE__,__FILE__).
setFatal();
405 poca.SetXYZ(state7[0][0],state7[1][0],state7[2][0]);
406 dirInPoca.SetXYZ(state7[3][0],state7[4][0],state7[5][0]);
414 TVector3 theWire = extr2-extr1;
415 if(theWire.Mag()<1.E-8){
416 throw GFException(
"RKTrackRep::poca2Line(): try to find poca between line and point, but the line is really just a point",__LINE__,__FILE__).
setFatal();
418 double t = 1./(theWire*theWire)*(point*theWire+extr1*extr1-extr1*extr2);
419 return (extr1+t*theWire);
426 const TVector3& point2,
429 TVector3& poca_onwire){
430 static const int maxIt(30);
435 TVector3
w=u.Cross(v);
442 TMatrixT<Double_t> state7(7,1);
443 state7[0][0] = point.X();
444 state7[1][0] = point.Y();
445 state7[2][0] = point.Z();
446 state7[3][0] = pTilde.X();
447 state7[4][0] = pTilde.Y();
448 state7[5][0] = pTilde.Z();
449 state7[6][0] =
fState[0][0];
451 double coveredDistance(0.);
458 TVector3 currentDir(state7[3][0],state7[4][0],state7[5][0]);
459 pl.
setU(currentDir.Cross(point2-point1));
460 pl.
setV(point2-point1);
461 coveredDistance = this->
Extrap(pl,&state7);
463 if(fabs(coveredDistance)<
MINSTEP)
break;
464 if(++iterations == maxIt) {
465 throw GFException(
"RKTrackRep extrapolation to point failed, maximum number of iterations reached",__LINE__,__FILE__).
setFatal();
468 poca.SetXYZ(state7[0][0],state7[1][0],state7[2][0]);
469 dirInPoca.SetXYZ(state7[3][0],state7[4][0],state7[5][0]);
470 poca_onwire =
poca2Line(point1,point2,poca);
477 TMatrixT<Double_t>& statePred,
478 TMatrixT<Double_t>& covPred){
480 TMatrixT<Double_t> cov7x7(7,7);
481 TMatrixT<Double_t> J_pM(7,5);
486 TVector3
w=u.Cross(v);
487 std::ostream* pOut =
nullptr;
489 J_pM[0][3] = u.X();J_pM[0][4]=v.X();
490 J_pM[1][3] = u.Y();J_pM[1][4]=v.Y();
491 J_pM[2][3] = u.Z();J_pM[2][4]=v.Z();
494 double pTildeMag = pTilde.Mag();
499 J_pM[3][1] =
fSpu/pTildeMag*(u.X()-pTilde.X()/(pTildeMag*pTildeMag)*u*pTilde);
500 J_pM[4][1] =
fSpu/pTildeMag*(u.Y()-pTilde.Y()/(pTildeMag*pTildeMag)*u*pTilde);
501 J_pM[5][1] =
fSpu/pTildeMag*(u.Z()-pTilde.Z()/(pTildeMag*pTildeMag)*u*pTilde);
503 J_pM[3][2] =
fSpu/pTildeMag*(v.X()-pTilde.X()/(pTildeMag*pTildeMag)*v*pTilde);
504 J_pM[4][2] =
fSpu/pTildeMag*(v.Y()-pTilde.Y()/(pTildeMag*pTildeMag)*v*pTilde);
505 J_pM[5][2] =
fSpu/pTildeMag*(v.Z()-pTilde.Z()/(pTildeMag*pTildeMag)*v*pTilde);
509 TMatrixT<Double_t> J_pM_transp(J_pM);
512 cov7x7 = J_pM*(
fCov*J_pM_transp);
513 if (cov7x7[0][0]>=1000. || cov7x7[0][0]<1.
E-50)
516 (*pOut) <<
"RKTrackRep::extrapolate(): cov7x7[0][0] is crazy. Rescale off-diags. Try again. fCov, cov7x7 were: " << std::endl;
521 cov7x7 = J_pM*(
fCov*J_pM_transp);
523 (*pOut) <<
"New cov7x7 and fCov are ... " << std::endl;
531 TMatrixT<Double_t> state7(7,1);
532 state7[0][0] = pos.X();
533 state7[1][0] = pos.Y();
534 state7[2][0] = pos.Z();
535 state7[3][0] = pTilde.X()/pTildeMag;;
536 state7[4][0] = pTilde.Y()/pTildeMag;;
537 state7[5][0] = pTilde.Z()/pTildeMag;;
538 state7[6][0] =
fState[0][0];
540 double coveredDistance = this->
Extrap(pl,&state7,&cov7x7);
543 TVector3 O = pl.
getO();
544 TVector3 U = pl.
getU();
545 TVector3 V = pl.
getV();
548 double X = state7[0][0];
549 double Y = state7[1][0];
550 double Z = state7[2][0];
551 double AX = state7[3][0];
552 double AY = state7[4][0];
553 double AZ = state7[5][0];
554 double QOP = state7[6][0];
555 TVector3 A(AX,AY,AZ);
556 TVector3
Point(X,Y,Z);
557 TMatrixT<Double_t> J_Mp(5,7);
563 J_Mp[1][3] = (U.X()*(AtW)-W.X()*(A*U))/(AtW*AtW);
564 J_Mp[1][4] = (U.Y()*(AtW)-W.Y()*(A*U))/(AtW*AtW);
565 J_Mp[1][5] = (U.Z()*(AtW)-W.Z()*(A*U))/(AtW*AtW);
567 J_Mp[2][3] = (V.X()*(AtW)-W.X()*(A*V))/(AtW*AtW);
568 J_Mp[2][4] = (V.Y()*(AtW)-W.Y()*(A*V))/(AtW*AtW);
569 J_Mp[2][5] = (V.Z()*(AtW)-W.Z()*(A*V))/(AtW*AtW);
579 TMatrixT<Double_t> J_Mp_transp(J_Mp);
582 covPred.ResizeTo(5,5);
583 covPred = J_Mp*(cov7x7*J_Mp_transp);
586 statePred.ResizeTo(5,1);
587 statePred[0][0] = QOP;
588 statePred[1][0] = (A*U)/(A*W);
589 statePred[2][0] = (A*V)/(A*W);
590 statePred[3][0] = (Point-O)*U;
591 statePred[4][0] = (Point-O)*V;
596 return coveredDistance;
603 TMatrixT<Double_t>& statePred){
608 TVector3
w=u.Cross(v);
612 double pTildeMag = pTilde.Mag();
616 TMatrixT<Double_t> state7(7,1);
617 state7[0][0] = pos.X();
618 state7[1][0] = pos.Y();
619 state7[2][0] = pos.Z();
620 state7[3][0] = pTilde.X()/pTildeMag;
621 state7[4][0] = pTilde.Y()/pTildeMag;
622 state7[5][0] = pTilde.Z()/pTildeMag;
623 state7[6][0] =
fState[0][0];
625 TVector3 O = pl.
getO();
626 TVector3 U = pl.
getU();
627 TVector3 V = pl.
getV();
630 double coveredDistance = this->
Extrap(pl,&state7);
632 double X = state7[0][0];
633 double Y = state7[1][0];
634 double Z = state7[2][0];
635 double AX = state7[3][0];
636 double AY = state7[4][0];
637 double AZ = state7[5][0];
638 double QOP = state7[6][0];
639 TVector3 A(AX,AY,AZ);
640 TVector3
Point(X,Y,Z);
642 statePred.ResizeTo(5,1);
643 statePred[0][0] = QOP;
644 statePred[1][0] = (A*U)/(A*W);
645 statePred[2][0] = (A*V)/(A*W);
646 statePred[3][0] = (Point-O)*U;
647 statePred[4][0] = (Point-O)*V;
649 return coveredDistance;
694 double& coveredDistance,
695 std::vector<TVector3>& points,
696 std::vector<double>& pointPaths,
698 bool calcCov)
const {
700 static const double EC = .000149896229;
701 static const double DLT = .0002;
702 static const double DLT32 = DLT/32.;
703 static const double P3 = 1./3.;
704 static const double Smax = 100.0;
705 static const double Wmax = 3000.;
707 static const double Pmin = 1.E-11;
709 static const int ND = 56;
710 static const int ND1 = ND-7;
713 double SA[3] = {0.,0.,0.};
714 double Pinv = P[6]*EC;
718 bool stopBecauseOfMaterial =
false;
724 std::cerr <<
"RKTrackRep::RKutta ==> momentum too low: " << fabs(
fCharge/P[6])*1000. <<
" MeV" << std::endl;
729 TVector3 O = plane.
getO();
746 double Step,An,Dist,Dis,S,Sl=0;
748 points.push_back(TVector3(R[0],R[1],R[2]));
749 pointPaths.push_back(0.);
751 An=A[0]*SU[0]+A[1]*SU[1]+A[2]*SU[2];
755 std::cerr <<
"RKTrackRep::RKutta ==> cannot propagate perpendicular to plane " << std::endl;
758 if( plane.
inActive(TVector3(R[0],R[1],R[2]),TVector3(A[0],A[1],A[2]))) {
759 Dist=SU[3]-R[0]*SU[0]-R[1]*SU[1]-R[2]*SU[2];
763 if( (O.X()-R[0])*A[0] + (O.Y()-R[1])*A[1] + (O.Z()-R[2])*A[2] >0 ){
764 Dist = sqrt((R[0]-O.X())*(R[0]-O.X())+
765 (R[1]-O.Y())*(R[1]-O.Y())+
766 (R[2]-O.Z())*(R[2]-O.Z()));
769 Dist = -1.*sqrt((R[0]-O.X())*(R[0]-O.X())+
770 (R[1]-O.Y())*(R[1]-O.Y())+
771 (R[2]-O.Z())*(R[2]-O.Z()));
776 if(fabs(Step)>Wmax) {
778 std::cerr<<
"RKTrackRep::RKutta ==> Too long extrapolation requested : "<<Step<<
" cm !"<<std::endl; std::cerr<<
"X = "<<R[0]<<
" Y = "<<R[1]<<
" Z = "<<R[2]
779 <<
" COSx = "<<A[0]<<
" 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__).
setFatal();
791 Step>Smax ? S=Smax : Step<-Smax ? S=-Smax : S=Step;
801 while(fabs(Step)>
MINSTEP && !stopBecauseOfMaterial) {
816 Ssign*A[0],Ssign*A[1],Ssign*A[2],
822 if (S > stepperLen) {
824 stopBecauseOfMaterial =
true;
826 else if (S < -stepperLen) {
828 stopBecauseOfMaterial =
true;
831 double H0[12],H1[12],H2[12],r[3];
832 double S3=P3*S, S4=.25*S, PS2=Pinv*S;
837 r[0]=R[0] ; r[1]=R[1] ; r[2]=R[2] ;
838 TVector3 pos(r[0],r[1],r[2]);
840 H0[0]=PS2*H0vect.X(); H0[1]=PS2*H0vect.Y(); H0[2]=PS2*H0vect.Z();
841 double A0=A[1]*H0[2]-A[2]*H0[1], B0=A[2]*H0[0]-A[0]*H0[2], C0=A[0]*H0[1]-A[1]*H0[0];
842 double A2=A[0]+A0 , B2=A[1]+B0 , C2=A[2]+C0 ;
843 double A1=A2+A[0] , B1=B2+A[1] , C1=C2+A[2] ;
848 r[0]+=A1*S4 ; r[1]+=B1*S4 ; r[2]+=C1*S4 ;
849 pos.SetXYZ(r[0],r[1],r[2]);
851 H1[0]=H1vect.X()*PS2; H1[1]=H1vect.Y()*PS2;H1[2]=H1vect.Z()*PS2;
852 double A3,B3,C3,A4,B4,C4,A5,B5,C5;
853 A3 = B2*H1[2]-C2*H1[1]+A[0]; B3=C2*H1[0]-A2*H1[2]+A[1]; C3=A2*H1[1]-B2*H1[0]+A[2];
854 A4 = B3*H1[2]-C3*H1[1]+A[0]; B4=C3*H1[0]-A3*H1[2]+A[1]; C4=A3*H1[1]-B3*H1[0]+A[2];
855 A5 = A4-A[0]+A4 ; B5=B4-A[1]+B4 ; C5=C4-A[2]+C4 ;
860 r[0]=R[0]+S*A4 ; r[1]=R[1]+S*B4 ; r[2]=R[2]+S*C4 ;
861 pos.SetXYZ(r[0],r[1],r[2]);
863 H2[0]=H2vect.X()*PS2; H2[1]=H2vect.Y()*PS2;H2[2]=H2vect.Z()*PS2;
864 double A6=B5*H2[2]-C5*H2[1], B6=C5*H2[0]-A5*H2[2], C6=A5*H2[1]-B5*H2[0];
869 double EST = fabs((A1+A6)-(A3+A4))+fabs((B1+B6)-(B3+B4))+fabs((C1+C6)-(C3+C4));
872 stopBecauseOfMaterial =
false;
880 for(
int i=7; i!=ND; i+=7) {
883 double* dA = &P[i+3];
886 double dA0 = H0[ 2]*dA[1]-H0[ 1]*dA[2];
887 double dB0 = H0[ 0]*dA[2]-H0[ 2]*dA[0];
888 double dC0 = H0[ 1]*dA[0]-H0[ 0]*dA[1];
890 if(i==ND1) {dA0+=A0; dB0+=B0; dC0+=C0;}
892 double dA2 = dA0+dA[0];
893 double dB2 = dB0+dA[1];
894 double dC2 = dC0+dA[2];
897 double dA3 = dA[0]+dB2*H1[2]-dC2*H1[1];
898 double dB3 = dA[1]+dC2*H1[0]-dA2*H1[2];
899 double dC3 = dA[2]+dA2*H1[1]-dB2*H1[0];
901 if(i==ND1) {dA3+=A3-A[0]; dB3+=B3-A[1]; dC3+=C3-A[2];}
903 double dA4 = dA[0]+dB3*H1[2]-dC3*H1[1];
904 double dB4 = dA[1]+dC3*H1[0]-dA3*H1[2];
905 double dC4 = dA[2]+dA3*H1[1]-dB3*H1[0];
907 if(i==ND1) {dA4+=A4-A[0]; dB4+=B4-A[1]; dC4+=C4-A[2];}
910 double dA5 = dA4+dA4-dA[0];
911 double dB5 = dB4+dB4-dA[1];
912 double dC5 = dC4+dC4-dA[2];
914 double dA6 = dB5*H2[2]-dC5*H2[1];
915 double dB6 = dC5*H2[0]-dA5*H2[2];
916 double dC6 = dA5*H2[1]-dB5*H2[0];
918 if(i==ND1) {dA6+=A6; dB6+=B6; dC6+=C6;}
920 dR[0]+=(dA2+dA3+dA4)*S3; dA[0] = (dA0+dA3+dA3+dA5+dA6)*P3;
921 dR[1]+=(dB2+dB3+dB4)*S3; dA[1] = (dB0+dB3+dB3+dB5+dB6)*P3;
922 dR[2]+=(dC2+dC3+dC4)*S3; dA[2] = (dC0+dC3+dC3+dC5+dC6)*P3;
927 if((Way+=fabs(S))>Wmax){
928 std::cerr<<
"PaAlgo::RKutta ==> Trajectory is longer than length limit : "<<Way<<
" cm !" 929 <<
" p/q = "<<1./P[6]<<
" GeV"<<std::endl;
936 R[0]+=(A2+A3+A4)*S3; A[0]+=(SA[0]=(A0+A3+A3+A5+A6)*P3-A[0]);
937 R[1]+=(B2+B3+B4)*S3; A[1]+=(SA[1]=(B0+B3+B3+B5+B6)*P3-A[1]);
938 R[2]+=(C2+C3+C4)*S3; A[2]+=(SA[2]=(C0+C3+C3+C5+C6)*P3-A[2]);
944 pointPaths.at(pointPaths.size()-1)+=S;
945 points.erase(points.end());
948 pointPaths.push_back(S);
951 points.push_back(TVector3(R[0],R[1],R[2]));
953 double CBA = 1./sqrt(A[0]*A[0]+A[1]*A[1]+A[2]*A[2]);
954 A[0]*=CBA; A[1]*=CBA; A[2]*=CBA;
957 if(fabs(Way2)>Wmax) {
966 An=A[0]*SU[0]+A[1]*SU[1]+A[2]*SU[2];
968 if( plane.
inActive(TVector3(R[0],R[1],R[2]),TVector3(A[0],A[1],A[2]))) {
969 Dis=SU[3]-R[0]*SU[0]-R[1]*SU[1]-R[2]*SU[2];
973 if( (O.X()-R[0])*A[0] + (O.Y()-R[1])*A[1] + (O.Z()-R[2])*A[2] >0 ){
974 Dis = sqrt((R[0]-O.X())*(R[0]-O.X())+
975 (R[1]-O.Y())*(R[1]-O.Y())+
976 (R[2]-O.Z())*(R[2]-O.Z()));
979 Dis = -1.*sqrt((R[0]-O.X())*(R[0]-O.X())+
980 (R[1]-O.Y())*(R[1]-O.Y())+
981 (R[2]-O.Z())*(R[2]-O.Z()));
987 if (Dis*Dist>0 && fabs(Dis)>fabs(Dist)) {
998 if (S*Step<0. || fabs(S)>fabs(Step)) S=Step;
999 else if (EST<DLT32 && fabs(2.*S)<=Smax) S*=2.;
1007 if (!stopBecauseOfMaterial) {
1009 A [0]+=(SA[0]*=Sl)*Step;
1010 A [1]+=(SA[1]*=Sl)*Step;
1011 A [2]+=(SA[2]*=Sl)*Step;
1013 P[0] = R[0]+Step*(A[0]-.5*Step*SA[0]);
1014 P[1] = R[1]+Step*(A[1]-.5*Step*SA[1]);
1015 P[2] = R[2]+Step*(A[2]-.5*Step*SA[2]);
1017 points.push_back(TVector3(P[0],P[1],P[2]));
1018 pointPaths.push_back(Step);
1021 double CBA = 1./sqrt(A[0]*A[0]+A[1]*A[1]+A[2]*A[2]);
1030 An = A[0]*SU[0]+A[1]*SU[1]+A[2]*SU[2];
1032 fabs(An) < 1.E-6 ? An=1./An : An = 0;
1034 if(calcCov && !stopBecauseOfMaterial){
1035 for(
int i=7; i!=ND; i+=7) {
1036 double* dR = &P[i];
double* dA = &P[i+3];
1037 S = (dR[0]*SU[0]+dR[1]*SU[1]+dR[2]*SU[2])*An;
1038 dR[0]-=S*A [0]; dR[1]-=S*A [1]; dR[2]-=S*A [2];
1039 dA[0]-=S*SA[0]; dA[1]-=S*SA[1]; dA[2]-=S*SA[2];
1045 std::cerr <<
"RKTrackRep::RKutta ==> Do not get closer. Path = " << Way <<
" cm" <<
" p/q = " << 1./P[6] <<
" GeV" << std::endl;
1050 if (!stopBecauseOfMaterial) coveredDistance=Way2+Step;
1051 else coveredDistance=Way2;
1061 static const int maxNumIt(2000);
1064 if(cov==NULL) calcCov=
false;
1067 if(calcCov)
std::fill(P, P + std::extent<decltype(P)>::
value, 0);
1070 for(
int i=0;i<7;++i){
1071 P[i] = (*state)[i][0];
1074 TMatrixT<Double_t> jac(7,7);
1075 TMatrixT<Double_t> jacT(7,7);
1076 TMatrixT<Double_t> oldCov(7,7);
1077 if(calcCov) oldCov=(*cov);
1078 double coveredDistance(0.);
1079 double sumDistance(0.);
1082 if(numIt++ > maxNumIt){
1083 throw GFException(
"RKTrackRep::Extrap ==> maximum number of iterations exceeded",
1088 memset(&P[7],0x00,49*
sizeof(
double));
1089 for(
int i=0; i<6; ++i){
1092 P[55] = (*state)[6][0];
1097 TVector3 Pvect(P[0],P[1],P[2]);
1098 TVector3 Avect(P[3],P[4],P[5]);
1099 TVector3 dist = plane.
dist(Pvect);
1108 TVector3 directionBefore(P[3],P[4],P[5]);
1109 directionBefore.SetMag(1.);
1112 std::vector<TVector3> points;
1113 std::vector<double> pointPaths;
1114 if( ! this->
RKutta(plane,P,coveredDistance,points,pointPaths,-1.,calcCov) ) {
1119 mf::LogInfo(
"RKTrackRep::RKutta(): ") <<
"Throw cet exception here, ... ";
1120 throw GFException(
"RKTrackRep::RKutta(): Runge Kutta propagation failed",
1124 TVector3 directionAfter(P[3],P[4],P[5]);
1125 directionAfter.SetMag(1.);
1127 sumDistance+=coveredDistance;
1130 std::vector<TVector3> pointsFilt(1, points.at(0));
1131 std::vector<double> pointPathsFilt(1, 0.);
1133 for(
unsigned int i=1;i<points.size();++i){
1134 if (pointPaths.at(i) * coveredDistance > 0.) {
1135 pointsFilt.push_back(points.at(i));
1136 pointPathsFilt.push_back(pointPaths.at(i));
1139 pointsFilt.back() = points.at(i);
1140 pointPathsFilt.back() += pointPaths.at(i);
1143 int position = pointsFilt.size()-1;
1144 if (fabs(pointPathsFilt.back()) <
MINSTEP && position > 1) {
1145 pointsFilt.at(position-1) = pointsFilt.at(position);
1146 pointsFilt.pop_back();
1147 pointPathsFilt.at(position-1) += pointPathsFilt.at(position);
1148 pointPathsFilt.pop_back();
1153 double checkSum(0.);
1154 for(
unsigned int i=0;i<pointPathsFilt.size();++i){
1155 checkSum+=pointPathsFilt.at(i);
1158 if(fabs(checkSum-coveredDistance)>1.
E-7){
1159 throw GFException(
"RKTrackRep::Extrap ==> fabs(checkSum-coveredDistance)>1.E-7",__LINE__,__FILE__).
setFatal();
1163 for(
int i=0;i<7;++i){
1164 for(
int j=0;j<7;++j){
1165 if(i<6) jac[i][j] = P[ (i+1)*7+j ];
1166 else jac[i][j] = P[ (i+1)*7+j ]/P[6];
1173 TMatrixT<Double_t>
noise(7,7);
1199 if(fabs(P[6])>1.
E-10){
1205 *cov = jacT*((oldCov)*jac)+
noise;
1211 if( plane.
inActive(TVector3(P[0],P[1],P[2]),TVector3(P[3],P[4],P[5]))) {
1215 (*state)[0][0] = P[0]; (*state)[1][0] = P[1];
1216 (*state)[2][0] = P[2]; (*state)[3][0] = P[3];
1217 (*state)[4][0] = P[4]; (*state)[5][0] = P[5];
1218 (*state)[6][0] = P[6];
1226 for(
int i=0;i<
fCov.GetNrows();++i){
1227 for(
int j=0;j<
fCov.GetNcols();++j){
1232 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
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
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.
std::string value(boost::any const &)
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
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.
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.