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

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