EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CbmRichRingFitterCircle.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CbmRichRingFitterCircle.cxx
1 
9 #include "CbmRichRingLight.h"
10 
12 {
13 
14 }
15 
17 {
18 
19 }
20 
22  CbmRichRingLight* ring)
23 {
24  int nofHits = ring->GetNofHits();
25  if (nofHits < 3) return;
26 
27  float c[3], a[3][3];
28 
29  float b1 = 0.f;
30  float b2 = 0.f;
31  float b3 = 0.f;
32 
33  float b12 = 0.f;
34  float b22 = 0.f;
35  float b32 = nofHits;
36 
37  float a11 = 0.f;
38  float a12 = 0.f;
39  float a13 = 0.f;
40  float a21 = 0.f;
41  float a22 = 0.f;
42  float a23 = 0.f;
43  float a31 = 0.f;
44  float a32 = 0.f;
45  float a33 = 0.f;
46 
47  float meanX = 0.f;
48  float meanY = 0.f;
49 
50  for (int iHit = 0; iHit < nofHits; iHit++) {
51  float hx = ring->GetHit(iHit).fX;
52  float hy = ring->GetHit(iHit).fY;
53 
54  b1 += (hx*hx + hy*hy) * hx;
55  b2 += (hx*hx + hy*hy) * hy;
56  b3 += (hx*hx + hy*hy);
57 
58  b12 += hx;
59  b22 += hy;
60 
61  a11 += 2*hx*hx;
62  a12 += 2*hx*hy;
63  a22 += 2*hy*hy;
64 
65  meanX += hx;
66  meanY += hy;
67  }
68 
69  if (nofHits != 0) {
70  meanX = meanX/(float)(nofHits);
71  meanY = meanY/(float)(nofHits);
72  }
73 
74  a21 = a12;
75 
76  a13 = b12;
77  a23 = b22;
78 
79  a31 = 2*b12;
80  a32 = 2*b22;
81  a33 = b32;
82 
83  c[0] = b1*b22 - b2*b12;
84  c[1] = b1*b32 - b3*b12;
85  c[2] = b2*b32 - b3*b22;
86 
87  a[0][0] = a11*b22 - a21*b12;
88  a[1][0] = a12*b22 - a22*b12;
89  a[2][0] = a13*b22 - a23*b12;
90 
91  a[0][1] = a11*b32 - a31*b12;
92  a[1][1] = a12*b32 - a32*b12;
93  a[2][1] = a13*b32 - a33*b12;
94 
95  a[0][2] = a21*b32-a31*b22;
96  a[1][2] = a22*b32-a32*b22;
97  a[2][2] = a23*b32-a33*b22;
98 
99  float det1 = a[0][0]*a[1][1] - a[0][1]*a[1][0];
100 
101  float x11 = (c[0]*a[1][1] - c[1]*a[1][0]) / det1;
102  float x21 = (a[0][0]*c[1] - a[0][1]*c[0]) / det1;
103 
104 // Float_t det2 = a[0][1]*a[1][2] - a[0][2]*a[1][1];
105 // Float_t det3 = a[0][0]*a[1][2] - a[0][2]*a[1][0];
106 // Float_t x12 = (c[1]*a[1][2] - c[2]*a[1][1])/det2;
107 // Float_t x22 = (a[0][1]*c[2] - a[0][2]*c[1])/det2;
108 
109  float radius = sqrt((b3 + b32*(x11*x11 + x21*x21) - a31*x11 - a32*x21)/a33);
110  float centerX = x11;
111  float centerY = x21;
112 
113  ring->SetRadius(radius);
114  ring->SetCenterX(centerX);
115  ring->SetCenterY(centerY);
116 
117  //if (TMath::IsNaN(radius) == 1) ring->SetRadius(0.);
118  //if (TMath::IsNaN(centerX) == 1) ring->SetCenterX(0.);
119  //if (TMath::IsNaN(centerY) == 1) ring->SetCenterY(0.);
120 
121  CalcChi2(ring);
122 }