]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDtrack.cxx
Bug fixes and code cleaning
[u/mrichter/AliRoot.git] / TRD / AliTRDtrack.cxx
CommitLineData
46d29e70 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
17$Log$
18Revision 1.1.2.1 2000/09/22 14:47:52 cblume
19Add the tracking code
20
21*/
22
23#include <iostream.h>
24
25#include <TObject.h>
26
27#include "AliTRD.h"
28#include "AliTRDconst.h"
29#include "AliTRDgeometry.h"
30#include "AliTRDcluster.h"
31#include "AliTRDtrack.h"
32
33ClassImp(AliTRDtrack)
34
35
36//_____________________________________________________________________________
37
38AliTRDtrack::AliTRDtrack(UInt_t index, const Double_t xx[5],
39const Double_t cc[15], Double_t xref, Double_t alpha) {
40 //-----------------------------------------------------------------
41 // This is the main track constructor.
42 //-----------------------------------------------------------------
43 fLab=-1;
44 fChi2=0.;
45 fdEdx=0.;
46
47 fAlpha=alpha;
48 fX=xref;
49
50 fY=xx[0]; fZ=xx[1]; fC=xx[2]; fE=xx[3]; fT=xx[4];
51
52 fCyy=cc[0];
53 fCzy=cc[1]; fCzz=cc[2];
54 fCcy=cc[3]; fCcz=cc[4]; fCcc=cc[5];
55 fCey=cc[6]; fCez=cc[7]; fCec=cc[8]; fCee=cc[9];
56 fCty=cc[10]; fCtz=cc[11]; fCtc=cc[12]; fCte=cc[13]; fCtt=cc[14];
57
58 fN=0;
59 fIndex[fN++]=index;
60}
61
62//_____________________________________________________________________________
63AliTRDtrack::AliTRDtrack(const AliTRDtrack& t) {
64 //
65 // Copy constructor.
66 //
67
68 fLab=t.fLab;
69
70 fChi2=t.fChi2;
71 fdEdx=t.fdEdx;
72
73 fAlpha=t.fAlpha;
74 fX=t.fX;
75
76 fY=t.fY; fZ=t.fZ; fC=t.fC; fE=t.fE; fT=t.fT;
77
78 fCyy=t.fCyy;
79 fCzy=t.fCzy; fCzz=t.fCzz;
80 fCcy=t.fCcy; fCcz=t.fCcz; fCcc=t.fCcc;
81 fCey=t.fCey; fCez=t.fCez; fCec=t.fCec; fCee=t.fCee;
82 fCty=t.fCty; fCtz=t.fCtz; fCtc=t.fCtc; fCte=t.fCte; fCtt=t.fCtt;
83
84 fN=t.fN;
85 for (Int_t i=0; i<fN; i++) fIndex[i]=t.fIndex[i];
86}
87
88//_____________________________________________________________________________
89void AliTRDtrack::GetCovariance(Double_t cc[15]) const {
90 cc[0]=fCyy;
91 cc[1]=fCzy; cc[2]=fCzz;
92 cc[3]=fCcy; cc[4]=fCcz; cc[5]=fCcc;
93 cc[6]=fCey; cc[7]=fCez; cc[8]=fCec; cc[9]=fCee;
94 cc[10]=fCty; cc[11]=fCtz; cc[12]=fCtc; cc[13]=fCte; cc[14]=fCtt;
95}
96
97//_____________________________________________________________________________
98Int_t AliTRDtrack::Compare(TObject *o) {
99
100// Compares tracks according to their Y2
101
102 AliTRDtrack *t=(AliTRDtrack*)o;
103 // Double_t co=t->GetSigmaY2();
104 // Double_t c =GetSigmaY2();
105
106 Double_t co=TMath::Abs(t->GetC());
107 Double_t c =TMath::Abs(GetC());
108
109 if (c>co) return 1;
110 else if (c<co) return -1;
111 return 0;
112}
113
114//_____________________________________________________________________________
115Int_t AliTRDtrack::PropagateTo(Double_t xk,Double_t x0,Double_t rho,Double_t pm)
116{
117 // Propagates a track of particle with mass=pm to a reference plane
118 // defined by x=xk through media of density=rho and radiationLength=x0
119
120 if (TMath::Abs(fC*xk - fE) >= 0.99999) {
121 if (fN>4) cerr<<fN<<" AliTRDtrack warning: Propagation failed !\n";
122 return 0;
123 }
124
125 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fY, z1=fZ;
126 Double_t c1=fC*x1 - fE, r1=sqrt(1.- c1*c1);
127 Double_t c2=fC*x2 - fE, r2=sqrt(1.- c2*c2);
128
129 fY += dx*(c1+c2)/(r1+r2);
130 fZ += dx*(c1+c2)/(c1*r2 + c2*r1)*fT;
131
132 //f = F - 1
133 Double_t rr=r1+r2, cc=c1+c2, xx=x1+x2;
134 Double_t f02= dx*(rr*xx + cc*(c1*x1/r1+c2*x2/r2))/(rr*rr);
135 Double_t f03=-dx*(2*rr + cc*(c1/r1 + c2/r2))/(rr*rr);
136 Double_t cr=c1*r2+c2*r1;
137 Double_t f12= dx*fT*(cr*xx-cc*(r1*x2-c2*c1*x1/r1+r2*x1-c1*c2*x2/r2))/(cr*cr);
138 Double_t f13=-dx*fT*(2*cr + cc*(c2*c1/r1-r1 + c1*c2/r2-r2))/(cr*cr);
139 Double_t f14= dx*cc/cr;
140
141 //b = C*ft
142 Double_t b00=f02*fCcy + f03*fCey, b01=f12*fCcy + f13*fCey + f14*fCty;
143 Double_t b10=f02*fCcz + f03*fCez, b11=f12*fCcz + f13*fCez + f14*fCtz;
144 Double_t b20=f02*fCcc + f03*fCec, b21=f12*fCcc + f13*fCec + f14*fCtc;
145 Double_t b30=f02*fCec + f03*fCee, b31=f12*fCec + f13*fCee + f14*fCte;
146 Double_t b40=f02*fCtc + f03*fCte, b41=f12*fCtc + f13*fCte + f14*fCtt;
147
148 //a = f*b = f*C*ft
149 Double_t a00=f02*b20+f03*b30,a01=f02*b21+f03*b31,a11=f12*b21+f13*b31+f14*b41;
150
151 //F*C*Ft = C + (a + b + bt)
152 fCyy += a00 + 2*b00;
153 fCzy += a01 + b01 + b10;
154 fCcy += b20;
155 fCey += b30;
156 fCty += b40;
157 fCzz += a11 + 2*b11;
158 fCcz += b21;
159 fCez += b31;
160 fCtz += b41;
161
162 fX=x2;
163
164
165 //Multiple scattering ******************
166
167 Double_t d=sqrt((x1-fX)*(x1-fX)+(y1-fY)*(y1-fY)+(z1-fZ)*(z1-fZ));
168 Double_t p2=GetPt()*GetPt()*(1.+fT*fT);
169 Double_t beta2=p2/(p2 + pm*pm);
170
171 Double_t ey=fC*fX - fE, ez=fT;
172 Double_t xz=fC*ez, zz1=ez*ez+1, xy=fE+ey;
173
174 Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho;
175 fCcc += xz*xz*theta2;
176 fCec += xz*ez*xy*theta2;
177 fCtc += xz*zz1*theta2;
178 fCee += (2*ey*ez*ez*fE+1-ey*ey+ez*ez+fE*fE*ez*ez)*theta2;
179 fCte += ez*zz1*xy*theta2;
180 fCtt += zz1*zz1*theta2;
181
182
183 //Energy losses************************
184
185 Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2)) - beta2)*d*rho;
186 if (x1 < x2) dE=-dE;
187 fC*=(1.- sqrt(p2+pm*pm)/p2*dE);
188 //fE*=(1.- sqrt(p2+pm*pm)/p2*dE);
189
190 return 1;
191
192}
193
194
195//_____________________________________________________________________________
196void AliTRDtrack::PropagateToVertex(Double_t x0,Double_t rho,Double_t pm)
197{
198 // This function propagates tracks to the "vertex".
199
200 Double_t c=fC*fX - fE;
201 Double_t tgf=-fE/(fC*fY + sqrt(1-c*c));
202 Double_t snf=tgf/sqrt(1.+ tgf*tgf);
203 Double_t xv=(fE+snf)/fC;
204 PropagateTo(xv,x0,rho,pm);
205}
206
207
208//_____________________________________________________________________________
209void AliTRDtrack::Update(const AliTRDcluster *c, Double_t chisq, UInt_t index)
210{
211 // Assignes found cluster to the track and updates track information
212
213 Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2()*12;
214 r00+=fCyy; r01+=fCzy; r11+=fCzz;
215 Double_t det=r00*r11 - r01*r01;
216 Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
217
218 Double_t k00=fCyy*r00+fCzy*r01, k01=fCyy*r01+fCzy*r11;
219 Double_t k10=fCzy*r00+fCzz*r01, k11=fCzy*r01+fCzz*r11;
220 Double_t k20=fCcy*r00+fCcz*r01, k21=fCcy*r01+fCcz*r11;
221 Double_t k30=fCey*r00+fCez*r01, k31=fCey*r01+fCez*r11;
222 Double_t k40=fCty*r00+fCtz*r01, k41=fCty*r01+fCtz*r11;
223
224 Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
225 Double_t cur=fC + k20*dy + k21*dz, eta=fE + k30*dy + k31*dz;
226 if (TMath::Abs(cur*fX-eta) >= 0.99999) {
227 if (fN>4) cerr<<fN<<" AliTRDtrack warning: Filtering failed !\n";
228 return;
229 }
230
231 fY += k00*dy + k01*dz;
232 fZ += k10*dy + k11*dz;
233 fC = cur;
234 fE = eta;
235 fT += k40*dy + k41*dz;
236
237 Double_t c01=fCzy, c02=fCcy, c03=fCey, c04=fCty;
238 Double_t c12=fCcz, c13=fCez, c14=fCtz;
239
240 fCyy-=k00*fCyy+k01*fCzy; fCzy-=k00*c01+k01*fCzz;
241 fCcy-=k00*c02+k01*c12; fCey-=k00*c03+k01*c13;
242 fCty-=k00*c04+k01*c14;
243
244 fCzz-=k10*c01+k11*fCzz;
245 fCcz-=k10*c02+k11*c12; fCez-=k10*c03+k11*c13;
246 fCtz-=k10*c04+k11*c14;
247
248 fCcc-=k20*c02+k21*c12; fCec-=k20*c03+k21*c13;
249 fCtc-=k20*c04+k21*c14;
250
251 fCee-=k30*c03+k31*c13;
252 fCte-=k30*c04+k31*c14;
253
254 fCtt-=k40*c04+k41*c14;
255
256 fIndex[fN++]=index;
257 fChi2 += chisq;
258
259 // cerr<<"in update: fIndex["<<fN<<"] = "<<index<<endl;
260}
261
262//_____________________________________________________________________________
263Int_t AliTRDtrack::Rotate(Double_t alpha)
264{
265 // Rotates track parameters in R*phi plane
266
267 fAlpha += alpha;
268
269 Double_t x1=fX, y1=fY;
270 Double_t ca=cos(alpha), sa=sin(alpha);
271 Double_t r1=fC*fX - fE;
272
273 fX = x1*ca + y1*sa;
274 fY=-x1*sa + y1*ca;
275 fE=fE*ca + (fC*y1 + sqrt(1.- r1*r1))*sa;
276
277 Double_t r2=fC*fX - fE;
278 if (TMath::Abs(r2) >= 0.99999) {
279 if (fN>4) cerr<<fN<<" AliTRDtrack warning: Rotation failed !\n";
280 return 0;
281 }
282
283 Double_t y0=fY + sqrt(1.- r2*r2)/fC;
284 if ((fY-y0)*fC >= 0.) {
285 if (fN>4) cerr<<fN<<" AliTRDtrack warning: Rotation failed !!!\n";
286 return 0;
287 }
288
289 //f = F - 1
290 Double_t f00=ca-1, f32=(y1 - r1*x1/sqrt(1.- r1*r1))*sa,
291 f30=fC*sa, f33=(ca + sa*r1/sqrt(1.- r1*r1))-1;
292
293 //b = C*ft
294 Double_t b00=fCyy*f00, b03=fCyy*f30+fCcy*f32+fCey*f33;
295 Double_t b10=fCzy*f00, b13=fCzy*f30+fCcz*f32+fCez*f33;
296 Double_t b20=fCcy*f00, b23=fCcy*f30+fCcc*f32+fCec*f33;
297 Double_t b30=fCey*f00, b33=fCey*f30+fCec*f32+fCee*f33;
298 Double_t b40=fCty*f00, b43=fCty*f30+fCtc*f32+fCte*f33;
299
300 //a = f*b = f*C*ft
301 Double_t a00=f00*b00, a03=f00*b03, a33=f30*b03+f32*b23+f33*b33;
302
303 // *** Double_t dy2=fCyy;
304
305 //F*C*Ft = C + (a + b + bt)
306 fCyy += a00 + 2*b00;
307 fCzy += b10;
308 fCcy += b20;
309 fCey += a03+b30+b03;
310 fCty += b40;
311 fCez += b13;
312 fCec += b23;
313 fCee += a33 + 2*b33;
314 fCte += b43;
315
316 // *** fCyy+=dy2*sa*sa*r1*r1/(1.- r1*r1);
317 // *** fCzz+=d2y*sa*sa*fT*fT/(1.- r1*r1);
318
319 return 1;
320}
321
322
323
324
325//_____________________________________________________________________________
326Double_t AliTRDtrack::GetPredictedChi2(const AliTRDcluster *c) const
327{
328 Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2()*12;
329 r00+=fCyy; r01+=fCzy; r11+=fCzz;
330
331 Double_t det=r00*r11 - r01*r01;
332 if (TMath::Abs(det) < 1.e-10) {
333 if (fN>4) cerr<<fN<<" AliTRDtrack warning: Singular matrix !\n";
334 return 1e10;
335 }
336 Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
337
338 Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
339
340 return (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
341}
342
343
344//_________________________________________________________________________
345void AliTRDtrack::GetPxPyPz(Double_t& px, Double_t& py, Double_t& pz) const
346{
347 // Returns reconstructed track momentum in the global system.
348
349 Double_t pt=TMath::Abs(GetPt()); // GeV/c
350 Double_t r=fC*fX-fE;
351 Double_t y0=fY + sqrt(1.- r*r)/fC;
352 px=-pt*(fY-y0)*fC; //cos(phi);
353 py=-pt*(fE-fX*fC); //sin(phi);
354 pz=pt*fT;
355 Double_t tmp=px*TMath::Cos(fAlpha) - py*TMath::Sin(fAlpha);
356 py=px*TMath::Sin(fAlpha) + py*TMath::Cos(fAlpha);
357 px=tmp;
358
359}
360
361//____________________________________________________________________________
362void AliTRDtrack::Streamer(TBuffer &R__b)
363{
364 if (R__b.IsReading()) {
365 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
366 TObject::Streamer(R__b);
367 R__b >> fLab;
368 R__b >> fChi2;
369 R__b >> fdEdx;
370 R__b >> fAlpha;
371 R__b >> fX;
372 R__b >> fY;
373 R__b >> fZ;
374 R__b >> fC;
375 R__b >> fE;
376 R__b >> fT;
377 R__b >> fCyy;
378 R__b >> fCzy;
379 R__b >> fCzz;
380 R__b >> fCcy;
381 R__b >> fCcz;
382 R__b >> fCcc;
383 R__b >> fCey;
384 R__b >> fCez;
385 R__b >> fCec;
386 R__b >> fCee;
387 R__b >> fCty;
388 R__b >> fCtz;
389 R__b >> fCtc;
390 R__b >> fCte;
391 R__b >> fCtt;
392 R__b >> fN;
393 for (Int_t i=0; i<fN; i++) R__b >> fIndex[i];
394 } else {
395 R__b.WriteVersion(AliTRDtrack::IsA());
396 TObject::Streamer(R__b);
397 R__b << fLab;
398 R__b << fChi2;
399 R__b << fdEdx;
400 R__b << fAlpha;
401 R__b << fX;
402 R__b << fY;
403 R__b << fZ;
404 R__b << fC;
405 R__b << fE;
406 R__b << fT;
407 R__b << fCyy;
408 R__b << fCzy;
409 R__b << fCzz;
410 R__b << fCcy;
411 R__b << fCcz;
412 R__b << fCcc;
413 R__b << fCey;
414 R__b << fCez;
415 R__b << fCec;
416 R__b << fCee;
417 R__b << fCty;
418 R__b << fCtz;
419 R__b << fCtc;
420 R__b << fCte;
421 R__b << fCtt;
422 R__b << fN;
423 for (Int_t i=0; i<fN; i++) R__b << fIndex[i];
424 }
425}
426
427//_____________________________________________________________________________
428void AliTRDseed::CookdEdx(Double_t low, Double_t up) {
429
430 // Calculates dE/dX within the "low" and "up" cuts.
431
432 Int_t i;
433 Int_t nc=this->GetNclusters();
434
435 Int_t swap;//stupid sorting
436 do {
437 swap=0;
438 for (i=0; i<nc-1; i++) {
439 if (fdEdx[i]<=fdEdx[i+1]) continue;
440 Float_t tmp=fdEdx[i]; fdEdx[i]=fdEdx[i+1]; fdEdx[i+1]=tmp;
441 swap++;
442 }
443 } while (swap);
444
445 Int_t nl=Int_t(low*nc), nu=Int_t(up*nc);
446 Float_t dedx=0;
447 for (i=nl; i<=nu; i++) dedx += fdEdx[i];
448 dedx /= (nu-nl+1);
449 SetdEdx(dedx);
450}
451