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 for(int i =0; i<3; i++) fBudget[i] = 0.;
51 Float_t pid = 1./AliPID::kSPECIES;
52 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
54 for(int ip=0; ip<kNplane; ip++){
55 fTrackletIndex[ip] = 0xffff;
60 //_______________________________________________________________
61 AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &ref) : AliKalmanTrack(ref)
62 ,fPIDquality(ref.fPIDquality)
70 for(int ip=0; ip<kNplane; ip++){
71 fTrackletIndex[ip] = ref.fTrackletIndex[ip];
72 fTracklet[ip] = ref.fTracklet[ip];
75 for (Int_t i = 0; i < 3;i++) fBudget[i] = ref.fBudget[i];
77 for(Int_t is = 0; is<AliPID::kSPECIES; is++) fPID[is] = ref.fPID[is];
79 AliKalmanTrack::SetNumberOfClusters(ref.GetNumberOfClusters());
82 //_______________________________________________________________
83 AliTRDtrackV1::AliTRDtrackV1(const AliESDtrack &t) : AliKalmanTrack()
89 // Constructor from AliESDtrack
92 SetLabel(t.GetLabel());
95 AliKalmanTrack::SetNumberOfClusters(t.GetTRDncls());
96 Int_t ti[kNplane]; t.GetTRDtracklets(&ti[0]);
97 for(int ip=0; ip<kNplane; ip++){
98 fTrackletIndex[ip] = ti[ip] < 0 ? 0xffff : ti[ip];
101 for(int i =0; i<3; i++) fBudget[i] = 0.;
103 Float_t pid = 1./AliPID::kSPECIES;
104 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
106 const AliExternalTrackParam *par = &t;
107 if (t.GetStatus() & AliESDtrack::kTRDbackup) {
108 par = t.GetOuterParam();
110 AliError("No backup info!");
117 ,par->GetCovariance());
119 if(t.GetStatus() & AliESDtrack::kTIME) {
122 t.GetIntegratedTimes(times);
123 SetIntegratedTimes(times);
124 SetIntegratedLength(t.GetIntegratedLength());
128 //_______________________________________________________________
129 AliTRDtrackV1::AliTRDtrackV1(AliTRDseedV1 *trklts, const Double_t p[5], const Double_t cov[15]
130 , Double_t x, Double_t alpha) : AliKalmanTrack()
136 // The stand alone tracking constructor
137 // TEMPORARY !!!!!!!!!!!
139 // 1. covariance matrix
140 // 2. dQdl calculation
143 Double_t cnv = GetBz() < 1.e-5 ? 1.e5 : 1.0 / (GetBz() * kB2C);
144 // Double_t cnv = 1.0 / (GetBz() * kB2C);
146 Double_t pp[5] = { p[0]
152 Double_t c22 = x*x*cov[14] - 2*x*cov[12] + cov[ 5];
153 Double_t c32 = x*cov[13] - cov[ 8];
154 Double_t c20 = x*cov[10] - cov[ 3];
155 Double_t c21 = x*cov[11] - cov[ 4];
156 Double_t c42 = x*cov[14] - cov[12];
158 Double_t cc[15] = { cov[ 0]
161 , cov[ 6], cov[ 7], c32, cov[ 9]
162 , cov[10]*cnv, cov[11]*cnv, c42*cnv, cov[13]*cnv, cov[14]*cnv*cnv };
164 Double_t mostProbablePt=AliExternalTrackParam::GetMostProbablePt();
165 Double_t p0=TMath::Sign(1/mostProbablePt,pp[4]);
166 Double_t w0=cc[14]/(cc[14] + p0*p0), w1=p0*p0/(cc[14] + p0*p0);
167 pp[4] = w0*p0 + w1*pp[4];
168 cc[10]*=w1; cc[11]*=w1; cc[12]*=w1; cc[13]*=w1; cc[14]*=w1;
172 for(int iplane=0; iplane<kNplane; iplane++){
173 fTrackletIndex[iplane] = 0xffff;
174 if(!trklts[iplane].IsOK()) fTracklet[iplane] = 0x0;
176 fTracklet[iplane] = new AliTRDseedV1(trklts[iplane]);
177 ncls += fTracklet[iplane]->GetN();
180 AliKalmanTrack::SetNumberOfClusters(ncls);
181 for(int i =0; i<3; i++) fBudget[i] = 0.;
183 Float_t pid = 1./AliPID::kSPECIES;
184 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
188 //_______________________________________________________________
189 AliTRDtrackV1::~AliTRDtrackV1()
197 for(Int_t ip=0; ip<kNplane; ip++){
198 if(fTracklet[ip]) delete fTracklet[ip];
204 //_______________________________________________________________
205 Bool_t AliTRDtrackV1::CookLabel(Float_t wrong)
207 // set MC label for this track
209 Int_t s[kMAXCLUSTERSPERTRACK][2];
210 for (Int_t i = 0; i < kMAXCLUSTERSPERTRACK; i++) {
217 AliTRDcluster *c = 0x0;
218 for (Int_t ip = 0; ip < kNplane; ip++) {
219 if(fTrackletIndex[ip] == 0xffff) continue;
220 for (Int_t ic = 0; ic < AliTRDseed::knTimebins; ic++) {
221 if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
222 for (Int_t k = 0; k < 3; k++) {
223 label = c->GetLabel(k);
227 while ((!labelAdded) && (j < kMAXCLUSTERSPERTRACK)) {
228 if ((s[j][0] == label) ||
243 for (Int_t i = 0; i < kMAXCLUSTERSPERTRACK; i++) {
244 if (s[i][1] <= max) continue;
249 if ((1. - Float_t(max)/GetNumberOfClusters()) > wrong) label = -label;
256 //_______________________________________________________________
257 Bool_t AliTRDtrackV1::CookPID()
260 // Cook the PID information
263 // Reset the a priori probabilities
264 Double_t pid = 1. / AliPID::kSPECIES;
265 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) {
270 // steer PID calculation @ tracklet level
271 Double_t *prob = 0x0;
272 for(int ip=0; ip<kNplane; ip++){
273 if(fTrackletIndex[ip] == 0xffff) continue;
274 if(!fTracklet[ip]->IsOK()) continue;
275 if(!(prob = fTracklet[ip]->GetProbability())) return kFALSE;
277 Int_t nspec = 0; // quality check of tracklet dEdx
278 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++){
279 if(prob[ispec] < 0.) continue;
280 fPID[ispec] *= prob[ispec];
288 // no tracklet found for PID calculations
289 if(!fPIDquality) return kTRUE;
291 // slot for PID calculation @ track level
294 // normalize probabilities
295 Double_t probTotal = 0.0;
296 for (Int_t is = 0; is < AliPID::kSPECIES; is++) probTotal += fPID[is];
299 if (probTotal <= 0.0) {
300 AliWarning("The total probability over all species <= 0. This may be caused by some error in the reference data.");
304 for (Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++) fPID[iSpecies] /= probTotal;
309 //_____________________________________________________________________________
310 Double_t AliTRDtrackV1::GetBz() const
313 // Returns Bz component of the magnetic field (kG)
316 if (AliTracker::UniformField()) return AliTracker::GetBz();
320 return AliTracker::GetBz(r);
323 //_______________________________________________________________
324 Int_t AliTRDtrackV1::GetClusterIndex(Int_t id) const
327 for(Int_t ip=0; ip<kNplane; ip++){
328 if(!fTracklet[ip]) continue;
329 if(n+fTracklet[ip]->GetN() < id){
330 n+=fTracklet[ip]->GetN();
333 for(Int_t ic=34; ic>=0; ic--){
334 if(!fTracklet[ip]->GetClusters(ic)) continue;
337 return fTracklet[ip]->GetIndexes(ic);
343 //_______________________________________________________________
344 Double_t AliTRDtrackV1::GetPredictedChi2(const AliTRDseedV1 *trklt) const
347 // Get the predicted chi2
350 Double_t x = trklt->GetX0();
351 Double_t p[2] = { trklt->GetYat(x)
352 , trklt->GetZat(x) };
354 trklt->GetCovAt(x, cov);
356 return AliExternalTrackParam::GetPredictedChi2(p, cov);
360 //_____________________________________________________________________________
361 void AliTRDtrackV1::MakeBackupTrack()
364 // Creates a backup track
368 fBackupTrack->~AliTRDtrackV1();
369 new(fBackupTrack) AliTRDtrackV1((AliTRDtrackV1&)(*this));
372 fBackupTrack = new AliTRDtrackV1((AliTRDtrackV1&)(*this));
375 //_____________________________________________________________________________
376 Int_t AliTRDtrackV1::GetProlongation(Double_t xk, Double_t &y, Double_t &z)
379 // Find a prolongation at given x
380 // Return 0 if it does not exist
383 Double_t bz = GetBz();
384 if (!AliExternalTrackParam::GetYAt(xk,bz,y)) return 0;
385 if (!AliExternalTrackParam::GetZAt(xk,bz,z)) return 0;
391 //_____________________________________________________________________________
392 Bool_t AliTRDtrackV1::PropagateTo(Double_t xk, Double_t xx0, Double_t xrho)
395 // Propagates this track to a reference plane defined by "xk" [cm]
396 // correcting for the mean crossed material.
398 // "xx0" - thickness/rad.length [units of the radiation length]
399 // "xrho" - thickness*density [g/cm^2]
406 Double_t oldX = GetX();
407 Double_t oldY = GetY();
408 Double_t oldZ = GetZ();
410 Double_t bz = GetBz();
412 if (!AliExternalTrackParam::PropagateTo(xk,bz)) {
422 if (IsStartedTimeIntegral()) {
423 Double_t l2 = TMath::Sqrt((x-oldX)*(x-oldX)
425 + (z-oldZ)*(z-oldZ));
426 Double_t crv = AliExternalTrackParam::GetC(bz);
427 if (TMath::Abs(l2*crv) > 0.0001) {
428 // Make correction for curvature if neccesary
429 l2 = 0.5 * TMath::Sqrt((x-oldX)*(x-oldX)
430 + (y-oldY)*(y-oldY));
431 l2 = 2.0 * TMath::ASin(l2 * crv) / crv;
432 l2 = TMath::Sqrt(l2*l2 + (z-oldZ)*(z-oldZ));
438 if (!AliExternalTrackParam::CorrectForMeanMaterial(xx0,xrho,GetMass())) {
445 Double_t p2 = (1.0 + GetTgl()*GetTgl()) / (GetSigned1Pt()*GetSigned1Pt());
446 Double_t beta2 = p2 / (p2 + GetMass()*GetMass());
447 if ((beta2 < 1.0e-10) ||
448 ((5940.0 * beta2/(1.0 - beta2 + 1.0e-10) - beta2) < 0.0)) {
452 Double_t dE = 0.153e-3 / beta2
453 * (TMath::Log(5940.0 * beta2/(1.0 - beta2 + 1.0e-10)) - beta2)
458 // Suspicious part - think about it ?
459 Double_t kinE = TMath::Sqrt(p2);
460 if (dE > 0.8*kinE) dE = 0.8 * kinE; //
461 if (dE < 0) dE = 0.0; // Not valid region for Bethe bloch
468 Double_t sigmade = 0.07 * TMath::Sqrt(TMath::Abs(dE)); // Energy loss fluctuation
469 Double_t sigmac2 = sigmade*sigmade*fC*fC*(p2+GetMass()*GetMass())/(p2*p2);
471 fCee += fX*fX * sigmac2;
479 //_____________________________________________________________________________
480 Int_t AliTRDtrackV1::PropagateToR(Double_t r,Double_t step)
483 // Propagate track to the radial position
484 // Rotation always connected to the last track position
492 Double_t radius = TMath::Sqrt(GetX()*GetX() + GetY()*GetY());
494 Double_t dir = (radius > r) ? -1.0 : 1.0;
496 for (Double_t x = radius+dir*step; dir*x < dir*r; x += dir*step) {
499 Double_t alpha = TMath::ATan2(xyz0[1],xyz0[0]);
502 GetProlongation(x,y,z);
503 xyz1[0] = x * TMath::Cos(alpha) + y * TMath::Sin(alpha);
504 xyz1[1] = x * TMath::Sin(alpha) - y * TMath::Cos(alpha);
507 AliTracker::MeanMaterialBudget(xyz0,xyz1,param);
509 param[1] = 100000000;
511 PropagateTo(x,param[1],param[0]*param[4]);
516 Double_t alpha = TMath::ATan2(xyz0[1],xyz0[0]);
519 GetProlongation(r,y,z);
520 xyz1[0] = r * TMath::Cos(alpha) + y * TMath::Sin(alpha);
521 xyz1[1] = r * TMath::Sin(alpha) - y * TMath::Cos(alpha);
524 AliTracker::MeanMaterialBudget(xyz0,xyz1,param);
527 param[1] = 100000000;
529 PropagateTo(r,param[1],param[0]*param[4]);
535 //_____________________________________________________________________________
536 Bool_t AliTRDtrackV1::Rotate(Double_t alpha, Bool_t absolute)
539 // Rotates track parameters in R*phi plane
540 // if absolute rotation alpha is in global system
541 // otherwise alpha rotation is relative to the current rotation angle
544 if (absolute) alpha -= GetAlpha();
547 return AliExternalTrackParam::Rotate(GetAlpha()+alpha);
550 //___________________________________________________________
551 void AliTRDtrackV1::SetNumberOfClusters()
553 // Calculate the number of clusters attached to this track
556 for(int ip=0; ip<kNplane; ip++){
557 if(fTracklet[ip] && fTrackletIndex[ip] != 0xffff) ncls += fTracklet[ip]->GetN();
559 AliKalmanTrack::SetNumberOfClusters(ncls);
563 //_______________________________________________________________
564 void AliTRDtrackV1::SetOwner()
567 // Toggle ownership of tracklets
570 if(TestBit(1)) return;
571 for (Int_t ip = 0; ip < kNplane; ip++) {
572 if(fTrackletIndex[ip] == 0xffff) continue;
573 fTracklet[ip] = new AliTRDseedV1(*fTracklet[ip]);
574 fTracklet[ip]->SetOwner();
579 //_______________________________________________________________
580 void AliTRDtrackV1::SetTracklet(AliTRDseedV1 *trklt, Int_t index)
585 Int_t plane = trklt->GetPlane();
586 if(fTrackletIndex[plane]==0xffff && fTracklet[plane]){
587 delete fTracklet[plane];
589 fTracklet[plane] = trklt;
590 fTrackletIndex[plane] = index;
593 //_______________________________________________________________
594 Bool_t AliTRDtrackV1::Update(AliTRDseedV1 *trklt, Double_t chisq)
597 // Update track and tracklet parameters
600 Double_t x = trklt->GetX0();
601 Double_t p[2] = { trklt->GetYat(x)
602 , trklt->GetZat(x) };
604 trklt->GetCovAt(x, cov);
606 if(!AliExternalTrackParam::Update(p, cov)) return kFALSE;
608 AliTRDcluster *c = 0x0;
609 Int_t ic = 0; while(!(c = trklt->GetClusters(ic))) ic++;
610 AliTracker::FillResiduals(this, p, cov, c->GetVolumeId());
613 // Register info to track
614 SetNumberOfClusters();
615 SetChi2(GetChi2() + chisq);
618 trklt->SetMomentum(GetP());
619 trklt->SetSnp(GetSnp());
620 trklt->SetTgl(GetTgl());
624 //_______________________________________________________________
625 void AliTRDtrackV1::UpdateESDtrack(AliESDtrack *track)
628 // Update the TRD PID information in the ESD track
631 track->SetNumberOfTRDslices(kNslice);
633 for (Int_t ip = 0; ip < kNplane; ip++) {
634 if(fTrackletIndex[ip] == 0xffff) continue;
635 fTracklet[ip]->CookdEdx(kNslice);
636 Float_t *dedx = fTracklet[ip]->GetdEdx();
637 for (Int_t js = 0; js < kNslice; js++) track->SetTRDslice(dedx[js], ip, js);
641 track->SetTRDpid(fPID);
642 track->SetTRDpidQuality(fPIDquality);