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 AliHelix class
20 // Origin: Marian Ivanov, CERN, marian.ivanov@cern.ch
21 //-------------------------------------------------------------------------
25 #include "AliKalmanTrack.h"
26 #include "AliTracker.h"
31 //_______________________________________________________________________
35 // Default constructor
37 for (Int_t i =0;i<9;i++) fHelix[i]=0;
40 //_______________________________________________________________________
41 AliHelix::AliHelix(const AliHelix &t):TObject(t){
44 for (Int_t i=0;i<9;i++)
45 fHelix[i]=t.fHelix[i];
48 AliHelix::AliHelix(const AliKalmanTrack &t)
52 Double_t alpha,x,cs,sn;
53 t.GetExternalParameters(x,fHelix);
57 //PH Sometimes fP4 and fHelix[4] are very big and the calculation
58 //PH of the Sqrt cannot be done. To be investigated...
59 fHelix[4]=fHelix[4]/(1000/0.299792458/AliTracker::GetBz()); // C
60 cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
65 Double_t dummy = 1-(x-xc)*(x-xc)*fHelix[4]*fHelix[4];
67 AliError(Form("The argument of the Sqrt is %f => set to 0\n",dummy));
70 yc = fHelix[0]+TMath::Sqrt(dummy)/fHelix[4];
72 fHelix[6] = xc*cs - yc*sn;
73 fHelix[7] = xc*sn + yc*cs;
74 fHelix[8] = TMath::Abs(rc);
77 fHelix[5]=x*cs - fHelix[0]*sn; // x0
78 fHelix[0]=x*sn + fHelix[0]*cs; // y0
80 fHelix[2]=TMath::ATan2(-(fHelix[5]-fHelix[6]),fHelix[0]-fHelix[7]); // phi0
81 if (fHelix[4]>0) fHelix[2]-=TMath::Pi();
86 fHelix[5] = fHelix[6];
87 fHelix[0] = fHelix[7];
91 AliHelix::AliHelix(const AliExternalTrackParam &t)
95 Double_t alpha,x,cs,sn;
96 const Double_t *param =t.GetParameter();
97 for (Int_t i=0;i<5;i++) fHelix[i]=param[i];
102 //PH Sometimes fP4 and fHelix[4] are very big and the calculation
103 //PH of the Sqrt cannot be done. To be investigated...
104 fHelix[4]=fHelix[4]/(1000/0.299792458/AliTracker::GetBz()); // C
105 cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
110 Double_t dummy = 1-(x-xc)*(x-xc)*fHelix[4]*fHelix[4];
112 AliError(Form("The argument of the Sqrt is %f => set to 0\n",dummy));
115 yc = fHelix[0]+TMath::Sqrt(dummy)/fHelix[4];
117 fHelix[6] = xc*cs - yc*sn;
118 fHelix[7] = xc*sn + yc*cs;
119 fHelix[8] = TMath::Abs(rc);
122 fHelix[5]=x*cs - fHelix[0]*sn; // x0
123 fHelix[0]=x*sn + fHelix[0]*cs; // y0
125 fHelix[2]=TMath::ASin(fHelix[2]) + alpha; // phi0
129 fHelix[5] = fHelix[6];
130 fHelix[0] = fHelix[7];
133 AliHelix::AliHelix(Double_t x[3], Double_t p[3], Double_t charge, Double_t conversion)
138 Double_t pt = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
139 if (TMath::Abs(conversion)<0.00000001)
140 conversion = 1000/0.299792458/AliTracker::GetBz();
143 fHelix[4] = charge/(conversion*pt); // C
144 fHelix[3] = p[2]/pt; // tgl
148 xc = x[0] -rc*p[1]/pt;
149 yc = x[1] +rc*p[0]/pt;
151 fHelix[5] = x[0]; // x0
152 fHelix[0] = x[1]; // y0
153 fHelix[1] = x[2]; // z0
157 fHelix[8] = TMath::Abs(rc);
162 if (TMath::Abs(p[1])<TMath::Abs(p[0])){
163 fHelix[2]=TMath::ASin(p[1]/pt);
164 if (charge*yc<charge*x[1]) fHelix[2] = TMath::Pi()-fHelix[2];
167 fHelix[2]=TMath::ACos(p[0]/pt);
168 if (charge*xc>charge*x[0]) fHelix[2] = -fHelix[2];
173 void AliHelix::GetMomentum(Double_t phase, Double_t p[4],Double_t conversion, Double_t *xr)
175 // return momentum at given phase
176 Double_t x[3],g[3],gg[3];
177 Evaluate(phase,x,g,gg);
178 if (TMath::Abs(conversion)<0.0001) conversion = 1000/0.299792458/AliTracker::GetBz();
179 Double_t mt = TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
180 p[0] = fHelix[8]*g[0]/(mt*conversion);
181 p[1] = fHelix[8]*g[1]/(mt*conversion);
182 p[2] = fHelix[8]*g[2]/(mt*conversion);
184 xr[0] = x[0]; xr[1] = x[1]; xr[2] = x[2];
188 void AliHelix::GetAngle(Double_t t1, AliHelix &h, Double_t t2, Double_t angle[3])
193 Double_t x1[3],g1[3],gg1[3];
194 Double_t x2[3],g2[3],gg2[3];
195 Evaluate(t1,x1,g1,gg1);
196 h.Evaluate(t2,x2,g2,gg2);
199 Double_t norm1r = g1[0]*g1[0]+g1[1]*g1[1];
200 Double_t norm1 = TMath::Sqrt(norm1r+g1[2]*g1[2]);
201 norm1r = TMath::Sqrt(norm1r);
203 Double_t norm2r = g2[0]*g2[0]+g2[1]*g2[1];
204 Double_t norm2 = TMath::Sqrt(norm2r+g2[2]*g2[2]);
205 norm2r = TMath::Sqrt(norm2r);
207 angle[0] = (g1[0]*g2[0]+g1[1]*g2[1])/(norm1r*norm2r); // angle in phi projection
208 if (TMath::Abs(angle[0])<1.) angle[0] = TMath::ACos(angle[0]);
210 if (angle[0]>0) angle[0] = 0;
211 if (angle[0]<0) angle[0] = TMath::Pi();
214 angle[1] = ((norm1r*norm2r)+g1[2]*g2[2])/(norm1*norm2); // angle in rz projection
215 if (TMath::Abs(angle[1])<1.) angle[1] = TMath::ACos(angle[1]);
219 angle[2] = (g1[0]*g2[0]+g1[1]*g2[1]+g1[2]*g2[2])/(norm1*norm2); //3D angle
220 if (TMath::Abs(angle[2])<1.) angle[2] = TMath::ACos(angle[2]);
230 void AliHelix::Evaluate(Double_t t,
231 Double_t r[3], //radius vector
232 Double_t g[3], //first defivatives
233 Double_t gg[3]) //second derivatives
235 //--------------------------------------------------------------------
236 // Calculate position of a point on a track and some derivatives at given phase
237 //--------------------------------------------------------------------
238 Double_t phase=fHelix[4]*t+fHelix[2];
239 Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
241 r[0] = fHelix[5] + sn/fHelix[4];
242 r[1] = fHelix[0] - cs/fHelix[4];
243 r[2] = fHelix[1] + fHelix[3]*t;
245 g[0] = cs; g[1]=sn; g[2]=fHelix[3];
247 gg[0]=-fHelix[4]*sn; gg[1]=fHelix[4]*cs; gg[2]=0.;
250 Int_t AliHelix::GetClosestPhases(AliHelix &h, Double_t phase[2][2])
253 // get phases to minimize distances
258 for (Int_t i=0;i<2;i++){
259 Evaluate(phase[i][0] ,xyz0);
260 h.Evaluate(phase[i][1],xyz1);
261 Double_t mindist = TMath::Sqrt((xyz0[0]-xyz1[0])*(xyz0[0]-xyz1[0])+
262 (xyz0[1]-xyz1[1])*(xyz0[1]-xyz1[1])+
263 (xyz0[2]-xyz1[2])*(xyz0[2]-xyz1[2]));
264 Double_t tbest[2]={phase[i][0],phase[i][1]};
265 for (Int_t i0=-1;i0<=1;i0++){
266 Double_t t0 = ((phase[i][0]*fHelix[4])+i0*2.*TMath::Pi())/fHelix[4];
268 for (Int_t i1=-1;i1<=1;i1++){
269 Double_t t1 = ((phase[i][1]*h.fHelix[4])+i1*2.*TMath::Pi())/h.fHelix[4];
271 Double_t dist = TMath::Sqrt((xyz0[0]-xyz1[0])*(xyz0[0]-xyz1[0])+
272 (xyz0[1]-xyz1[1])*(xyz0[1]-xyz1[1])+
273 (xyz0[2]-xyz1[2])*(xyz0[2]-xyz1[2]));
281 phase[i][0] = tbest[0];
282 phase[i][1] = tbest[1];
287 Double_t AliHelix::GetPointAngle(AliHelix &h, Double_t phase[2], const Float_t * vertex)
290 // get point angle bettwen two helixes
292 Double_t r0[3],p0[4];
293 Double_t r1[3],p1[4];
294 GetMomentum(phase[0],p0,1,r0);
295 h.GetMomentum(phase[1],p1,1,r1);
297 Double_t r[3] = {(r0[0]+r1[0])*0.5-vertex[0],(r0[1]+r1[1])*0.5-vertex[1],(r0[2]+r1[2])*0.5-vertex[2]};
298 //intersection point - relative to the prim vertex
299 Double_t p[3] = { p0[0]+p1[0], p0[1]+p1[1],p0[2]+p1[2]};
301 Double_t normr = TMath::Sqrt(r[0]*r[0]+r[1]*r[1]+r[2]*r[2]);
302 Double_t normp = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]+p[2]*p[2]);
303 Double_t pointAngle = (r[0]*p[0]+r[1]*p[1]+r[2]*p[2])/(normr*normp);
307 Double_t AliHelix::GetPhase(Double_t x, Double_t y )
311 //calculate helix param at given x,y point
313 //Double_t phase2 = TMath::ATan2((y-fHelix[0]), (x-fHelix[5]))- TMath::Pi()/2.;
314 Double_t phase2 = TMath::ATan2(-(x-fHelix[5]),(y-fHelix[0]));
315 Int_t sign = (fHelix[4]>0)? 1:-1;
316 if (sign>0) phase2 = phase2-TMath::Pi();
318 Float_t delta = TMath::Nint((phase2-fHelix[2])/(2.*TMath::Pi()));
319 phase2-= 2*TMath::Pi()*delta;
320 if ( (phase2-fHelix[2])>TMath::Pi()) phase2 -=2.*TMath::Pi();
321 if ( (phase2-fHelix[2])<-TMath::Pi()) phase2+=2.*TMath::Pi();
323 Double_t t = (phase2-fHelix[2]);
328 Int_t AliHelix::GetPhase(Double_t /*r0*/, Double_t * /*t[2]*/)
331 //calculate helix param at given r point - return nearest point ()
333 // not implemented yet
340 Double_t AliHelix::GetPhaseZ(Double_t z0)
344 return (z0-fHelix[1])/fHelix[3];
348 Int_t AliHelix::GetRPHIintersections(AliHelix &h, Double_t phase[2][2], Double_t ri[2], Double_t cut)
350 //--------------------------------------------------------------------
351 // This function returns phase vectors with intesection between helix (0, 1 or 2)
352 // in x-y plane projection
353 //--------------------------------------------------------------------
355 // Double_t * c1 = &fHelix[6];
356 //Double_t * c2 = &(h.fHelix[6]);
357 // Double_t c1[3] = {fHelix[5],fHelix[0],fHelix[8]};
359 // PH initiaziation in case of return
360 phase[0][0]=phase[0][1]=phase[1][0]=phase[1][1]=0;
363 Double_t c1[3] = {0,0,fHelix[8]};
364 Double_t c2[3] = {h.fHelix[5]-fHelix[5],h.fHelix[0]-fHelix[0],h.fHelix[8]};
366 Double_t d = TMath::Sqrt(c2[0]*c2[0]+c2[1]*c2[1]);
367 if (d<0.000000000001) return 0;
372 if ( d>=(c1[2]+c2[2])){
373 if (d>=(c1[2]+c2[2]+cut)) return 0;
374 x0[0] = (d+c1[2]-c2[2])*c2[0]/(2*d)+ fHelix[5];
375 y0[0] = (d+c1[2]-c2[2])*c2[1]/(2*d)+ fHelix[0];
377 phase[1][0] = phase[0][0] = GetPhase(x0[0],y0[0]);
378 phase[1][1] = phase[0][1] = h.GetPhase(x0[0],y0[0]);
379 ri[1] = ri[0] = x0[0]*x0[0]+y0[0]*y0[0];
382 if ( (d+c2[2])<c1[2]){
383 if ( (d+c2[2])+cut<c1[2]) return 0;
385 Double_t xx = c2[0]+ c2[0]*c2[2]/d+ fHelix[5];
386 Double_t yy = c2[1]+ c2[1]*c2[2]/d+ fHelix[0];
387 phase[1][1] = phase[0][1] = h.GetPhase(xx,yy);
389 Double_t xx2 = c2[0]*c1[2]/d+ fHelix[5];
390 Double_t yy2 = c2[1]*c1[2]/d+ fHelix[0];
391 phase[1][0] = phase[0][0] = GetPhase(xx2,yy2);
392 ri[1] = ri[0] = xx*xx+yy*yy;
396 if ( (d+c1[2])<c2[2]){
397 if ( (d+c1[2])+cut<c2[2]) return 0;
399 Double_t xx = -c2[0]*c1[2]/d+ fHelix[5];
400 Double_t yy = -c2[1]*c1[2]/d+ fHelix[0];
401 phase[1][1] = phase[0][1] = GetPhase(xx,yy);
403 Double_t xx2 = c2[0]- c2[0]*c2[2]/d+ fHelix[5];
404 Double_t yy2 = c2[1]- c2[1]*c2[2]/d+ fHelix[0];
405 phase[1][0] = phase[0][0] = h.GetPhase(xx2,yy2);
406 ri[1] = ri[0] = xx*xx+yy*yy;
410 Double_t d1 = (d*d+c1[2]*c1[2]-c2[2]*c2[2])/(2.*d);
411 Double_t v1 = c1[2]*c1[2]-d1*d1;
413 v1 = TMath::Sqrt(v1);
415 x0[0] = (c2[0]*d1+c2[1]*v1)/d + fHelix[5];
416 y0[0] = (c2[1]*d1-c2[0]*v1)/d + fHelix[0];
418 x0[1] = (c2[0]*d1-c2[1]*v1)/d + fHelix[5];
419 y0[1] = (c2[1]*d1+c2[0]*v1)/d + fHelix[0];
421 for (Int_t i=0;i<2;i++){
422 phase[i][0] = GetPhase(x0[i],y0[i]);
423 phase[i][1] = h.GetPhase(x0[i],y0[i]);
424 ri[i] = x0[i]*x0[i]+y0[i]*y0[i];
431 Int_t AliHelix::LinearDCA(AliHelix &h, Double_t &t1, Double_t &t2,
432 Double_t &R, Double_t &dist)
436 // find intersection using linear approximation
437 Double_t r1[3],g1[3],gg1[3];
438 Double_t r2[3],g2[3],gg2[3];
440 Evaluate(t1,r1,g1,gg1);
441 h.Evaluate(t2,r2,g2,gg2);
443 Double_t g1_2 = g1[0]*g1[0] +g1[1]*g1[1] +g1[2]*g1[2];
444 Double_t g2_2 = g2[0]*g2[0] +g2[1]*g2[1] +g2[2]*g2[2];
445 Double_t g1x2 = g1[0]*g2[0] +g1[1]*g2[1] +g1[2]*g2[2];
446 Double_t det = g1_2*g2_2 - g1x2*g1x2;
448 if (TMath::Abs(det)>0){
450 Double_t r1g1 = r1[0]*g1[0] +r1[1]*g1[1] +r1[2]*g1[2];
451 Double_t r2g1 = r2[0]*g1[0] +r2[1]*g1[1] +r2[2]*g1[2];
452 Double_t r1g2 = r1[0]*g2[0] +r1[1]*g2[1] +r1[2]*g2[2];
453 Double_t r2g2 = r2[0]*g2[0] +r2[1]*g2[1] +r2[2]*g2[2];
455 Double_t dt = - ( g2_2*(r1g1-r2g1) - g1x2*(r1g2-r2g2)) / det;
456 Double_t dp = - ( g1_2*(r2g2-r1g2) - g1x2*(r2g1-r1g1)) / det;
463 dist = (r1[0]-r2[0])*(r1[0]-r2[0])+
464 (r1[1]-r2[1])*(r1[1]-r2[1])+
465 (r1[2]-r2[2])*(r1[2]-r2[2]);
466 R = ((r1[0]+r2[0])*(r1[0]+r2[0])+(r1[1]+r2[1])*(r1[1]+r2[1]))/4.;
472 Int_t AliHelix::ParabolicDCA(AliHelix&h, //helixes
473 Double_t &t1, Double_t &t2,
474 Double_t &R, Double_t &dist, Int_t iter)
478 // find intersection using linear fit
479 Double_t r1[3],g1[3],gg1[3];
480 Double_t r2[3],g2[3],gg2[3];
482 Evaluate(t1,r1,g1,gg1);
483 h.Evaluate(t2,r2,g2,gg2);
490 Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
491 Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
496 Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
497 Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
499 Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 +
500 (g1[1]*g1[1] - dy*gg1[1])/dy2 +
501 (g1[2]*g1[2] - dz*gg1[2])/dz2;
502 Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 +
503 (g2[1]*g2[1] + dy*gg2[1])/dy2 +
504 (g2[2]*g2[2] + dz*gg2[2])/dz2;
505 Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
507 Double_t det=h11*h22-h12*h12;
510 if (TMath::Abs(det)<1.e-33) {
511 //(quasi)singular Hessian
514 dt1=-(gt1*h22 - gt2*h12)/det;
515 dt2=-(h11*gt2 - h12*gt1)/det;
518 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
520 //if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
521 // if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
526 for (Int_t div=1 ; div<512 ; div*=2) {
527 Evaluate(t1+dt1,r1,g1,gg1);
528 h.Evaluate(t2+dt2,r2,g2,gg2);
529 dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
530 dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
544 Evaluate(t1,r1,g1,gg1);
545 h.Evaluate(t2,r2,g2,gg2);
547 dist = (r1[0]-r2[0])*(r1[0]-r2[0])+
548 (r1[1]-r2[1])*(r1[1]-r2[1])+
549 (r1[2]-r2[2])*(r1[2]-r2[2]);
551 R = ((r1[0]+r2[0])*(r1[0]+r2[0])+(r1[1]+r2[1])*(r1[1]+r2[1]))/4;
557 Int_t AliHelix::ParabolicDCA2(AliHelix&h, //helixes
558 Double_t &t1, Double_t &t2,
559 Double_t &R, Double_t &dist, Double_t err[3], Int_t iter)
563 // find intersection using linear fit
564 Double_t r1[3],g1[3],gg1[3];
565 Double_t r2[3],g2[3],gg2[3];
567 Evaluate(t1,r1,g1,gg1);
568 h.Evaluate(t2,r2,g2,gg2);
575 Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
576 Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
581 Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
582 Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
584 Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 +
585 (g1[1]*g1[1] - dy*gg1[1])/dy2 +
586 (g1[2]*g1[2] - dz*gg1[2])/dz2;
587 Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 +
588 (g2[1]*g2[1] + dy*gg2[1])/dy2 +
589 (g2[2]*g2[2] + dz*gg2[2])/dz2;
590 Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
592 Double_t det=h11*h22-h12*h12;
595 if (TMath::Abs(det)<1.e-33) {
596 //(quasi)singular Hessian
599 dt1=-(gt1*h22 - gt2*h12)/det;
600 dt2=-(h11*gt2 - h12*gt1)/det;
603 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
605 //if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
606 // if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
611 for (Int_t div=1 ; div<512 ; div*=2) {
612 Evaluate(t1+dt1,r1,g1,gg1);
613 h.Evaluate(t2+dt2,r2,g2,gg2);
614 dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
615 dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
629 Evaluate(t1,r1,g1,gg1);
630 h.Evaluate(t2,r2,g2,gg2);
632 dist = (r1[0]-r2[0])*(r1[0]-r2[0])+
633 (r1[1]-r2[1])*(r1[1]-r2[1])+
634 (r1[2]-r2[2])*(r1[2]-r2[2]);
636 R = ((r1[0]+r2[0])*(r1[0]+r2[0])+(r1[1]+r2[1])*(r1[1]+r2[1]))/4;