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