EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CbmLitMath.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CbmLitMath.cxx
1 #include "utils/CbmLitMath.h"
2 
3 #include "data/CbmLitTrackParam.h"
4 #include "data/CbmLitHit.h"
5 #include "data/CbmLitStripHit.h"
6 #include "data/CbmLitPixelHit.h"
7 #include "data/CbmLitTrack.h"
8 
9 #include <iostream>
10 #include <cmath>
11 
12 namespace lit
13 {
14 
15 litfloat ChiSq(
16  const CbmLitTrackParam* par,
17  const CbmLitHit* hit)
18 {
19  litfloat chisq = 0.;
20  if (hit->GetType() == kLITSTRIPHIT) {
21  chisq = ChiSq(par, static_cast<const CbmLitStripHit*>(hit));
22  } else if (hit->GetType() == kLITPIXELHIT) {
23  chisq = ChiSq(par, static_cast<const CbmLitPixelHit*>(hit));
24  }
25  return chisq;
26 }
27 
28 litfloat ChiSq(
29  const CbmLitTrackParam* par,
30  const CbmLitStripHit* hit)
31 {
32  litfloat duu = hit->GetDu() * hit->GetDu();
33  litfloat phiCos = hit->GetCosPhi();
34  litfloat phiSin = hit->GetSinPhi();
35  litfloat phiCosSq = phiCos * phiCos;
36  litfloat phiSinSq = phiSin * phiSin;
37  litfloat phi2SinCos = 2 * phiCos * phiSin;
38  litfloat C0 = par->GetCovariance(0);
39  litfloat C1 = par->GetCovariance(1);
40  litfloat C5 = par->GetCovariance(5);
41 
42  litfloat ru = hit->GetU() - par->GetX() * phiCos - par->GetY() * phiSin;
43 
44  return (ru * ru) / (duu - phiCosSq*C0 - phi2SinCos*C1 - phiSinSq*C5);
45 }
46 
47 litfloat ChiSq(
48  const CbmLitTrackParam* par,
49  const CbmLitPixelHit* hit)
50 {
51  litfloat dxx = hit->GetDx() * hit->GetDx();
52  litfloat dxy = hit->GetDxy();
53  litfloat dyy = hit->GetDy() * hit->GetDy();
54  litfloat xmx = hit->GetX() - par->GetX();
55  litfloat ymy = hit->GetY() - par->GetY();
56  litfloat C0 = par->GetCovariance(0);
57  litfloat C1 = par->GetCovariance(1);
58  litfloat C5 = par->GetCovariance(5);
59 
60  litfloat norm = dxx * dyy - dxx * C5 - dyy * C0 + C0 * C5
61  - dxy * dxy + 2 * dxy * C1 - C1 * C1;
62  if (norm == 0.) { norm = 1e-10; }
63  return ((xmx * (dyy - C5) - ymy * (dxy - C1)) * xmx
64  +(-xmx * (dxy - C1) + ymy * (dxx - C0)) * ymy) / norm;
65 }
66 
67 Int_t NDF(
68  const CbmLitTrack* track)
69 {
70  Int_t ndf = 0;
71  for (Int_t i = 0; i < track->GetNofHits(); i++) {
72  if (track->GetHit(i)->GetType() == kLITPIXELHIT) { ndf += 2; }
73  else if (track->GetHit(i)->GetType() == kLITSTRIPHIT) { ndf++; }
74  }
75  ndf -= 5;
76  if (ndf > 0) { return ndf; }
77  else { return 1; }
78 }
79 
80 }
81