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