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