Changeset 18620
- Timestamp:
- 09/18/16 14:45:04 (8 years ago)
- Location:
- trunk/FACT++/drive
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/drive/Ring.cc
r18618 r18620 6 6 7 7 #include "Led.h" 8 #include "Leds.h"9 10 #include "Rings.h"11 #include "MString.h"12 13 ClassImp(Ring);14 8 15 9 using namespace std; 16 10 17 Ring::Ring( Double_t x, Double_ty) :18 fX(x), fY(y), fR(0), fPhi(0) , fDx(-1), fDy(-1), fDr(-1), fDphi(-1)11 Ring::Ring(double x, double y) : 12 fX(x), fY(y), fR(0), fPhi(0) 19 13 { 20 14 } 21 15 22 bool Ring::CalcCenter( const Leds &leds, Int_t i, Int_t j, Int_tk)16 bool Ring::CalcCenter(Led i, Led j, Led k) 23 17 { 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(); 18 double h1 = i.GetY() - j.GetY(); 41 19 42 20 if (h1==0) 43 21 { 44 Swap(j, k);45 h1 = leds(i).GetY()- leds(j).GetY();22 std::swap(j, k); 23 h1 = i.GetY() - j.GetY(); 46 24 if (h1==0) 47 25 { 48 26 cout << "Ring::CalcCenter: h1==0" <<endl; 49 return kFALSE;27 return false; 50 28 } 51 29 } 52 30 53 Double_t h2 = leds(j).GetY() - leds(k).GetY();31 double h2 = j.GetY() - k.GetY(); 54 32 55 33 if (h2==0) 56 34 { 57 Swap(i, j);58 h2 = leds(j).GetY() - leds(k).GetY();35 std::swap(i, j); 36 h2 = j.GetY() - k.GetY(); 59 37 if (h2==0) 60 38 { 61 39 cout << "Ring::CalcCenter: h2==0" << endl; 62 return kFALSE;40 return false; 63 41 } 64 42 } 65 43 66 const Double_t w1 = leds(i).GetX() - leds(j).GetX();67 const Double_t w2 = leds(j).GetX() - leds(k).GetX();44 const double w1 = i.GetX() - j.GetX(); 45 const double w2 = j.GetX() - k.GetX(); 68 46 69 const Double_tm1 = -w1/h1;70 const Double_tm2 = -w2/h2;47 const double m1 = -w1/h1; 48 const double m2 = -w2/h2; 71 49 72 if (m2 -m1==0)50 if (m2 - m1==0) 73 51 { 74 52 cout << "Ring::CalcCenter: All three points in a row! (m2-m1==0)" << endl; 75 return kFALSE;53 return false; 76 54 } 77 55 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);56 fX = ((m2*(j.GetX() + k.GetX()) + i.GetY() - k.GetY() -m1*(i.GetX() + j.GetX()))/(m2-m1)/2); 57 fY = ((m2*(i.GetY() + j.GetY()) + m1*m2*(k.GetX() - i.GetX())-m1*(j.GetY() + k.GetY()))/(m2-m1)/2); 80 58 81 fR = hypot(fX -leds(i).GetX(), fY-leds(i).GetY());59 fR = hypot(fX - i.GetX(), fY - i.GetY()); 82 60 83 fMag = ( leds(i).GetMag() + leds(j).GetMag() + leds(k).GetMag())/3;61 fMag = (i.GetMag() + j.GetMag() + k.GetMag())/3; 84 62 85 return kTRUE;63 return true; 86 64 } 87 65 88 void Ring::InterpolCenters(const Rings&rings)66 void Ring::InterpolCenters(const vector<Ring> &rings) 89 67 { 90 const int n=rings.GetEntries();91 92 68 fX = 0; 93 69 fY = 0; 94 70 fR = 0; 95 71 96 fDx=0;97 fDy=0;98 fDr=0;99 100 72 fMag=0; 101 73 102 if (n<1) 74 const int n=rings.size(); 75 if (n==0) 103 76 return; 104 77 105 for ( int i=0; i<n; i++)78 for (auto it=rings.begin(); it!=rings.end(); it++) 106 79 { 107 const Ring &ring = rings(i); 108 109 fX += ring.GetX(); 110 fY += ring.GetY(); 111 fR += ring.GetR(); 112 fMag += ring.GetMag(); 80 fX += it->GetX(); 81 fY += it->GetY(); 82 fR += it->GetR(); 83 fMag += it->GetMag(); 113 84 } 114 85 … … 117 88 fR /= n; 118 89 fMag /= n; 119 120 if (n<2)121 return;122 123 //124 // deviation of x- and y coordinate and radius125 //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 90 } 139 140 void Ring::Print(Option_t *o) const141 {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 -
trunk/FACT++/drive/Ring.h
r18618 r18620 2 2 #define COSY_Ring 3 3 4 #ifndef ROOT_TObject 5 #include <TObject.h> 6 #endif 4 #include <vector> 7 5 8 class Leds; 6 #include "Led.h" 7 9 8 class Rings; 10 9 11 class Ring : public TObject10 class Ring 12 11 { 13 12 private: 14 Double_tfX;15 Double_tfY;16 Double_tfR;17 Double_tfPhi;13 double fX; 14 double fY; 15 double fR; 16 double fPhi; 18 17 19 Double_t fDx; 20 Double_t fDy; 21 Double_t fDr; 22 Double_t fDphi; 18 double fMag; 23 19 24 Double_t fMag; 25 26 Double_t sqr(Double_t x) { return x*x; } 27 28 void Swap(int &m, int &n) 29 { 30 int dummy = m; 31 m = n; 32 n = dummy; 33 } 20 double sqr(double x) { return x*x; } 34 21 35 22 public: 36 Ring( Double_t x=0, Double_ty=0);23 Ring(double x=0, double y=0); 37 24 38 void SetXY(Double_t x=0, Double_t y=0) { fX=x; fY=y; } 25 void SetXY(double x=0, double y=0) { fX=x; fY=y; } 26 void SetPhi(double phi) { fPhi=phi; } 39 27 40 Double_tGetX() const { return fX; }41 Double_tGetY() const { return fY; }42 Double_tGetR() const { return fR; }43 Double_tGetPhi() const { return fPhi; }28 double GetX() const { return fX; } 29 double GetY() const { return fY; } 30 double GetR() const { return fR; } 31 double GetPhi() const { return fPhi; } 44 32 45 Double_tGetMag() const { return fMag; }33 double GetMag() const { return fMag; } 46 34 47 bool CalcCenter(const Leds &leds, Int_t i, Int_t j, Int_t k); 48 void InterpolCenters(const Rings &rings); 49 50 void Print(Option_t *o=NULL) const; 51 52 ClassDef(Ring, 1) 35 bool CalcCenter(Led, Led, Led); 36 void InterpolCenters(const std::vector<Ring> &rings); 53 37 }; 54 38
Note:
See TracChangeset
for help on using the changeset viewer.