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