]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDtrackV1.cxx
Compare method fixed (Plamen)
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackV1.cxx
CommitLineData
d9950a5a 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
203967fc 18#include "AliLog.h"
eb38ed55 19#include "AliESDtrack.h"
41880fac 20#include "AliTracker.h"
eb38ed55 21
d9950a5a 22#include "AliTRDtrackV1.h"
23#include "AliTRDcluster.h"
24#include "AliTRDcalibDB.h"
3afdab72 25#include "AliTRDReconstructor.h"
d9950a5a 26#include "AliTRDrecoParam.h"
27
d9950a5a 28ClassImp(AliTRDtrackV1)
29
0906e73e 30///////////////////////////////////////////////////////////////////////////////
31// //
32// Represents a reconstructed TRD track //
33// Local TRD Kalman track //
34// //
35// Authors: //
36// Alex Bercuci <A.Bercuci@gsi.de> //
37// Markus Fasel <M.Fasel@gsi.de> //
38// //
39///////////////////////////////////////////////////////////////////////////////
d9950a5a 40
41//_______________________________________________________________
3b57a3f7 42AliTRDtrackV1::AliTRDtrackV1() : AliKalmanTrack()
eb2b4f91 43 ,fStatus(0)
3b57a3f7 44 ,fDE(0.)
215f7116 45 ,fReconstructor(0x0)
3b57a3f7 46 ,fBackupTrack(0x0)
e3cf3d02 47 ,fTrackLow(0x0)
48 ,fTrackHigh(0x0)
0906e73e 49{
d9950a5a 50 //
51 // Default constructor
52 //
6e49cfdb 53 //printf("AliTRDtrackV1::AliTRDtrackV1()\n");
e44586fb 54
3b57a3f7 55 for(int i =0; i<3; i++) fBudget[i] = 0.;
56
57 Float_t pid = 1./AliPID::kSPECIES;
58 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
59
60 for(int ip=0; ip<kNplane; ip++){
61 fTrackletIndex[ip] = 0xffff;
62 fTracklet[ip] = 0x0;
63 }
d9950a5a 64}
65
66//_______________________________________________________________
3b57a3f7 67AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &ref) : AliKalmanTrack(ref)
eb2b4f91 68 ,fStatus(ref.fStatus)
3b57a3f7 69 ,fDE(ref.fDE)
215f7116 70 ,fReconstructor(ref.fReconstructor)
3b57a3f7 71 ,fBackupTrack(0x0)
e3cf3d02 72 ,fTrackLow(0x0)
73 ,fTrackHigh(0x0)
d9950a5a 74{
75 //
3b57a3f7 76 // Copy constructor
d9950a5a 77 //
78
6e49cfdb 79 //printf("AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &)\n");
29b87567 80 SetBit(kOwner, kFALSE);
3b57a3f7 81 for(int ip=0; ip<kNplane; ip++){
82 fTrackletIndex[ip] = ref.fTrackletIndex[ip];
83 fTracklet[ip] = ref.fTracklet[ip];
84 }
e3cf3d02 85 if(ref.fTrackLow) fTrackLow = new AliExternalTrackParam(*ref.fTrackLow);
86 if(ref.fTrackHigh) fTrackHigh = new AliExternalTrackParam(*ref.fTrackHigh);
87
3b57a3f7 88 for (Int_t i = 0; i < 3;i++) fBudget[i] = ref.fBudget[i];
89
90 for(Int_t is = 0; is<AliPID::kSPECIES; is++) fPID[is] = ref.fPID[is];
91
92 AliKalmanTrack::SetNumberOfClusters(ref.GetNumberOfClusters());
d9950a5a 93}
94
95//_______________________________________________________________
3b57a3f7 96AliTRDtrackV1::AliTRDtrackV1(const AliESDtrack &t) : AliKalmanTrack()
eb2b4f91 97 ,fStatus(0)
3b57a3f7 98 ,fDE(0.)
215f7116 99 ,fReconstructor(0x0)
3b57a3f7 100 ,fBackupTrack(0x0)
e3cf3d02 101 ,fTrackLow(0x0)
102 ,fTrackHigh(0x0)
d9950a5a 103{
104 //
3b57a3f7 105 // Constructor from AliESDtrack
d9950a5a 106 //
107
3b57a3f7 108 SetLabel(t.GetLabel());
109 SetChi2(0.0);
0b433f72 110
111 SetMass(t.GetMass()/*0.000510*/);
3b57a3f7 112 AliKalmanTrack::SetNumberOfClusters(t.GetTRDncls());
113 Int_t ti[kNplane]; t.GetTRDtracklets(&ti[0]);
114 for(int ip=0; ip<kNplane; ip++){
115 fTrackletIndex[ip] = ti[ip] < 0 ? 0xffff : ti[ip];
116 fTracklet[ip] = 0x0;
117 }
118 for(int i =0; i<3; i++) fBudget[i] = 0.;
119
120 Float_t pid = 1./AliPID::kSPECIES;
121 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
122
123 const AliExternalTrackParam *par = &t;
124 if (t.GetStatus() & AliESDtrack::kTRDbackup) {
125 par = t.GetOuterParam();
126 if (!par) {
127 AliError("No backup info!");
128 par = &t;
129 }
130 }
131 Set(par->GetX()
132 ,par->GetAlpha()
133 ,par->GetParameter()
134 ,par->GetCovariance());
135
136 if(t.GetStatus() & AliESDtrack::kTIME) {
137 StartTimeIntegral();
138 Double_t times[10];
139 t.GetIntegratedTimes(times);
140 SetIntegratedTimes(times);
141 SetIntegratedLength(t.GetIntegratedLength());
142 }
d9950a5a 143}
144
d9950a5a 145//_______________________________________________________________
eb38ed55 146AliTRDtrackV1::AliTRDtrackV1(AliTRDseedV1 *trklts, const Double_t p[5], const Double_t cov[15]
3b57a3f7 147 , Double_t x, Double_t alpha) : AliKalmanTrack()
eb2b4f91 148 ,fStatus(0)
3b57a3f7 149 ,fDE(0.)
215f7116 150 ,fReconstructor(0x0)
3b57a3f7 151 ,fBackupTrack(0x0)
e3cf3d02 152 ,fTrackLow(0x0)
153 ,fTrackHigh(0x0)
d9950a5a 154{
0906e73e 155 //
156 // The stand alone tracking constructor
157 // TEMPORARY !!!!!!!!!!!
158 // to check :
159 // 1. covariance matrix
160 // 2. dQdl calculation
161 //
d9950a5a 162
fb17de1f 163 Double_t cnv = GetBz() < 1.e-5 ? 1.e5 : 1.0 / (GetBz() * kB2C);
164 // Double_t cnv = 1.0 / (GetBz() * kB2C);
d9950a5a 165
166 Double_t pp[5] = { p[0]
167 , p[1]
93f695a3 168 , p[2]
d9950a5a 169 , p[3]
170 , p[4]*cnv };
171
172 Double_t c22 = x*x*cov[14] - 2*x*cov[12] + cov[ 5];
173 Double_t c32 = x*cov[13] - cov[ 8];
174 Double_t c20 = x*cov[10] - cov[ 3];
175 Double_t c21 = x*cov[11] - cov[ 4];
176 Double_t c42 = x*cov[14] - cov[12];
177
178 Double_t cc[15] = { cov[ 0]
179 , cov[ 1], cov[ 2]
180 , c20, c21, c22
181 , cov[ 6], cov[ 7], c32, cov[ 9]
182 , cov[10]*cnv, cov[11]*cnv, c42*cnv, cov[13]*cnv, cov[14]*cnv*cnv };
ae3fbe1f 183
184 Double_t mostProbablePt=AliExternalTrackParam::GetMostProbablePt();
185 Double_t p0=TMath::Sign(1/mostProbablePt,pp[4]);
186 Double_t w0=cc[14]/(cc[14] + p0*p0), w1=p0*p0/(cc[14] + p0*p0);
187 pp[4] = w0*p0 + w1*pp[4];
188 cc[10]*=w1; cc[11]*=w1; cc[12]*=w1; cc[13]*=w1; cc[14]*=w1;
189
d9950a5a 190 Set(x,alpha,pp,cc);
41702fec 191 Int_t ncls = 0;
3b57a3f7 192 for(int iplane=0; iplane<kNplane; iplane++){
41702fec 193 fTrackletIndex[iplane] = 0xffff;
194 if(!trklts[iplane].IsOK()) fTracklet[iplane] = 0x0;
195 else{
76b60503 196 fTracklet[iplane] = &trklts[iplane];
41702fec 197 ncls += fTracklet[iplane]->GetN();
198 }
d9950a5a 199 }
41702fec 200 AliKalmanTrack::SetNumberOfClusters(ncls);
201 for(int i =0; i<3; i++) fBudget[i] = 0.;
202
203 Float_t pid = 1./AliPID::kSPECIES;
204 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
205
d9950a5a 206}
207
bb56afff 208//_______________________________________________________________
3b57a3f7 209AliTRDtrackV1::~AliTRDtrackV1()
bb56afff 210{
e44586fb 211 //AliInfo("");
6e49cfdb 212 //printf("I-AliTRDtrackV1::~AliTRDtrackV1() : Owner[%s]\n", TestBit(kOwner)?"YES":"NO");
76b60503 213
e3cf3d02 214 if(fBackupTrack) delete fBackupTrack; fBackupTrack = 0x0;
215
216 if(fTrackLow) delete fTrackLow; fTrackLow = 0x0;
217 if(fTrackHigh) delete fTrackHigh; fTrackHigh = 0x0;
bb56afff 218
76b60503 219 for(Int_t ip=0; ip<kNplane; ip++){
220 if(TestBit(kOwner) && fTracklet[ip]) delete fTracklet[ip];
221 fTracklet[ip] = 0x0;
222 fTrackletIndex[ip] = 0xffff;
3b57a3f7 223 }
224}
225
226//_______________________________________________________________
227Bool_t AliTRDtrackV1::CookLabel(Float_t wrong)
228{
229 // set MC label for this track
bb2db46c 230 if(!GetNumberOfClusters()) return kFALSE;
231
bb56afff 232 Int_t s[kMAXCLUSTERSPERTRACK][2];
233 for (Int_t i = 0; i < kMAXCLUSTERSPERTRACK; i++) {
234 s[i][0] = -1;
235 s[i][1] = 0;
236 }
3b57a3f7 237
bb56afff 238 Bool_t labelAdded;
3b57a3f7 239 Int_t label;
240 AliTRDcluster *c = 0x0;
241 for (Int_t ip = 0; ip < kNplane; ip++) {
242 if(fTrackletIndex[ip] == 0xffff) continue;
8d2bec9e 243 for (Int_t ic = 0; ic < AliTRDseedV1::kNclusters; ic++) {
3b57a3f7 244 if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
245 for (Int_t k = 0; k < 3; k++) {
246 label = c->GetLabel(k);
247 labelAdded = kFALSE;
248 Int_t j = 0;
249 if (label >= 0) {
250 while ((!labelAdded) && (j < kMAXCLUSTERSPERTRACK)) {
251 if ((s[j][0] == label) ||
252 (s[j][1] == 0)) {
253 s[j][0] = label;
254 s[j][1]++;
255 labelAdded = kTRUE;
256 }
257 j++;
258 }
259 }
260 }
261 }
262 }
263
bb56afff 264 Int_t max = 0;
265 label = -123456789;
266 for (Int_t i = 0; i < kMAXCLUSTERSPERTRACK; i++) {
267 if (s[i][1] <= max) continue;
3b57a3f7 268 max = s[i][1];
269 label = s[i][0];
bb56afff 270 }
bb56afff 271 if ((1. - Float_t(max)/GetNumberOfClusters()) > wrong) label = -label;
3b57a3f7 272
bb56afff 273 SetLabel(label);
3b57a3f7 274
275 return kTRUE;
bb56afff 276}
277
d9950a5a 278//_______________________________________________________________
279Bool_t AliTRDtrackV1::CookPID()
280{
0906e73e 281 //
282 // Cook the PID information
283 //
3b57a3f7 284
285 // Reset the a priori probabilities
286 Double_t pid = 1. / AliPID::kSPECIES;
eb2b4f91 287 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fPID[ispec] = pid;
288
289 UChar_t fPIDquality = SetNumberOfTrackletsPID(kTRUE);
290 // no tracklet found for PID calculations
291 if(!fPIDquality) return kFALSE;
292
293 // slot for PID calculation @ track level
294
295 // normalize probabilities
296 Double_t probTotal = 0.0;
297 for (Int_t is = 0; is < AliPID::kSPECIES; is++) probTotal += fPID[is];
298
299
300 if (probTotal <= 0.0) {
301 AliWarning("The total probability over all species <= 0. This may be caused by some error in the reference data.");
302 return kFALSE;
3b57a3f7 303 }
3b57a3f7 304
eb2b4f91 305 for (Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++) fPID[iSpecies] /= probTotal;
306
307 return kTRUE;
308}
309
310//___________________________________________________________
311UChar_t AliTRDtrackV1::GetNumberOfTrackletsPID() const
312{
313// Retrieve number of tracklets used for PID calculation.
314
e20bef2b 315 UChar_t nPID = 0;
e3cf3d02 316 Float_t *prob = 0x0;
3b57a3f7 317 for(int ip=0; ip<kNplane; ip++){
318 if(fTrackletIndex[ip] == 0xffff) continue;
319 if(!fTracklet[ip]->IsOK()) continue;
e20bef2b 320 if(!(prob = fTracklet[ip]->GetProbability(kFALSE))) continue;
3b57a3f7 321
322 Int_t nspec = 0; // quality check of tracklet dEdx
323 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++){
324 if(prob[ispec] < 0.) continue;
3b57a3f7 325 nspec++;
326 }
327 if(!nspec) continue;
328
e20bef2b 329 fTracklet[ip]->SetPID();
330 nPID++;
0906e73e 331 }
e20bef2b 332 return nPID;
eb2b4f91 333}
334
335//___________________________________________________________
336UChar_t AliTRDtrackV1::SetNumberOfTrackletsPID(Bool_t recalc)
337{
338// Retrieve number of tracklets used for PID calculation. // Recalculated PID at tracklet level by quering the PID DB.
339
340 UChar_t fPIDquality = 0;
0906e73e 341
eb2b4f91 342 // steer PID calculation @ tracklet level
343 Float_t *prob = 0x0;
344 for(int ip=0; ip<kNplane; ip++){
345 if(fTrackletIndex[ip] == 0xffff) continue;
346 if(!fTracklet[ip]->IsOK()) continue;
347 if(!(prob = fTracklet[ip]->GetProbability(recalc))) return 0;
348
349 Int_t nspec = 0; // quality check of tracklet dEdx
350 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++){
351 if(prob[ispec] < 0.) continue;
352 fPID[ispec] *= prob[ispec];
353 nspec++;
354 }
355 if(!nspec) continue;
356
357 fPIDquality++;
d9950a5a 358 }
eb2b4f91 359 return fPIDquality;
d9950a5a 360}
361
0349cc67 362//_______________________________________________________________
363AliTRDcluster* AliTRDtrackV1::GetCluster(Int_t id)
364{
365 Int_t n = 0;
366 for(Int_t ip=0; ip<kNplane; ip++){
367 if(!fTracklet[ip]) continue;
368 if(n+fTracklet[ip]->GetN() <= id){
369 n+=fTracklet[ip]->GetN();
370 continue;
371 }
372 AliTRDcluster *c = 0x0;
8d2bec9e 373 for(Int_t ic=AliTRDseedV1::kNclusters; ic--;){
0349cc67 374 if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
375
376 if(n<id){n++; continue;}
377 return c;
378 }
379 }
380 return 0x0;
381}
382
3b57a3f7 383//_______________________________________________________________
384Int_t AliTRDtrackV1::GetClusterIndex(Int_t id) const
385{
386 Int_t n = 0;
387 for(Int_t ip=0; ip<kNplane; ip++){
388 if(!fTracklet[ip]) continue;
76b60503 389 if(n+fTracklet[ip]->GetN() <= id){
3b57a3f7 390 n+=fTracklet[ip]->GetN();
391 continue;
392 }
76b60503 393 AliTRDcluster *c = 0x0;
8d2bec9e 394 for(Int_t ic=AliTRDseedV1::kNclusters; ic--;){
76b60503 395 if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
396
397 if(n<id){n++; continue;}
3b57a3f7 398 return fTracklet[ip]->GetIndexes(ic);
399 }
400 }
401 return -1;
0906e73e 402}
d9950a5a 403
404//_______________________________________________________________
b72f4eaf 405Double_t AliTRDtrackV1::GetPredictedChi2(const AliTRDseedV1 *trklt, Double_t *cov) const
d9950a5a 406{
ed15ef4f 407// Compute chi2 between tracklet and track. The value is calculated at the radial position of the track
408// equal to the reference radial position of the tracklet (see AliTRDseedV1)
409//
410// The chi2 estimator is computed according to the following formula
411// BEGIN_LATEX
412// #chi^{2}=(X_{trklt}-X_{track})(C_{trklt}+C_{track})^{-1}(X_{trklt}-X_{track})^{T}
413// END_LATEX
414// where X=(y z), the position of the track/tracklet in the yz plane
415//
416
b72f4eaf 417 Double_t p[2] = { trklt->GetY(), trklt->GetZ()};
418 trklt->GetCovAt(trklt->GetX(), cov);
ed15ef4f 419 return AliExternalTrackParam::GetPredictedChi2(p, cov);
3b57a3f7 420}
d9950a5a 421
eb2b4f91 422//_______________________________________________________________
423Int_t AliTRDtrackV1::GetSector() const
424{
425 return Int_t(GetAlpha()/AliTRDgeometry::GetAlpha() + (GetAlpha()>0. ? 0 : AliTRDgeometry::kNsector));
426}
427
203967fc 428//_______________________________________________________________
429Bool_t AliTRDtrackV1::IsEqual(const TObject *o) const
430{
431 if (!o) return kFALSE;
432 const AliTRDtrackV1 *inTrack = dynamic_cast<const AliTRDtrackV1*>(o);
433 if (!inTrack) return kFALSE;
434
eb2b4f91 435 //if ( fPIDquality != inTrack->GetPIDquality() ) return kFALSE;
203967fc 436
437 for(Int_t i = 0; i < AliPID::kSPECIES; i++){
438 if ( fPID[i] != inTrack->GetPID(i) ) return kFALSE;
439 }
440
441 for (Int_t i = 0; i < 3; i++){
442 if ( fBudget[i] != inTrack->GetBudget(i) ) return kFALSE;
443 }
444 if ( fDE != inTrack->GetEdep() ) return kFALSE;
445 if ( fFakeRatio != inTrack->GetFakeRatio() ) return kFALSE;
446 if ( fChi2 != inTrack->GetChi2() ) return kFALSE;
447 if ( fMass != inTrack->GetMass() ) return kFALSE;
448 if ( fLab != inTrack->GetLabel() ) return kFALSE;
449 if ( fN != inTrack->GetNumberOfClusters() ) return kFALSE;
450 if ( AliKalmanTrack::GetIntegratedLength() != inTrack->GetIntegratedLength() ) return kFALSE;
451
452 if ( GetX() != inTrack->GetX() ) return kFALSE;
453 if ( GetAlpha() != inTrack->GetAlpha() ) return kFALSE;
454 const Double_t *inP = inTrack->GetParameter();
455 const Double_t *curP = GetParameter();
456 for (Int_t i = 0; i < 5; i++){
457 if ( curP[i] != inP[i]) return kFALSE;
458 }
459 const Double_t *inC = inTrack->GetCovariance();
460 const Double_t *curC = GetCovariance();
461 for (Int_t i = 0; i < 15; i++){
462 if ( curC[i] != inC[i]) return kFALSE;
463 }
464
465 for (Int_t iTracklet = 0; iTracklet < kNplane; iTracklet++){
466 AliTRDseedV1 *curTracklet = fTracklet[iTracklet];
467 AliTRDseedV1 *inTracklet = inTrack->GetTracklet(iTracklet);
468 if (curTracklet && inTracklet){
469 if (! curTracklet->IsEqual(inTracklet) ) {
470 curTracklet->Print();
471 inTracklet->Print();
472 return kFALSE;
473 }
474 } else {
475 // if one tracklet exists, and corresponding
476 // in other track doesn't - return kFALSE
477 if(inTracklet || curTracklet) return kFALSE;
478 }
479 }
480
481 return kTRUE;
482}
483
22a4ab0c 484//_______________________________________________________________
485Bool_t AliTRDtrackV1::IsElectron() const
486{
215f7116 487 if(GetPID(0) > fReconstructor->GetRecoParam()->GetPIDThreshold(GetP())) return kTRUE;
22a4ab0c 488 return kFALSE;
489}
490
3b57a3f7 491
492//_____________________________________________________________________________
493void AliTRDtrackV1::MakeBackupTrack()
494{
495 //
496 // Creates a backup track
497 //
498
499 if(fBackupTrack) {
500 fBackupTrack->~AliTRDtrackV1();
501 new(fBackupTrack) AliTRDtrackV1((AliTRDtrackV1&)(*this));
592fdd48 502 return;
3b57a3f7 503 }
504 fBackupTrack = new AliTRDtrackV1((AliTRDtrackV1&)(*this));
d9950a5a 505}
506
3b57a3f7 507//_____________________________________________________________________________
508Int_t AliTRDtrackV1::GetProlongation(Double_t xk, Double_t &y, Double_t &z)
509{
510 //
511 // Find a prolongation at given x
530fb4e2 512 // Return -1 if it does not exist
3b57a3f7 513 //
514
515 Double_t bz = GetBz();
530fb4e2 516 if (!AliExternalTrackParam::GetYAt(xk,bz,y)) return -1;
517 if (!AliExternalTrackParam::GetZAt(xk,bz,z)) return -1;
3b57a3f7 518
519 return 1;
520
521}
522
523//_____________________________________________________________________________
524Bool_t AliTRDtrackV1::PropagateTo(Double_t xk, Double_t xx0, Double_t xrho)
0906e73e 525{
526 //
3b57a3f7 527 // Propagates this track to a reference plane defined by "xk" [cm]
528 // correcting for the mean crossed material.
0906e73e 529 //
3b57a3f7 530 // "xx0" - thickness/rad.length [units of the radiation length]
531 // "xrho" - thickness*density [g/cm^2]
532 //
0906e73e 533
3b57a3f7 534 if (xk == GetX()) {
535 return kTRUE;
536 }
537
538 Double_t oldX = GetX();
539 Double_t oldY = GetY();
540 Double_t oldZ = GetZ();
541
542 Double_t bz = GetBz();
543
544 if (!AliExternalTrackParam::PropagateTo(xk,bz)) {
545 return kFALSE;
546 }
547
548 Double_t x = GetX();
549 Double_t y = GetY();
550 Double_t z = GetZ();
551
552 if (oldX < xk) {
553 xrho = -xrho;
554 if (IsStartedTimeIntegral()) {
555 Double_t l2 = TMath::Sqrt((x-oldX)*(x-oldX)
556 + (y-oldY)*(y-oldY)
557 + (z-oldZ)*(z-oldZ));
558 Double_t crv = AliExternalTrackParam::GetC(bz);
559 if (TMath::Abs(l2*crv) > 0.0001) {
560 // Make correction for curvature if neccesary
561 l2 = 0.5 * TMath::Sqrt((x-oldX)*(x-oldX)
562 + (y-oldY)*(y-oldY));
563 l2 = 2.0 * TMath::ASin(l2 * crv) / crv;
564 l2 = TMath::Sqrt(l2*l2 + (z-oldZ)*(z-oldZ));
565 }
566 AddTimeStep(l2);
567 }
568 }
569
fd40f855 570 if (!AliExternalTrackParam::CorrectForMeanMaterial(xx0, xrho, GetMass())) return kFALSE;
571
3b57a3f7 572
573 {
574
575 // Energy losses
576 Double_t p2 = (1.0 + GetTgl()*GetTgl()) / (GetSigned1Pt()*GetSigned1Pt());
577 Double_t beta2 = p2 / (p2 + GetMass()*GetMass());
578 if ((beta2 < 1.0e-10) ||
579 ((5940.0 * beta2/(1.0 - beta2 + 1.0e-10) - beta2) < 0.0)) {
580 return kFALSE;
581 }
582
583 Double_t dE = 0.153e-3 / beta2
584 * (TMath::Log(5940.0 * beta2/(1.0 - beta2 + 1.0e-10)) - beta2)
585 * xrho;
586 fBudget[0] += xrho;
587
588 /*
589 // Suspicious part - think about it ?
590 Double_t kinE = TMath::Sqrt(p2);
591 if (dE > 0.8*kinE) dE = 0.8 * kinE; //
592 if (dE < 0) dE = 0.0; // Not valid region for Bethe bloch
593 */
594
595 fDE += dE;
596
597 /*
598 // Suspicious ! I.B.
599 Double_t sigmade = 0.07 * TMath::Sqrt(TMath::Abs(dE)); // Energy loss fluctuation
600 Double_t sigmac2 = sigmade*sigmade*fC*fC*(p2+GetMass()*GetMass())/(p2*p2);
601 fCcc += sigmac2;
602 fCee += fX*fX * sigmac2;
603 */
604
605 }
606
607 return kTRUE;
0906e73e 608}
3b57a3f7 609
87a7fa94 610//_____________________________________________________________________________
3b57a3f7 611Int_t AliTRDtrackV1::PropagateToR(Double_t r,Double_t step)
87a7fa94 612{
613 //
3b57a3f7 614 // Propagate track to the radial position
615 // Rotation always connected to the last track position
87a7fa94 616 //
617
3b57a3f7 618 Double_t xyz0[3];
619 Double_t xyz1[3];
620 Double_t y;
621 Double_t z;
622
623 Double_t radius = TMath::Sqrt(GetX()*GetX() + GetY()*GetY());
624 // Direction +-
625 Double_t dir = (radius > r) ? -1.0 : 1.0;
626
627 for (Double_t x = radius+dir*step; dir*x < dir*r; x += dir*step) {
628
629 GetXYZ(xyz0);
630 Double_t alpha = TMath::ATan2(xyz0[1],xyz0[0]);
631 Rotate(alpha,kTRUE);
632 GetXYZ(xyz0);
e20bef2b 633 if(GetProlongation(x,y,z)<0) return -1;
3b57a3f7 634 xyz1[0] = x * TMath::Cos(alpha) + y * TMath::Sin(alpha);
635 xyz1[1] = x * TMath::Sin(alpha) - y * TMath::Cos(alpha);
636 xyz1[2] = z;
637 Double_t param[7];
83dea92e 638 if(AliTracker::MeanMaterialBudget(xyz0,xyz1,param)<=0.) return -1;
3b57a3f7 639 if (param[1] <= 0) {
640 param[1] = 100000000;
641 }
642 PropagateTo(x,param[1],param[0]*param[4]);
643
644 }
645
646 GetXYZ(xyz0);
647 Double_t alpha = TMath::ATan2(xyz0[1],xyz0[0]);
648 Rotate(alpha,kTRUE);
649 GetXYZ(xyz0);
530fb4e2 650 if(GetProlongation(r,y,z)<0) return -1;
3b57a3f7 651 xyz1[0] = r * TMath::Cos(alpha) + y * TMath::Sin(alpha);
652 xyz1[1] = r * TMath::Sin(alpha) - y * TMath::Cos(alpha);
653 xyz1[2] = z;
654 Double_t param[7];
83dea92e 655 if(AliTracker::MeanMaterialBudget(xyz0,xyz1,param) <= 0.) return -1;
3b57a3f7 656
657 if (param[1] <= 0) {
658 param[1] = 100000000;
87a7fa94 659 }
3b57a3f7 660 PropagateTo(r,param[1],param[0]*param[4]);
661
662 return 0;
663
87a7fa94 664}
665
203967fc 666//_____________________________________________________________________________
667void AliTRDtrackV1::Print(Option_t *o) const
668{
eb2b4f91 669 AliInfo(Form("PID [%4.1f %4.1f %4.1f %4.1f %4.1f]", 1.E2*fPID[0], 1.E2*fPID[1], 1.E2*fPID[2], 1.E2*fPID[3], 1.E2*fPID[4]));
203967fc 670 AliInfo(Form("Material[%5.2f %5.2f %5.2f]", fBudget[0], fBudget[1], fBudget[2]));
671
672 AliInfo(Form("x[%7.2f] t[%7.4f] alpha[%f] mass[%f]", GetX(), GetIntegratedLength(), GetAlpha(), fMass));
eb2b4f91 673 AliInfo(Form("Ntr[%1d] NtrPID[%1d] Ncl[%3d] lab[%3d]", GetNumberOfTracklets(), GetNumberOfTrackletsPID(), fN, fLab));
203967fc 674
675 if(strcmp(o, "a")!=0) return;
676 printf("|X| = (");
677 const Double_t *curP = GetParameter();
678 for (Int_t i = 0; i < 5; i++) printf("%7.2f ", curP[i]);
679 printf(")\n");
680
681 printf("|V| = \n");
682 const Double_t *curC = GetCovariance();
683 for (Int_t i = 0, j=4, k=0; i<15; i++, k++){
684 printf("%7.2f ", curC[i]);
685 if(k==j){
686 printf("\n");
687 k=-1; j--;
688 }
689 }
690
691 for(Int_t ip=0; ip<kNplane; ip++){
692 if(!fTracklet[ip]) continue;
693 fTracklet[ip]->Print(o);
694 }
695}
696
697
3b57a3f7 698//_____________________________________________________________________________
699Bool_t AliTRDtrackV1::Rotate(Double_t alpha, Bool_t absolute)
700{
701 //
702 // Rotates track parameters in R*phi plane
703 // if absolute rotation alpha is in global system
704 // otherwise alpha rotation is relative to the current rotation angle
705 //
706
707 if (absolute) alpha -= GetAlpha();
708 //else fNRotate++;
709
710 return AliExternalTrackParam::Rotate(GetAlpha()+alpha);
711}
87a7fa94 712
eb38ed55 713//___________________________________________________________
714void AliTRDtrackV1::SetNumberOfClusters()
715{
716// Calculate the number of clusters attached to this track
717
3b57a3f7 718 Int_t ncls = 0;
719 for(int ip=0; ip<kNplane; ip++){
720 if(fTracklet[ip] && fTrackletIndex[ip] != 0xffff) ncls += fTracklet[ip]->GetN();
721 }
722 AliKalmanTrack::SetNumberOfClusters(ncls);
eb38ed55 723}
724
725
0906e73e 726//_______________________________________________________________
3b57a3f7 727void AliTRDtrackV1::SetOwner()
0906e73e 728{
729 //
730 // Toggle ownership of tracklets
731 //
732
e44586fb 733 if(TestBit(kOwner)) return;
3b57a3f7 734 for (Int_t ip = 0; ip < kNplane; ip++) {
735 if(fTrackletIndex[ip] == 0xffff) continue;
736 fTracklet[ip] = new AliTRDseedV1(*fTracklet[ip]);
737 fTracklet[ip]->SetOwner();
738 }
e44586fb 739 SetBit(kOwner);
0906e73e 740}
741
d9950a5a 742//_______________________________________________________________
3b57a3f7 743void AliTRDtrackV1::SetTracklet(AliTRDseedV1 *trklt, Int_t index)
d9950a5a 744{
745 //
0906e73e 746 // Set the tracklets
d9950a5a 747 //
3b57a3f7 748 Int_t plane = trklt->GetPlane();
76b60503 749
3b57a3f7 750 fTracklet[plane] = trklt;
751 fTrackletIndex[plane] = index;
d9950a5a 752}
753
e3cf3d02 754//_______________________________________________________________
755void AliTRDtrackV1::SetTrackLow()
756{
757 const AliExternalTrackParam *op = dynamic_cast<const AliExternalTrackParam*>(this);
758 fTrackLow = fTrackLow ? new(fTrackLow) AliExternalTrackParam(*op) : new AliExternalTrackParam(*op);
759}
760
761//_______________________________________________________________
762void AliTRDtrackV1::SetTrackHigh(const AliExternalTrackParam *op)
763{
764 if(!op) op = dynamic_cast<const AliExternalTrackParam*>(this);
765 fTrackHigh = fTrackHigh ? new(fTrackHigh) AliExternalTrackParam(*op) : new AliExternalTrackParam(*op);
766}
767
181d2c97 768//_______________________________________________________________
769void AliTRDtrackV1::UnsetTracklet(Int_t plane)
770{
771 if(plane<0 && plane >= kNplane) return;
772 fTrackletIndex[plane] = 0xffff;
773 fTracklet[plane] = 0x0;
774}
775
776
d9950a5a 777//_______________________________________________________________
b72f4eaf 778Bool_t AliTRDtrackV1::Update(Double_t *p, Double_t *cov, Double_t chi2)
d9950a5a 779{
780 //
b72f4eaf 781 // Update track
d9950a5a 782 //
d9950a5a 783 if(!AliExternalTrackParam::Update(p, cov)) return kFALSE;
b1957d3c 784
d9950a5a 785 // Register info to track
3b57a3f7 786 SetNumberOfClusters();
b72f4eaf 787 SetChi2(GetChi2() + chi2);
3b57a3f7 788 return kTRUE;
d9950a5a 789}
790
791//_______________________________________________________________
0906e73e 792void AliTRDtrackV1::UpdateESDtrack(AliESDtrack *track)
d9950a5a 793{
794 //
6984f7c1 795 // Update the TRD PID information in the ESD track
d9950a5a 796 //
6984f7c1 797
0d83b3a5 798 Int_t nslices = fReconstructor->IsEightSlices() ? (Int_t)AliTRDpidUtil::kNNslices : (Int_t)AliTRDpidUtil::kLQslices;
e20bef2b 799 // number of tracklets used for PID calculation
800 UChar_t nPID = GetNumberOfTrackletsPID();
801 // number of tracklets attached to the track
802 UChar_t nTrk = GetNumberOfTracklets();
803 // pack the two numbers together and store them in the ESD
804 track->SetTRDntracklets(nPID | (nTrk<<3));
805 // allocate space to store raw PID signals dEdx & momentum
b48e9cbb 806 track->SetNumberOfTRDslices((nslices+2)*AliTRDgeometry::kNlayer);
e20bef2b 807 // store raw signals
7b23a4e1 808 Float_t p, sp; Double_t spd;
6984f7c1 809 for (Int_t ip = 0; ip < kNplane; ip++) {
3b57a3f7 810 if(fTrackletIndex[ip] == 0xffff) continue;
e20bef2b 811 if(!fTracklet[ip]->HasPID()) continue;
3b57a3f7 812 Float_t *dedx = fTracklet[ip]->GetdEdx();
215f7116 813 for (Int_t js = 0; js < nslices; js++, dedx++) track->SetTRDslice(*dedx, ip, js);
7b23a4e1 814 p = fTracklet[ip]->GetMomentum(&sp); spd = sp;
815 track->SetTRDmomentum(p, ip, &spd);
6984f7c1 816 }
e20bef2b 817 // store PID probabilities
818 track->SetTRDpid(fPID);
d9950a5a 819}