Changeset 4107 for trunk/MagicSoft/Cosy/tpoint
- Timestamp:
- 05/20/04 05:40:59 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/tpoint/gui.C
r2568 r4107 1 #include <fstream.h> 2 #include <fstream.h> 1 3 #include <fstream.h> 2 4 #include <iostream.h> 3 5 #include <iomanip.h> 6 7 #include <TError.h> 4 8 5 9 #include <TGFrame.h> … … 38 42 public: 39 43 Set(Double_t sel=0, Double_t saz=0, Double_t rel=0, Double_t raz=0) : 40 fStarAz(saz*TMath::Pi()/180), 41 fStarEl(sel*TMath::Pi()/180), 42 fRawAz(raz*TMath::Pi()/180), 43 fRawEl(rel*TMath::Pi()/180) 44 { 45 } 46 47 Double_t GetResidual() const 48 { 49 Double_t del = fRawEl-fStarEl; 50 Double_t daz = fRawAz-fStarAz; 51 Double_t dphi2 = daz/2.; 52 Double_t cos2 = cos(dphi2)*cos(dphi2); 53 Double_t sin2 = sin(dphi2)*sin(dphi2); 54 Double_t d = cos(del)*cos2 - cos(fRawEl+fStarEl)*sin2; 55 56 Double_t dist = acos(d); 57 58 return dist * 180 / TMath::Pi(); 44 fStarAz(saz*TMath::DegToRad()), 45 fStarEl(sel*TMath::DegToRad()), 46 fRawAz(raz*TMath::DegToRad()), 47 fRawEl(rel*TMath::DegToRad()) 48 { 49 } 50 51 Double_t GetResidual(Double_t *err=0) const 52 { 53 /* 54 TVector3 v1, v2; 55 v1.SetMagThetaPhi(1, TMath::Pi()/2-fRawEl, fRawAz); 56 v2.SetMagThetaPhi(1, TMath::Pi()/2-fStarEl, fStarAz); 57 58 return v1.Angle(v2)*TMath::RadToDeg(); 59 */ 60 61 const Double_t del = fRawEl-fStarEl; 62 const Double_t daz = fRawAz-fStarAz; 63 /* 64 const Double_t dphi2 = daz/2.; 65 const Double_t cos2 = cos(dphi2)*cos(dphi2); 66 const Double_t sin2 = sin(dphi2)*sin(dphi2); 67 const Double_t d = cos(del)*cos2 - cos(fRawEl+fStarEl)*sin2; 68 */ 69 70 const Double_t d = cos(del) - cos(fRawEl)*cos(fStarEl)*(1.-cos(daz)); 71 72 if (err) 73 { 74 // Error of one pixel in the CCD 75 const Double_t e1 = 32./3600*TMath::DegToRad() * 0.5; 76 77 // Error of one SE unit 78 const Double_t e2 = 360./16384*TMath::DegToRad() * 0.5; 79 80 const Double_t e11 = sin(del)+cos(fRawEl)*sin(fStarEl)*(1-cos(daz)); 81 const Double_t e12 = cos(fRawEl)*cos(fStarEl)*sin(daz); 82 83 const Double_t e21 = -sin(del)+sin(fRawEl)*cos(fStarEl)*(1-cos(daz)); 84 const Double_t e22 = -cos(fRawEl)*cos(fStarEl)*sin(daz); 85 86 const Double_t err1 = sqrt(1-d*d); 87 const Double_t err2 = (e11*e11 + e12*e12)*e1*e1; 88 const Double_t err3 = (e21*e21 + e22*e22)*e2*e2; 89 90 *err = sqrt(err2+err3)/err1 * TMath::RadToDeg(); 91 } 92 93 const Double_t dist = acos(d); 94 return dist * TMath::RadToDeg(); 59 95 } 60 96 … … 67 103 } 68 104 69 Double_t GetDEl() const { return (fRawEl-fStarEl)* 180/TMath::Pi(); }105 Double_t GetDEl() const { return (fRawEl-fStarEl)*TMath::RadToDeg(); } 70 106 Double_t GetDZd() const { return -GetDEl(); } 71 Double_t GetDAz() const { return (fRawAz-fStarAz)* 180/TMath::Pi(); }72 Double_t GetStarEl() const { return fStarEl* 180/TMath::Pi(); }73 Double_t GetStarZd() const { return 90.-fStarEl* 180/TMath::Pi(); }74 Double_t GetStarAz() const { return fStarAz* 180/TMath::Pi(); }75 Double_t GetRawEl() const { return fRawEl* 180/TMath::Pi(); }76 Double_t GetRawAz() const { return fRawAz* 180/TMath::Pi(); }77 Double_t GetRawZd() const { return 90.-fRawEl* 180/TMath::Pi(); }107 Double_t GetDAz() const { return (fRawAz-fStarAz)*TMath::RadToDeg(); } 108 Double_t GetStarEl() const { return fStarEl*TMath::RadToDeg(); } 109 Double_t GetStarZd() const { return 90.-fStarEl*TMath::RadToDeg(); } 110 Double_t GetStarAz() const { return fStarAz*TMath::RadToDeg(); } 111 Double_t GetRawEl() const { return fRawEl*TMath::RadToDeg(); } 112 Double_t GetRawAz() const { return fRawAz*TMath::RadToDeg(); } 113 Double_t GetRawZd() const { return 90.-fRawEl*TMath::RadToDeg(); } 78 114 79 115 ZdAz GetStarZdAz() const { return ZdAz(TMath::Pi()/2-fStarEl, fStarAz); } … … 83 119 AltAz GetRawAltAz() const { return AltAz(fRawEl, fRawAz); } 84 120 85 void AdjustEl(Double_t del) { fStarEl += del*TMath:: Pi()/180; }86 void AdjustAz(Double_t daz) { fStarAz += daz*TMath:: Pi()/180; }121 void AdjustEl(Double_t del) { fStarEl += del*TMath::DegToRad(); } 122 void AdjustAz(Double_t daz) { fStarAz += daz*TMath::DegToRad(); } 87 123 88 124 void Adjust(const MBending &bend) … … 105 141 ifstream &operator>>(ifstream &fin, Set &set) 106 142 { 107 Double_t v[4]; 108 fin >> v[0]; 109 fin >> v[1]; 110 fin >> v[2]; 111 fin >> v[3]; 112 113 Double_t dummy; 114 fin>>dummy; 115 fin>>dummy; 116 fin>>dummy; 117 118 set.fStarAz = v[0]*TMath::Pi()/180; 119 set.fStarEl = v[1]*TMath::Pi()/180; 120 121 set.fRawAz = v[2]*TMath::Pi()/180; 122 set.fRawEl = v[3]*TMath::Pi()/180; 143 TString str; 144 str.ReadLine(fin); 145 146 Float_t v[4]; 147 sscanf(str.Data(), "%f %f %f %f", v, v+1, v+2, v+3); 148 149 set.fStarAz = v[0]*TMath::DegToRad(); 150 set.fStarEl = v[1]*TMath::DegToRad(); 151 152 set.fRawAz = v[2]*TMath::DegToRad(); 153 set.fRawEl = v[3]*TMath::DegToRad(); 154 155 if (fin) 156 { 157 Double_t res, err; 158 res = set.GetResidual(&err); 159 cout << "Read: " << v[0] << " " << v[1] << " : " << v[2] << " " << v[3] << " : " << v[2]-v[0] << " " << v[3]-v[1] << " : " << res << " " << err << " " << err/res << endl; 160 } 123 161 124 162 return fin; … … 160 198 set.Adjust(bend); 161 199 162 Double_t err = 0.02; // [deg] = 1SE 163 Double_t res = set.GetResidual()/err; 200 Double_t err;// = 0.005; // [deg] = 0.25SE 201 Double_t res = set.GetResidual(&err); 202 res /= err; 164 203 165 204 f += res*res; … … 168 207 //f /= (fCoordinates.GetSize()-7)*(fCoordinates.GetSize()-7); 169 208 //f /= fCoordinates.GetSize()*fCoordinates.GetSize(); 209 //cout << f << ": " << fCoordinates.GetSize() << endl; 170 210 f /= fCoordinates.GetSize(); 171 211 } … … 187 227 188 228 TMarker mark0; 189 TMarker mark1;229 //TMarker mark1; 190 230 mark0.SetMarkerStyle(kStar); 191 mark1.SetMarkerStyle(kStar);192 mark1.SetMarkerColor(kRed);231 //mark1.SetMarkerStyle(kStar); 232 //mark1.SetMarkerColor(kRed); 193 233 194 234 r0 /= 90; 195 r1 /= 90;196 phi0 *= TMath:: Pi()/180;197 phi1 *= TMath::Pi()/180;198 235 //r1 /= 90; 236 phi0 *= TMath::DegToRad(); 237 //phi1 *= TMath::DegToRad(); 238 199 239 Double_t x0[3] = { r0*cos(phi0), r0*sin(phi0), 0}; 200 Double_t x1[3] = { r1*cos(phi1), r1*sin(phi1), 0};201 240 //Double_t x1[3] = { r1*cos(phi1), r1*sin(phi1), 0}; 241 202 242 Double_t y0[3], y1[3]; 203 243 204 244 view->WCtoNDC(x0, y0); 205 view->WCtoNDC(x1, y1);245 //view->WCtoNDC(x1, y1); 206 246 207 247 mark0.DrawMarker(y0[0], y0[1]); 208 mark1.DrawMarker(y1[0], y1[1]);248 //mark1.DrawMarker(y1[0], y1[1]); 209 249 } 210 250 … … 256 296 Double_t dp = p1-p0; 257 297 258 Double_t x0[3] = { r0*cos(p0*TMath:: Pi()/180), r0*sin(p0*TMath::Pi()/180), 0};298 Double_t x0[3] = { r0*cos(p0*TMath::DegToRad()), r0*sin(p0*TMath::DegToRad()), 0}; 259 299 260 300 for (double i=p0+10; i<p1+10; i+=10) … … 264 304 265 305 Double_t r = dr/dp*(i-p0)+r0; 266 Double_t p = TMath:: Pi()/180*i;306 Double_t p = TMath::DegToRad()*i; 267 307 268 308 Double_t x1[3] = { r*cos(p), r*sin(p), 0}; … … 280 320 } 281 321 282 void DrawSet(TVirtualPad *pad, Set &set, Float_t scale=-1 )322 void DrawSet(TVirtualPad *pad, Set &set, Float_t scale=-1, Float_t angle=0) 283 323 { 284 324 Double_t r0 = set.GetRawZd(); 285 Double_t phi0 = set.GetRawAz() ;325 Double_t phi0 = set.GetRawAz()-angle; 286 326 Double_t r1 = set.GetStarZd(); 287 Double_t phi1 = set.GetStarAz() ;327 Double_t phi1 = set.GetStarAz()-angle; 288 328 289 329 if (r0<0) … … 323 363 } 324 364 325 void Fit( )365 void Fit(Double_t &before, Double_t &after, Double_t &backw) 326 366 { 327 367 if (fOriginal.GetSize()==0) … … 336 376 337 377 cout << "-----------------------------------------------------------------------" << endl; 338 339 TH1F hres1("Res1", " Residuals before correction ", fOriginal.GetSize()/2, 0, 3); 340 TH1F hres2("Res2", " Residuals after correction ", fOriginal.GetSize(), 0, 3); 341 TH1F hres3("Res3", " Residuals after backward correction ", fOriginal.GetSize(), 0, 3); 378 379 gStyle->SetOptStat("emro"); 380 381 TH1F hres1("Res1", " Residuals before correction ", fOriginal.GetSize()/3, 0, 0.3); 382 TH1F hres2("Res2", " Residuals after correction ", fOriginal.GetSize()/3, 0, 0.3); 383 TH1F hres3("Res3", " Residuals after backward correction ", fOriginal.GetSize()/3, 0, 0.3); 342 384 343 385 hres1.SetXTitle("\\Delta [\\circ]"); … … 505 547 cout << endl; 506 548 507 508 509 549 510 550 TCanvas *c1; … … 576 616 cout << "before: " << hres1.GetMean() << " \xb1 " << hres1.GetRMS() << " deg " << endl; 577 617 cout << "after: " << hres2.GetMean() << " \xb1 " << hres2.GetRMS() << " deg " << endl; 578 cout << "before: " << (int)(hres1.GetMean()*60+.5) << " \xb1 " << (int)(hres1.GetRMS()*60+.5) << " arcmin" << endl;579 cout << "after: " << (int)(hres2.GetMean()*60+.5) << " \xb1 " << (int)(hres2.GetRMS()*60+.5) << " arcmin" << endl;580 cout << "before: " << (int)(hres1.GetMean()*60*60/23.4+.5) << " \xb1 " << (int)(hres1.GetRMS()*60*60/23.4+.5) << " pix" << endl;581 cout << "after: " << (int)(hres2.GetMean()*60*60/23.4+.5) << " \xb1 " << (int)(hres2.GetRMS()*60*60/23.4+.5) << " pix" << endl;582 cout << "after: " << (int)(hres2.GetMean()*16384/360+.5) << " \xb1 " << (int)(hres2.GetRMS()*16384/360+.5) << " SE" << endl;583 618 cout << endl; 584 cout << "backw: " << (int)(hres3.GetMean()*60+.5) << " \xb1 " << (int)(hres3.GetRMS()*60+.5) << " arcmin" << endl; 619 cout << "before: " << Form("%.1f", hres1.GetMean()*60) << " \xb1 " << Form("%.1f", hres1.GetRMS()*60) << " arcmin" << endl; 620 cout << "after: " << Form("%.1f", hres2.GetMean()*60) << " \xb1 " << Form("%.1f", hres2.GetRMS()*60) << " arcmin" << endl; 621 cout << endl; 622 cout << "before: " << Form("%.1f", hres1.GetMean()*60*60/23.4) << " \xb1 " << Form("%.1f", hres1.GetRMS()*60*60/23.4) << " pix" << endl; 623 cout << "after: " << Form("%.1f", hres2.GetMean()*60*60/23.4) << " \xb1 " << Form("%.1f", hres2.GetRMS()*60*60/23.4) << " pix" << endl; 624 cout << "after: " << Form("%.1f", hres2.GetMean()*16384/360) << " \xb1 " << Form("%.1f", hres2.GetRMS()*16384/360) << " SE" << endl; 625 cout << endl; 626 cout << "backw: " << Form("%.1f", hres3.GetMean()*60) << " \xb1 " << Form("%.1f", hres3.GetRMS()*60) << " arcmin" << endl; 585 627 cout << endl; // ± 586 628 587 629 630 before = hres1.GetMean()*16384/360; 631 after = hres2.GetMean()*16384/360; 632 backw = hres3.GetMean()*16384/360; 633 588 634 589 635 gStyle->SetOptStat(1110); … … 615 661 cout << "Gaus-Fit Sigma: " << f.GetParameter(2) << "\xb0" << endl; 616 662 cout << "Fit-Probability: " << f.GetProb()*100 << "%" << endl; 617 cout << " Chi^2/NDF: " << f.GetChisquare() /f.GetNDF() << endl;663 cout << " Chi^2/NDF: " << f.GetChisquare() << "/" << f.GetNDF() << " = " << f.GetChisquare()/f.GetNDF() << endl; 618 664 619 665 c1->cd(1); … … 626 672 gPad->Modified(); 627 673 gPad->Update(); 628 for (int i=0; i<f Coordinates.GetSize(); i++)629 DrawSet(gPad, *(Set*) list.At(i));//, 10./hres1.GetMean());674 for (int i=0; i<fOriginal.GetSize(); i++) 675 DrawSet(gPad, *(Set*)fOriginal.At(i));//, 10./hres1.GetMean()); 630 676 631 677 c1->cd(3); … … 638 684 gPad->Update(); 639 685 for (int i=0; i<fCoordinates.GetSize(); i++) 640 DrawSet(gPad, *(Set*)fCoordinates.At(i), 10./hres2.GetMean() );686 DrawSet(gPad, *(Set*)fCoordinates.At(i), 10./hres2.GetMean(), par[0]); 641 687 642 688 RaiseWindow(); … … 663 709 664 710 fin >> set; // Read data from file [deg], it is stored in [rad] 665 666 711 if (!fin) 667 712 break; … … 687 732 { 688 733 case kTbFit: 689 Fit(); 690 DisplayBending(); 734 { 735 Double_t before=0; 736 Double_t after=0; 737 Double_t backw=0; 738 Fit(before, after, backw); 739 DisplayBending(); 740 DisplayResult(before, after, backw); 741 } 691 742 return kTRUE; 692 743 case kTbLoad: 693 fBending.Load("bending_ magic.txt");744 fBending.Load("bending_new.txt"); 694 745 DisplayBending(); 695 746 return kTRUE; 696 747 case kTbSave: 697 fBending.Save("bending_ magic.txt");748 fBending.Save("bending_new.txt"); 698 749 return kTRUE; 699 750 case kTbLoadStars: … … 767 818 } 768 819 820 void DisplayResult(Double_t before, Double_t after, Double_t backw) 821 { 822 TGLabel *l1 = (TGLabel*)fLabel.At(3*MBending::GetNumPar()+1); 823 l1->SetText(Form("Before: %.1f +- %.1f SE", before)); 824 825 TGLabel *l2 = (TGLabel*)fLabel.At(3*MBending::GetNumPar()+2); 826 l2->SetText(Form("After: %.1f +- %.1f SE", after)); 827 828 TGLabel *l3 = (TGLabel*)fLabel.At(3*MBending::GetNumPar()+3); 829 l3->SetText(Form("Backw: %.1f +- %.1f SE", backw)); 830 } 831 769 832 public: 770 833 ~MFit() … … 866 929 fLabel.Add(l); 867 930 931 l = new TGLabel(grp1, ""); 932 l->SetTextJustify(kTextLeft); 933 grp1->AddFrame(l, hints5); 934 fList->Add(l); 935 fLabel.Add(l); 936 937 l = new TGLabel(grp1, ""); 938 l->SetTextJustify(kTextLeft); 939 grp1->AddFrame(l, hints5); 940 fList->Add(l); 941 fLabel.Add(l); 942 943 l = new TGLabel(grp1, ""); 944 l->SetTextJustify(kTextLeft); 945 grp1->AddFrame(l, hints5); 946 fList->Add(l); 947 fLabel.Add(l); 948 868 949 869 950 ((TGCheckButton*)fList->FindWidget(0))->SetState(kButtonDown); … … 893 974 void gui() 894 975 { 976 gErrorIgnoreLevel = kError; 895 977 new MFit; 896 978 }
Note:
See TracChangeset
for help on using the changeset viewer.