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