]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDtrack.cxx
Recreate the file with tracklets. Remove the additional check which is not needed...
[u/mrichter/AliRoot.git] / STEER / AliESDtrack.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 //           Implementation of the ESD track class
17 //   ESD = Event Summary Data
18 //   This is the class to deal with during the phisics analysis of data
19 //      Origin: Iouri Belikov, CERN
20 //      e-mail: Jouri.Belikov@cern.ch
21 //-----------------------------------------------------------------
22
23 #include <TMath.h>
24
25 #include "AliESDVertex.h"
26 #include "AliESDtrack.h"
27 #include "AliKalmanTrack.h"
28 #include "AliLog.h"
29 #include "AliTrackPointArray.h"
30
31 ClassImp(AliESDtrack)
32
33 void SetPIDValues(Float_t * dest, const Double_t * src, Int_t n) {
34   // This function copies "n" PID weights from "scr" to "dest"
35   // and normalizes their sum to 1 thus producing conditional probabilities.
36   // The negative weights are set to 0.
37   // In case all the weights are non-positive they are replaced by
38   // uniform probabilities
39
40   if (n<=0) return;
41
42   Float_t uniform = 1./(Float_t)n;
43
44   Float_t sum = 0;
45   for (Int_t i=0; i<n; i++) 
46     if (src[i]>=0) {
47       sum+=src[i];
48       dest[i] = src[i];
49     }
50     else {
51       dest[i] = 0;
52     }
53
54   if(sum>0)
55     for (Int_t i=0; i<n; i++) dest[i] /= sum;
56   else
57     for (Int_t i=0; i<n; i++) dest[i] = uniform;
58 }
59
60 //_______________________________________________________________________
61 AliESDtrack::AliESDtrack() : 
62   AliExternalTrackParam(),
63   fFlags(0),
64   fLabel(0),
65   fID(0),
66   fTrackLength(0),
67   fD(0),fZ(0),
68   fCdd(0),fCdz(0),fCzz(0),
69   fStopVertex(0),
70   fCp(0),
71   fCchi2(1e10),
72   fIp(0),
73   fOp(0),
74   fITSchi2(0),
75   fITSncls(0),
76   fITSsignal(0),
77   fITSLabel(0),
78   fITSFakeRatio(0),
79   fTPCchi2(0),
80   fTPCncls(0),
81   fTPCnclsF(0),
82   fTPCClusterMap(159),//number of padrows
83   fTPCsignal(0),
84   fTPCsignalN(0),
85   fTPCsignalS(0),
86   fTPCLabel(0),
87   fTRDchi2(0),
88   fTRDncls(0),
89   fTRDncls0(0),
90   fTRDsignal(0),
91   fTRDLabel(0),
92   fTRDQuality(0),
93   fTRDBudget(0),
94   fTOFchi2(0),
95   fTOFindex(0),
96   fTOFCalChannel(-1),
97   fTOFsignal(-1),
98   fTOFsignalToT(0),
99   fRICHchi2(1e10),
100   fRICHncls(0),
101   fRICHindex(0),
102   fRICHsignal(-1),
103   fRICHtheta(-1),
104   fRICHphi(-1),
105   fRICHdx(-1),
106   fRICHdy(-1),
107   fRICHmipX(-1),
108   fRICHmipY(-1),
109   fPoints(0),
110   fFriendTrack(new AliESDfriendTrack())
111 {
112   //
113   // The default ESD constructor 
114   //
115   Int_t i;
116   for (i=0; i<AliPID::kSPECIES; i++) {
117     fTrackTime[i]=0.;
118     fR[i]=1.;
119     fITSr[i]=1.;
120     fTPCr[i]=1.;
121     fTRDr[i]=1.;
122     fTOFr[i]=1.;
123     fRICHr[i]=1.;
124   }
125   
126   for (i=0; i<3; i++)   { fKinkIndexes[i]=0;}
127   for (i=0; i<3; i++)   { fV0Indexes[i]=-1;}
128   for (i=0;i<kNPlane;i++) {fTRDsignals[i]=0.; fTRDTimBin[i]=-1;}
129   for (i=0;i<4;i++) {fTPCPoints[i]=-1;}
130   for (i=0;i<3;i++) {fTOFLabel[i]=-1;}
131   for (i=0;i<10;i++) {fTOFInfo[i]=-1;}
132 }
133
134 //_______________________________________________________________________
135 AliESDtrack::AliESDtrack(const AliESDtrack& track):
136   AliExternalTrackParam(track),
137   fFlags(track.fFlags),
138   fLabel(track.fLabel),
139   fID(track.fID),
140   fTrackLength(track.fTrackLength),
141   fD(track.fD),fZ(track.fZ),
142   fCdd(track.fCdd),fCdz(track.fCdz),fCzz(track.fCzz),
143   fStopVertex(track.fStopVertex),
144   fCp(0),
145   fCchi2(track.fCchi2),
146   fIp(0),
147   fOp(0),
148   fITSchi2(track.fITSchi2),
149   fITSncls(track.fITSncls),
150   fITSsignal(track.fITSsignal),
151   fITSLabel(track.fITSLabel),
152   fITSFakeRatio(track.fITSFakeRatio),
153   fTPCchi2(track.fTPCchi2),
154   fTPCncls(track.fTPCncls),
155   fTPCnclsF(track.fTPCnclsF),
156   fTPCClusterMap(track.fTPCClusterMap),
157   fTPCsignal(track.fTPCsignal),
158   fTPCsignalN(track.fTPCsignalN),
159   fTPCsignalS(track.fTPCsignalS),
160   fTPCLabel(track.fTPCLabel),
161   fTRDchi2(track.fTRDchi2),
162   fTRDncls(track.fTRDncls),
163   fTRDncls0(track.fTRDncls0),
164   fTRDsignal(track.fTRDsignal),
165   fTRDLabel(track.fTRDLabel),
166   fTRDQuality(track.fTRDQuality),
167   fTRDBudget(track.fTRDBudget),
168   fTOFchi2(track.fTOFchi2),
169   fTOFindex(track.fTOFindex),
170   fTOFCalChannel(track.fTOFCalChannel),
171   fTOFsignal(track.fTOFsignal),
172   fTOFsignalToT(track.fTOFsignalToT),
173   fRICHchi2(track.fRICHchi2),
174   fRICHncls(track.fRICHncls),
175   fRICHindex(track.fRICHindex),
176   fRICHsignal(track.fRICHsignal),
177   fRICHtheta(track.fRICHtheta),
178   fRICHphi(track.fRICHphi),
179   fRICHdx(track.fRICHdx),
180   fRICHdy(track.fRICHdy),
181   fRICHmipX(track.fRICHmipX),
182   fRICHmipY(track.fRICHmipY),
183   fPoints(0),
184   fFriendTrack(new AliESDfriendTrack(*(track.fFriendTrack)))
185 {
186   //
187   //copy constructor
188   //
189   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTrackTime[i]=track.fTrackTime[i];
190   for (Int_t i=0;i<AliPID::kSPECIES;i++)  fR[i]=track.fR[i];
191   //
192   for (Int_t i=0;i<AliPID::kSPECIES;i++) fITSr[i]=track.fITSr[i]; 
193   //
194   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTPCr[i]=track.fTPCr[i]; 
195   for (Int_t i=0;i<4;i++) {fTPCPoints[i]=track.fTPCPoints[i];}
196   for (Int_t i=0; i<3;i++)   { fKinkIndexes[i]=track.fKinkIndexes[i];}
197   for (Int_t i=0; i<3;i++)   { fV0Indexes[i]=track.fV0Indexes[i];}
198   //
199   for (Int_t i=0;i<kNPlane;i++) {
200       fTRDsignals[i]=track.fTRDsignals[i]; 
201       fTRDTimBin[i]=track.fTRDTimBin[i];
202   }
203   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTRDr[i]=track.fTRDr[i]; 
204   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTOFr[i]=track.fTOFr[i];
205   for (Int_t i=0;i<3;i++) fTOFLabel[i]=track.fTOFLabel[i];
206   for (Int_t i=0;i<10;i++) fTOFInfo[i]=track.fTOFInfo[i];
207   for (Int_t i=0;i<AliPID::kSPECIES;i++) fRICHr[i]=track.fRICHr[i];
208
209   if (track.fCp) fCp=new AliExternalTrackParam(*track.fCp);
210   if (track.fIp) fIp=new AliExternalTrackParam(*track.fIp);
211   if (track.fOp) fOp=new AliExternalTrackParam(*track.fOp);
212
213   if (track.fPoints) fPoints=new AliTrackPointArray(*(track.fPoints));
214 }
215
216 //_______________________________________________________________________
217 AliESDtrack::~AliESDtrack(){ 
218   //
219   // This is destructor according Coding Conventrions 
220   //
221   //printf("Delete track\n");
222   delete fIp; 
223   delete fOp;
224   delete fCp; 
225   delete fFriendTrack;
226   delete fPoints;
227 }
228
229 //_______________________________________________________________________
230 void AliESDtrack::MakeMiniESDtrack(){
231   // Resets everything except
232   // fFlags: Reconstruction status flags 
233   // fLabel: Track label
234   // fID:  Unique ID of the track
235   // fD: Impact parameter in XY-plane
236   // fZ: Impact parameter in Z 
237   // fR[AliPID::kSPECIES]: combined "detector response probability"
238   // Running track parameters
239   // fRalpha: track rotation angle
240   // fRx: X-coordinate of the track reference plane 
241   // fRp[5]: external track parameters  
242   // fRc[15]: external cov. matrix of the track parameters
243   
244   fTrackLength = 0;
245   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTrackTime[i] = 0;
246   fStopVertex = 0;
247
248   // Reset track parameters constrained to the primary vertex
249   fCp = 0;
250   fCchi2 = 0;
251
252   // Reset track parameters at the inner wall of TPC
253   fIp = 0;
254
255   // Reset track parameters at the inner wall of the TRD
256   fOp = 0;
257
258   // Reset ITS track related information
259   fITSchi2 = 0;
260   fITSncls = 0;       
261   fITSsignal = 0;     
262   for (Int_t i=0;i<AliPID::kSPECIES;i++) fITSr[i]=0; 
263   fITSLabel = 0;       
264   fITSFakeRatio = 0;   
265
266   // Reset TPC related track information
267   fTPCchi2 = 0;       
268   fTPCncls = 0;       
269   fTPCnclsF = 0;       
270   fTPCClusterMap = 0;  
271   fTPCsignal= 0;      
272   fTPCsignalS= 0;      
273   fTPCsignalN= 0;      
274   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTPCr[i]=0; 
275   fTPCLabel=0;       
276   for (Int_t i=0;i<4;i++) fTPCPoints[i] = 0;
277   for (Int_t i=0; i<3;i++)   fKinkIndexes[i] = 0;
278   for (Int_t i=0; i<3;i++)   fV0Indexes[i] = 0;
279
280   // Reset TRD related track information
281   fTRDchi2 = 0;        
282   fTRDncls = 0;       
283   fTRDncls0 = 0;       
284   fTRDsignal = 0;      
285   for (Int_t i=0;i<kNPlane;i++) {
286       fTRDsignals[i] = 0; 
287       fTRDTimBin[i]  = 0;
288   }
289   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTRDr[i] = 0; 
290   fTRDLabel = 0;       
291   fTRDQuality  = 0;
292   fTRDBudget  = 0;
293
294   // Reset TOF related track information
295   fTOFchi2 = 0;        
296   fTOFindex = 0;       
297   fTOFsignal = 0;      
298   fTOFCalChannel = -1;
299   fTOFsignalToT = 0;
300   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTOFr[i] = 0;
301   for (Int_t i=0;i<3;i++) fTOFLabel[i] = 0;
302   for (Int_t i=0;i<10;i++) fTOFInfo[i] = 0;
303
304   // Reset RICH related track information
305   fRICHchi2 = 0;     
306   fRICHncls = 0;     
307   fRICHindex = 0;     
308   fRICHsignal = 0;     
309   for (Int_t i=0;i<AliPID::kSPECIES;i++) fRICHr[i] = 0;
310   fRICHtheta = 0;     
311   fRICHphi = 0;      
312   fRICHdx = 0;     
313   fRICHdy = 0;      
314
315   delete fFriendTrack; fFriendTrack = 0;
316   delete fPoints; fPoints = 0;
317
318 //_______________________________________________________________________
319 Double_t AliESDtrack::GetMass() const {
320   // Returns the mass of the most probable particle type
321   Float_t max=0.;
322   Int_t k=-1;
323   for (Int_t i=0; i<AliPID::kSPECIES; i++) {
324     if (fR[i]>max) {k=i; max=fR[i];}
325   }
326   if (k==0) { // dE/dx "crossing points" in the TPC
327      Double_t p=GetP();
328      if ((p>0.38)&&(p<0.48))
329         if (fR[0]<fR[3]*10.) return AliPID::ParticleMass(AliPID::kKaon);
330      if ((p>0.75)&&(p<0.85))
331         if (fR[0]<fR[4]*10.) return AliPID::ParticleMass(AliPID::kProton);
332      return 0.00051;
333   }
334   if (k==1) return AliPID::ParticleMass(AliPID::kMuon); 
335   if (k==2||k==-1) return AliPID::ParticleMass(AliPID::kPion);
336   if (k==3) return AliPID::ParticleMass(AliPID::kKaon);
337   if (k==4) return AliPID::ParticleMass(AliPID::kProton);
338   AliWarning("Undefined mass !");
339   return AliPID::ParticleMass(AliPID::kPion);
340 }
341
342 //_______________________________________________________________________
343 Bool_t AliESDtrack::UpdateTrackParams(const AliKalmanTrack *t, ULong_t flags){
344   //
345   // This function updates track's running parameters 
346   //
347   Int_t *index=0;
348   Bool_t rc=kTRUE;
349
350   SetStatus(flags);
351   fLabel=t->GetLabel();
352
353   if (t->IsStartedTimeIntegral()) {
354     SetStatus(kTIME);
355     Double_t times[10];t->GetIntegratedTimes(times); SetIntegratedTimes(times);
356     SetIntegratedLength(t->GetIntegratedLength());
357   }
358
359   Set(*t);
360   
361   switch (flags) {
362     
363   case kITSin: case kITSout: case kITSrefit:
364     index=fFriendTrack->GetITSindices(); 
365     for (Int_t i=0;i<AliESDfriendTrack::kMaxITScluster;i++) 
366          index[i]=t->GetClusterIndex(i);
367     fITSncls=t->GetNumberOfClusters();
368     fITSchi2=t->GetChi2();
369     fITSsignal=t->GetPIDsignal();
370     fITSLabel = t->GetLabel();
371     fITSFakeRatio = t->GetFakeRatio();
372     break;
373     
374   case kTPCin: case kTPCrefit:
375     fTPCLabel = t->GetLabel();
376     if (!fIp) fIp=new AliExternalTrackParam(*t);
377     else fIp->Set(*t);
378   case kTPCout:
379     index=fFriendTrack->GetTPCindices(); 
380     if (flags & kTPCout){
381       if (!fOp) fOp=new AliExternalTrackParam(*t);
382       else fOp->Set(*t);
383     }
384     fTPCncls=t->GetNumberOfClusters();    
385     fTPCchi2=t->GetChi2();
386     
387      {//prevrow must be declared in separate namespace, otherwise compiler cries:
388       //"jump to case label crosses initialization of `Int_t prevrow'"
389        Int_t prevrow = -1;
390        //       for (Int_t i=0;i<fTPCncls;i++) 
391        for (Int_t i=0;i<AliESDfriendTrack::kMaxTPCcluster;i++) 
392         {
393           index[i]=t->GetClusterIndex(i);
394           Int_t idx = index[i];
395
396           if (idx<0) continue; 
397
398           // Piotr's Cluster Map for HBT  
399           // ### please change accordingly if cluster array is changing 
400           // to "New TPC Tracking" style (with gaps in array) 
401           Int_t sect = (idx&0xff000000)>>24;
402           Int_t row = (idx&0x00ff0000)>>16;
403           if (sect > 18) row +=63; //if it is outer sector, add number of inner sectors
404
405           fTPCClusterMap.SetBitNumber(row,kTRUE);
406
407           //Fill the gap between previous row and this row with 0 bits
408           //In case  ###  pleas change it as well - just set bit 0 in case there 
409           //is no associated clusters for current "i"
410           if (prevrow < 0) 
411            {
412              prevrow = row;//if previous bit was not assigned yet == this is the first one
413            }
414           else
415            { //we don't know the order (inner to outer or reverse)
416              //just to be save in case it is going to change
417              Int_t n = 0, m = 0;
418              if (prevrow < row)
419               {
420                 n = prevrow;
421                 m = row;
422               }
423              else
424               {
425                 n = row;
426                 m = prevrow;
427               }
428
429              for (Int_t j = n+1; j < m; j++)
430               {
431                 fTPCClusterMap.SetBitNumber(j,kFALSE);
432               }
433              prevrow = row; 
434            }
435           // End Of Piotr's Cluster Map for HBT
436         }
437      }
438     fTPCsignal=t->GetPIDsignal();
439     break;
440
441   case kTRDout: case kTRDin: case kTRDrefit:
442     index=fFriendTrack->GetTRDindices();
443     fTRDLabel = t->GetLabel(); 
444     fTRDncls=t->GetNumberOfClusters();
445     fTRDchi2=t->GetChi2();
446     for (Int_t i=0;i<fTRDncls;i++) index[i]=t->GetClusterIndex(i);
447     fTRDsignal=t->GetPIDsignal();
448     break;
449   case kTRDbackup:
450     if (!fOp) fOp=new AliExternalTrackParam(*t);
451     else fOp->Set(*t);
452     fTRDncls0 = t->GetNumberOfClusters(); 
453     break;
454   case kTOFin: 
455     break;
456   case kTOFout: 
457     break;
458   case kTRDStop:
459     break;
460   default: 
461     AliError("Wrong flag !");
462     return kFALSE;
463   }
464
465   return rc;
466 }
467
468 //_______________________________________________________________________
469 void AliESDtrack::GetExternalParameters(Double_t &x, Double_t p[5]) const {
470   //---------------------------------------------------------------------
471   // This function returns external representation of the track parameters
472   //---------------------------------------------------------------------
473   x=GetX();
474   for (Int_t i=0; i<5; i++) p[i]=GetParameter()[i];
475 }
476
477 //_______________________________________________________________________
478 void AliESDtrack::GetExternalCovariance(Double_t cov[15]) const {
479   //---------------------------------------------------------------------
480   // This function returns external representation of the cov. matrix
481   //---------------------------------------------------------------------
482   for (Int_t i=0; i<15; i++) cov[i]=AliExternalTrackParam::GetCovariance()[i];
483 }
484
485 //_______________________________________________________________________
486 Bool_t AliESDtrack::GetConstrainedExternalParameters
487                  (Double_t &alpha, Double_t &x, Double_t p[5]) const {
488   //---------------------------------------------------------------------
489   // This function returns the constrained external track parameters
490   //---------------------------------------------------------------------
491   if (!fCp) return kFALSE;
492   alpha=fCp->GetAlpha();
493   x=fCp->GetX();
494   for (Int_t i=0; i<5; i++) p[i]=fCp->GetParameter()[i];
495   return kTRUE;
496 }
497
498 //_______________________________________________________________________
499 Bool_t 
500 AliESDtrack::GetConstrainedExternalCovariance(Double_t c[15]) const {
501   //---------------------------------------------------------------------
502   // This function returns the constrained external cov. matrix
503   //---------------------------------------------------------------------
504   if (!fCp) return kFALSE;
505   for (Int_t i=0; i<15; i++) c[i]=fCp->GetCovariance()[i];
506   return kTRUE;
507 }
508
509 Bool_t
510 AliESDtrack::GetInnerExternalParameters
511                  (Double_t &alpha, Double_t &x, Double_t p[5]) const {
512   //---------------------------------------------------------------------
513   // This function returns external representation of the track parameters 
514   // at the inner layer of TPC
515   //---------------------------------------------------------------------
516   if (!fIp) return kFALSE;
517   alpha=fIp->GetAlpha();
518   x=fIp->GetX();
519   for (Int_t i=0; i<5; i++) p[i]=fIp->GetParameter()[i];
520   return kTRUE;
521 }
522
523 Bool_t 
524 AliESDtrack::GetInnerExternalCovariance(Double_t cov[15]) const {
525  //---------------------------------------------------------------------
526  // This function returns external representation of the cov. matrix 
527  // at the inner layer of TPC
528  //---------------------------------------------------------------------
529   if (!fIp) return kFALSE;
530   for (Int_t i=0; i<15; i++) cov[i]=fIp->GetCovariance()[i];
531   return kTRUE;
532 }
533
534 Bool_t 
535 AliESDtrack::GetOuterExternalParameters
536                  (Double_t &alpha, Double_t &x, Double_t p[5]) const {
537   //---------------------------------------------------------------------
538   // This function returns external representation of the track parameters 
539   // at the inner layer of TRD
540   //---------------------------------------------------------------------
541   if (!fOp) return kFALSE;
542   alpha=fOp->GetAlpha();
543   x=fOp->GetX();
544   for (Int_t i=0; i<5; i++) p[i]=fOp->GetParameter()[i];
545   return kTRUE;
546 }
547
548 Bool_t 
549 AliESDtrack::GetOuterExternalCovariance(Double_t cov[15]) const {
550  //---------------------------------------------------------------------
551  // This function returns external representation of the cov. matrix 
552  // at the inner layer of TRD
553  //---------------------------------------------------------------------
554   if (!fOp) return kFALSE;
555   for (Int_t i=0; i<15; i++) cov[i]=fOp->GetCovariance()[i];
556   return kTRUE;
557 }
558
559 Int_t AliESDtrack::GetNcls(Int_t idet) const
560 {
561   // Get number of clusters by subdetector index
562   //
563   Int_t ncls = 0;
564   switch(idet){
565   case 0:
566     ncls = fITSncls;
567     break;
568   case 1:
569     ncls = fTPCncls;
570     break;
571   case 2:
572     ncls = fTRDncls;
573     break;
574   case 3:
575     if (fTOFindex != 0)
576       ncls = 1;
577     break;
578   default:
579     break;
580   }
581   return ncls;
582 }
583
584 Int_t AliESDtrack::GetClusters(Int_t idet, Int_t *idx) const
585 {
586   // Get cluster index array by subdetector index
587   //
588   Int_t ncls = 0;
589   switch(idet){
590   case 0:
591     ncls = GetITSclusters(idx);
592     break;
593   case 1:
594     ncls = GetTPCclusters(idx);
595     break;
596   case 2:
597     ncls = GetTRDclusters(idx);
598     break;
599   case 3:
600     if (fTOFindex != 0) {
601       idx[0] = GetTOFcluster();
602       ncls = 1;
603     }
604     break;
605   default:
606     break;
607   }
608   return ncls;
609 }
610
611 //_______________________________________________________________________
612 void AliESDtrack::GetIntegratedTimes(Double_t *times) const {
613   // Returns the array with integrated times for each particle hypothesis
614   for (Int_t i=0; i<AliPID::kSPECIES; i++) times[i]=fTrackTime[i];
615 }
616
617 //_______________________________________________________________________
618 void AliESDtrack::SetIntegratedTimes(const Double_t *times) {
619   // Sets the array with integrated times for each particle hypotesis
620   for (Int_t i=0; i<AliPID::kSPECIES; i++) fTrackTime[i]=times[i];
621 }
622
623 //_______________________________________________________________________
624 void AliESDtrack::SetITSpid(const Double_t *p) {
625   // Sets values for the probability of each particle type (in ITS)
626   SetPIDValues(fITSr,p,AliPID::kSPECIES);
627   SetStatus(AliESDtrack::kITSpid);
628 }
629
630 //_______________________________________________________________________
631 void AliESDtrack::GetITSpid(Double_t *p) const {
632   // Gets the probability of each particle type (in ITS)
633   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fITSr[i];
634 }
635
636 //_______________________________________________________________________
637 Int_t AliESDtrack::GetITSclusters(Int_t *idx) const {
638   //---------------------------------------------------------------------
639   // This function returns indices of the assgined ITS clusters 
640   //---------------------------------------------------------------------
641   if (idx!=0) {
642      Int_t *index=fFriendTrack->GetITSindices();
643      for (Int_t i=0; i<AliESDfriendTrack::kMaxITScluster; i++) idx[i]=index[i];
644   }
645   return fITSncls;
646 }
647
648 //_______________________________________________________________________
649 Int_t AliESDtrack::GetTPCclusters(Int_t *idx) const {
650   //---------------------------------------------------------------------
651   // This function returns indices of the assgined ITS clusters 
652   //---------------------------------------------------------------------
653   if (idx!=0) {
654     Int_t *index=fFriendTrack->GetTPCindices();
655     for (Int_t i=0; i<AliESDfriendTrack::kMaxTPCcluster; i++) idx[i]=index[i];
656   }
657   return fTPCncls;
658 }
659
660 Float_t AliESDtrack::GetTPCdensity(Int_t row0, Int_t row1) const{
661   //
662   // GetDensity of the clusters on given region between row0 and row1
663   // Dead zone effect takin into acoount
664   //
665   Int_t good  = 0;
666   Int_t found = 0;
667   //  
668   Int_t *index=fFriendTrack->GetTPCindices();
669   for (Int_t i=row0;i<=row1;i++){     
670     Int_t idx = index[i];
671     if (idx!=-1)  good++;             // track outside of dead zone
672     if (idx>0)    found++;
673   }
674   Float_t density=0.5;
675   if (good>(row1-row0)*0.5) density = Float_t(found)/Float_t(good);
676   return density;
677 }
678
679 //_______________________________________________________________________
680 void AliESDtrack::SetTPCpid(const Double_t *p) {  
681   // Sets values for the probability of each particle type (in TPC)
682   SetPIDValues(fTPCr,p,AliPID::kSPECIES);
683   SetStatus(AliESDtrack::kTPCpid);
684 }
685
686 //_______________________________________________________________________
687 void AliESDtrack::GetTPCpid(Double_t *p) const {
688   // Gets the probability of each particle type (in TPC)
689   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTPCr[i];
690 }
691
692 //_______________________________________________________________________
693 Int_t AliESDtrack::GetTRDclusters(Int_t *idx) const {
694   //---------------------------------------------------------------------
695   // This function returns indices of the assgined TRD clusters 
696   //---------------------------------------------------------------------
697   if (idx!=0) {
698      Int_t *index=fFriendTrack->GetTRDindices();
699      for (Int_t i=0; i<AliESDfriendTrack::kMaxTRDcluster; i++) idx[i]=index[i];
700   }
701   return fTRDncls;
702 }
703
704 //_______________________________________________________________________
705 void AliESDtrack::SetTRDpid(const Double_t *p) {  
706   // Sets values for the probability of each particle type (in TRD)
707   SetPIDValues(fTRDr,p,AliPID::kSPECIES);
708   SetStatus(AliESDtrack::kTRDpid);
709 }
710
711 //_______________________________________________________________________
712 void AliESDtrack::GetTRDpid(Double_t *p) const {
713   // Gets the probability of each particle type (in TRD)
714   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTRDr[i];
715 }
716
717 //_______________________________________________________________________
718 void    AliESDtrack::SetTRDpid(Int_t iSpecies, Float_t p)
719 {
720   // Sets the probability of particle type iSpecies to p (in TRD)
721   fTRDr[iSpecies] = p;
722 }
723
724 Float_t AliESDtrack::GetTRDpid(Int_t iSpecies) const
725 {
726   // Returns the probability of particle type iSpecies (in TRD)
727   return fTRDr[iSpecies];
728 }
729
730 //_______________________________________________________________________
731 void AliESDtrack::SetTOFpid(const Double_t *p) {  
732   // Sets the probability of each particle type (in TOF)
733   SetPIDValues(fTOFr,p,AliPID::kSPECIES);
734   SetStatus(AliESDtrack::kTOFpid);
735 }
736
737 //_______________________________________________________________________
738 void AliESDtrack::SetTOFLabel(const Int_t *p) {  
739   // Sets  (in TOF)
740   for (Int_t i=0; i<3; i++) fTOFLabel[i]=p[i];
741 }
742
743 //_______________________________________________________________________
744 void AliESDtrack::GetTOFpid(Double_t *p) const {
745   // Gets probabilities of each particle type (in TOF)
746   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTOFr[i];
747 }
748
749 //_______________________________________________________________________
750 void AliESDtrack::GetTOFLabel(Int_t *p) const {
751   // Gets (in TOF)
752   for (Int_t i=0; i<3; i++) p[i]=fTOFLabel[i];
753 }
754
755 //_______________________________________________________________________
756 void AliESDtrack::GetTOFInfo(Float_t *info) const {
757   // Gets (in TOF)
758   for (Int_t i=0; i<10; i++) info[i]=fTOFInfo[i];
759 }
760
761 //_______________________________________________________________________
762 void AliESDtrack::SetTOFInfo(Float_t*info) {
763   // Gets (in TOF)
764   for (Int_t i=0; i<10; i++) fTOFInfo[i]=info[i];
765 }
766
767
768
769 //_______________________________________________________________________
770 void AliESDtrack::SetRICHpid(const Double_t *p) {  
771   // Sets the probability of each particle type (in RICH)
772   SetPIDValues(fRICHr,p,AliPID::kSPECIES);
773   SetStatus(AliESDtrack::kRICHpid);
774 }
775
776 //_______________________________________________________________________
777 void AliESDtrack::GetRICHpid(Double_t *p) const {
778   // Gets probabilities of each particle type (in RICH)
779   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fRICHr[i];
780 }
781
782
783
784 //_______________________________________________________________________
785 void AliESDtrack::SetESDpid(const Double_t *p) {  
786   // Sets the probability of each particle type for the ESD track
787   SetPIDValues(fR,p,AliPID::kSPECIES);
788   SetStatus(AliESDtrack::kESDpid);
789 }
790
791 //_______________________________________________________________________
792 void AliESDtrack::GetESDpid(Double_t *p) const {
793   // Gets probability of each particle type for the ESD track
794   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fR[i];
795 }
796
797 //_______________________________________________________________________
798 Bool_t AliESDtrack::RelateToVertex
799 (const AliESDVertex *vtx, Double_t b, Double_t maxd) {
800   //
801   // Try to relate this track to the vertex "vtx", 
802   // if the (rough) transverse impact parameter is not bigger then "maxd". 
803   //            Magnetic field is "b" (kG).
804   //
805   // a) The track gets extapolated to the DCA to the vertex.
806   // b) The impact parameters and their covariance matrix are calculated.
807   // c) An attempt to constrain this track to the vertex is done.
808   //
809   //    In the case of success, the returned value is kTRUE
810   //    (otherwise, it's kFALSE)
811   //  
812   Double_t alpha=GetAlpha();
813   Double_t sn=TMath::Sin(alpha), cs=TMath::Cos(alpha);
814   Double_t x=GetX(), y=GetParameter()[0], snp=GetParameter()[2];
815   Double_t xv= vtx->GetXv()*cs + vtx->GetYv()*sn;
816   Double_t yv=-vtx->GetXv()*sn + vtx->GetYv()*cs, zv=vtx->GetZv();
817   x-=xv; y-=yv;
818
819   //Estimate the impact parameter neglecting the track curvature
820   Double_t d=TMath::Abs(x*snp - y*TMath::Sqrt(1.- snp*snp));
821   if (d > maxd) return kFALSE; 
822
823   //Propagate to the DCA
824   Double_t crv=0.299792458e-3*b*GetParameter()[4];
825   Double_t tgfv=-(crv*x - snp)/(crv*y + TMath::Sqrt(1.-snp*snp));
826   sn=tgfv/TMath::Sqrt(1.+ tgfv*tgfv);
827   if (TMath::Abs(tgfv)>0.) cs = sn/tgfv;
828   else cs=1.;
829
830   x = xv*cs + yv*sn;
831   yv=-xv*sn + yv*cs; xv=x;
832
833   if (!Propagate(alpha+TMath::ASin(sn),xv,b)) return kFALSE;
834
835   fD = GetParameter()[0] - yv;
836   fZ = GetParameter()[1] - zv;
837   
838   Double_t cov[6]; vtx->GetCovMatrix(cov);
839   fCdd = GetCovariance()[0] + cov[2];      // neglecting non-diagonals
840   fCdz = GetCovariance()[1];               //     in the vertex's    
841   fCzz = GetCovariance()[2] + cov[5];      //    covariance matrix
842
843   {//Try to constrain 
844     Double_t p[2]={yv,zv}, c[3]={cov[2],0.,cov[5]};
845     Double_t chi2=GetPredictedChi2(p,c);
846
847     if (chi2>77.) return kFALSE;
848
849     AliExternalTrackParam tmp(*this);
850     if (!tmp.Update(p,c)) return kFALSE;
851
852     fCchi2=chi2;
853     if (!fCp) fCp=new AliExternalTrackParam();
854     new (fCp) AliExternalTrackParam(tmp);
855   }
856
857   return kTRUE;
858 }
859
860 void AliESDtrack::SetTrackPointArray(AliTrackPointArray *points) { 
861     fPoints=points;
862     //fFriendTrack->SetTrackPointArray(points); 
863 }
864 const AliTrackPointArray *AliESDtrack::GetTrackPointArray() const { 
865     return fPoints;
866   //return fFriendTrack->GetTrackPointArray(); 
867 }
868
869 //_______________________________________________________________________
870 void AliESDtrack::Print(Option_t *) const {
871   // Prints info on the track
872   
873   printf("ESD track info\n") ; 
874   Double_t p[AliPID::kSPECIESN] ; 
875   Int_t index = 0 ; 
876   if( IsOn(kITSpid) ){
877     printf("From ITS: ") ; 
878     GetITSpid(p) ; 
879     for(index = 0 ; index < AliPID::kSPECIES; index++) 
880       printf("%f, ", p[index]) ;
881     printf("\n           signal = %f\n", GetITSsignal()) ;
882   } 
883   if( IsOn(kTPCpid) ){
884     printf("From TPC: ") ; 
885     GetTPCpid(p) ; 
886     for(index = 0 ; index < AliPID::kSPECIES; index++) 
887       printf("%f, ", p[index]) ;
888     printf("\n           signal = %f\n", GetTPCsignal()) ;
889   }
890   if( IsOn(kTRDpid) ){
891     printf("From TRD: ") ; 
892     GetTRDpid(p) ; 
893     for(index = 0 ; index < AliPID::kSPECIES; index++) 
894       printf("%f, ", p[index]) ;
895     printf("\n           signal = %f\n", GetTRDsignal()) ;
896   }
897   if( IsOn(kTOFpid) ){
898     printf("From TOF: ") ; 
899     GetTOFpid(p) ; 
900     for(index = 0 ; index < AliPID::kSPECIES; index++) 
901       printf("%f, ", p[index]) ;
902     printf("\n           signal = %f\n", GetTOFsignal()) ;
903   }
904   if( IsOn(kRICHpid) ){
905     printf("From RICH: ") ; 
906     GetRICHpid(p) ; 
907     for(index = 0 ; index < AliPID::kSPECIES; index++) 
908       printf("%f, ", p[index]) ;
909     printf("\n           signal = %f\n", GetRICHsignal()) ;
910   }
911