1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliESDtrack.h"
19 #include "AliTracker.h"
21 #include "AliTRDtrackV1.h"
22 #include "AliTRDcluster.h"
23 #include "AliTRDcalibDB.h"
24 #include "AliTRDReconstructor.h"
25 #include "AliTRDrecoParam.h"
27 ClassImp(AliTRDtrackV1)
29 ///////////////////////////////////////////////////////////////////////////////
31 // Represents a reconstructed TRD track //
32 // Local TRD Kalman track //
35 // Alex Bercuci <A.Bercuci@gsi.de> //
36 // Markus Fasel <M.Fasel@gsi.de> //
38 ///////////////////////////////////////////////////////////////////////////////
40 //_______________________________________________________________
41 AliTRDtrackV1::AliTRDtrackV1() : AliKalmanTrack()
47 // Default constructor
49 //printf("AliTRDtrackV1::AliTRDtrackV1()\n");
51 for(int i =0; i<3; i++) fBudget[i] = 0.;
53 Float_t pid = 1./AliPID::kSPECIES;
54 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
56 for(int ip=0; ip<kNplane; ip++){
57 fTrackletIndex[ip] = 0xffff;
62 //_______________________________________________________________
63 AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &ref) : AliKalmanTrack(ref)
64 ,fPIDquality(ref.fPIDquality)
72 //printf("AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &)\n");
73 SetBit(kOwner, kFALSE);
74 for(int ip=0; ip<kNplane; ip++){
75 fTrackletIndex[ip] = ref.fTrackletIndex[ip];
76 fTracklet[ip] = ref.fTracklet[ip];
79 for (Int_t i = 0; i < 3;i++) fBudget[i] = ref.fBudget[i];
81 for(Int_t is = 0; is<AliPID::kSPECIES; is++) fPID[is] = ref.fPID[is];
83 AliKalmanTrack::SetNumberOfClusters(ref.GetNumberOfClusters());
86 //_______________________________________________________________
87 AliTRDtrackV1::AliTRDtrackV1(const AliESDtrack &t) : AliKalmanTrack()
93 // Constructor from AliESDtrack
96 SetLabel(t.GetLabel());
99 AliKalmanTrack::SetNumberOfClusters(t.GetTRDncls());
100 Int_t ti[kNplane]; t.GetTRDtracklets(&ti[0]);
101 for(int ip=0; ip<kNplane; ip++){
102 fTrackletIndex[ip] = ti[ip] < 0 ? 0xffff : ti[ip];
105 for(int i =0; i<3; i++) fBudget[i] = 0.;
107 Float_t pid = 1./AliPID::kSPECIES;
108 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
110 const AliExternalTrackParam *par = &t;
111 if (t.GetStatus() & AliESDtrack::kTRDbackup) {
112 par = t.GetOuterParam();
114 AliError("No backup info!");
121 ,par->GetCovariance());
123 if(t.GetStatus() & AliESDtrack::kTIME) {
126 t.GetIntegratedTimes(times);
127 SetIntegratedTimes(times);
128 SetIntegratedLength(t.GetIntegratedLength());
132 //_______________________________________________________________
133 AliTRDtrackV1::AliTRDtrackV1(AliTRDseedV1 *trklts, const Double_t p[5], const Double_t cov[15]
134 , Double_t x, Double_t alpha) : AliKalmanTrack()
140 // The stand alone tracking constructor
141 // TEMPORARY !!!!!!!!!!!
143 // 1. covariance matrix
144 // 2. dQdl calculation
147 Double_t cnv = GetBz() < 1.e-5 ? 1.e5 : 1.0 / (GetBz() * kB2C);
148 // Double_t cnv = 1.0 / (GetBz() * kB2C);
150 Double_t pp[5] = { p[0]
156 Double_t c22 = x*x*cov[14] - 2*x*cov[12] + cov[ 5];
157 Double_t c32 = x*cov[13] - cov[ 8];
158 Double_t c20 = x*cov[10] - cov[ 3];
159 Double_t c21 = x*cov[11] - cov[ 4];
160 Double_t c42 = x*cov[14] - cov[12];
162 Double_t cc[15] = { cov[ 0]
165 , cov[ 6], cov[ 7], c32, cov[ 9]
166 , cov[10]*cnv, cov[11]*cnv, c42*cnv, cov[13]*cnv, cov[14]*cnv*cnv };
168 Double_t mostProbablePt=AliExternalTrackParam::GetMostProbablePt();
169 Double_t p0=TMath::Sign(1/mostProbablePt,pp[4]);
170 Double_t w0=cc[14]/(cc[14] + p0*p0), w1=p0*p0/(cc[14] + p0*p0);
171 pp[4] = w0*p0 + w1*pp[4];
172 cc[10]*=w1; cc[11]*=w1; cc[12]*=w1; cc[13]*=w1; cc[14]*=w1;
176 for(int iplane=0; iplane<kNplane; iplane++){
177 fTrackletIndex[iplane] = 0xffff;
178 if(!trklts[iplane].IsOK()) fTracklet[iplane] = 0x0;
180 fTracklet[iplane] = &trklts[iplane];
181 ncls += fTracklet[iplane]->GetN();
184 AliKalmanTrack::SetNumberOfClusters(ncls);
185 for(int i =0; i<3; i++) fBudget[i] = 0.;
187 Float_t pid = 1./AliPID::kSPECIES;
188 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
192 //_______________________________________________________________
193 AliTRDtrackV1::~AliTRDtrackV1()
196 //printf("I-AliTRDtrackV1::~AliTRDtrackV1() : Owner[%s]\n", TestBit(kOwner)?"YES":"NO");
198 if(fBackupTrack) delete fBackupTrack;
201 for(Int_t ip=0; ip<kNplane; ip++){
202 if(TestBit(kOwner) && fTracklet[ip]) delete fTracklet[ip];
204 fTrackletIndex[ip] = 0xffff;
208 //_______________________________________________________________
209 Bool_t AliTRDtrackV1::CookLabel(Float_t wrong)
211 // set MC label for this track
213 Int_t s[kMAXCLUSTERSPERTRACK][2];
214 for (Int_t i = 0; i < kMAXCLUSTERSPERTRACK; i++) {
221 AliTRDcluster *c = 0x0;
222 for (Int_t ip = 0; ip < kNplane; ip++) {
223 if(fTrackletIndex[ip] == 0xffff) continue;
224 for (Int_t ic = 0; ic < AliTRDseed::knTimebins; ic++) {
225 if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
226 for (Int_t k = 0; k < 3; k++) {
227 label = c->GetLabel(k);
231 while ((!labelAdded) && (j < kMAXCLUSTERSPERTRACK)) {
232 if ((s[j][0] == label) ||
247 for (Int_t i = 0; i < kMAXCLUSTERSPERTRACK; i++) {
248 if (s[i][1] <= max) continue;
253 if ((1. - Float_t(max)/GetNumberOfClusters()) > wrong) label = -label;
260 //_______________________________________________________________
261 Bool_t AliTRDtrackV1::CookPID()
264 // Cook the PID information
267 // Reset the a priori probabilities
268 Double_t pid = 1. / AliPID::kSPECIES;
269 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) {
274 // steer PID calculation @ tracklet level
275 Double_t *prob = 0x0;
276 for(int ip=0; ip<kNplane; ip++){
277 if(fTrackletIndex[ip] == 0xffff) continue;
278 if(!fTracklet[ip]->IsOK()) continue;
279 if(!(prob = fTracklet[ip]->GetProbability())) return kFALSE;
281 Int_t nspec = 0; // quality check of tracklet dEdx
282 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++){
283 if(prob[ispec] < 0.) continue;
284 fPID[ispec] *= prob[ispec];
292 // no tracklet found for PID calculations
293 if(!fPIDquality) return kTRUE;
295 // slot for PID calculation @ track level
298 // normalize probabilities
299 Double_t probTotal = 0.0;
300 for (Int_t is = 0; is < AliPID::kSPECIES; is++) probTotal += fPID[is];
303 if (probTotal <= 0.0) {
304 AliWarning("The total probability over all species <= 0. This may be caused by some error in the reference data.");
308 for (Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++) fPID[iSpecies] /= probTotal;
313 //_____________________________________________________________________________
314 Double_t AliTRDtrackV1::GetBz() const
317 // Returns Bz component of the magnetic field (kG)
320 if (AliTracker::UniformField()) return AliTracker::GetBz();
324 return AliTracker::GetBz(r);
327 //_______________________________________________________________
328 Int_t AliTRDtrackV1::GetClusterIndex(Int_t id) const
331 for(Int_t ip=0; ip<kNplane; ip++){
332 if(!fTracklet[ip]) continue;
333 if(n+fTracklet[ip]->GetN() <= id){
334 n+=fTracklet[ip]->GetN();
337 AliTRDcluster *c = 0x0;
338 for(Int_t ic=AliTRDseed::knTimebins-1; ic>=0; ic--){
339 if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
341 if(n<id){n++; continue;}
342 return fTracklet[ip]->GetIndexes(ic);
348 //_______________________________________________________________
349 Double_t AliTRDtrackV1::GetPredictedChi2(const AliTRDseedV1 *trklt) const
352 // Get the predicted chi2
355 Double_t x = trklt->GetX0();
356 Double_t p[2] = { trklt->GetYat(x)
357 , trklt->GetZat(x) };
359 trklt->GetCovAt(x, cov);
361 return AliExternalTrackParam::GetPredictedChi2(p, cov);
365 //_____________________________________________________________________________
366 void AliTRDtrackV1::MakeBackupTrack()
369 // Creates a backup track
373 fBackupTrack->~AliTRDtrackV1();
374 new(fBackupTrack) AliTRDtrackV1((AliTRDtrackV1&)(*this));
377 fBackupTrack = new AliTRDtrackV1((AliTRDtrackV1&)(*this));
380 //_____________________________________________________________________________
381 Int_t AliTRDtrackV1::GetProlongation(Double_t xk, Double_t &y, Double_t &z)
384 // Find a prolongation at given x
385 // Return 0 if it does not exist
388 Double_t bz = GetBz();
389 if (!AliExternalTrackParam::GetYAt(xk,bz,y)) return 0;
390 if (!AliExternalTrackParam::GetZAt(xk,bz,z)) return 0;
396 //_____________________________________________________________________________
397 Bool_t AliTRDtrackV1::PropagateTo(Double_t xk, Double_t xx0, Double_t xrho)
400 // Propagates this track to a reference plane defined by "xk" [cm]
401 // correcting for the mean crossed material.
403 // "xx0" - thickness/rad.length [units of the radiation length]
404 // "xrho" - thickness*density [g/cm^2]
411 Double_t oldX = GetX();
412 Double_t oldY = GetY();
413 Double_t oldZ = GetZ();
415 Double_t bz = GetBz();
417 if (!AliExternalTrackParam::PropagateTo(xk,bz)) {
427 if (IsStartedTimeIntegral()) {
428 Double_t l2 = TMath::Sqrt((x-oldX)*(x-oldX)
430 + (z-oldZ)*(z-oldZ));
431 Double_t crv = AliExternalTrackParam::GetC(bz);
432 if (TMath::Abs(l2*crv) > 0.0001) {
433 // Make correction for curvature if neccesary
434 l2 = 0.5 * TMath::Sqrt((x-oldX)*(x-oldX)
435 + (y-oldY)*(y-oldY));
436 l2 = 2.0 * TMath::ASin(l2 * crv) / crv;
437 l2 = TMath::Sqrt(l2*l2 + (z-oldZ)*(z-oldZ));
443 if (!AliExternalTrackParam::CorrectForMeanMaterial(xx0,xrho,GetMass())) {
450 Double_t p2 = (1.0 + GetTgl()*GetTgl()) / (GetSigned1Pt()*GetSigned1Pt());
451 Double_t beta2 = p2 / (p2 + GetMass()*GetMass());
452 if ((beta2 < 1.0e-10) ||
453 ((5940.0 * beta2/(1.0 - beta2 + 1.0e-10) - beta2) < 0.0)) {
457 Double_t dE = 0.153e-3 / beta2
458 * (TMath::Log(5940.0 * beta2/(1.0 - beta2 + 1.0e-10)) - beta2)
463 // Suspicious part - think about it ?
464 Double_t kinE = TMath::Sqrt(p2);
465 if (dE > 0.8*kinE) dE = 0.8 * kinE; //
466 if (dE < 0) dE = 0.0; // Not valid region for Bethe bloch
473 Double_t sigmade = 0.07 * TMath::Sqrt(TMath::Abs(dE)); // Energy loss fluctuation
474 Double_t sigmac2 = sigmade*sigmade*fC*fC*(p2+GetMass()*GetMass())/(p2*p2);
476 fCee += fX*fX * sigmac2;
484 //_____________________________________________________________________________
485 Int_t AliTRDtrackV1::PropagateToR(Double_t r,Double_t step)
488 // Propagate track to the radial position
489 // Rotation always connected to the last track position
497 Double_t radius = TMath::Sqrt(GetX()*GetX() + GetY()*GetY());
499 Double_t dir = (radius > r) ? -1.0 : 1.0;
501 for (Double_t x = radius+dir*step; dir*x < dir*r; x += dir*step) {
504 Double_t alpha = TMath::ATan2(xyz0[1],xyz0[0]);
507 GetProlongation(x,y,z);
508 xyz1[0] = x * TMath::Cos(alpha) + y * TMath::Sin(alpha);
509 xyz1[1] = x * TMath::Sin(alpha) - y * TMath::Cos(alpha);
512 AliTracker::MeanMaterialBudget(xyz0,xyz1,param);
514 param[1] = 100000000;
516 PropagateTo(x,param[1],param[0]*param[4]);
521 Double_t alpha = TMath::ATan2(xyz0[1],xyz0[0]);
524 GetProlongation(r,y,z);
525 xyz1[0] = r * TMath::Cos(alpha) + y * TMath::Sin(alpha);
526 xyz1[1] = r * TMath::Sin(alpha) - y * TMath::Cos(alpha);
529 AliTracker::MeanMaterialBudget(xyz0,xyz1,param);
532 param[1] = 100000000;
534 PropagateTo(r,param[1],param[0]*param[4]);
540 //_____________________________________________________________________________
541 Bool_t AliTRDtrackV1::Rotate(Double_t alpha, Bool_t absolute)
544 // Rotates track parameters in R*phi plane
545 // if absolute rotation alpha is in global system
546 // otherwise alpha rotation is relative to the current rotation angle
549 if (absolute) alpha -= GetAlpha();
552 return AliExternalTrackParam::Rotate(GetAlpha()+alpha);
555 //___________________________________________________________
556 void AliTRDtrackV1::SetNumberOfClusters()
558 // Calculate the number of clusters attached to this track
561 for(int ip=0; ip<kNplane; ip++){
562 if(fTracklet[ip] && fTrackletIndex[ip] != 0xffff) ncls += fTracklet[ip]->GetN();
564 AliKalmanTrack::SetNumberOfClusters(ncls);
568 //_______________________________________________________________
569 void AliTRDtrackV1::SetOwner()
572 // Toggle ownership of tracklets
575 if(TestBit(kOwner)) return;
576 for (Int_t ip = 0; ip < kNplane; ip++) {
577 if(fTrackletIndex[ip] == 0xffff) continue;
578 fTracklet[ip] = new AliTRDseedV1(*fTracklet[ip]);
579 fTracklet[ip]->SetOwner();
584 //_______________________________________________________________
585 void AliTRDtrackV1::SetTracklet(AliTRDseedV1 *trklt, Int_t index)
590 Int_t plane = trklt->GetPlane();
592 fTracklet[plane] = trklt;
593 fTrackletIndex[plane] = index;
596 //_______________________________________________________________
597 void AliTRDtrackV1::UnsetTracklet(Int_t plane)
599 if(plane<0 && plane >= kNplane) return;
600 fTrackletIndex[plane] = 0xffff;
601 fTracklet[plane] = 0x0;
605 //_______________________________________________________________
606 Bool_t AliTRDtrackV1::Update(AliTRDseedV1 *trklt, Double_t chisq)
609 // Update track and tracklet parameters
612 Double_t x = trklt->GetX0();
613 Double_t p[2] = { trklt->GetYat(x)
614 , trklt->GetZat(x) };
616 trklt->GetCovAt(x, cov);
618 if(!AliExternalTrackParam::Update(p, cov)) return kFALSE;
620 AliTRDcluster *c = 0x0;
621 Int_t ic = 0; while(!(c = trklt->GetClusters(ic))) ic++;
622 AliTracker::FillResiduals(this, p, cov, c->GetVolumeId());
625 // Register info to track
626 SetNumberOfClusters();
627 SetChi2(GetChi2() + chisq);
630 trklt->SetMomentum(GetP());
631 trklt->SetSnp(GetSnp());
632 trklt->SetTgl(GetTgl());
636 //_______________________________________________________________
637 void AliTRDtrackV1::UpdateESDtrack(AliESDtrack *track)
640 // Update the TRD PID information in the ESD track
643 track->SetNumberOfTRDslices(kNslice);
645 for (Int_t ip = 0; ip < kNplane; ip++) {
646 if(fTrackletIndex[ip] == 0xffff) continue;
647 fTracklet[ip]->CookdEdx(kNslice);
648 Float_t *dedx = fTracklet[ip]->GetdEdx();
649 for (Int_t js = 0; js < kNslice; js++) track->SetTRDslice(dedx[js], ip, js);
653 if(!fPIDquality) return;
654 track->SetTRDpid(fPID);
655 track->SetTRDpidQuality(fPIDquality);