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