source: trunk/MagicSoft/Cosy/caos/Ring.cc@ 4107

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