]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliKalmanTrack.cxx
Coding conventions
[u/mrichter/AliRoot.git] / STEER / AliKalmanTrack.cxx
CommitLineData
87594435 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
acd84897 16/* $Id$ */
fb17acd4 17
87594435 18//-------------------------------------------------------------------------
19// Implementation of the AliKalmanTrack class
066782e8 20// that is the base for AliTPCtrack, AliITStrackV2 and AliTRDtrack
87594435 21// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
22//-------------------------------------------------------------------------
23
24#include "AliKalmanTrack.h"
4557b520 25#include "TGeoManager.h"
87594435 26
27ClassImp(AliKalmanTrack)
28
c84a5e9e 29const AliMagF *AliKalmanTrack::fgkFieldMap=0;
30Double_t AliKalmanTrack::fgConvConst=0.;
9b280d80 31
e2afb3b6 32//_______________________________________________________________________
33AliKalmanTrack::AliKalmanTrack():
34 fLab(-3141593),
68b8060b 35 fFakeRatio(0),
e2afb3b6 36 fChi2(0),
304864ab 37 fMass(AliPID::ParticleMass(AliPID::kPion)),
90e48c0c 38 fN(0),
c84a5e9e 39 fLocalConvConst(0),
90e48c0c 40 fStartTimeIntegral(kFALSE),
41 fIntegratedLength(0)
e2afb3b6 42{
116cbefd 43 //
44 // Default constructor
45 //
c84a5e9e 46 if (fgkFieldMap==0) {
f37d970d 47 AliFatal("The magnetic field has not been set!");
8de97894 48 }
c84a5e9e 49
50 for(Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i] = 0;
e2afb3b6 51}
52
53//_______________________________________________________________________
54AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
55 TObject(t),
56 fLab(t.fLab),
babd135a 57 fFakeRatio(t.fFakeRatio),
e2afb3b6 58 fChi2(t.fChi2),
59 fMass(t.fMass),
90e48c0c 60 fN(t.fN),
c84a5e9e 61 fLocalConvConst(t.fLocalConvConst),
90e48c0c 62 fStartTimeIntegral(t.fStartTimeIntegral),
63 fIntegratedLength(t.fIntegratedLength)
e2afb3b6 64{
116cbefd 65 //
66 // Copy constructor
67 //
c84a5e9e 68 if (fgkFieldMap==0) {
f37d970d 69 AliFatal("The magnetic field has not been set!");
8de97894 70 }
74f9526e 71
c84a5e9e 72 for (Int_t i=0; i<AliPID::kSPECIES; i++)
73 fIntegratedTime[i] = t.fIntegratedTime[i];
74f9526e 74}
c5507f6d 75
74f9526e 76//_______________________________________________________________________
77void AliKalmanTrack::StartTimeIntegral()
78{
49a7a79a 79 // Sylwester Radomski, GSI
80 // S.Radomski@gsi.de
74f9526e 81 //
82 // Start time integration
83 // To be called at Vertex by ITS tracker
84 //
85
86 //if (fStartTimeIntegral)
f37d970d 87 // AliWarning("Reseting Recorded Time.");
74f9526e 88
89 fStartTimeIntegral = kTRUE;
304864ab 90 for(Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i] = 0;
74f9526e 91 fIntegratedLength = 0;
92}
93//_______________________________________________________________________
94void AliKalmanTrack:: AddTimeStep(Double_t length)
95{
96 //
97 // Add step to integrated time
98 // this method should be called by a sublasses at the end
99 // of the PropagateTo function or by a tracker
100 // each time step is made.
101 //
102 // If integration not started function does nothing
103 //
104 // Formula
105 // dt = dl * sqrt(p^2 + m^2) / p
106 // p = pT * (1 + tg^2 (lambda) )
107 //
108 // pt = 1/external parameter [4]
109 // tg lambda = external parameter [3]
110 //
111 //
112 // Sylwester Radomski, GSI
113 // S.Radomski@gsi.de
114 //
115
5d8718b8 116 static const Double_t kcc = 2.99792458e-2;
74f9526e 117
118 if (!fStartTimeIntegral) return;
119
120 fIntegratedLength += length;
121
74f9526e 122 Double_t xr, param[5];
123 Double_t pt, tgl;
124
125 GetExternalParameters(xr, param);
126 pt = 1/param[4] ;
127 tgl = param[3];
128
129 Double_t p = TMath::Abs(pt * TMath::Sqrt(1+tgl*tgl));
130
131 if (length > 100) return;
132
304864ab 133 for (Int_t i=0; i<AliPID::kSPECIES; i++) {
74f9526e 134
304864ab 135 Double_t mass = AliPID::ParticleMass(i);
74f9526e 136 Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
5d8718b8 137 Double_t time = length * correction / kcc;
74f9526e 138
74f9526e 139 fIntegratedTime[i] += time;
140 }
e2afb3b6 141}
142
74f9526e 143//_______________________________________________________________________
144
145Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const
146{
49a7a79a 147 // Sylwester Radomski, GSI
148 // S.Radomski@gsi.de
74f9526e 149 //
150 // Return integrated time hypothesis for a given particle
151 // type assumption.
152 //
153 // Input parameter:
154 // pdg - Pdg code of a particle type
155 //
156
157
158 if (!fStartTimeIntegral) {
f37d970d 159 AliWarning("Time integration not started");
74f9526e 160 return 0.;
161 }
162
304864ab 163 for (Int_t i=0; i<AliPID::kSPECIES; i++)
164 if (AliPID::ParticleCode(i) == TMath::Abs(pdg)) return fIntegratedTime[i];
74f9526e 165
f37d970d 166 AliWarning(Form("Particle type [%d] not found", pdg));
74f9526e 167 return 0;
168}
ae982df3 169
170void AliKalmanTrack::GetIntegratedTimes(Double_t *times) const {
304864ab 171 for (Int_t i=0; i<AliPID::kSPECIES; i++) times[i]=fIntegratedTime[i];
ae982df3 172}
173
174void AliKalmanTrack::SetIntegratedTimes(const Double_t *times) {
304864ab 175 for (Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i]=times[i];
ae982df3 176}
177
74f9526e 178//_______________________________________________________________________
179
180void AliKalmanTrack::PrintTime() const
181{
49a7a79a 182 // Sylwester Radomski, GSI
183 // S.Radomski@gsi.de
184 //
74f9526e 185 // For testing
186 // Prints time for all hypothesis
187 //
188
304864ab 189 for (Int_t i=0; i<AliPID::kSPECIES; i++)
190 printf("%d: %.2f ", AliPID::ParticleCode(i), fIntegratedTime[i]);
74f9526e 191 printf("\n");
192}
193
c84a5e9e 194void AliKalmanTrack::External2Helix(Double_t helix[6]) const {
49a7a79a 195 //--------------------------------------------------------------------
196 // External track parameters -> helix parameters
197 //--------------------------------------------------------------------
198 Double_t alpha,x,cs,sn;
c84a5e9e 199 GetExternalParameters(x,helix); alpha=GetAlpha();
49a7a79a 200
201 cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
202 helix[5]=x*cs - helix[0]*sn; // x0
203 helix[0]=x*sn + helix[0]*cs; // y0
204//helix[1]= // z0
205 helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
206//helix[3]= // tgl
c84a5e9e 207 helix[4]=helix[4]/GetLocalConvConst(); // C
49a7a79a 208}
209
210static void Evaluate(const Double_t *h, Double_t t,
211 Double_t r[3], //radius vector
212 Double_t g[3], //first defivatives
213 Double_t gg[3]) //second derivatives
214{
215 //--------------------------------------------------------------------
216 // Calculate position of a point on a track and some derivatives
217 //--------------------------------------------------------------------
218 Double_t phase=h[4]*t+h[2];
219 Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
220
221 r[0] = h[5] + (sn - h[6])/h[4];
222 r[1] = h[0] - (cs - h[7])/h[4];
223 r[2] = h[1] + h[3]*t;
224
225 g[0] = cs; g[1]=sn; g[2]=h[3];
226
227 gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
228}
229
230Double_t AliKalmanTrack::
231GetDCA(const AliKalmanTrack *p, Double_t &xthis, Double_t &xp) const {
232 //------------------------------------------------------------
233 // Returns the (weighed !) distance of closest approach between
234 // this track and the track passed as the argument.
235 // Other returned values:
236 // xthis, xt - coordinates of tracks' reference planes at the DCA
237 //-----------------------------------------------------------
238 Double_t dy2=GetSigmaY2() + p->GetSigmaY2();
239 Double_t dz2=GetSigmaZ2() + p->GetSigmaZ2();
240 Double_t dx2=dy2;
241
242 //dx2=dy2=dz2=1.;
243
c84a5e9e 244 Double_t p1[8]; External2Helix(p1);
49a7a79a 245 p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
c84a5e9e 246 Double_t p2[8]; p->External2Helix(p2);
49a7a79a 247 p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
248
249
250 Double_t r1[3],g1[3],gg1[3]; Double_t t1=0.;
251 Evaluate(p1,t1,r1,g1,gg1);
252 Double_t r2[3],g2[3],gg2[3]; Double_t t2=0.;
253 Evaluate(p2,t2,r2,g2,gg2);
74f9526e 254
49a7a79a 255 Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
256 Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
257
258 Int_t max=27;
259 while (max--) {
260 Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
261 Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
262 Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 +
263 (g1[1]*g1[1] - dy*gg1[1])/dy2 +
264 (g1[2]*g1[2] - dz*gg1[2])/dz2;
265 Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 +
266 (g2[1]*g2[1] + dy*gg2[1])/dy2 +
267 (g2[2]*g2[2] + dz*gg2[2])/dz2;
268 Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
269
270 Double_t det=h11*h22-h12*h12;
271
272 Double_t dt1,dt2;
273 if (TMath::Abs(det)<1.e-33) {
274 //(quasi)singular Hessian
275 dt1=-gt1; dt2=-gt2;
276 } else {
277 dt1=-(gt1*h22 - gt2*h12)/det;
278 dt2=-(h11*gt2 - h12*gt1)/det;
279 }
280
281 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
282
283 //check delta(phase1) ?
284 //check delta(phase2) ?
285
286 if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
287 if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
288 if ((gt1*gt1+gt2*gt2) > 1.e-4/dy2/dy2)
f37d970d 289 AliWarning(" stopped at not a stationary point !");
49a7a79a 290 Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
291 if (lmb < 0.)
f37d970d 292 AliWarning(" stopped at not a minimum !");
49a7a79a 293 break;
294 }
295
296 Double_t dd=dm;
297 for (Int_t div=1 ; ; div*=2) {
298 Evaluate(p1,t1+dt1,r1,g1,gg1);
299 Evaluate(p2,t2+dt2,r2,g2,gg2);
300 dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
301 dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
302 if (dd<dm) break;
303 dt1*=0.5; dt2*=0.5;
304 if (div>512) {
f37d970d 305 AliWarning(" overshoot !"); break;
49a7a79a 306 }
307 }
308 dm=dd;
309
310 t1+=dt1;
311 t2+=dt2;
312
313 }
314
f37d970d 315 if (max<=0) AliWarning(" too many iterations !");
49a7a79a 316
317 Double_t cs=TMath::Cos(GetAlpha());
318 Double_t sn=TMath::Sin(GetAlpha());
319 xthis=r1[0]*cs + r1[1]*sn;
320
321 cs=TMath::Cos(p->GetAlpha());
322 sn=TMath::Sin(p->GetAlpha());
323 xp=r2[0]*cs + r2[1]*sn;
324
325 return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
326}
327
328Double_t AliKalmanTrack::
329PropagateToDCA(AliKalmanTrack *p, Double_t d, Double_t x0) {
330 //--------------------------------------------------------------
331 // Propagates this track and the argument track to the position of the
332 // distance of closest approach.
333 // Returns the (weighed !) distance of closest approach.
334 //--------------------------------------------------------------
335 Double_t xthis,xp;
336 Double_t dca=GetDCA(p,xthis,xp);
337
338 if (!PropagateTo(xthis,d,x0)) {
f37d970d 339 //AliWarning(" propagation failed !");
49a7a79a 340 return 1e+33;
341 }
342
343 if (!p->PropagateTo(xp,d,x0)) {
f37d970d 344 //AliWarning(" propagation failed !";
49a7a79a 345 return 1e+33;
346 }
347
348 return dca;
349}
c84a5e9e 350
4557b520 351
352
353
354
355Double_t AliKalmanTrack::MeanMaterialBudget(Double_t *start, Double_t *end, Double_t *mparam)
356{
357 //
358 // calculate mean material budget and material properties beween point start and end
359 // mparam - returns parameters used for dEdx and multiple scatering
360 //
361 // mparam[0] - density mean
362 // mparam[1] - rad length
363 // mparam[2] - A mean
364 // mparam[3] - Z mean
365 // mparam[4] - length
366 // mparam[5] - Z/A mean
367 // mparam[6] - number of boundary crosses
368 //
369 mparam[0]=0; mparam[1]=1; mparam[2] =0; mparam[3] =0, mparam[4]=0, mparam[5]=0; mparam[6]=0;
370 //
371 Double_t bparam[6], lparam[6]; // bparam - total param - lparam - local parameters
372 for (Int_t i=0;i<6;i++) bparam[i]=0; //
373
374 if (!gGeoManager) {
375 printf("ERROR: no TGeo\n");
376 return 0.;
377 }
378 //
379 Double_t length;
380 Double_t dir[3];
381 length = TMath::Sqrt((end[0]-start[0])*(end[0]-start[0])+
382 (end[1]-start[1])*(end[1]-start[1])+
383 (end[2]-start[2])*(end[2]-start[2]));
384 mparam[4]=length;
385 if (length<TGeoShape::Tolerance()) return 0.0;
386 Double_t invlen = 1./length;
387 dir[0] = (end[0]-start[0])*invlen;
388 dir[1] = (end[1]-start[1])*invlen;
389 dir[2] = (end[2]-start[2])*invlen;
390 // Initialize start point and direction
391 TGeoNode *currentnode = 0;
392 TGeoNode *startnode = gGeoManager->InitTrack(start, dir);
393 // printf("%s length=%f\n",gGeoManager->GetPath(),length);
394 if (!startnode) {
395 printf("ERROR: start point out of geometry\n");
396 return 0.0;
397 }
398 TGeoMaterial *material = startnode->GetVolume()->GetMedium()->GetMaterial();
399 lparam[0] = material->GetDensity();
400 lparam[1] = material->GetRadLen();
401 lparam[2] = material->GetA();
402 lparam[3] = material->GetZ();
403 lparam[5] = lparam[3]/lparam[2];
404 if (material->IsMixture()) {
405 lparam[1]*=lparam[0]; // different normalization in the modeler for mixture
406 TGeoMixture * mixture = (TGeoMixture*)material;
407 lparam[5] =0;
408 Double_t sum =0;
409 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
410 sum += mixture->GetWmixt()[iel];
411 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
412 }
413 lparam[5]/=sum;
414 }
415 gGeoManager->FindNextBoundary(length);
416 Double_t snext = gGeoManager->GetStep();
417 Double_t step = 0.0;
418 // If no boundary within proposed length, return current density
419 if (snext>=length) {
420 for (Int_t ip=0;ip<5;ip++) mparam[ip] = lparam[ip];
421 return lparam[0];
422 }
423 // Try to cross the boundary and see what is next
424 while (length>TGeoShape::Tolerance()) {
425 mparam[6]+=1.;
426 currentnode = gGeoManager->Step();
427 step += snext+1.E-6;
428 bparam[1] += snext*lparam[1];
429 bparam[2] += snext*lparam[2];
430 bparam[3] += snext*lparam[3];
431 bparam[5] += snext*lparam[5];
432 bparam[0] += snext*lparam[0];
433
434 if (snext>=length) break;
435 // printf("%s snext=%f density=%f bparam[0]=%f\n", gGeoManager->GetPath(),snext,density,bparam[0]);
436 if (!gGeoManager->IsEntering()) {
437 gGeoManager->SetStep(1.E-3);
438 currentnode = gGeoManager->Step();
439 if (!gGeoManager->IsEntering() || !currentnode) {
440 // printf("ERROR: cannot cross boundary\n");
441 mparam[0] = bparam[0]/step;
442 mparam[1] = bparam[1]/step;
443 mparam[2] = bparam[2]/step;
444 mparam[3] = bparam[3]/step;
445 mparam[5] = bparam[5]/step;
446 mparam[4] = step;
447 mparam[0] = 0.; // if crash of navigation take mean density 0
448 mparam[1] = 1000000; // and infinite rad length
449 return bparam[0]/step;
450 }
451 step += 1.E-3;
452 snext += 1.E-3;
453 bparam[0] += lparam[0]*1.E-3;
454 bparam[1] += lparam[1]*1.E-3;
455 bparam[2] += lparam[2]*1.E-3;
456 bparam[3] += lparam[3]*1.E-3;
457 bparam[5] += lparam[5]*1.E-3;
458 }
459 length -= snext;
460 material = currentnode->GetVolume()->GetMedium()->GetMaterial();
461 lparam[0] = material->GetDensity();
462 lparam[1] = material->GetRadLen();
463 lparam[2] = material->GetA();
464 lparam[3] = material->GetZ();
465 lparam[5] = lparam[3]/lparam[2];
466 if (material->IsMixture()) {
467 lparam[1]*=lparam[0];
468 TGeoMixture * mixture = (TGeoMixture*)material;
469 lparam[5]=0;
470 Double_t sum =0;
471 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
472 sum+= mixture->GetWmixt()[iel];
473 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
474 }
475 lparam[5]/=sum;
476 }
477 gGeoManager->FindNextBoundary(length);
478 snext = gGeoManager->GetStep();
479 }
480 mparam[0] = bparam[0]/step;
481 mparam[1] = bparam[1]/step;
482 mparam[2] = bparam[2]/step;
483 mparam[3] = bparam[3]/step;
484 mparam[5] = bparam[5]/step;
485 return bparam[0]/step;
486
487}