CbmRoot
Loading...
Searching...
No Matches
CbmRichRingFitterCircle.cxx
Go to the documentation of this file.
1/* Copyright (C) 2006-2012 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Supriya Das, Semen Lebedev, Denis Bertini [committer] */
4
13
14#include "CbmRichRingLight.h"
15
17
19
21{
22 int nofHits = ring->GetNofHits();
23 if (nofHits < 3) return;
24
25 float c[3], a[3][3];
26
27 float b1 = 0.f;
28 float b2 = 0.f;
29 float b3 = 0.f;
30
31 float b12 = 0.f;
32 float b22 = 0.f;
33 float b32 = nofHits;
34
35 float a11 = 0.f;
36 float a12 = 0.f;
37 float a13 = 0.f;
38 float a21 = 0.f;
39 float a22 = 0.f;
40 float a23 = 0.f;
41 float a31 = 0.f;
42 float a32 = 0.f;
43 float a33 = 0.f;
44
45 float meanX = 0.f;
46 float meanY = 0.f;
47
48 for (int iHit = 0; iHit < nofHits; iHit++) {
49 float hx = ring->GetHit(iHit).fX;
50 float hy = ring->GetHit(iHit).fY;
51
52 b1 += (hx * hx + hy * hy) * hx;
53 b2 += (hx * hx + hy * hy) * hy;
54 b3 += (hx * hx + hy * hy);
55
56 b12 += hx;
57 b22 += hy;
58
59 a11 += 2 * hx * hx;
60 a12 += 2 * hx * hy;
61 a22 += 2 * hy * hy;
62
63 meanX += hx;
64 meanY += hy;
65 }
66
67 if (nofHits != 0) {
68 meanX = meanX / (float) (nofHits);
69 meanY = meanY / (float) (nofHits);
70 }
71
72 a21 = a12;
73
74 a13 = b12;
75 a23 = b22;
76
77 a31 = 2 * b12;
78 a32 = 2 * b22;
79 a33 = b32;
80
81 c[0] = b1 * b22 - b2 * b12;
82 c[1] = b1 * b32 - b3 * b12;
83 c[2] = b2 * b32 - b3 * b22;
84
85 a[0][0] = a11 * b22 - a21 * b12;
86 a[1][0] = a12 * b22 - a22 * b12;
87 a[2][0] = a13 * b22 - a23 * b12;
88
89 a[0][1] = a11 * b32 - a31 * b12;
90 a[1][1] = a12 * b32 - a32 * b12;
91 a[2][1] = a13 * b32 - a33 * b12;
92
93 a[0][2] = a21 * b32 - a31 * b22;
94 a[1][2] = a22 * b32 - a32 * b22;
95 a[2][2] = a23 * b32 - a33 * b22;
96
97 float det1 = a[0][0] * a[1][1] - a[0][1] * a[1][0];
98
99 float x11 = (c[0] * a[1][1] - c[1] * a[1][0]) / det1;
100 float x21 = (a[0][0] * c[1] - a[0][1] * c[0]) / det1;
101
102 // Float_t det2 = a[0][1]*a[1][2] - a[0][2]*a[1][1];
103 // Float_t det3 = a[0][0]*a[1][2] - a[0][2]*a[1][0];
104 // Float_t x12 = (c[1]*a[1][2] - c[2]*a[1][1])/det2;
105 // Float_t x22 = (a[0][1]*c[2] - a[0][2]*c[1])/det2;
106
107 float radius = sqrt((b3 + b32 * (x11 * x11 + x21 * x21) - a31 * x11 - a32 * x21) / a33);
108 float centerX = x11;
109 float centerY = x21;
110
111 ring->SetRadius(radius);
112 ring->SetCenterX(centerX);
113 ring->SetCenterY(centerY);
114
115 //if (TMath::IsNaN(radius) == 1) ring->SetRadius(0.);
116 //if (TMath::IsNaN(centerX) == 1) ring->SetCenterX(0.);
117 //if (TMath::IsNaN(centerY) == 1) ring->SetCenterY(0.);
118
119 CalcChi2(ring);
120}
Implementation of a ring fitting algorithm with equation of a circle. Algorithm from F77 subroutine o...
friend fvec sqrt(const fvec &a)
virtual void CalcChi2(CbmRichRingLight *ring)
Calculate chi2 for circle fitting algorithms.
void DoFit(CbmRichRingLight *ring)
Inherited from CbmRichRingFitterBase.
virtual ~CbmRichRingFitterCircle()
Destructor.
CbmRichRingFitterCircle()
Default constructor.
void SetRadius(float r)
void SetCenterY(float y)
int GetNofHits() const
Return number of hits in ring.
CbmRichHitLight GetHit(int ind)
Return hit by the index.
void SetCenterX(float x)