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