]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliHelix.cxx
Clean-up in includes.
[u/mrichter/AliRoot.git] / STEER / AliHelix.cxx
CommitLineData
7f572c00 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
16/* $Id$ */
17
18//-------------------------------------------------------------------------
19// Implementation of the AliHelix class
20// Origin: Marian Ivanov, CERN, marian.ivanov@cern.ch
21//-------------------------------------------------------------------------
22
23
24#include "AliHelix.h"
25#include "AliKalmanTrack.h"
6c94f330 26#include "AliTracker.h"
7f572c00 27#include "TMath.h"
28ClassImp(AliHelix)
29
30
31//_______________________________________________________________________
32AliHelix::AliHelix()
33{
34 //
35 // Default constructor
36 //
37 for (Int_t i =0;i<9;i++) fHelix[i]=0;
38}
39
40//_______________________________________________________________________
176aff27 41AliHelix::AliHelix(const AliHelix &t):TObject(t){
7f572c00 42 //
43 //
44 for (Int_t i=0;i<9;i++)
45 fHelix[i]=t.fHelix[i];
46}
47
48AliHelix::AliHelix(const AliKalmanTrack &t)
49{
50 //
51 //
52 Double_t alpha,x,cs,sn;
53 t.GetExternalParameters(x,fHelix);
54 alpha=t.GetAlpha();
55 //
56 //circle parameters
022ba35d 57 //PH Sometimes fP4 and fHelix[4] are very big and the calculation
58 //PH of the Sqrt cannot be done. To be investigated...
6c94f330 59 fHelix[4]=fHelix[4]/(1000/0.299792458/AliTracker::GetBz()); // C
7f572c00 60 cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
61
62 Double_t xc, yc, rc;
63 rc = 1/fHelix[4];
64 xc = x-fHelix[2]*rc;
022ba35d 65 Double_t dummy = 1-(x-xc)*(x-xc)*fHelix[4]*fHelix[4];
66 if (dummy<0) {
67 AliError(Form("The argument of the Sqrt is %f => set to 0\n",dummy));
68 dummy = 0;
69 }
70 yc = fHelix[0]+TMath::Sqrt(dummy)/fHelix[4];
7f572c00 71
72 fHelix[6] = xc*cs - yc*sn;
73 fHelix[7] = xc*sn + yc*cs;
74 fHelix[8] = TMath::Abs(rc);
75 //
76 //
77 fHelix[5]=x*cs - fHelix[0]*sn; // x0
78 fHelix[0]=x*sn + fHelix[0]*cs; // y0
79 //fHelix[1]= // z0
9be2fe3a 80 fHelix[2]=TMath::ATan2(-(fHelix[5]-fHelix[6]),fHelix[0]-fHelix[7]); // phi0
81 if (fHelix[4]>0) fHelix[2]-=TMath::Pi();
82
7f572c00 83 //fHelix[3]= // tgl
84 //
85 //
86 fHelix[5] = fHelix[6];
87 fHelix[0] = fHelix[7];
7f572c00 88}
89
51ad6848 90
91AliHelix::AliHelix(const AliExternalTrackParam &t)
92{
93 //
94 //
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];
c9ec41e8 98 x = t.GetX();
99 alpha=t.GetAlpha();
51ad6848 100 //
101 //circle parameters
022ba35d 102 //PH Sometimes fP4 and fHelix[4] are very big and the calculation
103 //PH of the Sqrt cannot be done. To be investigated...
6c94f330 104 fHelix[4]=fHelix[4]/(1000/0.299792458/AliTracker::GetBz()); // C
51ad6848 105 cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
106
107 Double_t xc, yc, rc;
108 rc = 1/fHelix[4];
109 xc = x-fHelix[2]*rc;
022ba35d 110 Double_t dummy = 1-(x-xc)*(x-xc)*fHelix[4]*fHelix[4];
111 if (dummy<0) {
112 AliError(Form("The argument of the Sqrt is %f => set to 0\n",dummy));
113 dummy = 0;
114 }
115 yc = fHelix[0]+TMath::Sqrt(dummy)/fHelix[4];
51ad6848 116
117 fHelix[6] = xc*cs - yc*sn;
118 fHelix[7] = xc*sn + yc*cs;
119 fHelix[8] = TMath::Abs(rc);
120 //
121 //
122 fHelix[5]=x*cs - fHelix[0]*sn; // x0
123 fHelix[0]=x*sn + fHelix[0]*cs; // y0
124 //fHelix[1]= // z0
125 fHelix[2]=TMath::ASin(fHelix[2]) + alpha; // phi0
126 //fHelix[3]= // tgl
127 //
128 //
129 fHelix[5] = fHelix[6];
130 fHelix[0] = fHelix[7];
51ad6848 131}
132
7f572c00 133AliHelix::AliHelix(Double_t x[3], Double_t p[3], Double_t charge, Double_t conversion)
134{
135 //
136 //
137 //
138 Double_t pt = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
139 if (TMath::Abs(conversion)<0.00000001)
6c94f330 140 conversion = 1000/0.299792458/AliTracker::GetBz();
7f572c00 141 //
142 //
143 fHelix[4] = charge/(conversion*pt); // C
144 fHelix[3] = p[2]/pt; // tgl
145 //
146 Double_t xc, yc, rc;
147 rc = 1/fHelix[4];
148 xc = x[0] -rc*p[1]/pt;
149 yc = x[1] +rc*p[0]/pt;
150 //
151 fHelix[5] = x[0]; // x0
152 fHelix[0] = x[1]; // y0
153 fHelix[1] = x[2]; // z0
154 //
155 fHelix[6] = xc;
156 fHelix[7] = yc;
157 fHelix[8] = TMath::Abs(rc);
158 //
159 fHelix[5]=xc;
160 fHelix[0]=yc;
161 //
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];
165 }
166 else{
167 fHelix[2]=TMath::ACos(p[0]/pt);
168 if (charge*xc>charge*x[0]) fHelix[2] = -fHelix[2];
169 }
170
171}
172
81e97e0d 173void AliHelix::GetMomentum(Double_t phase, Double_t p[4],Double_t conversion, Double_t *xr)
7f572c00 174{
175 // return momentum at given phase
176 Double_t x[3],g[3],gg[3];
177 Evaluate(phase,x,g,gg);
6c94f330 178 if (TMath::Abs(conversion)<0.0001) conversion = 1000/0.299792458/AliTracker::GetBz();
7f572c00 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);
81e97e0d 183 if (xr){
184 xr[0] = x[0]; xr[1] = x[1]; xr[2] = x[2];
185 }
7f572c00 186}
187
188void AliHelix::GetAngle(Double_t t1, AliHelix &h, Double_t t2, Double_t angle[3])
189{
190 //
191 //
192 //
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);
197
198 //
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);
202 //
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);
206 //
51ad6848 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]);
9be2fe3a 209 else{
210 if (angle[0]>0) angle[0] = 0;
211 if (angle[0]<0) angle[0] = TMath::Pi();
212 }
51ad6848 213 //
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]);
9be2fe3a 216 else
217 angle[1]=0;
51ad6848 218
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]);
9be2fe3a 221 else
222 angle[2]=0;
7f572c00 223
51ad6848 224
7f572c00 225
226
227}
228
229
230void 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
234{
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);
240
7f572c00 241 r[0] = fHelix[5] + sn/fHelix[4];
242 r[1] = fHelix[0] - cs/fHelix[4];
243 r[2] = fHelix[1] + fHelix[3]*t;
244
245 g[0] = cs; g[1]=sn; g[2]=fHelix[3];
246
247 gg[0]=-fHelix[4]*sn; gg[1]=fHelix[4]*cs; gg[2]=0.;
248}
249
9be2fe3a 250Int_t AliHelix::GetClosestPhases(AliHelix &h, Double_t phase[2][2])
251{
252 //
253 // get phases to minimize distances
254 //
255 Double_t xyz0[3];
256 Double_t xyz1[3];
257
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];
267 Evaluate(t0,xyz0);
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];
270 h.Evaluate(t1,xyz1);
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]));
274 if (dist<=mindist){
275 tbest[0] = t0;
276 tbest[1] = t1;
277 mindist=dist;
278 }
279 }
280 }
281 phase[i][0] = tbest[0];
282 phase[i][1] = tbest[1];
283 }
284 return 1;
285}
286
81e97e0d 287Double_t AliHelix::GetPointAngle(AliHelix &h, Double_t phase[2], const Float_t * vertex)
288{
289 //
290 // get point angle bettwen two helixes
291 //
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);
296 //
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]};
300 // derivation vector
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);
304 return pointAngle;
305}
306
7f572c00 307Double_t AliHelix::GetPhase(Double_t x, Double_t y )
308
309{
310 //
311 //calculate helix param at given x,y point
312 //
9be2fe3a 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();
317 //
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();
7f572c00 322
9be2fe3a 323 Double_t t = (phase2-fHelix[2]);
324 t/=fHelix[4];
7f572c00 325 return t;
326}
327
176aff27 328Int_t AliHelix::GetPhase(Double_t /*r0*/, Double_t * /*t[2]*/)
7f572c00 329{
330 //
331 //calculate helix param at given r point - return nearest point ()
332 //
333 // not implemented yet
334
335
336 return 0;
337}
338
339
340Double_t AliHelix::GetPhaseZ(Double_t z0)
341{
342 //
343 //
344 return (z0-fHelix[1])/fHelix[3];
345}
346
347
348Int_t AliHelix::GetRPHIintersections(AliHelix &h, Double_t phase[2][2], Double_t ri[2], Double_t cut)
349{
350 //--------------------------------------------------------------------
351 // This function returns phase vectors with intesection between helix (0, 1 or 2)
352 // in x-y plane projection
353 //--------------------------------------------------------------------
354 //
355 // Double_t * c1 = &fHelix[6];
356 //Double_t * c2 = &(h.fHelix[6]);
357 // Double_t c1[3] = {fHelix[5],fHelix[0],fHelix[8]};
9e8f4343 358
359 // PH initiaziation in case of return
360 phase[0][0]=phase[0][1]=phase[1][0]=phase[1][1]=0;
361 ri[0]=ri[1]=1000000;
362
7f572c00 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]};
365
366 Double_t d = TMath::Sqrt(c2[0]*c2[0]+c2[1]*c2[1]);
51ad6848 367 if (d<0.000000000001) return 0;
7f572c00 368 //
369 Double_t x0[2];
370 Double_t y0[2];
371 //
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];
51ad6848 376 // return 0;
9e8f4343 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];
51ad6848 380 return 1;
7f572c00 381 }
382 if ( (d+c2[2])<c1[2]){
383 if ( (d+c2[2])+cut<c1[2]) return 0;
384 //
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];
9e8f4343 387 phase[1][1] = phase[0][1] = h.GetPhase(xx,yy);
7f572c00 388 //
389 Double_t xx2 = c2[0]*c1[2]/d+ fHelix[5];
390 Double_t yy2 = c2[1]*c1[2]/d+ fHelix[0];
9e8f4343 391 phase[1][0] = phase[0][0] = GetPhase(xx2,yy2);
392 ri[1] = ri[0] = xx*xx+yy*yy;
7f572c00 393 return 1;
394 }
395
396 if ( (d+c1[2])<c2[2]){
397 if ( (d+c1[2])+cut<c2[2]) return 0;
398 //
399 Double_t xx = -c2[0]*c1[2]/d+ fHelix[5];
400 Double_t yy = -c2[1]*c1[2]/d+ fHelix[0];
9e8f4343 401 phase[1][1] = phase[0][1] = GetPhase(xx,yy);
7f572c00 402 //
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];
9e8f4343 405 phase[1][0] = phase[0][0] = h.GetPhase(xx2,yy2);
406 ri[1] = ri[0] = xx*xx+yy*yy;
7f572c00 407 return 1;
408 }
409
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;
412 if (v1<0) return 0;
413 v1 = TMath::Sqrt(v1);
414 //
415 x0[0] = (c2[0]*d1+c2[1]*v1)/d + fHelix[5];
416 y0[0] = (c2[1]*d1-c2[0]*v1)/d + fHelix[0];
417 //
418 x0[1] = (c2[0]*d1-c2[1]*v1)/d + fHelix[5];
419 y0[1] = (c2[1]*d1+c2[0]*v1)/d + fHelix[0];
420 //
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];
425 }
426 return 2;
427}
428
7f572c00 429
430
431Int_t AliHelix::LinearDCA(AliHelix &h, Double_t &t1, Double_t &t2,
432 Double_t &R, Double_t &dist)
433{
434 //
435 //
436 // find intersection using linear approximation
437 Double_t r1[3],g1[3],gg1[3];
438 Double_t r2[3],g2[3],gg2[3];
439 //
440 Evaluate(t1,r1,g1,gg1);
441 h.Evaluate(t2,r2,g2,gg2);
442 //
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;
447 //
448 if (TMath::Abs(det)>0){
449 //
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];
454 //
455 Double_t dt = - ( g2_2*(r1g1-r2g1) - g1x2*(r1g2-r2g2)) / det;
456 Double_t dp = - ( g1_2*(r2g2-r1g2) - g1x2*(r2g1-r1g1)) / det;
457 //
458 t1+=dt;
459 t2+=dp;
460 Evaluate(t1,r1);
461 h.Evaluate(t2,r2);
462 //
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.;
467 }
468 return 0;
469}
470
471
7f572c00 472Int_t AliHelix::ParabolicDCA(AliHelix&h, //helixes
473 Double_t &t1, Double_t &t2,
474 Double_t &R, Double_t &dist, Int_t iter)
475{
476 //
477 //
478 // find intersection using linear fit
479 Double_t r1[3],g1[3],gg1[3];
480 Double_t r2[3],g2[3],gg2[3];
481 //
482 Evaluate(t1,r1,g1,gg1);
483 h.Evaluate(t2,r2,g2,gg2);
484
485 //
486 Double_t dx2=1.;
487 Double_t dy2=1.;
488 Double_t dz2=1.;
489 //
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;
492 //
493
494 iter++;
495 while (iter--) {
9be2fe3a 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);
498
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);
506
507 Double_t det=h11*h22-h12*h12;
508
509 Double_t dt1,dt2;
510 if (TMath::Abs(det)<1.e-33) {
511 //(quasi)singular Hessian
512 dt1=-gt1; dt2=-gt2;
513 } else {
514 dt1=-(gt1*h22 - gt2*h12)/det;
515 dt2=-(h11*gt2 - h12*gt1)/det;
516 }
517
518 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
519
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) {
522 // break;
523 // }
524
525 Double_t dd=dm;
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;
531 if (dd<dm) break;
532 dt1*=0.5; dt2*=0.5;
533 if (div==0){
534 div =1;
535 }
536 if (div>512) {
537 break;
538 }
539 }
540 dm=dd;
541 t1+=dt1;
542 t2+=dt2;
7f572c00 543 }
7f572c00 544 Evaluate(t1,r1,g1,gg1);
545 h.Evaluate(t2,r2,g2,gg2);
546 //
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]);
550
551 R = ((r1[0]+r2[0])*(r1[0]+r2[0])+(r1[1]+r2[1])*(r1[1]+r2[1]))/4;
9be2fe3a 552 return 0;
7f572c00 553
554}
7f572c00 555
556
9be2fe3a 557Int_t AliHelix::ParabolicDCA2(AliHelix&h, //helixes
7f572c00 558 Double_t &t1, Double_t &t2,
9be2fe3a 559 Double_t &R, Double_t &dist, Double_t err[3], Int_t iter)
7f572c00 560{
561 //
562 //
563 // find intersection using linear fit
564 Double_t r1[3],g1[3],gg1[3];
565 Double_t r2[3],g2[3],gg2[3];
566 //
567 Evaluate(t1,r1,g1,gg1);
568 h.Evaluate(t2,r2,g2,gg2);
569
570 //
9be2fe3a 571 Double_t dx2=err[0];
572 Double_t dy2=err[1];
573 Double_t dz2=err[2];
7f572c00 574 //
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;
577 //
578
579 iter++;
580 while (iter--) {
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);
583
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);
591
592 Double_t det=h11*h22-h12*h12;
593
594 Double_t dt1,dt2;
595 if (TMath::Abs(det)<1.e-33) {
596 //(quasi)singular Hessian
597 dt1=-gt1; dt2=-gt2;
598 } else {
599 dt1=-(gt1*h22 - gt2*h12)/det;
600 dt2=-(h11*gt2 - h12*gt1)/det;
601 }
602
603 if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
604
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) {
607 // break;
608 // }
609
610 Double_t dd=dm;
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;
616 if (dd<dm) break;
617 dt1*=0.5; dt2*=0.5;
618 if (div==0){
619 div =1;
620 }
621 if (div>512) {
622 break;
623 }
624 }
625 dm=dd;
626 t1+=dt1;
627 t2+=dt2;
628 }
629 Evaluate(t1,r1,g1,gg1);
630 h.Evaluate(t2,r2,g2,gg2);
631 //
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]);
635
636 R = ((r1[0]+r2[0])*(r1[0]+r2[0])+(r1[1]+r2[1])*(r1[1]+r2[1]))/4;
637 return 0;
638
639}
640