1 | #include "Ring.h"
|
---|
2 |
|
---|
3 | #include <iostream.h>
|
---|
4 |
|
---|
5 | #include "Led.h"
|
---|
6 | #include "Leds.h"
|
---|
7 |
|
---|
8 | #include "Rings.h"
|
---|
9 |
|
---|
10 | ClassImp(Ring);
|
---|
11 |
|
---|
12 | Ring::Ring() :
|
---|
13 | fX(0), fY(0), fR(0), fPhi(0), fDx(-1), fDy(-1), fDr(-1), fDphi(-1)
|
---|
14 | {
|
---|
15 | }
|
---|
16 |
|
---|
17 |
|
---|
18 | bool Ring::CalcCenter(const Leds &leds, Int_t i, Int_t j, Int_t k)
|
---|
19 | {
|
---|
20 | Double_t h1 = leds(i).GetY()- leds(j).GetY();
|
---|
21 |
|
---|
22 | if (h1==0)
|
---|
23 | {
|
---|
24 | Swap(&j, &k);
|
---|
25 | h1 = leds(i).GetY()- leds(j).GetY();
|
---|
26 | if (h1==0)
|
---|
27 | {
|
---|
28 | cout << "h1==0" <<endl;
|
---|
29 | return kFALSE;
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | Double_t h2 = leds(j).GetY() - leds(k).GetY();
|
---|
34 |
|
---|
35 | if (h2==0)
|
---|
36 | {
|
---|
37 | Swap(&i, &j);
|
---|
38 | h2 = leds(j).GetY() - leds(k).GetY();
|
---|
39 | if (h2==0)
|
---|
40 | {
|
---|
41 | cout << "h2==0" << endl;
|
---|
42 | return kFALSE;
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | const Double_t w1 = leds(i).GetX() - leds(j).GetX();
|
---|
47 | const Double_t w2 = leds(j).GetX() - leds(k).GetX();
|
---|
48 |
|
---|
49 | const Double_t m1 = -w1/h1;
|
---|
50 | const Double_t m2 = -w2/h2;
|
---|
51 |
|
---|
52 | if (m2-m1==0)
|
---|
53 | {
|
---|
54 | cout << "All three points in a row! (m2-m1==0)" << endl;
|
---|
55 | return kFALSE;
|
---|
56 | }
|
---|
57 |
|
---|
58 | fX = ((m2*(leds(j).GetX() + leds(k).GetX()) + leds(i).GetY() - leds(k).GetY() -m1*(leds(i).GetX() + leds(j).GetX()))/(m2-m1)/2);
|
---|
59 | fY = ((m2*(leds(i).GetY() + leds(j).GetY()) +m1*m2*(leds(k).GetX() - leds(i).GetX())-m1*(leds(j).GetY() + leds(k).GetY()))/(m2-m1)/2);
|
---|
60 |
|
---|
61 | fR = hypot(fX-leds(i).GetX(), fY-leds(i).GetY());
|
---|
62 |
|
---|
63 | return kTRUE;
|
---|
64 | }
|
---|
65 |
|
---|
66 | void Ring::InterpolCenters(const Rings &rings)
|
---|
67 | {
|
---|
68 | const int n=rings.GetEntries();
|
---|
69 |
|
---|
70 | fX = 0;
|
---|
71 | fY = 0;
|
---|
72 | fR = 0;
|
---|
73 |
|
---|
74 | fDx=0;
|
---|
75 | fDy=0;
|
---|
76 | fDr=0;
|
---|
77 |
|
---|
78 | if (n<1)
|
---|
79 | return;
|
---|
80 |
|
---|
81 | for (int i=0; i<n; i++)
|
---|
82 | {
|
---|
83 | const Ring &ring = rings(i);
|
---|
84 |
|
---|
85 | fX += ring.GetX();
|
---|
86 | fY += ring.GetY();
|
---|
87 | fR += ring.GetR();
|
---|
88 | }
|
---|
89 |
|
---|
90 | fX /= n;
|
---|
91 | fY /= n;
|
---|
92 | fR /= n;
|
---|
93 |
|
---|
94 | if (n<2)
|
---|
95 | return;
|
---|
96 |
|
---|
97 | //
|
---|
98 | // deviation of x- and y coordinate and radius
|
---|
99 | //
|
---|
100 | for (int i=0; i<n; i++)
|
---|
101 | {
|
---|
102 | const Ring &ring = rings(i);
|
---|
103 |
|
---|
104 | fDx += sqr(ring.GetX()-fX);
|
---|
105 | fDy += sqr(ring.GetY()-fY);
|
---|
106 | fDr += sqr(ring.GetR()-fR);
|
---|
107 | }
|
---|
108 |
|
---|
109 | fDx=sqrt(fDx)/n;
|
---|
110 | fDy=sqrt(fDy)/n;
|
---|
111 | fDr=sqrt(fDr)/n;
|
---|
112 | }
|
---|
113 |
|
---|
114 | void Ring::Print(Option_t *o=NULL) const
|
---|
115 | {
|
---|
116 | cout << "Ring: ";
|
---|
117 | cout << "x=" << Form("%5.1f", fX) << "+-" << Form("%.1f", fDx) << ", ";
|
---|
118 | cout << "y=" << Form("%5.1f", fY) << "+-" << Form("%.1f", fDy) << ", ";
|
---|
119 | cout << "r=" << Form("%5.1f", fR) << "+-" << Form("%.1f", fDr) << ", ";
|
---|
120 | cout << "phi=" << fPhi << "+-" << fDphi << endl;
|
---|
121 | }
|
---|
122 |
|
---|