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