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