]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCtrack.cxx
Moving from base to calib, and adding packing interface (a packed value is simply...
[u/mrichter/AliRoot.git] / TPC / AliTPCtrack.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 /* $Id$ */
17
18 //-----------------------------------------------------------------
19 //           Implementation of the TPC track class
20 //        This class is used by the AliTPCtracker class
21 //      Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
22 //-----------------------------------------------------------------
23
24 #include <Riostream.h>
25
26 #include "AliTPCtrack.h"
27 #include "AliCluster.h"
28 #include "AliTracker.h"
29 #include "AliESDtrack.h"
30
31 ClassImp(AliTPCtrack)
32
33 //_________________________________________________________________________
34 AliTPCtrack::AliTPCtrack(): 
35   AliKalmanTrack(),
36   fdEdx(0),
37   fSdEdx(1e10),
38   fNFoundable(0),
39   fBConstrain(kFALSE),
40   fLastPoint(-1),
41   fFirstPoint(-1),
42   fRemoval(0),
43   fTrackType(0),
44   fLab2(-1),
45   fNShared(0),
46   fReference()
47 {
48   //-------------------------------------------------
49   // default constructor
50   //-------------------------------------------------
51   for (Int_t i=0; i<kMaxRow;i++) fIndex[i]=-2;
52   for (Int_t i=0; i<4;i++) fPoints[i]=0.;
53   for (Int_t i=0; i<12;i++) fKinkPoint[i]=0.;
54   for (Int_t i=0; i<3;i++) fKinkIndexes[i]=0;
55   for (Int_t i=0; i<3;i++) fV0Indexes[i]=0;
56 }
57
58 //_________________________________________________________________________
59
60
61
62 AliTPCtrack::AliTPCtrack(Double_t x, Double_t alpha, const Double_t p[5],
63                          const Double_t cov[15], Int_t index) :
64   AliKalmanTrack(),
65   fdEdx(0),
66   fSdEdx(1e10),
67   fNFoundable(0),
68   fBConstrain(kFALSE),
69   fLastPoint(0),
70   fFirstPoint(0),
71   fRemoval(0),
72   fTrackType(0),
73   fLab2(0),
74   fNShared(0),
75   fReference()
76 {
77   //-----------------------------------------------------------------
78   // This is the main track constructor.
79   //-----------------------------------------------------------------
80   Double_t cnv=1./(AliTracker::GetBz()*kB2C);
81
82   Double_t pp[5]={
83     p[0],
84     p[1],
85     x*p[4] - p[2],
86     p[3],
87     p[4]*cnv
88   };
89
90   Double_t c22 = x*x*cov[14] - 2*x*cov[12] + cov[5];
91   Double_t c32 = x*cov[13] - cov[8];
92   Double_t c20 = x*cov[10] - cov[3], 
93            c21 = x*cov[11] - cov[4], c42 = x*cov[14] - cov[12];
94
95   Double_t cc[15]={
96     cov[0 ],
97     cov[1 ],     cov[2 ],
98     c20,         c21,         c22,
99     cov[6 ],     cov[7 ],     c32,     cov[9 ],
100     cov[10]*cnv, cov[11]*cnv, c42*cnv, cov[13]*cnv, cov[14]*cnv*cnv
101   };
102
103   Double_t p0=TMath::Sign(1/kMostProbablePt,pp[4]);
104   Double_t w0=cc[14]/(cc[14] + p0*p0), w1=p0*p0/(cc[14] + p0*p0);
105   pp[4] = w0*p0 + w1*pp[4]; 
106   cc[10]*=w1; cc[11]*=w1; cc[12]*=w1; cc[13]*=w1; cc[14]*=w1;
107
108   Set(x,alpha,pp,cc);
109
110   SetNumberOfClusters(1);
111   
112   fIndex[0]=index;
113   for (Int_t i=1; i<kMaxRow;i++) fIndex[i]=-2;
114   for (Int_t i=0; i<4;i++) fPoints[i]=0.;
115   for (Int_t i=0; i<12;i++) fKinkPoint[i]=0.;
116   for (Int_t i=0; i<3;i++) fKinkIndexes[i]=0;
117   for (Int_t i=0; i<3;i++) fV0Indexes[i]=0;
118 }
119
120 //_____________________________________________________________________________
121 AliTPCtrack::AliTPCtrack(const AliESDtrack& t) :
122   AliKalmanTrack(),
123   fdEdx(t.GetTPCsignal()),
124   fSdEdx(1e10),
125   fNFoundable(0),
126   fBConstrain(kFALSE),
127   fLastPoint(0),
128   fFirstPoint(0),
129   fRemoval(0),
130   fTrackType(0),
131   fLab2(0),
132   fNShared(0),
133   fReference()
134 {
135   //-----------------------------------------------------------------
136   // Conversion AliESDtrack -> AliTPCtrack.
137   //-----------------------------------------------------------------
138   SetNumberOfClusters(t.GetTPCclusters(fIndex));
139   SetLabel(t.GetLabel());
140   SetMass(t.GetMass());
141   for (Int_t i=0; i<4;i++) fPoints[i]=0.;
142   for (Int_t i=0; i<12;i++) fKinkPoint[i]=0.;
143   for (Int_t i=0; i<3;i++) fKinkIndexes[i]=0;
144   for (Int_t i=0; i<3;i++) fV0Indexes[i]=0;
145
146   Set(t.GetX(),t.GetAlpha(),t.GetParameter(),t.GetCovariance());
147
148   if ((t.GetStatus()&AliESDtrack::kTIME) == 0) return;
149   StartTimeIntegral();
150   Double_t times[10]; t.GetIntegratedTimes(times); SetIntegratedTimes(times);
151   SetIntegratedLength(t.GetIntegratedLength());
152 }
153
154 //_____________________________________________________________________________
155 AliTPCtrack::AliTPCtrack(const AliTPCtrack& t) :
156   AliKalmanTrack(t),
157   fdEdx(t.fdEdx),
158   fSdEdx(t.fSdEdx),
159   fNFoundable(t.fNFoundable),
160   fBConstrain(t.fBConstrain),
161   fLastPoint(t.fLastPoint),
162   fFirstPoint(t.fFirstPoint),
163   fRemoval(t.fRemoval),
164   fTrackType(t.fTrackType),
165   fLab2(t.fLab2),
166   fNShared(t.fNShared),
167   fReference(t.fReference)
168
169 {
170   //-----------------------------------------------------------------
171   // This is a track copy constructor.
172   //-----------------------------------------------------------------
173   Set(t.GetX(),t.GetAlpha(),t.GetParameter(),t.GetCovariance());
174
175   for (Int_t i=0; i<kMaxRow; i++) fIndex[i]=t.fIndex[i];
176   for (Int_t i=0; i<4;i++) fPoints[i]=t.fPoints[i];
177   for (Int_t i=0; i<12;i++) fKinkPoint[i]=t.fKinkPoint[i];
178   for (Int_t i=0; i<3;i++) fKinkIndexes[i]=t.fKinkIndexes[i];
179   for (Int_t i=0; i<3;i++) fV0Indexes[i]=t.fV0Indexes[i];
180 }
181
182 //_____________________________________________________________________________
183 Int_t AliTPCtrack::Compare(const TObject *o) const {
184   //-----------------------------------------------------------------
185   // This function compares tracks according to the their curvature
186   //-----------------------------------------------------------------
187   AliTPCtrack *t=(AliTPCtrack*)o;
188   //Double_t co=TMath::Abs(t->Get1Pt());
189   //Double_t c =TMath::Abs(Get1Pt());
190   Double_t co=t->GetSigmaY2()*t->GetSigmaZ2();
191   Double_t c =GetSigmaY2()*GetSigmaZ2();
192   if (c>co) return 1;
193   else if (c<co) return -1;
194   return 0;
195 }
196
197 Double_t AliTPCtrack::GetPredictedChi2(const AliCluster *c) const {
198   //-----------------------------------------------------------------
199   // This function calculates a predicted chi2 increment.
200   //-----------------------------------------------------------------
201   Double_t p[2]={c->GetY(), c->GetZ()};
202   Double_t cov[3]={c->GetSigmaY2(), 0., c->GetSigmaZ2()};
203   return AliExternalTrackParam::GetPredictedChi2(p,cov);
204 }
205
206 //_____________________________________________________________________________
207 Bool_t AliTPCtrack::PropagateTo(Double_t xk,Double_t rho,Double_t x0) {
208   //-----------------------------------------------------------------
209   //  This function propagates a track to a reference plane x=xk.
210   //  rho - density of the crossed matrial (g/cm^3)
211   //  x0  - radiation length of the crossed material (g/cm^2) 
212   //-----------------------------------------------------------------
213   Double_t oldX=GetX(), oldY=GetY(), oldZ=GetZ();
214
215   Double_t bz=GetBz();
216   if (!AliExternalTrackParam::PropagateTo(xk,bz)) return kFALSE;
217
218   Double_t d = TMath::Sqrt((GetX()-oldX)*(GetX()-oldX) + 
219                            (GetY()-oldY)*(GetY()-oldY) + 
220                            (GetZ()-oldZ)*(GetZ()-oldZ));
221   if (IsStartedTimeIntegral() && GetX()>oldX) AddTimeStep(d);
222
223   if (oldX < xk) d = -d;
224   if (!AliExternalTrackParam::CorrectForMaterial(d*rho/x0,x0,GetMass())) 
225      return kFALSE;
226
227   return kTRUE;
228 }
229
230 //_____________________________________________________________________________
231 Bool_t 
232 AliTPCtrack::PropagateToVertex(const AliESDVertex *v,Double_t d,Double_t x0) 
233 {
234   //-----------------------------------------------------------------
235   // This function propagates tracks to the vertex.
236   //-----------------------------------------------------------------
237   Double_t bz=GetBz();
238   if (PropagateToDCA(v,bz,kVeryBig))
239    if (AliExternalTrackParam::CorrectForMaterial(d,x0,GetMass())) return kTRUE;
240   return kFALSE;
241 }
242
243 //_____________________________________________________________________________
244 Bool_t AliTPCtrack::Update(const AliCluster *c, Double_t chisq, Int_t index) {
245   //-----------------------------------------------------------------
246   // This function associates a cluster with this track.
247   //-----------------------------------------------------------------
248   Double_t p[2]={c->GetY(), c->GetZ()};
249   Double_t cov[3]={c->GetSigmaY2(), 0., c->GetSigmaZ2()};
250
251   if (!AliExternalTrackParam::Update(p,cov)) return kFALSE;
252
253   Int_t n=GetNumberOfClusters();
254   fIndex[n]=index;
255   SetNumberOfClusters(n+1);
256   SetChi2(GetChi2()+chisq);
257
258   return kTRUE;
259 }
260
261 ////////////////////////////////////////////////////////////////////////
262 // MI ADDITION
263
264 Float_t AliTPCtrack::Density(Int_t row0, Int_t row1)
265 {
266   //
267   // calculate cluster density
268   Int_t good  = 0;
269   Int_t found = 0;
270   //if (row0<fFirstPoint) row0 = fFirstPoint;
271   if (row1>fLastPoint) row1 = fLastPoint;
272
273   
274   for (Int_t i=row0;i<=row1;i++){ 
275     //    Int_t index = fClusterIndex[i];
276     Int_t index = fIndex[i];
277     if (index!=-1)  good++;
278     if (index>0)    found++;
279   }
280   Float_t density=0;
281   if (good>0) density = Float_t(found)/Float_t(good);
282   return density;
283 }
284
285
286 Float_t AliTPCtrack::Density2(Int_t row0, Int_t row1)
287 {
288   //
289   // calculate cluster density
290   Int_t good  = 0;
291   Int_t found = 0;
292   //  
293   for (Int_t i=row0;i<=row1;i++){     
294     Int_t index = fIndex[i];
295     if (index!=-1)  good++;
296     if (index>0)    found++;
297   }
298   Float_t density=0;
299   if (good>0) density = Float_t(found)/Float_t(good);
300   return density;
301 }
302
303 void  AliTPCtrack::UpdatePoints()
304 {
305   //--------------------------------------------------
306   //calculates first ,amx dens and last points
307   //--------------------------------------------------
308   Float_t density[160];
309   for (Int_t i=0;i<160;i++) density[i]=-1.;
310   fPoints[0]= 160;
311   fPoints[1] = -1;
312   //
313   Int_t ngood=0;
314   Int_t undeff=0;
315   Int_t nall =0;
316   Int_t range=20;
317   for (Int_t i=0;i<160;i++){
318     Int_t last = i-range;
319     if (nall<range) nall++;
320     if (last>=0){
321       if (fIndex[last]>0&& (fIndex[last]&0x8000)==0) ngood--;
322       if (fIndex[last]==-1) undeff--;
323     }
324     if (fIndex[i]>0&& (fIndex[i]&0x8000)==0)   ngood++;
325     if (fIndex[i]==-1) undeff++;
326     if (nall==range &&undeff<range/2) density[i-range/2] = Float_t(ngood)/Float_t(nall-undeff);
327   }
328   Float_t maxdens=0;
329   Int_t indexmax =0;
330   for (Int_t i=0;i<160;i++){
331     if (density[i]<0) continue;
332     if (density[i]>maxdens){
333       maxdens=density[i];
334       indexmax=i;
335     }
336   }
337   //
338   //max dens point
339   fPoints[3] = maxdens;
340   fPoints[1] = indexmax;
341   //
342   // last point
343   for (Int_t i=indexmax;i<160;i++){
344     if (density[i]<0) continue;
345     if (density[i]<maxdens/2.) {
346       break;
347     }
348     fPoints[2]=i;
349   }
350   //
351   // first point
352   for (Int_t i=indexmax;i>0;i--){
353     if (density[i]<0) continue;
354     if (density[i]<maxdens/2.) {
355       break;
356     }
357     fPoints[0]=i;
358   }
359   //
360 }
361
362 Double_t AliTPCtrack::GetBz() const {
363   //
364   // returns Bz component of the magnetic field (kG)
365   //
366   if (AliTracker::UniformField()) return AliTracker::GetBz();
367   Double_t r[3]; GetXYZ(r);
368   return AliTracker::GetBz(r);
369 }
370