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