source: trunk/Cosy/caos/Ring.cc@ 17113

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