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