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