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

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