BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
HTrackParameter.cxx
Go to the documentation of this file.
3#include "VertexFit/BField.h"
4#include "CLHEP/Units/PhysicalConstants.h"
5using namespace CLHEP;
6const double alpha = -0.00299792458;
7//const double bField = 1.0;
8
10 m_trackID = -1;
11 m_partID = -1;
12 m_hel = HepVector(5, 0);
13 m_eHel = HepSymMatrix(5, 0);
14}
15
17 m_trackID = htrk.m_trackID;
18 m_partID = htrk.m_partID;
19 m_hel = htrk.m_hel;
20 m_eHel = htrk.m_eHel;
21}
22
23HTrackParameter &HTrackParameter :: operator = (const HTrackParameter &htrk) {
24 m_trackID = htrk.m_trackID;
25 m_partID = htrk.m_partID;
26 m_hel = htrk.m_hel;
27 m_eHel = htrk.m_eHel;
28 return (*this);
29}
30
31//
32// for DstMdcKalTrack --> HTrackParameter
33//
34
35
36HTrackParameter::HTrackParameter(const HepVector h, const HepSymMatrix eH,
37 const int trackid, const int partid) {
38
39 m_hel = HepVector(5, 0);
40 m_eHel = HepSymMatrix(5, 0);
41
42 m_trackID = trackid;
43 m_partID = partid;
44 m_hel = h;
45 m_eHel = eH;
46
47}
48
49//
50// for DstMdcTrack --> HTrackParameter
51//
52
53
54HTrackParameter::HTrackParameter(const HepVector h, const double eH[],
55 const int trackid, const int partid) {
56
57 m_hel = HepVector(5, 0);
58 m_eHel = HepSymMatrix(5, 0);
59
60 m_trackID = trackid;
61 m_partID = partid;
62 m_hel = h;
63 int k = 0;
64 for(int i = 0; i < 5; i++){
65 for(int j = 0; j < 5; j++) {
66 m_eHel[i][j] = eH[k];
67 m_eHel[j][i] = eH[k];
68 k++;
69 }
70 }
71}
72
73//
74// WTrackParameter --> HTrackParameter
75//
76
78
79 HepVector p(3, 0);
80 HepVector x(3, 0);
81 for(int i = 0; i < 3; i++) {
82 p[i] = wtrk.w()[i];
83 x[i] = wtrk.w()[i+4];
84 }
85
86 HTrackParameter htrk(wtrk.charge(), p, x);
87 HepMatrix A(5, 3, 0);
88 HepMatrix B(5, 3, 0);
89
90 A = htrk.dHdx(p, x);
91 B = htrk.dHdp(p, x);
92 HepMatrix T(5, 7, 0);
93 for(int i = 0; i < 5; i++) {
94 for(int j = 0; j < 3; j++){
95 T[i][j] = B[i][j];
96 T[i][j+4] = A[i][j];
97 }
98 }
99
100 HepSymMatrix eH(5, 0);
101 eH = (wtrk.Ew()).similarity(T);
102 int m_trackID = -1;
103 double mass = (wtrk.p()).m();
104 int m_partID = -1;
105 for(int i = 0; i < 5; i++) {
106 if(fabs(mass - xmass(i)) < 0.01) {
107 m_partID = i;
108 break;
109 }
110 }
111 // htrk.setTrackID(trackID);
112 // htrk.setPartID(partID);
113 htrk.setEHel(eH);
114 m_hel = htrk.hel();
115 m_eHel = htrk.eHel();
116}
117
118//
119// radius and centers of Helix in xy plane
120//
121
123 double bField = VertexFitBField::instance()->getBFieldZ(x3());
124 int charge = m_hel[2] > 0 ? +1: -1;
125 double a = alpha * bField * charge;
126 double pxy = charge/m_hel[2];
127 return (pxy/a);
128}
129
131 double bField = VertexFitBField::instance()->getBFieldZ(x3());
132 int charge = m_hel[2] > 0 ? +1: -1;
133 double a = alpha * bField * charge;
134 double pxy = charge/m_hel[2];
135 double rad = pxy/a;
136 double x = (m_hel[0] + rad) * cos(m_hel[1]);
137 double y = (m_hel[0] + rad) * sin(m_hel[1]);
138 double z = 0.0;
139 return HepPoint3D(x, y, z);
140}
141
142//
143// Helix parameter from instantaneous position and momentum
144//
145
146HTrackParameter::HTrackParameter(const int charge, const HepVector p, const HepVector vx) {
147 m_trackID = -1;
148 m_partID = -1;
149 m_hel = HepVector(5, 0);
150 m_eHel = HepSymMatrix(5, 0);
151
152 HepPoint3D xyz(vx[0], vx[1], vx[2]);
153 double bField = VertexFitBField::instance()->getBFieldZ(xyz);
154 //std::cout << "bField in HTrackParameter(charge,p,vx) = " << bField << std::endl;
155
156 double a = alpha * bField * charge;
157 double px = p[0];
158 double py = p[1];
159 double pz = p[2];
160
161 double x = vx[0];
162 double y = vx[1];
163 double z = vx[2];
164
165 double pxy = sqrt(px*px+py*py);
166 double T = sqrt((px+a*y)*(px+a*y)+(py-a*x)*(py-a*x));
167 double J= (x*px+y*py)/T*a/pxy;
168
169 double drho = (pxy/a)-(T/a);
170 double phi0 = fmod((4*CLHEP::pi)+atan2(0-px-a*y, py-a*x), (2*CLHEP::pi));
171 double kappa = charge/pxy;
172 double dz = z - (pz/a) *asin(J);
173 double lambda = pz/pxy;
174
175 m_hel[0] = drho; m_hel[1] = phi0; m_hel[2] = kappa;
176 m_hel[3] = dz; m_hel[4] = lambda;
177}
178
179//
180// derivative Matrix, used in Kalman Vertex Fit A= dH/dx
181//
182
183HepMatrix HTrackParameter::dHdx(const HepVector p, const HepVector vx){
184 HepPoint3D xyz(vx[0], vx[1], vx[2]);
185 double bField = VertexFitBField::instance()->getBFieldZ(xyz);
186 //std::cout << "bField in dHdx(p,vx) = " << bField << std::endl;
187
188 double a = alpha * bField * charge();
189 double px = p[0];
190 double py = p[1];
191 double pz = p[2];
192
193 double x = vx[0];
194 double y = vx[1];
195 // double z = vx[2];
196
197 // double pxy = sqrt(px*px+py*py);
198 double T = sqrt((px+a*y)*(px+a*y)+(py-a*x)*(py-a*x));
199 // double J= (x*px+y*py)/T*a/pxy;
200
201 HepMatrix m_A(5, 3, 0);
202
203 m_A[0][0] = (py-a*x)/T;
204 m_A[0][1] = 0 -(px + a*y)/T;
205 m_A[1][0] = 0- a*(px + a*y)/T/T;
206 m_A[1][1] = 0 - a * (py - a*x)/T/T;
207 m_A[3][0] = 0 - (pz/T)*(px + a*y)/T;
208 m_A[3][1] = 0 - (pz/T)*(py - a*x)/T;
209 m_A[3][2] = 1;
210
211 return m_A;
212}
213
214//
215// derivative Matrix, used in Kalman Vertex Fit B= dH/dp
216//
217
218HepMatrix HTrackParameter::dHdp(const HepVector p, const HepVector vx){
219 HepPoint3D xyz(vx[0], vx[1], vx[2]);
220 double bField = VertexFitBField::instance()->getBFieldZ(xyz);
221
222 double a = alpha * bField * charge();
223 double px = p[0];
224 double py = p[1];
225 double pz = p[2];
226
227 double x = vx[0];
228 double y = vx[1];
229 // double z = vx[2];
230
231 double pxy = sqrt(px*px+py*py);
232 double T = sqrt((px+a*y)*(px+a*y)+(py-a*x)*(py-a*x));
233 double J= (x*px+y*py)/T*a/pxy;
234
235 HepMatrix m_B(5, 3, 0);
236
237 m_B[0][0] = (px/pxy - (px+a*y)/T)/a;
238 m_B[0][1] = (py/pxy - (py-a*x)/T)/a;
239 m_B[1][0] = 0 -(py-a*x)/T/T;
240 m_B[1][1] = (px + a*y)/T/T;
241 m_B[2][0] = 0-charge() *px/pxy/pxy/pxy;
242 m_B[2][1] = 0-charge() *py/pxy/pxy/pxy;
243 m_B[3][0] = (pz/a)*(py/pxy/pxy-(py-a*x)/T/T);
244 m_B[3][1] = 0-(pz/a)*(px/pxy/pxy-(px+a*y)/T/T);
245 m_B[3][2] = 0 - asin(J)/a;
246 m_B[4][0] = 0 - (px/pxy)*(pz/pxy)/pxy;
247 m_B[4][1] = 0 - (py/pxy)*(pz/pxy)/pxy;
248 m_B[4][2] = 1/pxy;
249
250 return m_B;
251}
252
253//
254// HTrackParameter --> WTrackParameter
255//
256
258
259 WTrackParameter wtrk;
260 wtrk.setCharge(charge());
261 HepVector w(7,0);
262 HepMatrix dWdh(7, 5, 0);
263
264 double ptrk = p3().rho(); double E = sqrt(ptrk*ptrk + mass * mass);
265 double px = p3().x();
266 double py = p3().y();
267 double pz = p3().z();
268 double x0 = x3().x();
269 double y0 = x3().y();
270 double z0 = x3().z();
271 w[0] = px; w[1] = py; w[2] = pz; w[3] = E;
272 w[4] = x0; w[5] = y0; w[6] = z0;
273 wtrk.setW(w);
274 dWdh[0][1] = -py; dWdh[0][2] = 0 - px/kappa();
275 dWdh[1][1] = px; dWdh[1][2] = 0 - py/kappa();
276 dWdh[2][2] = 0 - pz/kappa(); dWdh[2][4] = charge()/kappa();
277 dWdh[3][2] = 0 - (1 + lambda() * lambda())/ E / kappa() / kappa() / kappa();
278 dWdh[3][4] = lambda() / E / kappa() / kappa();
279 dWdh[4][0] = cos(phi0()); dWdh[4][1] = 0 - y0;
280 dWdh[5][0] = sin(phi0()); dWdh[5][1] = x0;
281 dWdh[6][3] = 1;
282 HepSymMatrix Ew(7, 0);
283 Ew = m_eHel.similarity(dWdh);
284 wtrk.setEw(Ew);
285 return wtrk;
286}
287
289 WTrackParameter wtrk;
290 if(m_partID > -1 && m_partID < 5) {
291 double mass = xmass(m_partID);
292 wtrk = wTrack(mass);
293 }
294 return wtrk;
295}
296
297//
298// Utilities functions
299//
300
301double HTrackParameter::xmass(int n) const {
302 double mass[5] = {0.000511, 0.105658, 0.139570,0.493677, 0.938272};
303 if(n < 0 || n >=5) return 0.0;
304 return mass[n];
305}
306
307
308//
309// Intersection position of two helice in xy plane
310//
312 double bField1 = VertexFitBField::instance()->getBFieldZ(x3());
313 double bField2 = VertexFitBField::instance()->getBFieldZ(htrk.x3());
314
315 HepPoint3D pos1 = x3();
316 HepPoint3D pos2 = htrk.x3();
317 double rad1 = radius();
318 double rad2 = htrk.radius();
319 HepPoint3D xc1 = center();
320 HepPoint3D xc2 = htrk.center();
321 //
322 // requires the solution of
323 // a * y**2 + b*y + c = 0
324 // and
325 // x = (rt - 2*yt * y) / (2 * xt)
326 // where
327 // xt = xc2.x() - xc1.x()
328 // yt = xc2.y() - xc1.y()
329 // rt = rad1*rad1-rad2*rad2-xc1.perp2()+xc2.perp2()
330 // a = 1 + yt*yt/(xt*xt);
331 // b = 2*xc1.x()*yt/xt-yt*rt/(xt*xt)-2*xc1.y();
332 // c = rt*rt/(4*xt*xt)-xc1.x()*rt/xt-rad1*rad1+xc1.perp2();
333 //
334
335 double xt = xc2.x() - xc1.x();
336 double yt = xc2.y() - xc1.y();
337 if(xt == 0 && yt == 0) return HepPoint3D(999,999,999);
338 double rt = rad1*rad1-rad2*rad2-xc1.perp2()+xc2.perp2();
339 double x1, y1, x2, y2;
340 if( xt != 0) {
341 double a = 1 + yt*yt/(xt*xt);
342 if(a == 0) return HepPoint3D(999,999,999);
343 double b = 2*xc1.x()*yt/xt-yt*rt/(xt*xt)-2*xc1.y();
344 double c = rt*rt/(4*xt*xt)-xc1.x()*rt/xt-rad1*rad1+xc1.perp2();
345 double d = b*b - 4 * a * c;
346 if( d < 0) return HepPoint3D(999,999,999);
347 d = sqrt(d);
348 // two solution of intersection points
349
350 y1 = (-b + d)/(2*a);
351 x1 = (rt - 2 * yt * y1)/(2*xt);
352
353 y2 = (-b - d)/(2*a);
354 x2 = (rt - 2 * yt * y2)/(2*xt);
355 } else {
356 double a = 1 + xt*xt/(yt*yt);
357 if(a == 0) return HepPoint3D(999,999,999);
358 double b = 2*xc1.y()*xt/yt-xt*rt/(yt*yt)-2*xc1.x();
359 double c = rt*rt/(4*yt*yt)-xc1.y()*rt/yt-rad1*rad1+xc1.perp2();
360 double d = b*b - 4 * a * c;
361 if( d < 0) return HepPoint3D(999,999,999);
362 d = sqrt(d);
363 // two solution of intersection points
364
365 x1 = (-b + d)/(2*a);
366 y1 = (rt - 2 * xt * x1)/(2*yt);
367
368 x2 = (-b - d)/(2*a);
369 y2 = (rt - 2 * xt * x2)/(2*yt);
370 }
371
372 double z1[2], z2[2], J1[2], J2[2];
373
374
375 double a1 = alpha * bField1 * charge();
376 double a2 = alpha * bField2 * htrk.charge();
377 // z for solotion one
378 J1[0] = a1*((x1-x3().x())*p3().x()+(y1-x3().y())*p3().y())/p3().perp2();
379 J1[1] = a2*((x1-htrk.x3().x())*htrk.p3().x()+(y1-htrk.x3().y())*htrk.p3().y())/htrk.p3().perp2();
380 z1[0] = x3().z()+p3().z()/a1*asin(J1[0]);
381 z1[1] = htrk.x3().z()+htrk.p3().z()/a2*asin(J1[1]);
382 // z for solotion two
383 J2[0] = a1*((x2-x3().x())*p3().x()+(y2-x3().y())*p3().y())/p3().perp2();
384 J2[1] = a2*((x2-htrk.x3().x())*htrk.p3().x()+(y2-htrk.x3().y())*htrk.p3().y())/htrk.p3().perp2();
385 z2[0] = x3().z()+p3().z()/a2*asin(J2[0]);
386 z2[1] = htrk.x3().z()+htrk.p3().z()/a2*asin(J2[1]);
387
388 // take the solution if delta z is small
389
390 if(fabs(z1[0]-z1[1]) < fabs(z2[0]-z2[1])) {
391 return HepPoint3D(x1, y1, 0.5*(z1[0]+z1[1]));
392 } else {
393 return HepPoint3D(x2, y2, 0.5*(z2[0]+z2[1]));
394 }
395}
396
397
398
399//
400// intersection position of helix and Plane
401//
402
404 return HepPoint3D(999,999,999);
405}
406
407//
408// intersection position of helix and a cylinder
409//
410
412 return HepPoint3D(999,999,999);
413}
414
415//
416// intersection position of helix and a cone
417//
418
420 return HepPoint3D(999,999,999);
421}
422
423//
424// Minimum distance of two helice
425//
426
428 int ifail;
429 double h = radius();
430 double g = G.radius();
431 double phiH0 = fmod((4*CLHEP::pi)+atan2(p3().y(), p3().x()), (2*CLHEP::pi));
432 double phiG0 = fmod((4*CLHEP::pi)+atan2(G.p3().y(), G.p3().x()), (2*CLHEP::pi));
433 double lamH = lambda();
434 double lamG = G.lambda();
435 double a = x3().x() - G.x3().x() + g*sin(phiG0) - h*sin(phiH0);
436 double b = x3().y() - G.x3().y() - g*cos(phiG0) + h*cos(phiH0);
437 double c1 = h*lamH*lamH;
438 double c2 = 0 - g*lamG*lamG;
439 double d1 = 0 - g*lamG*lamH;
440 double d2 = h*lamG*lamH;
441 double e1 = lamH*(x3().z() - G.x3().z() - h*phiH0*lamH + g*phiG0*lamG);
442 double e2 = lamG*(x3().z() - G.x3().z() - h*phiH0*lamH + g*phiG0*lamG);
443
444 HepVector phiE(2, 0);
445 phiE[0] = phiH0;
446 phiE[1] = phiG0;
447 for(int iter = 0; iter < 100; iter++) {
448 HepVector z(2, 0);
449 HepSymMatrix Omega(2, 0);
450 double phiH = phiE[0];
451 double phiG = phiE[1];
452 z[0] = cos(phiH)*(a-g*sin(phiG))+sin(phiH)*(b+g*cos(phiG))+c1*phiH+d1*phiG+e1;
453 z[1] = cos(phiG)*(a+h*sin(phiH))+sin(phiG)*(b-h*cos(phiH))+c2*phiG+d2*phiH+e2;
454 Omega[0][0] = 0-sin(phiH)*(a-g*sin(phiG))+cos(phiH)*(b+g*cos(phiG))+c1;
455 Omega[0][1] = -g*cos(phiH)*cos(phiG)-g*sin(phiH)*sin(phiG)+d1;
456 Omega[1][0] =h*cos(phiH)*cos(phiG)+h*sin(phiG)*sin(phiH)+d2;
457 Omega[1][1] = -sin(phiG)*(a+h*sin(phiH))+cos(phiG)*(b-h*cos(phiH))+c2;
458 HepVector phi(2, 0);
459 phi = phiE - Omega.inverse(ifail) * z;
460 if((fabs(phi[0]-phiE[0])<1E-3) && (fabs(phi[1]-phiE[1])<1E-3)) {
461 phiE = phi;
462 // std::cout << "number of iteration = " << iter <<std::endl;
463 break;
464 }
465 phiE = phi;
466 }
467
468 double phiH = phiE[0];
469 double phiG = phiE[1];
470 HepPoint3D posH = HepPoint3D(x3().x()+h*(sin(phiH)-sin(phiH0)), x3().y()+h*(cos(phiH0)-cos(phiH)), x3().z()+lamH*(phiH-phiH0));
471 HepPoint3D posG = HepPoint3D(G.x3().x()+g*(sin(phiG)-sin(phiG0)), G.x3().y()+g*(cos(phiG0)-cos(phiG)), G.x3().z()+lamG*(phiG-phiG0));
472 double dis = (posH-posG).rho();
473 mpos = 0.5*(posH+posG);
474 return dis;
475}
476//
477// Minimum distance of helix and a line
478//
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
double mass
const Int_t n
Double_t e1
Double_t e2
const double alpha
const double xmass[5]
Definition: Gam4pikp.cxx:50
const double alpha
HepGeom::Point3D< double > HepPoint3D
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
double lambda() const
HepPoint3D positionCylinder(const double) const
HepPoint3D positionTwoHelix(const HTrackParameter) const
HepMatrix dHdp(const HepVector p, const HepVector x)
double minDistanceTwoHelix(const HTrackParameter G, HepPoint3D &pos)
HepMatrix dHdx(const HepVector p, const HepVector x)
double xmass(const int i) const
WTrackParameter wTrack() const
double kappa() const
HepVector p() const
HepPoint3D positionPlane(const double) const
HepVector hel() const
HepPoint3D x3() const
double phi0() const
HepPoint3D center() const
double drho() const
int charge() const
double dz() const
double pxy() const
HepSymMatrix eHel() const
void setEHel(const HepSymMatrix eH)
double radius() const
Hep3Vector p3() const
HepVector x() const
HepPoint3D positionCone() const
void setEw(const HepSymMatrix &Ew)
int charge() const
HepLorentzVector p() const
void setCharge(const int charge)
HepVector w() const
void setW(const HepVector &w)
HepSymMatrix Ew() const
double y[1000]
float charge
float ptrk
const double b
Definition: slope.cxx:9
const float rad
Definition: vector3.h:134