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