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 //-------------------------------------------------------------------------
24 #include "AliKalmanTrack.h"
25 #include "TGeoManager.h"
27 ClassImp(AliKalmanTrack)
29 const AliMagF *AliKalmanTrack::fgkFieldMap=0;
30 Double_t AliKalmanTrack::fgConvConst=0.;
32 //_______________________________________________________________________
33 AliKalmanTrack::AliKalmanTrack():
37 fMass(AliPID::ParticleMass(AliPID::kPion)),
40 fStartTimeIntegral(kFALSE),
44 // Default constructor
47 AliFatal("The magnetic field has not been set!");
50 for(Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i] = 0;
53 //_______________________________________________________________________
54 AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
57 fFakeRatio(t.fFakeRatio),
61 fLocalConvConst(t.fLocalConvConst),
62 fStartTimeIntegral(t.fStartTimeIntegral),
63 fIntegratedLength(t.fIntegratedLength)
69 AliFatal("The magnetic field has not been set!");
72 for (Int_t i=0; i<AliPID::kSPECIES; i++)
73 fIntegratedTime[i] = t.fIntegratedTime[i];
76 //_______________________________________________________________________
77 void AliKalmanTrack::StartTimeIntegral()
79 // Sylwester Radomski, GSI
82 // Start time integration
83 // To be called at Vertex by ITS tracker
86 //if (fStartTimeIntegral)
87 // AliWarning("Reseting Recorded Time.");
89 fStartTimeIntegral = kTRUE;
90 for(Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i] = 0;
91 fIntegratedLength = 0;
93 //_______________________________________________________________________
94 void AliKalmanTrack:: AddTimeStep(Double_t length)
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.
102 // If integration not started function does nothing
105 // dt = dl * sqrt(p^2 + m^2) / p
106 // p = pT * (1 + tg^2 (lambda) )
108 // pt = 1/external parameter [4]
109 // tg lambda = external parameter [3]
112 // Sylwester Radomski, GSI
116 static const Double_t kcc = 2.99792458e-2;
118 if (!fStartTimeIntegral) return;
120 fIntegratedLength += length;
122 Double_t xr, param[5];
125 GetExternalParameters(xr, param);
129 Double_t p = TMath::Abs(pt * TMath::Sqrt(1+tgl*tgl));
131 if (length > 100) return;
133 for (Int_t i=0; i<AliPID::kSPECIES; i++) {
135 Double_t mass = AliPID::ParticleMass(i);
136 Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
137 Double_t time = length * correction / kcc;
139 fIntegratedTime[i] += time;
143 //_______________________________________________________________________
145 Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const
147 // Sylwester Radomski, GSI
150 // Return integrated time hypothesis for a given particle
154 // pdg - Pdg code of a particle type
158 if (!fStartTimeIntegral) {
159 AliWarning("Time integration not started");
163 for (Int_t i=0; i<AliPID::kSPECIES; i++)
164 if (AliPID::ParticleCode(i) == TMath::Abs(pdg)) return fIntegratedTime[i];
166 AliWarning(Form("Particle type [%d] not found", pdg));
170 void AliKalmanTrack::GetIntegratedTimes(Double_t *times) const {
171 for (Int_t i=0; i<AliPID::kSPECIES; i++) times[i]=fIntegratedTime[i];
174 void AliKalmanTrack::SetIntegratedTimes(const Double_t *times) {
175 for (Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i]=times[i];
178 //_______________________________________________________________________
180 void AliKalmanTrack::PrintTime() const
182 // Sylwester Radomski, GSI
186 // Prints time for all hypothesis
189 for (Int_t i=0; i<AliPID::kSPECIES; i++)
190 printf("%d: %.2f ", AliPID::ParticleCode(i), fIntegratedTime[i]);
194 void AliKalmanTrack::External2Helix(Double_t helix[6]) const {
195 //--------------------------------------------------------------------
196 // External track parameters -> helix parameters
197 //--------------------------------------------------------------------
198 Double_t alpha,x,cs,sn;
199 GetExternalParameters(x,helix); alpha=GetAlpha();
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
205 helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
207 helix[4]=helix[4]/GetLocalConvConst(); // C
210 static 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
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);
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;
225 g[0] = cs; g[1]=sn; g[2]=h[3];
227 gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
230 Double_t AliKalmanTrack::
231 GetDCA(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();
244 Double_t p1[8]; External2Helix(p1);
245 p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
246 Double_t p2[8]; p->External2Helix(p2);
247 p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
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);
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;
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);
270 Double_t det=h11*h22-h12*h12;
273 if (TMath::Abs(det)<1.e-33) {
274 //(quasi)singular Hessian
277 dt1=-(gt1*h22 - gt2*h12)/det;
278 dt2=-(h11*gt2 - h12*gt1)/det;
281 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
283 //check delta(phase1) ?
284 //check delta(phase2) ?
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)
289 AliWarning(" stopped at not a stationary point !");
290 Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
292 AliWarning(" stopped at not a minimum !");
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;
305 AliWarning(" overshoot !"); break;
315 if (max<=0) AliWarning(" too many iterations !");
317 Double_t cs=TMath::Cos(GetAlpha());
318 Double_t sn=TMath::Sin(GetAlpha());
319 xthis=r1[0]*cs + r1[1]*sn;
321 cs=TMath::Cos(p->GetAlpha());
322 sn=TMath::Sin(p->GetAlpha());
323 xp=r2[0]*cs + r2[1]*sn;
325 return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
328 Double_t AliKalmanTrack::
329 PropagateToDCA(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 //--------------------------------------------------------------
336 Double_t dca=GetDCA(p,xthis,xp);
338 if (!PropagateTo(xthis,d,x0)) {
339 //AliWarning(" propagation failed !");
343 if (!p->PropagateTo(xp,d,x0)) {
344 //AliWarning(" propagation failed !";
355 Double_t AliKalmanTrack::MeanMaterialBudget(Double_t *start, Double_t *end, Double_t *mparam)
358 // calculate mean material budget and material properties beween point start and end
359 // mparam - returns parameters used for dEdx and multiple scatering
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
369 mparam[0]=0; mparam[1]=1; mparam[2] =0; mparam[3] =0, mparam[4]=0, mparam[5]=0; mparam[6]=0;
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; //
375 printf("ERROR: no TGeo\n");
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]));
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);
395 printf("ERROR: start point out of geometry\n");
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;
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];
415 gGeoManager->FindNextBoundary(length);
416 Double_t snext = gGeoManager->GetStep();
418 // If no boundary within proposed length, return current density
420 for (Int_t ip=0;ip<5;ip++) mparam[ip] = lparam[ip];
423 // Try to cross the boundary and see what is next
424 while (length>TGeoShape::Tolerance()) {
426 currentnode = gGeoManager->Step();
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];
434 if (snext>=length) break;
435 if (!currentnode) break;
436 // printf("%s snext=%f density=%f bparam[0]=%f\n", gGeoManager->GetPath(),snext,density,bparam[0]);
437 if (!gGeoManager->IsEntering()) {
438 gGeoManager->SetStep(1.E-3);
439 currentnode = gGeoManager->Step();
440 if (!gGeoManager->IsEntering() || !currentnode) {
441 // printf("ERROR: cannot cross boundary\n");
442 mparam[0] = bparam[0]/step;
443 mparam[1] = bparam[1]/step;
444 mparam[2] = bparam[2]/step;
445 mparam[3] = bparam[3]/step;
446 mparam[5] = bparam[5]/step;
448 mparam[0] = 0.; // if crash of navigation take mean density 0
449 mparam[1] = 1000000; // and infinite rad length
450 return bparam[0]/step;
454 bparam[0] += lparam[0]*1.E-3;
455 bparam[1] += lparam[1]*1.E-3;
456 bparam[2] += lparam[2]*1.E-3;
457 bparam[3] += lparam[3]*1.E-3;
458 bparam[5] += lparam[5]*1.E-3;
461 material = currentnode->GetVolume()->GetMedium()->GetMaterial();
462 lparam[0] = material->GetDensity();
463 lparam[1] = material->GetRadLen();
464 lparam[2] = material->GetA();
465 lparam[3] = material->GetZ();
466 lparam[5] = lparam[3]/lparam[2];
467 if (material->IsMixture()) {
468 lparam[1]*=lparam[0];
469 TGeoMixture * mixture = (TGeoMixture*)material;
472 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
473 sum+= mixture->GetWmixt()[iel];
474 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
478 gGeoManager->FindNextBoundary(length);
479 snext = gGeoManager->GetStep();
481 mparam[0] = bparam[0]/step;
482 mparam[1] = bparam[1]/step;
483 mparam[2] = bparam[2]/step;
484 mparam[3] = bparam[3]/step;
485 mparam[5] = bparam[5]/step;
486 return bparam[0]/step;