1 #include "TMatrixDSym.h"
3 #include "AliTrackFitterStraight.h"
5 ClassImp(AliTrackFitterStraight)
7 AliTrackFitterStraight::AliTrackFitterStraight():
11 // default constructor
14 for (Int_t i=0;i<5;i++) fSumXY[i] = 0;
16 for (Int_t i=0;i<5;i++) fSumXZ[i] = 0;
23 AliTrackFitterStraight::AliTrackFitterStraight(AliTrackPointArray *array, Bool_t owner):
24 AliTrackFitter(array,owner)
30 for (Int_t i=0;i<5;i++) fSumXY[i] = 0;
32 for (Int_t i=0;i<5;i++) fSumXZ[i] = 0;
38 AliTrackFitterStraight::AliTrackFitterStraight(const AliTrackFitterStraight &fitter):
39 AliTrackFitter(fitter)
44 fAlpha = fitter.fAlpha;
45 for (Int_t i=0;i<5;i++) fSumXY[i] = fitter.fSumXY[i];
46 fSumYY = fitter.fSumYY;
47 for (Int_t i=0;i<5;i++) fSumXZ[i] = fitter.fSumXZ[i];
48 fSumZZ = fitter.fSumZZ;
49 fNUsed = fitter.fNUsed;
53 //_____________________________________________________________________________
54 AliTrackFitterStraight &AliTrackFitterStraight::operator =(const AliTrackFitterStraight& fitter)
56 // assignment operator
58 if(this==&fitter) return *this;
59 ((AliTrackFitter *)this)->operator=(fitter);
61 fAlpha = fitter.fAlpha;
62 for (Int_t i=0;i<5;i++) fSumXY[i] = fitter.fSumXY[i];
63 fSumYY = fitter.fSumYY;
64 for (Int_t i=0;i<5;i++) fSumXZ[i] = fitter.fSumXZ[i];
65 fSumZZ = fitter.fSumZZ;
66 fNUsed = fitter.fNUsed;
72 AliTrackFitterStraight::~AliTrackFitterStraight()
78 void AliTrackFitterStraight::Reset()
80 // Reset the track parameters and
82 AliTrackFitter::Reset();
84 for (Int_t i=0;i<5;i++) fSumXY[i] = 0;
86 for (Int_t i=0;i<5;i++) fSumXZ[i] = 0;
92 Bool_t AliTrackFitterStraight::Fit(const TArrayI *volIds,const TArrayI *volIdsFit,
93 AliAlignObj::ELayerID layerRangeMin,
94 AliAlignObj::ELayerID layerRangeMax)
96 // Fit the track points. The method takes as an input
97 // the set of id's (volids) of the volumes in which
98 // one wants to calculate the residuals.
99 // The following parameters are used to define the
100 // range of volumes to be used in the fitting
101 // As a result two AliTrackPointArray's obects are filled.
102 // The first one contains the space points with
103 // volume id's from volids list. The second array of points represents
104 // the track extrapolations corresponding to the space points
105 // in the first array. The two arrays can be used to find
106 // the residuals in the volids and consequently construct a
107 // chi2 function to be minimized during the alignment
108 // procedures. For the moment the track extrapolation is taken
109 // at the space-point reference plane. The reference plane is
110 // found using the covariance matrix of the point
111 // (assuming sigma(x)=0 at the reference coordinate system.
115 Int_t npoints = fPoints->GetNPoints();
116 if (npoints < 2) return kFALSE;
118 Bool_t isAlphaCalc = kFALSE;
119 AliTrackPoint p,plocal;
123 Int_t *pindex = new Int_t[npoints];
124 for (Int_t ipoint = 0; ipoint < npoints; ipoint++)
126 fPoints->GetPoint(p,ipoint);
127 UShort_t iVolId = p.GetVolumeID();
128 if (FindVolId(volIds,iVolId)) {
129 pindex[npVolId] = ipoint;
132 if (volIdsFit != 0x0) {
133 if (!FindVolId(volIdsFit,iVolId)) continue;
136 if (iVolId < AliAlignObj::LayerToVolUID(layerRangeMin,0) ||
137 iVolId > AliAlignObj::LayerToVolUID(layerRangeMax,
138 AliAlignObj::LayerSize(layerRangeMax-
139 AliAlignObj::kFirstLayer))) continue;
142 fAlpha = p.GetAngle();
145 plocal = p.Rotate(fAlpha);
146 AddPoint(plocal.GetX(),plocal.GetY(),plocal.GetZ(),
147 TMath::Sqrt(plocal.GetCov()[3]),TMath::Sqrt(plocal.GetCov()[5]));
163 if (fNUsed < fMinNPoints ) {
168 fPVolId = new AliTrackPointArray(npVolId);
169 fPTrack = new AliTrackPointArray(npVolId);
171 for (Int_t ipoint = 0; ipoint < npVolId; ipoint++)
173 Int_t index = pindex[ipoint];
174 fPoints->GetPoint(p,index);
176 Float_t xyz[3],xyz2[3];
177 p.GetXYZ(xyz); p2.GetXYZ(xyz2);
178 // printf("residuals %f %d %d %f %f %f %f %f %f\n",fChi2,fNUsed,fConv,xyz[0],xyz[1],xyz[2],xyz2[0]-xyz[0],xyz2[1]-xyz[1],xyz2[2]-xyz[2]);
179 fPVolId->AddPoint(ipoint,&p);
180 fPTrack->AddPoint(ipoint,&p2);
189 void AliTrackFitterStraight::AddPoint(Float_t x, Float_t y, Float_t z, Float_t sy, Float_t sz)
191 // Straight track fitter
192 // The method add a point to the sums
193 // used to extract track parameters
198 Double_t weight = 1./(sy*sy);
200 fSumXY[1] +=x*weight; fSumXY[2] +=x*x*weight;
201 fSumXY[3] +=y*weight; fSumXY[4] +=x*y*weight;
202 fSumYY += y*y*weight;
208 fSumXZ[1] +=x*weight; fSumXZ[2] +=x*x*weight;
209 fSumXZ[3] +=z*weight; fSumXZ[4] +=x*z*weight;
210 fSumZZ += z*z*weight;
213 void AliTrackFitterStraight::Update(){
215 // Track fitter update
218 for (Int_t i=0;i<6;i++)fParams[i]=0;
225 TMatrixDSym smatrix(2);
227 smatrix(0,0) = fSumXY[0]; smatrix(1,1)=fSumXY[2];
228 smatrix(0,1) = fSumXY[1];
229 sums(0,0) = fSumXY[3]; sums(0,1) =fSumXY[4];
231 if (smatrix.IsValid()){
232 for (Int_t i=0;i<2;i++)
233 for (Int_t j=0;j<=i;j++){
234 (*fCov)(i,j)=smatrix(i,j);
236 TMatrixD res = sums*smatrix;
237 fParams[0] = res(0,0);
238 fParams[1] = res(0,1);
239 TMatrixD tmp = res*sums.T();
240 fChi2 += fSumYY - tmp(0,0);
247 TMatrixDSym smatrixz(2);
248 TMatrixD sumsxz(1,2);
249 smatrixz(0,0) = fSumXZ[0]; smatrixz(1,1) = fSumXZ[2];
250 smatrixz(0,1) = fSumXZ[1];
251 sumsxz(0,0) = fSumXZ[3]; sumsxz(0,1) = fSumXZ[4];
253 if (smatrixz.IsValid()){
254 TMatrixD res = sumsxz*smatrixz;
255 fParams[2] = res(0,0);
256 fParams[3] = res(0,1);
257 fParams[4] = fParams[5] = 0;
258 for (Int_t i=0;i<2;i++)
259 for (Int_t j=0;j<=i;j++){
260 (*fCov)(i+2,j+2)=smatrixz(i,j);
262 TMatrixD tmp = res*sumsxz.T();
263 fChi2 += fSumZZ - tmp(0,0);
274 Double_t AliTrackFitterStraight::GetYat(Double_t x) const {
275 if (!fConv) return 0.;
276 return (fParams[0]+x*fParams[1]);
279 Double_t AliTrackFitterStraight::GetDYat(Double_t x) const {
280 if (!fConv) return 0.;
281 return fParams[1]+0.*x;
286 Double_t AliTrackFitterStraight::GetZat(Double_t x) const {
287 if (!fConv) return 0.;
288 return (fParams[2]+x*fParams[3]);
291 Double_t AliTrackFitterStraight::GetDZat(Double_t x) const {
292 if (!fConv) return 0.;
293 return fParams[3]+0.*x;
296 Bool_t AliTrackFitterStraight::GetXYZat(Double_t r, Float_t *xyz) const {
297 if (!fConv) return kFALSE;
298 Double_t y = (fParams[0]+r*fParams[1]);
299 Double_t z = (fParams[2]+r*fParams[3]);
301 Double_t sin = TMath::Sin(fAlpha);
302 Double_t cos = TMath::Cos(fAlpha);
303 xyz[0] = r*cos - y*sin;
304 xyz[1] = y*cos + r*sin;
310 Bool_t AliTrackFitterStraight::GetPCA(const AliTrackPoint &p, AliTrackPoint &p2) const
312 // Get the closest to a given spacepoint track trajectory point
313 // Look for details in the description of the Fit() method
315 if (!fConv) return kFALSE;
317 // First X and Y coordinates
318 Double_t sin = TMath::Sin(fAlpha);
319 Double_t cos = TMath::Cos(fAlpha);
320 // Track parameters in the global coordinate system
321 Double_t x0 = -fParams[0]*sin;
322 Double_t y0 = fParams[0]*cos;
323 if ((cos - fParams[1]*sin) == 0) return kFALSE;
324 Double_t dydx = (fParams[1]*cos + sin)/(cos - fParams[1]*sin);
326 // Define space-point refence plane
327 Double_t alphap = p.GetAngle();
328 Double_t sinp = TMath::Sin(alphap);
329 Double_t cosp = TMath::Cos(alphap);
330 Double_t x = p.GetX()*cosp + p.GetY()*sinp;
331 // Double_t y = p.GetY()*cosp - p.GetX()*sinp;
332 Double_t x0p= x0*cosp + y0*sinp;
333 Double_t y0p= y0*cosp - x0*sinp;
334 if ((cos + dydx*sin) == 0) return kFALSE;
335 Double_t dydxp = (dydx*cos - sin)/(cos + dydx*sin);
336 Double_t yprime = y0p + dydxp*(x-x0p);
338 // Back to the global coordinate system
339 Double_t xsecond = x*cosp - yprime*sinp;
340 Double_t ysecond = yprime*cosp + x*sinp;
342 // Now Z coordinate and track angles
343 Double_t x2 = xsecond*cos + ysecond*sin;
344 Double_t zsecond = GetZat(x2);
345 Double_t dydx2 = fParams[1];
346 Double_t dzdx = fParams[3];
348 // Fill the cov matrix of the track extrapolation point
349 Double_t cov[6] = {0,0,0,0,0,0};
350 Double_t sigmax = 100*100.;
351 cov[0] = sigmax; cov[1] = sigmax*dydx2; cov[2] = sigmax*dzdx;
352 cov[3] = sigmax*dydx2*dydx2; cov[4] = sigmax*dydx2*dzdx;
353 cov[5] = sigmax*dzdx*dzdx;
356 newcov[0] = cov[0]*cos*cos-
359 newcov[1] = cov[1]*(cos*cos-sin*sin)-
360 (cov[3]-cov[0])*sin*cos;
361 newcov[2] = cov[2]*cos-
363 newcov[3] = cov[0]*sin*sin+
366 newcov[4] = cov[4]*cos+
370 p2.SetXYZ(xsecond,ysecond,zsecond,newcov);