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