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