]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDtrack.cxx
Adding the TPC-only impact parameters.
[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 #include <TMath.h>
24 #include <TParticle.h>
25
26 #include "AliESDVertex.h"
27 #include "AliESDtrack.h"
28 #include "AliKalmanTrack.h"
29 #include "AliLog.h"
30 #include "AliTrackPointArray.h"
31 #include "TPolyMarker3D.h"
32
33 ClassImp(AliESDtrack)
34
35 void SetPIDValues(Double_t * dest, const Double_t * src, Int_t n) {
36   // This function copies "n" PID weights from "scr" to "dest"
37   // and normalizes their sum to 1 thus producing conditional probabilities.
38   // The negative weights are set to 0.
39   // In case all the weights are non-positive they are replaced by
40   // uniform probabilities
41
42   if (n<=0) return;
43
44   Float_t uniform = 1./(Float_t)n;
45
46   Float_t sum = 0;
47   for (Int_t i=0; i<n; i++) 
48     if (src[i]>=0) {
49       sum+=src[i];
50       dest[i] = src[i];
51     }
52     else {
53       dest[i] = 0;
54     }
55
56   if(sum>0)
57     for (Int_t i=0; i<n; i++) dest[i] /= sum;
58   else
59     for (Int_t i=0; i<n; i++) dest[i] = uniform;
60 }
61
62 //_______________________________________________________________________
63 AliESDtrack::AliESDtrack() : 
64   AliExternalTrackParam(),
65   fCp(0),
66   fIp(0),
67   fTPCInner(0),
68   fOp(0),
69   fFriendTrack(new AliESDfriendTrack()),
70   fTPCClusterMap(159),//number of padrows
71   fTPCSharedMap(159),//number of padrows
72   fFlags(0),
73   fID(0),
74   fLabel(0),
75   fITSLabel(0),
76   fTPCLabel(0),
77   fTRDLabel(0),
78   fTOFCalChannel(0),
79   fTOFindex(-1),
80   fHMPIDqn(0),
81   fHMPIDcluIdx(0),
82   fEMCALindex(kEMCALNoMatch),
83   fHMPIDtrkTheta(0),
84   fHMPIDtrkPhi(0),
85   fHMPIDsignal(0),
86   fTrackLength(0),
87   fdTPC(0),fzTPC(0),
88   fCddTPC(0),fCdzTPC(0),fCzzTPC(0),
89   fD(0),fZ(0),
90   fCdd(0),fCdz(0),fCzz(0),
91   fCchi2(0),
92   fITSchi2(0),
93   fTPCchi2(0),
94   fTRDchi2(0),
95   fTOFchi2(0),
96   fHMPIDchi2(0),
97   fITSsignal(0),
98   fTPCsignal(0),
99   fTPCsignalS(0),
100   fTRDsignal(0),
101   fTRDQuality(0),
102   fTRDBudget(0),
103   fTOFsignal(0),
104   fTOFsignalToT(0),
105   fTOFsignalRaw(0),
106   fTOFsignalDz(0),
107   fHMPIDtrkX(0),
108   fHMPIDtrkY(0),
109   fHMPIDmipX(0),
110   fHMPIDmipY(0),
111   fTPCncls(0),
112   fTPCnclsF(0),
113   fTPCsignalN(0),
114   fITSncls(0),
115   fITSClusterMap(0),
116   fTRDncls(0),
117   fTRDncls0(0),
118   fTRDpidQuality(0),
119   fTRDnSlices(0),
120   fTRDslices(0x0)
121   
122 {
123   //
124   // The default ESD constructor 
125   //
126   Int_t i;
127   for (i=0; i<AliPID::kSPECIES; i++) {
128     fTrackTime[i]=0.;
129     fR[i]=0.;
130     fITSr[i]=0.;
131     fTPCr[i]=0.;
132     fTRDr[i]=0.;
133     fTOFr[i]=0.;
134     fHMPIDr[i]=0.;
135   }
136   
137   for (i=0; i<3; i++)   { fKinkIndexes[i]=0;}
138   for (i=0; i<3; i++)   { fV0Indexes[i]=0;}
139   for (i=0;i<kTRDnPlanes;i++) {
140     fTRDTimBin[i]=0;
141   }
142   for (i=0;i<4;i++) {fTPCPoints[i]=0;}
143   for (i=0;i<3;i++) {fTOFLabel[i]=0;}
144   for (i=0;i<10;i++) {fTOFInfo[i]=0;}
145   for (i=0;i<12;i++) {fITSModule[i]=-1;}
146 }
147
148 //_______________________________________________________________________
149 AliESDtrack::AliESDtrack(const AliESDtrack& track):
150   AliExternalTrackParam(track),
151   fCp(0),
152   fIp(0),
153   fTPCInner(0),
154   fOp(0),
155   fFriendTrack(0),
156   fTPCClusterMap(track.fTPCClusterMap),
157   fTPCSharedMap(track.fTPCSharedMap),
158   fFlags(track.fFlags),
159   fID(track.fID),
160   fLabel(track.fLabel),
161   fITSLabel(track.fITSLabel),
162   fTPCLabel(track.fTPCLabel),
163   fTRDLabel(track.fTRDLabel),
164   fTOFCalChannel(track.fTOFCalChannel),
165   fTOFindex(track.fTOFindex),
166   fHMPIDqn(track.fHMPIDqn),
167   fHMPIDcluIdx(track.fHMPIDcluIdx),
168   fEMCALindex(track.fEMCALindex),
169   fHMPIDtrkTheta(track.fHMPIDtrkTheta),
170   fHMPIDtrkPhi(track.fHMPIDtrkPhi),
171   fHMPIDsignal(track.fHMPIDsignal),
172   fTrackLength(track.fTrackLength),
173   fdTPC(track.fdTPC),fzTPC(track.fzTPC),
174   fCddTPC(track.fCddTPC),fCdzTPC(track.fCdzTPC),fCzzTPC(track.fCzzTPC),
175   fD(track.fD),fZ(track.fZ),
176   fCdd(track.fCdd),fCdz(track.fCdz),fCzz(track.fCzz),
177   fCchi2(track.fCchi2),
178   fITSchi2(track.fITSchi2),
179   fTPCchi2(track.fTPCchi2),
180   fTRDchi2(track.fTRDchi2),
181   fTOFchi2(track.fTOFchi2),
182   fHMPIDchi2(track.fHMPIDchi2),
183   fITSsignal(track.fITSsignal),
184   fTPCsignal(track.fTPCsignal),
185   fTPCsignalS(track.fTPCsignalS),
186   fTRDsignal(track.fTRDsignal),
187   fTRDQuality(track.fTRDQuality),
188   fTRDBudget(track.fTRDBudget),
189   fTOFsignal(track.fTOFsignal),
190   fTOFsignalToT(track.fTOFsignalToT),
191   fTOFsignalRaw(track.fTOFsignalRaw),
192   fTOFsignalDz(track.fTOFsignalDz),
193   fHMPIDtrkX(track.fHMPIDtrkX),
194   fHMPIDtrkY(track.fHMPIDtrkY),
195   fHMPIDmipX(track.fHMPIDmipX),
196   fHMPIDmipY(track.fHMPIDmipY),
197   fTPCncls(track.fTPCncls),
198   fTPCnclsF(track.fTPCnclsF),
199   fTPCsignalN(track.fTPCsignalN),
200   fITSncls(track.fITSncls),
201   fITSClusterMap(track.fITSClusterMap),
202   fTRDncls(track.fTRDncls),
203   fTRDncls0(track.fTRDncls0),
204   fTRDpidQuality(track.fTRDpidQuality),
205   fTRDnSlices(track.fTRDnSlices),
206   fTRDslices(0x0)
207 {
208   //
209   //copy constructor
210   //
211   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTrackTime[i]=track.fTrackTime[i];
212   for (Int_t i=0;i<AliPID::kSPECIES;i++)  fR[i]=track.fR[i];
213   //
214   for (Int_t i=0;i<AliPID::kSPECIES;i++) fITSr[i]=track.fITSr[i]; 
215   //
216   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTPCr[i]=track.fTPCr[i]; 
217   for (Int_t i=0;i<4;i++) {fTPCPoints[i]=track.fTPCPoints[i];}
218   for (Int_t i=0; i<3;i++)   { fKinkIndexes[i]=track.fKinkIndexes[i];}
219   for (Int_t i=0; i<3;i++)   { fV0Indexes[i]=track.fV0Indexes[i];}
220   //
221   for (Int_t i=0;i<kTRDnPlanes;i++) {
222     fTRDTimBin[i]=track.fTRDTimBin[i];
223   }
224
225   if (fTRDnSlices) {
226     fTRDslices=new Double32_t[fTRDnSlices];
227     for (Int_t i=0; i<fTRDnSlices; i++) fTRDslices[i]=track.fTRDslices[i];
228   }
229
230   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTRDr[i]=track.fTRDr[i]; 
231   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTOFr[i]=track.fTOFr[i];
232   for (Int_t i=0;i<3;i++) fTOFLabel[i]=track.fTOFLabel[i];
233   for (Int_t i=0;i<10;i++) fTOFInfo[i]=track.fTOFInfo[i];
234   for (Int_t i=0;i<12;i++) fITSModule[i]=track.fITSModule[i];
235   for (Int_t i=0;i<AliPID::kSPECIES;i++) fHMPIDr[i]=track.fHMPIDr[i];
236
237   if (track.fCp) fCp=new AliExternalTrackParam(*track.fCp);
238   if (track.fIp) fIp=new AliExternalTrackParam(*track.fIp);
239   if (track.fTPCInner) fTPCInner=new AliExternalTrackParam(*track.fTPCInner);
240   if (track.fOp) fOp=new AliExternalTrackParam(*track.fOp);
241
242   if (track.fFriendTrack) fFriendTrack=new AliESDfriendTrack(*(track.fFriendTrack));
243 }
244
245 //_______________________________________________________________________
246 AliESDtrack::AliESDtrack(TParticle * part) : 
247   AliExternalTrackParam(),
248   fCp(0),
249   fIp(0),
250   fTPCInner(0),
251   fOp(0),
252   fFriendTrack(0),
253   fTPCClusterMap(159),//number of padrows
254   fTPCSharedMap(159),//number of padrows
255   fFlags(0),
256   fID(0),
257   fLabel(0),
258   fITSLabel(0),
259   fTPCLabel(0),
260   fTRDLabel(0),
261   fTOFCalChannel(0),
262   fTOFindex(-1),
263   fHMPIDqn(0),
264   fHMPIDcluIdx(0),
265   fEMCALindex(kEMCALNoMatch),
266   fHMPIDtrkTheta(0),
267   fHMPIDtrkPhi(0),
268   fHMPIDsignal(0),
269   fTrackLength(0),
270   fdTPC(0),fzTPC(0),
271   fCddTPC(0),fCdzTPC(0),fCzzTPC(0),
272   fD(0),fZ(0),
273   fCdd(0),fCdz(0),fCzz(0),
274   fCchi2(0),
275   fITSchi2(0),
276   fTPCchi2(0),
277   fTRDchi2(0),
278   fTOFchi2(0),
279   fHMPIDchi2(0),
280   fITSsignal(0),
281   fTPCsignal(0),
282   fTPCsignalS(0),
283   fTRDsignal(0),
284   fTRDQuality(0),
285   fTRDBudget(0),
286   fTOFsignal(0),
287   fTOFsignalToT(0),
288   fTOFsignalRaw(0),
289   fTOFsignalDz(0),
290   fHMPIDtrkX(0),
291   fHMPIDtrkY(0),
292   fHMPIDmipX(0),
293   fHMPIDmipY(0),
294   fTPCncls(0),
295   fTPCnclsF(0),
296   fTPCsignalN(0),
297   fITSncls(0),
298   fITSClusterMap(0),
299   fTRDncls(0),
300   fTRDncls0(0),
301   fTRDpidQuality(0),
302   fTRDnSlices(0),
303   fTRDslices(0x0)
304 {
305   //
306   // ESD track from TParticle
307   //
308
309   // Reset all the arrays
310   Int_t i;
311   for (i=0; i<AliPID::kSPECIES; i++) {
312     fTrackTime[i]=0.;
313     fR[i]=0.;
314     fITSr[i]=0.;
315     fTPCr[i]=0.;
316     fTRDr[i]=0.;
317     fTOFr[i]=0.;
318     fHMPIDr[i]=0.;
319   }
320   
321   for (i=0; i<3; i++)   { fKinkIndexes[i]=0;}
322   for (i=0; i<3; i++)   { fV0Indexes[i]=-1;}
323   for (i=0;i<kTRDnPlanes;i++) {
324     fTRDTimBin[i]=0;
325   }
326   for (i=0;i<4;i++) {fTPCPoints[i]=0;}
327   for (i=0;i<3;i++) {fTOFLabel[i]=0;}
328   for (i=0;i<10;i++) {fTOFInfo[i]=0;}
329   for (i=0;i<12;i++) {fITSModule[i]=-1;}
330
331   // Calculate the AliExternalTrackParam content
332
333   Double_t xref;
334   Double_t alpha;
335   Double_t param[5];
336   Double_t covar[15];
337
338   // Calculate alpha: the rotation angle of the corresponding local system (TPC sector)
339   alpha = part->Phi()*180./TMath::Pi();
340   if (alpha<0) alpha+= 360.;
341   if (alpha>360) alpha -= 360.;
342
343   Int_t sector = (Int_t)(alpha/20.);
344   alpha = 10. + 20.*sector;
345   alpha /= 180;
346   alpha *= TMath::Pi();
347
348   // Covariance matrix: no errors, the parameters are exact
349   for (i=0; i<15; i++) covar[i]=0.;
350
351   // Get the vertex of origin and the momentum
352   TVector3 ver(part->Vx(),part->Vy(),part->Vz());
353   TVector3 mom(part->Px(),part->Py(),part->Pz());
354
355   // Rotate to the local coordinate system (TPC sector)
356   ver.RotateZ(-alpha);
357   mom.RotateZ(-alpha);
358
359   // X of the referense plane
360   xref = ver.X();
361
362   Int_t pdgCode = part->GetPdgCode();
363
364   Double_t charge = 
365     TDatabasePDG::Instance()->GetParticle(pdgCode)->Charge();
366
367   param[0] = ver.Y();
368   param[1] = ver.Z();
369   param[2] = TMath::Sin(mom.Phi());
370   param[3] = mom.Pz()/mom.Pt();
371   param[4] = TMath::Sign(1/mom.Pt(),charge);
372
373   // Set AliExternalTrackParam
374   Set(xref, alpha, param, covar);
375
376   // Set the PID
377   Int_t indexPID = 99;
378
379   switch (TMath::Abs(pdgCode)) {
380
381   case  11: // electron
382     indexPID = 0;
383     break;
384
385   case 13: // muon
386     indexPID = 1;
387     break;
388
389   case 211: // pion
390     indexPID = 2;
391     break;
392
393   case 321: // kaon
394     indexPID = 3;
395     break;
396
397   case 2212: // proton
398     indexPID = 4;
399     break;
400
401   default:
402     break;
403   }
404
405   // If the particle is not e,mu,pi,K or p the PID probabilities are set to 0
406   if (indexPID < AliPID::kSPECIES) {
407     fR[indexPID]=1.;
408     fITSr[indexPID]=1.;
409     fTPCr[indexPID]=1.;
410     fTRDr[indexPID]=1.;
411     fTOFr[indexPID]=1.;
412     fHMPIDr[indexPID]=1.;
413
414   }
415   // AliESD track label
416   SetLabel(part->GetUniqueID());
417
418 }
419
420 //_______________________________________________________________________
421 AliESDtrack::~AliESDtrack(){ 
422   //
423   // This is destructor according Coding Conventrions 
424   //
425   //printf("Delete track\n");
426   delete fIp; 
427   delete fTPCInner; 
428   delete fOp;
429   delete fCp; 
430   delete fFriendTrack;
431   if(fTRDnSlices)
432     delete[] fTRDslices;
433 }
434
435 AliESDtrack &AliESDtrack::operator=(const AliESDtrack &source){
436   
437
438   if(&source == this) return *this;
439   AliExternalTrackParam::operator=(source);
440
441   
442   if(source.fCp){
443     // we have the trackparam: assign or copy construct
444     if(fCp)*fCp = *source.fCp;
445     else fCp = new AliExternalTrackParam(*source.fCp);
446   }
447   else{
448     // no track param delete the old one
449     if(fCp)delete fCp;
450     fCp = 0;
451   }
452
453   if(source.fIp){
454     // we have the trackparam: assign or copy construct
455     if(fIp)*fIp = *source.fIp;
456     else fIp = new AliExternalTrackParam(*source.fIp);
457   }
458   else{
459     // no track param delete the old one
460     if(fIp)delete fIp;
461     fIp = 0;
462   }
463
464
465   if(source.fTPCInner){
466     // we have the trackparam: assign or copy construct
467     if(fTPCInner) *fTPCInner = *source.fTPCInner;
468     else fTPCInner = new AliExternalTrackParam(*source.fTPCInner);
469   }
470   else{
471     // no track param delete the old one
472     if(fTPCInner)delete fTPCInner;
473     fTPCInner = 0;
474   }
475
476
477   if(source.fOp){
478     // we have the trackparam: assign or copy construct
479     if(fOp) *fOp = *source.fOp;
480     else fOp = new AliExternalTrackParam(*source.fOp);
481   }
482   else{
483     // no track param delete the old one
484     if(fOp)delete fOp;
485     fOp = 0;
486   }
487
488   // copy also the friend track 
489   // use copy constructor
490   if(source.fFriendTrack){
491     // we have the trackparam: assign or copy construct
492     delete fFriendTrack; fFriendTrack=new AliESDfriendTrack(*source.fFriendTrack);
493   }
494   else{
495     // no track param delete the old one
496     delete fFriendTrack; fFriendTrack= 0;
497   }
498
499   fTPCClusterMap = source.fTPCClusterMap; 
500   fTPCSharedMap  = source.fTPCSharedMap;  
501   // the simple stuff
502   fFlags    = source.fFlags; 
503   fID       = source.fID;             
504   fLabel    = source.fLabel;
505   fITSLabel = source.fITSLabel;
506   for(int i = 0; i< 12;++i){
507     fITSModule[i] = source.fITSModule[i];
508   }
509   fTPCLabel = source.fTPCLabel; 
510   fTRDLabel = source.fTRDLabel;
511   for(int i = 0; i< 3;++i){
512     fTOFLabel[i] = source.fTOFLabel[i];    
513   }
514   fTOFCalChannel = source.fTOFCalChannel;
515   fTOFindex      = source.fTOFindex;
516   fHMPIDqn       = source.fHMPIDqn;
517   fHMPIDcluIdx   = source.fHMPIDcluIdx; 
518   fEMCALindex    = source.fEMCALindex;
519
520   for(int i = 0; i< 3;++i){
521     fKinkIndexes[i] = source.fKinkIndexes[i]; 
522     fV0Indexes[i]   = source.fV0Indexes[i]; 
523   }
524
525   for(int i = 0; i< AliPID::kSPECIES;++i){
526     fR[i]     = source.fR[i];
527     fITSr[i]  = source.fITSr[i];
528     fTPCr[i]  = source.fTPCr[i];
529     fTRDr[i]  = source.fTRDr[i];
530     fTOFr[i]  = source.fTOFr[i];
531     fHMPIDr[i] = source.fHMPIDr[i];
532     fTrackTime[i] = source.fTrackTime[i];  
533   }
534
535   fHMPIDtrkTheta = source.fHMPIDtrkTheta;
536   fHMPIDtrkPhi   = source.fHMPIDtrkPhi;
537   fHMPIDsignal   = source.fHMPIDsignal; 
538
539   
540   fTrackLength   = source. fTrackLength;
541   fdTPC  = source.fdTPC; 
542   fzTPC  = source.fzTPC; 
543   fCddTPC = source.fCddTPC;
544   fCdzTPC = source.fCdzTPC;
545   fCzzTPC = source.fCzzTPC;
546   fD  = source.fD; 
547   fZ  = source.fZ; 
548   fCdd = source.fCdd;
549   fCdz = source.fCdz;
550   fCzz = source.fCzz;
551
552   fCchi2     = source.fCchi2;
553   fITSchi2   = source.fITSchi2;             
554   fTPCchi2   = source.fTPCchi2;            
555   fTRDchi2   = source.fTRDchi2;      
556   fTOFchi2   = source.fTOFchi2;      
557   fHMPIDchi2 = source.fHMPIDchi2;      
558
559
560   fITSsignal  = source.fITSsignal;     
561   fTPCsignal  = source.fTPCsignal;     
562   fTPCsignalS = source.fTPCsignalS;    
563   for(int i = 0; i< 4;++i){
564     fTPCPoints[i] = source.fTPCPoints[i];  
565   }
566   fTRDsignal = source.fTRDsignal;
567
568   for(int i = 0;i < kTRDnPlanes;++i){
569     fTRDTimBin[i] = source.fTRDTimBin[i];   
570   }
571
572   if(fTRDnSlices)
573     delete[] fTRDslices;
574   fTRDslices=0;
575   fTRDnSlices=source.fTRDnSlices;
576   if (fTRDnSlices) {
577     fTRDslices=new Double32_t[fTRDnSlices];
578     for(int j = 0;j < fTRDnSlices;++j) fTRDslices[j] = source.fTRDslices[j];
579   }
580
581   fTRDQuality =   source.fTRDQuality;     
582   fTRDBudget  =   source.fTRDBudget;      
583   fTOFsignal  =   source.fTOFsignal;     
584   fTOFsignalToT = source.fTOFsignalToT;   
585   fTOFsignalRaw = source.fTOFsignalRaw;  
586   fTOFsignalDz  = source.fTOFsignalDz;      
587   
588   for(int i = 0;i<10;++i){
589     fTOFInfo[i] = source.fTOFInfo[i];    
590   }
591
592   fHMPIDtrkX = source.fHMPIDtrkX; 
593   fHMPIDtrkY = source.fHMPIDtrkY; 
594   fHMPIDmipX = source.fHMPIDmipX;
595   fHMPIDmipY = source.fHMPIDmipY; 
596
597   fTPCncls    = source.fTPCncls;      
598   fTPCnclsF   = source.fTPCnclsF;     
599   fTPCsignalN = source.fTPCsignalN;   
600
601   fITSncls = source.fITSncls;       
602   fITSClusterMap = source.fITSClusterMap; 
603   fTRDncls   = source.fTRDncls;       
604   fTRDncls0  = source.fTRDncls0;      
605   fTRDpidQuality  = source.fTRDpidQuality; 
606   return *this;
607 }
608
609
610
611 void AliESDtrack::Copy(TObject &obj) const {
612   
613   // this overwrites the virtual TOBject::Copy()
614   // to allow run time copying without casting
615   // in AliESDEvent
616
617   if(this==&obj)return;
618   AliESDtrack *robj = dynamic_cast<AliESDtrack*>(&obj);
619   if(!robj)return; // not an AliESDtrack
620   *robj = *this;
621
622 }
623
624
625
626 void AliESDtrack::AddCalibObject(TObject * object){
627   //
628   // add calib object to the list
629   //
630   if (!fFriendTrack) fFriendTrack  = new AliESDfriendTrack;
631   fFriendTrack->AddCalibObject(object);
632 }
633
634 TObject *  AliESDtrack::GetCalibObject(Int_t index){
635   //
636   // return calib objct at given position
637   //
638   if (!fFriendTrack) return 0;
639   return fFriendTrack->GetCalibObject(index);
640 }
641
642
643 //_______________________________________________________________________
644 void AliESDtrack::MakeMiniESDtrack(){
645   // Resets everything except
646   // fFlags: Reconstruction status flags 
647   // fLabel: Track label
648   // fID:  Unique ID of the track
649   // Impact parameter information
650   // fR[AliPID::kSPECIES]: combined "detector response probability"
651   // Running track parameters in the base class (AliExternalTrackParam)
652   
653   fTrackLength = 0;
654
655   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTrackTime[i] = 0;
656
657   // Reset track parameters constrained to the primary vertex
658   delete fCp;fCp = 0;
659   fCchi2 = 0;
660
661   // Reset track parameters at the inner wall of TPC
662   delete fIp;fIp = 0;
663   delete fTPCInner;fTPCInner=0;
664   // Reset track parameters at the inner wall of the TRD
665   delete fOp;fOp = 0;
666
667
668   // Reset ITS track related information
669   fITSchi2 = 0;
670   fITSncls = 0;       
671   fITSClusterMap=0;
672   fITSsignal = 0;     
673   for (Int_t i=0;i<AliPID::kSPECIES;i++) fITSr[i]=0; 
674   fITSLabel = 0;       
675
676   // Reset TPC related track information
677   fTPCchi2 = 0;       
678   fTPCncls = 0;       
679   fTPCnclsF = 0;       
680   fTPCClusterMap = 0;  
681   fTPCSharedMap = 0;  
682   fTPCsignal= 0;      
683   fTPCsignalS= 0;      
684   fTPCsignalN= 0;      
685   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTPCr[i]=0; 
686   fTPCLabel=0;       
687   for (Int_t i=0;i<4;i++) fTPCPoints[i] = 0;
688   for (Int_t i=0; i<3;i++)   fKinkIndexes[i] = 0;
689   for (Int_t i=0; i<3;i++)   fV0Indexes[i] = 0;
690
691   // Reset TRD related track information
692   fTRDchi2 = 0;        
693   fTRDncls = 0;       
694   fTRDncls0 = 0;       
695   fTRDsignal = 0;      
696   for (Int_t i=0;i<kTRDnPlanes;i++) {
697     fTRDTimBin[i]  = 0;
698   }
699   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTRDr[i] = 0; 
700   fTRDLabel = 0;       
701   fTRDQuality  = 0;
702   fTRDpidQuality = 0;
703   if(fTRDnSlices)
704     delete[] fTRDslices;
705   fTRDslices=0x0;
706   fTRDnSlices=0;
707   fTRDBudget  = 0;
708
709   // Reset TOF related track information
710   fTOFchi2 = 0;        
711   fTOFindex = -1;       
712   fTOFsignal = 0;      
713   fTOFCalChannel = 0;
714   fTOFsignalToT = 0;
715   fTOFsignalRaw = 0;
716   fTOFsignalDz = 0;
717   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTOFr[i] = 0;
718   for (Int_t i=0;i<3;i++) fTOFLabel[i] = 0;
719   for (Int_t i=0;i<10;i++) fTOFInfo[i] = 0;
720
721   // Reset HMPID related track information
722   fHMPIDchi2 = 0;     
723   fHMPIDqn = 0;     
724   fHMPIDcluIdx = 0;     
725   fHMPIDsignal = 0;     
726   for (Int_t i=0;i<AliPID::kSPECIES;i++) fHMPIDr[i] = 0;
727   fHMPIDtrkTheta = 0;     
728   fHMPIDtrkPhi = 0;      
729   fHMPIDtrkX = 0;     
730   fHMPIDtrkY = 0;      
731   fHMPIDmipX = 0;
732   fHMPIDmipY = 0;
733   fEMCALindex = kEMCALNoMatch;
734
735   delete fFriendTrack; fFriendTrack = 0;
736
737 //_______________________________________________________________________
738 Double_t AliESDtrack::GetMass() const {
739   // Returns the mass of the most probable particle type
740   Float_t max=0.;
741   Int_t k=-1;
742   for (Int_t i=0; i<AliPID::kSPECIES; i++) {
743     if (fR[i]>max) {k=i; max=fR[i];}
744   }
745   if (k==0) { // dE/dx "crossing points" in the TPC
746      Double_t p=GetP();
747      if ((p>0.38)&&(p<0.48))
748         if (fR[0]<fR[3]*10.) return AliPID::ParticleMass(AliPID::kKaon);
749      if ((p>0.75)&&(p<0.85))
750         if (fR[0]<fR[4]*10.) return AliPID::ParticleMass(AliPID::kProton);
751      return 0.00051;
752   }
753   if (k==1) return AliPID::ParticleMass(AliPID::kMuon); 
754   if (k==2||k==-1) return AliPID::ParticleMass(AliPID::kPion);
755   if (k==3) return AliPID::ParticleMass(AliPID::kKaon);
756   if (k==4) return AliPID::ParticleMass(AliPID::kProton);
757   AliWarning("Undefined mass !");
758   return AliPID::ParticleMass(AliPID::kPion);
759 }
760
761 //______________________________________________________________________________
762 Double_t AliESDtrack::E() const
763 {
764   // Returns the energy of the particle given its assumed mass.
765   // Assumes the pion mass if the particle can't be identified properly.
766   
767   Double_t m = M();
768   Double_t p = P();
769   return TMath::Sqrt(p*p + m*m);
770 }
771
772 //______________________________________________________________________________
773 Double_t AliESDtrack::Y() const
774 {
775   // Returns the rapidity of a particle given its assumed mass.
776   // Assumes the pion mass if the particle can't be identified properly.
777   
778   Double_t e = E();
779   Double_t pz = Pz();
780   if (e != TMath::Abs(pz)) { // energy was not equal to pz
781     return 0.5*TMath::Log((e+pz)/(e-pz));
782   } else { // energy was equal to pz
783     return -999.;
784   }
785 }
786
787 //_______________________________________________________________________
788 Bool_t AliESDtrack::UpdateTrackParams(const AliKalmanTrack *t, ULong_t flags){
789   //
790   // This function updates track's running parameters 
791   //
792   Int_t *index=0;
793   Bool_t rc=kTRUE;
794
795   SetStatus(flags);
796   fLabel=t->GetLabel();
797
798   if (t->IsStartedTimeIntegral()) {
799     SetStatus(kTIME);
800     Double_t times[10];t->GetIntegratedTimes(times); SetIntegratedTimes(times);
801     SetIntegratedLength(t->GetIntegratedLength());
802   }
803
804   Set(t->GetX(),t->GetAlpha(),t->GetParameter(),t->GetCovariance());
805   
806   switch (flags) {
807     
808   case kITSin: case kITSout: case kITSrefit:
809     fITSClusterMap=0;
810     fITSncls=t->GetNumberOfClusters();
811     index=fFriendTrack->GetITSindices(); 
812     for (Int_t i=0;i<AliESDfriendTrack::kMaxITScluster;i++) {
813         index[i]=t->GetClusterIndex(i);
814         if (i<fITSncls) {
815            Int_t l=(index[i] & 0xf0000000) >> 28;
816            SETBIT(fITSClusterMap,l);                 
817         }
818     }
819     fITSchi2=t->GetChi2();
820     fITSsignal=t->GetPIDsignal();
821     fITSLabel = t->GetLabel();
822     break;
823     
824   case kTPCin: case kTPCrefit:
825     fTPCLabel = t->GetLabel();
826     if (flags==kTPCin)  fTPCInner=new AliExternalTrackParam(*t);
827     if (!fIp) fIp=new AliExternalTrackParam(*t);
828     else 
829       fIp->Set(t->GetX(),t->GetAlpha(),t->GetParameter(),t->GetCovariance());
830   case kTPCout:
831     index=fFriendTrack->GetTPCindices(); 
832     if (flags & kTPCout){
833       if (!fOp) fOp=new AliExternalTrackParam(*t);
834       else 
835         fOp->Set(t->GetX(),t->GetAlpha(),t->GetParameter(),t->GetCovariance());
836     }
837     fTPCncls=t->GetNumberOfClusters();    
838     fTPCchi2=t->GetChi2();
839     
840      {//prevrow must be declared in separate namespace, otherwise compiler cries:
841       //"jump to case label crosses initialization of `Int_t prevrow'"
842        Int_t prevrow = -1;
843        //       for (Int_t i=0;i<fTPCncls;i++) 
844        for (Int_t i=0;i<AliESDfriendTrack::kMaxTPCcluster;i++) 
845         {
846           index[i]=t->GetClusterIndex(i);
847           Int_t idx = index[i];
848
849           if (idx<0) continue; 
850
851           // Piotr's Cluster Map for HBT  
852           // ### please change accordingly if cluster array is changing 
853           // to "New TPC Tracking" style (with gaps in array) 
854           Int_t sect = (idx&0xff000000)>>24;
855           Int_t row = (idx&0x00ff0000)>>16;
856           if (sect > 18) row +=63; //if it is outer sector, add number of inner sectors
857
858           fTPCClusterMap.SetBitNumber(row,kTRUE);
859
860           //Fill the gap between previous row and this row with 0 bits
861           //In case  ###  pleas change it as well - just set bit 0 in case there 
862           //is no associated clusters for current "i"
863           if (prevrow < 0) 
864            {
865              prevrow = row;//if previous bit was not assigned yet == this is the first one
866            }
867           else
868            { //we don't know the order (inner to outer or reverse)
869              //just to be save in case it is going to change
870              Int_t n = 0, m = 0;
871              if (prevrow < row)
872               {
873                 n = prevrow;
874                 m = row;
875               }
876              else
877               {
878                 n = row;
879                 m = prevrow;
880               }
881
882              for (Int_t j = n+1; j < m; j++)
883               {
884                 fTPCClusterMap.SetBitNumber(j,kFALSE);
885               }
886              prevrow = row; 
887            }
888           // End Of Piotr's Cluster Map for HBT
889         }
890      }
891     fTPCsignal=t->GetPIDsignal();
892     break;
893
894   case kTRDout: case kTRDin: case kTRDrefit:
895     index     = fFriendTrack->GetTRDindices();
896     fTRDLabel = t->GetLabel(); 
897     fTRDchi2  = t->GetChi2();
898     fTRDncls  = t->GetNumberOfClusters();
899     for (Int_t i=0;i<6;i++) index[i]=t->GetTrackletIndex(i);
900     
901     fTRDsignal=t->GetPIDsignal();
902     break;
903   case kTRDbackup:
904     if (!fOp) fOp=new AliExternalTrackParam(*t);
905     else 
906       fOp->Set(t->GetX(),t->GetAlpha(),t->GetParameter(),t->GetCovariance());
907     fTRDncls0 = t->GetNumberOfClusters(); 
908     break;
909   case kTOFin: 
910     break;
911   case kTOFout: 
912     break;
913   case kTRDStop:
914     break;
915   default: 
916     AliError("Wrong flag !");
917     return kFALSE;
918   }
919
920   return rc;
921 }
922
923 //_______________________________________________________________________
924 void AliESDtrack::GetExternalParameters(Double_t &x, Double_t p[5]) const {
925   //---------------------------------------------------------------------
926   // This function returns external representation of the track parameters
927   //---------------------------------------------------------------------
928   x=GetX();
929   for (Int_t i=0; i<5; i++) p[i]=GetParameter()[i];
930 }
931
932 //_______________________________________________________________________
933 void AliESDtrack::GetExternalCovariance(Double_t cov[15]) const {
934   //---------------------------------------------------------------------
935   // This function returns external representation of the cov. matrix
936   //---------------------------------------------------------------------
937   for (Int_t i=0; i<15; i++) cov[i]=AliExternalTrackParam::GetCovariance()[i];
938 }
939
940 //_______________________________________________________________________
941 Bool_t AliESDtrack::GetConstrainedExternalParameters
942                  (Double_t &alpha, Double_t &x, Double_t p[5]) const {
943   //---------------------------------------------------------------------
944   // This function returns the constrained external track parameters
945   //---------------------------------------------------------------------
946   if (!fCp) return kFALSE;
947   alpha=fCp->GetAlpha();
948   x=fCp->GetX();
949   for (Int_t i=0; i<5; i++) p[i]=fCp->GetParameter()[i];
950   return kTRUE;
951 }
952
953 //_______________________________________________________________________
954 Bool_t 
955 AliESDtrack::GetConstrainedExternalCovariance(Double_t c[15]) const {
956   //---------------------------------------------------------------------
957   // This function returns the constrained external cov. matrix
958   //---------------------------------------------------------------------
959   if (!fCp) return kFALSE;
960   for (Int_t i=0; i<15; i++) c[i]=fCp->GetCovariance()[i];
961   return kTRUE;
962 }
963
964 Bool_t
965 AliESDtrack::GetInnerExternalParameters
966                  (Double_t &alpha, Double_t &x, Double_t p[5]) const {
967   //---------------------------------------------------------------------
968   // This function returns external representation of the track parameters 
969   // at the inner layer of TPC
970   //---------------------------------------------------------------------
971   if (!fIp) return kFALSE;
972   alpha=fIp->GetAlpha();
973   x=fIp->GetX();
974   for (Int_t i=0; i<5; i++) p[i]=fIp->GetParameter()[i];
975   return kTRUE;
976 }
977
978 Bool_t 
979 AliESDtrack::GetInnerExternalCovariance(Double_t cov[15]) const {
980  //---------------------------------------------------------------------
981  // This function returns external representation of the cov. matrix 
982  // at the inner layer of TPC
983  //---------------------------------------------------------------------
984   if (!fIp) return kFALSE;
985   for (Int_t i=0; i<15; i++) cov[i]=fIp->GetCovariance()[i];
986   return kTRUE;
987 }
988
989 Bool_t 
990 AliESDtrack::GetOuterExternalParameters
991                  (Double_t &alpha, Double_t &x, Double_t p[5]) const {
992   //---------------------------------------------------------------------
993   // This function returns external representation of the track parameters 
994   // at the inner layer of TRD
995   //---------------------------------------------------------------------
996   if (!fOp) return kFALSE;
997   alpha=fOp->GetAlpha();
998   x=fOp->GetX();
999   for (Int_t i=0; i<5; i++) p[i]=fOp->GetParameter()[i];
1000   return kTRUE;
1001 }
1002
1003 Bool_t 
1004 AliESDtrack::GetOuterExternalCovariance(Double_t cov[15]) const {
1005  //---------------------------------------------------------------------
1006  // This function returns external representation of the cov. matrix 
1007  // at the inner layer of TRD
1008  //---------------------------------------------------------------------
1009   if (!fOp) return kFALSE;
1010   for (Int_t i=0; i<15; i++) cov[i]=fOp->GetCovariance()[i];
1011   return kTRUE;
1012 }
1013
1014 Int_t AliESDtrack::GetNcls(Int_t idet) const
1015 {
1016   // Get number of clusters by subdetector index
1017   //
1018   Int_t ncls = 0;
1019   switch(idet){
1020   case 0:
1021     ncls = fITSncls;
1022     break;
1023   case 1:
1024     ncls = fTPCncls;
1025     break;
1026   case 2:
1027     ncls = fTRDncls;
1028     break;
1029   case 3:
1030     if (fTOFindex != -1)
1031       ncls = 1;
1032     break;
1033   default:
1034     break;
1035   }
1036   return ncls;
1037 }
1038
1039 Int_t AliESDtrack::GetClusters(Int_t idet, Int_t *idx) const
1040 {
1041   // Get cluster index array by subdetector index
1042   //
1043   Int_t ncls = 0;
1044   switch(idet){
1045   case 0:
1046     ncls = GetITSclusters(idx);
1047     break;
1048   case 1:
1049     ncls = GetTPCclusters(idx);
1050     break;
1051   case 2:
1052     ncls = GetTRDclusters(idx);
1053     break;
1054   case 3:
1055     if (fTOFindex != -1) {
1056       idx[0] = fTOFindex;
1057       ncls = 1;
1058     }
1059     break;
1060   case 4: //PHOS
1061     break;
1062   case 5:
1063     if (fHMPIDcluIdx != 0) {
1064       idx[0] = GetHMPIDcluIdx();
1065       ncls = 1;
1066     }    
1067     break;
1068   case 6: //EMCAL
1069     break;
1070   default:
1071     break;
1072   }
1073   return ncls;
1074 }
1075
1076 //_______________________________________________________________________
1077 void AliESDtrack::GetIntegratedTimes(Double_t *times) const {
1078   // Returns the array with integrated times for each particle hypothesis
1079   for (Int_t i=0; i<AliPID::kSPECIES; i++) times[i]=fTrackTime[i];
1080 }
1081
1082 //_______________________________________________________________________
1083 void AliESDtrack::SetIntegratedTimes(const Double_t *times) {
1084   // Sets the array with integrated times for each particle hypotesis
1085   for (Int_t i=0; i<AliPID::kSPECIES; i++) fTrackTime[i]=times[i];
1086 }
1087
1088 //_______________________________________________________________________
1089 void AliESDtrack::SetITSpid(const Double_t *p) {
1090   // Sets values for the probability of each particle type (in ITS)
1091   SetPIDValues(fITSr,p,AliPID::kSPECIES);
1092   SetStatus(AliESDtrack::kITSpid);
1093 }
1094
1095 //_______________________________________________________________________
1096 void AliESDtrack::GetITSpid(Double_t *p) const {
1097   // Gets the probability of each particle type (in ITS)
1098   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fITSr[i];
1099 }
1100
1101 //_______________________________________________________________________
1102 Char_t AliESDtrack::GetITSclusters(Int_t *idx) const {
1103   //---------------------------------------------------------------------
1104   // This function returns indices of the assgined ITS clusters 
1105   //---------------------------------------------------------------------
1106   if (idx!=0) {
1107      Int_t *index=fFriendTrack->GetITSindices();
1108      for (Int_t i=0; i<AliESDfriendTrack::kMaxITScluster; i++) idx[i]=index[i];
1109   }
1110   return fITSncls;
1111 }
1112
1113 //_______________________________________________________________________
1114 Bool_t AliESDtrack::GetITSModuleIndexInfo(Int_t ilayer,Int_t &idet,Int_t &status,
1115                                          Float_t &xloc,Float_t &zloc) const {
1116   //----------------------------------------------------------------------
1117   // This function encodes in the module number also the status of cluster association
1118   // "status" can have the following values: 
1119   // 1 "found" (cluster is associated), 
1120   // 2 "dead" (module is dead from OCDB), 
1121   // 3 "skipped" (module or layer forced to be skipped),
1122   // 4 "outinz" (track out of z acceptance), 
1123   // 5 "nocls" (no clusters in the road), 
1124   // 6 "norefit" (cluster rejected during refit), 
1125   // 7 "deadzspd" (holes in z in SPD)
1126   // Also given are the coordinates of the crossing point of track and module
1127   // (in the local module ref. system)
1128   // WARNING: THIS METHOD HAS TO BE SYNCHRONIZED WITH AliITStrackV2::GetModuleIndexInfo()!
1129   //----------------------------------------------------------------------
1130
1131   if(fITSModule[ilayer]==-1) {
1132     AliError("fModule was not set !");
1133     idet = -1;
1134     status=0;
1135     xloc=-99.; zloc=-99.;
1136     return kFALSE;
1137   }
1138
1139   Int_t module = fITSModule[ilayer];
1140
1141   idet = Int_t(module/1000000);
1142
1143   module -= idet*1000000;
1144
1145   status = Int_t(module/100000);
1146
1147   module -= status*100000;
1148
1149   Int_t signs = Int_t(module/10000);
1150
1151   module-=signs*10000;
1152
1153   Int_t xInt = Int_t(module/100);
1154   module -= xInt*100;
1155
1156   Int_t zInt = module;
1157
1158   if(signs==1) { xInt*=1; zInt*=1; }
1159   if(signs==2) { xInt*=1; zInt*=-1; }
1160   if(signs==3) { xInt*=-1; zInt*=1; }
1161   if(signs==4) { xInt*=-1; zInt*=-1; }
1162
1163   xloc = 0.1*(Float_t)xInt;
1164   zloc = 0.1*(Float_t)zInt;
1165
1166   if(status==4) idet = -1;
1167
1168   return kTRUE;
1169 }
1170
1171 //_______________________________________________________________________
1172 UShort_t AliESDtrack::GetTPCclusters(Int_t *idx) const {
1173   //---------------------------------------------------------------------
1174   // This function returns indices of the assgined ITS clusters 
1175   //---------------------------------------------------------------------
1176   if (idx!=0) {
1177     Int_t *index=fFriendTrack->GetTPCindices();
1178     for (Int_t i=0; i<AliESDfriendTrack::kMaxTPCcluster; i++) idx[i]=index[i];
1179   }
1180   return fTPCncls;
1181 }
1182
1183 Double_t AliESDtrack::GetTPCdensity(Int_t row0, Int_t row1) const{
1184   //
1185   // GetDensity of the clusters on given region between row0 and row1
1186   // Dead zone effect takin into acoount
1187   //
1188   Int_t good  = 0;
1189   Int_t found = 0;
1190   //  
1191   Int_t *index=fFriendTrack->GetTPCindices();
1192   for (Int_t i=row0;i<=row1;i++){     
1193     Int_t idx = index[i];
1194     if (idx!=-1)  good++;             // track outside of dead zone
1195     if (idx>0)    found++;
1196   }
1197   Float_t density=0.5;
1198   if (good>(row1-row0)*0.5) density = Float_t(found)/Float_t(good);
1199   return density;
1200 }
1201
1202 //_______________________________________________________________________
1203 void AliESDtrack::SetTPCpid(const Double_t *p) {  
1204   // Sets values for the probability of each particle type (in TPC)
1205   SetPIDValues(fTPCr,p,AliPID::kSPECIES);
1206   SetStatus(AliESDtrack::kTPCpid);
1207 }
1208
1209 //_______________________________________________________________________
1210 void AliESDtrack::GetTPCpid(Double_t *p) const {
1211   // Gets the probability of each particle type (in TPC)
1212   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTPCr[i];
1213 }
1214
1215 //_______________________________________________________________________
1216 UChar_t AliESDtrack::GetTRDclusters(Int_t *idx) const {
1217   //---------------------------------------------------------------------
1218   // This function returns indices of the assgined TRD clusters 
1219   //---------------------------------------------------------------------
1220   if (idx!=0) {
1221      Int_t *index=fFriendTrack->GetTRDindices();
1222      for (Int_t i=0; i<AliESDfriendTrack::kMaxTRDcluster; i++) idx[i]=index[i];
1223   }
1224   return fTRDncls;
1225 }
1226
1227 //_______________________________________________________________________
1228 UChar_t AliESDtrack::GetTRDtracklets(Int_t *idx) const {
1229   //---------------------------------------------------------------------
1230   // This function returns indices of the assigned TRD tracklets 
1231   //---------------------------------------------------------------------
1232   if (idx!=0) {
1233      Int_t *index=fFriendTrack->GetTRDindices();
1234      for (Int_t i=0; i<6/*AliESDfriendTrack::kMaxTRDcluster*/; i++) idx[i]=index[i];
1235   }
1236   return fTRDncls;
1237 }
1238
1239 //_______________________________________________________________________
1240 void AliESDtrack::SetTRDpid(const Double_t *p) {  
1241   // Sets values for the probability of each particle type (in TRD)
1242   SetPIDValues(fTRDr,p,AliPID::kSPECIES);
1243   SetStatus(AliESDtrack::kTRDpid);
1244 }
1245
1246 //_______________________________________________________________________
1247 void AliESDtrack::GetTRDpid(Double_t *p) const {
1248   // Gets the probability of each particle type (in TRD)
1249   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTRDr[i];
1250 }
1251
1252 //_______________________________________________________________________
1253 void    AliESDtrack::SetTRDpid(Int_t iSpecies, Float_t p)
1254 {
1255   // Sets the probability of particle type iSpecies to p (in TRD)
1256   fTRDr[iSpecies] = p;
1257 }
1258
1259 Double_t AliESDtrack::GetTRDpid(Int_t iSpecies) const
1260 {
1261   // Returns the probability of particle type iSpecies (in TRD)
1262   return fTRDr[iSpecies];
1263 }
1264
1265 void  AliESDtrack::SetNumberOfTRDslices(Int_t n) {
1266   //Sets the number of slices used for PID 
1267   if (fTRDnSlices != 0) return;
1268   fTRDnSlices=kTRDnPlanes*n;
1269   fTRDslices=new Double32_t[fTRDnSlices];
1270   for (Int_t i=0; i<fTRDnSlices; i++) fTRDslices[i]=-1.;
1271 }
1272
1273 void  AliESDtrack::SetTRDslice(Double_t q, Int_t plane, Int_t slice) {
1274   //Sets the charge q in the slice of the plane
1275   Int_t ns=GetNumberOfTRDslices();
1276   if (ns==0) {
1277     AliError("No TRD slices allocated for this track !");
1278     return;
1279   }
1280
1281   if ((plane<0) || (plane>=kTRDnPlanes)) {
1282     AliError("Wrong TRD plane !");
1283     return;
1284   }
1285   if ((slice<0) || (slice>=ns)) {
1286     AliError("Wrong TRD slice !");
1287     return;
1288   }
1289   Int_t n=plane*ns + slice;
1290   fTRDslices[n]=q;
1291 }
1292
1293 Double_t  AliESDtrack::GetTRDslice(Int_t plane, Int_t slice) const {
1294   //Gets the charge from the slice of the plane
1295   Int_t ns=GetNumberOfTRDslices();
1296   if (ns==0) {
1297     //AliError("No TRD slices allocated for this track !");
1298     return -1.;
1299   }
1300
1301   if ((plane<0) || (plane>=kTRDnPlanes)) {
1302     AliError("Wrong TRD plane !");
1303     return -1.;
1304   }
1305   if ((slice<-1) || (slice>=ns)) {
1306     //AliError("Wrong TRD slice !");  
1307     return -1.;
1308   }
1309
1310   if (slice==-1) {
1311     Double_t q=0.;
1312     for (Int_t i=0; i<ns; i++) q+=fTRDslices[plane*ns + i];
1313     return q/ns;
1314   }
1315
1316   return fTRDslices[plane*ns + slice];
1317 }
1318
1319
1320 //_______________________________________________________________________
1321 void AliESDtrack::SetTOFpid(const Double_t *p) {  
1322   // Sets the probability of each particle type (in TOF)
1323   SetPIDValues(fTOFr,p,AliPID::kSPECIES);
1324   SetStatus(AliESDtrack::kTOFpid);
1325 }
1326
1327 //_______________________________________________________________________
1328 void AliESDtrack::SetTOFLabel(const Int_t *p) {  
1329   // Sets  (in TOF)
1330   for (Int_t i=0; i<3; i++) fTOFLabel[i]=p[i];
1331 }
1332
1333 //_______________________________________________________________________
1334 void AliESDtrack::GetTOFpid(Double_t *p) const {
1335   // Gets probabilities of each particle type (in TOF)
1336   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTOFr[i];
1337 }
1338
1339 //_______________________________________________________________________
1340 void AliESDtrack::GetTOFLabel(Int_t *p) const {
1341   // Gets (in TOF)
1342   for (Int_t i=0; i<3; i++) p[i]=fTOFLabel[i];
1343 }
1344
1345 //_______________________________________________________________________
1346 void AliESDtrack::GetTOFInfo(Float_t *info) const {
1347   // Gets (in TOF)
1348   for (Int_t i=0; i<10; i++) info[i]=fTOFInfo[i];
1349 }
1350
1351 //_______________________________________________________________________
1352 void AliESDtrack::SetTOFInfo(Float_t*info) {
1353   // Gets (in TOF)
1354   for (Int_t i=0; i<10; i++) fTOFInfo[i]=info[i];
1355 }
1356
1357
1358
1359 //_______________________________________________________________________
1360 void AliESDtrack::SetHMPIDpid(const Double_t *p) {  
1361   // Sets the probability of each particle type (in HMPID)
1362   SetPIDValues(fHMPIDr,p,AliPID::kSPECIES);
1363   SetStatus(AliESDtrack::kHMPIDpid);
1364 }
1365
1366 //_______________________________________________________________________
1367 void AliESDtrack::GetHMPIDpid(Double_t *p) const {
1368   // Gets probabilities of each particle type (in HMPID)
1369   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fHMPIDr[i];
1370 }
1371
1372
1373
1374 //_______________________________________________________________________
1375 void AliESDtrack::SetESDpid(const Double_t *p) {  
1376   // Sets the probability of each particle type for the ESD track
1377   SetPIDValues(fR,p,AliPID::kSPECIES);
1378   SetStatus(AliESDtrack::kESDpid);
1379 }
1380
1381 //_______________________________________________________________________
1382 void AliESDtrack::GetESDpid(Double_t *p) const {
1383   // Gets probability of each particle type for the ESD track
1384   for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fR[i];
1385 }
1386
1387 //_______________________________________________________________________
1388 Bool_t AliESDtrack::RelateToVertexTPC
1389 (const AliESDVertex *vtx, Double_t b, Double_t maxd) {
1390   //
1391   // Try to relate the TPC-only track paramters to the vertex "vtx", 
1392   // if the (rough) transverse impact parameter is not bigger then "maxd". 
1393   //            Magnetic field is "b" (kG).
1394   //
1395   // a) The TPC-only paramters are extapolated to the DCA to the vertex.
1396   // b) The impact parameters and their covariance matrix are calculated.
1397   //
1398
1399   if (!fTPCInner) return kFALSE;
1400   if (!vtx) return kFALSE;
1401
1402   Double_t dz[2],cov[3];
1403   if (!fTPCInner->PropagateToDCA(vtx, b, maxd, dz, cov)) return kFALSE;
1404
1405   fdTPC = dz[0];
1406   fzTPC = dz[1];  
1407   fCddTPC = cov[0];
1408   fCdzTPC = cov[1];
1409   fCzzTPC = cov[2];
1410   
1411   return kTRUE;
1412 }
1413
1414 //_______________________________________________________________________
1415 Bool_t AliESDtrack::RelateToVertex
1416 (const AliESDVertex *vtx, Double_t b, Double_t maxd) {
1417   //
1418   // Try to relate this track to the vertex "vtx", 
1419   // if the (rough) transverse impact parameter is not bigger then "maxd". 
1420   //            Magnetic field is "b" (kG).
1421   //
1422   // a) The track gets extapolated to the DCA to the vertex.
1423   // b) The impact parameters and their covariance matrix are calculated.
1424   // c) An attempt to constrain this track to the vertex is done.
1425   //
1426   //    In the case of success, the returned value is kTRUE
1427   //    (otherwise, it's kFALSE)
1428   //  
1429
1430   if (!vtx) return kFALSE;
1431
1432   Double_t dz[2],cov[3];
1433   if (!PropagateToDCA(vtx, b, maxd, dz, cov)) return kFALSE;
1434
1435   fD = dz[0];
1436   fZ = dz[1];  
1437   fCdd = cov[0];
1438   fCdz = cov[1];
1439   fCzz = cov[2];
1440   
1441   Double_t covar[6]; vtx->GetCovMatrix(covar);
1442   Double_t p[2]={GetParameter()[0]-dz[0],GetParameter()[1]-dz[1]};
1443   Double_t c[3]={covar[2],0.,covar[5]};
1444
1445   Double_t chi2=GetPredictedChi2(p,c);
1446   if (chi2>77.) return kFALSE;
1447
1448   delete fCp;
1449   fCp=new AliExternalTrackParam(*this);  
1450
1451   if (!fCp->Update(p,c)) {delete fCp; fCp=0; return kFALSE;}
1452   
1453   fCchi2=chi2;
1454   return kTRUE;
1455 }
1456
1457 //_______________________________________________________________________
1458 void AliESDtrack::Print(Option_t *) const {
1459   // Prints info on the track
1460   
1461   printf("ESD track info\n") ; 
1462   Double_t p[AliPID::kSPECIESN] ; 
1463   Int_t index = 0 ; 
1464   if( IsOn(kITSpid) ){
1465     printf("From ITS: ") ; 
1466     GetITSpid(p) ; 
1467     for(index = 0 ; index < AliPID::kSPECIES; index++) 
1468       printf("%f, ", p[index]) ;
1469     printf("\n           signal = %f\n", GetITSsignal()) ;
1470   } 
1471   if( IsOn(kTPCpid) ){
1472     printf("From TPC: ") ; 
1473     GetTPCpid(p) ; 
1474     for(index = 0 ; index < AliPID::kSPECIES; index++) 
1475       printf("%f, ", p[index]) ;
1476     printf("\n           signal = %f\n", GetTPCsignal()) ;
1477   }
1478   if( IsOn(kTRDpid) ){
1479     printf("From TRD: ") ; 
1480     GetTRDpid(p) ; 
1481     for(index = 0 ; index < AliPID::kSPECIES; index++) 
1482       printf("%f, ", p[index]) ;
1483       printf("\n           signal = %f\n", GetTRDsignal()) ;
1484   }
1485   if( IsOn(kTOFpid) ){
1486     printf("From TOF: ") ; 
1487     GetTOFpid(p) ; 
1488     for(index = 0 ; index < AliPID::kSPECIES; index++) 
1489       printf("%f, ", p[index]) ;
1490     printf("\n           signal = %f\n", GetTOFsignal()) ;
1491   }
1492   if( IsOn(kHMPIDpid) ){
1493     printf("From HMPID: ") ; 
1494     GetHMPIDpid(p) ; 
1495     for(index = 0 ; index < AliPID::kSPECIES; index++) 
1496       printf("%f, ", p[index]) ;
1497     printf("\n           signal = %f\n", GetHMPIDsignal()) ;
1498   }
1499
1500
1501
1502 //
1503 // Draw functionality
1504 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
1505 //
1506 void AliESDtrack::FillPolymarker(TPolyMarker3D *pol, Float_t magF, Float_t minR, Float_t maxR, Float_t stepR){
1507   //
1508   // Fill points in the polymarker
1509   //
1510   TObjArray arrayRef;
1511   arrayRef.AddLast(new AliExternalTrackParam(*this));
1512   if (fIp) arrayRef.AddLast(new AliExternalTrackParam(*fIp));
1513   if (fOp) arrayRef.AddLast(new AliExternalTrackParam(*fOp));
1514   //
1515   Double_t mpos[3]={0,0,0};
1516   Int_t entries=arrayRef.GetEntries();
1517   for (Int_t i=0;i<entries;i++){
1518     Double_t pos[3];
1519     ((AliExternalTrackParam*)arrayRef.At(i))->GetXYZ(pos);
1520     mpos[0]+=pos[0]/entries;
1521     mpos[1]+=pos[1]/entries;
1522     mpos[2]+=pos[2]/entries;    
1523   }
1524   // Rotate to the mean position
1525   //
1526   Float_t fi= TMath::ATan2(mpos[1],mpos[0]);
1527   for (Int_t i=0;i<entries;i++){
1528     Bool_t res = ((AliExternalTrackParam*)arrayRef.At(i))->Rotate(fi);
1529     if (!res) delete arrayRef.RemoveAt(i);
1530   }
1531   Int_t counter=0;
1532   for (Double_t r=minR; r<maxR; r+=stepR){
1533     Double_t sweight=0;
1534     Double_t mlpos[3]={0,0,0};
1535     for (Int_t i=0;i<entries;i++){
1536       Double_t point[3]={0,0,0};
1537       AliExternalTrackParam *param = ((AliExternalTrackParam*)arrayRef.At(i));
1538       if (!param) continue;
1539       if (param->GetXYZAt(r,magF,point)){
1540         Double_t weight = 1./(10.+(r-param->GetX())*(r-param->GetX()));
1541         sweight+=weight;
1542         mlpos[0]+=point[0]*weight;
1543         mlpos[1]+=point[1]*weight;
1544         mlpos[2]+=point[2]*weight;
1545       }
1546     }
1547     if (sweight>0){
1548       mlpos[0]/=sweight;
1549       mlpos[1]/=sweight;
1550       mlpos[2]/=sweight;      
1551       pol->SetPoint(counter,mlpos[0],mlpos[1], mlpos[2]);
1552       printf("xyz\t%f\t%f\t%f\n",mlpos[0], mlpos[1],mlpos[2]);
1553       counter++;
1554     }
1555   }
1556 }