14 #include "FairRunSim.h"
15 #include "FairRunAna.h"
16 #include "FairField.h"
32 if( FairRun::Instance()->IsAna() )
34 FairRunAna::Instance()->GetField()->GetFieldValue ( pnt, Bf );
36 FairRunSim::Instance()->GetField()->GetFieldValue ( pnt, Bf );
53 for(Int_t
i=0;
i<6;
i++) {
54 for(Int_t j=0; j<6; j++) {
56 if(j>=3) { cMat[
i-3][j-3] = tmpMat[
i][j]; }
57 else { cMat[
i-3][j+3] = tmpMat[
i][j]; }
59 if(j>=3) { cMat[
i+3][j-3] = tmpMat[
i][j]; }
60 else { cMat[
i+3][j+3] = tmpMat[
i][j]; }
72 for(Int_t
i=0;
i<6;
i++) {
73 for(Int_t j=0; j<6; j++) {
75 if(j>=3) { cMat[
i-3][j-3] = tmpMat[
i][j]; }
76 else { cMat[
i-3][j+3] = tmpMat[
i][j]; }
78 if(j>=3) { cMat[
i+3][j-3] = tmpMat[
i][j]; }
79 else { cMat[
i+3][j+3] = tmpMat[
i][j]; }
89 for(Int_t
i=0;
i<7;
i++) {
90 for(Int_t j=0; j<7; j++) {
92 if(j>=3) { cMat[
i-3][j-3] = tmpMat[
i][j]; }
93 else { cMat[
i-3][j+3] = tmpMat[
i][j]; }
95 if(j>=3) { cMat[
i+4][j-3] = tmpMat[
i][j]; }
96 else { cMat[
i+4][j+4] = tmpMat[
i][j]; }
107 for(Int_t
i=0;
i<7;
i++) {
108 for(Int_t j=0; j<7; j++) {
110 if(j>=4) { cMat[
i-4][j-4] = tmpMat[
i][j]; }
111 else { cMat[
i-4][j+3] = tmpMat[
i][j]; }
113 if(j>=4) { cMat[
i+3][j-4] = tmpMat[
i][j]; }
114 else { cMat[
i+3][j+3] = tmpMat[
i][j]; }
125 for(Int_t
i=0;
i<6;
i++) {
126 for(Int_t j=0; j<6; j++) {
128 if(j>=3) { cMat[
i-3][j-3] = tmpMat[
i][j]; }
129 else { cMat[
i-3][j+3] = tmpMat[
i][j]; }
131 if(j>=3) { cMat[
i+3][j-3] = tmpMat[
i][j]; }
132 else { cMat[
i+3][j+3] = tmpMat[
i][j]; }
143 for(
unsigned i=0;
i<3; ++
i) {
144 for(
unsigned j=
i; j<3; ++j) {
145 err[
i][j] = err[j][
i] = e[
i][j];
146 err[3+
i][3+j] = err[3+j][3+
i] = e[4+
i][4+j];
149 for(
unsigned i=0;
i<3; ++
i) {
150 for(
unsigned j=0; j<3; ++j) {
151 err[
i][3+j] = err[3+j][
i] = e[
i][4+j];
162 for(
unsigned i=0;
i<3; ++
i) {
163 for(
unsigned j=
i; j<3; ++j) {
164 hsm[
i][j] = hsm[j][
i] = e[
i][j];
165 hsm[4+
i][4+j] = hsm[4+j][4+
i] = e[3+
i][3+j];
168 for(
unsigned i=0;
i<3; ++
i) {
169 for(
unsigned j=0; j<3; ++j) {
170 hsm[
i][4+j] = hsm[4+j][
i] = e[
i][3+j];
173 double invE = 1./p.E();
174 hsm[0][3] = hsm[3][0] = (p.X()*hsm[0][0]+p.Y()*hsm[0][1]+p.Z()*hsm[0][2])*invE;
175 hsm[1][3] = hsm[3][1] = (p.X()*hsm[0][1]+p.Y()*hsm[1][1]+p.Z()*hsm[1][2])*invE;
176 hsm[2][3] = hsm[3][2] = (p.X()*hsm[0][2]+p.Y()*hsm[1][2]+p.Z()*hsm[2][2])*invE;
177 hsm[3][3] = (p.X()*p.X()*hsm[0][0]+p.Y()*p.Y()*hsm[1][1]+p.Z()*p.Z()*hsm[2][2]
178 +2.0*p.X()*p.Y()*hsm[0][1]
179 +2.0*p.X()*p.Z()*hsm[0][2]
180 +2.0*p.Y()*p.Z()*hsm[1][2])*invE*invE;
181 hsm[3][4] = hsm[4][3] = (p.X()*hsm[0][4]+p.Y()*hsm[1][4]+p.Z()*hsm[2][4])*invE;
182 hsm[3][5] = hsm[5][3] = (p.X()*hsm[0][5]+p.Y()*hsm[1][5]+p.Z()*hsm[2][5])*invE;
183 hsm[3][6] = hsm[6][3] = (p.X()*hsm[0][6]+p.Y()*hsm[1][6]+p.Z()*hsm[2][6])*invE;
244 if(p4.Perp()< 1e-9) {Warning(
"P7toHelix",
"Too small transverse momentum: %g",p4.Perp());
return kFALSE;}
270 const double xp = pos.X();
271 const double yp = pos.Y();
272 const double zp = pos.Z();
273 const double px = p4.Px();
274 const double py = p4.Py();
275 const double pz = p4.Pz();
280 if(
fVerbose>1) {
printf(
"P7ToHelix: P_t is %g GeV/c\n",p4.Perp()); }
284 const double rho = qBc*pti;
288 const double tanDip=pz*pti;
289 const double R0 = 1./rho;
291 if(
fVerbose>1) {
printf(
"P7ToHelix: R0 = rho^-1 is %g cm\n",R0); }
294 const double xc = xp - py/qBc;
295 const double yc = yp + px/qBc;
300 const double RCsq = xc*xc+yc*yc;
305 if(
fVerbose>1) {
printf(
"P7ToHelix: phi0 is %g, phiP is %g, DeltaPhi = %g \n",phi0,phip,phip-phi0); }
314 const double z0 = zp - pz*(phip-
phi0)/qBc;
322 helixparams[4]=tanDip;
324 for(
int ai=0; ai<5; ai++) {
325 std::cout<<
"helixparams["<<ai<<
"]="<<helixparams[ai]<<std::endl;
332 jacobian[0][0] = xc/RC;
333 jacobian[0][1] = yc/RC;
335 jacobian[0][3] = yc/(qBc*RC)-px*pti/
fabs(qBc);
336 jacobian[0][4] = -1.*xc/(qBc*RC)-py*pti/
fabs(qBc);
340 jacobian[1][0] = yc/(RCsq);
341 jacobian[1][1] = -1.*xc/(RCsq);
343 jacobian[1][3] = -1.*xc/(RCsq*qBc);
344 jacobian[1][4] = -1.*yc/(RCsq*qBc);
351 jacobian[2][3] = -1.*rho*px*pti*pti;
352 jacobian[2][4] = -1.*rho*py*pti*pti;
356 jacobian[3][0] = pz*yc/(RCsq*qBc);
357 jacobian[3][1] = -1.*pz*xc/(RCsq*qBc);
359 jacobian[3][3] = pz/qBc * (py*pti*pti + xc/(qBc*RCsq));
360 jacobian[3][4] = -1.*pz/qBc * (px*pti*pti - yc/(qBc*RCsq));
361 jacobian[3][5] = (phi0-phip)/qBc;
367 jacobian[4][3] = -1.*tanDip*px*pti*pti;
368 jacobian[4][4] = -1.*tanDip*py*pti*pti;
369 jacobian[4][5] = pti;
372 TMatrixD tempmat(jacobian,TMatrixD::kMult,cov77);
373 TMatrixD covrho(tempmat,TMatrixD::kMultTranspose,jacobian);
377 std::cout<<
"cov77: ";
380 std::cout<<
"jacobian: ";
382 std::cout<<
"covrho (D0,Phi0,rho,Z0,tanDip): ";
385 std::cout<<
"helixparams[0] = D0 \t= ("<<helixparams[0]<<
" \t+- "<<
sqrt(helixCov[0][0])<<
") cm"<<std::endl;
386 std::cout<<
"helixparams[1] = Phi0 \t= ("<<helixparams[1]<<
" \t+- "<<
sqrt(helixCov[1][1])<<
") rad"<<std::endl;
387 std::cout<<
"helixparams[2] = rho \t= ("<<helixparams[2]<<
" \t+- "<<
sqrt(helixCov[2][2])<<
") 1/cm"<<std::endl;
388 std::cout<<
"helixparams[3] = Z0 \t= ("<<helixparams[3]<<
" \t+- "<<
sqrt(helixCov[3][3])<<
") cm"<<std::endl;
389 std::cout<<
"helixparams[4] = tanDip\t= ("<<helixparams[4]<<
" \t+- "<<
sqrt(helixCov[4][4])<<
")"<<std::endl;
404 const double pt = p4.Perp();
406 Warning(
"P7toPRG",
"Too small transverse momentum: %g",pt);
411 const double B =
GetBz(pos);
412 const double qBc = -0.000299792458*B*Q;
419 const double xp = pos.X()-expPoint.X();
420 const double yp = pos.Y()-expPoint.Y();
421 const double zp = pos.Z()-expPoint.Z();
422 const double px = p4.Px();
423 const double py = p4.Py();
424 const double pz = p4.Pz();
425 const double p2 = px*px+py*py+pz*
pz;
426 const double p2i = (p2==0.)?0.:1./
p2;
427 const double pti = 1/
pt;
429 if(
fVerbose>1) {
printf(
"P7toPRG: x is [%8g,%8g,%8g] cm \n",xp,yp,zp); }
430 if(
fVerbose>1) {
printf(
"P7toPRG: p is [%8g,%8g,%8g] GeV/c \n",px,py,pz); }
432 const double phip = p4.Phi();
448 double eta = phip - TMath::ACos(xp/r);
449 double tht = p4.Theta();
451 helixparams[0] = r*
sin(eta);
452 helixparams[1] = zp - r*
cos(eta)/tan(tht);
453 helixparams[2] =
tht;
454 helixparams[3] = phip;
461 jacobian[0][1] = yp*
sin(eta)/r - xp*yp*
cos(eta)/(r*r*
TMath::Sqrt(1-xp*xp/(r*r)));
468 jacobian[1][0] =
TMath::Sqrt(1-xp*xp/(r*r))*
sin(eta)/tan(tht) - xp/r *
cos(eta)/tan(tht);
469 jacobian[1][1] = -(yp/r*
cos(eta)/tan(tht)+xp*yp/(r*
r)*
sin(eta)/tan(tht)/
TMath::Sqrt(1-xp*xp/(r*r)));
479 jacobian[2][3] = px*pz*pti*p2i;
480 jacobian[2][4] = py*pz*pti*p2i;
481 jacobian[2][5] = -pt*p2i;
487 jacobian[3][3] = -py*pti;
488 jacobian[3][4] = px*pti;
505 const double rho = qBc*pti;
506 const double R0 = 1./rho;
513 const double theta=p4.Theta();
518 const double xc = xp - py/qBc;
519 const double yc = yp + px/qBc;
520 const double RCsq = xc*xc + yc*yc;
526 const double epsilon = Q*(RC -
TMath::Abs(R0));
530 const double direction = TMath::Sign(1.,Q);
539 if(
fVerbose>1) {
printf(
"P7toPRG: phi0 = %.4g, \tphiP = %.4g, \tDeltaPhi = %.4g \tepsilon=%.4g, \tQ=%g\n",phi0,phip,phip-phi0, epsilon, Q); }
541 double xnew=epsilon*
sin(phi0);
542 double ynew=-epsilon*
cos(phi0);
543 printf(
"P7toPRG: xnew = %.4g, \tynew = %.4g, \t(x^2+y^2) = %.4g \tepsilon^2=%.4g\n",xnew,ynew,xnew*xnew+ynew*ynew, epsilon*epsilon);
547 const double z0 = zp - pz*(phip-
phi0)/qBc;
549 if(
fVerbose>1) {
printf(
"P7toPRG: z0 is %g cm from zp=%.3g cm\n",z0,zp); }
551 helixparams[0]=epsilon;
553 helixparams[2]=
theta;
557 for(
int ai=0; ai<5; ai++) {
558 std::cout<<
"helixparams["<<ai<<
"]="<<helixparams[ai]<<std::endl;
565 jacobian[0][0] = Q*xc/RC;
566 jacobian[0][1] = Q*yc/RC;
568 jacobian[0][3] = Q*(yc/(qBc*RC)-TMath::Sign(pti,R0)*px/qBc);
569 jacobian[0][4] = Q*(-xc/(qBc*RC)-TMath::Sign(pti,R0)*py/qBc);
573 jacobian[1][0] = -pz*yc/(RCsq*qBc);
574 jacobian[1][1] = pz*xc/(RCsq*qBc);
576 jacobian[1][3] = (py*pti*pti + xc/(qBc*RCsq))*pz/qBc;
577 jacobian[1][4] = -(px*pti*pti - yc/(qBc*RCsq))*pz/qBc;
578 jacobian[1][5] = -(phip-
phi0)/qBc;
585 jacobian[2][3] = px*pz*pti*p2i;
586 jacobian[2][4] = py*pz*pti*p2i;
587 jacobian[2][5] = -pt*p2i;
591 jacobian[3][0] = -yc/(RCsq);
592 jacobian[3][1] = xc/(RCsq);
594 jacobian[3][3] = xc/(RCsq*qBc);
595 jacobian[3][4] = yc/(RCsq*qBc);
602 jacobian[4][3] = -rho*px*pti*pti;
603 jacobian[4][4] = -rho*py*pti*pti;
610 TMatrixD tempmat(jacobian,TMatrixD::kMult,cov77);
611 TMatrixD covrho(tempmat,TMatrixD::kMultTranspose,jacobian);
615 std::cout<<
"cov77: ";
618 std::cout<<
"jacobian: ";
622 std::cout<<
"covrho (epsilon,Z0,Theta,Phi0,rho): ";
624 std::cout<<
"helixparams[0] = epsilon\t= ("<<helixparams[0]<<
" \t+- "<<
sqrt(helixCov[0][0])<<
") cm"<<std::endl;
625 std::cout<<
"helixparams[1] = Z0 \t= ("<<helixparams[1]<<
" \t+- "<<
sqrt(helixCov[1][1])<<
") cm"<<std::endl;
626 std::cout<<
"helixparams[2] = Theta \t= ("<<helixparams[2]<<
" \t+- "<<
sqrt(helixCov[2][2])<<
") rad"<<std::endl;
627 std::cout<<
"helixparams[3] = Phi0 \t= ("<<helixparams[3]<<
" \t+- "<<
sqrt(helixCov[3][3])<<
") rad"<<std::endl;
628 std::cout<<
"helixparams[4] = rho\t= ("<<helixparams[4]<<
" \t+- "<<
sqrt(helixCov[4][4])<<
") 1/cm"<<std::endl;
694 TVector3
pos = cand->
Pos();
695 TLorentzVector
mom = cand->
P4();
697 if(ztolerance>0. &&
fabs(cand->
Pos().Z()-
z) > ztolerance)
701 const double dz = z-pos.Z();
702 const double px = mom.Px();
703 const double py = mom.Py();
704 const double pzi = 1./mom.Pz();
706 const double B =
GetBz(pos);
707 const double a = -0.000299792458*B*cand->
Charge();
708 const double ai = 1./
a;
709 const double rho = a/mom.P();
710 const double rhoTimesS = a*dz*pzi;
711 const double L=
sin(rhoTimesS);
713 const double K=
sqrt(1-L*L);
716 for(
int i=0;
i<7;
i++) J[
i][
i]=1.;
729 J[3][5] = rho*pzi*(px*L+py*K);
730 J[4][5] = rho*pzi*(py*L-px*K);
732 double x1 = pos.X() + (L*px-(1.-K)*py)*ai;
733 double y1 = pos.Y() + (L*py+(1.-K)*px)*ai;
735 double px1 = px*K-py*
L;
736 double py1 = py*K+px*
L;
737 TMatrixD Jcov(J,TMatrixD::kMult,cov7);
738 TMatrixD newcov(Jcov,TMatrixD::kMultTranspose,J);
753 for(
int i=0;
i<6;
i++){
754 for(
int j=0;j<6;j++){
755 cov6[
i][j]=cov7[
i][j];
762 double ,
double ,
double vz,
double ztolerance=-1. )
798 TLorentzVector
mom = cand->
P4();
804 double p2=px*px+py*py+pz*
pz;
808 if (pz == 0. || p == 0.) {std::cout<<
"RhoCalculationTools::StateFromTrajectory(): Zero protection: pz="<<pz<<
" Gev/c p="<<p<<
" GeV/c"<<std::endl;
return kFALSE;}
819 J[2][5] = -pzi*state[2];
821 J[3][5] = -pzi*state[3];
822 J[4][3] = -px*state[4]*p2i;
823 J[4][4] = -py*state[4]*p2i;
824 J[4][5] = -pz*state[4]*p2i;
827 TMatrixD tempmat(J,TMatrixD::kMult,cov7);
828 TMatrixD cov5(tempmat,TMatrixD::kMultTranspose,J);
829 for(
int i=0;
i<5;
i++){
830 for(
int j=0;j<5;j++){
831 cov[
i][j]=cov5[
i][j];
849 TVector3
pos = cand->
Pos();
850 TLorentzVector
mom = cand->
P4();
852 const double dz = z-pos.Z();
853 const double px = mom.Px();
854 const double py = mom.Py();
855 const double pzi = 1./mom.Pz();
857 const double B =
GetBz(pos);
858 const double a = -0.000299792458*B*cand->
Charge();
859 const double ai = 1./
a;
860 const double rho = a/mom.P();
861 const double rhoTimesS = a*dz*pzi;
862 const double L=
sin(rhoTimesS);
864 const double K=
sqrt(1-L*L);
867 for(
int i=0;
i<7;
i++) J[
i][
i]=1.;
880 J[3][5] = rho*pzi*(px*L+py*K);
881 J[4][5] = rho*pzi*(py*L-px*K);
883 double x1 = pos.X() + (L*px-(1.-K)*py)*ai;
884 double y1 = pos.Y() + (L*py+(1.-K)*px)*ai;
886 double px1 = px*K-py*
L;
887 double py1 = py*K+px*
L;
888 TMatrixD Jcov(J,TMatrixD::kMult,cov7);
889 TMatrixD newcov(Jcov,TMatrixD::kMultTranspose,J);
933 Error(
"Print",
"Matrix is invalid");
936 const Int_t ncols = m.GetNcols();
937 const Int_t nrows = m.GetNrows();
938 const Int_t collwb = m.GetColLwb();
939 const Int_t rowlwb = m.GetRowLwb();
940 const Int_t nelems = m.GetNoElements();
942 const char *format =
"%11.4g ";
948 const char *topbarstart=
"-----";
950 snprintf(topbar,25,format,123.456789);
951 Int_t nch = strlen(topbar);
952 if (nch > 18) nch = 18;
954 const char *ftopbar=Form(
" %s%dd |",
"%",nch-5);
955 std::cout<<std::endl<<nrows<<
"x"<<ncols<<
" matrix is as follows"<<std::endl;
959 for (Int_t
i = 0;
i < nch;
i++) topbar[
i] =
'-';
962 std::cout<<std::endl<<std::endl<<
" |"<<std::flush;
963 for (Int_t j = 1; j <= ncols; j++)
965 std::cout<<Form(ftopbar,j+collwb-1)<<std::flush;
967 std::cout<<std::endl<<topbarstart;
968 for (Int_t j = 1; j <= ncols; j++) std::cout<<topbar;
969 std::cout<<std::endl;
971 if (nelems <= 0)
return;
972 for (Int_t
i = 1;
i <= nrows;
i++)
974 std::cout<<Form(
"%4d |",
i+rowlwb-1)<<std::flush;
975 for (Int_t j = 1; j <= ncols; j++)
977 std::cout<<Form(format,
m(
i+rowlwb-1,j+collwb-1))<<std::flush;
979 std::cout<<std::endl;
981 std::cout<<std::endl;
988 Error(
"Print",
"Matrix is invalid");
991 const Int_t ncols = m.GetNcols();
992 const Int_t nrows = m.GetNrows();
993 const Int_t collwb = m.GetColLwb();
994 const Int_t rowlwb = m.GetRowLwb();
995 const Int_t nelems = m.GetNoElements();
997 const char *format =
"%11.4g ";
1003 const char *topbarstart=
"-----";
1004 snprintf(topbar,25,format,123.456789);
1005 Int_t nch = strlen(topbar);
1006 if (nch > 18) nch = 18;
1007 if (nch < 7) nch = 7;
1008 const char *ftopbar=Form(
" %s%dd |",
"%",nch-5);
1009 std::cout<<std::endl<<nrows<<
"x"<<ncols<<
" matrix is as follows"<<std::endl;
1010 for (Int_t
i = 0;
i < nch;
i++) topbar[
i] =
'-';
1013 std::cout<<std::endl<<std::endl<<
" SYM |"<<std::flush;
1014 for (Int_t j = 1; j <= ncols; j++)
1016 std::cout<<Form(ftopbar,j+collwb-1)<<std::flush;
1018 std::cout<<std::endl<<topbarstart;
1019 for (Int_t j = 1; j <= ncols; j++) std::cout<<topbar;
1020 std::cout<<std::endl;
1022 if (nelems <= 0)
return;
1023 for (Int_t
i = 1;
i <= nrows;
i++)
1025 std::cout<<Form(
"%4d |",
i+rowlwb-1)<<std::flush;
1026 for (Int_t j = 1; j <= ncols; j++)
1029 std::cout<< (
i==j ?
"\e[1m" :
"\e[0m") <<Form(format,
m(i+rowlwb-1,j+collwb-1))<<
"\e[0m"<<std::flush;
1031 std::cout<<std::endl;
1033 std::cout<<std::endl;
1039 Error(
"Print",
"Matrix is invalid");
1042 const Int_t ncols = m.GetNcols();
1043 const Int_t nrows = m.GetNrows();
1044 const Int_t collwb = m.GetColLwb();
1045 const Int_t rowlwb = m.GetRowLwb();
1046 const Int_t nelems = m.GetNoElements();
1048 const char *format =
"%11.4g ";
1054 const char *topbarstart =
"-----";
1055 snprintf(topbar,25,format,123.456789);
1056 Int_t nch = strlen(topbar);
1057 if (nch > 18) nch = 18;
1058 if (nch < 7) nch = 7;
1059 const char *ftopbar=Form(
" %s%dd |",
"%",nch-5);
1060 std::cout<<std::endl<<nrows<<
"x"<<ncols<<
" matrix is as follows"<<std::endl;
1061 for (Int_t
i = 0;
i < nch;
i++) topbar[
i] =
'-';
1064 std::cout<<std::endl<<std::endl<<
" RHO |"<<std::flush;
1065 for (Int_t j = 1; j <= ncols; j++)
1067 std::cout<<Form(ftopbar,j+collwb-1)<<std::flush;
1069 std::cout<<std::endl<<topbarstart;
1070 for (Int_t j = 1; j <= ncols; j++) std::cout<<topbar;
1071 std::cout<<std::endl;
1073 if (nelems <= 0)
return;
1074 for (Int_t
i = 1;
i <= nrows;
i++)
1076 std::cout<<Form(
"%4d |",
i+rowlwb-1)<<std::flush;
1077 for (Int_t j = 1; j <= ncols; j++)
1080 std::cout<< (
i==j ?
"\e[1m" :
"\e[0m") <<Form(format,
m(i+rowlwb-1,j+collwb-1))<<
"\e[0m"<<std::flush;
1082 std::cout<<std::endl;
1084 std::cout<<std::endl;
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
friend F32vec4 cos(const F32vec4 &a)
void SetPos(const TVector3 &pos)
friend F32vec4 sqrt(const F32vec4 &a)
static T Sqrt(const T &x)
friend F32vec4 sin(const F32vec4 &a)
TString pt(TString pts, TString exts="px py pz")
void SetP4(Double_t mass, const TVector3 &p3)
static T ATan2(const T &y, const T &x)
TString tht(TString pts, TString exts="px py pz")
TLorentzVector P4() const
friend F32vec4 fabs(const F32vec4 &a)
void SetCov7(const TMatrixD &cov7)
TMatrixT< double > TMatrixD