]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDtrack.cxx
Updated DAs to comply with root known problems
[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 //
24 //  What do you need to know before starting analysis
25 //  (by Marian Ivanov: marian.ivanov@cern.ch)
26 //
27 //
28 //   AliESDtrack:
29 //   1.  What is the AliESDtrack
30 //   2.  What informations do we store
31 //   3.  How to use the information for analysis
32 //   
33 //
34 //   1.AliESDtrack is the container of the information about the track/particle
35 //     reconstructed during Barrel Tracking.
36 //     The track information is propagated from one tracking detector to 
37 //     other using the functionality of AliESDtrack - Current parameters.  
38 //
39 //     No global fit model is used.
40 //     Barrel tracking use Kalman filtering technique, it gives optimal local 
41 //     track parameters at given point under certian assumptions.
42 //             
43 //     Kalman filter take into account additional effect which are 
44 //     difficult to handle using global fit.
45 //     Effects:
46 //        a.) Multiple scattering
47 //        b.) Energy loss
48 //        c.) Non homogenous magnetic field
49 //
50 //     In general case, following barrel detectors are contributing to 
51 //     the Kalman track information:
52 //         a. TPC
53 //         b. ITS
54 //         c. TRD
55 //
56 //      In general 3 reconstruction itteration are performed:
57 //         1. Find tracks   - sequence TPC->ITS
58 //         2. PropagateBack - sequence ITS->TPC->TRD -> Outer PID detectors
59 //         3. Refit invward - sequence TRD->TPC->ITS
60 //      The current tracks are updated after each detector (see bellow).
61 //      In specical cases a track  sanpshots are stored.   
62 // 
63 //
64 //      For some type of analysis (+visualization) track local parameters at 
65 //      different position are neccesary. A snapshots during the track 
66 //      propagation are created.
67 //      (See AliExternalTrackParam class for desctiption of variables and 
68 //      functionality)
69 //      Snapshots:
70 //      a. Current parameters - class itself (AliExternalTrackParam)
71 //         Contributors: general case TRD->TPC->ITS
72 //         Preferable usage:  Decission  - primary or secondary track
73 //         NOTICE - By default the track parameters are stored at the DCA point
74 //                  to the primary vertex. optimal for primary tracks, 
75 //                  far from optimal for secondary tracks.
76 //      b. Constrained parameters - Kalman information updated with 
77 //         the Primary vertex information 
78 //         Contributors: general case TRD->TPC->ITS
79 //         Preferable usage: Use only for tracks selected as primary
80 //         NOTICE - not real constrain - taken as additional measurement 
81 //         with corresponding error
82 //         Function:  
83 //       const AliExternalTrackParam *GetConstrainedParam() const {return fCp;}
84 //      c. Inner parameters -  Track parameters at inner wall of the TPC 
85 //         Contributors: general case TRD->TPC
86 //         function:
87 //           const AliExternalTrackParam *GetInnerParam() const { return fIp;}
88 //
89 //      d. TPCinnerparam  - contributors - TPC only
90 //         Contributors:  TPC
91 //         Preferable usage: Requested for HBT study 
92 //                         (smaller correlations as using also ITS information)
93 //         NOTICE - the track parameters are propagated to the DCA to  
94 //         to primary vertex
95 //         Optimal for primary, far from optimal for secondary tracks
96 //         Function:
97 //    const AliExternalTrackParam *GetTPCInnerParam() const {return fTPCInner;}
98 //     
99 //      e. Outer parameters - 
100 //           Contributors-  general case - ITS-> TPC -> TRD
101 //           The last point - Outer parameters radius is determined
102 //           e.a) Local inclination angle bigger than threshold - 
103 //                Low momenta tracks 
104 //           e.a) Catastrofic energy losss in material
105 //           e.b) Not further improvement (no space points)
106 //           Usage:             
107 //              a.) Tracking: Starting parameter for Refit inward 
108 //              b.) Visualization
109 //              c.) QA
110 //         NOTICE: Should be not used for the physic analysis
111 //         Function:
112 //            const AliExternalTrackParam *GetOuterParam() const { return fOp;}
113 //
114 //-----------------------------------------------------------------
115
116 #include <TMath.h>
117 #include <TParticle.h>
118
119 #include "AliESDVertex.h"
120 #include "AliESDtrack.h"
121 #include "AliKalmanTrack.h"
122 #include "AliVTrack.h"
123 #include "AliLog.h"
124 #include "AliTrackPointArray.h"
125 #include "TPolyMarker3D.h"
126
127 ClassImp(AliESDtrack)
128
129 void SetPIDValues(Double_t * dest, const Double_t * src, Int_t n) {
130   // This function copies "n" PID weights from "scr" to "dest"
131   // and normalizes their sum to 1 thus producing conditional probabilities.
132   // The negative weights are set to 0.
133   // In case all the weights are non-positive they are replaced by
134   // uniform probabilities
135
136   if (n<=0) return;
137
138   Float_t uniform = 1./(Float_t)n;
139
140   Float_t sum = 0;
141   for (Int_t i=0; i<n; i++) 
142     if (src[i]>=0) {
143       sum+=src[i];
144       dest[i] = src[i];
145     }
146     else {
147       dest[i] = 0;
148     }
149
150   if(sum>0)
151     for (Int_t i=0; i<n; i++) dest[i] /= sum;
152   else
153     for (Int_t i=0; i<n; i++) dest[i] = uniform;
154 }
155
156 //_______________________________________________________________________
157 AliESDtrack::AliESDtrack() : 
158   AliExternalTrackParam(),
159   fCp(0),
160   fIp(0),
161   fTPCInner(0),
162   fOp(0),
163   fFriendTrack(new AliESDfriendTrack()),
164   fTPCClusterMap(159),//number of padrows
165   fTPCSharedMap(159),//number of padrows
166   fFlags(0),
167   fID(0),
168   fLabel(0),
169   fITSLabel(0),
170   fTPCLabel(0),
171   fTRDLabel(0),
172   fTOFCalChannel(0),
173   fTOFindex(-1),
174   fHMPIDqn(0),
175   fHMPIDcluIdx(-1),
176   fEMCALindex(kEMCALNoMatch),
177   fHMPIDtrkTheta(0),
178   fHMPIDtrkPhi(0),
179   fHMPIDsignal(0),
180   fTrackLength(0),
181   fdTPC(0),fzTPC(0),
182   fCddTPC(0),fCdzTPC(0),fCzzTPC(0),
183   fCchi2TPC(0),
184   fD(0),fZ(0),
185   fCdd(0),fCdz(0),fCzz(0),
186   fCchi2(0),
187   fITSchi2(0),
188   fTPCchi2(0),
189   fTRDchi2(0),
190   fTOFchi2(0),
191   fHMPIDchi2(0),
192   fGlobalChi2(0),
193   fITSsignal(0),
194   fTPCsignal(0),
195   fTPCsignalS(0),
196   fTRDsignal(0),
197   fTRDQuality(0),
198   fTRDBudget(0),
199   fTOFsignal(0),
200   fTOFsignalToT(0),
201   fTOFsignalRaw(0),
202   fTOFsignalDz(0),
203   fHMPIDtrkX(0),
204   fHMPIDtrkY(0),
205   fHMPIDmipX(0),
206   fHMPIDmipY(0),
207   fTPCncls(0),
208   fTPCnclsF(0),
209   fTPCsignalN(0),
210   fITSncls(0),
211   fITSClusterMap(0),
212   fTRDncls(0),
213   fTRDncls0(0),
214   fTRDntracklets(0),
215   fTRDnSlices(0),
216   fTRDslices(0x0),
217   fVertexID(-2) // -2 means an orphan track 
218 {
219   //
220   // The default ESD constructor 
221   //
222   Int_t i;
223   for (i=0; i<AliPID::kSPECIES; i++) {
224     fTrackTime[i]=0.;
225     fR[i]=0.;
226     fITSr[i]=0.;
227     fTPCr[i]=0.;
228     fTRDr[i]=0.;
229     fTOFr[i]=0.;
230     fHMPIDr[i]=0.;
231   }
232   
233   for (i=0; i<3; i++)   { fKinkIndexes[i]=0;}
234   for (i=0; i<3; i++)   { fV0Indexes[i]=0;}
235   for (i=0;i<kTRDnPlanes;i++) {
236     fTRDTimBin[i]=0;
237   }
238   for (i=0;i<4;i++) {fITSdEdxSamples[i]=0.;}
239   for (i=0;i<4;i++) {fTPCPoints[i]=0;}
240   for (i=0;i<3;i++) {fTOFLabel[i]=0;}
241   for (i=0;i<10;i++) {fTOFInfo[i]=0;}
242   for (i=0;i<12;i++) {fITSModule[i]=-1;}
243 }
244
245 //_______________________________________________________________________
246 AliESDtrack::AliESDtrack(const AliESDtrack& track):
247   AliExternalTrackParam(track),
248   fCp(0),
249   fIp(0),
250   fTPCInner(0),
251   fOp(0),
252   fFriendTrack(0),
253   fTPCClusterMap(track.fTPCClusterMap),
254   fTPCSharedMap(track.fTPCSharedMap),
255   fFlags(track.fFlags),
256   fID(track.fID),
257   fLabel(track.fLabel),
258   fITSLabel(track.fITSLabel),
259   fTPCLabel(track.fTPCLabel),
260   fTRDLabel(track.fTRDLabel),
261   fTOFCalChannel(track.fTOFCalChannel),
262   fTOFindex(track.fTOFindex),
263   fHMPIDqn(track.fHMPIDqn),
264   fHMPIDcluIdx(track.fHMPIDcluIdx),
265   fEMCALindex(track.fEMCALindex),
266   fHMPIDtrkTheta(track.fHMPIDtrkTheta),
267   fHMPIDtrkPhi(track.fHMPIDtrkPhi),
268   fHMPIDsignal(track.fHMPIDsignal),
269   fTrackLength(track.fTrackLength),
270   fdTPC(track.fdTPC),fzTPC(track.fzTPC),
271   fCddTPC(track.fCddTPC),fCdzTPC(track.fCdzTPC),fCzzTPC(track.fCzzTPC),
272   fCchi2TPC(track.fCchi2TPC),
273   fD(track.fD),fZ(track.fZ),
274   fCdd(track.fCdd),fCdz(track.fCdz),fCzz(track.fCzz),
275   fCchi2(track.fCchi2),
276   fITSchi2(track.fITSchi2),
277   fTPCchi2(track.fTPCchi2),
278   fTRDchi2(track.fTRDchi2),
279   fTOFchi2(track.fTOFchi2),
280   fHMPIDchi2(track.fHMPIDchi2),
281   fGlobalChi2(track.fGlobalChi2),
282   fITSsignal(track.fITSsignal),
283   fTPCsignal(track.fTPCsignal),
284   fTPCsignalS(track.fTPCsignalS),
285   fTRDsignal(track.fTRDsignal),
286   fTRDQuality(track.fTRDQuality),
287   fTRDBudget(track.fTRDBudget),
288   fTOFsignal(track.fTOFsignal),
289   fTOFsignalToT(track.fTOFsignalToT),
290   fTOFsignalRaw(track.fTOFsignalRaw),
291   fTOFsignalDz(track.fTOFsignalDz),
292   fHMPIDtrkX(track.fHMPIDtrkX),
293   fHMPIDtrkY(track.fHMPIDtrkY),
294   fHMPIDmipX(track.fHMPIDmipX),
295   fHMPIDmipY(track.fHMPIDmipY),
296   fTPCncls(track.fTPCncls),
297   fTPCnclsF(track.fTPCnclsF),
298   fTPCsignalN(track.fTPCsignalN),
299   fITSncls(track.fITSncls),
300   fITSClusterMap(track.fITSClusterMap),
301   fTRDncls(track.fTRDncls),
302   fTRDncls0(track.fTRDncls0),
303   fTRDntracklets(track.fTRDntracklets),
304   fTRDnSlices(track.fTRDnSlices),
305   fTRDslices(0x0),
306   fVertexID(track.fVertexID)
307 {
308   //
309   //copy constructor
310   //
311   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTrackTime[i]=track.fTrackTime[i];
312   for (Int_t i=0;i<AliPID::kSPECIES;i++)  fR[i]=track.fR[i];
313   //
314   for (Int_t i=0;i<AliPID::kSPECIES;i++) fITSr[i]=track.fITSr[i]; 
315   //
316   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTPCr[i]=track.fTPCr[i]; 
317   for (Int_t i=0;i<4;i++) {fITSdEdxSamples[i]=track.fITSdEdxSamples[i];}
318   for (Int_t i=0;i<4;i++) {fTPCPoints[i]=track.fTPCPoints[i];}
319   for (Int_t i=0; i<3;i++)   { fKinkIndexes[i]=track.fKinkIndexes[i];}
320   for (Int_t i=0; i<3;i++)   { fV0Indexes[i]=track.fV0Indexes[i];}
321   //
322   for (Int_t i=0;i<kTRDnPlanes;i++) {
323     fTRDTimBin[i]=track.fTRDTimBin[i];
324   }
325
326   if (fTRDnSlices) {
327     fTRDslices=new Double32_t[fTRDnSlices];
328     for (Int_t i=0; i<fTRDnSlices; i++) fTRDslices[i]=track.fTRDslices[i];
329   }
330
331   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTRDr[i]=track.fTRDr[i]; 
332   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTOFr[i]=track.fTOFr[i];
333   for (Int_t i=0;i<3;i++) fTOFLabel[i]=track.fTOFLabel[i];
334   for (Int_t i=0;i<10;i++) fTOFInfo[i]=track.fTOFInfo[i];
335   for (Int_t i=0;i<12;i++) fITSModule[i]=track.fITSModule[i];
336   for (Int_t i=0;i<AliPID::kSPECIES;i++) fHMPIDr[i]=track.fHMPIDr[i];
337
338   if (track.fCp) fCp=new AliExternalTrackParam(*track.fCp);
339   if (track.fIp) fIp=new AliExternalTrackParam(*track.fIp);
340   if (track.fTPCInner) fTPCInner=new AliExternalTrackParam(*track.fTPCInner);
341   if (track.fOp) fOp=new AliExternalTrackParam(*track.fOp);
342
343   if (track.fFriendTrack) fFriendTrack=new AliESDfriendTrack(*(track.fFriendTrack));
344 }
345
346 //_______________________________________________________________________
347 AliESDtrack::AliESDtrack(const AliVTrack *track) : 
348   AliExternalTrackParam(track),
349   fCp(0),
350   fIp(0),
351   fTPCInner(0),
352   fOp(0),
353   fFriendTrack(0),
354   fTPCClusterMap(159),//number of padrows
355   fTPCSharedMap(159),//number of padrows
356   fFlags(0),
357   fID(),
358   fLabel(0),
359   fITSLabel(0),
360   fTPCLabel(0),
361   fTRDLabel(0),
362   fTOFCalChannel(0),
363   fTOFindex(-1),
364   fHMPIDqn(0),
365   fHMPIDcluIdx(-1),
366   fEMCALindex(kEMCALNoMatch),
367   fHMPIDtrkTheta(0),
368   fHMPIDtrkPhi(0),
369   fHMPIDsignal(0),
370   fTrackLength(0),
371   fdTPC(0),fzTPC(0),
372   fCddTPC(0),fCdzTPC(0),fCzzTPC(0),
373   fCchi2TPC(0),
374   fD(0),fZ(0),
375   fCdd(0),fCdz(0),fCzz(0),
376   fCchi2(0),
377   fITSchi2(0),
378   fTPCchi2(0),
379   fTRDchi2(0),
380   fTOFchi2(0),
381   fHMPIDchi2(0),
382   fGlobalChi2(0),
383   fITSsignal(0),
384   fTPCsignal(0),
385   fTPCsignalS(0),
386   fTRDsignal(0),
387   fTRDQuality(0),
388   fTRDBudget(0),
389   fTOFsignal(0),
390   fTOFsignalToT(0),
391   fTOFsignalRaw(0),
392   fTOFsignalDz(0),
393   fHMPIDtrkX(0),
394   fHMPIDtrkY(0),
395   fHMPIDmipX(0),
396   fHMPIDmipY(0),
397   fTPCncls(0),
398   fTPCnclsF(0),
399   fTPCsignalN(0),
400   fITSncls(0),
401   fITSClusterMap(0),
402   fTRDncls(0),
403   fTRDncls0(0),
404   fTRDntracklets(0),
405   fTRDnSlices(0),
406   fTRDslices(0x0),
407   fVertexID(-2)  // -2 means an orphan track
408 {
409   //
410   // ESD track from AliVTrack.
411   // This is not a copy constructor !
412   //
413
414   if (track->InheritsFrom("AliExternalTrackParam")) {
415      AliError("This is not a copy constructor. Use AliESDtrack(const AliESDtrack &) !");
416      AliWarning("Calling the default constructor...");
417      AliESDtrack();
418      return;
419   }
420
421   // Reset all the arrays
422   Int_t i;
423   for (i=0; i<AliPID::kSPECIES; i++) {
424     fTrackTime[i]=0.;
425     fR[i]=0.;
426     fITSr[i]=0.;
427     fTPCr[i]=0.;
428     fTRDr[i]=0.;
429     fTOFr[i]=0.;
430     fHMPIDr[i]=0.;
431   }
432   
433   for (i=0; i<3; i++)   { fKinkIndexes[i]=0;}
434   for (i=0; i<3; i++)   { fV0Indexes[i]=-1;}
435   for (i=0;i<kTRDnPlanes;i++) {
436     fTRDTimBin[i]=0;
437   }
438   for (i=0;i<4;i++) {fITSdEdxSamples[i]=0.;}
439   for (i=0;i<4;i++) {fTPCPoints[i]=0;}
440   for (i=0;i<3;i++) {fTOFLabel[i]=0;}
441   for (i=0;i<10;i++) {fTOFInfo[i]=0;}
442   for (i=0;i<12;i++) {fITSModule[i]=-1;}
443
444   // Set the ID
445   SetID(track->GetID());
446
447   // Set ITS cluster map
448   fITSClusterMap=track->GetITSClusterMap();
449
450   fITSncls=0;
451   for(i=0; i<6; i++) {
452     if(HasPointOnITSLayer(i)) fITSncls++;
453   }
454
455   // Set the combined PID
456   const Double_t *pid = track->PID();
457   if(pid){
458     for (i=0; i<AliPID::kSPECIES; i++) fR[i]=pid[i];
459   }
460   // AliESD track label
461   SetLabel(track->GetLabel());
462   // Set the status
463   SetStatus(track->GetStatus());
464 }
465
466 //_______________________________________________________________________
467 AliESDtrack::AliESDtrack(TParticle * part) : 
468   AliExternalTrackParam(),
469   fCp(0),
470   fIp(0),
471   fTPCInner(0),
472   fOp(0),
473   fFriendTrack(0),
474   fTPCClusterMap(159),//number of padrows
475   fTPCSharedMap(159),//number of padrows
476   fFlags(0),
477   fID(0),
478   fLabel(0),
479   fITSLabel(0),
480   fTPCLabel(0),
481   fTRDLabel(0),
482   fTOFCalChannel(0),
483   fTOFindex(-1),
484   fHMPIDqn(0),
485   fHMPIDcluIdx(-1),
486   fEMCALindex(kEMCALNoMatch),
487   fHMPIDtrkTheta(0),
488   fHMPIDtrkPhi(0),
489   fHMPIDsignal(0),
490   fTrackLength(0),
491   fdTPC(0),fzTPC(0),
492   fCddTPC(0),fCdzTPC(0),fCzzTPC(0),
493   fCchi2TPC(0),
494   fD(0),fZ(0),
495   fCdd(0),fCdz(0),fCzz(0),
496   fCchi2(0),
497   fITSchi2(0),
498   fTPCchi2(0),
499   fTRDchi2(0),
500   fTOFchi2(0),
501   fHMPIDchi2(0),
502   fGlobalChi2(0),
503   fITSsignal(0),
504   fTPCsignal(0),
505   fTPCsignalS(0),
506   fTRDsignal(0),
507   fTRDQuality(0),
508   fTRDBudget(0),
509   fTOFsignal(0),
510   fTOFsignalToT(0),
511   fTOFsignalRaw(0),
512   fTOFsignalDz(0),
513   fHMPIDtrkX(0),
514   fHMPIDtrkY(0),
515   fHMPIDmipX(0),
516   fHMPIDmipY(0),
517   fTPCncls(0),
518   fTPCnclsF(0),
519   fTPCsignalN(0),
520   fITSncls(0),
521   fITSClusterMap(0),
522   fTRDncls(0),
523   fTRDncls0(0),
524   fTRDntracklets(0),
525   fTRDnSlices(0),
526   fTRDslices(0x0),
527   fVertexID(-2)  // -2 means an orphan track
528 {
529   //
530   // ESD track from TParticle
531   //
532
533   // Reset all the arrays
534   Int_t i;
535   for (i=0; i<AliPID::kSPECIES; i++) {
536     fTrackTime[i]=0.;
537     fR[i]=0.;
538     fITSr[i]=0.;
539     fTPCr[i]=0.;
540     fTRDr[i]=0.;
541     fTOFr[i]=0.;
542     fHMPIDr[i]=0.;
543   }
544   
545   for (i=0; i<3; i++)   { fKinkIndexes[i]=0;}
546   for (i=0; i<3; i++)   { fV0Indexes[i]=-1;}
547   for (i=0;i<kTRDnPlanes;i++) {
548     fTRDTimBin[i]=0;
549   }
550   for (i=0;i<4;i++) {fITSdEdxSamples[i]=0.;}
551   for (i=0;i<4;i++) {fTPCPoints[i]=0;}
552   for (i=0;i<3;i++) {fTOFLabel[i]=0;}
553   for (i=0;i<10;i++) {fTOFInfo[i]=0;}
554   for (i=0;i<12;i++) {fITSModule[i]=-1;}
555
556   // Calculate the AliExternalTrackParam content
557
558   Double_t xref;
559   Double_t alpha;
560   Double_t param[5];
561   Double_t covar[15];
562
563   // Calculate alpha: the rotation angle of the corresponding local system (TPC sector)
564   alpha = part->Phi()*180./TMath::Pi();
565   if (alpha<0) alpha+= 360.;
566   if (alpha>360) alpha -= 360.;
567
568   Int_t sector = (Int_t)(alpha/20.);
569   alpha = 10. + 20.*sector;
570   alpha /= 180;
571   alpha *= TMath::Pi();
572
573   // Covariance matrix: no errors, the parameters are exact
574   for (i=0; i<15; i++) covar[i]=0.;
575
576   // Get the vertex of origin and the momentum
577   TVector3 ver(part->Vx(),part->Vy(),part->Vz());
578   TVector3 mom(part->Px(),part->Py(),part->Pz());
579
580   // Rotate to the local coordinate system (TPC sector)
581   ver.RotateZ(-alpha);
582   mom.RotateZ(-alpha);
583
584   // X of the referense plane
585   xref = ver.X();
586
587   Int_t pdgCode = part->GetPdgCode();
588
589   Double_t charge = 
590     TDatabasePDG::Instance()->GetParticle(pdgCode)->Charge();
591
592   param[0] = ver.Y();
593   param[1] = ver.Z();
594   param[2] = TMath::Sin(mom.Phi());
595   param[3] = mom.Pz()/mom.Pt();
596   param[4] = TMath::Sign(1/mom.Pt(),charge);
597
598   // Set AliExternalTrackParam
599   Set(xref, alpha, param, covar);
600
601   // Set the PID
602   Int_t indexPID = 99;
603
604   switch (TMath::Abs(pdgCode)) {
605
606   case  11: // electron
607     indexPID = 0;
608     break;
609
610   case 13: // muon
611     indexPID = 1;
612     break;
613
614   case 211: // pion
615     indexPID = 2;
616     break;
617
618   case 321: // kaon
619     indexPID = 3;
620     break;
621
622   case 2212: // proton
623     indexPID = 4;
624     break;
625
626   default:
627     break;
628   }
629
630   // If the particle is not e,mu,pi,K or p the PID probabilities are set to 0
631   if (indexPID < AliPID::kSPECIES) {
632     fR[indexPID]=1.;
633     fITSr[indexPID]=1.;
634     fTPCr[indexPID]=1.;
635     fTRDr[indexPID]=1.;
636     fTOFr[indexPID]=1.;
637     fHMPIDr[indexPID]=1.;
638
639   }
640   // AliESD track label
641   SetLabel(part->GetUniqueID());
642
643 }
644
645 //_______________________________________________________________________
646 AliESDtrack::~AliESDtrack(){ 
647   //
648   // This is destructor according Coding Conventrions 
649   //
650   //printf("Delete track\n");
651   delete fIp; 
652   delete fTPCInner; 
653   delete fOp;
654   delete fCp; 
655   delete fFriendTrack;
656   if(fTRDnSlices)
657     delete[] fTRDslices;
658 }
659
660 AliESDtrack &AliESDtrack::operator=(const AliESDtrack &source){
661   
662
663   if(&source == this) return *this;
664   AliExternalTrackParam::operator=(source);
665
666   
667   if(source.fCp){
668     // we have the trackparam: assign or copy construct
669     if(fCp)*fCp = *source.fCp;
670     else fCp = new AliExternalTrackParam(*source.fCp);
671   }
672   else{
673     // no track param delete the old one
674     if(fCp)delete fCp;
675     fCp = 0;
676   }
677
678   if(source.fIp){
679     // we have the trackparam: assign or copy construct
680     if(fIp)*fIp = *source.fIp;
681     else fIp = new AliExternalTrackParam(*source.fIp);
682   }
683   else{
684     // no track param delete the old one
685     if(fIp)delete fIp;
686     fIp = 0;
687   }
688
689
690   if(source.fTPCInner){
691     // we have the trackparam: assign or copy construct
692     if(fTPCInner) *fTPCInner = *source.fTPCInner;
693     else fTPCInner = new AliExternalTrackParam(*source.fTPCInner);
694   }
695   else{
696     // no track param delete the old one
697     if(fTPCInner)delete fTPCInner;
698     fTPCInner = 0;
699   }
700
701
702   if(source.fOp){
703     // we have the trackparam: assign or copy construct
704     if(fOp) *fOp = *source.fOp;
705     else fOp = new AliExternalTrackParam(*source.fOp);
706   }
707   else{
708     // no track param delete the old one
709     if(fOp)delete fOp;
710     fOp = 0;
711   }
712
713   // copy also the friend track 
714   // use copy constructor
715   if(source.fFriendTrack){
716     // we have the trackparam: assign or copy construct
717     delete fFriendTrack; fFriendTrack=new AliESDfriendTrack(*source.fFriendTrack);
718   }
719   else{
720     // no track param delete the old one
721     delete fFriendTrack; fFriendTrack= 0;
722   }
723
724   fTPCClusterMap = source.fTPCClusterMap; 
725   fTPCSharedMap  = source.fTPCSharedMap;  
726   // the simple stuff
727   fFlags    = source.fFlags; 
728   fID       = source.fID;             
729   fLabel    = source.fLabel;
730   fITSLabel = source.fITSLabel;
731   for(int i = 0; i< 12;++i){
732     fITSModule[i] = source.fITSModule[i];
733   }
734   fTPCLabel = source.fTPCLabel; 
735   fTRDLabel = source.fTRDLabel;
736   for(int i = 0; i< 3;++i){
737     fTOFLabel[i] = source.fTOFLabel[i];    
738   }
739   fTOFCalChannel = source.fTOFCalChannel;
740   fTOFindex      = source.fTOFindex;
741   fHMPIDqn       = source.fHMPIDqn;
742   fHMPIDcluIdx   = source.fHMPIDcluIdx; 
743   fEMCALindex    = source.fEMCALindex;
744
745   for(int i = 0; i< 3;++i){
746     fKinkIndexes[i] = source.fKinkIndexes[i]; 
747     fV0Indexes[i]   = source.fV0Indexes[i]; 
748   }
749
750   for(int i = 0; i< AliPID::kSPECIES;++i){
751     fR[i]     = source.fR[i];
752     fITSr[i]  = source.fITSr[i];
753     fTPCr[i]  = source.fTPCr[i];
754     fTRDr[i]  = source.fTRDr[i];
755     fTOFr[i]  = source.fTOFr[i];
756     fHMPIDr[i] = source.fHMPIDr[i];
757     fTrackTime[i] = source.fTrackTime[i];  
758   }
759
760   fHMPIDtrkTheta = source.fHMPIDtrkTheta;
761   fHMPIDtrkPhi   = source.fHMPIDtrkPhi;
762   fHMPIDsignal   = source.fHMPIDsignal; 
763
764   
765   fTrackLength   = source. fTrackLength;
766   fdTPC  = source.fdTPC; 
767   fzTPC  = source.fzTPC; 
768   fCddTPC = source.fCddTPC;
769   fCdzTPC = source.fCdzTPC;
770   fCzzTPC = source.fCzzTPC;
771   fCchi2TPC = source.fCchi2TPC;
772
773   fD  = source.fD; 
774   fZ  = source.fZ; 
775   fCdd = source.fCdd;
776   fCdz = source.fCdz;
777   fCzz = source.fCzz;
778   fCchi2     = source.fCchi2;
779
780   fITSchi2   = source.fITSchi2;             
781   fTPCchi2   = source.fTPCchi2;            
782   fTRDchi2   = source.fTRDchi2;      
783   fTOFchi2   = source.fTOFchi2;      
784   fHMPIDchi2 = source.fHMPIDchi2;      
785
786   fGlobalChi2 = source.fGlobalChi2;      
787
788   fITSsignal  = source.fITSsignal;     
789   for (Int_t i=0;i<4;i++) {fITSdEdxSamples[i]=source.fITSdEdxSamples[i];}
790   fTPCsignal  = source.fTPCsignal;     
791   fTPCsignalS = source.fTPCsignalS;    
792   for(int i = 0; i< 4;++i){
793     fTPCPoints[i] = source.fTPCPoints[i];  
794   }
795   fTRDsignal = source.fTRDsignal;
796
797   for(int i = 0;i < kTRDnPlanes;++i){
798     fTRDTimBin[i] = source.fTRDTimBin[i];   
799   }
800
801   if(fTRDnSlices)
802     delete[] fTRDslices;
803   fTRDslices=0;
804   fTRDnSlices=source.fTRDnSlices;
805   if (fTRDnSlices) {
806     fTRDslices=new Double32_t[fTRDnSlices];
807     for(int j = 0;j < fTRDnSlices;++j) fTRDslices[j] = source.fTRDslices[j];
808   }
809
810   fTRDQuality =   source.fTRDQuality;     
811   fTRDBudget  =   source.fTRDBudget;      
812   fTOFsignal  =   source.fTOFsignal;     
813   fTOFsignalToT = source.fTOFsignalToT;   
814   fTOFsignalRaw = source.fTOFsignalRaw;  
815   fTOFsignalDz  = source.fTOFsignalDz;      
816   
817   for(int i = 0;i<10;++i){
818     fTOFInfo[i] = source.fTOFInfo[i];    
819   }
820
821   fHMPIDtrkX = source.fHMPIDtrkX; 
822   fHMPIDtrkY = source.fHMPIDtrkY; 
823   fHMPIDmipX = source.fHMPIDmipX;
824   fHMPIDmipY = source.fHMPIDmipY; 
825
826   fTPCncls    = source.fTPCncls;      
827   fTPCnclsF   = source.fTPCnclsF;     
828   fTPCsignalN = source.fTPCsignalN;   
829
830   fITSncls = source.fITSncls;       
831   fITSClusterMap = source.fITSClusterMap; 
832   fTRDncls   = source.fTRDncls;       
833   fTRDncls0  = source.fTRDncls0;      
834   fTRDntracklets  = source.fTRDntracklets; 
835   fVertexID = source.fVertexID;
836   return *this;
837 }
838
839
840
841 void AliESDtrack::Copy(TObject &obj) const {
842   
843   // this overwrites the virtual TOBject::Copy()
844   // to allow run time copying without casting
845   // in AliESDEvent
846
847   if(this==&obj)return;
848   AliESDtrack *robj = dynamic_cast<AliESDtrack*>(&obj);
849   if(!robj)return; // not an AliESDtrack
850   *robj = *this;
851
852 }
853
854
855
856 void AliESDtrack::AddCalibObject(TObject * object){
857   //
858   // add calib object to the list
859   //
860   if (!fFriendTrack) fFriendTrack  = new AliESDfriendTrack;
861   fFriendTrack->AddCalibObject(object);
862 }
863
864 TObject *  AliESDtrack::GetCalibObject(Int_t index){
865   //
866   // return calib objct at given position
867   //
868   if (!fFriendTrack) return 0;
869   return fFriendTrack->GetCalibObject(index);
870 }
871
872
873 Bool_t AliESDtrack::FillTPCOnlyTrack(AliESDtrack &track){
874   
875   // Fills the information of the TPC-only first reconstruction pass
876   // into the passed ESDtrack object. For consistency fTPCInner is also filled
877   // again
878
879
880
881   // For data produced before r26675
882   // RelateToVertexTPC was not properly called during reco
883   // so you'll have to call it again, before FillTPCOnlyTrack
884   //  Float_t p[2],cov[3];
885   // track->GetImpactParametersTPC(p,cov); 
886   // if(p[0]==0&&p[1]==0) // <- Default values
887   //  track->RelateToVertexTPC(esd->GetPrimaryVertexTPC(),esd->GetMagneticField(),kVeryBig);
888   
889
890   if(!fTPCInner)return kFALSE;
891
892   // fill the TPC track params to the global track parameters
893   track.Set(fTPCInner->GetX(),fTPCInner->GetAlpha(),fTPCInner->GetParameter(),fTPCInner->GetCovariance());
894   track.fD = fdTPC;
895   track.fZ = fzTPC;
896   track.fCdd = fCddTPC;
897   track.fCdz = fCdzTPC;
898   track.fCzz = fCzzTPC;
899
900   // copy the TPCinner parameters
901   if(track.fTPCInner) *track.fTPCInner = *fTPCInner;
902   else track.fTPCInner = new AliExternalTrackParam(*fTPCInner);
903   track.fdTPC   = fdTPC;
904   track.fzTPC   = fzTPC;
905   track.fCddTPC = fCddTPC;
906   track.fCdzTPC = fCdzTPC;
907   track.fCzzTPC = fCzzTPC;
908   track.fCchi2TPC = fCchi2TPC;
909
910
911   // copy all other TPC specific parameters
912
913   // replace label by TPC label
914   track.fLabel    = fTPCLabel;
915   track.fTPCLabel = fTPCLabel;
916
917   track.fTPCchi2 = fTPCchi2; 
918   track.fTPCsignal = fTPCsignal;
919   track.fTPCsignalS = fTPCsignalS;
920   for(int i = 0;i<4;++i)track.fTPCPoints[i] = fTPCPoints[i];
921
922   track.fTPCncls    = fTPCncls;     
923   track.fTPCnclsF   = fTPCnclsF;     
924   track.fTPCsignalN =  fTPCsignalN;
925
926   // PID 
927   for(int i=0;i<AliPID::kSPECIES;++i){
928     track.fTPCr[i] = fTPCr[i];
929     // combined PID is TPC only!
930     track.fR[i] = fTPCr[i];
931   }
932   track.fTPCClusterMap = fTPCClusterMap;
933   track.fTPCSharedMap = fTPCSharedMap;
934
935
936   // reset the flags
937   track.fFlags = kTPCin;
938   track.fID    = fID;
939
940   track.fFlags |= fFlags & kTPCpid; //copy the TPCpid status flag
941  
942   for (Int_t i=0;i<3;i++) track.fKinkIndexes[i] = fKinkIndexes[i];
943   
944   return kTRUE;
945     
946 }
947
948 //_______________________________________________________________________
949 void AliESDtrack::MakeMiniESDtrack(){
950   // Resets everything except
951   // fFlags: Reconstruction status flags 
952   // fLabel: Track label
953   // fID:  Unique ID of the track
954   // Impact parameter information
955   // fR[AliPID::kSPECIES]: combined "detector response probability"
956   // Running track parameters in the base class (AliExternalTrackParam)
957   
958   fTrackLength = 0;
959
960   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTrackTime[i] = 0;
961
962   // Reset track parameters constrained to the primary vertex
963   delete fCp;fCp = 0;
964
965   // Reset track parameters at the inner wall of TPC
966   delete fIp;fIp = 0;
967   delete fTPCInner;fTPCInner=0;
968   // Reset track parameters at the inner wall of the TRD
969   delete fOp;fOp = 0;
970
971
972   // Reset ITS track related information
973   fITSchi2 = 0;
974   fITSncls = 0;       
975   fITSClusterMap=0;
976   fITSsignal = 0;     
977   for (Int_t i=0;i<4;i++) fITSdEdxSamples[i] = 0.;
978   for (Int_t i=0;i<AliPID::kSPECIES;i++) fITSr[i]=0; 
979   fITSLabel = 0;       
980
981   // Reset TPC related track information
982   fTPCchi2 = 0;       
983   fTPCncls = 0;       
984   fTPCnclsF = 0;       
985   fTPCClusterMap = 0;  
986   fTPCSharedMap = 0;  
987   fTPCsignal= 0;      
988   fTPCsignalS= 0;      
989   fTPCsignalN= 0;      
990   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTPCr[i]=0; 
991   fTPCLabel=0;       
992   for (Int_t i=0;i<4;i++) fTPCPoints[i] = 0;
993   for (Int_t i=0; i<3;i++)   fKinkIndexes[i] = 0;
994   for (Int_t i=0; i<3;i++)   fV0Indexes[i] = 0;
995
996   // Reset TRD related track information
997   fTRDchi2 = 0;        
998   fTRDncls = 0;       
999   fTRDncls0 = 0;       
1000   fTRDsignal = 0;      
1001   for (Int_t i=0;i<kTRDnPlanes;i++) {
1002     fTRDTimBin[i]  = 0;
1003   }
1004   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTRDr[i] = 0; 
1005   fTRDLabel = 0;       
1006   fTRDQuality  = 0;
1007   fTRDntracklets = 0;
1008   if(fTRDnSlices)
1009     delete[] fTRDslices;
1010   fTRDslices=0x0;
1011   fTRDnSlices=0;
1012   fTRDBudget  = 0;
1013
1014   // Reset TOF related track information
1015   fTOFchi2 = 0;        
1016   fTOFindex = -1;       
1017   fTOFsignal = 0;      
1018   fTOFCalChannel = 0;
1019   fTOFsignalToT = 0;
1020   fTOFsignalRaw = 0;
1021   fTOFsignalDz = 0;
1022   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTOFr[i] = 0;
1023   for (Int_t i=0;i<3;i++) fTOFLabel[i] = 0;
1024   for (Int_t i=0;i<10;i++) fTOFInfo[i] = 0;
1025
1026   // Reset HMPID related track information
1027   fHMPIDchi2 = 0;     
1028   fHMPIDqn = 0;     
1029   fHMPIDcluIdx = -1;     
1030   fHMPIDsignal = 0;     
1031   for (Int_t i=0;i<AliPID::kSPECIES;i++) fHMPIDr[i] = 0;
1032   fHMPIDtrkTheta = 0;     
1033   fHMPIDtrkPhi = 0;      
1034   fHMPIDtrkX = 0;     
1035   fHMPIDtrkY = 0;      
1036   fHMPIDmipX = 0;
1037   fHMPIDmipY = 0;
1038   fEMCALindex = kEMCALNoMatch;
1039
1040   // reset global track chi2
1041   fGlobalChi2 = 0;
1042
1043   fVertexID = -2; // an orphan track
1044
1045   delete fFriendTrack; fFriendTrack = 0;
1046
1047 //_______________________________________________________________________
1048 Double_t AliESDtrack::GetMass() const {
1049   // Returns the mass of the most probable particle type
1050   Float_t max=0.;
1051   Int_t k=-1;
1052   for (Int_t i=0; i<AliPID::kSPECIES; i++) {
1053     if (fR[i]>max) {k=i; max=fR[i];}
1054   }
1055   if (k==0) { // dE/dx "crossing points" in the TPC
1056      Double_t p=GetP();
1057      if ((p>0.38)&&(p<0.48))
1058         if (fR[0]<fR[3]*10.) return AliPID::ParticleMass(AliPID::kKaon);
1059      if ((p>0.75)&&(p<0.85))
1060         if (fR[0]<fR[4]*10.) return AliPID::ParticleMass(AliPID::kProton);
1061      return 0.00051;
1062   }
1063   if (k==1) return AliPID::ParticleMass(AliPID::kMuon); 
1064   if (k==2||k==-1) return AliPID::ParticleMass(AliPID::kPion);
1065   if (k==3) return AliPID::ParticleMass(AliPID::kKaon);
1066   if (k==4) return AliPID::ParticleMass(AliPID::kProton);
1067   AliWarning("Undefined mass !");
1068   return AliPID::ParticleMass(AliPID::kPion);
1069 }
1070
1071 //______________________________________________________________________________
1072 Double_t AliESDtrack::E() const
1073 {
1074   // Returns the energy of the particle given its assumed mass.
1075   // Assumes the pion mass if the particle can't be identified properly.
1076   
1077   Double_t m = M();
1078   Double_t p = P();
1079   return TMath::Sqrt(p*p + m*m);
1080 }
1081
1082 //______________________________________________________________________________
1083 Double_t AliESDtrack::Y() const
1084 {
1085   // Returns the rapidity of a particle given its assumed mass.
1086   // Assumes the pion mass if the particle can't be identified properly.
1087   
1088   Double_t e = E();
1089   Double_t pz = Pz();
1090   if (e != TMath::Abs(pz)) { // energy was not equal to pz
1091     return 0.5*TMath::Log((e+pz)/(e-pz));
1092   } else { // energy was equal to pz
1093     return -999.;
1094   }
1095 }
1096
1097 //_______________________________________________________________________
1098 Bool_t AliESDtrack::UpdateTrackParams(const AliKalmanTrack *t, ULong_t flags){
1099   //
1100   // This function updates track's running parameters 
1101   //
1102   Int_t *index=0;
1103   Bool_t rc=kTRUE;
1104
1105   SetStatus(flags);
1106   fLabel=t->GetLabel();
1107
1108   if (t->IsStartedTimeIntegral()) {
1109     SetStatus(kTIME);
1110     Double_t times[10];t->GetIntegratedTimes(times); SetIntegratedTimes(times);
1111     SetIntegratedLength(t->GetIntegratedLength());
1112   }
1113
1114   Set(t->GetX(),t->GetAlpha(),t->GetParameter(),t->GetCovariance());
1115   if (flags==kITSout) fFriendTrack->SetITSOut(*t);
1116   if (flags==kTPCout) fFriendTrack->SetTPCOut(*t);
1117   if (flags==kTRDrefit) fFriendTrack->SetTRDIn(*t);
1118   
1119   switch (flags) {
1120     
1121   case kITSin: case kITSout: case kITSrefit:
1122     fITSClusterMap=0;
1123     fITSncls=t->GetNumberOfClusters();
1124     index=fFriendTrack->GetITSindices(); 
1125     for (Int_t i=0;i<AliESDfriendTrack::kMaxITScluster;i++) {
1126         index[i]=t->GetClusterIndex(i);
1127         if (i<fITSncls) {
1128            Int_t l=(index[i] & 0xf0000000) >> 28;
1129            SETBIT(fITSClusterMap,l);                 
1130         }
1131     }
1132     fITSchi2=t->GetChi2();
1133     fITSsignal=t->GetPIDsignal();
1134     fITSLabel = t->GetLabel();
1135     // keep in fOp the parameters outside ITS for ITS stand-alone tracks 
1136     if (flags==kITSout) { 
1137       if (!fOp) fOp=new AliExternalTrackParam(*t);
1138       else 
1139         fOp->Set(t->GetX(),t->GetAlpha(),t->GetParameter(),t->GetCovariance());
1140     }   
1141     break;
1142     
1143   case kTPCin: case kTPCrefit:
1144     fTPCLabel = t->GetLabel();
1145     if (flags==kTPCin)  fTPCInner=new AliExternalTrackParam(*t);
1146     if (!fIp) fIp=new AliExternalTrackParam(*t);
1147     else 
1148       fIp->Set(t->GetX(),t->GetAlpha(),t->GetParameter(),t->GetCovariance());
1149   case kTPCout:
1150     index=fFriendTrack->GetTPCindices(); 
1151     if (flags & kTPCout){
1152       if (!fOp) fOp=new AliExternalTrackParam(*t);
1153       else 
1154         fOp->Set(t->GetX(),t->GetAlpha(),t->GetParameter(),t->GetCovariance());
1155     }
1156     fTPCncls=t->GetNumberOfClusters();    
1157     fTPCchi2=t->GetChi2();
1158     
1159      {//prevrow must be declared in separate namespace, otherwise compiler cries:
1160       //"jump to case label crosses initialization of `Int_t prevrow'"
1161        Int_t prevrow = -1;
1162        //       for (Int_t i=0;i<fTPCncls;i++) 
1163        for (Int_t i=0;i<AliESDfriendTrack::kMaxTPCcluster;i++) 
1164         {
1165           index[i]=t->GetClusterIndex(i);
1166           Int_t idx = index[i];
1167
1168           if (idx<0) continue; 
1169
1170           // Piotr's Cluster Map for HBT  
1171           // ### please change accordingly if cluster array is changing 
1172           // to "New TPC Tracking" style (with gaps in array) 
1173           Int_t sect = (idx&0xff000000)>>24;
1174           Int_t row = (idx&0x00ff0000)>>16;
1175           if (sect > 18) row +=63; //if it is outer sector, add number of inner sectors
1176
1177           fTPCClusterMap.SetBitNumber(row,kTRUE);
1178
1179           //Fill the gap between previous row and this row with 0 bits
1180           //In case  ###  pleas change it as well - just set bit 0 in case there 
1181           //is no associated clusters for current "i"
1182           if (prevrow < 0) 
1183            {
1184              prevrow = row;//if previous bit was not assigned yet == this is the first one
1185            }
1186           else
1187            { //we don't know the order (inner to outer or reverse)
1188              //just to be save in case it is going to change
1189              Int_t n = 0, m = 0;
1190              if (prevrow < row)
1191               {
1192                 n = prevrow;
1193                 m = row;
1194               }
1195              else
1196               {
1197                 n = row;
1198                 m = prevrow;
1199               }
1200
1201              for (Int_t j = n+1; j < m; j++)
1202               {
1203                 fTPCClusterMap.SetBitNumber(j,kFALSE);
1204               }
1205              prevrow = row; 
1206            }
1207           // End Of Piotr's Cluster Map for HBT
1208         }
1209      }
1210     fTPCsignal=t->GetPIDsignal();
1211     break;
1212
1213   case kTRDin: case kTRDrefit:
1214     break;
1215   case kTRDout:
1216     index     = fFriendTrack->GetTRDindices();
1217     fTRDLabel = t->GetLabel(); 
1218     fTRDchi2  = t->GetChi2();
1219     fTRDncls  = t->GetNumberOfClusters();
1220     for (Int_t i=0;i<6;i++) index[i]=t->GetTrackletIndex(i);
1221     
1222     fTRDsignal=t->GetPIDsignal();
1223     break;
1224   case kTRDbackup:
1225     if (!fOp) fOp=new AliExternalTrackParam(*t);
1226     else 
1227       fOp->Set(t->GetX(),t->GetAlpha(),t->GetParameter(),t->GetCovariance());
1228     fTRDncls0 = t->GetNumberOfClusters(); 
1229     break;
1230   case kTOFin: 
1231     break;
1232   case kTOFout: 
1233     break;
1234   case kTRDStop:
1235     break;
1236   default: 
1237     AliError("Wrong flag !");
1238     return kFALSE;
1239   }
1240
1241   return rc;
1242 }
1243
1244 //_______________________________________________________________________
1245 void AliESDtrack::GetExternalParameters(Double_t &x, Double_t p[5]) const {
1246   //---------------------------------------------------------------------
1247   // This function returns external representation of the track parameters
1248   //---------------------------------------------------------------------
1249   x=GetX();
1250   for (Int_t i=0; i<5; i++) p[i]=GetParameter()[i];
1251 }
1252
1253 //_______________________________________________________________________
1254 void AliESDtrack::GetExternalCovariance(Double_t cov[15]) const {
1255   //---------------------------------------------------------------------
1256   // This function returns external representation of the cov. matrix
1257   //---------------------------------------------------------------------
1258   for (Int_t i=0; i<15; i++) cov[i]=AliExternalTrackParam::GetCovariance()[i];
1259 }
1260
1261 //_______________________________________________________________________
1262 Bool_t AliESDtrack::GetConstrainedExternalParameters
1263                  (Double_t &alpha, Double_t &x, Double_t p[5]) const {
1264   //---------------------------------------------------------------------
1265   // This function returns the constrained external track parameters
1266   //---------------------------------------------------------------------
1267   if (!fCp) return kFALSE;
1268   alpha=fCp->GetAlpha();
1269   x=fCp->GetX();
1270   for (Int_t i=0; i<5; i++) p[i]=fCp->GetParameter()[i];
1271   return kTRUE;
1272 }
1273
1274 //_______________________________________________________________________
1275 Bool_t 
1276 AliESDtrack::GetConstrainedExternalCovariance(Double_t c[15]) const {
1277   //---------------------------------------------------------------------
1278   // This function returns the constrained external cov. matrix
1279   //---------------------------------------------------------------------
1280   if (!fCp) return kFALSE;
1281   for (Int_t i=0; i<15; i++) c[i]=fCp->GetCovariance()[i];
1282   return kTRUE;
1283 }
1284
1285 Bool_t
1286 AliESDtrack::GetInnerExternalParameters
1287                  (Double_t &alpha, Double_t &x, Double_t p[5]) const {
1288   //---------------------------------------------------------------------
1289   // This function returns external representation of the track parameters 
1290   // at the inner layer of TPC
1291   //---------------------------------------------------------------------
1292   if (!fIp) return kFALSE;
1293   alpha=fIp->GetAlpha();
1294   x=fIp->GetX();
1295   for (Int_t i=0; i<5; i++) p[i]=fIp->GetParameter()[i];
1296   return kTRUE;
1297 }
1298
1299 Bool_t 
1300 AliESDtrack::GetInnerExternalCovariance(Double_t cov[15]) const {
1301  //---------------------------------------------------------------------
1302  // This function returns external representation of the cov. matrix 
1303  // at the inner layer of TPC
1304  //---------------------------------------------------------------------
1305   if (!fIp) return kFALSE;
1306   for (Int_t i=0; i<15; i++) cov[i]=fIp->GetCovariance()[i];
1307   return kTRUE;
1308 }
1309
1310 void 
1311 AliESDtrack::SetOuterParam(const AliExternalTrackParam *p, ULong_t flags) {
1312   //
1313   // This is a direct setter for the outer track parameters
1314   //
1315   SetStatus(flags);
1316   if (fOp) delete fOp;
1317   fOp=new AliExternalTrackParam(*p);
1318 }
1319
1320 Bool_t 
1321 AliESDtrack::GetOuterExternalParameters
1322                  (Double_t &alpha, Double_t &x, Double_t p[5]) const {
1323   //---------------------------------------------------------------------
1324   // This function returns external representation of the track parameters 
1325   // at the inner layer of TRD
1326   //---------------------------------------------------------------------
1327   if (!fOp) return kFALSE;
1328   alpha=fOp->GetAlpha();
1329   x=fOp->GetX();
1330   for (Int_t i=0; i<5; i++) p[i]=fOp->GetParameter()[i];
1331   return kTRUE;
1332 }
1333
1334 Bool_t 
1335 AliESDtrack::GetOuterExternalCovariance(Double_t cov[15]) const {
1336  //---------------------------------------------------------------------
1337  // This function returns external representation of the cov. matrix 
1338  // at the inner layer of TRD
1339  //---------------------------------------------------------------------
1340   if (!fOp) return kFALSE;
1341   for (Int_t i=0; i<15; i++) cov[i]=fOp->GetCovariance()[i];
1342   return kTRUE;
1343 }
1344
1345 Int_t AliESDtrack::GetNcls(Int_t idet) const
1346 {
1347   // Get number of clusters by subdetector index
1348   //
1349   Int_t ncls = 0;
1350   switch(idet){
1351   case 0:
1352     ncls = fITSncls;
1353     break;
1354   case 1:
1355     ncls = fTPCncls;
1356     break;
1357   case 2:
1358     ncls = fTRDncls;
1359     break;
1360   case 3:
1361     if (fTOFindex != -1)
1362       ncls = 1;
1363     break;
1364   case 4: //PHOS
1365     break;
1366   case 5: //HMPID
1367     if ((fHMPIDcluIdx >= 0) && (fHMPIDcluIdx < 7000000)) {
1368       if ((fHMPIDcluIdx%1000000 != 9999) && (fHMPIDcluIdx%1000000 != 99999)) {
1369         ncls = 1;
1370       }
1371     }    
1372     break;
1373   default:
1374     break;
1375   }
1376   return ncls;
1377 }
1378
1379 Int_t AliESDtrack::GetClusters(Int_t idet, Int_t *idx) const
1380 {
1381   // Get cluster index array by subdetector index
1382   //
1383   Int_t ncls = 0;
1384   switch(idet){
1385   case 0:
1386     ncls = GetITSclusters(idx);
1387     break;
1388   case 1:
1389     ncls = GetTPCclusters(idx);
1390     break;
1391   case 2:
1392     ncls = GetTRDclusters(idx);
1393     break;
1394   case 3:
1395     if (fTOFindex != -1) {
1396       idx[0] = fTOFindex;
1397       ncls = 1;
1398     }
1399     break;
1400   case 4: //PHOS
1401     break;
1402   case 5:
1403     if ((fHMPIDcluIdx >= 0) && (fHMPIDcluIdx < 7000000)) {
1404       if ((fHMPIDcluIdx%1000000 != 9999) && (fHMPIDcluIdx%1000000 != 99999)) {
1405         idx[0] = GetHMPIDcluIdx();
1406         ncls = 1;
1407       }
1408     }    
1409     break;
1410   case 6: //EMCAL
1411     break;
1412   default:
1413     break;
1414   }
1415   return ncls;
1416 }
1417
1418 //_______________________________________________________________________
1419 void AliESDtrack::GetIntegratedTimes(Double_t *times) const {
1420   // Returns the array with integrated times for each particle hypothesis
1421   for (Int_t i=0; i<AliPID::kSPECIES; i++) times[i]=fTrackTime[i];
1422 }
1423
1424 //_______________________________________________________________________
1425 void AliESDtrack::SetIntegratedTimes(const Double_t *times) {
1426   // Sets the array with integrated times for each particle hypotesis
1427   for (Int_t i=0; i<AliPID::kSPECIES; i++) fTrackTime[i]=times[i];
1428 }
1429
1430 //_______________________________________________________________________
1431 void AliESDtrack::SetITSpid(const Double_t *p) {
1432   // Sets values for the probability of each particle type (in ITS)
1433   SetPIDValues(fITSr,p,AliPID::kSPECIES);
1434   SetStatus(AliESDtrack::kITSpid);
1435 }
1436
1437 //_______________________________________________________________________
1438 void AliESDtrack::GetITSpid(Double_t *p) const {
1439   // Gets the probability of each particle type (in ITS)
1440   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fITSr[i];
1441 }
1442
1443 //_______________________________________________________________________
1444 Char_t AliESDtrack::GetITSclusters(Int_t *idx) const {
1445   //---------------------------------------------------------------------
1446   // This function returns indices of the assgined ITS clusters 
1447   //---------------------------------------------------------------------
1448   if (idx!=0) {
1449      Int_t *index=fFriendTrack->GetITSindices();
1450      for (Int_t i=0; i<AliESDfriendTrack::kMaxITScluster; i++) {
1451          if ( (i>=fITSncls) && (i<6) ) idx[i]=-1;
1452          else idx[i]=index[i];
1453      }
1454   }
1455   return fITSncls;
1456 }
1457
1458 //_______________________________________________________________________
1459 Bool_t AliESDtrack::GetITSModuleIndexInfo(Int_t ilayer,Int_t &idet,Int_t &status,
1460                                          Float_t &xloc,Float_t &zloc) const {
1461   //----------------------------------------------------------------------
1462   // This function encodes in the module number also the status of cluster association
1463   // "status" can have the following values: 
1464   // 1 "found" (cluster is associated), 
1465   // 2 "dead" (module is dead from OCDB), 
1466   // 3 "skipped" (module or layer forced to be skipped),
1467   // 4 "outinz" (track out of z acceptance), 
1468   // 5 "nocls" (no clusters in the road), 
1469   // 6 "norefit" (cluster rejected during refit), 
1470   // 7 "deadzspd" (holes in z in SPD)
1471   // Also given are the coordinates of the crossing point of track and module
1472   // (in the local module ref. system)
1473   // WARNING: THIS METHOD HAS TO BE SYNCHRONIZED WITH AliITStrackV2::GetModuleIndexInfo()!
1474   //----------------------------------------------------------------------
1475
1476   if(fITSModule[ilayer]==-1) {
1477     idet = -1;
1478     status=0;
1479     xloc=-99.; zloc=-99.;
1480     return kFALSE;
1481   }
1482
1483   Int_t module = fITSModule[ilayer];
1484
1485   idet = Int_t(module/1000000);
1486
1487   module -= idet*1000000;
1488
1489   status = Int_t(module/100000);
1490
1491   module -= status*100000;
1492
1493   Int_t signs = Int_t(module/10000);
1494
1495   module-=signs*10000;
1496
1497   Int_t xInt = Int_t(module/100);
1498   module -= xInt*100;
1499
1500   Int_t zInt = module;
1501
1502   if(signs==1) { xInt*=1; zInt*=1; }
1503   if(signs==2) { xInt*=1; zInt*=-1; }
1504   if(signs==3) { xInt*=-1; zInt*=1; }
1505   if(signs==4) { xInt*=-1; zInt*=-1; }
1506
1507   xloc = 0.1*(Float_t)xInt;
1508   zloc = 0.1*(Float_t)zInt;
1509
1510   if(status==4) idet = -1;
1511
1512   return kTRUE;
1513 }
1514
1515 //_______________________________________________________________________
1516 UShort_t AliESDtrack::GetTPCclusters(Int_t *idx) const {
1517   //---------------------------------------------------------------------
1518   // This function returns indices of the assgined ITS clusters 
1519   //---------------------------------------------------------------------
1520   if (idx!=0) {
1521     Int_t *index=fFriendTrack->GetTPCindices();
1522     for (Int_t i=0; i<AliESDfriendTrack::kMaxTPCcluster; i++) idx[i]=index[i];
1523   }
1524   return fTPCncls;
1525 }
1526
1527 Double_t AliESDtrack::GetTPCdensity(Int_t row0, Int_t row1) const{
1528   //
1529   // GetDensity of the clusters on given region between row0 and row1
1530   // Dead zone effect takin into acoount
1531   //
1532   Int_t good  = 0;
1533   Int_t found = 0;
1534   //  
1535   Int_t *index=fFriendTrack->GetTPCindices();
1536   for (Int_t i=row0;i<=row1;i++){     
1537     Int_t idx = index[i];
1538     if (idx!=-1)  good++;             // track outside of dead zone
1539     if (idx>0)    found++;
1540   }
1541   Float_t density=0.5;
1542   if (good>(row1-row0)*0.5) density = Float_t(found)/Float_t(good);
1543   return density;
1544 }
1545
1546 //_______________________________________________________________________
1547 void AliESDtrack::SetTPCpid(const Double_t *p) {  
1548   // Sets values for the probability of each particle type (in TPC)
1549   SetPIDValues(fTPCr,p,AliPID::kSPECIES);
1550   SetStatus(AliESDtrack::kTPCpid);
1551 }
1552
1553 //_______________________________________________________________________
1554 void AliESDtrack::GetTPCpid(Double_t *p) const {
1555   // Gets the probability of each particle type (in TPC)
1556   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTPCr[i];
1557 }
1558
1559 //_______________________________________________________________________
1560 UChar_t AliESDtrack::GetTRDclusters(Int_t *idx) const {
1561   //---------------------------------------------------------------------
1562   // This function returns indices of the assgined TRD clusters 
1563   //---------------------------------------------------------------------
1564   if (idx!=0) {
1565      Int_t *index=fFriendTrack->GetTRDindices();
1566      for (Int_t i=0; i<AliESDfriendTrack::kMaxTRDcluster; i++) idx[i]=index[i];
1567   }
1568   return fTRDncls;
1569 }
1570
1571 //_______________________________________________________________________
1572 UChar_t AliESDtrack::GetTRDtracklets(Int_t *idx) const {
1573   //---------------------------------------------------------------------
1574   // This function returns indices of the assigned TRD tracklets 
1575   //---------------------------------------------------------------------
1576   if (idx!=0) {
1577      Int_t *index=fFriendTrack->GetTRDindices();
1578      for (Int_t i=0; i<6/*AliESDfriendTrack::kMaxTRDcluster*/; i++) idx[i]=index[i];
1579   }
1580   return fTRDncls;
1581 }
1582
1583 //_______________________________________________________________________
1584 void AliESDtrack::SetTRDpid(const Double_t *p) {  
1585   // Sets values for the probability of each particle type (in TRD)
1586   SetPIDValues(fTRDr,p,AliPID::kSPECIES);
1587   SetStatus(AliESDtrack::kTRDpid);
1588 }
1589
1590 //_______________________________________________________________________
1591 void AliESDtrack::GetTRDpid(Double_t *p) const {
1592   // Gets the probability of each particle type (in TRD)
1593   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTRDr[i];
1594 }
1595
1596 //_______________________________________________________________________
1597 void    AliESDtrack::SetTRDpid(Int_t iSpecies, Float_t p)
1598 {
1599   // Sets the probability of particle type iSpecies to p (in TRD)
1600   fTRDr[iSpecies] = p;
1601 }
1602
1603 Double_t AliESDtrack::GetTRDpid(Int_t iSpecies) const
1604 {
1605   // Returns the probability of particle type iSpecies (in TRD)
1606   return fTRDr[iSpecies];
1607 }
1608
1609 //____________________________________________________
1610 Int_t AliESDtrack::GetNumberOfTRDslices() const 
1611 {
1612   // built in backward compatibility
1613   Int_t idx = fTRDnSlices - (kTRDnPlanes<<1);
1614   return idx<18 ? fTRDnSlices/kTRDnPlanes : idx/kTRDnPlanes;
1615 }
1616
1617 //____________________________________________________
1618 Double_t AliESDtrack::GetTRDmomentum(Int_t plane, Double_t *sp) const
1619 {
1620 //Returns momentum estimation and optional its error (sp)
1621 // in TRD layer "plane".
1622
1623   if (!fTRDnSlices) {
1624     AliError("No TRD info allocated for this track !");
1625     return -1.;
1626   }
1627   if ((plane<0) || (plane>=kTRDnPlanes)) {
1628     AliError("Info for TRD plane not available!");
1629     return -1.;
1630   }
1631
1632   Int_t idx = fTRDnSlices-(kTRDnPlanes<<1)+plane;
1633   // Protection for backward compatibility
1634   if(idx<(GetNumberOfTRDslices()*kTRDnPlanes)) return -1.;
1635
1636   if(sp) (*sp) = fTRDslices[idx+kTRDnPlanes];
1637   return fTRDslices[idx];
1638 }
1639
1640 //____________________________________________________
1641 Double_t  AliESDtrack::GetTRDslice(Int_t plane, Int_t slice) const {
1642   //Gets the charge from the slice of the plane
1643
1644   if(!fTRDslices) {
1645     //AliError("No TRD slices allocated for this track !");
1646     return -1.;
1647   }
1648   if ((plane<0) || (plane>=kTRDnPlanes)) {
1649     AliError("Info for TRD plane not available !");
1650     return -1.;
1651   }
1652   Int_t ns=GetNumberOfTRDslices();
1653   if ((slice<-1) || (slice>=ns)) {
1654     //AliError("Wrong TRD slice !");  
1655     return -1.;
1656   }
1657
1658   if(slice>=0) return fTRDslices[plane*ns + slice];
1659
1660   // return average of the dEdx measurements
1661   Double_t q=0.; Double32_t *s = &fTRDslices[plane*ns];
1662   for (Int_t i=0; i<ns; i++, s++) if((*s)>0.) q+=(*s);
1663   return q/ns;
1664 }
1665
1666 //____________________________________________________
1667 void  AliESDtrack::SetNumberOfTRDslices(Int_t n) {
1668   //Sets the number of slices used for PID 
1669   if (fTRDnSlices) return;
1670
1671   fTRDnSlices=n;
1672   fTRDslices=new Double32_t[fTRDnSlices];
1673   
1674   // set-up correctly the allocated memory
1675   memset(fTRDslices, 0, n*sizeof(Double32_t));
1676   for (Int_t i=GetNumberOfTRDslices(); i--;) fTRDslices[i]=-1.;
1677 }
1678
1679 //____________________________________________________
1680 void  AliESDtrack::SetTRDslice(Double_t q, Int_t plane, Int_t slice) {
1681   //Sets the charge q in the slice of the plane
1682   if(!fTRDslices) {
1683     AliError("No TRD slices allocated for this track !");
1684     return;
1685   }
1686   if ((plane<0) || (plane>=kTRDnPlanes)) {
1687     AliError("Info for TRD plane not allocated !");
1688     return;
1689   }
1690   Int_t ns=GetNumberOfTRDslices();
1691   if ((slice<0) || (slice>=ns)) {
1692     AliError("Wrong TRD slice !");
1693     return;
1694   }
1695   Int_t n=plane*ns + slice;
1696   fTRDslices[n]=q;
1697 }
1698
1699
1700 //____________________________________________________
1701 void AliESDtrack::SetTRDmomentum(Double_t p, Int_t plane, Double_t *sp)
1702 {
1703   if(!fTRDslices) {
1704     AliError("No TRD slices allocated for this track !");
1705     return;
1706   }
1707   if ((plane<0) || (plane>=kTRDnPlanes)) {
1708     AliError("Info for TRD plane not allocated !");
1709     return;
1710   }
1711
1712   Int_t idx = fTRDnSlices-(kTRDnPlanes<<1)+plane;
1713   // Protection for backward compatibility
1714   if(idx<GetNumberOfTRDslices()*kTRDnPlanes) return;
1715
1716   if(sp) fTRDslices[idx+kTRDnPlanes] = (*sp);
1717   fTRDslices[idx] = p;
1718 }
1719
1720
1721 //_______________________________________________________________________
1722 void AliESDtrack::SetTOFpid(const Double_t *p) {  
1723   // Sets the probability of each particle type (in TOF)
1724   SetPIDValues(fTOFr,p,AliPID::kSPECIES);
1725   SetStatus(AliESDtrack::kTOFpid);
1726 }
1727
1728 //_______________________________________________________________________
1729 void AliESDtrack::SetTOFLabel(const Int_t *p) {  
1730   // Sets  (in TOF)
1731   for (Int_t i=0; i<3; i++) fTOFLabel[i]=p[i];
1732 }
1733
1734 //_______________________________________________________________________
1735 void AliESDtrack::GetTOFpid(Double_t *p) const {
1736   // Gets probabilities of each particle type (in TOF)
1737   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTOFr[i];
1738 }
1739
1740 //_______________________________________________________________________
1741 void AliESDtrack::GetTOFLabel(Int_t *p) const {
1742   // Gets (in TOF)
1743   for (Int_t i=0; i<3; i++) p[i]=fTOFLabel[i];
1744 }
1745
1746 //_______________________________________________________________________
1747 void AliESDtrack::GetTOFInfo(Float_t *info) const {
1748   // Gets (in TOF)
1749   for (Int_t i=0; i<10; i++) info[i]=fTOFInfo[i];
1750 }
1751
1752 //_______________________________________________________________________
1753 void AliESDtrack::SetTOFInfo(Float_t*info) {
1754   // Gets (in TOF)
1755   for (Int_t i=0; i<10; i++) fTOFInfo[i]=info[i];
1756 }
1757
1758
1759
1760 //_______________________________________________________________________
1761 void AliESDtrack::SetHMPIDpid(const Double_t *p) {  
1762   // Sets the probability of each particle type (in HMPID)
1763   SetPIDValues(fHMPIDr,p,AliPID::kSPECIES);
1764   SetStatus(AliESDtrack::kHMPIDpid);
1765 }
1766
1767 //_______________________________________________________________________
1768 void AliESDtrack::GetHMPIDpid(Double_t *p) const {
1769   // Gets probabilities of each particle type (in HMPID)
1770   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fHMPIDr[i];
1771 }
1772
1773
1774
1775 //_______________________________________________________________________
1776 void AliESDtrack::SetESDpid(const Double_t *p) {  
1777   // Sets the probability of each particle type for the ESD track
1778   SetPIDValues(fR,p,AliPID::kSPECIES);
1779   SetStatus(AliESDtrack::kESDpid);
1780 }
1781
1782 //_______________________________________________________________________
1783 void AliESDtrack::GetESDpid(Double_t *p) const {
1784   // Gets probability of each particle type for the ESD track
1785   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fR[i];
1786 }
1787
1788 //_______________________________________________________________________
1789 Bool_t AliESDtrack::RelateToVertexTPC(const AliESDVertex *vtx, 
1790 Double_t b, Double_t maxd, AliExternalTrackParam *cParam) {
1791   //
1792   // Try to relate the TPC-only track parameters to the vertex "vtx", 
1793   // if the (rough) transverse impact parameter is not bigger then "maxd". 
1794   //            Magnetic field is "b" (kG).
1795   //
1796   // a) The TPC-only paramters are extapolated to the DCA to the vertex.
1797   // b) The impact parameters and their covariance matrix are calculated.
1798   // c) An attempt to constrain the TPC-only params to the vertex is done.
1799   //    The constrained params are returned via "cParam".
1800   //
1801   // In the case of success, the returned value is kTRUE
1802   // otherwise, it's kFALSE)
1803   // 
1804
1805   if (!fTPCInner) return kFALSE;
1806   if (!vtx) return kFALSE;
1807
1808   Double_t dz[2],cov[3];
1809   if (!fTPCInner->PropagateToDCA(vtx, b, maxd, dz, cov)) return kFALSE;
1810
1811   fdTPC = dz[0];
1812   fzTPC = dz[1];  
1813   fCddTPC = cov[0];
1814   fCdzTPC = cov[1];
1815   fCzzTPC = cov[2];
1816   
1817   Double_t covar[6]; vtx->GetCovMatrix(covar);
1818   Double_t p[2]={GetParameter()[0]-dz[0],GetParameter()[1]-dz[1]};
1819   Double_t c[3]={covar[2],0.,covar[5]};
1820
1821   Double_t chi2=GetPredictedChi2(p,c);
1822   if (chi2>kVeryBig) return kFALSE;
1823
1824   fCchi2TPC=chi2;
1825
1826   if (!cParam) return kTRUE;
1827
1828   *cParam = *fTPCInner;
1829   if (!cParam->Update(p,c)) return kFALSE;
1830
1831   return kTRUE;
1832 }
1833
1834 //_______________________________________________________________________
1835 Bool_t AliESDtrack::RelateToVertex(const AliESDVertex *vtx, 
1836 Double_t b, Double_t maxd, AliExternalTrackParam *cParam) {
1837   //
1838   // Try to relate this track to the vertex "vtx", 
1839   // if the (rough) transverse impact parameter is not bigger then "maxd". 
1840   //            Magnetic field is "b" (kG).
1841   //
1842   // a) The track gets extapolated to the DCA to the vertex.
1843   // b) The impact parameters and their covariance matrix are calculated.
1844   // c) An attempt to constrain this track to the vertex is done.
1845   //    The constrained params are returned via "cParam".
1846   //
1847   // In the case of success, the returned value is kTRUE
1848   // (otherwise, it's kFALSE)
1849   //  
1850
1851   if (!vtx) return kFALSE;
1852
1853   Double_t dz[2],cov[3];
1854   if (!PropagateToDCA(vtx, b, maxd, dz, cov)) return kFALSE;
1855
1856   fD = dz[0];
1857   fZ = dz[1];  
1858   fCdd = cov[0];
1859   fCdz = cov[1];
1860   fCzz = cov[2];
1861   
1862   Double_t covar[6]; vtx->GetCovMatrix(covar);
1863   Double_t p[2]={GetParameter()[0]-dz[0],GetParameter()[1]-dz[1]};
1864   Double_t c[3]={covar[2],0.,covar[5]};
1865
1866   Double_t chi2=GetPredictedChi2(p,c);
1867   if (chi2>kVeryBig) return kFALSE;
1868
1869   fCchi2=chi2;
1870
1871
1872   //--- Could now these lines be removed ? ---
1873   delete fCp;
1874   fCp=new AliExternalTrackParam(*this);  
1875
1876   if (!fCp->Update(p,c)) {delete fCp; fCp=0; return kFALSE;}
1877   //----------------------------------------
1878
1879   fVertexID = vtx->GetID();
1880
1881   if (!cParam) return kTRUE;
1882
1883   *cParam = *this;
1884   if (!cParam->Update(p,c)) return kFALSE; 
1885
1886   return kTRUE;
1887 }
1888
1889 //_______________________________________________________________________
1890 void AliESDtrack::Print(Option_t *) const {
1891   // Prints info on the track
1892   AliExternalTrackParam::Print();
1893   printf("ESD track info\n") ; 
1894   Double_t p[AliPID::kSPECIESN] ; 
1895   Int_t index = 0 ; 
1896   if( IsOn(kITSpid) ){
1897     printf("From ITS: ") ; 
1898     GetITSpid(p) ; 
1899     for(index = 0 ; index < AliPID::kSPECIES; index++) 
1900       printf("%f, ", p[index]) ;
1901     printf("\n           signal = %f\n", GetITSsignal()) ;
1902   } 
1903   if( IsOn(kTPCpid) ){
1904     printf("From TPC: ") ; 
1905     GetTPCpid(p) ; 
1906     for(index = 0 ; index < AliPID::kSPECIES; index++) 
1907       printf("%f, ", p[index]) ;
1908     printf("\n           signal = %f\n", GetTPCsignal()) ;
1909   }
1910   if( IsOn(kTRDpid) ){
1911     printf("From TRD: ") ; 
1912     GetTRDpid(p) ; 
1913     for(index = 0 ; index < AliPID::kSPECIES; index++) 
1914       printf("%f, ", p[index]) ;
1915       printf("\n           signal = %f\n", GetTRDsignal()) ;
1916   }
1917   if( IsOn(kTOFpid) ){
1918     printf("From TOF: ") ; 
1919     GetTOFpid(p) ; 
1920     for(index = 0 ; index < AliPID::kSPECIES; index++) 
1921       printf("%f, ", p[index]) ;
1922     printf("\n           signal = %f\n", GetTOFsignal()) ;
1923   }
1924   if( IsOn(kHMPIDpid) ){
1925     printf("From HMPID: ") ; 
1926     GetHMPIDpid(p) ; 
1927     for(index = 0 ; index < AliPID::kSPECIES; index++) 
1928       printf("%f, ", p[index]) ;
1929     printf("\n           signal = %f\n", GetHMPIDsignal()) ;
1930   }
1931
1932
1933
1934 //
1935 // Draw functionality
1936 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
1937 //
1938 void AliESDtrack::FillPolymarker(TPolyMarker3D *pol, Float_t magF, Float_t minR, Float_t maxR, Float_t stepR){
1939   //
1940   // Fill points in the polymarker
1941   //
1942   TObjArray arrayRef;
1943   arrayRef.AddLast(new AliExternalTrackParam(*this));
1944   if (fIp) arrayRef.AddLast(new AliExternalTrackParam(*fIp));
1945   if (fOp) arrayRef.AddLast(new AliExternalTrackParam(*fOp));
1946   //
1947   Double_t mpos[3]={0,0,0};
1948   Int_t entries=arrayRef.GetEntries();
1949   for (Int_t i=0;i<entries;i++){
1950     Double_t pos[3];
1951     ((AliExternalTrackParam*)arrayRef.At(i))->GetXYZ(pos);
1952     mpos[0]+=pos[0]/entries;
1953     mpos[1]+=pos[1]/entries;
1954     mpos[2]+=pos[2]/entries;    
1955   }
1956   // Rotate to the mean position
1957   //
1958   Float_t fi= TMath::ATan2(mpos[1],mpos[0]);
1959   for (Int_t i=0;i<entries;i++){
1960     Bool_t res = ((AliExternalTrackParam*)arrayRef.At(i))->Rotate(fi);
1961     if (!res) delete arrayRef.RemoveAt(i);
1962   }
1963   Int_t counter=0;
1964   for (Double_t r=minR; r<maxR; r+=stepR){
1965     Double_t sweight=0;
1966     Double_t mlpos[3]={0,0,0};
1967     for (Int_t i=0;i<entries;i++){
1968       Double_t point[3]={0,0,0};
1969       AliExternalTrackParam *param = ((AliExternalTrackParam*)arrayRef.At(i));
1970       if (!param) continue;
1971       if (param->GetXYZAt(r,magF,point)){
1972         Double_t weight = 1./(10.+(r-param->GetX())*(r-param->GetX()));
1973         sweight+=weight;
1974         mlpos[0]+=point[0]*weight;
1975         mlpos[1]+=point[1]*weight;
1976         mlpos[2]+=point[2]*weight;
1977       }
1978     }
1979     if (sweight>0){
1980       mlpos[0]/=sweight;
1981       mlpos[1]/=sweight;
1982       mlpos[2]/=sweight;      
1983       pol->SetPoint(counter,mlpos[0],mlpos[1], mlpos[2]);
1984       printf("xyz\t%f\t%f\t%f\n",mlpos[0], mlpos[1],mlpos[2]);
1985       counter++;
1986     }
1987   }
1988 }
1989
1990 //_______________________________________________________________________
1991 void AliESDtrack::SetITSdEdxSamples(const Double_t s[4]) {
1992   //
1993   // Store the dE/dx samples measured by the two SSD and two SDD layers.
1994   // These samples are corrected for the track segment length. 
1995   //
1996   for (Int_t i=0; i<4; i++) fITSdEdxSamples[i]=s[i];
1997 }
1998
1999 //_______________________________________________________________________
2000 void AliESDtrack::GetITSdEdxSamples(Double_t *s) const {
2001   //
2002   // Get the dE/dx samples measured by the two SSD and two SDD layers.  
2003   // These samples are corrected for the track segment length.
2004   //
2005   for (Int_t i=0; i<4; i++) s[i]=fITSdEdxSamples[i];
2006 }