1 | #include <iostream>
|
---|
2 | #include <iomanip>
|
---|
3 | #include <fstream>
|
---|
4 |
|
---|
5 | #include <TGraph.h>
|
---|
6 | #include <TCanvas.h>
|
---|
7 | #include <TSystem.h>
|
---|
8 |
|
---|
9 | #include "mars/MTime.h"
|
---|
10 | #include "mars/MMath.h"
|
---|
11 | #include "mars/MAstro.h"
|
---|
12 | #include "mars/MDirIter.h"
|
---|
13 | #include "mars/MStatusDisplay.h"
|
---|
14 |
|
---|
15 | using namespace std;
|
---|
16 |
|
---|
17 | int ReadFile(const char *fname, TGraph &g1, TGraph &g2, TGraph &g0)
|
---|
18 | {
|
---|
19 | ifstream fin(fname);
|
---|
20 |
|
---|
21 | cout << "Reading " << setw(23) << gSystem->BaseName(fname) << "..." << flush;
|
---|
22 |
|
---|
23 | MTime t;
|
---|
24 | while (1)
|
---|
25 | {
|
---|
26 | TString str;
|
---|
27 | str.ReadLine(fin);
|
---|
28 | if (!fin)
|
---|
29 | break;
|
---|
30 |
|
---|
31 | if (str.Contains("#"))
|
---|
32 | continue;
|
---|
33 |
|
---|
34 | Float_t alt, az, dalt, daz, mjd;
|
---|
35 | if (sscanf(str.Data(), "%f %f %*f %*f %*f %*f %f %f %f",
|
---|
36 | &az, &alt, &dalt, &daz, &mjd)!=5)
|
---|
37 | continue;
|
---|
38 |
|
---|
39 | if (dalt==0)
|
---|
40 | continue;
|
---|
41 |
|
---|
42 | Double_t res = MAstro::GetDevAbs(90-(alt-dalt), -dalt, -daz)*60;
|
---|
43 |
|
---|
44 | if (res>12)
|
---|
45 | continue;
|
---|
46 |
|
---|
47 | t.SetMjd(mjd);
|
---|
48 |
|
---|
49 | g0.SetPoint(g0.GetN(), t.GetAxisTime(), g0.GetN());
|
---|
50 | g1.SetPoint(g1.GetN(), t.GetAxisTime(), res);
|
---|
51 | g2.SetPoint(g2.GetN(), g2.GetN(), res);
|
---|
52 | }
|
---|
53 |
|
---|
54 | cout << g1.GetN() << endl;
|
---|
55 |
|
---|
56 | return g1.GetN();
|
---|
57 | }
|
---|
58 |
|
---|
59 | void DrawGrid(TH1 &h)
|
---|
60 | {
|
---|
61 | TGraph l;
|
---|
62 | l.SetLineStyle(kDashed);
|
---|
63 | l.SetLineWidth(2);
|
---|
64 | l.SetLineColor(kBlue);
|
---|
65 |
|
---|
66 | Int_t style[] = { kSolid, 9, 7 };
|
---|
67 |
|
---|
68 | Double_t x[2] = { h.GetXaxis()->GetXmin(), h.GetXaxis()->GetXmax() };
|
---|
69 | Double_t y[2];
|
---|
70 |
|
---|
71 | for (int i=0; i<3; i++)
|
---|
72 | {
|
---|
73 | y[0] = y[1] = i+1;
|
---|
74 | l.SetLineStyle(style[i]);
|
---|
75 | l.DrawGraph(2, x, y, "L");
|
---|
76 | }
|
---|
77 |
|
---|
78 | if (x[0]<1e6)
|
---|
79 | return;
|
---|
80 |
|
---|
81 | Double_t X[2];
|
---|
82 | Double_t Y[2] = { h.GetMinimum(), h.GetMaximum() };
|
---|
83 |
|
---|
84 | l.SetLineWidth(1);
|
---|
85 |
|
---|
86 | for (int i=2004; i<2020; i++)
|
---|
87 | {
|
---|
88 | for (int j=0; j<12; j++)
|
---|
89 | {
|
---|
90 | X[0] = X[1] = MTime(i, 1+j, 1).GetAxisTime();
|
---|
91 |
|
---|
92 | if (X[0]<x[0] || X[0]>x[1])
|
---|
93 | continue;
|
---|
94 |
|
---|
95 | l.SetLineStyle(j==0 ? kDashed : kDotted);
|
---|
96 | l.DrawGraph(2, X, Y, "L");
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | void DrawTimes(TH1 &h)
|
---|
102 | {
|
---|
103 | TGraph l;
|
---|
104 | l.SetLineColor(kBlue);
|
---|
105 |
|
---|
106 | Double_t x[2];
|
---|
107 | Double_t y[2] = { h.GetMinimum(), h.GetMaximum() };
|
---|
108 |
|
---|
109 | for (int i=0; dates[i+1]>0; i++)
|
---|
110 | {
|
---|
111 | x[0] = x[1] = dates[i];
|
---|
112 | l.DrawGraph(2, x, y, "L");
|
---|
113 | }
|
---|
114 |
|
---|
115 | DrawGrid(h);
|
---|
116 | }
|
---|
117 |
|
---|
118 | Int_t GetBin(TGraph ×, Int_t i)
|
---|
119 | {
|
---|
120 | return TMath::BinarySearch(times.GetN(), times.GetX(), dates[i]);;
|
---|
121 | }
|
---|
122 |
|
---|
123 | void DrawIndices(TGraph ×, TH1 &h)
|
---|
124 | {
|
---|
125 | TGraph l;
|
---|
126 | l.SetLineStyle(kDashed);
|
---|
127 | l.SetLineColor(kBlue);
|
---|
128 |
|
---|
129 | Double_t x[2];
|
---|
130 | Double_t y[2] = { h.GetMinimum(), h.GetMaximum() };
|
---|
131 |
|
---|
132 | for (int i=0; dates[i+1]>0; i++)
|
---|
133 | {
|
---|
134 | Int_t bin = GetBin(times, i);
|
---|
135 | if (bin<0)
|
---|
136 | continue;
|
---|
137 |
|
---|
138 | x[0] = x[1] = bin+0.5;
|
---|
139 | l.DrawGraph(2, x, y, "L");
|
---|
140 | }
|
---|
141 |
|
---|
142 | DrawGrid(h);
|
---|
143 | }
|
---|
144 |
|
---|
145 | void plot(MDirIter &Next)
|
---|
146 | {
|
---|
147 | Next.Sort();
|
---|
148 |
|
---|
149 | TGraph g1;
|
---|
150 | TGraph g2;
|
---|
151 | TGraph g0;
|
---|
152 |
|
---|
153 | while (1)
|
---|
154 | {
|
---|
155 | TString name=Next();
|
---|
156 | if (name.IsNull())
|
---|
157 | break;
|
---|
158 |
|
---|
159 | ReadFile(name, g1, g2, g0);
|
---|
160 | }
|
---|
161 |
|
---|
162 | MStatusDisplay *d = new MStatusDisplay;
|
---|
163 |
|
---|
164 | gROOT->SetSelectedPad(0);
|
---|
165 | TCanvas &c0 = d->AddTab("TimeLine");
|
---|
166 | c0.SetGrid();
|
---|
167 |
|
---|
168 | g0.SetTitle("TimeLine");
|
---|
169 | g0.GetXaxis()->SetTimeDisplay(1);
|
---|
170 | g0.SetMarkerStyle(kFullDotMedium);
|
---|
171 | g0.SetLineWidth(1);
|
---|
172 | g0.SetLineColor(kGreen);
|
---|
173 | g0.DrawClone("ALP");
|
---|
174 |
|
---|
175 | DrawTimes(*g0.GetHistogram());
|
---|
176 |
|
---|
177 |
|
---|
178 | gROOT->SetSelectedPad(0);
|
---|
179 | TCanvas &c1 = d->AddTab("ResDate");
|
---|
180 | //c1.SetGrid();
|
---|
181 |
|
---|
182 | g1.SetTitle("Measured Residual vs. Date");
|
---|
183 | g1.GetXaxis()->SetTimeDisplay(1);
|
---|
184 | // g1.SetMaximum(10);
|
---|
185 | g1.SetMarkerStyle(kFullDotMedium);
|
---|
186 | g1.DrawClone("AP");
|
---|
187 |
|
---|
188 | DrawTimes(*g1.GetHistogram());
|
---|
189 |
|
---|
190 |
|
---|
191 | gROOT->SetSelectedPad(0);
|
---|
192 | TCanvas &c2 = d->AddTab("ResIdx");
|
---|
193 | c2.SetGrid();
|
---|
194 |
|
---|
195 | g2.SetTitle("Measured Residual vs. Index");
|
---|
196 | // g2.SetMaximum(0.1);
|
---|
197 | g2.SetMarkerStyle(kFullDotMedium);
|
---|
198 | g2.DrawClone("AP");
|
---|
199 |
|
---|
200 | DrawIndices(g0, *g2.GetHistogram());
|
---|
201 |
|
---|
202 | Double_t prob[4] = { 0.5, MMath::GaussProb(1), MMath::GaussProb(2), MMath::GaussProb(3) };
|
---|
203 | Double_t quant[4];
|
---|
204 |
|
---|
205 | int n;
|
---|
206 | for (n=0; dates[n]>0; n++);
|
---|
207 |
|
---|
208 | TH1F h0("Q98", "", n-1, dates);
|
---|
209 | TH1F h1("Q95", "", n-1, dates);
|
---|
210 | TH1F h2("Q68", "", n-1, dates);
|
---|
211 | TH1F h3("Q50", "", n-1, dates);
|
---|
212 |
|
---|
213 | Int_t first = 0;
|
---|
214 |
|
---|
215 | cout << "n=" << n << endl;
|
---|
216 |
|
---|
217 | for (int i=0; dates[i+1]>0; i++)
|
---|
218 | {
|
---|
219 | Int_t bin0 = GetBin(g0, i);
|
---|
220 | Int_t bin1 = GetBin(g0, i+1);
|
---|
221 |
|
---|
222 | cout << i << " " << bin0 << " " << bin1 << endl;
|
---|
223 | if (bin0<0)
|
---|
224 | continue;
|
---|
225 |
|
---|
226 | if (bin0==bin1)
|
---|
227 | continue;
|
---|
228 |
|
---|
229 | TMath::Quantiles(bin1-bin0, 4, g2.GetY()+bin0, quant, prob, kFALSE, NULL, 7);
|
---|
230 |
|
---|
231 | h0.SetBinContent(i+1, quant[0]);
|
---|
232 | h1.SetBinContent(i+1, quant[1]);
|
---|
233 | h2.SetBinContent(i+1, quant[2]);
|
---|
234 | h3.SetBinContent(i+1, quant[3]);
|
---|
235 |
|
---|
236 | if (first==0)
|
---|
237 | first = i;
|
---|
238 | }
|
---|
239 |
|
---|
240 |
|
---|
241 | gROOT->SetSelectedPad(0);
|
---|
242 | TCanvas &c4 = d->AddTab("Quantiles");
|
---|
243 | //c4.SetGrid();
|
---|
244 |
|
---|
245 | h2.SetFillColor(19);
|
---|
246 | h1.SetFillColor(16);
|
---|
247 | h0.SetFillColor(13);
|
---|
248 |
|
---|
249 | h2.SetTitle("Measured Residual-Distribution vs. Date");
|
---|
250 | h2.SetYTitle("Residual [arcmin]");
|
---|
251 | h2.SetStats(kFALSE);
|
---|
252 | h2.GetXaxis()->SetTimeDisplay(1);
|
---|
253 | h2.GetXaxis()->SetTimeFormat("%y/%m");
|
---|
254 | h2.GetYaxis()->CenterTitle();
|
---|
255 | h2.SetMinimum(0);
|
---|
256 | //.SetMaximum(h2.GetMaximum()*1.2);
|
---|
257 | h2.SetMarkerStyle(kFullDotMedium);
|
---|
258 | h2.GetXaxis()->SetRange(first, h3.GetNbinsX());
|
---|
259 | h2.DrawCopy();
|
---|
260 |
|
---|
261 | //.DrawCopy("same");
|
---|
262 | h1.DrawCopy("same");
|
---|
263 | h0.DrawCopy("same");
|
---|
264 |
|
---|
265 | TGraph g;
|
---|
266 | for (int i=0; i<h2.GetNbinsX(); i++)
|
---|
267 | {
|
---|
268 | Double_t x[2] = { h2.GetBinLowEdge(i+1), h2.GetBinLowEdge(i+1) };
|
---|
269 | Double_t y[2] = { 0, h2.GetBinContent(i+1) };
|
---|
270 |
|
---|
271 | g.DrawGraph(2, x, y, "L");
|
---|
272 | }
|
---|
273 |
|
---|
274 | DrawGrid(h2);
|
---|
275 |
|
---|
276 | gROOT->SetSelectedPad(0);
|
---|
277 | TCanvas &c5 = d->AddTab("Combined");
|
---|
278 |
|
---|
279 | h2.DrawCopy();
|
---|
280 | h1.DrawCopy("same");
|
---|
281 | h0.DrawCopy("same");
|
---|
282 |
|
---|
283 | for (int i=0; i<h2.GetNbinsX(); i++)
|
---|
284 | {
|
---|
285 | Double_t x[2] = { h2.GetBinLowEdge(i+1), h2.GetBinLowEdge(i+1) };
|
---|
286 | Double_t y[2] = { 0, h2.GetBinContent(i+1) };
|
---|
287 |
|
---|
288 | g.DrawGraph(2, x, y, "L");
|
---|
289 | }
|
---|
290 |
|
---|
291 | g1.DrawClone("P");
|
---|
292 |
|
---|
293 | DrawGrid(h2);
|
---|
294 |
|
---|
295 |
|
---|
296 | }
|
---|