BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
KFParticle.cxx
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// Implementation of the KFParticle class
3// .
4// @author S.Gorbunov, I.Kisel, I.Kulakov, M.Zyzak
5// @version 1.0
6// @since 13.05.07
7//
8// Class to reconstruct and store the decayed particle parameters.
9// The method is described in CBM-SOFT note 2007-003,
10// ``Reconstruction of decayed particles based on the Kalman filter'',
11// http://www.gsi.de/documents/DOC-2007-May-14-1.pdf
12//
13// This class is ALICE interface to general mathematics in KFParticleCore
14//
15// -= Copyright &copy ALICE HLT and CBM L1 Groups =-
16//____________________________________________________________________________
17
18#include "KFParticle.h"
19
20#include "TDatabasePDG.h"
21#include "TParticlePDG.h"
22
23#ifdef HomogeneousField
24#include "AliVTrack.h"
25#include "AliVVertex.h"
26#endif
27
28#ifdef NonhomogeneousField
29#include "CbmKFTrack.h"
30#include "CbmKFVertex.h"
31#endif
32
33#ifdef HomogeneousField
34Double_t KFParticle::fgBz = -5.; //* Bz compoment of the magnetic field
35#endif
36
38{
39 if (!gamma) {
40 KFParticle mother;
41 mother += d1;
42 mother += d2;
43 *this = mother;
44 } else
45 ConstructGamma(d1, d2);
46}
47
48void KFParticle::Create(const Double_t Param[], const Double_t Cov[], Int_t Charge, Double_t mass /*Int_t PID*/)
49{
50 // Constructor from "cartesian" track, PID hypothesis should be provided
51 //
52 // Param[6] = { X, Y, Z, Px, Py, Pz } - position and momentum
53 // Cov [21] = lower-triangular part of the covariance matrix:
54 //
55 // ( 0 . . . . . )
56 // ( 1 2 . . . . )
57 // Cov. matrix = ( 3 4 5 . . . ) - numbering of covariance elements in Cov[]
58 // ( 6 7 8 9 . . )
59 // ( 10 11 12 13 14 . )
60 // ( 15 16 17 18 19 20 )
61 Double_t C[21];
62 for (int i = 0; i < 21; i++)
63 C[i] = Cov[i];
64
65 // TParticlePDG* particlePDG = TDatabasePDG::Instance()->GetParticle(PID);
66 // Double_t mass = (particlePDG) ? particlePDG->Mass() :0.13957;
67
68 KFParticleBase::Initialize(Param, C, Charge, mass);
69}
70
71#ifdef NonhomogeneousField
73{
74 CbmKFTrack Tr(*Track);
75
76 Double_t* m = Tr.GetTrack();
77 Double_t* V = Tr.GetCovMatrix();
78
79 //* Fit of vertex track slopes and momentum (a,b,qp) to xyz0 vertex
80
81 // if( z0 ) Tr.Extrapolate( *z0 );
82
83 Double_t a = m[2], b = m[3], qp = m[4];
84
85 //* convert the track to (x,y,px,py,pz,e,t/p) parameterization
86
87 double c2 = 1. / (1. + a * a + b * b);
88 double pq = 1. / qp;
89 if (qHypo)
90 pq *= *qHypo;
91 double p2 = pq * pq;
92 double pz = sqrt(p2 * c2);
93 double px = a * pz;
94 double py = b * pz;
95 double H[3] = {-px * c2, -py * c2, -pz * pq};
96
97 Double_t r[6];
98
99 r[0] = m[0];
100 r[1] = m[1];
101 r[2] = m[5];
102 r[3] = px;
103 r[4] = py;
104 r[5] = pz;
105
106 double cxpz = H[0] * V[3] + H[1] * V[6] + H[2] * V[10];
107 double cypz = H[0] * V[4] + H[1] * V[7] + H[2] * V[11];
108 double capz = H[0] * V[5] + H[1] * V[8] + H[2] * V[12];
109 double cbpz = H[0] * V[8] + H[1] * V[9] + H[2] * V[13];
110 // double cqpz = H[0]*V[12] + H[1]*V[13] + H[2]*V[14];
111 double cpzpz = H[0] * H[0] * V[5] + H[1] * H[1] * V[9] + H[2] * H[2] * V[14]
112 + 2 * (H[0] * H[1] * V[8] + H[0] * H[2] * V[12] + H[1] * H[2] * V[13]);
113
114 Double_t C[21];
115
116 C[0] = V[0];
117 C[1] = V[1];
118 C[2] = V[2];
119 C[3] = 0;
120 C[4] = 0;
121 C[5] = 0;
122 C[6] = V[3] * pz + a * cxpz;
123 C[7] = V[4] * pz + a * cypz;
124 C[8] = 0;
125 C[9] = V[5] * pz * pz + 2 * a * pz * capz + a * a * cpzpz;
126 C[10] = V[6] * pz + b * cxpz;
127 C[11] = V[7] * pz + b * cypz;
128 C[12] = 0;
129 C[13] = V[8] * pz * pz + a * pz * cbpz + b * pz * capz + a * b * cpzpz;
130 C[14] = V[9] * pz * pz + 2 * b * pz * cbpz + b * b * cpzpz;
131 C[15] = cxpz;
132 C[16] = cypz;
133 C[17] = 0;
134 C[18] = capz * pz + a * cpzpz;
135 C[19] = cbpz * pz + b * cpzpz;
136 C[20] = cpzpz;
137
138 Double_t Charge = (qp > 0.) ? 1 : ((qp < 0) ? -1 : 0);
139 if (qHypo)
140 Charge *= *qHypo;
141
142 Double_t mass = Tr.GetMass();
143
144 if (PID) {
145 TParticlePDG* particlePDG = TDatabasePDG::Instance()->GetParticle(*PID);
146 mass = (particlePDG) ? particlePDG->Mass() : 0.13957;
147 }
148
149 Create(r, C, Charge, mass);
150}
151
153{
154 // Constructor from CBM KF vertex
155 fP[0] = vertex.GetRefX();
156 fP[1] = vertex.GetRefY();
157 fP[2] = vertex.GetRefZ();
158 for (Int_t i = 0; i < 6; i++)
159 fC[i] = vertex.GetCovMatrix()[i];
160 fChi2 = vertex.GetRefChi2();
161 fNDF = vertex.GetRefNDF(); // 2*vertex.GetNContributors() - 3;
162 fQ = 0;
164 fIsLinearized = 0;
165 fSFromDecay = 0;
166}
167
168#endif
169
170#ifdef HomogeneousField
171KFParticle::KFParticle(const AliVTrack& track, Int_t PID)
172{
173 // Constructor from ALICE track, PID hypothesis should be provided
174
175 track.XvYvZv(fP);
176 track.PxPyPz(fP + 3);
177 fQ = track.Charge();
178 track.GetCovarianceXYZPxPyPz(fC);
179
180 TParticlePDG* particlePDG = TDatabasePDG::Instance()->GetParticle(PID);
181 Double_t mass = (particlePDG) ? particlePDG->Mass() : 0.13957;
182
183 Create(fP, fC, fQ, mass);
184}
185
186KFParticle::KFParticle(const AliVVertex& vertex)
187{
188 // Constructor from ALICE vertex
189
190 vertex.GetXYZ(fP);
191 vertex.GetCovarianceMatrix(fC);
192 fChi2 = vertex.GetChi2();
193 fNDF = 2 * vertex.GetNContributors() - 3;
194 fQ = 0;
196 fIsLinearized = 0;
197 fSFromDecay = 0;
198}
199
201{
202 // Conversion to AliExternalTrackParam parameterization
203
204 Double_t cosA = p.GetPx(), sinA = p.GetPy();
205 Double_t pt = TMath::Sqrt(cosA * cosA + sinA * sinA);
206 Double_t pti = 0;
207 if (pt < 1.e-4) {
208 cosA = 1;
209 sinA = 0;
210 } else {
211 pti = 1. / pt;
212 cosA *= pti;
213 sinA *= pti;
214 }
215 Alpha = TMath::ATan2(sinA, cosA);
216 X = p.GetX() * cosA + p.GetY() * sinA;
217 P[0] = p.GetY() * cosA - p.GetX() * sinA;
218 P[1] = p.GetZ();
219 P[2] = 0;
220 P[3] = p.GetPz() * pti;
221 P[4] = p.GetQ() * pti;
222}
223
224#endif
225
227 const Double_t Cv[],
228 Double_t& val,
229 Double_t& err) const
230{
231 //* Calculate DCA distance from vertex (transverse impact parameter) in XY
232 //* v = [xy], Cv=[Cxx,Cxy,Cyy ]-covariance matrix
233
234 Bool_t ret = 0;
235
236 Double_t mP[8];
237 Double_t mC[36];
238
239 Transport(GetDStoPoint(vtx), mP, mC);
240
241 Double_t dx = mP[0] - vtx[0];
242 Double_t dy = mP[1] - vtx[1];
243 Double_t px = mP[3];
244 Double_t py = mP[4];
245 Double_t pt = TMath::Sqrt(px * px + py * py);
246 Double_t ex = 0, ey = 0;
247 if (pt < 1.e-4) {
248 ret = 1;
249 pt = 1.;
250 val = 1.e4;
251 } else {
252 ex = px / pt;
253 ey = py / pt;
254 val = dy * ex - dx * ey;
255 }
256
257 Double_t h0 = -ey;
258 Double_t h1 = ex;
259 Double_t h3 = (dy * ey + dx * ex) * ey / pt;
260 Double_t h4 = -(dy * ey + dx * ex) * ex / pt;
261
262 err =
263 h0 * (h0 * GetCovariance(0, 0) + h1 * GetCovariance(0, 1) + h3 * GetCovariance(0, 3) + h4 * GetCovariance(0, 4))
264 + h1
265 * (h0 * GetCovariance(1, 0) + h1 * GetCovariance(1, 1) + h3 * GetCovariance(1, 3)
266 + h4 * GetCovariance(1, 4))
267 + h3
268 * (h0 * GetCovariance(3, 0) + h1 * GetCovariance(3, 1) + h3 * GetCovariance(3, 3)
269 + h4 * GetCovariance(3, 4))
270 + h4
271 * (h0 * GetCovariance(4, 0) + h1 * GetCovariance(4, 1) + h3 * GetCovariance(4, 3)
272 + h4 * GetCovariance(4, 4));
273
274 if (Cv) {
275 err += h0 * (h0 * Cv[0] + h1 * Cv[1]) + h1 * (h0 * Cv[1] + h1 * Cv[2]);
276 }
277
278 err = TMath::Sqrt(TMath::Abs(err));
279
280 return ret;
281}
282
284{
285 return GetDistanceFromVertexXY(vtx, 0, val, err);
286}
287
289{
290 //* Calculate distance from vertex [cm] in XY-plane
291
292 return GetDistanceFromVertexXY(Vtx.fP, Vtx.fC, val, err);
293}
294
295#ifdef HomogeneousField
296Bool_t KFParticle::GetDistanceFromVertexXY(const AliVVertex& Vtx, Double_t& val, Double_t& err) const
297{
298 //* Calculate distance from vertex [cm] in XY-plane
299
300 return GetDistanceFromVertexXY(KFParticle(Vtx), val, err);
301}
302#endif
303
305{
306 //* Calculate distance from vertex [cm] in XY-plane
307 Double_t val, err;
308 GetDistanceFromVertexXY(vtx, 0, val, err);
309 return val;
310}
311
313{
314 //* Calculate distance from vertex [cm] in XY-plane
315
316 return GetDistanceFromVertexXY(Vtx.fP);
317}
318
319#ifdef HomogeneousField
320Double_t KFParticle::GetDistanceFromVertexXY(const AliVVertex& Vtx) const
321{
322 //* Calculate distance from vertex [cm] in XY-plane
323
325}
326#endif
327
329{
330 //* Calculate distance to other particle [cm]
331
332 Double_t dS, dS1;
333 GetDStoParticleXY(p, dS, dS1);
334 Double_t mP[8], mC[36], mP1[8], mC1[36];
335 Transport(dS, mP, mC);
336 p.Transport(dS1, mP1, mC1);
337 Double_t dx = mP[0] - mP1[0];
338 Double_t dy = mP[1] - mP1[1];
339 return TMath::Sqrt(dx * dx + dy * dy);
340}
341
343{
344 //* Calculate sqrt(Chi2/ndf) deviation from other particle
345
346 Double_t dS, dS1;
347 GetDStoParticleXY(p, dS, dS1);
348 Double_t mP1[8], mC1[36];
349 p.Transport(dS1, mP1, mC1);
350
351 Double_t d[2] = {fP[0] - mP1[0], fP[1] - mP1[1]};
352
353 Double_t sigmaS = .1 + 10. * TMath::Sqrt((d[0] * d[0] + d[1] * d[1]) / (mP1[3] * mP1[3] + mP1[4] * mP1[4]));
354
355 Double_t h[2] = {mP1[3] * sigmaS, mP1[4] * sigmaS};
356
357 mC1[0] += h[0] * h[0];
358 mC1[1] += h[1] * h[0];
359 mC1[2] += h[1] * h[1];
360
361 return GetDeviationFromVertexXY(mP1, mC1) * TMath::Sqrt(2. / 1.);
362}
363
365{
366 //* Calculate sqrt(Chi2/ndf) deviation from vertex
367 //* v = [xyz], Cv=[Cxx,Cxy,Cyy,Cxz,Cyz,Czz]-covariance matrix
368
369 Double_t val, err;
370 Bool_t problem = GetDistanceFromVertexXY(vtx, Cv, val, err);
371 if (problem || err < 1.e-20)
372 return 1.e4;
373 else
374 return val / err;
375}
376
378{
379 //* Calculate sqrt(Chi2/ndf) deviation from vertex
380 //* v = [xyz], Cv=[Cxx,Cxy,Cyy,Cxz,Cyz,Czz]-covariance matrix
381
382 return GetDeviationFromVertexXY(Vtx.fP, Vtx.fC);
383}
384
385#ifdef HomogeneousField
386Double_t KFParticle::GetDeviationFromVertexXY(const AliVVertex& Vtx) const
387{
388 //* Calculate sqrt(Chi2/ndf) deviation from vertex
389 //* v = [xyz], Cv=[Cxx,Cxy,Cyy,Cxz,Cyz,Czz]-covariance matrix
390
391 KFParticle v(Vtx);
392 return GetDeviationFromVertexXY(v.fP, v.fC);
393}
394#endif
395
397{
398 //* Calculate the opening angle between two particles
399
400 Double_t dS, dS1;
401 GetDStoParticle(p, dS, dS1);
402 Double_t mP[8], mC[36], mP1[8], mC1[36];
403 Transport(dS, mP, mC);
404 p.Transport(dS1, mP1, mC1);
405 Double_t n = TMath::Sqrt(mP[3] * mP[3] + mP[4] * mP[4] + mP[5] * mP[5]);
406 Double_t n1 = TMath::Sqrt(mP1[3] * mP1[3] + mP1[4] * mP1[4] + mP1[5] * mP1[5]);
407 n *= n1;
408 Double_t a = 0;
409 if (n > 1.e-8)
410 a = (mP[3] * mP1[3] + mP[4] * mP1[4] + mP[5] * mP1[5]) / n;
411 if (TMath::Abs(a) < 1.)
412 a = TMath::ACos(a);
413 else
414 a = (a >= 0) ? 0 : TMath::Pi();
415 return a;
416}
417
419{
420 //* Calculate the opening angle between two particles in XY plane
421
422 Double_t dS, dS1;
423 GetDStoParticleXY(p, dS, dS1);
424 Double_t mP[8], mC[36], mP1[8], mC1[36];
425 Transport(dS, mP, mC);
426 p.Transport(dS1, mP1, mC1);
427 Double_t n = TMath::Sqrt(mP[3] * mP[3] + mP[4] * mP[4]);
428 Double_t n1 = TMath::Sqrt(mP1[3] * mP1[3] + mP1[4] * mP1[4]);
429 n *= n1;
430 Double_t a = 0;
431 if (n > 1.e-8)
432 a = (mP[3] * mP1[3] + mP[4] * mP1[4]) / n;
433 if (TMath::Abs(a) < 1.)
434 a = TMath::ACos(a);
435 else
436 a = (a >= 0) ? 0 : TMath::Pi();
437 return a;
438}
439
441{
442 //* Calculate the opening angle between two particles in RZ plane
443
444 Double_t dS, dS1;
445 GetDStoParticle(p, dS, dS1);
446 Double_t mP[8], mC[36], mP1[8], mC1[36];
447 Transport(dS, mP, mC);
448 p.Transport(dS1, mP1, mC1);
449 Double_t nr = TMath::Sqrt(mP[3] * mP[3] + mP[4] * mP[4]);
450 Double_t n1r = TMath::Sqrt(mP1[3] * mP1[3] + mP1[4] * mP1[4]);
451 Double_t n = TMath::Sqrt(nr * nr + mP[5] * mP[5]);
452 Double_t n1 = TMath::Sqrt(n1r * n1r + mP1[5] * mP1[5]);
453 n *= n1;
454 Double_t a = 0;
455 if (n > 1.e-8)
456 a = (nr * n1r + mP[5] * mP1[5]) / n;
457 if (TMath::Abs(a) < 1.)
458 a = TMath::ACos(a);
459 else
460 a = (a >= 0) ? 0 : TMath::Pi();
461 return a;
462}
463
464/*
465
466#include "AliExternalTrackParam.h"
467
468void KFParticle::GetDStoParticleALICE( const KFParticleBase &p,
469 Double_t &DS, Double_t &DS1 )
470 const
471{
472 DS = DS1 = 0;
473 Double_t x1, a1, x2, a2;
474 Double_t par1[5], par2[5], cov[15];
475 for(int i=0; i<15; i++) cov[i] = 0;
476 cov[0] = cov[2] = cov[5] = cov[9] = cov[14] = .001;
477
478 GetExternalTrackParam( *this, x1, a1, par1 );
479 GetExternalTrackParam( p, x2, a2, par2 );
480
481 AliExternalTrackParam t1(x1,a1, par1, cov);
482 AliExternalTrackParam t2(x2,a2, par2, cov);
483
484 Double_t xe1=0, xe2=0;
485 t1.GetDCA( &t2, -GetFieldAlice(), xe1, xe2 );
486 t1.PropagateTo( xe1, -GetFieldAlice() );
487 t2.PropagateTo( xe2, -GetFieldAlice() );
488
489 Double_t xyz1[3], xyz2[3];
490 t1.GetXYZ( xyz1 );
491 t2.GetXYZ( xyz2 );
492
493 DS = GetDStoPoint( xyz1 );
494 DS1 = p.GetDStoPoint( xyz2 );
495
496 return;
497}
498*/
499
500// * Pseudo Proper Time of decay = (r*pt) / |pt| * M/|pt|
502{ // TODO optimize with respect to time and stability
503 const Double_t ipt2 = 1 / (Px() * Px() + Py() * Py());
504 const Double_t mipt2 = mass * ipt2;
505 const Double_t dx = X() - pV.X();
506 const Double_t dy = Y() - pV.Y();
507
508 if (timeErr2) {
509 // -- calculate error = sigma(f(r)) = f'Cf'
510 // r = {x,y,px,py,x_pV,y_pV}
511 // df/dr = { px*m/pt^2,
512 // py*m/pt^2,
513 // ( x - x_pV )*m*(1/pt^2 - 2(px/pt^2)^2),
514 // ( y - y_pV )*m*(1/pt^2 - 2(py/pt^2)^2),
515 // -px*m/pt^2,
516 // -py*m/pt^2 }
517 const Double_t f0 = Px() * mipt2;
518 const Double_t f1 = Py() * mipt2;
519 const Double_t mipt2derivative = mipt2 * (1 - 2 * Px() * Px() * ipt2);
520 const Double_t f2 = dx * mipt2derivative;
521 const Double_t f3 = -dy * mipt2derivative;
522 const Double_t f4 = -f0;
523 const Double_t f5 = -f1;
524
525 const Double_t& mC00 = GetCovariance(0, 0);
526 const Double_t& mC10 = GetCovariance(0, 1);
527 const Double_t& mC11 = GetCovariance(1, 1);
528 const Double_t& mC20 = GetCovariance(3, 0);
529 const Double_t& mC21 = GetCovariance(3, 1);
530 const Double_t& mC22 = GetCovariance(3, 3);
531 const Double_t& mC30 = GetCovariance(4, 0);
532 const Double_t& mC31 = GetCovariance(4, 1);
533 const Double_t& mC32 = GetCovariance(4, 3);
534 const Double_t& mC33 = GetCovariance(4, 4);
535 const Double_t& mC44 = pV.GetCovariance(0, 0);
536 const Double_t& mC54 = pV.GetCovariance(1, 0);
537 const Double_t& mC55 = pV.GetCovariance(1, 1);
538
539 *timeErr2 = f5 * mC55 * f5 + f5 * mC54 * f4 + f4 * mC44 * f4 + f3 * mC33 * f3 + f3 * mC32 * f2 + f3 * mC31 * f1
540 + f3 * mC30 * f0 + f2 * mC22 * f2 + f2 * mC21 * f1 + f2 * mC20 * f0 + f1 * mC11 * f1
541 + f1 * mC10 * f0 + f0 * mC00 * f0;
542 }
543 return (dx * Px() + dy * Py()) * mipt2;
544}
__m128 v
Definition P4_F32vec4.h:1
int i
Definition P4_F32vec4.h:22
__m128 m
Definition P4_F32vec4.h:27
bool Bool_t
int Int_t
double Double_t
Double_t GetMass()
Information not to be changed.
Definition CbmKFTrack.h:78
Double_t * GetTrack()
Is it electron.
Definition CbmKFTrack.h:74
Double_t * GetCovMatrix()
array[6] of track parameters(x,y,tx,ty,qp,z)
Definition CbmKFTrack.h:75
virtual Double_t & GetRefY()
virtual Double_t & GetRefX()
I/O parameters for vertex fit routines.
virtual Double_t & GetRefZ()
virtual Double_t & GetRefChi2()
Array[6] of covariance matrix.
virtual Int_t & GetRefNDF()
Chi^2 after fit.
virtual Double_t * GetCovMatrix()
Double_t GetPz() const
Double_t GetY() const
Bool_t fAtProductionVertex
Double_t GetPx() const
Double_t GetZ() const
Int_t GetQ() const
Double_t GetPy() const
Double_t GetX() const
Double_t fC[36]
void ConstructGamma(const KFParticle &daughter1, const KFParticle &daughter2)
void GetDStoParticleXY(const KFParticleBase &p, Double_t &DS, Double_t &DSp) const
Bool_t GetDistanceFromVertexXY(const Double_t vtx[], Double_t &val, Double_t &err) const
static void GetExternalTrackParam(const KFParticleBase &p, Double_t &X, Double_t &Alpha, Double_t P[5])
const Double_t & Px() const
Definition KFParticle.h:131
Double_t GetDeviationFromVertexXY(const Double_t v[], const Double_t Cv[]=0) const
Double_t GetDeviationFromParticleXY(const KFParticle &p) const
void Transport(Double_t dS, Double_t P[], Double_t C[]) const
const Double_t & Y() const
Definition KFParticle.h:129
const Double_t & Py() const
Definition KFParticle.h:132
Double_t GetAngle(const KFParticle &p) const
Double_t GetPseudoProperDecayTime(const KFParticle &primVertex, const Double_t &mass, Double_t *timeErr2=0) const
Double_t GetDistanceFromParticleXY(const KFParticle &p) const
Double_t GetAngleXY(const KFParticle &p) const
Double_t GetAngleRZ(const KFParticle &p) const
const Double_t & X() const
Definition KFParticle.h:128
Double_t GetDStoPoint(const Double_t xyz[]) const
Definition KFParticle.h:919
void GetDStoParticle(const KFParticle &p, Double_t &DS, Double_t &DSp) const
Definition KFParticle.h:929
Double_t GetCovariance(int i) const
Definition KFParticle.h:492
void Create(const Double_t Param[], const Double_t Cov[], Int_t Charge, Double_t mass)
static TDatabasePDG * Instance()
TParticlePDG * GetParticle(const char *name) const
Double_t Mass() const
RVec< PromoteType< T > > sqrt(const RVec< T > &v)
*brief user defined string literal for JSON values *sa std::size_t n
Definition json.hpp:20362
Double_t ACos(Double_t)
Double_t ATan2(Double_t y, Double_t x)
Double_t Sqrt(Double_t x)
constexpr Double_t Pi()
Double_t Abs(Double_t d)