Minor changes
[u/mrichter/AliRoot.git] / STEER / AliESDtrack.cxx
CommitLineData
ae982df3 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 **************************************************************************/
ae982df3 15//-----------------------------------------------------------------
16// Implementation of the ESD track class
4427806c 17// ESD = Event Summary Data
15614b8b 18// This is the class to deal with during the phisics analysis of data
4427806c 19// Origin: Iouri Belikov, CERN
20// e-mail: Jouri.Belikov@cern.ch
ae982df3 21//-----------------------------------------------------------------
22
e1e6896f 23#include <TMath.h>
ae982df3 24
49d13e89 25#include "AliESDVertex.h"
ae982df3 26#include "AliESDtrack.h"
27#include "AliKalmanTrack.h"
5f7789fc 28#include "AliLog.h"
15e85efa 29#include "AliTrackPointArray.h"
ae982df3 30
31ClassImp(AliESDtrack)
32
d27bbc79 33void SetPIDValues(Float_t * dest, const Double_t * src, Int_t n) {
34 // This function copies "n" PID weights from "scr" to "dest"
35 // and normalizes their sum to 1 thus producing conditional probabilities.
36 // The negative weights are set to 0.
37 // In case all the weights are non-positive they are replaced by
38 // uniform probabilities
39
40 if (n<=0) return;
41
42 Float_t uniform = 1./(Float_t)n;
43
44 Float_t sum = 0;
45 for (Int_t i=0; i<n; i++)
46 if (src[i]>=0) {
47 sum+=src[i];
48 dest[i] = src[i];
49 }
50 else {
51 dest[i] = 0;
52 }
53
54 if(sum>0)
55 for (Int_t i=0; i<n; i++) dest[i] /= sum;
56 else
57 for (Int_t i=0; i<n; i++) dest[i] = uniform;
58}
59
ae982df3 60//_______________________________________________________________________
61AliESDtrack::AliESDtrack() :
c9ec41e8 62 AliExternalTrackParam(),
90e48c0c 63 fFlags(0),
64 fLabel(0),
65 fID(0),
66 fTrackLength(0),
49d13e89 67 fD(0),fZ(0),
68 fCdd(0),fCdz(0),fCzz(0),
90e48c0c 69 fStopVertex(0),
c9ec41e8 70 fCp(0),
90e48c0c 71 fCchi2(1e10),
c9ec41e8 72 fIp(0),
73 fOp(0),
90e48c0c 74 fITSchi2(0),
75 fITSncls(0),
76 fITSsignal(0),
77 fITSLabel(0),
78 fITSFakeRatio(0),
90e48c0c 79 fTPCchi2(0),
80 fTPCncls(0),
e1d4c1b5 81 fTPCnclsF(0),
90e48c0c 82 fTPCClusterMap(159),//number of padrows
83 fTPCsignal(0),
e1d4c1b5 84 fTPCsignalN(0),
85 fTPCsignalS(0),
90e48c0c 86 fTPCLabel(0),
87 fTRDchi2(0),
88 fTRDncls(0),
89 fTRDncls0(0),
90 fTRDsignal(0),
91 fTRDLabel(0),
92 fTRDQuality(0),
23d49657 93 fTRDBudget(0),
90e48c0c 94 fTOFchi2(0),
95 fTOFindex(0),
85324138 96 fTOFCalChannel(-1),
90e48c0c 97 fTOFsignal(-1),
85324138 98 fTOFsignalToT(0),
90e48c0c 99 fRICHchi2(1e10),
100 fRICHncls(0),
101 fRICHindex(0),
102 fRICHsignal(-1),
2714766e 103 fRICHtheta(-1),
104 fRICHphi(-1),
105 fRICHdx(-1),
106 fRICHdy(-1),
107 fRICHmipX(-1),
108 fRICHmipY(-1),
15e85efa 109 fPoints(0),
110 fFriendTrack(new AliESDfriendTrack())
ae982df3 111{
112 //
113 // The default ESD constructor
114 //
6d45eaef 115 Int_t i, j;
6238d7a9 116 for (i=0; i<AliPID::kSPECIES; i++) {
4a78b8c5 117 fTrackTime[i]=0.;
118 fR[i]=1.;
119 fITSr[i]=1.;
120 fTPCr[i]=1.;
121 fTRDr[i]=1.;
122 fTOFr[i]=1.;
4a78b8c5 123 fRICHr[i]=1.;
2bad268c 124 }
ac2f7574 125
ef7253ac 126 for (i=0; i<3; i++) { fKinkIndexes[i]=0;}
127 for (i=0; i<3; i++) { fV0Indexes[i]=-1;}
6d45eaef 128 for (i=0;i<kNPlane;i++) {
129 for (j=0;j<kNSlice;j++) {
130 fTRDsignals[i][j]=0.;
131 }
132 fTRDTimBin[i]=-1;
133 }
c9ec41e8 134 for (i=0;i<4;i++) {fTPCPoints[i]=-1;}
135 for (i=0;i<3;i++) {fTOFLabel[i]=-1;}
136 for (i=0;i<10;i++) {fTOFInfo[i]=-1;}
c4d11b15 137}
138
139//_______________________________________________________________________
90e48c0c 140AliESDtrack::AliESDtrack(const AliESDtrack& track):
c9ec41e8 141 AliExternalTrackParam(track),
90e48c0c 142 fFlags(track.fFlags),
143 fLabel(track.fLabel),
144 fID(track.fID),
145 fTrackLength(track.fTrackLength),
49d13e89 146 fD(track.fD),fZ(track.fZ),
147 fCdd(track.fCdd),fCdz(track.fCdz),fCzz(track.fCzz),
90e48c0c 148 fStopVertex(track.fStopVertex),
c9ec41e8 149 fCp(0),
90e48c0c 150 fCchi2(track.fCchi2),
c9ec41e8 151 fIp(0),
152 fOp(0),
90e48c0c 153 fITSchi2(track.fITSchi2),
154 fITSncls(track.fITSncls),
155 fITSsignal(track.fITSsignal),
156 fITSLabel(track.fITSLabel),
157 fITSFakeRatio(track.fITSFakeRatio),
90e48c0c 158 fTPCchi2(track.fTPCchi2),
159 fTPCncls(track.fTPCncls),
e1d4c1b5 160 fTPCnclsF(track.fTPCnclsF),
90e48c0c 161 fTPCClusterMap(track.fTPCClusterMap),
162 fTPCsignal(track.fTPCsignal),
e1d4c1b5 163 fTPCsignalN(track.fTPCsignalN),
164 fTPCsignalS(track.fTPCsignalS),
90e48c0c 165 fTPCLabel(track.fTPCLabel),
166 fTRDchi2(track.fTRDchi2),
167 fTRDncls(track.fTRDncls),
168 fTRDncls0(track.fTRDncls0),
169 fTRDsignal(track.fTRDsignal),
170 fTRDLabel(track.fTRDLabel),
171 fTRDQuality(track.fTRDQuality),
23d49657 172 fTRDBudget(track.fTRDBudget),
90e48c0c 173 fTOFchi2(track.fTOFchi2),
174 fTOFindex(track.fTOFindex),
85324138 175 fTOFCalChannel(track.fTOFCalChannel),
90e48c0c 176 fTOFsignal(track.fTOFsignal),
85324138 177 fTOFsignalToT(track.fTOFsignalToT),
90e48c0c 178 fRICHchi2(track.fRICHchi2),
179 fRICHncls(track.fRICHncls),
180 fRICHindex(track.fRICHindex),
181 fRICHsignal(track.fRICHsignal),
182 fRICHtheta(track.fRICHtheta),
183 fRICHphi(track.fRICHphi),
184 fRICHdx(track.fRICHdx),
6238d7a9 185 fRICHdy(track.fRICHdy),
186 fRICHmipX(track.fRICHmipX),
15e85efa 187 fRICHmipY(track.fRICHmipY),
188 fPoints(0),
189 fFriendTrack(new AliESDfriendTrack(*(track.fFriendTrack)))
90e48c0c 190{
c4d11b15 191 //
192 //copy constructor
193 //
ef7253ac 194 for (Int_t i=0;i<AliPID::kSPECIES;i++) fTrackTime[i]=track.fTrackTime[i];
195 for (Int_t i=0;i<AliPID::kSPECIES;i++) fR[i]=track.fR[i];
c4d11b15 196 //
304864ab 197 for (Int_t i=0;i<AliPID::kSPECIES;i++) fITSr[i]=track.fITSr[i];
c4d11b15 198 //
304864ab 199 for (Int_t i=0;i<AliPID::kSPECIES;i++) fTPCr[i]=track.fTPCr[i];
51ad6848 200 for (Int_t i=0;i<4;i++) {fTPCPoints[i]=track.fTPCPoints[i];}
201 for (Int_t i=0; i<3;i++) { fKinkIndexes[i]=track.fKinkIndexes[i];}
202 for (Int_t i=0; i<3;i++) { fV0Indexes[i]=track.fV0Indexes[i];}
c4d11b15 203 //
eab5961e 204 for (Int_t i=0;i<kNPlane;i++) {
6d45eaef 205 for (Int_t j=0;j<kNSlice;j++) {
206 fTRDsignals[i][j]=track.fTRDsignals[i][j];
207 }
208 fTRDTimBin[i]=track.fTRDTimBin[i];
eab5961e 209 }
304864ab 210 for (Int_t i=0;i<AliPID::kSPECIES;i++) fTRDr[i]=track.fTRDr[i];
304864ab 211 for (Int_t i=0;i<AliPID::kSPECIES;i++) fTOFr[i]=track.fTOFr[i];
51ad6848 212 for (Int_t i=0;i<3;i++) fTOFLabel[i]=track.fTOFLabel[i];
213 for (Int_t i=0;i<10;i++) fTOFInfo[i]=track.fTOFInfo[i];
304864ab 214 for (Int_t i=0;i<AliPID::kSPECIES;i++) fRICHr[i]=track.fRICHr[i];
c9ec41e8 215
216 if (track.fCp) fCp=new AliExternalTrackParam(*track.fCp);
217 if (track.fIp) fIp=new AliExternalTrackParam(*track.fIp);
218 if (track.fOp) fOp=new AliExternalTrackParam(*track.fOp);
15e85efa 219
220 if (track.fPoints) fPoints=new AliTrackPointArray(*(track.fPoints));
ae982df3 221}
15e85efa 222
c4d11b15 223//_______________________________________________________________________
224AliESDtrack::~AliESDtrack(){
225 //
226 // This is destructor according Coding Conventrions
227 //
228 //printf("Delete track\n");
c9ec41e8 229 delete fIp;
230 delete fOp;
231 delete fCp;
15e85efa 232 delete fFriendTrack;
98937d93 233 delete fPoints;
c4d11b15 234}
ae982df3 235
00dce61a 236void AliESDtrack::AddCalibObject(TObject * object){
237 //
238 // add calib object to the list
239 //
240 if (!fFriendTrack) fFriendTrack = new AliESDfriendTrack;
241 fFriendTrack->AddCalibObject(object);
242}
243
244TObject * AliESDtrack::GetCalibObject(Int_t index){
245 //
246 // return calib objct at given position
247 //
248 if (!fFriendTrack) return 0;
249 return fFriendTrack->GetCalibObject(index);
250}
251
252
ae982df3 253//_______________________________________________________________________
9559cbc4 254void AliESDtrack::MakeMiniESDtrack(){
255 // Resets everything except
256 // fFlags: Reconstruction status flags
257 // fLabel: Track label
258 // fID: Unique ID of the track
259 // fD: Impact parameter in XY-plane
260 // fZ: Impact parameter in Z
261 // fR[AliPID::kSPECIES]: combined "detector response probability"
262 // Running track parameters
263 // fRalpha: track rotation angle
264 // fRx: X-coordinate of the track reference plane
265 // fRp[5]: external track parameters
266 // fRc[15]: external cov. matrix of the track parameters
267
268 fTrackLength = 0;
269 for (Int_t i=0;i<AliPID::kSPECIES;i++) fTrackTime[i] = 0;
270 fStopVertex = 0;
271
272 // Reset track parameters constrained to the primary vertex
c9ec41e8 273 fCp = 0;
9559cbc4 274 fCchi2 = 0;
275
276 // Reset track parameters at the inner wall of TPC
c9ec41e8 277 fIp = 0;
9559cbc4 278
279 // Reset track parameters at the inner wall of the TRD
c9ec41e8 280 fOp = 0;
9559cbc4 281
282 // Reset ITS track related information
283 fITSchi2 = 0;
9559cbc4 284 fITSncls = 0;
9559cbc4 285 fITSsignal = 0;
ef7253ac 286 for (Int_t i=0;i<AliPID::kSPECIES;i++) fITSr[i]=0;
9559cbc4 287 fITSLabel = 0;
288 fITSFakeRatio = 0;
9559cbc4 289
290 // Reset TPC related track information
291 fTPCchi2 = 0;
292 fTPCncls = 0;
e1d4c1b5 293 fTPCnclsF = 0;
9559cbc4 294 fTPCClusterMap = 0;
295 fTPCsignal= 0;
e1d4c1b5 296 fTPCsignalS= 0;
297 fTPCsignalN= 0;
9559cbc4 298 for (Int_t i=0;i<AliPID::kSPECIES;i++) fTPCr[i]=0;
299 fTPCLabel=0;
300 for (Int_t i=0;i<4;i++) fTPCPoints[i] = 0;
301 for (Int_t i=0; i<3;i++) fKinkIndexes[i] = 0;
302 for (Int_t i=0; i<3;i++) fV0Indexes[i] = 0;
303
304 // Reset TRD related track information
305 fTRDchi2 = 0;
306 fTRDncls = 0;
307 fTRDncls0 = 0;
9559cbc4 308 fTRDsignal = 0;
309 for (Int_t i=0;i<kNPlane;i++) {
6d45eaef 310 for (Int_t j=0;j<kNSlice;j++) {
311 fTRDsignals[i][j] = 0;
312 }
313 fTRDTimBin[i] = 0;
9559cbc4 314 }
315 for (Int_t i=0;i<AliPID::kSPECIES;i++) fTRDr[i] = 0;
316 fTRDLabel = 0;
9559cbc4 317 fTRDQuality = 0;
23d49657 318 fTRDBudget = 0;
9559cbc4 319
320 // Reset TOF related track information
321 fTOFchi2 = 0;
322 fTOFindex = 0;
323 fTOFsignal = 0;
85324138 324 fTOFCalChannel = -1;
325 fTOFsignalToT = 0;
9559cbc4 326 for (Int_t i=0;i<AliPID::kSPECIES;i++) fTOFr[i] = 0;
327 for (Int_t i=0;i<3;i++) fTOFLabel[i] = 0;
328 for (Int_t i=0;i<10;i++) fTOFInfo[i] = 0;
329
9559cbc4 330 // Reset RICH related track information
331 fRICHchi2 = 0;
332 fRICHncls = 0;
333 fRICHindex = 0;
334 fRICHsignal = 0;
335 for (Int_t i=0;i<AliPID::kSPECIES;i++) fRICHr[i] = 0;
336 fRICHtheta = 0;
337 fRICHphi = 0;
338 fRICHdx = 0;
339 fRICHdy = 0;
340
15e85efa 341 delete fFriendTrack; fFriendTrack = 0;
342 delete fPoints; fPoints = 0;
9559cbc4 343}
344//_______________________________________________________________________
4a78b8c5 345Double_t AliESDtrack::GetMass() const {
4427806c 346 // Returns the mass of the most probable particle type
ae982df3 347 Float_t max=0.;
348 Int_t k=-1;
304864ab 349 for (Int_t i=0; i<AliPID::kSPECIES; i++) {
ae982df3 350 if (fR[i]>max) {k=i; max=fR[i];}
351 }
db3989b3 352 if (k==0) { // dE/dx "crossing points" in the TPC
353 Double_t p=GetP();
354 if ((p>0.38)&&(p<0.48))
304864ab 355 if (fR[0]<fR[3]*10.) return AliPID::ParticleMass(AliPID::kKaon);
db3989b3 356 if ((p>0.75)&&(p<0.85))
304864ab 357 if (fR[0]<fR[4]*10.) return AliPID::ParticleMass(AliPID::kProton);
db3989b3 358 return 0.00051;
359 }
304864ab 360 if (k==1) return AliPID::ParticleMass(AliPID::kMuon);
361 if (k==2||k==-1) return AliPID::ParticleMass(AliPID::kPion);
362 if (k==3) return AliPID::ParticleMass(AliPID::kKaon);
363 if (k==4) return AliPID::ParticleMass(AliPID::kProton);
5f7789fc 364 AliWarning("Undefined mass !");
304864ab 365 return AliPID::ParticleMass(AliPID::kPion);
ae982df3 366}
367
368//_______________________________________________________________________
c9ec41e8 369Bool_t AliESDtrack::UpdateTrackParams(const AliKalmanTrack *t, ULong_t flags){
ae982df3 370 //
371 // This function updates track's running parameters
372 //
15e85efa 373 Int_t *index=0;
15614b8b 374 Bool_t rc=kTRUE;
375
9b859005 376 SetStatus(flags);
377 fLabel=t->GetLabel();
378
379 if (t->IsStartedTimeIntegral()) {
380 SetStatus(kTIME);
381 Double_t times[10];t->GetIntegratedTimes(times); SetIntegratedTimes(times);
382 SetIntegratedLength(t->GetIntegratedLength());
383 }
384
c9ec41e8 385 Set(*t);
e1d4c1b5 386
ae982df3 387 switch (flags) {
ad2f1f2b 388
9b859005 389 case kITSin: case kITSout: case kITSrefit:
15e85efa 390 index=fFriendTrack->GetITSindices();
391 for (Int_t i=0;i<AliESDfriendTrack::kMaxITScluster;i++)
392 index[i]=t->GetClusterIndex(i);
ae982df3 393 fITSncls=t->GetNumberOfClusters();
394 fITSchi2=t->GetChi2();
ae982df3 395 fITSsignal=t->GetPIDsignal();
6e5b1b04 396 fITSLabel = t->GetLabel();
babd135a 397 fITSFakeRatio = t->GetFakeRatio();
ae982df3 398 break;
ad2f1f2b 399
9b859005 400 case kTPCin: case kTPCrefit:
6e5b1b04 401 fTPCLabel = t->GetLabel();
c9ec41e8 402 if (!fIp) fIp=new AliExternalTrackParam(*t);
403 else fIp->Set(*t);
9b859005 404 case kTPCout:
15e85efa 405 index=fFriendTrack->GetTPCindices();
1d303a24 406 if (flags & kTPCout){
407 if (!fOp) fOp=new AliExternalTrackParam(*t);
408 else fOp->Set(*t);
409 }
e1d4c1b5 410 fTPCncls=t->GetNumberOfClusters();
ae982df3 411 fTPCchi2=t->GetChi2();
a866ac60 412
413 {//prevrow must be declared in separate namespace, otherwise compiler cries:
414 //"jump to case label crosses initialization of `Int_t prevrow'"
415 Int_t prevrow = -1;
6e5b1b04 416 // for (Int_t i=0;i<fTPCncls;i++)
15e85efa 417 for (Int_t i=0;i<AliESDfriendTrack::kMaxTPCcluster;i++)
a866ac60 418 {
15e85efa 419 index[i]=t->GetClusterIndex(i);
420 Int_t idx = index[i];
a866ac60 421
15e85efa 422 if (idx<0) continue;
9fe5b2ff 423
a866ac60 424 // Piotr's Cluster Map for HBT
425 // ### please change accordingly if cluster array is changing
426 // to "New TPC Tracking" style (with gaps in array)
a866ac60 427 Int_t sect = (idx&0xff000000)>>24;
428 Int_t row = (idx&0x00ff0000)>>16;
429 if (sect > 18) row +=63; //if it is outer sector, add number of inner sectors
430
431 fTPCClusterMap.SetBitNumber(row,kTRUE);
432
433 //Fill the gap between previous row and this row with 0 bits
434 //In case ### pleas change it as well - just set bit 0 in case there
435 //is no associated clusters for current "i"
436 if (prevrow < 0)
437 {
438 prevrow = row;//if previous bit was not assigned yet == this is the first one
439 }
440 else
441 { //we don't know the order (inner to outer or reverse)
442 //just to be save in case it is going to change
443 Int_t n = 0, m = 0;
444 if (prevrow < row)
445 {
446 n = prevrow;
447 m = row;
448 }
449 else
450 {
451 n = row;
452 m = prevrow;
453 }
454
455 for (Int_t j = n+1; j < m; j++)
456 {
457 fTPCClusterMap.SetBitNumber(j,kFALSE);
458 }
459 prevrow = row;
460 }
461 // End Of Piotr's Cluster Map for HBT
462 }
463 }
ae982df3 464 fTPCsignal=t->GetPIDsignal();
ae982df3 465 break;
9b859005 466
23904d16 467 case kTRDout: case kTRDin: case kTRDrefit:
15e85efa 468 index=fFriendTrack->GetTRDindices();
51ad6848 469 fTRDLabel = t->GetLabel();
79e94bf8 470 fTRDncls=t->GetNumberOfClusters();
471 fTRDchi2=t->GetChi2();
15e85efa 472 for (Int_t i=0;i<fTRDncls;i++) index[i]=t->GetClusterIndex(i);
79e94bf8 473 fTRDsignal=t->GetPIDsignal();
474 break;
c4d11b15 475 case kTRDbackup:
c9ec41e8 476 if (!fOp) fOp=new AliExternalTrackParam(*t);
477 else fOp->Set(*t);
c4d11b15 478 fTRDncls0 = t->GetNumberOfClusters();
479 break;
480 case kTOFin:
481 break;
482 case kTOFout:
483 break;
d0862fea 484 case kTRDStop:
485 break;
ae982df3 486 default:
5f7789fc 487 AliError("Wrong flag !");
ae982df3 488 return kFALSE;
489 }
490
15614b8b 491 return rc;
ae982df3 492}
493
494//_______________________________________________________________________
495void AliESDtrack::GetExternalParameters(Double_t &x, Double_t p[5]) const {
496 //---------------------------------------------------------------------
497 // This function returns external representation of the track parameters
498 //---------------------------------------------------------------------
c9ec41e8 499 x=GetX();
500 for (Int_t i=0; i<5; i++) p[i]=GetParameter()[i];
15614b8b 501}
502
67c3dcbe 503//_______________________________________________________________________
a866ac60 504void AliESDtrack::GetExternalCovariance(Double_t cov[15]) const {
67c3dcbe 505 //---------------------------------------------------------------------
506 // This function returns external representation of the cov. matrix
507 //---------------------------------------------------------------------
c9ec41e8 508 for (Int_t i=0; i<15; i++) cov[i]=AliExternalTrackParam::GetCovariance()[i];
67c3dcbe 509}
510
67c3dcbe 511//_______________________________________________________________________
c0b978f0 512Bool_t AliESDtrack::GetConstrainedExternalParameters
513 (Double_t &alpha, Double_t &x, Double_t p[5]) const {
67c3dcbe 514 //---------------------------------------------------------------------
515 // This function returns the constrained external track parameters
516 //---------------------------------------------------------------------
c0b978f0 517 if (!fCp) return kFALSE;
518 alpha=fCp->GetAlpha();
c9ec41e8 519 x=fCp->GetX();
520 for (Int_t i=0; i<5; i++) p[i]=fCp->GetParameter()[i];
c0b978f0 521 return kTRUE;
67c3dcbe 522}
c9ec41e8 523
67c3dcbe 524//_______________________________________________________________________
c0b978f0 525Bool_t
67c3dcbe 526AliESDtrack::GetConstrainedExternalCovariance(Double_t c[15]) const {
527 //---------------------------------------------------------------------
528 // This function returns the constrained external cov. matrix
529 //---------------------------------------------------------------------
c0b978f0 530 if (!fCp) return kFALSE;
c9ec41e8 531 for (Int_t i=0; i<15; i++) c[i]=fCp->GetCovariance()[i];
c0b978f0 532 return kTRUE;
67c3dcbe 533}
534
c0b978f0 535Bool_t
536AliESDtrack::GetInnerExternalParameters
537 (Double_t &alpha, Double_t &x, Double_t p[5]) const {
538 //---------------------------------------------------------------------
c9ec41e8 539 // This function returns external representation of the track parameters
540 // at the inner layer of TPC
9b859005 541 //---------------------------------------------------------------------
c0b978f0 542 if (!fIp) return kFALSE;
543 alpha=fIp->GetAlpha();
c9ec41e8 544 x=fIp->GetX();
545 for (Int_t i=0; i<5; i++) p[i]=fIp->GetParameter()[i];
c0b978f0 546 return kTRUE;
9b859005 547}
548
c0b978f0 549Bool_t
550AliESDtrack::GetInnerExternalCovariance(Double_t cov[15]) const {
c9ec41e8 551 //---------------------------------------------------------------------
552 // This function returns external representation of the cov. matrix
553 // at the inner layer of TPC
554 //---------------------------------------------------------------------
c0b978f0 555 if (!fIp) return kFALSE;
c9ec41e8 556 for (Int_t i=0; i<15; i++) cov[i]=fIp->GetCovariance()[i];
c0b978f0 557 return kTRUE;
9b859005 558}
559
c0b978f0 560Bool_t
561AliESDtrack::GetOuterExternalParameters
562 (Double_t &alpha, Double_t &x, Double_t p[5]) const {
563 //---------------------------------------------------------------------
c9ec41e8 564 // This function returns external representation of the track parameters
565 // at the inner layer of TRD
a866ac60 566 //---------------------------------------------------------------------
c0b978f0 567 if (!fOp) return kFALSE;
568 alpha=fOp->GetAlpha();
c9ec41e8 569 x=fOp->GetX();
570 for (Int_t i=0; i<5; i++) p[i]=fOp->GetParameter()[i];
c0b978f0 571 return kTRUE;
a866ac60 572}
c9ec41e8 573
c0b978f0 574Bool_t
575AliESDtrack::GetOuterExternalCovariance(Double_t cov[15]) const {
a866ac60 576 //---------------------------------------------------------------------
c9ec41e8 577 // This function returns external representation of the cov. matrix
578 // at the inner layer of TRD
a866ac60 579 //---------------------------------------------------------------------
c0b978f0 580 if (!fOp) return kFALSE;
c9ec41e8 581 for (Int_t i=0; i<15; i++) cov[i]=fOp->GetCovariance()[i];
c0b978f0 582 return kTRUE;
a866ac60 583}
584
98937d93 585Int_t AliESDtrack::GetNcls(Int_t idet) const
586{
587 // Get number of clusters by subdetector index
588 //
589 Int_t ncls = 0;
590 switch(idet){
591 case 0:
592 ncls = fITSncls;
593 break;
594 case 1:
595 ncls = fTPCncls;
596 break;
597 case 2:
598 ncls = fTRDncls;
599 break;
600 case 3:
601 if (fTOFindex != 0)
602 ncls = 1;
603 break;
604 default:
605 break;
606 }
607 return ncls;
608}
609
ef7253ac 610Int_t AliESDtrack::GetClusters(Int_t idet, Int_t *idx) const
98937d93 611{
612 // Get cluster index array by subdetector index
613 //
614 Int_t ncls = 0;
615 switch(idet){
616 case 0:
617 ncls = GetITSclusters(idx);
618 break;
619 case 1:
ef7253ac 620 ncls = GetTPCclusters(idx);
98937d93 621 break;
622 case 2:
623 ncls = GetTRDclusters(idx);
624 break;
625 case 3:
626 if (fTOFindex != 0) {
627 idx[0] = GetTOFcluster();
628 ncls = 1;
629 }
630 break;
631 default:
632 break;
633 }
634 return ncls;
635}
636
ae982df3 637//_______________________________________________________________________
ae982df3 638void AliESDtrack::GetIntegratedTimes(Double_t *times) const {
4427806c 639 // Returns the array with integrated times for each particle hypothesis
304864ab 640 for (Int_t i=0; i<AliPID::kSPECIES; i++) times[i]=fTrackTime[i];
ae982df3 641}
642
643//_______________________________________________________________________
644void AliESDtrack::SetIntegratedTimes(const Double_t *times) {
4427806c 645 // Sets the array with integrated times for each particle hypotesis
304864ab 646 for (Int_t i=0; i<AliPID::kSPECIES; i++) fTrackTime[i]=times[i];
ae982df3 647}
648
649//_______________________________________________________________________
4427806c 650void AliESDtrack::SetITSpid(const Double_t *p) {
651 // Sets values for the probability of each particle type (in ITS)
d27bbc79 652 SetPIDValues(fITSr,p,AliPID::kSPECIES);
c630aafd 653 SetStatus(AliESDtrack::kITSpid);
654}
655
656//_______________________________________________________________________
657void AliESDtrack::GetITSpid(Double_t *p) const {
4427806c 658 // Gets the probability of each particle type (in ITS)
304864ab 659 for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fITSr[i];
c630aafd 660}
661
662//_______________________________________________________________________
ef7253ac 663Int_t AliESDtrack::GetITSclusters(Int_t *idx) const {
ae982df3 664 //---------------------------------------------------------------------
665 // This function returns indices of the assgined ITS clusters
666 //---------------------------------------------------------------------
15e85efa 667 if (idx!=0) {
668 Int_t *index=fFriendTrack->GetITSindices();
669 for (Int_t i=0; i<AliESDfriendTrack::kMaxITScluster; i++) idx[i]=index[i];
670 }
ae982df3 671 return fITSncls;
672}
673
674//_______________________________________________________________________
05e445cd 675Int_t AliESDtrack::GetTPCclusters(Int_t *idx) const {
ae982df3 676 //---------------------------------------------------------------------
677 // This function returns indices of the assgined ITS clusters
678 //---------------------------------------------------------------------
15e85efa 679 if (idx!=0) {
680 Int_t *index=fFriendTrack->GetTPCindices();
681 for (Int_t i=0; i<AliESDfriendTrack::kMaxTPCcluster; i++) idx[i]=index[i];
682 }
ae982df3 683 return fTPCncls;
684}
8c6a71ab 685
81e97e0d 686Float_t AliESDtrack::GetTPCdensity(Int_t row0, Int_t row1) const{
687 //
688 // GetDensity of the clusters on given region between row0 and row1
689 // Dead zone effect takin into acoount
690 //
691 Int_t good = 0;
692 Int_t found = 0;
693 //
15e85efa 694 Int_t *index=fFriendTrack->GetTPCindices();
81e97e0d 695 for (Int_t i=row0;i<=row1;i++){
15e85efa 696 Int_t idx = index[i];
697 if (idx!=-1) good++; // track outside of dead zone
698 if (idx>0) found++;
81e97e0d 699 }
700 Float_t density=0.5;
701 if (good>(row1-row0)*0.5) density = Float_t(found)/Float_t(good);
702 return density;
703}
c84a5e9e 704
8c6a71ab 705//_______________________________________________________________________
706void AliESDtrack::SetTPCpid(const Double_t *p) {
4427806c 707 // Sets values for the probability of each particle type (in TPC)
d27bbc79 708 SetPIDValues(fTPCr,p,AliPID::kSPECIES);
8c6a71ab 709 SetStatus(AliESDtrack::kTPCpid);
710}
711
712//_______________________________________________________________________
713void AliESDtrack::GetTPCpid(Double_t *p) const {
4427806c 714 // Gets the probability of each particle type (in TPC)
304864ab 715 for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTPCr[i];
8c6a71ab 716}
717
718//_______________________________________________________________________
ef7253ac 719Int_t AliESDtrack::GetTRDclusters(Int_t *idx) const {
bb2ceb1f 720 //---------------------------------------------------------------------
721 // This function returns indices of the assgined TRD clusters
722 //---------------------------------------------------------------------
15e85efa 723 if (idx!=0) {
724 Int_t *index=fFriendTrack->GetTRDindices();
725 for (Int_t i=0; i<AliESDfriendTrack::kMaxTRDcluster; i++) idx[i]=index[i];
726 }
bb2ceb1f 727 return fTRDncls;
728}
729
730//_______________________________________________________________________
c630aafd 731void AliESDtrack::SetTRDpid(const Double_t *p) {
4427806c 732 // Sets values for the probability of each particle type (in TRD)
d27bbc79 733 SetPIDValues(fTRDr,p,AliPID::kSPECIES);
c630aafd 734 SetStatus(AliESDtrack::kTRDpid);
735}
736
737//_______________________________________________________________________
738void AliESDtrack::GetTRDpid(Double_t *p) const {
4427806c 739 // Gets the probability of each particle type (in TRD)
304864ab 740 for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTRDr[i];
c630aafd 741}
742
743//_______________________________________________________________________
79e94bf8 744void AliESDtrack::SetTRDpid(Int_t iSpecies, Float_t p)
745{
4427806c 746 // Sets the probability of particle type iSpecies to p (in TRD)
79e94bf8 747 fTRDr[iSpecies] = p;
748}
749
750Float_t AliESDtrack::GetTRDpid(Int_t iSpecies) const
751{
4427806c 752 // Returns the probability of particle type iSpecies (in TRD)
79e94bf8 753 return fTRDr[iSpecies];
754}
755
756//_______________________________________________________________________
c630aafd 757void AliESDtrack::SetTOFpid(const Double_t *p) {
4427806c 758 // Sets the probability of each particle type (in TOF)
d27bbc79 759 SetPIDValues(fTOFr,p,AliPID::kSPECIES);
c630aafd 760 SetStatus(AliESDtrack::kTOFpid);
761}
762
763//_______________________________________________________________________
51ad6848 764void AliESDtrack::SetTOFLabel(const Int_t *p) {
765 // Sets (in TOF)
766 for (Int_t i=0; i<3; i++) fTOFLabel[i]=p[i];
767}
768
769//_______________________________________________________________________
c630aafd 770void AliESDtrack::GetTOFpid(Double_t *p) const {
4427806c 771 // Gets probabilities of each particle type (in TOF)
304864ab 772 for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fTOFr[i];
c630aafd 773}
774
51ad6848 775//_______________________________________________________________________
776void AliESDtrack::GetTOFLabel(Int_t *p) const {
777 // Gets (in TOF)
778 for (Int_t i=0; i<3; i++) p[i]=fTOFLabel[i];
779}
780
781//_______________________________________________________________________
782void AliESDtrack::GetTOFInfo(Float_t *info) const {
783 // Gets (in TOF)
784 for (Int_t i=0; i<10; i++) info[i]=fTOFInfo[i];
785}
786
787//_______________________________________________________________________
788void AliESDtrack::SetTOFInfo(Float_t*info) {
789 // Gets (in TOF)
790 for (Int_t i=0; i<10; i++) fTOFInfo[i]=info[i];
791}
792
4a78b8c5 793
794
795//_______________________________________________________________________
4a78b8c5 796void AliESDtrack::SetRICHpid(const Double_t *p) {
797 // Sets the probability of each particle type (in RICH)
d27bbc79 798 SetPIDValues(fRICHr,p,AliPID::kSPECIES);
4a78b8c5 799 SetStatus(AliESDtrack::kRICHpid);
800}
801
802//_______________________________________________________________________
803void AliESDtrack::GetRICHpid(Double_t *p) const {
804 // Gets probabilities of each particle type (in RICH)
304864ab 805 for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fRICHr[i];
4a78b8c5 806}
807
808
809
c630aafd 810//_______________________________________________________________________
8c6a71ab 811void AliESDtrack::SetESDpid(const Double_t *p) {
4427806c 812 // Sets the probability of each particle type for the ESD track
d27bbc79 813 SetPIDValues(fR,p,AliPID::kSPECIES);
8c6a71ab 814 SetStatus(AliESDtrack::kESDpid);
815}
816
817//_______________________________________________________________________
818void AliESDtrack::GetESDpid(Double_t *p) const {
4427806c 819 // Gets probability of each particle type for the ESD track
304864ab 820 for (Int_t i=0; i<AliPID::kSPECIES; i++) p[i]=fR[i];
8c6a71ab 821}
822
ac2f7574 823//_______________________________________________________________________
49d13e89 824Bool_t AliESDtrack::RelateToVertex
825(const AliESDVertex *vtx, Double_t b, Double_t maxd) {
826 //
827 // Try to relate this track to the vertex "vtx",
828 // if the (rough) transverse impact parameter is not bigger then "maxd".
829 // Magnetic field is "b" (kG).
830 //
831 // a) The track gets extapolated to the DCA to the vertex.
832 // b) The impact parameters and their covariance matrix are calculated.
833 // c) An attempt to constrain this track to the vertex is done.
834 //
835 // In the case of success, the returned value is kTRUE
836 // (otherwise, it's kFALSE)
837 //
b5d34a4c 838
839 if (!vtx) return kFALSE;
840
49d13e89 841 Double_t alpha=GetAlpha();
842 Double_t sn=TMath::Sin(alpha), cs=TMath::Cos(alpha);
843 Double_t x=GetX(), y=GetParameter()[0], snp=GetParameter()[2];
844 Double_t xv= vtx->GetXv()*cs + vtx->GetYv()*sn;
845 Double_t yv=-vtx->GetXv()*sn + vtx->GetYv()*cs, zv=vtx->GetZv();
846 x-=xv; y-=yv;
847
848 //Estimate the impact parameter neglecting the track curvature
849 Double_t d=TMath::Abs(x*snp - y*TMath::Sqrt(1.- snp*snp));
850 if (d > maxd) return kFALSE;
851
852 //Propagate to the DCA
5773defd 853 Double_t crv=kB2C*b*GetParameter()[4];
854 if (TMath::Abs(b) < kAlmost0Field) crv=0.;
855
49d13e89 856 Double_t tgfv=-(crv*x - snp)/(crv*y + TMath::Sqrt(1.-snp*snp));
f54395bf 857 sn=tgfv/TMath::Sqrt(1.+ tgfv*tgfv);
858 if (TMath::Abs(tgfv)>0.) cs = sn/tgfv;
859 else cs=1.;
49d13e89 860
861 x = xv*cs + yv*sn;
862 yv=-xv*sn + yv*cs; xv=x;
863
864 if (!Propagate(alpha+TMath::ASin(sn),xv,b)) return kFALSE;
865
866 fD = GetParameter()[0] - yv;
867 fZ = GetParameter()[1] - zv;
868
869 Double_t cov[6]; vtx->GetCovMatrix(cov);
870 fCdd = GetCovariance()[0] + cov[2]; // neglecting non-diagonals
871 fCdz = GetCovariance()[1]; // in the vertex's
872 fCzz = GetCovariance()[2] + cov[5]; // covariance matrix
873
874 {//Try to constrain
875 Double_t p[2]={yv,zv}, c[3]={cov[2],0.,cov[5]};
876 Double_t chi2=GetPredictedChi2(p,c);
877
878 if (chi2>77.) return kFALSE;
879
880 AliExternalTrackParam tmp(*this);
881 if (!tmp.Update(p,c)) return kFALSE;
882
883 fCchi2=chi2;
884 if (!fCp) fCp=new AliExternalTrackParam();
885 new (fCp) AliExternalTrackParam(tmp);
886 }
887
888 return kTRUE;
889}
890
15e85efa 891void AliESDtrack::SetTrackPointArray(AliTrackPointArray *points) {
892 fPoints=points;
893 //fFriendTrack->SetTrackPointArray(points);
894}
895const AliTrackPointArray *AliESDtrack::GetTrackPointArray() const {
896 return fPoints;
897 //return fFriendTrack->GetTrackPointArray();
898}
899
49d13e89 900//_______________________________________________________________________
ac2f7574 901void AliESDtrack::Print(Option_t *) const {
902 // Prints info on the track
903
5f7789fc 904 printf("ESD track info\n") ;
304864ab 905 Double_t p[AliPID::kSPECIESN] ;
ac2f7574 906 Int_t index = 0 ;
907 if( IsOn(kITSpid) ){
908 printf("From ITS: ") ;
909 GetITSpid(p) ;
304864ab 910 for(index = 0 ; index < AliPID::kSPECIES; index++)
ac2f7574 911 printf("%f, ", p[index]) ;
912 printf("\n signal = %f\n", GetITSsignal()) ;
913 }
914 if( IsOn(kTPCpid) ){
915 printf("From TPC: ") ;
916 GetTPCpid(p) ;
304864ab 917 for(index = 0 ; index < AliPID::kSPECIES; index++)
ac2f7574 918 printf("%f, ", p[index]) ;
919 printf("\n signal = %f\n", GetTPCsignal()) ;
920 }
921 if( IsOn(kTRDpid) ){
922 printf("From TRD: ") ;
923 GetTRDpid(p) ;
304864ab 924 for(index = 0 ; index < AliPID::kSPECIES; index++)
ac2f7574 925 printf("%f, ", p[index]) ;
926 printf("\n signal = %f\n", GetTRDsignal()) ;
927 }
928 if( IsOn(kTOFpid) ){
929 printf("From TOF: ") ;
930 GetTOFpid(p) ;
304864ab 931 for(index = 0 ; index < AliPID::kSPECIES; index++)
ac2f7574 932 printf("%f, ", p[index]) ;
933 printf("\n signal = %f\n", GetTOFsignal()) ;
934 }
935 if( IsOn(kRICHpid) ){
038834e7 936 printf("From RICH: ") ;
ac2f7574 937 GetRICHpid(p) ;
304864ab 938 for(index = 0 ; index < AliPID::kSPECIES; index++)
ac2f7574 939 printf("%f, ", p[index]) ;
940 printf("\n signal = %f\n", GetRICHsignal()) ;
941 }
ac2f7574 942}