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