]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDtrack.cxx
Additional ESD data members related to TRD tracking quality (M.Ivanov)
[u/mrichter/AliRoot.git] / STEER / AliESDtrack.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15 //-----------------------------------------------------------------
16 //           Implementation of the ESD track class
17 //   ESD = Event Summary Data
18 //   This is the class to deal with during the phisics analysis of data
19 //      Origin: Iouri Belikov, CERN
20 //      e-mail: Jouri.Belikov@cern.ch
21 //-----------------------------------------------------------------
22
23 #include "TMath.h"
24
25 #include "AliESDtrack.h"
26 #include "AliKalmanTrack.h"
27 #include "AliLog.h"
28
29 ClassImp(AliESDtrack)
30
31 //_______________________________________________________________________
32 AliESDtrack::AliESDtrack() : 
33 fFlags(0),
34 fLabel(0),
35 fID(0),
36 fTrackLength(0),
37 fD(0),
38 fZ(0),
39 fStopVertex(0),
40 fRalpha(0),
41 fRx(0),
42 fCalpha(0),
43 fCx(0),
44 fCchi2(1e10),
45 fIalpha(0),
46 fIx(0),
47 fTalpha(0),
48 fTx(0),
49 fITSchi2(0),
50 fITSncls(0),
51 fITSsignal(0),
52 fTPCchi2(0),
53 fTPCncls(0),
54 fTPCClusterMap(159),//number of padrows
55 fTPCsignal(0),
56 fTRDchi2(0),
57 fTRDncls(0),
58 fTRDncls0(0),
59 fTRDsignal(0),
60 fTRDQuality(0),
61 fTOFchi2(0),
62 fTOFindex(0),
63 fTOFsignal(-1),
64 fPHOSsignal(-1),
65 fEMCALsignal(-1),
66 fRICHchi2(1e10),
67 fRICHncls(0),
68 fRICHindex(0),
69 fRICHsignal(-1),
70 fRICHtheta(0),
71 fRICHphi(0),
72 fRICHdx(0),
73 fRICHdy(0)
74 {
75   //
76   // The default ESD constructor 
77   //
78   for (Int_t i=0; i<AliPID::kSPECIES; i++) {
79     fTrackTime[i]=0.;
80     fR[i]=1.;
81     fITSr[i]=1.;
82     fTPCr[i]=1.;
83     fTRDr[i]=1.;
84     fTOFr[i]=1.;
85     fRICHr[i]=1.;
86   }
87   
88   for (Int_t i=0; i<AliPID::kSPECIESN; i++) {
89     fPHOSr[i]  = 1.;
90     fEMCALr[i] = 1.;
91   }
92
93  
94   fPHOSpos[0]=fPHOSpos[1]=fPHOSpos[2]=0.;
95   fEMCALpos[0]=fEMCALpos[1]=fEMCALpos[2]=0.;
96   Int_t i;
97   for (i=0; i<5; i++)  { 
98     fRp[i]=fCp[i]=fIp[i]=fTp[i]=0.;
99   }
100   for (i=0; i<15; i++) { 
101     fRc[i]=fCc[i]=fIc[i]=fTc[i]=0.;  
102   }
103   for (i=0; i<6; i++)  { fITSindex[i]=0; }
104   for (i=0; i<180; i++){ fTPCindex[i]=0; }
105   for (i=0; i<3;i++)   { fKinkIndexes[i]=0;}
106   for (i=0; i<3;i++)   { fV0Indexes[i]=-1;}
107   for (i=0; i<130; i++) { fTRDindex[i]=0; }
108   for (i=0;i<kNPlane;i++) {fTRDsignals[i]=0.; fTRDTimBin[i]=-1;}
109   for (Int_t i=0;i<4;i++) {fTPCPoints[i]=-1;}
110   for (Int_t i=0;i<3;i++) {fTOFLabel[i]=-1;}
111   for (Int_t i=0;i<10;i++) {fTOFInfo[i]=-1;}
112   fTPCLabel = 0;
113   fTRDLabel = 0;
114   fTRDQuality =0;
115   fITSLabel = 0;
116   fITStrack = 0;
117   fTRDtrack = 0;  
118 }
119
120 //_______________________________________________________________________
121
122 AliESDtrack::AliESDtrack(const AliESDtrack& track):TObject(track){
123   //
124   //copy constructor
125   //
126   fFlags = track.fFlags;
127   fLabel =track.fLabel;
128   fID = track.fID;
129   fTrackLength =track.fTrackLength;
130   fD=track.fD; fZ=track.fZ;
131   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTrackTime[i] =track.fTrackTime[i];
132   for (Int_t i=0;i<AliPID::kSPECIES;i++)  fR[i] =track.fR[i];
133   fStopVertex =track.fStopVertex;
134   //
135   fRalpha =track.fRalpha;
136   fRx =track.fRx;
137   for (Int_t i=0;i<5;i++) fRp[i] =track.fRp[i];
138   for (Int_t i=0;i<15;i++) fRc[i] =track.fRc[i];
139   //
140   fCalpha =track.fCalpha;
141   fCx =track.fCx;
142   for (Int_t i=0;i<5;i++) fCp[i] =track.fCp[i];
143   for (Int_t i=0;i<15;i++)  fCc[i] =track.fCc[i];
144   fCchi2 =track.fCchi2;
145   //
146   fIalpha =track.fIalpha;
147   fIx =track.fIx;
148   for (Int_t i=0;i<5;i++) fIp[i] =track.fIp[i];
149   for (Int_t i=0;i<15;i++)  fIc[i] =track.fIc[i];
150   //
151   fTalpha =track.fTalpha;
152   fTx =track.fTx;
153   for (Int_t i=0;i<5;i++) fTp[i] =track.fTp[i];
154   for (Int_t i=0;i<15;i++)  fTc[i] =track.fTc[i];
155   //
156   fITSchi2 =track.fITSchi2;
157   for (Int_t i=0;i<12;i++) fITSchi2MIP[i] =track.fITSchi2MIP[i];
158   fITSncls =track.fITSncls;       
159   for (Int_t i=0;i<6;i++) fITSindex[i]=track.fITSindex[i];    
160   fITSsignal =track.fITSsignal;     
161   for (Int_t i=0;i<AliPID::kSPECIES;i++) fITSr[i]=track.fITSr[i]; 
162   fITSLabel =track.fITSLabel;       
163   fITSFakeRatio =track.fITSFakeRatio;   
164   fITStrack =0;  //coping separatelly - in user code
165   //
166   fTPCchi2 =track.fTPCchi2;       
167   fTPCncls =track.fTPCncls;       
168   for (Int_t i=0;i<180;i++) fTPCindex[i]=track.fTPCindex[i];  
169   fTPCClusterMap=track.fTPCClusterMap;  
170   fTPCsignal=track.fTPCsignal;      
171   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTPCr[i]=track.fTPCr[i]; 
172   fTPCLabel=track.fTPCLabel;       
173   for (Int_t i=0;i<4;i++) {fTPCPoints[i]=track.fTPCPoints[i];}
174   for (Int_t i=0; i<3;i++)   { fKinkIndexes[i]=track.fKinkIndexes[i];}
175   for (Int_t i=0; i<3;i++)   { fV0Indexes[i]=track.fV0Indexes[i];}
176   //
177   fTRDchi2=track.fTRDchi2;        
178   fTRDncls=track.fTRDncls;       
179   fTRDncls0=track.fTRDncls0;       
180   for (Int_t i=0;i<130;i++) fTRDindex[i]=track.fTRDindex[i];   
181   fTRDsignal=track.fTRDsignal;      
182   for (Int_t i=0;i<kNPlane;i++) {
183       fTRDsignals[i]=track.fTRDsignals[i]; 
184       fTRDTimBin[i]=track.fTRDTimBin[i];
185   }
186   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTRDr[i]=track.fTRDr[i]; 
187   fTRDLabel=track.fTRDLabel;       
188   fTRDtrack=0; 
189   fTRDQuality  = track.fTRDQuality;
190   //
191   fTOFchi2=track.fTOFchi2;        
192   fTOFindex=track.fTOFindex;       
193   fTOFsignal=track.fTOFsignal;      
194   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTOFr[i]=track.fTOFr[i];
195   for (Int_t i=0;i<3;i++) fTOFLabel[i]=track.fTOFLabel[i];
196   for (Int_t i=0;i<10;i++) fTOFInfo[i]=track.fTOFInfo[i];
197   //
198   for (Int_t i=0;i<3;i++) fPHOSpos[i]=track.fPHOSpos[i]; 
199   fPHOSsignal=track.fPHOSsignal; 
200   for (Int_t i=0;i<AliPID::kSPECIESN;i++) fPHOSr[i]=track.fPHOSr[i]; 
201   //
202   for (Int_t i=0;i<3;i++) fEMCALpos[i]=track.fEMCALpos[i]; 
203   fEMCALsignal=track.fEMCALsignal; 
204   for (Int_t i=0;i<AliPID::kSPECIESN;i++) fEMCALr[i]=track.fEMCALr[i]; 
205   //
206   fRICHchi2=track.fRICHchi2;     
207   fRICHncls=track.fRICHncls;     
208   fRICHindex=track.fRICHindex;     
209   fRICHsignal=track.fRICHsignal;     
210   for (Int_t i=0;i<AliPID::kSPECIES;i++) fRICHr[i]=track.fRICHr[i];
211   fRICHtheta=track.fRICHtheta;     
212   fRICHphi=track.fRICHphi;      
213   fRICHdx=track.fRICHdx;     
214   fRICHdy=track.fRICHdy;      
215 }
216 //_______________________________________________________________________
217 AliESDtrack::~AliESDtrack(){ 
218   //
219   // This is destructor according Coding Conventrions 
220   //
221   //printf("Delete track\n");
222   delete fITStrack;
223   delete fTRDtrack;  
224 }
225
226 //_______________________________________________________________________
227 Double_t AliESDtrack::GetMass() const {
228   // Returns the mass of the most probable particle type
229   Float_t max=0.;
230   Int_t k=-1;
231   for (Int_t i=0; i<AliPID::kSPECIES; i++) {
232     if (fR[i]>max) {k=i; max=fR[i];}
233   }
234   if (k==0) { // dE/dx "crossing points" in the TPC
235      Double_t p=GetP();
236      if ((p>0.38)&&(p<0.48))
237         if (fR[0]<fR[3]*10.) return AliPID::ParticleMass(AliPID::kKaon);
238      if ((p>0.75)&&(p<0.85))
239         if (fR[0]<fR[4]*10.) return AliPID::ParticleMass(AliPID::kProton);
240      return 0.00051;
241   }
242   if (k==1) return AliPID::ParticleMass(AliPID::kMuon); 
243   if (k==2||k==-1) return AliPID::ParticleMass(AliPID::kPion);
244   if (k==3) return AliPID::ParticleMass(AliPID::kKaon);
245   if (k==4) return AliPID::ParticleMass(AliPID::kProton);
246   AliWarning("Undefined mass !");
247   return AliPID::ParticleMass(AliPID::kPion);
248 }
249
250 //_______________________________________________________________________
251 Bool_t AliESDtrack::UpdateTrackParams(const AliKalmanTrack *t, ULong_t flags) {
252   //
253   // This function updates track's running parameters 
254   //
255   Bool_t rc=kTRUE;
256
257   SetStatus(flags);
258   fLabel=t->GetLabel();
259
260   if (t->IsStartedTimeIntegral()) {
261     SetStatus(kTIME);
262     Double_t times[10];t->GetIntegratedTimes(times); SetIntegratedTimes(times);
263     SetIntegratedLength(t->GetIntegratedLength());
264   }
265
266   fRalpha=t->GetAlpha();
267   t->GetExternalParameters(fRx,fRp);
268   t->GetExternalCovariance(fRc);
269
270   switch (flags) {
271     
272   case kITSin: case kITSout: case kITSrefit:
273     fITSncls=t->GetNumberOfClusters();
274     fITSchi2=t->GetChi2();
275     for (Int_t i=0;i<fITSncls;i++) fITSindex[i]=t->GetClusterIndex(i);
276     fITSsignal=t->GetPIDsignal();
277     fITSLabel = t->GetLabel();
278     fITSFakeRatio = t->GetFakeRatio();
279     break;
280     
281   case kTPCin: case kTPCrefit:
282     fTPCLabel = t->GetLabel();
283     fIalpha=fRalpha;
284     fIx=fRx;    
285     {
286       Int_t i;
287       for (i=0; i<5; i++) fIp[i]=fRp[i];
288       for (i=0; i<15;i++) fIc[i]=fRc[i];
289     }
290   case kTPCout:
291   
292     fTPCncls=t->GetNumberOfClusters();
293     fTPCchi2=t->GetChi2();
294     
295      {//prevrow must be declared in separate namespace, otherwise compiler cries:
296       //"jump to case label crosses initialization of `Int_t prevrow'"
297        Int_t prevrow = -1;
298        //       for (Int_t i=0;i<fTPCncls;i++) 
299        for (Int_t i=0;i<160;i++) 
300         {
301           fTPCindex[i]=t->GetClusterIndex(i);
302
303           // Piotr's Cluster Map for HBT  
304           // ### please change accordingly if cluster array is changing 
305           // to "New TPC Tracking" style (with gaps in array) 
306           Int_t idx = fTPCindex[i];
307           Int_t sect = (idx&0xff000000)>>24;
308           Int_t row = (idx&0x00ff0000)>>16;
309           if (sect > 18) row +=63; //if it is outer sector, add number of inner sectors
310
311           fTPCClusterMap.SetBitNumber(row,kTRUE);
312
313           //Fill the gap between previous row and this row with 0 bits
314           //In case  ###  pleas change it as well - just set bit 0 in case there 
315           //is no associated clusters for current "i"
316           if (prevrow < 0) 
317            {
318              prevrow = row;//if previous bit was not assigned yet == this is the first one
319            }
320           else
321            { //we don't know the order (inner to outer or reverse)
322              //just to be save in case it is going to change
323              Int_t n = 0, m = 0;
324              if (prevrow < row)
325               {
326                 n = prevrow;
327                 m = row;
328               }
329              else
330               {
331                 n = row;
332                 m = prevrow;
333               }
334
335              for (Int_t j = n+1; j < m; j++)
336               {
337                 fTPCClusterMap.SetBitNumber(j,kFALSE);
338               }
339              prevrow = row; 
340            }
341           // End Of Piotr's Cluster Map for HBT
342         }
343      }
344     fTPCsignal=t->GetPIDsignal();
345     {Double_t mass=t->GetMass();    // preliminary mass setting 
346     if (mass>0.5) fR[4]=1.;         //        used by
347     else if (mass<0.4) fR[2]=1.;    // the ITS reconstruction
348     else fR[3]=1.;}
349                      //
350     break;
351
352   case kTRDout: case kTRDin: case kTRDrefit:
353     fTRDLabel = t->GetLabel(); 
354     fTRDncls=t->GetNumberOfClusters();
355     fTRDchi2=t->GetChi2();
356     for (Int_t i=0;i<fTRDncls;i++) fTRDindex[i]=t->GetClusterIndex(i);
357     fTRDsignal=t->GetPIDsignal();
358     break;
359   case kTRDbackup:
360     t->GetExternalParameters(fTx,fTp);
361     t->GetExternalCovariance(fTc);
362     fTalpha = t->GetAlpha();
363     fTRDncls0 = t->GetNumberOfClusters(); 
364     break;
365   case kTOFin: 
366     break;
367   case kTOFout: 
368     break;
369   case kTRDStop:
370     break;
371   default: 
372     AliError("Wrong flag !");
373     return kFALSE;
374   }
375
376   return rc;
377 }
378
379 //_______________________________________________________________________
380 void 
381 AliESDtrack::SetConstrainedTrackParams(const AliKalmanTrack *t, Double_t chi2) {
382   //
383   // This function sets the constrained track parameters 
384   //
385   Int_t i;
386   Double_t x,buf[15];
387   fCalpha=t->GetAlpha();
388   t->GetExternalParameters(x,buf); fCx=x;
389   for (i=0; i<5; i++) fCp[i]=buf[i];
390   t->GetExternalCovariance(buf);
391   for (i=0; i<15; i++) fCc[i]=buf[i];
392   fCchi2=chi2;
393 }
394
395
396 //_______________________________________________________________________
397 void AliESDtrack::GetExternalParameters(Double_t &x, Double_t p[5]) const {
398   //---------------------------------------------------------------------
399   // This function returns external representation of the track parameters
400   //---------------------------------------------------------------------
401   x=fRx;
402   for (Int_t i=0; i<5; i++) p[i]=fRp[i];
403 }
404
405 //_______________________________________________________________________
406 Bool_t AliESDtrack::GetExternalParametersAt(Double_t x, Double_t p[5]) const {
407   //---------------------------------------------------------------------
408   // This function returns external representation of the track parameters
409   // at the position given by the first argument 
410   //---------------------------------------------------------------------
411   Double_t dx=x-fRx;
412   Double_t f1=fRp[2], f2=f1 + dx*fRp[4]/AliKalmanTrack::GetConvConst();
413
414   if (TMath::Abs(f2) >= 0.9999) return kFALSE;
415   
416   Double_t r1=TMath::Sqrt(1.- f1*f1), r2=TMath::Sqrt(1.- f2*f2);
417   p[0] = fRp[0] + dx*(f1+f2)/(r1+r2);
418   p[1] = fRp[1] + dx*(f1+f2)/(f1*r2 + f2*r1)*fRp[3];
419   p[2] = f2;
420   p[3] = fRp[3];
421   p[4] = fRp[4];
422
423   return kTRUE;
424 }
425
426 //_______________________________________________________________________
427 void AliESDtrack::GetExternalCovariance(Double_t cov[15]) const {
428   //---------------------------------------------------------------------
429   // This function returns external representation of the cov. matrix
430   //---------------------------------------------------------------------
431   for (Int_t i=0; i<15; i++) cov[i]=fRc[i];
432 }
433
434
435 //_______________________________________________________________________
436 void 
437 AliESDtrack::GetConstrainedExternalParameters(Double_t &x, Double_t p[5])const{
438   //---------------------------------------------------------------------
439   // This function returns the constrained external track parameters
440   //---------------------------------------------------------------------
441   x=fCx;
442   for (Int_t i=0; i<5; i++) p[i]=fCp[i];
443 }
444 //_______________________________________________________________________
445 void 
446 AliESDtrack::GetConstrainedExternalCovariance(Double_t c[15]) const {
447   //---------------------------------------------------------------------
448   // This function returns the constrained external cov. matrix
449   //---------------------------------------------------------------------
450   for (Int_t i=0; i<15; i++) c[i]=fCc[i];
451 }
452
453
454 Double_t AliESDtrack::GetP() const {
455   //---------------------------------------------------------------------
456   // This function returns the track momentum
457   // Results for (nearly) straight tracks are meaningless !
458   //---------------------------------------------------------------------
459   if (TMath::Abs(fRp[4])<=0) return 0;
460   Double_t pt=1./TMath::Abs(fRp[4]);
461   return pt*TMath::Sqrt(1.+ fRp[3]*fRp[3]);
462 }
463
464 Bool_t Local2GlobalMomentum(Double_t p[3],Double_t alpha) {
465   //----------------------------------------------------------------
466   // This function performs local->global transformation of the
467   // track momentum.
468   // When called, the arguments are:
469   //    p[0] = 1/pt of the track;
470   //    p[1] = sine of local azim. angle of the track momentum;
471   //    p[2] = tangent of the track momentum dip angle;
472   //   alpha - rotation angle. 
473   // The result is returned as:
474   //    p[0] = px
475   //    p[1] = py
476   //    p[2] = pz
477   // Results for (nearly) straight tracks are meaningless !
478   //----------------------------------------------------------------
479   if (TMath::Abs(p[0])<=0)        return kFALSE;
480   if (TMath::Abs(p[1])> 0.999999) return kFALSE;
481
482   Double_t pt=1./TMath::Abs(p[0]);
483   Double_t cs=TMath::Cos(alpha), sn=TMath::Sin(alpha);
484   Double_t r=TMath::Sqrt(1 - p[1]*p[1]);
485   p[0]=pt*(r*cs - p[1]*sn); p[1]=pt*(p[1]*cs + r*sn); p[2]=pt*p[2];
486
487   return kTRUE;
488 }
489
490 Bool_t Local2GlobalPosition(Double_t r[3],Double_t alpha) {
491   //----------------------------------------------------------------
492   // This function performs local->global transformation of the
493   // track position.
494   // When called, the arguments are:
495   //    r[0] = local x
496   //    r[1] = local y
497   //    r[2] = local z
498   //   alpha - rotation angle. 
499   // The result is returned as:
500   //    r[0] = global x
501   //    r[1] = global y
502   //    r[2] = global z
503   //----------------------------------------------------------------
504   Double_t cs=TMath::Cos(alpha), sn=TMath::Sin(alpha), x=r[0];
505   r[0]=x*cs - r[1]*sn; r[1]=x*sn + r[1]*cs;
506
507   return kTRUE;
508 }
509
510 Bool_t AliESDtrack::GetConstrainedPxPyPz(Double_t *p) const {
511   //---------------------------------------------------------------------
512   // This function returns the constrained global track momentum components
513   // Results for (nearly) straight tracks are meaningless !
514   //---------------------------------------------------------------------
515   p[0]=fCp[4]; p[1]=fCp[2]; p[2]=fCp[3];
516   return Local2GlobalMomentum(p,fCalpha);
517 }  
518
519 Bool_t AliESDtrack::GetConstrainedXYZ(Double_t *r) const {
520   //---------------------------------------------------------------------
521   // This function returns the constrained global track position
522   //---------------------------------------------------------------------
523   r[0]=fCx; r[1]=fCp[0]; r[2]=fCp[1];
524   return Local2GlobalPosition(r,fCalpha);
525 }
526
527 Bool_t AliESDtrack::GetPxPyPz(Double_t *p) const {
528   //---------------------------------------------------------------------
529   // This function returns the global track momentum components
530   // Results for (nearly) straight tracks are meaningless !
531   //---------------------------------------------------------------------
532   p[0]=fRp[4]; p[1]=fRp[2]; p[2]=fRp[3];
533   return Local2GlobalMomentum(p,fRalpha);
534 }
535
536 Bool_t AliESDtrack::GetXYZ(Double_t *r) const {
537   //---------------------------------------------------------------------
538   // This function returns the global track position
539   //---------------------------------------------------------------------
540   r[0]=fRx; r[1]=fRp[0]; r[2]=fRp[1];
541   return Local2GlobalPosition(r,fRalpha);
542 }
543
544 void AliESDtrack::GetCovariance(Double_t cv[21]) const {
545   //---------------------------------------------------------------------
546   // This function returns the global covariance matrix of the track params
547   // 
548   // Cov(x,x) ... :   cv[0]
549   // Cov(y,x) ... :   cv[1]  cv[2]
550   // Cov(z,x) ... :   cv[3]  cv[4]  cv[5]
551   // Cov(px,x)... :   cv[6]  cv[7]  cv[8]  cv[9]
552   // Cov(py,x)... :   cv[10] cv[11] cv[12] cv[13] cv[14]
553   // Cov(pz,x)... :   cv[15] cv[16] cv[17] cv[18] cv[19] cv[20]
554   //
555   // Results for (nearly) straight tracks are meaningless !
556   //---------------------------------------------------------------------
557   if (TMath::Abs(fRp[4])<=0) {
558      for (Int_t i=0; i<21; i++) cv[i]=0.;
559      return;
560   }
561   if (TMath::Abs(fRp[2]) > 0.999999) {
562      for (Int_t i=0; i<21; i++) cv[i]=0.;
563      return;
564   }
565   Double_t pt=1./TMath::Abs(fRp[4]);
566   Double_t cs=TMath::Cos(fRalpha), sn=TMath::Sin(fRalpha);
567   Double_t r=TMath::Sqrt(1-fRp[2]*fRp[2]);
568
569   Double_t m00=-sn, m10=cs;
570   Double_t m23=-pt*(sn + fRp[2]*cs/r), m43=-pt*pt*(r*cs - fRp[2]*sn);
571   Double_t m24= pt*(cs - fRp[2]*sn/r), m44=-pt*pt*(r*sn + fRp[2]*cs);
572   Double_t m35=pt, m45=-pt*pt*fRp[3];
573
574   cv[0]=fRc[0]*m00*m00;
575   cv[1]=fRc[0]*m00*m10; 
576   cv[2]=fRc[0]*m10*m10;
577   cv[3]=fRc[1]*m00; 
578   cv[4]=fRc[1]*m10; 
579   cv[5]=fRc[2];
580   cv[6]=m00*(fRc[3]*m23+fRc[10]*m43); 
581   cv[7]=m10*(fRc[3]*m23+fRc[10]*m43); 
582   cv[8]=fRc[4]*m23+fRc[11]*m43; 
583   cv[9]=m23*(fRc[5]*m23+fRc[12]*m43)+m43*(fRc[12]*m23+fRc[14]*m43);
584   cv[10]=m00*(fRc[3]*m24+fRc[10]*m44); 
585   cv[11]=m10*(fRc[3]*m24+fRc[10]*m44); 
586   cv[12]=fRc[4]*m24+fRc[11]*m44; 
587   cv[13]=m23*(fRc[5]*m24+fRc[12]*m44)+m43*(fRc[12]*m24+fRc[14]*m44);
588   cv[14]=m24*(fRc[5]*m24+fRc[12]*m44)+m44*(fRc[12]*m24+fRc[14]*m44);
589   cv[15]=m00*(fRc[6]*m35+fRc[10]*m45); 
590   cv[16]=m10*(fRc[6]*m35+fRc[10]*m45); 
591   cv[17]=fRc[7]*m35+fRc[11]*m45; 
592   cv[18]=m23*(fRc[8]*m35+fRc[12]*m45)+m43*(fRc[13]*m35+fRc[14]*m45);
593   cv[19]=m24*(fRc[8]*m35+fRc[12]*m45)+m44*(fRc[13]*m35+fRc[14]*m45); 
594   cv[20]=m35*(fRc[9]*m35+fRc[13]*m45)+m45*(fRc[13]*m35+fRc[14]*m45);
595 }
596
597 Bool_t AliESDtrack::GetInnerPxPyPz(Double_t *p) const {
598   //---------------------------------------------------------------------
599   // This function returns the global track momentum components
600   // af the entrance of the TPC
601   //---------------------------------------------------------------------
602   p[0]=fIp[4]; p[1]=fIp[2]; p[2]=fIp[3];
603   return Local2GlobalMomentum(p,fIalpha);
604 }
605
606 Bool_t AliESDtrack::GetInnerXYZ(Double_t *r) const {
607   //---------------------------------------------------------------------
608   // This function returns the global track position
609   // af the entrance of the TPC
610   //---------------------------------------------------------------------
611   if (fIx==0) return kFALSE;
612   r[0]=fIx; r[1]=fIp[0]; r[2]=fIp[1];
613   return Local2GlobalPosition(r,fIalpha);
614 }
615
616 void AliESDtrack::GetInnerExternalParameters(Double_t &x, Double_t p[5]) const 
617 {
618   //skowron
619  //---------------------------------------------------------------------
620   // This function returns external representation of the track parameters at Inner Layer of TPC
621   //---------------------------------------------------------------------
622   x=fIx;
623   for (Int_t i=0; i<5; i++) p[i]=fIp[i];
624 }
625 void AliESDtrack::GetInnerExternalCovariance(Double_t cov[15]) const
626 {
627  //skowron
628  //---------------------------------------------------------------------
629  // This function returns external representation of the cov. matrix at Inner Layer of TPC
630  //---------------------------------------------------------------------
631  for (Int_t i=0; i<15; i++) cov[i]=fIc[i];
632  
633 }
634
635 void  AliESDtrack::GetTRDExternalParameters(Double_t &x, Double_t&alpha, Double_t p[5], Double_t cov[15]) const
636 {
637   //
638   //this function returns TRD parameters
639   //
640   x=fTx;
641   alpha = fTalpha; 
642   for (Int_t i=0; i<5; i++) p[i]=fTp[i];
643   for (Int_t i=0; i<15; i++) cov[i]=fTc[i];
644 }
645
646 Bool_t AliESDtrack::GetPxPyPzAt(Double_t x,Double_t *p) const {
647   //---------------------------------------------------------------------
648   // This function returns the global track momentum components
649   // at the position "x" using the helix track approximation
650   //---------------------------------------------------------------------
651   p[0]=fRp[4]; 
652   p[1]=fRp[2]+(x-fRx)*fRp[4]/AliKalmanTrack::GetConvConst(); 
653   p[2]=fRp[3];
654   return Local2GlobalMomentum(p,fRalpha);
655 }
656
657 Bool_t AliESDtrack::GetXYZAt(Double_t x, Double_t *r) const {
658   //---------------------------------------------------------------------
659   // This function returns the global track position
660   // af the radius "x" using the helix track approximation
661   //---------------------------------------------------------------------
662   Double_t dx=x-fRx;
663   Double_t f1=fRp[2], f2=f1 + dx*fRp[4]/AliKalmanTrack::GetConvConst();
664
665   if (TMath::Abs(f2) >= 0.9999) return kFALSE;
666   
667   Double_t r1=TMath::Sqrt(1.- f1*f1), r2=TMath::Sqrt(1.- f2*f2);
668   r[0] = x;
669   r[1] = fRp[0] + dx*(f1+f2)/(r1+r2);
670   r[2] = fRp[1] + dx*(f1+f2)/(f1*r2 + f2*r1)*fRp[3];
671   return Local2GlobalPosition(r,fRalpha);
672 }
673
674 //_______________________________________________________________________
675 void AliESDtrack::GetIntegratedTimes(Double_t *times) const {
676   // Returns the array with integrated times for each particle hypothesis
677   for (Int_t i=0; i<AliPID::kSPECIES; i++) times[i]=fTrackTime[i];
678 }
679
680 //_______________________________________________________________________
681 void AliESDtrack::SetIntegratedTimes(const Double_t *times) {
682   // Sets the array with integrated times for each particle hypotesis
683   for (Int_t i=0; i<AliPID::kSPECIES; i++) fTrackTime[i]=times[i];
684 }
685
686 //_______________________________________________________________________
687 void AliESDtrack::SetITSpid(const Double_t *p) {
688   // Sets values for the probability of each particle type (in ITS)
689   for (Int_t i=0; i<AliPID::kSPECIES; i++) fITSr[i]=p[i];
690   SetStatus(AliESDtrack::kITSpid);
691 }
692
693 void AliESDtrack::SetITSChi2MIP(const Float_t *chi2mip){
694   for (Int_t i=0; i<12; i++) fITSchi2MIP[i]=chi2mip[i];
695 }
696 //_______________________________________________________________________
697 void AliESDtrack::GetITSpid(Double_t *p) const {
698   // Gets the probability of each particle type (in ITS)
699   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fITSr[i];
700 }
701
702 //_______________________________________________________________________
703 Int_t AliESDtrack::GetITSclusters(UInt_t *idx) const {
704   //---------------------------------------------------------------------
705   // This function returns indices of the assgined ITS clusters 
706   //---------------------------------------------------------------------
707   for (Int_t i=0; i<fITSncls; i++) idx[i]=fITSindex[i];
708   return fITSncls;
709 }
710
711 //_______________________________________________________________________
712 Int_t AliESDtrack::GetTPCclusters(Int_t *idx) const {
713   //---------------------------------------------------------------------
714   // This function returns indices of the assgined ITS clusters 
715   //---------------------------------------------------------------------
716   if (idx!=0)
717     for (Int_t i=0; i<180; i++) idx[i]=fTPCindex[i];  // MI I prefer some constant
718   return fTPCncls;
719 }
720
721 //_______________________________________________________________________
722 void AliESDtrack::SetTPCpid(const Double_t *p) {  
723   // Sets values for the probability of each particle type (in TPC)
724   for (Int_t i=0; i<AliPID::kSPECIES; i++) fTPCr[i]=p[i];
725   SetStatus(AliESDtrack::kTPCpid);
726 }
727
728 //_______________________________________________________________________
729 void AliESDtrack::GetTPCpid(Double_t *p) const {
730   // Gets the probability of each particle type (in TPC)
731   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTPCr[i];
732 }
733
734 //_______________________________________________________________________
735 Int_t AliESDtrack::GetTRDclusters(UInt_t *idx) const {
736   //---------------------------------------------------------------------
737   // This function returns indices of the assgined TRD clusters 
738   //---------------------------------------------------------------------
739   if (idx!=0)
740     for (Int_t i=0; i<130; i++) idx[i]=fTRDindex[i];  // MI I prefer some constant
741   return fTRDncls;
742 }
743
744 //_______________________________________________________________________
745 void AliESDtrack::SetTRDpid(const Double_t *p) {  
746   // Sets values for the probability of each particle type (in TRD)
747   for (Int_t i=0; i<AliPID::kSPECIES; i++) fTRDr[i]=p[i];
748   SetStatus(AliESDtrack::kTRDpid);
749 }
750
751 //_______________________________________________________________________
752 void AliESDtrack::GetTRDpid(Double_t *p) const {
753   // Gets the probability of each particle type (in TRD)
754   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTRDr[i];
755 }
756
757 //_______________________________________________________________________
758 void    AliESDtrack::SetTRDpid(Int_t iSpecies, Float_t p)
759 {
760   // Sets the probability of particle type iSpecies to p (in TRD)
761   fTRDr[iSpecies] = p;
762 }
763
764 Float_t AliESDtrack::GetTRDpid(Int_t iSpecies) const
765 {
766   // Returns the probability of particle type iSpecies (in TRD)
767   return fTRDr[iSpecies];
768 }
769
770 //_______________________________________________________________________
771 void AliESDtrack::SetTOFpid(const Double_t *p) {  
772   // Sets the probability of each particle type (in TOF)
773   for (Int_t i=0; i<AliPID::kSPECIES; i++) fTOFr[i]=p[i];
774   SetStatus(AliESDtrack::kTOFpid);
775 }
776
777 //_______________________________________________________________________
778 void AliESDtrack::SetTOFLabel(const Int_t *p) {  
779   // Sets  (in TOF)
780   for (Int_t i=0; i<3; i++) fTOFLabel[i]=p[i];
781 }
782
783 //_______________________________________________________________________
784 void AliESDtrack::GetTOFpid(Double_t *p) const {
785   // Gets probabilities of each particle type (in TOF)
786   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTOFr[i];
787 }
788
789 //_______________________________________________________________________
790 void AliESDtrack::GetTOFLabel(Int_t *p) const {
791   // Gets (in TOF)
792   for (Int_t i=0; i<3; i++) p[i]=fTOFLabel[i];
793 }
794
795 //_______________________________________________________________________
796 void AliESDtrack::GetTOFInfo(Float_t *info) const {
797   // Gets (in TOF)
798   for (Int_t i=0; i<10; i++) info[i]=fTOFInfo[i];
799 }
800
801 //_______________________________________________________________________
802 void AliESDtrack::SetTOFInfo(Float_t*info) {
803   // Gets (in TOF)
804   for (Int_t i=0; i<10; i++) fTOFInfo[i]=info[i];
805 }
806
807
808
809 //_______________________________________________________________________
810 void AliESDtrack::SetPHOSpid(const Double_t *p) {  
811   // Sets the probability of each particle type (in PHOS)
812   for (Int_t i=0; i<AliPID::kSPECIESN; i++) fPHOSr[i]=p[i];
813   SetStatus(AliESDtrack::kPHOSpid);
814 }
815
816 //_______________________________________________________________________
817 void AliESDtrack::GetPHOSpid(Double_t *p) const {
818   // Gets probabilities of each particle type (in PHOS)
819   for (Int_t i=0; i<AliPID::kSPECIESN; i++) p[i]=fPHOSr[i];
820 }
821
822 //_______________________________________________________________________
823 void AliESDtrack::SetEMCALpid(const Double_t *p) {  
824   // Sets the probability of each particle type (in EMCAL)
825   for (Int_t i=0; i<AliPID::kSPECIESN; i++) fEMCALr[i]=p[i];
826   SetStatus(AliESDtrack::kEMCALpid);
827 }
828
829 //_______________________________________________________________________
830 void AliESDtrack::GetEMCALpid(Double_t *p) const {
831   // Gets probabilities of each particle type (in EMCAL)
832   for (Int_t i=0; i<AliPID::kSPECIESN; i++) p[i]=fEMCALr[i];
833 }
834
835 //_______________________________________________________________________
836 void AliESDtrack::SetRICHpid(const Double_t *p) {  
837   // Sets the probability of each particle type (in RICH)
838   for (Int_t i=0; i<AliPID::kSPECIES; i++) fRICHr[i]=p[i];
839   SetStatus(AliESDtrack::kRICHpid);
840 }
841
842 //_______________________________________________________________________
843 void AliESDtrack::GetRICHpid(Double_t *p) const {
844   // Gets probabilities of each particle type (in RICH)
845   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fRICHr[i];
846 }
847
848
849
850 //_______________________________________________________________________
851 void AliESDtrack::SetESDpid(const Double_t *p) {  
852   // Sets the probability of each particle type for the ESD track
853   for (Int_t i=0; i<AliPID::kSPECIES; i++) fR[i]=p[i];
854   SetStatus(AliESDtrack::kESDpid);
855 }
856
857 //_______________________________________________________________________
858 void AliESDtrack::GetESDpid(Double_t *p) const {
859   // Gets probability of each particle type for the ESD track
860   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fR[i];
861 }
862
863 //_______________________________________________________________________
864 void AliESDtrack::Print(Option_t *) const {
865   // Prints info on the track
866   
867   printf("ESD track info\n") ; 
868   Double_t p[AliPID::kSPECIESN] ; 
869   Int_t index = 0 ; 
870   if( IsOn(kITSpid) ){
871     printf("From ITS: ") ; 
872     GetITSpid(p) ; 
873     for(index = 0 ; index < AliPID::kSPECIES; index++) 
874       printf("%f, ", p[index]) ;
875     printf("\n           signal = %f\n", GetITSsignal()) ;
876   } 
877   if( IsOn(kTPCpid) ){
878     printf("From TPC: ") ; 
879     GetTPCpid(p) ; 
880     for(index = 0 ; index < AliPID::kSPECIES; index++) 
881       printf("%f, ", p[index]) ;
882     printf("\n           signal = %f\n", GetTPCsignal()) ;
883   }
884   if( IsOn(kTRDpid) ){
885     printf("From TRD: ") ; 
886     GetTRDpid(p) ; 
887     for(index = 0 ; index < AliPID::kSPECIES; index++) 
888       printf("%f, ", p[index]) ;
889     printf("\n           signal = %f\n", GetTRDsignal()) ;
890   }
891   if( IsOn(kTOFpid) ){
892     printf("From TOF: ") ; 
893     GetTOFpid(p) ; 
894     for(index = 0 ; index < AliPID::kSPECIES; index++) 
895       printf("%f, ", p[index]) ;
896     printf("\n           signal = %f\n", GetTOFsignal()) ;
897   }
898   if( IsOn(kRICHpid) ){
899     printf("From TOF: ") ; 
900     GetRICHpid(p) ; 
901     for(index = 0 ; index < AliPID::kSPECIES; index++) 
902       printf("%f, ", p[index]) ;
903     printf("\n           signal = %f\n", GetRICHsignal()) ;
904   }
905   if( IsOn(kPHOSpid) ){
906     printf("From PHOS: ") ; 
907     GetPHOSpid(p) ; 
908     for(index = 0 ; index < AliPID::kSPECIESN; index++) 
909       printf("%f, ", p[index]) ;
910     printf("\n           signal = %f\n", GetPHOSsignal()) ;
911   }
912   if( IsOn(kEMCALpid) ){
913     printf("From EMCAL: ") ; 
914     GetEMCALpid(p) ; 
915     for(index = 0 ; index < AliPID::kSPECIESN; index++) 
916       printf("%f, ", p[index]) ;
917     printf("\n           signal = %f\n", GetEMCALsignal()) ;
918   }
919