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

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