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 //-------------------------------------------------------------------------
19 // Implementation of the AliKalmanTrack class
20 // that is the base for AliTPCtrack, AliITStrackV2 and AliTRDtrack
21 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
22 //-------------------------------------------------------------------------
23 #include "AliTracker.h"
24 #include "AliKalmanTrack.h"
25 #include "TGeoManager.h"
27 ClassImp(AliKalmanTrack)
29 //_______________________________________________________________________
30 AliKalmanTrack::AliKalmanTrack():
34 fMass(AliPID::ParticleMass(AliPID::kPion)),
37 fStartTimeIntegral(kFALSE),
41 // Default constructor
43 if (AliTracker::GetFieldMap()==0) {
44 AliFatal("The magnetic field has not been set!");
47 for(Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i] = 0;
50 //_______________________________________________________________________
51 AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
54 fFakeRatio(t.fFakeRatio),
58 fLocalConvConst(t.fLocalConvConst),
59 fStartTimeIntegral(t.fStartTimeIntegral),
60 fIntegratedLength(t.fIntegratedLength)
65 if (AliTracker::GetFieldMap()==0) {
66 AliFatal("The magnetic field has not been set!");
69 for (Int_t i=0; i<AliPID::kSPECIES; i++)
70 fIntegratedTime[i] = t.fIntegratedTime[i];
73 //_______________________________________________________________________
74 void AliKalmanTrack::StartTimeIntegral()
76 // Sylwester Radomski, GSI
79 // Start time integration
80 // To be called at Vertex by ITS tracker
83 //if (fStartTimeIntegral)
84 // AliWarning("Reseting Recorded Time.");
86 fStartTimeIntegral = kTRUE;
87 for(Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i] = 0;
88 fIntegratedLength = 0;
91 //_______________________________________________________________________
92 void AliKalmanTrack:: AddTimeStep(Double_t length)
95 // Add step to integrated time
96 // this method should be called by a sublasses at the end
97 // of the PropagateTo function or by a tracker
98 // each time step is made.
100 // If integration not started function does nothing
103 // dt = dl * sqrt(p^2 + m^2) / p
104 // p = pT * (1 + tg^2 (lambda) )
106 // pt = 1/external parameter [4]
107 // tg lambda = external parameter [3]
110 // Sylwester Radomski, GSI
114 static const Double_t kcc = 2.99792458e-2;
116 if (!fStartTimeIntegral) return;
118 fIntegratedLength += length;
120 Double_t xr, param[5];
123 GetExternalParameters(xr, param);
127 Double_t p = TMath::Abs(pt * TMath::Sqrt(1+tgl*tgl));
129 if (length > 100) return;
131 for (Int_t i=0; i<AliPID::kSPECIES; i++) {
133 Double_t mass = AliPID::ParticleMass(i);
134 Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
135 Double_t time = length * correction / kcc;
137 fIntegratedTime[i] += time;
141 //_______________________________________________________________________
142 Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const
144 // Sylwester Radomski, GSI
147 // Return integrated time hypothesis for a given particle
151 // pdg - Pdg code of a particle type
155 if (!fStartTimeIntegral) {
156 AliWarning("Time integration not started");
160 for (Int_t i=0; i<AliPID::kSPECIES; i++)
161 if (AliPID::ParticleCode(i) == TMath::Abs(pdg)) return fIntegratedTime[i];
163 AliWarning(Form("Particle type [%d] not found", pdg));
167 void AliKalmanTrack::GetIntegratedTimes(Double_t *times) const {
168 for (Int_t i=0; i<AliPID::kSPECIES; i++) times[i]=fIntegratedTime[i];
171 void AliKalmanTrack::SetIntegratedTimes(const Double_t *times) {
172 for (Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i]=times[i];
175 void AliKalmanTrack::External2Helix(Double_t helix[6]) const {
176 //--------------------------------------------------------------------
177 // External track parameters -> helix parameters
178 //--------------------------------------------------------------------
179 Double_t alpha,x,cs,sn;
180 GetExternalParameters(x,helix); alpha=GetAlpha();
182 cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
183 helix[5]=x*cs - helix[0]*sn; // x0
184 helix[0]=x*sn + helix[0]*cs; // y0
186 helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
188 helix[4]=helix[4]/GetLocalConvConst(); // C
191 static void Evaluate(const Double_t *h, Double_t t,
192 Double_t r[3], //radius vector
193 Double_t g[3], //first defivatives
194 Double_t gg[3]) //second derivatives
196 //--------------------------------------------------------------------
197 // Calculate position of a point on a track and some derivatives
198 //--------------------------------------------------------------------
199 Double_t phase=h[4]*t+h[2];
200 Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
202 r[0] = h[5] + (sn - h[6])/h[4];
203 r[1] = h[0] - (cs - h[7])/h[4];
204 r[2] = h[1] + h[3]*t;
206 g[0] = cs; g[1]=sn; g[2]=h[3];
208 gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
211 Double_t AliKalmanTrack::
212 GetDCA(const AliKalmanTrack *p, Double_t &xthis, Double_t &xp) const {
213 //------------------------------------------------------------
214 // Returns the (weighed !) distance of closest approach between
215 // this track and the track passed as the argument.
216 // Other returned values:
217 // xthis, xt - coordinates of tracks' reference planes at the DCA
218 //-----------------------------------------------------------
219 Double_t dy2=GetSigmaY2() + p->GetSigmaY2();
220 Double_t dz2=GetSigmaZ2() + p->GetSigmaZ2();
225 Double_t p1[8]; External2Helix(p1);
226 p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
227 Double_t p2[8]; p->External2Helix(p2);
228 p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
231 Double_t r1[3],g1[3],gg1[3]; Double_t t1=0.;
232 Evaluate(p1,t1,r1,g1,gg1);
233 Double_t r2[3],g2[3],gg2[3]; Double_t t2=0.;
234 Evaluate(p2,t2,r2,g2,gg2);
236 Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
237 Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
241 Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
242 Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
243 Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 +
244 (g1[1]*g1[1] - dy*gg1[1])/dy2 +
245 (g1[2]*g1[2] - dz*gg1[2])/dz2;
246 Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 +
247 (g2[1]*g2[1] + dy*gg2[1])/dy2 +
248 (g2[2]*g2[2] + dz*gg2[2])/dz2;
249 Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
251 Double_t det=h11*h22-h12*h12;
254 if (TMath::Abs(det)<1.e-33) {
255 //(quasi)singular Hessian
258 dt1=-(gt1*h22 - gt2*h12)/det;
259 dt2=-(h11*gt2 - h12*gt1)/det;
262 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
264 //check delta(phase1) ?
265 //check delta(phase2) ?
267 if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
268 if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
269 if ((gt1*gt1+gt2*gt2) > 1.e-4/dy2/dy2)
270 AliWarning(" stopped at not a stationary point !");
271 Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
273 AliWarning(" stopped at not a minimum !");
278 for (Int_t div=1 ; ; div*=2) {
279 Evaluate(p1,t1+dt1,r1,g1,gg1);
280 Evaluate(p2,t2+dt2,r2,g2,gg2);
281 dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
282 dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
286 AliWarning(" overshoot !"); break;
296 if (max<=0) AliWarning(" too many iterations !");
298 Double_t cs=TMath::Cos(GetAlpha());
299 Double_t sn=TMath::Sin(GetAlpha());
300 xthis=r1[0]*cs + r1[1]*sn;
302 cs=TMath::Cos(p->GetAlpha());
303 sn=TMath::Sin(p->GetAlpha());
304 xp=r2[0]*cs + r2[1]*sn;
306 return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
310 AliKalmanTrack::PropagateToDCA(AliKalmanTrack *p, Double_t d, Double_t x0) {
311 //--------------------------------------------------------------
312 // Propagates this track and the argument track to the position of the
313 // distance of closest approach.
314 // Returns the (weighed !) distance of closest approach.
315 //--------------------------------------------------------------
317 Double_t dca=GetDCA(p,xthis,xp);
319 if (!PropagateTo(xthis,d,x0)) {
320 //AliWarning(" propagation failed !");
324 if (!p->PropagateTo(xp,d,x0)) {
325 //AliWarning(" propagation failed !";
336 Double_t AliKalmanTrack::MeanMaterialBudget(Double_t *start, Double_t *end, Double_t *mparam)
339 // calculate mean material budget and material properties beween point start and end
340 // mparam - returns parameters used for dEdx and multiple scatering
342 // mparam[0] - density mean
343 // mparam[1] - rad length
344 // mparam[2] - A mean
345 // mparam[3] - Z mean
346 // mparam[4] - length
347 // mparam[5] - Z/A mean
348 // mparam[6] - number of boundary crosses
350 mparam[0]=0; mparam[1]=1; mparam[2] =0; mparam[3] =0, mparam[4]=0, mparam[5]=0; mparam[6]=0;
352 Double_t bparam[6], lparam[6]; // bparam - total param - lparam - local parameters
353 for (Int_t i=0;i<6;i++) bparam[i]=0; //
356 printf("ERROR: no TGeo\n");
362 length = TMath::Sqrt((end[0]-start[0])*(end[0]-start[0])+
363 (end[1]-start[1])*(end[1]-start[1])+
364 (end[2]-start[2])*(end[2]-start[2]));
366 if (length<TGeoShape::Tolerance()) return 0.0;
367 Double_t invlen = 1./length;
368 dir[0] = (end[0]-start[0])*invlen;
369 dir[1] = (end[1]-start[1])*invlen;
370 dir[2] = (end[2]-start[2])*invlen;
371 // Initialize start point and direction
372 TGeoNode *currentnode = 0;
373 TGeoNode *startnode = gGeoManager->InitTrack(start, dir);
374 // printf("%s length=%f\n",gGeoManager->GetPath(),length);
376 printf("ERROR: start point out of geometry\n");
379 TGeoMaterial *material = startnode->GetVolume()->GetMedium()->GetMaterial();
380 lparam[0] = material->GetDensity();
381 lparam[1] = material->GetRadLen();
382 lparam[2] = material->GetA();
383 lparam[3] = material->GetZ();
385 lparam[5] = lparam[3]/lparam[2];
386 if (material->IsMixture()) {
387 lparam[1]*=lparam[0]; // different normalization in the modeler for mixture
388 TGeoMixture * mixture = (TGeoMixture*)material;
391 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
392 sum += mixture->GetWmixt()[iel];
393 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
397 gGeoManager->FindNextBoundary(length);
398 Double_t snext = gGeoManager->GetStep();
400 // If no boundary within proposed length, return current density
402 for (Int_t ip=0;ip<5;ip++) mparam[ip] = lparam[ip];
405 // Try to cross the boundary and see what is next
406 while (length>TGeoShape::Tolerance()) {
408 currentnode = gGeoManager->Step();
410 bparam[1] += snext*lparam[1];
411 bparam[2] += snext*lparam[2];
412 bparam[3] += snext*lparam[3];
413 bparam[5] += snext*lparam[5];
414 bparam[0] += snext*lparam[0];
416 if (snext>=length) break;
417 if (!currentnode) break;
418 // printf("%s snext=%f density=%f bparam[0]=%f\n", gGeoManager->GetPath(),snext,density,bparam[0]);
419 if (!gGeoManager->IsEntering()) {
420 gGeoManager->SetStep(1.E-3);
421 currentnode = gGeoManager->Step();
422 if (!gGeoManager->IsEntering() || !currentnode) {
423 // printf("ERROR: cannot cross boundary\n");
424 mparam[0] = bparam[0]/step;
425 mparam[1] = bparam[1]/step;
426 mparam[2] = bparam[2]/step;
427 mparam[3] = bparam[3]/step;
428 mparam[5] = bparam[5]/step;
430 mparam[0] = 0.; // if crash of navigation take mean density 0
431 mparam[1] = 1000000; // and infinite rad length
432 return bparam[0]/step;
436 bparam[0] += lparam[0]*1.E-3;
437 bparam[1] += lparam[1]*1.E-3;
438 bparam[2] += lparam[2]*1.E-3;
439 bparam[3] += lparam[3]*1.E-3;
440 bparam[5] += lparam[5]*1.E-3;
443 material = currentnode->GetVolume()->GetMedium()->GetMaterial();
444 lparam[0] = material->GetDensity();
445 lparam[1] = material->GetRadLen();
446 lparam[2] = material->GetA();
447 lparam[3] = material->GetZ();
448 lparam[5] = lparam[3]/lparam[2];
449 if (material->IsMixture()) {
450 lparam[1]*=lparam[0];
451 TGeoMixture * mixture = (TGeoMixture*)material;
454 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
455 sum+= mixture->GetWmixt()[iel];
456 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
460 gGeoManager->FindNextBoundary(length);
461 snext = gGeoManager->GetStep();
463 mparam[0] = bparam[0]/step;
464 mparam[1] = bparam[1]/step;
465 mparam[2] = bparam[2]/step;
466 mparam[3] = bparam[3]/step;
467 mparam[5] = bparam[5]/step;
468 return bparam[0]/step;
472 Double_t AliKalmanTrack::GetConvConst() {
473 return 1000/0.299792458/AliTracker::GetBz();
476 void AliKalmanTrack::SaveLocalConvConst() {
477 //---------------------------------------------------------------------
478 // Saves local conversion constant "curvature (1/cm) -> pt (GeV/c)"
479 //---------------------------------------------------------------------
480 if (AliTracker::UniformField()) {
481 fLocalConvConst=1000/0.299792458/AliTracker::GetBz();
483 Float_t r[3]; GetXYZ(r);
484 fLocalConvConst=1000/0.299792458/AliTracker::GetBz(r);