source: trunk/Cosy/tpoint/gui.C@ 16323

Last change on this file since 16323 was 8807, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 42.9 KB
Line 
1#include <fstream>
2#include <iostream>
3#include <iomanip>
4
5#include <TError.h>
6
7#include <TGFrame.h>
8#include <TGLabel.h>
9#include <TGButton.h>
10#include <TGFileDialog.h>
11
12#include <TF1.h>
13#include <TH1.h>
14#include <TH2.h>
15#include <TText.h>
16#include <TProfile.h>
17#include <TPolyLine.h>
18#include <TGraphErrors.h>
19
20#include <TList.h>
21#include <TStyle.h>
22#include <TMinuit.h>
23
24#include <TView.h>
25#include <TLine.h>
26#include <TMarker.h>
27#include <TCanvas.h>
28
29//#include "coord.h"
30
31#include "MAstro.h"
32#include "MGList.h"
33#include "MPointing.h"
34
35using namespace std;
36
37//#define PRESENTATION
38
39class Set : public TObject
40{
41 friend istream &operator>>(istream &fin, Set &set);
42 friend ostream &operator<<(ostream &fout, Set &set);
43private:
44 Double_t fStarAz;
45 Double_t fStarEl;
46
47 Double_t fRawAz;
48 Double_t fRawEl;
49
50 Double_t fMag;
51public:
52 Set(Double_t sel=0, Double_t saz=0, Double_t rel=0, Double_t raz=0) :
53 fStarAz(saz*TMath::DegToRad()),
54 fStarEl(sel*TMath::DegToRad()),
55 fRawAz(raz*TMath::DegToRad()),
56 fRawEl(rel*TMath::DegToRad()), fMag(-25)
57 {
58 }
59
60 Double_t GetMag() const { return fMag; }
61 Double_t GetResidual(Double_t *err=0) const
62 {
63 const Double_t del = fRawEl-fStarEl;
64 const Double_t daz = fRawAz-fStarAz;
65
66 const Double_t d = cos(del) - cos(fRawEl)*cos(fStarEl)*(1.-cos(daz));
67
68 if (err)
69 {
70 // Error of one pixel in the CCD
71 const Double_t e1 = 32./3600*TMath::DegToRad() * 0.5;
72
73 // Error of one SE unit
74 const Double_t e2 = 360./16384*TMath::DegToRad() * 0.5;
75
76 const Double_t e11 = sin(del)+cos(fRawEl)*sin(fStarEl)*(1-cos(daz));
77 const Double_t e12 = cos(fRawEl)*cos(fStarEl)*sin(daz);
78
79 const Double_t e21 = -sin(del)+sin(fRawEl)*cos(fStarEl)*(1-cos(daz));
80 const Double_t e22 = -cos(fRawEl)*cos(fStarEl)*sin(daz);
81
82 const Double_t err1 = sqrt(1-d*d);
83 const Double_t err2 = (e11*e11 + e12*e12)*e1*e1;
84 const Double_t err3 = (e21*e21 + e22*e22)*e2*e2;
85
86 *err = sqrt(err2+err3)/err1 * TMath::RadToDeg();
87 }
88
89 //const Double_t dist = acos(d);
90 //return dist * TMath::RadToDeg();
91
92 return MAstro::GetDevAbs(90-fStarEl*TMath::RadToDeg(),
93 del*TMath::RadToDeg(),
94 -daz*TMath::RadToDeg());
95 }
96
97 void operator=(Set &set)
98 {
99 fStarAz = set.fStarAz;
100 fStarEl = set.fStarEl;
101 fRawAz = set.fRawAz;
102 fRawEl = set.fRawEl;
103 fMag = set.fMag;
104 }
105
106 Double_t GetDEl() const { return (fRawEl-fStarEl)*TMath::RadToDeg(); }
107 Double_t GetDZd() const { return -GetDEl(); }
108 Double_t GetDAz() const { return (fRawAz-fStarAz)*TMath::RadToDeg(); }
109 Double_t GetStarEl() const { return fStarEl*TMath::RadToDeg(); }
110 Double_t GetStarZd() const { return 90.-fStarEl*TMath::RadToDeg(); }
111 Double_t GetStarAz() const { return fStarAz*TMath::RadToDeg(); }
112 Double_t GetRawEl() const { return fRawEl*TMath::RadToDeg(); }
113 Double_t GetRawAz() const { return fRawAz*TMath::RadToDeg(); }
114 Double_t GetRawZd() const { return 90.-fRawEl*TMath::RadToDeg(); }
115
116 ZdAz GetStarZdAz() const { return ZdAz(TMath::Pi()/2-fStarEl, fStarAz); }
117 AltAz GetStarAltAz() const { return AltAz(fStarEl, fStarAz); }
118
119 ZdAz GetRawZdAz() const { return ZdAz(TMath::Pi()/2-fRawEl, fRawAz); }
120 AltAz GetRawAltAz() const { return AltAz(fRawEl, fRawAz); }
121
122 void AdjustEl(Double_t del) { fStarEl += del*TMath::DegToRad(); }
123 void AdjustAz(Double_t daz) { fStarAz += daz*TMath::DegToRad(); }
124
125 void Adjust(const MPointing &bend)
126 {
127 AltAz p = bend(GetStarAltAz());
128 fStarEl = p.Alt();
129 fStarAz = p.Az();
130 }
131 void AdjustBack(const MPointing &bend)
132 {
133 AltAz p = bend.CorrectBack(GetRawAltAz());
134 fRawEl = p.Alt();
135 fRawAz = p.Az();
136 }
137 ClassDef(Set, 0)
138};
139
140ClassImp(Set);
141
142istream &operator>>(istream &fin, Set &set)
143{
144 TString str;
145 do
146 {
147 str.ReadLine(fin);
148 if (!fin)
149 return fin;
150 } while (str[0]=='#');
151
152 Float_t v[4], mag;
153 Int_t n = sscanf(str.Data(), "%f %f %f %f %*f %*f %*f %*f %*f %*f %f", v, v+1, v+2, v+3, &mag);
154 if (n<4)
155 {
156 cout << "Read: ERROR - Not enough numbers" << endl;
157 return fin;
158 }
159 set.fMag = n<5 ? -25 : mag;
160
161 set.fStarAz = v[0]*TMath::DegToRad();
162 set.fStarEl = v[1]*TMath::DegToRad();
163
164 set.fRawAz = v[2]*TMath::DegToRad();
165 set.fRawEl = v[3]*TMath::DegToRad();
166
167 if (fin)
168 {
169 Double_t res, err;
170 res = set.GetResidual(&err);
171 cout << "Read: " << v[0] << " " << v[1] << " : " << v[2] << " " << v[3] << " : " << v[2]-v[0] << " " << v[3]-v[1] << " : " << res << " " << err << " " << err/res << endl;
172 }
173
174 return fin;
175}
176
177ostream &operator<<(ostream &out, Set &set)
178{
179 out << Form("%8.3f", set.fStarAz*TMath::RadToDeg()) << " ";
180 out << Form("%8.3f", set.fStarEl*TMath::RadToDeg()) << " ";
181 out << Form("%8.3f", set.fRawAz*TMath::RadToDeg()) << " ";
182 out << Form("%8.1f", set.fRawEl*TMath::RadToDeg()) << " ";
183 out << set.fMag;
184
185 return out;
186}
187
188class MFit : public TGMainFrame
189{
190private:
191 enum {
192 kTbFit = 19, //MPointing::GetNumPar(), // FIXME!!!
193 kTbLoad,
194 kTbSave,
195 kTbLoadStars,
196 kTbReset,
197 kTbResetStars,
198 kTbReloadStars
199 };
200
201 MGList *fList;
202
203 TList fOriginal;
204 TList fCoordinates;
205 TList fLabel;
206
207 MPointing fBending;
208
209 TString fFileNameStars;
210
211 FontStruct_t fFont;
212
213 void Fcn(Int_t &/*npar*/, Double_t */*gin*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
214 {
215 f = 0;
216
217 MPointing bend;
218 bend.SetParameters(par); // Set Parameters [deg] to MPointing
219
220 for (int i=0; i<fCoordinates.GetSize(); i++)
221 {
222 Set set = *(Set*)fCoordinates.At(i);
223
224 set.Adjust(bend);
225
226 Double_t err = 0.01; // [deg] = 0.25SE
227 Double_t res = set.GetResidual(); //(&err);
228 res /= err;
229
230 f += res*res;
231 }
232
233 f /= fCoordinates.GetSize();
234 }
235
236 static void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
237 {
238 ((MFit*)gMinuit->GetObjectFit())->Fcn(npar, gin, f, par, iflag);
239 }
240
241 void DrawMarker(TVirtualPad *pad, Double_t r0, Double_t phi0)
242 {
243 TView *view = pad->GetView();
244
245 if (!view)
246 {
247 cout << "No View!" << endl;
248 return;
249 }
250
251 TMarker mark0;
252 mark0.SetMarkerStyle(kFullDotLarge);
253 mark0.SetMarkerColor(kBlue);
254
255 r0 /= 90;
256 phi0 *= TMath::DegToRad();
257
258 Double_t x[6] = { r0*cos(phi0), r0*sin(phi0), 0, 0, 0, 0};
259
260 view->WCtoNDC(x, x+3);
261
262 mark0.DrawMarker(-x[3], x[4]);
263 }
264
265 void DrawPolLine(TVirtualPad *pad, Double_t r0, Double_t phi0, Double_t r1, Double_t phi1)
266 {
267 TView *view = pad->GetView();
268
269 if (!view)
270 {
271 cout << "No View!" << endl;
272 return;
273 }
274 /*
275 if (r0<0)
276 {
277 r0 = -r0;
278 phi0 += 180;
279 }
280 if (r1<0)
281 {
282 r1 = -r1;
283 phi1 += 180;
284 }
285
286 phi0 = fmod(phi0+360, 360);
287 phi1 = fmod(phi1+360, 360);
288
289 if (phi1-phi0<-180)
290 phi1+=360;
291 */
292 TLine line;
293 line.SetLineWidth(2);
294 line.SetLineColor(kBlue);
295
296 Double_t p0 = phi0<phi1?phi0:phi1;
297 Double_t p1 = phi0<phi1?phi1:phi0;
298
299 if (phi0>phi1)
300 {
301 Double_t d = r1;
302 r1 = r0;
303 r0 = d;
304 }
305
306 r0 /= 90;
307 r1 /= 90;
308
309 Double_t dr = r1-r0;
310 Double_t dp = p1-p0;
311
312 Double_t x0[3] = { r0*cos(p0*TMath::DegToRad()), r0*sin(p0*TMath::DegToRad()), 0};
313
314 for (double i=p0+10; i<p1+10; i+=10)
315 {
316 if (i>p1)
317 i=p1;
318
319 Double_t r = dr/dp*(i-p0)+r0;
320 Double_t p = TMath::DegToRad()*i;
321
322 Double_t x1[3] = { r*cos(p), r*sin(p), 0};
323
324 Double_t y0[3], y1[3];
325
326 view->WCtoNDC(x0, y0);
327 view->WCtoNDC(x1, y1);
328
329 line.DrawLine(y0[0], y0[1], y1[0], y1[1]);
330
331 x0[0] = x1[0];
332 x0[1] = x1[1];
333 }
334 }
335
336 void DrawSet(TVirtualPad *pad, Set &set, Float_t scale=-1, Float_t angle=0)
337 {
338 Double_t r0 = set.GetRawZd();
339 Double_t phi0 = set.GetRawAz()-angle;
340 Double_t r1 = set.GetStarZd();
341 Double_t phi1 = set.GetStarAz()-angle;
342
343 if (r0<0)
344 {
345 r0 = -r0;
346 phi0 += 180;
347 }
348 if (r1<0)
349 {
350 r1 = -r1;
351 phi1 += 180;
352 }
353
354 phi0 = fmod(phi0+360, 360);
355 phi1 = fmod(phi1+360, 360);
356
357 if (phi1-phi0<-180)
358 phi1+=360;
359
360 if (scale<0 || scale>1000)
361 scale = -1;
362
363 if (scale>0)
364 {
365 Double_t d = r1-r0;
366 r0 += scale*d;
367 r1 -= scale*d;
368 d = phi1-phi0;
369 phi0 += scale*d;
370 phi1 -= scale*d;
371
372 DrawPolLine(pad, r0, phi0, r1, phi1);
373 DrawMarker(pad, r0, phi0);
374 }
375 else
376 DrawMarker(pad, r1, phi1);
377 }
378
379 void DrawHorizon(TVirtualPad *pad, const char *fname="horizon.dat") const
380 {
381 TView *view = pad->GetView();
382
383 if (!view)
384 {
385 cout << "No View!" << endl;
386 return;
387 }
388
389 ifstream fin(fname);
390 if (!fin)
391 {
392 cout << "ERROR - " << fname << " not found." << endl;
393 return;
394 }
395
396 TPolyLine poly;
397 poly.SetLineWidth(2);
398 poly.SetLineColor(12);
399 poly.SetLineStyle(8);
400
401 while (1)
402 {
403 TString line;
404 line.ReadLine(fin);
405 if (!fin)
406 break;
407
408 Float_t az, alt;
409 sscanf(line.Data(), "%f %f", &az, &alt);
410
411 Float_t zd = 90-alt;
412
413 az *= TMath::DegToRad();
414 zd /= 90;
415
416 Double_t x[6] = { zd*cos(az), zd*sin(az), 0, 0, 0, 0};
417 view->WCtoNDC(x, x+3);
418 poly.SetNextPoint(-x[3], x[4]);
419 }
420
421 poly.DrawClone()->SetBit(kCanDelete);
422
423 }
424
425 void Fit(Double_t &before, Double_t &after, Double_t &backw)
426 {
427 if (fOriginal.GetSize()==0)
428 {
429 cout << "Sorry, no input data loaded..." << endl;
430 return;
431 }
432
433 fCoordinates.Delete();
434 for (int i=0; i<fOriginal.GetSize(); i++)
435 fCoordinates.Add(new Set(*(Set*)fOriginal.At(i)));
436
437 cout << "-----------------------------------------------------------------------" << endl;
438
439 gStyle->SetOptStat("emro");
440
441 TH1F hres1("Res1", " Residuals before correction ", fOriginal.GetSize()/3, 0, 0.3);
442 TH1F hres2("Res2", " Residuals after correction ", fOriginal.GetSize()/3, 0, 0.3);
443 TH1F hres3("Res3", " Residuals after backward correction ", fOriginal.GetSize()/3, 0, 0.3);
444
445 TProfile proaz ("ProAz", " \\Delta profile vs. Az", 48, -180, 180);
446 TProfile prozd ("ProZd", " \\Delta profile vs. Zd", 60, 0, 90);
447 TProfile promag("ProMag", " \\Delta profile vs. Mag", 40, 1, 4);
448
449 hres1.SetXTitle("\\Delta [\\circ]");
450 hres1.SetYTitle("Counts");
451
452 hres2.SetXTitle("\\Delta [\\circ]");
453 hres2.SetYTitle("Counts");
454
455 hres3.SetXTitle("\\Delta [\\circ]");
456 hres3.SetYTitle("Counts");
457
458 TGraph gdaz;
459 TGraph gdzd;
460 TGraph gaz;
461 TGraph gzd;
462 TGraphErrors graz;
463 TGraphErrors grzd;
464 TGraphErrors grmag;
465 TGraph gmaz;
466 TGraph gmzd;
467
468 gdaz.SetTitle(" \\Delta Az vs. Zd ");
469 gdzd.SetTitle(" \\Delta Zd vs. Az ");
470
471 gaz.SetTitle(" \\Delta Az vs. Az ");
472 gzd.SetTitle(" \\Delta Zd vs. Zd ");
473
474 gmaz.SetTitle(" \\Delta Az vs. Mag ");
475 gmzd.SetTitle(" \\Delta Zd vs. Mag ");
476
477 graz.SetTitle(" \\Delta vs. Az ");
478 grzd.SetTitle(" \\Delta vs. Zd ");
479 grmag.SetTitle(" \\Delta vs. Mag ");
480
481 gaz.SetMarkerStyle(kFullDotMedium);;
482 gzd.SetMarkerStyle(kFullDotMedium);
483 gdaz.SetMarkerStyle(kFullDotMedium);;
484 gdzd.SetMarkerStyle(kFullDotMedium);
485 gmaz.SetMarkerStyle(kFullDotMedium);;
486 gmzd.SetMarkerStyle(kFullDotMedium);
487
488 TMinuit minuit(MPointing::GetNumPar()); //initialize TMinuit with a maximum of 5 params
489 minuit.SetObjectFit(this);
490 minuit.SetPrintLevel(-1);
491 minuit.SetFCN(fcn);
492
493 fBending.SetMinuitParameters(minuit, MPointing::GetNumPar()); // Init Parameters [deg]
494
495 for (int i=0; i<MPointing::GetNumPar(); i++)
496 {
497 TGButton *l = (TGButton*)fList->FindWidget(i);
498 minuit.FixParameter(i);
499 if (l->GetState()==kButtonDown)
500 minuit.Release(i);
501 }
502
503 //minuit.Command("SHOW PARAMETERS");
504 //minuit.Command("SHOW LIMITS");
505
506 cout << endl;
507 cout << "Starting fit..." << endl;
508 cout << "For the fit an measurement error in the residual of ";
509 cout << "0.02deg (=1SE) is assumed." << endl;
510 cout << endl;
511
512 Int_t ierflg = 0;
513 ierflg = minuit.Migrad();
514 cout << "Migrad returns " << ierflg << endl;
515 // minuit.Release(2);
516 ierflg = minuit.Migrad();
517 cout << "Migrad returns " << ierflg << endl << endl;
518
519 //
520 // Get Fit Results
521 //
522 fBending.GetMinuitParameters(minuit);
523 fBending.PrintMinuitParameters(minuit);
524 cout << endl;
525 //fBending.Save("bending_magic.txt");
526
527
528 //
529 // Make a copy of all list entries
530 //
531 TList list;
532 list.SetOwner();
533 for (int i=0; i<fCoordinates.GetSize(); i++)
534 list.Add(new Set(*(Set*)fCoordinates.At(i)));
535
536 //
537 // Correct for Offsets only
538 //
539 TArrayD par;
540 fBending.GetParameters(par);
541 for (int i=2; i<MPointing::GetNumPar(); i++)
542 par[i]=0;
543
544 MPointing b2;
545 b2.SetParameters(par);
546
547 const Double_t minres = 0.05; //0.13;
548 const Double_t maxres = 0.13; //0.13;
549
550 cout << "Sets with Residual exceeding " << maxres << "deg:" << endl;
551
552 ofstream fout("residuals.txt");
553
554 //
555 // Calculate correction and residuals
556 //
557 for (int i=0; i<fCoordinates.GetSize(); i++)
558 {
559 Set orig = *(Set*)fCoordinates.At(i);
560
561 Set &set0 = *(Set*)fCoordinates.At(i);
562
563 ZdAz za(set0.GetStarZdAz());
564 za *=kRad2Deg;
565
566 //
567 // Correct for offsets only
568 //
569 Set set1(set0);
570 set1.Adjust(b2);
571
572 hres1.Fill(set1.GetResidual());
573
574 set0.Adjust(fBending);
575 hres2.Fill(set0.GetResidual());
576
577 Double_t dz = fmod(set0.GetDAz()+720, 360);
578 if (dz>180)
579 dz -= 360;
580
581 Double_t err;
582 Double_t resi = set0.GetResidual(&err);
583
584 gdzd.SetPoint(i, za.Az(), set0.GetDZd());
585 gdaz.SetPoint(i, za.Zd(), dz);
586 graz.SetPoint(i, za.Az(), resi);
587 graz.SetPointError(i, 0, err);
588 grzd.SetPoint(i, za.Zd(), resi);
589 grzd.SetPointError(i, 0, err);
590
591 if (resi>maxres)//orig.GetStarAz()>0 && orig.GetStarAz()<50 && set0.GetDZd()<-0.032 && orig.GetStarEl()<80) // 0.13
592 cout << " " << orig << " <" << resi << ">" << endl;
593 if (resi>minres)
594 {
595 fout << Form("%6.3f", resi) << ": " << (resi>maxres?"*":" ");
596 fout << " " << orig << endl;
597 }
598
599 if (fabs(set0.GetDZd())>0.05)
600 {
601 fout << "-> " <<Form("%6.3f", resi) << ": " << (resi>maxres?"*":" ");
602 fout << " " << orig << endl;
603 }
604
605 proaz.Fill(za.Az(), set0.GetResidual(&err));
606 prozd.Fill(za.Zd(), set0.GetResidual(&err));
607 promag.Fill(set0.GetMag(), set0.GetResidual(&err));
608
609 gaz.SetPoint( i, za.Az(), dz);
610 gzd.SetPoint( i, za.Zd(), set0.GetDZd());
611 if (set0.GetMag()>=-20)
612 {
613 grmag.SetPoint(i, set0.GetMag(), set0.GetResidual(&err));
614 grmag.SetPointError(i, 0, err);
615 gmaz.SetPoint( i, set0.GetMag(), dz);
616 gmzd.SetPoint( i, set0.GetMag(), set0.GetDZd());
617 }
618 }
619
620 cout << "Residuals (>0.13deg) written to residuals.txt." << endl;
621
622 //
623 // Check for overflows
624 //
625 const Stat_t ov = hres2.GetBinContent(hres2.GetNbinsX()+1);
626 if (ov>0)
627 cout << "WARNING: " << ov << " overflows (>" << maxres << ") in residuals." << endl;
628
629
630
631 cout << dec << endl;
632 cout << " Number of calls to FCN: " << minuit.fNfcn << endl;
633 cout << "Minimum value found for FCN (Chi^2?): " << minuit.fAmin << endl;
634 cout << " Fit-Probability(?): " << TMath::Prob(minuit.fAmin/*fOriginal.GetSize()*/, fOriginal.GetSize()-minuit.GetNumFreePars())*100 << "%" << endl;
635 cout << " Chi^2/NDF: " << minuit.fAmin/(fOriginal.GetSize()-minuit.GetNumFreePars()) << endl;
636 //cout << "Prob(?): " << TMath::Prob(fChisquare,ndf);
637
638
639
640 //
641 // Print all data sets for which the backward correction is
642 // twice times worse than the residual gotten from the
643 // bending correction itself
644 //
645 cout << endl;
646 cout << "Checking backward correction (raw-->star):" << endl;
647 for (int i=0; i<fCoordinates.GetSize(); i++)
648 {
649 Set set0(*(Set*)list.At(i));
650 Set &set1 = *(Set*)list.At(i);
651
652 set0.AdjustBack(fBending);
653 set1.Adjust(fBending);
654
655 const Double_t res0 = set0.GetResidual();
656 const Double_t res1 = set1.GetResidual();
657 const Double_t diff = TMath::Abs(res0-res1);
658
659 hres3.Fill(res0);
660
661 if (diff<hres2.GetMean()*0.66)
662 continue;
663
664 cout << "DBack: " << setw(6) << set0.GetStarZd() << " " << setw(7) << set0.GetStarAz() << ": ";
665 cout << "ResB="<< setw(7) << res0*60 << " ResF=" << setw(7) << res1*60 << " |ResB-ResF|=" << setw(7) << diff*60 << " arcmin" << endl;
666 }
667 cout << "OK." << endl;
668 cout << endl;
669
670 const Double_t max1 = TMath::Max(gaz.GetHistogram()->GetMaximum(), gdaz.GetHistogram()->GetMaximum());
671 const Double_t max2 = TMath::Max(gzd.GetHistogram()->GetMaximum(), gdzd.GetHistogram()->GetMaximum());
672 const Double_t max3 = TMath::Max(grzd.GetHistogram()->GetMaximum(), graz.GetHistogram()->GetMaximum());
673
674 const Double_t min1 = TMath::Min(gaz.GetHistogram()->GetMinimum(), gdaz.GetHistogram()->GetMinimum());
675 const Double_t min2 = TMath::Min(gzd.GetHistogram()->GetMinimum(), gdzd.GetHistogram()->GetMinimum());
676 const Double_t min3 = TMath::Min(grzd.GetHistogram()->GetMinimum(), graz.GetHistogram()->GetMinimum());
677
678 const Double_t absmax1 = TMath::Max(max1, TMath::Abs(min1));
679 const Double_t absmax2 = TMath::Max(max2, TMath::Abs(min2));
680 const Double_t absmax3 = TMath::Max(max3, TMath::Abs(min3));
681
682 gaz.SetMaximum(absmax1);
683 gzd.SetMaximum(absmax2);
684 gdaz.SetMaximum(absmax1);
685 gdzd.SetMaximum(absmax2);
686 gmaz.SetMaximum(absmax1);
687 gmzd.SetMaximum(absmax2);
688 graz.SetMaximum(absmax3);
689 grzd.SetMaximum(absmax3);
690 grmag.SetMaximum(absmax3);
691 gaz.SetMinimum(-absmax1);
692 gzd.SetMinimum(-absmax2);
693 gdaz.SetMinimum(-absmax1);
694 gdzd.SetMinimum(-absmax2);
695 gmaz.SetMinimum(-absmax1);
696 gmzd.SetMinimum(-absmax2);
697 graz.SetMinimum(0);
698 grzd.SetMinimum(0);
699 grmag.SetMinimum(0);
700
701 TCanvas *c1;
702
703 if (gROOT->FindObject("CanvGraphs"))
704 c1 = dynamic_cast<TCanvas*>(gROOT->FindObject("CanvGraphs"));
705 else
706 c1=new TCanvas("CanvGraphs", "Graphs");
707
708 gROOT->SetSelectedPad(0);
709 c1->SetSelectedPad(0);
710 c1->SetBorderMode(0);
711 c1->SetFrameBorderMode(0);
712 c1->Clear();
713
714 c1->SetFillColor(kWhite);
715#ifndef PRESENTATION
716 c1->Divide(3,3,1e-10,1e-10);
717#else
718 c1->Divide(2,2,1e-10,1e-10);
719#endif
720 c1->SetFillColor(kWhite);
721
722 TGraph *g=0;
723
724 TLine line;
725 line.SetLineColor(kGreen);
726 line.SetLineWidth(2);
727#ifndef PRESENTATION
728 c1->cd(1);
729 gPad->SetBorderMode(0);
730 gPad->SetFrameBorderMode(0);
731 gPad->SetGridx();
732 gPad->SetGridy();
733 g=(TGraph*)gaz.DrawClone("AP");
734 g->SetBit(kCanDelete);
735 g->GetHistogram()->SetXTitle("Az [\\circ]");
736 g->GetHistogram()->SetYTitle("\\Delta Az [\\circ]");
737
738 line.DrawLine(g->GetXaxis()->GetXmin(), 360./16384, g->GetXaxis()->GetXmax(), 360./16384);
739 line.DrawLine(g->GetXaxis()->GetXmin(), -360./16384, g->GetXaxis()->GetXmax(), -360./16384);
740
741 c1->cd(2);
742 gPad->SetBorderMode(0);
743 gPad->SetFrameBorderMode(0);
744 gPad->SetGridx();
745 gPad->SetGridy();
746 g=(TGraph*)gdaz.DrawClone("AP");
747 g->SetBit(kCanDelete);
748 g->GetHistogram()->SetXTitle("Zd [\\circ]");
749 g->GetHistogram()->SetYTitle("\\Delta Az [\\circ]");
750 line.DrawLine(g->GetXaxis()->GetXmin(), 360./16384, g->GetXaxis()->GetXmax(), 360./16384);
751 line.DrawLine(g->GetXaxis()->GetXmin(), -360./16384, g->GetXaxis()->GetXmax(), -360./16384);
752 cout << "Mean dAz: " << g->GetMean(2) << " \xb1 " << g->GetRMS(2) << endl;
753
754 c1->cd(3);
755 gPad->SetBorderMode(0);
756 gPad->SetFrameBorderMode(0);
757 gPad->SetGridx();
758 gPad->SetGridy();
759 if (gmaz.GetN()>0)
760 {
761 g=(TGraph*)gmaz.DrawClone("AP");
762 g->SetBit(kCanDelete);
763 g->GetHistogram()->SetXTitle("Mag");
764 g->GetHistogram()->SetYTitle("\\Delta Az [\\circ]");
765 line.DrawLine(g->GetXaxis()->GetXmin(), 360./16384, g->GetXaxis()->GetXmax(), 360./16384);
766 line.DrawLine(g->GetXaxis()->GetXmin(), -360./16384, g->GetXaxis()->GetXmax(), -360./16384);
767 }
768#endif
769
770#ifndef PRESENTATION
771 c1->cd(4);
772#else
773 c1->cd(1);
774#endif
775 gPad->SetBorderMode(0);
776 gPad->SetFrameBorderMode(0);
777 gPad->SetGridx();
778 gPad->SetGridy();
779 g=(TGraph*)gdzd.DrawClone("AP");
780 g->SetBit(kCanDelete);
781 g->GetHistogram()->SetXTitle("Az [\\circ]");
782 g->GetHistogram()->SetYTitle("\\Delta Zd [\\circ]");
783 line.DrawLine(g->GetXaxis()->GetXmin(), 360./16384, g->GetXaxis()->GetXmax(), 360./16384);
784 line.DrawLine(g->GetXaxis()->GetXmin(), -360./16384, g->GetXaxis()->GetXmax(), -360./16384);
785 cout << "Mean dZd: " << g->GetMean(2) << " \xb1 " << g->GetRMS(2) << endl;
786 cout << endl;
787
788#ifndef PRESENTATION
789 c1->cd(5);
790#else
791 c1->cd(2);
792#endif
793 gPad->SetBorderMode(0);
794 gPad->SetFrameBorderMode(0);
795 gPad->SetGridx();
796 gPad->SetGridy();
797 g=(TGraph*)gzd.DrawClone("AP");
798 g->SetBit(kCanDelete);
799 g->GetHistogram()->SetXTitle("Zd [\\circ]");
800 g->GetHistogram()->SetYTitle("\\Delta Zd [\\circ]");
801 line.DrawLine(g->GetXaxis()->GetXmin(), 360./16384, g->GetXaxis()->GetXmax(), 360./16384);
802 line.DrawLine(g->GetXaxis()->GetXmin(), -360./16384, g->GetXaxis()->GetXmax(), -360./16384);
803#ifndef PRESENTATION
804 c1->cd(6);
805 gPad->SetBorderMode(0);
806 gPad->SetFrameBorderMode(0);
807 gPad->SetGridx();
808 gPad->SetGridy();
809 if (gmzd.GetN()>0)
810 {
811 g=(TGraph*)gmzd.DrawClone("AP");
812 g->SetBit(kCanDelete);
813 g->GetHistogram()->SetXTitle("Mag");
814 g->GetHistogram()->SetYTitle("\\Delta Zd [\\circ]");
815 line.DrawLine(g->GetXaxis()->GetXmin(), 360./16384, g->GetXaxis()->GetXmax(), 360./16384);
816 line.DrawLine(g->GetXaxis()->GetXmin(), -360./16384, g->GetXaxis()->GetXmax(), -360./16384);
817 }
818#endif
819
820#ifndef PRESENTATION
821 c1->cd(7);
822#else
823 c1->cd(3);
824#endif
825 gPad->SetBorderMode(0);
826 gPad->SetFrameBorderMode(0);
827 gPad->SetGridx();
828 gPad->SetGridy();
829 g=(TGraph*)graz.DrawClone("AP");
830 g->SetBit(kCanDelete);
831 g->GetHistogram()->SetXTitle("Az [\\circ]");
832 g->GetHistogram()->SetYTitle("\\Delta [\\circ]");
833 line.DrawLine(g->GetXaxis()->GetXmin(), 360./16384, g->GetXaxis()->GetXmax(), 360./16384);
834
835 proaz.SetLineWidth(2);
836 proaz.SetLineColor(kBlue);
837 proaz.SetMarkerColor(kBlue);
838 proaz.DrawCopy("pc hist same");
839
840#ifndef PRESENTATION
841 c1->cd(8);
842#else
843 c1->cd(4);
844#endif
845 gPad->SetBorderMode(0);
846 gPad->SetFrameBorderMode(0);
847 gPad->SetGridx();
848 gPad->SetGridy();
849 g=(TGraph*)grzd.DrawClone("AP");
850 g->SetBit(kCanDelete);
851 g->GetHistogram()->SetXTitle("Zd [\\circ]");
852 g->GetHistogram()->SetYTitle("\\Delta [\\circ]");
853 line.DrawLine(g->GetXaxis()->GetXmin(), 360./16384, g->GetXaxis()->GetXmax(), 360./16384);
854
855 prozd.SetLineWidth(2);
856 prozd.SetLineColor(kBlue);
857 prozd.SetMarkerColor(kBlue);
858 prozd.DrawCopy("pc hist same");
859
860#ifndef PRESENTATION
861 c1->cd(9);
862 gPad->SetBorderMode(0);
863 gPad->SetFrameBorderMode(0);
864 gPad->SetGridx();
865 gPad->SetGridy();
866 if (grmag.GetN()>0)
867 {
868 g=(TGraph*)grmag.DrawClone("AP");
869 g->SetBit(kCanDelete);
870 g->GetHistogram()->SetXTitle("Mag");
871 g->GetHistogram()->SetYTitle("\\Delta [\\circ]");
872 line.DrawLine(g->GetXaxis()->GetXmin(), 360./16384, g->GetXaxis()->GetXmax(), 360./16384);
873 }
874 promag.SetLineWidth(2);
875 promag.SetLineColor(kBlue);
876 promag.SetMarkerColor(kBlue);
877 promag.DrawCopy("pc hist same");
878#endif
879
880 //
881 // Print out the residual before and after correction in several
882 // units
883 //
884 cout << fCoordinates.GetSize() << " data sets." << endl << endl;
885 cout << "Total Spread of Residual:" << endl;
886 cout << "-------------------------" << endl;
887 cout << "before: " << Form("%6.4f", hres1.GetMean()) << " \xb1 " << Form("%6.4f", hres1.GetRMS()) << " deg \t";
888 cout << "before: " << Form("%4.1f", hres1.GetMean()*60) << " \xb1 " << Form("%.1f", hres1.GetRMS()*60) << " arcmin" << endl;
889 cout << "after: " << Form("%6.4f", hres2.GetMean()) << " \xb1 " << Form("%6.4f", hres2.GetRMS()) << " deg \t";
890 cout << "after: " << Form("%4.1f", hres2.GetMean()*60) << " \xb1 " << Form("%.1f", hres2.GetRMS()*60) << " arcmin" << endl;
891 cout << "backw: " << Form("%6.4f", hres3.GetMean()) << " \xb1 " << Form("%6.4f", hres3.GetRMS()) << " deg \t";
892 cout << "backw: " << Form("%4.1f", hres3.GetMean()*60) << " \xb1 " << Form("%.1f", hres3.GetRMS()*60) << " arcmin" << endl;
893 cout << endl;
894 cout << "before: " << Form("%4.1f", hres1.GetMean()*16348/360) << " \xb1 " << Form("%.1f", hres1.GetRMS()*16384/360) << " SE \t\t";
895 cout << "before: " << Form("%4.1f", hres1.GetMean()*60*60/23.4) << " \xb1 " << Form("%.1f", hres1.GetRMS()*60*60/23.4) << " pix" << endl;
896 cout << "after: " << Form("%4.1f", hres2.GetMean()*16384/360) << " \xb1 " << Form("%.1f", hres2.GetRMS()*16384/360) << " SE \t\t";
897 cout << "after: " << Form("%4.1f", hres2.GetMean()*60*60/23.4) << " \xb1 " << Form("%.1f", hres2.GetRMS()*60*60/23.4) << " pix" << endl;
898 cout << "backw: " << Form("%4.1f", hres3.GetMean()*16384/360) << " \xb1 " << Form("%.1f", hres3.GetRMS()*16384/360) << " SE \t\t";
899 cout << "backw: " << Form("%4.1f", hres3.GetMean()*60*60/23.4) << " \xb1 " << Form("%.1f", hres3.GetRMS()*60*60/23.4) << " pix" << endl;
900 cout << endl;
901 cout << endl; // ±
902
903
904 before = hres1.GetMean()*16384/360;
905 after = hres2.GetMean()*16384/360;
906 backw = hres3.GetMean()*16384/360;
907
908
909 gStyle->SetOptStat(1110);
910 gStyle->SetStatFormat("6.2g");
911
912 if (gROOT->FindObject("CanvResiduals"))
913 c1 = dynamic_cast<TCanvas*>(gROOT->FindObject("CanvResiduals"));
914 else
915 c1=new TCanvas("CanvResiduals", "Residuals", 800, 800);
916
917 gROOT->SetSelectedPad(0);
918 c1->SetSelectedPad(0);
919 c1->Clear();
920 c1->SetFillColor(kWhite);
921
922 c1->Divide(2, 2, 1e-10, 1e-10);
923
924 c1->cd(2);
925 gPad->SetBorderMode(0);
926 gPad->SetFrameBorderMode(0);
927 hres1.SetLineColor(kRed);
928 hres1.DrawCopy();
929
930 gPad->Update();
931
932 line.DrawLine(360./16384, gPad->GetUymin(), 360./16384, gPad->GetUymax());
933
934 c1->cd(4);
935 gPad->SetBorderMode(0);
936 gPad->SetFrameBorderMode(0);
937 hres2.SetLineColor(kBlue);
938 TH1 *h=hres2.DrawCopy();
939 TF1 f("mygaus", "(gaus)", 0, 1);
940 f.SetLineColor(kMagenta/*6*/);
941 f.SetLineWidth(1);
942 f.SetParameter(0, h->GetBinContent(1));
943 f.FixParameter(1, 0);
944 f.SetParameter(2, h->GetRMS());
945 h->Fit("mygaus", "QR");
946 hres3.SetLineColor(kCyan);
947 hres3.SetLineStyle(kDashed);
948 hres3.DrawCopy("same");
949 cout << "Gaus-Fit Sigma: " << f.GetParameter(2) << "\xb0" << endl;
950 cout << "Fit-Probability: " << f.GetProb()*100 << "%" << endl;
951 cout << " Chi^2/NDF: " << f.GetChisquare() << "/" << f.GetNDF() << " = " << f.GetChisquare()/f.GetNDF() << endl;
952 gPad->Update();
953 line.DrawLine(360./16384, gPad->GetUymin(), 360./16384, gPad->GetUymax());
954
955 c1->cd(1);
956 gPad->SetBorderMode(0);
957 gPad->SetFrameBorderMode(0);
958 gPad->SetTheta(90);
959 gPad->SetPhi(90);
960 TH2F h2res1("Res2D1", " Dataset positions on the sky ", 36, 0, 360, 8, 0, 90);
961 h2res1.SetBit(TH1::kNoStats);
962 h2res1.DrawCopy("surf1pol");
963 gPad->Modified();
964 gPad->Update();
965 DrawHorizon(gPad);
966 for (int i=0; i<fOriginal.GetSize(); i++)
967 DrawSet(gPad, *(Set*)fOriginal.At(i));//, 10./hres1.GetMean());
968
969 TText text;
970 text.SetTextAlign(22);
971 text.DrawText( 0.00, 0.66, "N");
972 text.DrawText( 0.66, 0.00, "E");
973 text.DrawText( 0.00, -0.66, "S");
974 text.DrawText(-0.66, 0.00, "W");
975
976 c1->cd(3);
977 gPad->SetBorderMode(0);
978 gPad->SetFrameBorderMode(0);
979 gPad->SetTheta(90);
980 gPad->SetPhi(90);
981 h2res1.SetTitle(" Arb. Residuals after correction (scaled) ");
982 h2res1.DrawCopy("surf1pol");
983 gPad->Modified();
984 gPad->Update();
985// for (int i=0; i<fCoordinates.GetSize(); i++)
986// DrawSet(gPad, *(Set*)fCoordinates.At(i), 10./hres2.GetMean(), par[0]);
987
988 RaiseWindow();
989 }
990
991 Bool_t LoadCollection(TString fname)
992 {
993 ifstream fin(fname);
994 if (!fin)
995 {
996 cout << "Collection '" << fname << "' not found!" << endl;
997 return kFALSE;
998 }
999
1000 while (1)
1001 {
1002 TString line;
1003 line.ReadLine(fin);
1004 if (!fin)
1005 break;
1006
1007 line = line.Strip(TString::kBoth);
1008 if (line[0]=='#')
1009 continue;
1010 if (line.Length()==0)
1011 continue;
1012
1013 if (!line.EndsWith(".txt"))
1014 {
1015 cout << "WARNING - Wring extension: " << line << endl;
1016 continue;
1017 }
1018
1019 if (!LoadStarFile(line))
1020 return kFALSE;
1021 }
1022 return kTRUE;
1023 }
1024
1025 Bool_t LoadStarFile(TString fname)
1026 {
1027 const Int_t size = fOriginal.GetSize();
1028
1029 ifstream fin(fname);
1030
1031 while (fin && fin.get()!='\n');
1032 while (fin && fin.get()!='\n');
1033 while (fin && fin.get()!='\n');
1034 if (!fin)
1035 {
1036 cout << "File '" << fname << "' not found!" << endl;
1037 return kFALSE;
1038 }
1039
1040 while (1)
1041 {
1042 Set set;
1043
1044 fin >> set; // Read data from file [deg], it is stored in [rad]
1045 if (!fin)
1046 break;
1047
1048 fOriginal.Add(new Set(set));
1049 }
1050
1051 cout << "Found " << fOriginal.GetSize()-size;
1052 cout << " sets of coordinates in " << fname;
1053 cout << " (Total=" << fOriginal.GetSize() << ")" << endl;
1054
1055 return kTRUE;
1056 }
1057
1058 Bool_t LoadStars(TString fname="tpoint.txt")
1059 {
1060 const Bool_t iscol = fname.EndsWith(".col");
1061
1062 const Bool_t rc = iscol ? LoadCollection(fname) : LoadStarFile(fname);
1063 if (!rc)
1064 return kFALSE;
1065
1066 fFileNameStars = fname;
1067 SetWindowName(fname);
1068
1069 return kTRUE;
1070 }
1071
1072 // --------------------------------------------------------------------------
1073 //
1074 // Opens an open dialog
1075 //
1076 TString OpenDialog(EFileDialogMode mode=kFDOpen)
1077 {
1078 static const char *gOpenTypes[] =
1079 {
1080 "TPoint files", "*.txt",
1081 "Collection files", "*.col",
1082 "All files", "*",
1083 NULL, NULL
1084 };
1085
1086 static TString dir("tpoint/");
1087
1088 TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
1089
1090 fi.fFileTypes = (const char**)gOpenTypes;
1091 fi.fIniDir = StrDup(dir);
1092
1093 new TGFileDialog(fClient->GetRoot(), this, mode, &fi);
1094
1095 if (!fi.fFilename)
1096 return 0;
1097
1098 dir = fi.fIniDir;
1099
1100 return fi.fFilename;
1101 }
1102
1103 Bool_t ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
1104 {
1105 // cout << "Msg: " << hex << GET_MSG(msg) << endl;
1106 // cout << "SubMsg: " << hex << GET_SUBMSG(msg) << dec << endl;
1107 switch (GET_MSG(msg))
1108 {
1109 case kC_COMMAND:
1110 switch (GET_SUBMSG(msg))
1111 {
1112 case kCM_BUTTON:
1113 switch (mp1)
1114 {
1115 case kTbFit:
1116 {
1117 Double_t before=0;
1118 Double_t after=0;
1119 Double_t backw=0;
1120 Fit(before, after, backw);
1121 DisplayBending();
1122 DisplayResult(before, after, backw);
1123 }
1124 return kTRUE;
1125 case kTbLoad:
1126 fBending.Load(OpenDialog());
1127 DisplayBending();
1128 return kTRUE;
1129 case kTbSave:
1130 fBending.Save(OpenDialog(kFDSave));
1131 return kTRUE;
1132 case kTbLoadStars:
1133 LoadStars(OpenDialog());
1134 DisplayData();
1135 return kTRUE;
1136 case kTbReset:
1137 fBending.Clear();
1138 DisplayBending();
1139 return kTRUE;
1140 case kTbReloadStars:
1141 fOriginal.Delete();
1142 LoadStars(fFileNameStars); // FIXME: Use TGLabel!
1143 DisplayData();
1144 return kTRUE;
1145 case kTbResetStars:
1146 fOriginal.Delete();
1147 DisplayData();
1148 return kTRUE;
1149 }
1150
1151 // In the default cas a reset button must have been pressed
1152 cout << "DEL! " << mp1-2*MPointing::GetNumPar() <<endl;
1153
1154 fBending[mp1-2*MPointing::GetNumPar()] = 0;
1155 DisplayBending();
1156
1157 return kTRUE;
1158 }
1159 return kTRUE;
1160 }
1161 return kTRUE;
1162 }
1163
1164 TGButton *AddTextButton(TGCompositeFrame *f, TString txt, Int_t id=-1, TGLayoutHints *h=0)
1165 {
1166 TGButton *but = new TGTextButton(f, txt, id);
1167 but->Associate(this);
1168 f->AddFrame(but, h);
1169 fList->Add(but);
1170 return but;
1171
1172 }
1173
1174 TGButton *AddCheckButton(TGCompositeFrame *f, TString txt, Int_t id=-1, TGLayoutHints *h=0)
1175 {
1176 TGButton *but = new TGCheckButton(f, txt, id);
1177 but->Associate(this);
1178 f->AddFrame(but, h);
1179 fList->Add(but);
1180 return but;
1181 }
1182
1183 TGButton *AddResetButton(TGCompositeFrame *f, Int_t id, TGLayoutHints *h, Int_t height)
1184 {
1185 // Move this to a AddResetButton function
1186 TGPictureButton *but = new TGPictureButton(f, "Totenkopf.xpm", id);
1187 but->SetHeight(height); // Offsets from TGLayout
1188 but->SetWidth(height);
1189 but->Associate(this);
1190 f->AddFrame(but, h);
1191 fList->Add(but);
1192 return but;
1193 }
1194
1195 TGLabel *AddLabel(TGCompositeFrame *f, TString txt, TGLayoutHints *h=0)
1196 {
1197 TGLabel *l = new TGLabel(f, txt/*, TGLabel::GetDefaultGC()(), fFont*/);
1198 f->AddFrame(l, h);
1199 fList->Add(l);
1200 fLabel.Add(l);
1201 return l;
1202 }
1203
1204 void DisplayBending()
1205 {
1206 TArrayD par, err;
1207 fBending.GetParameters(par);
1208 fBending.GetError(err);
1209
1210 TGLabel *l;
1211
1212 for (int i=0; i<MPointing::GetNumPar(); i++)
1213 {
1214 l = (TGLabel*)fLabel.At(i);
1215 l->SetText(Form("%.4f\xb0", par[i]));
1216
1217 l = (TGLabel*)fLabel.At(MPointing::GetNumPar()+i);
1218 l->SetText(Form("\xb1 %8.4f\xb0", err[i]));
1219 }
1220 }
1221
1222 void DisplayData()
1223 {
1224 TGLabel *l = (TGLabel*)fLabel.At(3*MPointing::GetNumPar());
1225 l->SetText(Form("%d data sets loaded.", fOriginal.GetSize()));
1226 }
1227
1228 void DisplayResult(Double_t before, Double_t after, Double_t backw)
1229 {
1230 TGLabel *l1 = (TGLabel*)fLabel.At(3*MPointing::GetNumPar()+1);
1231 l1->SetText(Form("Before: %.1f +- %.1f SE", before, 0.));
1232
1233 TGLabel *l2 = (TGLabel*)fLabel.At(3*MPointing::GetNumPar()+2);
1234 l2->SetText(Form("After: %.1f +- %.1f SE", after, 0.));
1235
1236 TGLabel *l3 = (TGLabel*)fLabel.At(3*MPointing::GetNumPar()+3);
1237 l3->SetText(Form("Backw: %.1f +- %.1f SE", backw, 0.));
1238 }
1239
1240public:
1241 ~MFit()
1242 {
1243 if (fFont)
1244 gVirtualX->DeleteFont(fFont);
1245 }
1246 MFit(const char *fname) : TGMainFrame(gClient->GetRoot(), 750, 370, kHorizontalFrame)
1247 {
1248 fCoordinates.SetOwner();
1249 fOriginal.SetOwner();
1250
1251 fList = new MGList;
1252 fList->SetOwner();
1253
1254 fFont = gVirtualX->LoadQueryFont("7x13bold");
1255
1256 TGLayoutHints *hints0 = new TGLayoutHints(kLHintsExpandY, 7, 5, 5, 0);
1257 TGLayoutHints *hints1 = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 5, 7, 5, 6);
1258 TGLayoutHints *hints2 = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY, 5, 5, 5, 5);
1259 fList->Add(hints0);
1260 fList->Add(hints1);
1261 fList->Add(hints2);
1262
1263 TGGroupFrame *grp1 = new TGGroupFrame(this, "Control", kVerticalFrame);
1264 AddFrame(grp1, hints0);
1265 fList->Add(grp1);
1266
1267 TGGroupFrame *grp2 = new TGGroupFrame(this, "Parameters", kHorizontalFrame);
1268 AddFrame(grp2, hints1);
1269 fList->Add(grp2);
1270
1271
1272
1273 TGLayoutHints *hints4 = new TGLayoutHints(kLHintsExpandX, 5, 5, 3);
1274 TGLayoutHints *hints5 = new TGLayoutHints(kLHintsExpandX, 5, 5, 10);
1275 AddTextButton(grp1, "Load Pointing Model", kTbLoad, hints5);
1276 AddTextButton(grp1, "Save Pointing Model", kTbSave, hints4);
1277 AddTextButton(grp1, "Fit Parameters", kTbFit, hints5);
1278 AddTextButton(grp1, "Reset Parameters", kTbReset, hints4);
1279 AddTextButton(grp1, "Load Stars", kTbLoadStars, hints5);
1280 AddTextButton(grp1, "Reset Stars", kTbResetStars, hints4);
1281 AddTextButton(grp1, "Reload Stars", kTbReloadStars, hints4);
1282 fList->Add(hints4);
1283 fList->Add(hints5);
1284
1285
1286 TGHorizontalFrame *comp = new TGHorizontalFrame(grp2, 1, 1);
1287 grp2->AddFrame(comp);
1288 fList->Add(comp);
1289
1290 TGLayoutHints *hints3 = new TGLayoutHints(kLHintsLeft|kLHintsTop, 0, 10, 5, 0); //20, 5, 0);
1291 fList->Add(hints3);
1292
1293 TGVerticalFrame *vframe = new TGVerticalFrame(comp, 1, 1);
1294 for (int i=0; i<MPointing::GetNumPar(); i++)
1295 AddCheckButton(vframe, fBending.GetVarName(i), i);
1296
1297 TGButton *but = (TGButton*)fList->FindWidget(0);
1298
1299
1300
1301 comp->AddFrame(vframe, hints3);
1302 fList->Add(vframe);
1303
1304 vframe = new TGVerticalFrame(comp, 1, 1);
1305 comp->AddFrame(vframe, hints3);
1306 fList->Add(vframe);
1307
1308 hints3 = new TGLayoutHints(kLHintsLeft|kLHintsTop, 0, 7, 5, 0);
1309 fList->Add(hints3);
1310
1311 TGLabel *l = new TGLabel(vframe, "+000.0000");
1312 l->SetTextJustify(kTextRight);
1313 fList->Add(l);
1314 fLabel.Add(l);
1315
1316 TGLayoutHints *h = new TGLayoutHints(kLHintsCenterY, 0, 0, but->GetHeight()-l->GetHeight());
1317 fList->Add(h);
1318
1319 vframe->AddFrame(l,h);
1320
1321 for (int i=1; i<MPointing::GetNumPar(); i++)
1322 AddLabel(vframe, "+000.0000", h)->SetTextJustify(kTextRight);
1323
1324 vframe = new TGVerticalFrame(comp, 1, 1);
1325 comp->AddFrame(vframe, hints3);
1326 fList->Add(vframe);
1327 for (int i=0; i<MPointing::GetNumPar(); i++)
1328 AddLabel(vframe, "\xb1 00.0000\xb0", h)->SetTextJustify(kTextRight);
1329
1330 hints3 = new TGLayoutHints(kLHintsLeft|kLHintsTop, 0, 20, 5, 0);
1331 fList->Add(hints3);
1332
1333 TGLayoutHints *hreset = new TGLayoutHints(kLHintsNormal, 0, 0, 3, 1);
1334 fList->Add(hreset);
1335
1336 TGVerticalFrame *vframe2 = new TGVerticalFrame(comp, 1, 1);
1337 comp->AddFrame(vframe2, hints3);
1338 fList->Add(vframe2);
1339 for (int i=0; i<MPointing::GetNumPar(); i++)
1340 AddResetButton(vframe2, i+2*MPointing::GetNumPar(), hreset,
1341 but->GetHeight()-4);
1342
1343 vframe = new TGVerticalFrame(comp, 1, 1);
1344 comp->AddFrame(vframe, hints3);
1345 fList->Add(vframe);
1346 for (int i=0; i<MPointing::GetNumPar(); i++)
1347 AddLabel(vframe, fBending.GetDescription(i), h);
1348
1349 l = new TGLabel(grp1, "0000000 Data Sets loaded.");
1350 grp1->AddFrame(l, hints5);
1351 fList->Add(l);
1352 fLabel.Add(l);
1353
1354 l = new TGLabel(grp1, "");
1355 l->SetTextJustify(kTextLeft);
1356 grp1->AddFrame(l, hints5);
1357 fList->Add(l);
1358 fLabel.Add(l);
1359
1360 l = new TGLabel(grp1, "");
1361 l->SetTextJustify(kTextLeft);
1362 grp1->AddFrame(l, hints5);
1363 fList->Add(l);
1364 fLabel.Add(l);
1365
1366 l = new TGLabel(grp1, "");
1367 l->SetTextJustify(kTextLeft);
1368 grp1->AddFrame(l, hints5);
1369 fList->Add(l);
1370 fLabel.Add(l);
1371
1372
1373 ((TGCheckButton*)fList->FindWidget(0))->SetState(kButtonDown);
1374 ((TGCheckButton*)fList->FindWidget(1))->SetState(kButtonDown);
1375 ((TGCheckButton*)fList->FindWidget(6))->SetState(kButtonDown);
1376 ((TGCheckButton*)fList->FindWidget(10))->SetState(kButtonDown);
1377 ((TGCheckButton*)fList->FindWidget(12))->SetState(kButtonDown);
1378 ((TGCheckButton*)fList->FindWidget(17))->SetState(kButtonDown);
1379
1380 SetWindowName("TPoint Fitting Window");
1381 SetIconName("TPoint++");
1382
1383 Layout();
1384
1385 MapSubwindows();
1386 MapWindow();
1387
1388 if (fname)
1389 LoadStars(fname);
1390
1391 DisplayBending();
1392 DisplayData();
1393 }
1394 ClassDef(MFit, 0)
1395};
1396
1397ClassImp(MFit);
1398
1399void gui(const char *fname=NULL)
1400{
1401 gErrorIgnoreLevel = kError;
1402 new MFit(fname);
1403 // TF1 f1("f1", "[0]/cos((90-x)*3.1415/180)", 0, 90)
1404}
Note: See TracBrowser for help on using the repository browser.