new bugs fixed by Tomek
[u/mrichter/AliRoot.git] / ITS / AliITStrackV2.cxx
CommitLineData
006b5f7f 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
66e811e2 16///////////////////////////////////////////////////////////////////////////
006b5f7f 17// Implementation of the ITS track class
18//
19// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
a9a2d814 20// dEdx analysis by: Boris Batyunya, JINR, Boris.Batiounia@cern.ch
66e811e2 21///////////////////////////////////////////////////////////////////////////
006b5f7f 22#include <TMath.h>
006b5f7f 23
24#include "AliCluster.h"
6c94f330 25#include "AliTracker.h"
83d73500 26#include "AliESDtrack.h"
006b5f7f 27#include "AliITStrackV2.h"
28
8602c008 29const Int_t AliITStrackV2::fgkWARN = 5;
30
1aedd96e 31ClassImp(AliITStrackV2)
8676d691 32
e43c066c 33
006b5f7f 34//____________________________________________________________________________
6c94f330 35AliITStrackV2::AliITStrackV2() : AliKalmanTrack(),
22b13da0 36 fdEdx(0),
83d73500 37 fESDtrack(0)
e43c066c 38{
e50912db 39 for(Int_t i=0; i<2*AliITSgeomTGeo::kNLayers; i++) fIndex[i]=-1;
e43c066c 40 for(Int_t i=0; i<4; i++) fdEdxSample[i]=0;
e43c066c 41}
42
83d73500 43
22b13da0 44//____________________________________________________________________________
67c3dcbe 45AliITStrackV2::AliITStrackV2(AliESDtrack& t,Bool_t c) throw (const Char_t *) :
6c94f330 46 AliKalmanTrack(),
47 fdEdx(t.GetITSsignal()),
48 fESDtrack(&t)
49{
83d73500 50 //------------------------------------------------------------------
67c3dcbe 51 // Conversion ESD track -> ITS track.
52 // If c==kTRUE, create the ITS track out of the constrained params.
83d73500 53 //------------------------------------------------------------------
6c94f330 54 const AliExternalTrackParam *par=&t;
55 if (c) {
6c4ef2ed 56 par=t.GetConstrainedParam();
6c94f330 57 if (!par) throw "AliITStrackV2: conversion failed !\n";
58 }
59 Set(par->GetX(),par->GetAlpha(),par->GetParameter(),par->GetCovariance());
60
61 //if (!Invariant()) throw "AliITStrackV2: conversion failed !\n";
62
83d73500 63 SetLabel(t.GetLabel());
64 SetMass(t.GetMass());
6c94f330 65 SetNumberOfClusters(t.GetITSclusters(fIndex));
006b5f7f 66
83d73500 67 if (t.GetStatus()&AliESDtrack::kTIME) {
68 StartTimeIntegral();
69 Double_t times[10]; t.GetIntegratedTimes(times); SetIntegratedTimes(times);
70 SetIntegratedLength(t.GetIntegratedLength());
71 }
e43c066c 72
68b8060b 73 for(Int_t i=0; i<4; i++) fdEdxSample[i]=0;
006b5f7f 74}
75
15dd636f 76void AliITStrackV2::UpdateESDtrack(ULong_t flags) const {
83d73500 77 fESDtrack->UpdateTrackParams(this,flags);
78}
79
006b5f7f 80//____________________________________________________________________________
6c94f330 81AliITStrackV2::AliITStrackV2(const AliITStrackV2& t) :
82 AliKalmanTrack(t),
83 fdEdx(t.fdEdx),
84 fESDtrack(t.fESDtrack)
85{
006b5f7f 86 //------------------------------------------------------------------
87 //Copy constructor
88 //------------------------------------------------------------------
ef7253ac 89 Int_t i;
ef7253ac 90 for (i=0; i<4; i++) fdEdxSample[i]=t.fdEdxSample[i];
e50912db 91 for (i=0; i<2*AliITSgeomTGeo::GetNLayers(); i++) fIndex[i]=t.fIndex[i];
006b5f7f 92}
a9a2d814 93
006b5f7f 94//_____________________________________________________________________________
95Int_t AliITStrackV2::Compare(const TObject *o) const {
96 //-----------------------------------------------------------------
97 // This function compares tracks according to the their curvature
98 //-----------------------------------------------------------------
7f6ddf58 99 AliITStrackV2 *t=(AliITStrackV2*)o;
6c23ffed 100 //Double_t co=OneOverPt();
101 //Double_t c =OneOverPt();
15dd636f 102 Double_t co=t->GetSigmaY2()*t->GetSigmaZ2();
103 Double_t c =GetSigmaY2()*GetSigmaZ2();
006b5f7f 104 if (c>co) return 1;
105 else if (c<co) return -1;
106 return 0;
107}
108
006b5f7f 109//____________________________________________________________________________
6c94f330 110Bool_t
111AliITStrackV2::PropagateToVertex(const AliESDVertex *v,Double_t d,Double_t x0)
112{
006b5f7f 113 //------------------------------------------------------------------
114 //This function propagates a track to the minimal distance from the origin
6c94f330 115 //------------------------------------------------------------------
116 Double_t bz=GetBz();
e50912db 117 if (PropagateToDCA(v,bz,kVeryBig)) {
118 Double_t xOverX0,xTimesRho;
119 xOverX0 = d; xTimesRho = d*x0;
120 if (CorrectForMeanMaterial(xOverX0,xTimesRho,kTRUE)) return kTRUE;
121 }
6c94f330 122 return kFALSE;
006b5f7f 123}
124
125//____________________________________________________________________________
6c94f330 126Bool_t AliITStrackV2::
e50912db 127GetGlobalXYZat(Double_t xloc, Double_t &x, Double_t &y, Double_t &z) const {
006b5f7f 128 //------------------------------------------------------------------
129 //This function returns a track position in the global system
130 //------------------------------------------------------------------
6c94f330 131 Double_t r[3];
e50912db 132 Bool_t rc=GetXYZAt(xloc, AliTracker::GetBz(), r);
6c94f330 133 x=r[0]; y=r[1]; z=r[2];
134 return rc;
006b5f7f 135}
136
137//_____________________________________________________________________________
6c94f330 138Double_t AliITStrackV2::GetPredictedChi2(const AliCluster *c) const {
006b5f7f 139 //-----------------------------------------------------------------
140 // This function calculates a predicted chi2 increment.
141 //-----------------------------------------------------------------
6c94f330 142 Double_t p[2]={c->GetY(), c->GetZ()};
143 Double_t cov[3]={c->GetSigmaY2(), 0., c->GetSigmaZ2()};
144 return AliExternalTrackParam::GetPredictedChi2(p,cov);
a9a2d814 145}
146
147//____________________________________________________________________________
6c94f330 148Bool_t AliITStrackV2::PropagateTo(Double_t xk, Double_t d, Double_t x0) {
006b5f7f 149 //------------------------------------------------------------------
150 //This function propagates a track
151 //------------------------------------------------------------------
afd25725 152
6c94f330 153 Double_t oldX=GetX(), oldY=GetY(), oldZ=GetZ();
006b5f7f 154
6c94f330 155 Double_t bz=GetBz();
156 if (!AliExternalTrackParam::PropagateTo(xk,bz)) return kFALSE;
e50912db 157 Double_t xOverX0,xTimesRho;
158 xOverX0 = d; xTimesRho = d*x0;
159 if (!CorrectForMeanMaterial(xOverX0,xTimesRho,kTRUE)) return kFALSE;
006b5f7f 160
dd44614b 161 Double_t x=GetX(), y=GetY(), z=GetZ();
6c94f330 162 if (IsStartedTimeIntegral() && x>oldX) {
163 Double_t l2 = (x-oldX)*(x-oldX) + (y-oldY)*(y-oldY) + (z-oldZ)*(z-oldZ);
f29dbb4b 164 AddTimeStep(TMath::Sqrt(l2));
165 }
f29dbb4b 166
6c94f330 167 return kTRUE;
006b5f7f 168}
169
170//____________________________________________________________________________
e50912db 171Bool_t AliITStrackV2::PropagateToTGeo(Double_t xToGo, Int_t nstep, Double_t &xOverX0, Double_t &xTimesRho) {
afd25725 172 //-------------------------------------------------------------------
173 // Propagates the track to a reference plane x=xToGo in n steps.
174 // These n steps are only used to take into account the curvature.
175 // The material is calculated with TGeo. (L.Gaudichet)
176 //-------------------------------------------------------------------
177
178 Double_t startx = GetX(), starty = GetY(), startz = GetZ();
179 Double_t sign = (startx<xToGo) ? -1.:1.;
180 Double_t step = (xToGo-startx)/TMath::Abs(nstep);
181
182 Double_t start[3], end[3], mparam[7], bz = GetBz();
183 Double_t x = startx;
184
185 for (Int_t i=0; i<nstep; i++) {
186
187 GetXYZ(start); //starting global position
188 x += step;
189 if (!GetXYZAt(x, bz, end)) return kFALSE;
190 if (!AliExternalTrackParam::PropagateTo(x, bz)) return kFALSE;
191 AliTracker::MeanMaterialBudget(start, end, mparam);
afd25725 192 if (mparam[1]<900000) {
e50912db 193 xTimesRho = sign*mparam[4]*mparam[0];
194 xOverX0 = mparam[1];
afd25725 195 if (!AliExternalTrackParam::CorrectForMeanMaterial(xOverX0,
e50912db 196 xTimesRho,GetMass())) return kFALSE;
afd25725 197 }
198 }
199
200 if (IsStartedTimeIntegral() && GetX()>startx) {
201 Double_t l2 = ( (GetX()-startx)*(GetX()-startx) +
202 (GetY()-starty)*(GetY()-starty) +
203 (GetZ()-startz)*(GetZ()-startz) );
204 AddTimeStep(TMath::Sqrt(l2));
205 }
206
207 return kTRUE;
208}
209
210//____________________________________________________________________________
6c94f330 211Bool_t AliITStrackV2::Update(const AliCluster* c, Double_t chi2, Int_t index)
212{
006b5f7f 213 //------------------------------------------------------------------
214 //This function updates track parameters
215 //------------------------------------------------------------------
6c94f330 216 Double_t p[2]={c->GetY(), c->GetZ()};
217 Double_t cov[3]={c->GetSigmaY2(), 0., c->GetSigmaZ2()};
006b5f7f 218
6c94f330 219 if (!AliExternalTrackParam::Update(p,cov)) return kFALSE;
006b5f7f 220
221 if (!Invariant()) {
6c94f330 222 AliWarning("Wrong invariant !");
223 return kFALSE;
006b5f7f 224 }
225
6c94f330 226 if (chi2<0) return kTRUE;
67c3dcbe 227
006b5f7f 228 Int_t n=GetNumberOfClusters();
229 fIndex[n]=index;
230 SetNumberOfClusters(n+1);
231 SetChi2(GetChi2()+chi2);
232
6c94f330 233 return kTRUE;
006b5f7f 234}
235
6c94f330 236Bool_t AliITStrackV2::Invariant() const {
006b5f7f 237 //------------------------------------------------------------------
238 // This function is for debugging purpose only
239 //------------------------------------------------------------------
7f6ddf58 240 Int_t n=GetNumberOfClusters();
6c94f330 241
242 Double_t sP2=GetParameter()[2];
243 if (TMath::Abs(sP2) >= kAlmost1){
8602c008 244 if (n>fgkWARN) Warning("Invariant","fP2=%f\n",sP2);
6c94f330 245 return kFALSE;
a9a2d814 246 }
6c94f330 247 Double_t sC00=GetCovariance()[0];
248 if (sC00<=0 || sC00>9.) {
8602c008 249 if (n>fgkWARN) Warning("Invariant","fC00=%f\n",sC00);
6c94f330 250 return kFALSE;
a9a2d814 251 }
6c94f330 252 Double_t sC11=GetCovariance()[2];
253 if (sC11<=0 || sC11>9.) {
8602c008 254 if (n>fgkWARN) Warning("Invariant","fC11=%f\n",sC11);
6c94f330 255 return kFALSE;
a9a2d814 256 }
6c94f330 257 Double_t sC22=GetCovariance()[5];
258 if (sC22<=0 || sC22>1.) {
8602c008 259 if (n>fgkWARN) Warning("Invariant","fC22=%f\n",sC22);
6c94f330 260 return kFALSE;
a9a2d814 261 }
6c94f330 262 Double_t sC33=GetCovariance()[9];
263 if (sC33<=0 || sC33>1.) {
8602c008 264 if (n>fgkWARN) Warning("Invariant","fC33=%f\n",sC33);
6c94f330 265 return kFALSE;
a9a2d814 266 }
6c94f330 267 Double_t sC44=GetCovariance()[14];
268 if (sC44<=0 /*|| sC44>6e-5*/) {
8602c008 269 if (n>fgkWARN) Warning("Invariant","fC44=%f\n",sC44);
6c94f330 270 return kFALSE;
14825d5a 271 }
6c94f330 272
273 return kTRUE;
006b5f7f 274}
275
276//____________________________________________________________________________
6c94f330 277Bool_t AliITStrackV2::Propagate(Double_t alp,Double_t xk) {
006b5f7f 278 //------------------------------------------------------------------
279 //This function propagates a track
280 //------------------------------------------------------------------
6c94f330 281 Double_t bz=GetBz();
282 if (!AliExternalTrackParam::Propagate(alp,xk,bz)) return kFALSE;
006b5f7f 283
006b5f7f 284 if (!Invariant()) {
6c94f330 285 AliWarning("Wrong invariant !");
286 return kFALSE;
791f9a2a 287 }
288
6c94f330 289 return kTRUE;
a9a2d814 290}
006b5f7f 291
afd25725 292Bool_t AliITStrackV2::MeanBudgetToPrimVertex(Double_t xyz[3], Double_t step, Double_t &d) const {
293
294 //-------------------------------------------------------------------
295 // Get the mean material budget between the actual point and the
296 // primary vertex. (L.Gaudichet)
297 //-------------------------------------------------------------------
298
299 Double_t cs=TMath::Cos(GetAlpha()), sn=TMath::Sin(GetAlpha());
300 Double_t vertexX = xyz[0]*cs + xyz[1]*sn;
301
302 Int_t nstep = Int_t((GetX()-vertexX)/step);
303 if (nstep<1) nstep = 1;
304 step = (GetX()-vertexX)/nstep;
305
c7719399 306 // Double_t mparam[7], densMean=0, radLength=0, length=0;
307 Double_t mparam[7];
afd25725 308 Double_t p1[3], p2[3], x = GetX(), bz = GetBz();
309 GetXYZ(p1);
310
311 d=0.;
312
313 for (Int_t i=0; i<nstep; i++) {
314 x += step;
315 if (!GetXYZAt(x, bz, p2)) return kFALSE;
316 AliTracker::MeanMaterialBudget(p1, p2, mparam);
317 if (mparam[1]>900000) return kFALSE;
318 d += mparam[1];
319
320 p1[0] = p2[0];
321 p1[1] = p2[1];
322 p1[2] = p2[2];
323 }
324
325 return kTRUE;
326}
327
6c94f330 328Bool_t AliITStrackV2::Improve(Double_t x0,Double_t xyz[3],Double_t ers[3]) {
babd135a 329 //------------------------------------------------------------------
6c94f330 330 //This function improves angular track parameters
babd135a 331 //------------------------------------------------------------------
6c94f330 332 Double_t cs=TMath::Cos(GetAlpha()), sn=TMath::Sin(GetAlpha());
333//Double_t xv = xyz[0]*cs + xyz[1]*sn; // vertex
334 Double_t yv =-xyz[0]*sn + xyz[1]*cs; // in the
335 Double_t zv = xyz[2]; // local frame
babd135a 336
6c94f330 337 Double_t dy = Par(0) - yv, dz = Par(1) - zv;
338 Double_t r2=GetX()*GetX() + dy*dy;
6c23ffed 339 Double_t p2=(1.+ GetTgl()*GetTgl())/(GetSigned1Pt()*GetSigned1Pt());
a9a2d814 340 Double_t beta2=p2/(p2 + GetMass()*GetMass());
341 x0*=TMath::Sqrt((1.+ GetTgl()*GetTgl())/(1.- GetSnp()*GetSnp()));
8676d691 342 Double_t theta2=14.1*14.1/(beta2*p2*1e6)*x0;
343 //Double_t theta2=1.0259e-6*14*14/28/(beta2*p2)*x0*9.36*2.33;
6c94f330 344
345 Double_t cnv=GetBz()*kB2C;
a9a2d814 346 {
6c94f330 347 Double_t dummy = 4/r2 - GetC()*GetC();
348 if (dummy < 0) return kFALSE;
349 Double_t parp = 0.5*(GetC()*GetX() + dy*TMath::Sqrt(dummy));
350 Double_t sigma2p = theta2*(1.- GetSnp()*GetSnp())*(1. + GetTgl()*GetTgl());
351 sigma2p += Cov(0)/r2*(1.- dy*dy/r2)*(1.- dy*dy/r2);
352 sigma2p += ers[1]*ers[1]/r2;
353 sigma2p += 0.25*Cov(14)*cnv*cnv*GetX()*GetX();
00709873 354 Double_t eps2p=sigma2p/(Cov(5) + sigma2p);
6c94f330 355 Par(0) += Cov(3)/(Cov(5) + sigma2p)*(parp - GetSnp());
356 Par(2) = eps2p*GetSnp() + (1 - eps2p)*parp;
357 Cov(5) *= eps2p;
358 Cov(3) *= eps2p;
a9a2d814 359 }
360 {
6c94f330 361 Double_t parl=0.5*GetC()*dz/TMath::ASin(0.5*GetC()*TMath::Sqrt(r2));
362 Double_t sigma2l=theta2;
363 sigma2l += Cov(2)/r2 + Cov(0)*dy*dy*dz*dz/(r2*r2*r2);
364 sigma2l += ers[2]*ers[2]/r2;
365 Double_t eps2l = sigma2l/(Cov(9) + sigma2l);
366 Par(1) += Cov(7 )/(Cov(9) + sigma2l)*(parl - Par(3));
367 Par(4) += Cov(13)/(Cov(9) + sigma2l)*(parl - Par(3));
368 Par(3) = eps2l*Par(3) + (1-eps2l)*parl;
369 Cov(9) *= eps2l;
00709873 370 Cov(13)*= eps2l;
6c94f330 371 Cov(7) *= eps2l;
a9a2d814 372 }
6c94f330 373 if (!Invariant()) return kFALSE;
14825d5a 374
6c94f330 375 return kTRUE;
14825d5a 376}
23efe5f1 377
378void AliITStrackV2::CookdEdx(Double_t low, Double_t up) {
379 //-----------------------------------------------------------------
a9a2d814 380 // This function calculates dE/dX within the "low" and "up" cuts.
381 // Origin: Boris Batyunya, JINR, Boris.Batiounia@cern.ch
23efe5f1 382 //-----------------------------------------------------------------
23efe5f1 383 // The clusters order is: SSD-2, SSD-1, SDD-2, SDD-1, SPD-2, SPD-1
c0dd5278 384
385 Int_t i;
386 Int_t nc=0;
387 for (i=0; i<GetNumberOfClusters(); i++) {
388 Int_t idx=GetClusterIndex(i);
389 idx=(idx&0xf0000000)>>28;
390 if (idx>1) nc++; // Take only SSD and SDD
391 }
23efe5f1 392
a9a2d814 393 Int_t swap;//stupid sorting
23efe5f1 394 do {
395 swap=0;
396 for (i=0; i<nc-1; i++) {
397 if (fdEdxSample[i]<=fdEdxSample[i+1]) continue;
398 Float_t tmp=fdEdxSample[i];
399 fdEdxSample[i]=fdEdxSample[i+1]; fdEdxSample[i+1]=tmp;
400 swap++;
401 }
402 } while (swap);
403
a9a2d814 404 Int_t nl=Int_t(low*nc), nu=Int_t(up*nc); //b.b. to take two lowest dEdX
405 // values from four ones choose
406 // nu=2
23efe5f1 407 Float_t dedx=0;
a9a2d814 408 for (i=nl; i<nu; i++) dedx += fdEdxSample[i];
c0dd5278 409 if (nu-nl>0) dedx /= (nu-nl);
23efe5f1 410
23efe5f1 411 SetdEdx(dedx);
412}
c7bafca9 413
6c94f330 414Double_t AliITStrackV2::GetBz() const {
415 //
416 // returns Bz component of the magnetic field (kG)
417 //
418 if (AliTracker::UniformField()) return AliTracker::GetBz();
419 Double_t r[3]; GetXYZ(r);
420 return AliTracker::GetBz(r);
5773defd 421}
6c94f330 422
8602c008 423//____________________________________________________________________________
424Bool_t AliITStrackV2::
e50912db 425GetPhiZat(Double_t r, Double_t &phi, Double_t &z) const {
426 //------------------------------------------------------------------
427 // This function returns the global cylindrical (phi,z) of the track
428 // position estimated at the radius r.
429 // The track curvature is neglected.
430 //------------------------------------------------------------------
431 Double_t d=GetD(0.,0.);
432 if (TMath::Abs(d) > r) return kFALSE;
433
434 Double_t rcurr=TMath::Sqrt(GetX()*GetX() + GetY()*GetY());
435 if (TMath::Abs(d) > rcurr) return kFALSE;
436 Double_t phicurr=GetAlpha()+TMath::ASin(GetSnp());
437
438 phi=phicurr+TMath::ASin(d/r)-TMath::ASin(d/rcurr);
439 z=GetZ()+GetTgl()*(TMath::Sqrt(r*r-d*d) - TMath::Sqrt(rcurr*rcurr-d*d));
440
441 return kTRUE;
442}
443//____________________________________________________________________________
444Bool_t AliITStrackV2::
445GetLocalXat(Double_t r,Double_t &xloc) const {
8602c008 446 //------------------------------------------------------------------
e50912db 447 // This function returns the local x of the track
448 // position estimated at the radius r.
8602c008 449 // The track curvature is neglected.
450 //------------------------------------------------------------------
451 Double_t d=GetD(0.,0.);
e50912db 452 if (TMath::Abs(d) > r) return kFALSE;
8602c008 453
e50912db 454 Double_t rcurr=TMath::Sqrt(GetX()*GetX() + GetY()*GetY());
455 Double_t phicurr=GetAlpha()+TMath::ASin(GetSnp());
456 Double_t phi=phicurr+TMath::ASin(d/r)-TMath::ASin(d/rcurr);
8602c008 457
e50912db 458 xloc=r*(TMath::Cos(phi)*TMath::Cos(GetAlpha())
459 +TMath::Sin(phi)*TMath::Sin(GetAlpha()));
8602c008 460
461 return kTRUE;
462}
463