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

Last change on this file since 4823 was 4357, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 2.7 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 fMag = (leds(i).GetMag() + leds(j).GetMag() + leds(k).GetMag())/3;
65
66 return kTRUE;
67}
68
69void Ring::InterpolCenters(const Rings &rings)
70{
71 const int n=rings.GetEntries();
72
73 fX = 0;
74 fY = 0;
75 fR = 0;
76
77 fDx=0;
78 fDy=0;
79 fDr=0;
80
81 fMag=0;
82
83 if (n<1)
84 return;
85
86 for (int i=0; i<n; i++)
87 {
88 const Ring &ring = rings(i);
89
90 fX + = ring.GetX();
91 fY += ring.GetY();
92 fR += ring.GetR();
93 fMag += ring.GetMag();
94 }
95
96 fX /= n;
97 fY /= n;
98 fR /= n;
99 fMag /= n;
100
101 if (n<2)
102 return;
103
104 //
105 // deviation of x- and y coordinate and radius
106 //
107 for (int i=0; i<n; i++)
108 {
109 const Ring &ring = rings(i);
110
111 fDx += sqr(ring.GetX()-fX);
112 fDy += sqr(ring.GetY()-fY);
113 fDr += sqr(ring.GetR()-fR);
114 }
115
116 fDx=sqrt(fDx)/n;
117 fDy=sqrt(fDy)/n;
118 fDr=sqrt(fDr)/n;
119}
120
121void Ring::Print(Option_t *o=NULL) const
122{
123 MString str;
124 cout << "Ring: ";
125 cout << "x=" << str.Print("%5.1f", fX) << "+-" << Form("%.1f", fDx) << ", ";
126 cout << "y=" << str.Print("%5.1f", fY) << "+-" << Form("%.1f", fDy) << ", ";
127 cout << "r=" << str.Print("%5.1f", fR) << "+-" << Form("%.1f", fDr) << ", ";
128 cout << "phi=" << fPhi << "+-" << fDphi << endl;
129}
130
Note: See TracBrowser for help on using the repository browser.