// are implemented.
// Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch //
///////////////////////////////////////////////////////////////////////////////
+#include <cassert>
+
+#include <TVectorD.h>
#include <TMatrixDSym.h>
#include <TPolyMarker3D.h>
#include <TVector3.h>
//
for (Int_t i = 0; i < 5; i++) fP[i] = track.fP[i];
for (Int_t i = 0; i < 15; i++) fC[i] = track.fC[i];
+ CheckCovariance();
}
//_____________________________________________________________________________
for (Int_t i = 0; i < 5; i++) fP[i] = trkPar.fP[i];
for (Int_t i = 0; i < 15; i++) fC[i] = trkPar.fC[i];
+ CheckCovariance();
}
return *this;
//
for (Int_t i = 0; i < 5; i++) fP[i] = param[i];
for (Int_t i = 0; i < 15; i++) fC[i] = covar[i];
+ CheckCovariance();
}
//_____________________________________________________________________________
fC[13] = b1/b3-b2*fC[8]/b3;
fC[9 ] = TMath::Abs((cv[20]-fC[14]*(m45*m45)-fC[13]*2.*m35*m45)/(m35*m35));
+ CheckCovariance();
+
return;
}
fC[3] +=c[3]; fC[4] +=c[4]; fC[5] +=c[5];
fC[6] +=c[6]; fC[7] +=c[7]; fC[8] +=c[8]; fC[9] +=c[9];
fC[10]+=c[10]; fC[11]+=c[11]; fC[12]+=c[12]; fC[13]+=c[13]; fC[14]+=c[14];
+ CheckCovariance();
}
y = -x*sn + y*cs; x=a;
xt-=x; yt-=y;
- sn=rp4*xt - fP[2]; cs=rp4*yt + TMath::Sqrt(1.- fP[2]*fP[2]);
- a=2*(xt*fP[2] - yt*TMath::Sqrt(1.- fP[2]*fP[2]))-rp4*(xt*xt + yt*yt);
+ sn=rp4*xt - fP[2]; cs=rp4*yt + TMath::Sqrt((1.- fP[2])*(1.+fP[2]));
+ a=2*(xt*fP[2] - yt*TMath::Sqrt((1.-fP[2])*(1.+fP[2])))-rp4*(xt*xt + yt*yt);
return -a/(1 + TMath::Sqrt(sn*sn + cs*cs));
}
// with respect to a point with global coordinates (x,y)
// in the magnetic field "b" (kG)
//------------------------------------------------------------------
- Double_t f1 = fP[2], r1 = TMath::Sqrt(1. - f1*f1);
+ Double_t f1 = fP[2], r1 = TMath::Sqrt((1.-f1)*(1.+f1));
Double_t xt=fX, yt=fP[0];
Double_t sn=TMath::Sin(fAlpha), cs=TMath::Cos(fAlpha);
Double_t a = x*cs + y*sn;
a=2*(xt*f1 - yt*r1)-rp4*(xt*xt + yt*yt);
Double_t rr=TMath::Sqrt(sn*sn + cs*cs);
dz[0] = -a/(1 + rr);
- Double_t f2 = -sn/rr, r2 = TMath::Sqrt(1. - f2*f2);
+ Double_t f2 = -sn/rr, r2 = TMath::Sqrt((1.-f2)*(1.+f2));
dz[1] = fP[1] + fP[3]/rp4*TMath::ASin(f2*r1 - f1*r2) - z;
}
Double_t x= xv*cs + yv*sn;
Double_t y=-xv*sn + yv*cs;
- Double_t d = (fX-x)*fP[2] - (fP[0]-y)*TMath::Sqrt(1.- fP[2]*fP[2]);
+ Double_t d = (fX-x)*fP[2] - (fP[0]-y)*TMath::Sqrt((1.-fP[2])*(1.+fP[2]));
return -d;
}
//Apply angle correction, if requested
if(anglecorr) {
- Double_t angle=TMath::Sqrt((1.+ fP3*fP3)/(1.- fP2*fP2));
+ Double_t angle=TMath::Sqrt((1.+ fP3*fP3)/((1-fP2)*(1.+fP2)));
xOverX0 *=angle;
xTimesRho *=angle;
}
Double_t theta2=14.1*14.1/(beta2*p2*1e6)*TMath::Abs(xOverX0);
//Double_t theta2=1.0259e-6*14*14/28/(beta2*p2)*TMath::Abs(d)*9.36*2.33;
if(theta2>TMath::Pi()*TMath::Pi()) return kFALSE;
- cC22 = theta2*(1.- fP2*fP2)*(1. + fP3*fP3);
+ cC22 = theta2*((1.-fP2)*(1.+fP2))*(1. + fP3*fP3);
cC33 = theta2*(1. + fP3*fP3)*(1. + fP3*fP3);
cC43 = theta2*fP3*fP4*(1. + fP3*fP3);
cC44 = theta2*fP3*fP4*fP3*fP4;
fC44 += cC44;
fP4 *= cP4;
+ CheckCovariance();
+
return kTRUE;
}
Double_t p=GetP();
Double_t p2=p*p;
Double_t beta2=p2/(p2 + mass*mass);
- d*=TMath::Sqrt((1.+ fP3*fP3)/(1.- fP2*fP2));
+ d*=TMath::Sqrt((1.+ fP3*fP3)/((1.-fP2)*(1.+fP2)));
//Multiple scattering******************
Double_t cC22 = 0.;
Double_t theta2=14.1*14.1/(beta2*p2*1e6)*TMath::Abs(d);
//Double_t theta2=1.0259e-6*14*14/28/(beta2*p2)*TMath::Abs(d)*9.36*2.33;
if(theta2>TMath::Pi()*TMath::Pi()) return kFALSE;
- cC22 = theta2*(1.- fP2*fP2)*(1. + fP3*fP3);
+ cC22 = theta2*(1.-fP2)*(1.+fP2)*(1. + fP3*fP3);
cC33 = theta2*(1. + fP3*fP3)*(1. + fP3*fP3);
cC43 = theta2*fP3*fP4*(1. + fP3*fP3);
cC44 = theta2*fP3*fP4*fP3*fP4;
fC44 += cC44;
fP4 *= cP4;
+ CheckCovariance();
+
return kTRUE;
}
Double_t x=fX;
Double_t ca=TMath::Cos(alpha-fAlpha), sa=TMath::Sin(alpha-fAlpha);
- Double_t sf=fP2, cf=TMath::Sqrt(1.- fP2*fP2);
+ Double_t sf=fP2, cf=TMath::Sqrt((1.- fP2)*(1.+fP2)); // Improve precision
Double_t tmp=sf*ca - cf*sa;
if (TMath::Abs(tmp) >= kAlmost1) {
- AliError(Form("Rotation failed ! %.10e",tmp));
+ if (TMath::Abs(tmp) > 1.+ Double_t(FLT_EPSILON))
+ AliWarning(Form("Rotation failed ! %.10e",tmp));
return kFALSE;
}
fC40 *= ca;
fC42 *= rr;
+ CheckCovariance();
+
return kTRUE;
}
&fC30=fC[6], &fC31=fC[7], &fC32=fC[8], &fC33=fC[9],
&fC40=fC[10], &fC41=fC[11], &fC42=fC[12], &fC43=fC[13], &fC44=fC[14];
- Double_t r1=TMath::Sqrt(1.- f1*f1), r2=TMath::Sqrt(1.- f2*f2);
+ Double_t r1=TMath::Sqrt((1.-f1)*(1.+f1)), r2=TMath::Sqrt((1.-f2)*(1.+f2));
fX=xk;
fP0 += dx*(f1+f2)/(r1+r2);
fC32 += b32;
fC42 += b42;
+ CheckCovariance();
+
return kTRUE;
}
return kFALSE;
}
+Bool_t AliExternalTrackParam::PropagateBxByBz
+(Double_t alpha, Double_t x, Double_t b[3]) {
+ //------------------------------------------------------------------
+ // Transform this track to the local coord. system rotated
+ // by angle "alpha" (rad) with respect to the global coord. system,
+ // and propagate this track to the plane X=xk (cm),
+ // taking into account all three components of the B field, "b[3]" (kG)
+ //------------------------------------------------------------------
+
+ //Save the parameters
+ Double_t as=fAlpha;
+ Double_t xs=fX;
+ Double_t ps[5], cs[15];
+ for (Int_t i=0; i<5; i++) ps[i]=fP[i];
+ for (Int_t i=0; i<15; i++) cs[i]=fC[i];
+
+ if (Rotate(alpha))
+ if (PropagateToBxByBz(x,b)) return kTRUE;
+
+ //Restore the parameters, if the operation failed
+ fAlpha=as;
+ fX=xs;
+ for (Int_t i=0; i<5; i++) fP[i]=ps[i];
+ for (Int_t i=0; i<15; i++) fC[i]=cs[i];
+ return kFALSE;
+}
+
void AliExternalTrackParam::Propagate(Double_t len, Double_t x[3],
Double_t p[3], Double_t bz) const {
Double_t f=GetSnp();
if (TMath::Abs(f) >= kAlmost1) return kVeryBig;
- Double_t r=TMath::Sqrt(1.- f*f);
+ Double_t r=TMath::Sqrt((1.-f)*(1.+f));
Double_t a=f/r, b=GetTgl()/r;
Double_t s2=333.*333.; //something reasonably big (cm^2)
for (Int_t j = 0; j < 3; j++) chi2 += res[i]*res[j]*v(i,j);
return chi2;
+}
+Double_t AliExternalTrackParam::
+GetPredictedChi2(const AliExternalTrackParam *t) const {
+ //----------------------------------------------------------------
+ // Estimate the chi2 (5 dof) of this track with respect to the track
+ // given by the argument.
+ // The two tracks must be in the same reference system
+ // and estimated at the same reference plane.
+ //----------------------------------------------------------------
+
+ if (TMath::Abs(1. - t->GetAlpha()/GetAlpha()) > FLT_EPSILON) {
+ AliError("The reference systems of the tracks differ !");
+ return kVeryBig;
+ }
+ if (TMath::Abs(1. - t->GetX()/GetX()) > FLT_EPSILON) {
+ AliError("The reference of the tracks planes differ !");
+ return kVeryBig;
+ }
+
+ TMatrixDSym c(5);
+ c(0,0)=GetSigmaY2();
+ c(1,0)=GetSigmaZY(); c(1,1)=GetSigmaZ2();
+ c(2,0)=GetSigmaSnpY(); c(2,1)=GetSigmaSnpZ(); c(2,2)=GetSigmaSnp2();
+ c(3,0)=GetSigmaTglY(); c(3,1)=GetSigmaTglZ(); c(3,2)=GetSigmaTglSnp(); c(3,3)=GetSigmaTgl2();
+ c(4,0)=GetSigma1PtY(); c(4,1)=GetSigma1PtZ(); c(4,2)=GetSigma1PtSnp(); c(4,3)=GetSigma1PtTgl(); c(4,4)=GetSigma1Pt2();
+
+ c(0,0)+=t->GetSigmaY2();
+ c(1,0)+=t->GetSigmaZY(); c(1,1)+=t->GetSigmaZ2();
+ c(2,0)+=t->GetSigmaSnpY();c(2,1)+=t->GetSigmaSnpZ();c(2,2)+=t->GetSigmaSnp2();
+ c(3,0)+=t->GetSigmaTglY();c(3,1)+=t->GetSigmaTglZ();c(3,2)+=t->GetSigmaTglSnp();c(3,3)+=t->GetSigmaTgl2();
+ c(4,0)+=t->GetSigma1PtY();c(4,1)+=t->GetSigma1PtZ();c(4,2)+=t->GetSigma1PtSnp();c(4,3)+=t->GetSigma1PtTgl();c(4,4)+=t->GetSigma1Pt2();
+ c(0,1)=c(1,0);
+ c(0,2)=c(2,0); c(1,2)=c(2,1);
+ c(0,3)=c(3,0); c(1,3)=c(3,1); c(2,3)=c(3,2);
+ c(0,4)=c(4,0); c(1,4)=c(4,1); c(2,4)=c(4,2); c(3,4)=c(4,3);
+
+ c.Invert();
+ if (!c.IsValid()) return kVeryBig;
+
+
+ Double_t res[5] = {
+ GetY() - t->GetY(),
+ GetZ() - t->GetZ(),
+ GetSnp() - t->GetSnp(),
+ GetTgl() - t->GetTgl(),
+ GetSigned1Pt() - t->GetSigned1Pt()
+ };
+ Double_t chi2=0.;
+ for (Int_t i = 0; i < 5; i++)
+ for (Int_t j = 0; j < 5; j++) chi2 += res[i]*res[j]*c(i,j);
+
+ return chi2;
}
Bool_t AliExternalTrackParam::
Double_t f=GetSnp();
if (TMath::Abs(f) >= kAlmost1) return kFALSE;
- Double_t r=TMath::Sqrt(1.- f*f);
+ Double_t r=TMath::Sqrt((1.-f)*(1.+f));
Double_t a=f/r, b=GetTgl()/r;
Double_t s2=333.*333.; //something reasonably big (cm^2)
fC44-=k40*c04+k41*c14;
+ CheckCovariance();
+
return kTRUE;
}
x-=xv; y-=yv;
//Estimate the impact parameter neglecting the track curvature
- Double_t d=TMath::Abs(x*snp - y*TMath::Sqrt(1.- snp*snp));
+ Double_t d=TMath::Abs(x*snp - y*TMath::Sqrt((1.-snp)*(1.+snp)));
if (d > maxd) return kFALSE;
//Propagate to the DCA
Double_t crv=GetC(b);
if (TMath::Abs(b) < kAlmost0Field) crv=0.;
- Double_t tgfv=-(crv*x - snp)/(crv*y + TMath::Sqrt(1.-snp*snp));
- sn=tgfv/TMath::Sqrt(1.+ tgfv*tgfv); cs=TMath::Sqrt(1.- sn*sn);
+ Double_t tgfv=-(crv*x - snp)/(crv*y + TMath::Sqrt((1.-snp)*(1.+snp)));
+ sn=tgfv/TMath::Sqrt(1.+ tgfv*tgfv); cs=TMath::Sqrt((1.-sn)*(1.+sn));
if (TMath::Abs(tgfv)>0.) cs = sn/tgfv;
else cs=1.;
return kTRUE;
}
+Bool_t AliExternalTrackParam::PropagateToDCABxByBz(const AliVVertex *vtx,
+Double_t b[3], Double_t maxd, Double_t dz[2], Double_t covar[3]) {
+ //
+ // Propagate this track to the DCA to vertex "vtx",
+ // if the (rough) transverse impact parameter is not bigger then "maxd".
+ //
+ // This function takes into account all three components of the magnetic
+ // field given by the b[3] arument (kG)
+ //
+ // a) The track gets extapolated to the DCA to the vertex.
+ // b) The impact parameters and their covariance matrix are calculated.
+ //
+ // In the case of success, the returned value is kTRUE
+ // (otherwise, it's kFALSE)
+ //
+ Double_t alpha=GetAlpha();
+ Double_t sn=TMath::Sin(alpha), cs=TMath::Cos(alpha);
+ Double_t x=GetX(), y=GetParameter()[0], snp=GetParameter()[2];
+ Double_t xv= vtx->GetX()*cs + vtx->GetY()*sn;
+ Double_t yv=-vtx->GetX()*sn + vtx->GetY()*cs, zv=vtx->GetZ();
+ x-=xv; y-=yv;
+
+ //Estimate the impact parameter neglecting the track curvature
+ Double_t d=TMath::Abs(x*snp - y*TMath::Sqrt((1.-snp)*(1.+snp)));
+ if (d > maxd) return kFALSE;
+
+ //Propagate to the DCA
+ Double_t crv=GetC(b[2]);
+ if (TMath::Abs(b[2]) < kAlmost0Field) crv=0.;
+
+ Double_t tgfv=-(crv*x - snp)/(crv*y + TMath::Sqrt((1.-snp)*(1.+snp)));
+ sn=tgfv/TMath::Sqrt(1.+ tgfv*tgfv); cs=TMath::Sqrt((1.-sn)*(1.+sn));
+ if (TMath::Abs(tgfv)>0.) cs = sn/tgfv;
+ else cs=1.;
+
+ x = xv*cs + yv*sn;
+ yv=-xv*sn + yv*cs; xv=x;
+
+ if (!PropagateBxByBz(alpha+TMath::ASin(sn),xv,b)) return kFALSE;
+
+ if (dz==0) return kTRUE;
+ dz[0] = GetParameter()[0] - yv;
+ dz[1] = GetParameter()[1] - zv;
+
+ if (covar==0) return kTRUE;
+ Double_t cov[6]; vtx->GetCovarianceMatrix(cov);
+
+ //***** Improvements by A.Dainese
+ alpha=GetAlpha(); sn=TMath::Sin(alpha); cs=TMath::Cos(alpha);
+ Double_t s2ylocvtx = cov[0]*sn*sn + cov[2]*cs*cs - 2.*cov[1]*cs*sn;
+ covar[0] = GetCovariance()[0] + s2ylocvtx; // neglecting correlations
+ covar[1] = GetCovariance()[1]; // between (x,y) and z
+ covar[2] = GetCovariance()[2] + cov[5]; // in vertex's covariance matrix
+ //*****
+
+ return kTRUE;
+}
void AliExternalTrackParam::GetDirection(Double_t d[3]) const {
//----------------------------------------------------------------
//----------------------------------------------------------------
Double_t cs=TMath::Cos(fAlpha), sn=TMath::Sin(fAlpha);
Double_t snp=fP[2];
- Double_t csp =TMath::Sqrt((1.- snp)*(1.+snp));
+ Double_t csp =TMath::Sqrt((1.-snp)*(1.+snp));
Double_t norm=TMath::Sqrt(1.+ fP[3]*fP[3]);
d[0]=(csp*cs - snp*sn)/norm;
d[1]=(snp*cs + csp*sn)/norm;
return p[1];
}
-Double_t AliExternalTrackParam::Pz() const {
- //---------------------------------------------------------------------
- // Returns z-component of momentum
- // Result for (nearly) straight tracks is meaningless !
- //---------------------------------------------------------------------
-
- Double_t p[3]={kVeryBig,kVeryBig,kVeryBig};
- GetPxPyPz(p);
-
- return p[2];
-}
-
Double_t AliExternalTrackParam::Xv() const {
//---------------------------------------------------------------------
// Returns x-component of first track point
return r[1];
}
-Double_t AliExternalTrackParam::Zv() const {
- //---------------------------------------------------------------------
- // Returns z-component of first track point
- //---------------------------------------------------------------------
-
- Double_t r[3]={0.,0.,0.};
- GetXYZ(r);
-
- return r[2];
-}
-
Double_t AliExternalTrackParam::Theta() const {
// return theta angle of momentum
* *
******************************************************************/
const Int_t ix=0, iy=1, iz=2, ipx=3, ipy=4, ipz=5, ipp=6;
+ const Double_t kOvSqSix=TMath::Sqrt(1./6.);
Double_t cosx=vect[ipx], cosy=vect[ipy], cosz=vect[ipz];
cos1t = 2*t*t/tet;
} else {
tsint = tet*tet/6.;
- sintt = 1.- tsint;
+ sintt = (1.-tet*kOvSqSix)*(1.+tet*kOvSqSix); // 1.- tsint;
sint = tet*sintt;
cos1t = 0.5*tet;
}
&fC30=fC[6], &fC31=fC[7], &fC32=fC[8], &fC33=fC[9],
&fC40=fC[10], &fC41=fC[11], &fC42=fC[12], &fC43=fC[13], &fC44=fC[14];
- Double_t r1=TMath::Sqrt(1.- f1*f1), r2=TMath::Sqrt(1.- f2*f2);
+ Double_t r1=TMath::Sqrt((1.-f1)*(1.+f1)), r2=TMath::Sqrt((1.-f2)*(1.+f2));
//f = F - 1
Double_t f02= dx/(r1*r1*r1); Double_t cc=crv/fP4;
fC32 += b32;
fC42 += b42;
+ CheckCovariance();
// Appoximate step length
Double_t step=dx*TMath::Abs(r2 + f2*(f1+f2)/(r1+r2));
translation.GetXYZ(vTrasl);
//compute the new x,y,z of the track
- Double_t NewX=fX-vTrasl[0];
- Double_t NewY=fP[0]-vTrasl[1];
- Double_t NewZ=fP[1]-vTrasl[2];
+ Double_t newX=fX-vTrasl[0];
+ Double_t newY=fP[0]-vTrasl[1];
+ Double_t newZ=fP[1]-vTrasl[2];
//define the new parameters
- Double_t NewParam[5];
- NewParam[0]=NewY;
- NewParam[1]=NewZ;
- NewParam[2]=fP[2];
- NewParam[3]=fP[3];
- NewParam[4]=fP[4];
+ Double_t newParam[5];
+ newParam[0]=newY;
+ newParam[1]=newZ;
+ newParam[2]=fP[2];
+ newParam[3]=fP[3];
+ newParam[4]=fP[4];
// recompute the covariance matrix:
// 1. covV in the local system
// set the new parameters
- Set(NewX,fAlpha,NewParam,newCov);
+ Set(newX,fAlpha,newParam,newCov);
return kTRUE;
}
+
+void AliExternalTrackParam::CheckCovariance() {
+
+ // This function forces the diagonal elements of the covariance matrix to be positive.
+ // In case the diagonal element is bigger than the maximal allowed value, it is set to
+ // the limit and the off-diagonal elements that correspond to it are set to zero.
+
+ fC[0] = TMath::Abs(fC[0]);
+ if (fC[0]>kC0max) {
+ fC[0] = kC0max;
+ fC[1] = 0;
+ fC[3] = 0;
+ fC[6] = 0;
+ fC[10] = 0;
+ }
+ fC[2] = TMath::Abs(fC[2]);
+ if (fC[2]>kC2max) {
+ fC[2] = kC2max;
+ fC[1] = 0;
+ fC[4] = 0;
+ fC[7] = 0;
+ fC[11] = 0;
+ }
+ fC[5] = TMath::Abs(fC[5]);
+ if (fC[5]>kC5max) {
+ fC[5] = kC5max;
+ fC[3] = 0;
+ fC[4] = 0;
+ fC[8] = 0;
+ fC[12] = 0;
+ }
+ fC[9] = TMath::Abs(fC[9]);
+ if (fC[9]>kC9max) {
+ fC[9] = kC9max;
+ fC[6] = 0;
+ fC[7] = 0;
+ fC[8] = 0;
+ fC[13] = 0;
+ }
+ fC[14] = TMath::Abs(fC[14]);
+ if (fC[14]>kC14max) {
+ fC[14] = kC14max;
+ fC[10] = 0;
+ fC[11] = 0;
+ fC[12] = 0;
+ fC[13] = 0;
+ }
+
+ // The part below is used for tests and normally is commented out
+// TMatrixDSym m(5);
+// TVectorD eig(5);
+
+// m(0,0)=fC[0];
+// m(1,0)=fC[1]; m(1,1)=fC[2];
+// m(2,0)=fC[3]; m(2,1)=fC[4]; m(2,2)=fC[5];
+// m(3,0)=fC[6]; m(3,1)=fC[7]; m(3,2)=fC[8]; m(3,3)=fC[9];
+// m(4,0)=fC[10]; m(4,1)=fC[11]; m(4,2)=fC[12]; m(4,3)=fC[13]; m(4,4)=fC[14];
+
+// m(0,1)=m(1,0);
+// m(0,2)=m(2,0); m(1,2)=m(2,1);
+// m(0,3)=m(3,0); m(1,3)=m(3,1); m(2,3)=m(3,2);
+// m(0,4)=m(4,0); m(1,4)=m(4,1); m(2,4)=m(4,2); m(3,4)=m(4,3);
+// m.EigenVectors(eig);
+
+// // assert(eig(0)>=0 && eig(1)>=0 && eig(2)>=0 && eig(3)>=0 && eig(4)>=0);
+// if (!(eig(0)>=0 && eig(1)>=0 && eig(2)>=0 && eig(3)>=0 && eig(4)>=0)) {
+// AliWarning("Negative eigenvalues of the covariance matrix!");
+// this->Print();
+// eig.Print();
+// }
+}