CbmRoot
CbmLitMath.cxx
Go to the documentation of this file.
1 #include "utils/CbmLitMath.h"
2 
3 #include "data/CbmLitHit.h"
4 #include "data/CbmLitPixelHit.h"
5 #include "data/CbmLitStripHit.h"
6 #include "data/CbmLitTrack.h"
8 
9 #include <cmath>
10 #include <iostream>
11 
12 namespace lit {
13 
14  litfloat ChiSq(const CbmLitTrackParam* par, const CbmLitHit* hit) {
15  litfloat chisq = 0.;
16  if (hit->GetType() == kLITSTRIPHIT) {
17  chisq = ChiSq(par, static_cast<const CbmLitStripHit*>(hit));
18  } else if (hit->GetType() == kLITPIXELHIT) {
19  chisq = ChiSq(par, static_cast<const CbmLitPixelHit*>(hit));
20  }
21  return chisq;
22  }
23 
24  litfloat ChiSq(const CbmLitTrackParam* par, const CbmLitStripHit* hit) {
25  litfloat duu = hit->GetDu() * hit->GetDu();
26  litfloat phiCos = hit->GetCosPhi();
27  litfloat phiSin = hit->GetSinPhi();
28  litfloat phiCosSq = phiCos * phiCos;
29  litfloat phiSinSq = phiSin * phiSin;
30  litfloat phi2SinCos = 2 * phiCos * phiSin;
31  litfloat C0 = par->GetCovariance(0);
32  litfloat C1 = par->GetCovariance(1);
33  litfloat C5 = par->GetCovariance(5);
34 
35  litfloat ru = hit->GetU() - par->GetX() * phiCos - par->GetY() * phiSin;
36 
37  return (ru * ru) / (duu - phiCosSq * C0 - phi2SinCos * C1 - phiSinSq * C5);
38  }
39 
40  litfloat ChiSq(const CbmLitTrackParam* par, const CbmLitPixelHit* hit) {
41  litfloat dxx = hit->GetDx() * hit->GetDx();
42  litfloat dxy = hit->GetDxy();
43  litfloat dyy = hit->GetDy() * hit->GetDy();
44  litfloat dtt = hit->GetDt() * hit->GetDt();
45  litfloat xmx = hit->GetX() - par->GetX();
46  litfloat ymy = hit->GetY() - par->GetY();
47  litfloat tmt = hit->GetT() - par->GetTime();
48  litfloat C0 = par->GetCovariance(0);
49  litfloat C1 = par->GetCovariance(1);
50  litfloat C5 = par->GetCovariance(5);
51  litfloat C6 = par->GetCovariance(6);
52  litfloat C10 = par->GetCovariance(10);
53  litfloat C20 = par->GetCovariance(20);
54 
55  /*litfloat norm = dxx * dyy - dxx * C5 - dyy * C0 + C0 * C5
56  - dxy * dxy + 2 * dxy * C1 - C1 * C1;
57  if (norm == 0.) { norm = 1e-10; }
58  return ((xmx * (dyy - C5) - ymy * (dxy - C1)) * xmx
59  +(-xmx * (dxy - C1) + ymy * (dxx - C0)) * ymy) / norm;*/
60  litfloat norm = (dxx - C0) * ((dyy - C6) * (dtt - C20) - C10 * C10)
61  + (dxy - C1) * (C5 * C10 - (dxy - C1) * (dtt - C20))
62  + C5 * ((dxy - C1) * C10 - (dyy - C6) * C5);
63 
64  if (norm == 0.) { norm = 1e-10; }
65 
66  // Mij is the (symmetric) inverse of the residual matrix
67  litfloat M00 = ((dyy - C6) * (dtt - C20) - C10 * C10) / norm;
68  litfloat M01 = ((dxy - C1) * (dtt - C20) - C5 * C10) / norm;
69  litfloat M02 = ((dxy - C1) * C10 - (dyy - C6) * C5) / norm;
70  litfloat M11 = ((dxx - C0) * (dtt - C20) - C5 * C5) / norm;
71  litfloat M12 = ((dxx - C0) * C10 - (dxy - C1) * C5) / norm;
72  litfloat M22 = ((dxx - C0) * (dyy - C6) - (dxy - C1) * (dxy - C1)) / norm;
73 
74  return xmx * (xmx * M00 + ymy * M01 + tmt * M02)
75  + ymy * (xmx * M01 + ymy * M11 + tmt * M12)
76  + tmt * (xmx * M02 + ymy * M12 + tmt * M22);
77  }
78 
79  Int_t NDF(const CbmLitTrack* track) {
80  Int_t ndf = 0;
81  for (Int_t i = 0; i < track->GetNofHits(); i++) {
82  if (track->GetHit(i)->GetType() == kLITPIXELHIT) {
83  ndf += 2;
84  } else if (track->GetHit(i)->GetType() == kLITSTRIPHIT) {
85  ndf++;
86  }
87  }
88  ndf -= 5;
89  if (ndf > 0) {
90  return ndf;
91  } else {
92  return 1;
93  }
94  }
95 
96 } // namespace lit
CbmLitHit::GetT
litfloat GetT() const
Definition: CbmLitHit.h:50
CbmLitTrackParam.h
Data class for track parameters.
litfloat
double litfloat
Definition: CbmLitFloat.h:15
CbmLitPixelHit::GetDy
litfloat GetDy() const
Definition: CbmLitPixelHit.h:40
CbmLitStripHit.h
Base data class for strip hits.
CbmLitStripHit::GetCosPhi
litfloat GetCosPhi() const
Definition: CbmLitStripHit.h:41
CbmLitTrackParam::GetX
litfloat GetX() const
Definition: CbmLitTrackParam.h:53
CbmLitTrackParam
Data class for track parameters.
Definition: CbmLitTrackParam.h:29
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmLitTrackParam::GetY
litfloat GetY() const
Definition: CbmLitTrackParam.h:54
CbmLitTrackParam::GetCovariance
litfloat GetCovariance(int index) const
Definition: CbmLitTrackParam.h:60
CbmLitPixelHit.h
Base data class for pixel hits.
lit::ChiSq
litfloat ChiSq(const CbmLitTrackParam *par, const CbmLitHit *hit)
Definition: CbmLitMath.cxx:14
CbmLitStripHit::GetU
litfloat GetU() const
Definition: CbmLitStripHit.h:38
CbmLitPixelHit::GetY
litfloat GetY() const
Definition: CbmLitPixelHit.h:38
lit::NDF
Int_t NDF(const CbmLitTrack *track)
Definition: CbmLitMath.cxx:79
CbmLitHit
Base data class for hits.
Definition: CbmLitHit.h:26
kLITSTRIPHIT
@ kLITSTRIPHIT
Definition: CbmLitEnums.h:15
CbmLitMath.h
CbmLitTrack
Base data class for track.
Definition: CbmLitTrack.h:30
CbmLitPixelHit
Base data class for pixel hits.
Definition: CbmLitPixelHit.h:22
kLITPIXELHIT
@ kLITPIXELHIT
Definition: CbmLitEnums.h:16
CbmLitStripHit::GetDu
litfloat GetDu() const
Definition: CbmLitStripHit.h:39
CbmLitStripHit::GetSinPhi
litfloat GetSinPhi() const
Definition: CbmLitStripHit.h:42
CbmLitPixelHit::GetDxy
litfloat GetDxy() const
Definition: CbmLitPixelHit.h:41
CbmLitPixelHit::GetX
litfloat GetX() const
Definition: CbmLitPixelHit.h:37
CbmLitHit::GetDt
litfloat GetDt() const
Definition: CbmLitHit.h:51
CbmLitTrack.h
Base data class for track.
CbmLitTrackParam::GetTime
litfloat GetTime() const
Definition: CbmLitTrackParam.h:59
CbmLitTrack::GetHit
const CbmLitHit * GetHit(Int_t index) const
Definition: CbmLitTrack.h:65
CbmLitStripHit
Base data class for strip hits.
Definition: CbmLitStripHit.h:22
CbmLitHit::GetType
LitHitType GetType() const
Definition: CbmLitHit.h:47
CbmLitPixelHit::GetDx
litfloat GetDx() const
Definition: CbmLitPixelHit.h:39
CbmLitHit.h
Base data class for hits.
CbmLitTrack::GetNofHits
Int_t GetNofHits() const
Definition: CbmLitTrack.h:56
lit
Definition: LitTrackFinderNNVecElectron.h:19