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