1 | #include <algorithm>
|
---|
2 | #include <functional>
|
---|
3 |
|
---|
4 | Bool_t Contains(TArrayD **vec, Double_t t0, Double_t range=0)
|
---|
5 | {
|
---|
6 | TArrayD *arr0 = vec[0];
|
---|
7 | TArrayD *arr1 = vec[1];
|
---|
8 | TArrayD *arr2 = vec[2];
|
---|
9 |
|
---|
10 | for (int i=0; i<arr0->GetSize(); i++)
|
---|
11 | {
|
---|
12 | Double_t start = (*arr1)[i];
|
---|
13 | Double_t stop = (*arr2)[i];
|
---|
14 |
|
---|
15 | if (stop>start+305./24/3600)
|
---|
16 | stop = start+305./24/3600;
|
---|
17 |
|
---|
18 | if (t0>start-range && t0<stop+range)
|
---|
19 | //{
|
---|
20 | // if (fmod(t0, 1)>4./24 && fmod(t0,1)<4.1/24)
|
---|
21 | // cout << t0-start << " " <<t0 << " " << stop-t0 << " " << start-15779 << " " << stop-15779 << " " << (*arr0)[i] << endl;
|
---|
22 | return kTRUE;
|
---|
23 | //}
|
---|
24 | }
|
---|
25 |
|
---|
26 | return arr0->GetSize()==0;
|
---|
27 | }
|
---|
28 |
|
---|
29 | Int_t PlotThresholds(TArrayD **vec, TString fname)
|
---|
30 | {
|
---|
31 | fname += ".RATE_CONTROL_THRESHOLD.fits";
|
---|
32 |
|
---|
33 | fits file(fname.Data());
|
---|
34 | if (!file)
|
---|
35 | {
|
---|
36 | cerr << fname << ": " << gSystem->GetError() << endl;
|
---|
37 | return -2;
|
---|
38 | }
|
---|
39 |
|
---|
40 | //cout << fname << endl;
|
---|
41 |
|
---|
42 | Double_t time;
|
---|
43 | UShort_t th;
|
---|
44 |
|
---|
45 | if (!file.SetPtrAddress("Time", &time))
|
---|
46 | return -1;
|
---|
47 |
|
---|
48 | if (!file.SetPtrAddress("threshold", &th))
|
---|
49 | return -1;
|
---|
50 |
|
---|
51 | TGraph g;
|
---|
52 | g.SetName("Threshold");
|
---|
53 |
|
---|
54 | while (file.GetNextRow())
|
---|
55 | {
|
---|
56 | if (Contains(vec, time, 10./(24*3600)))
|
---|
57 | g.SetPoint(g.GetN(), time*24*3600, th);
|
---|
58 | }
|
---|
59 |
|
---|
60 | g.SetMinimum(281);
|
---|
61 | g.SetMarkerStyle(kFullDotMedium);
|
---|
62 | g.GetXaxis()->SetTimeDisplay(true);
|
---|
63 | g.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
|
---|
64 | g.GetXaxis()->SetLabelSize(0.12);
|
---|
65 | g.GetYaxis()->SetLabelSize(0.1);
|
---|
66 | g.GetYaxis()->SetTitle("THRESHOLD");
|
---|
67 | g.GetYaxis()->SetTitleOffset(0.2);
|
---|
68 | g.GetYaxis()->SetTitleSize(0.1);
|
---|
69 | g.DrawClone("AP");
|
---|
70 |
|
---|
71 | return 0;
|
---|
72 | }
|
---|
73 |
|
---|
74 | #include <vector>
|
---|
75 | #include <pair>
|
---|
76 |
|
---|
77 | vector<pair<double, Nova::EquPosn>> vecp;
|
---|
78 |
|
---|
79 | Nova::EquPosn FindPointing(Double_t time)
|
---|
80 | {
|
---|
81 | for (int i=0; i<vecp.size(); i++)
|
---|
82 | if (time<vecp[i].first)
|
---|
83 | {
|
---|
84 | if (i==0)
|
---|
85 | return Nova::EquPosn();
|
---|
86 | else
|
---|
87 | return vecp[i-1].second;
|
---|
88 | }
|
---|
89 |
|
---|
90 | return vecp[vecp.size()-1].second;
|
---|
91 | }
|
---|
92 |
|
---|
93 | Float_t Prediction(Double_t time)
|
---|
94 | {
|
---|
95 | Double_t jd = time + 40587 + 2400000.5;
|
---|
96 |
|
---|
97 | // Sun properties
|
---|
98 | Nova::EquPosn sun = Nova::GetSolarEquCoords(jd);
|
---|
99 | Nova::ZdAzPosn hrzs = Nova::GetHrzFromEqu(sun, jd);
|
---|
100 |
|
---|
101 | // Get source position
|
---|
102 | Nova::EquPosn pos = FindPointing(time);
|
---|
103 |
|
---|
104 | // Moon properties
|
---|
105 | Nova::EquPosn moon = Nova::GetLunarEquCoords(jd, 0.01);
|
---|
106 | Nova::HrzPosn hrzm = Nova::GetHrzFromEqu(moon, jd);
|
---|
107 | double disk = Nova::GetLunarDisk(jd);
|
---|
108 |
|
---|
109 | // Derived moon properties
|
---|
110 | double angle = Nova::GetAngularSeparation(moon, pos);
|
---|
111 | double edist = Nova::GetLunarEarthDist(jd)/384400;
|
---|
112 |
|
---|
113 | // Current prediction
|
---|
114 | double sin_malt = hrzm.alt<0 ? 0 : sin(hrzm.alt*TMath::DegToRad());
|
---|
115 | double cos_mdist = cos(angle*TMath::DegToRad());
|
---|
116 | double sin_szd = sin(hrzs.zd*TMath::DegToRad());
|
---|
117 |
|
---|
118 | double c0 = pow(disk, 2.63);
|
---|
119 | double c1 = pow(sin_malt, 0.60);
|
---|
120 | double c2 = pow(edist, -2.00);
|
---|
121 | double c3 = exp(0.67*cos_mdist*cos_mdist*cos_mdist*cos_mdist);
|
---|
122 | double c4 = exp(-97.8+105.8*sin_szd*sin_szd);
|
---|
123 |
|
---|
124 | double cur = 6.2 + 95.7*c0*c1*c2*c3 + c4;
|
---|
125 |
|
---|
126 | return cur;
|
---|
127 | }
|
---|
128 |
|
---|
129 | Int_t ReadSources(TString fname)
|
---|
130 | {
|
---|
131 | fname += ".DRIVE_CONTROL_SOURCE_POSITION.fits";
|
---|
132 |
|
---|
133 | fits file(fname.Data());
|
---|
134 | if (!file)
|
---|
135 | {
|
---|
136 | cerr << fname << ": " << gSystem->GetError() << endl;
|
---|
137 | return -2;
|
---|
138 | }
|
---|
139 |
|
---|
140 | Double_t time, ra, dec;
|
---|
141 | if (!file.SetPtrAddress("Time", &time))
|
---|
142 | return -1;
|
---|
143 | if (!file.SetPtrAddress("Ra_cmd", &ra))
|
---|
144 | return -1;
|
---|
145 | if (!file.SetPtrAddress("Dec_cmd", &dec))
|
---|
146 | return -1;
|
---|
147 |
|
---|
148 | while (file.GetNextRow())
|
---|
149 | {
|
---|
150 | Nova::EquPosn p;
|
---|
151 | p.ra = ra*15;
|
---|
152 | p.dec = dec;
|
---|
153 |
|
---|
154 | vecp.push_back(make_pair(time, p));
|
---|
155 | }
|
---|
156 |
|
---|
157 | return 0;
|
---|
158 | }
|
---|
159 |
|
---|
160 | Int_t PlotCurrent(TArrayD **vec, TString fname)
|
---|
161 | {
|
---|
162 | Int_t rc = ReadSources(fname);
|
---|
163 | if (rc<0)
|
---|
164 | return rc;
|
---|
165 |
|
---|
166 | fname += ".FEEDBACK_CALIBRATED_CURRENTS.fits";
|
---|
167 |
|
---|
168 | fits file(fname.Data());
|
---|
169 | if (!file)
|
---|
170 | {
|
---|
171 | cerr << fname << ": " << gSystem->GetError() << endl;
|
---|
172 | return -2;
|
---|
173 | }
|
---|
174 |
|
---|
175 | //cout << fname << endl;
|
---|
176 |
|
---|
177 | Double_t time;
|
---|
178 | Float_t Imed;
|
---|
179 | Float_t Idev;
|
---|
180 | Float_t I[416];
|
---|
181 |
|
---|
182 | if (!file.SetPtrAddress("Time", &time))
|
---|
183 | return -1;
|
---|
184 |
|
---|
185 | if (!file.SetPtrAddress("I_med", &Imed))
|
---|
186 | return -1;
|
---|
187 |
|
---|
188 | if (!file.SetPtrAddress("I_dev", &Idev))
|
---|
189 | return -1;
|
---|
190 |
|
---|
191 | if (!file.SetPtrAddress("I", I))
|
---|
192 | return -1;
|
---|
193 |
|
---|
194 | TGraph g1;
|
---|
195 | TGraph g2;
|
---|
196 | TGraph g3;
|
---|
197 | TGraph g4;
|
---|
198 | TGraph g5;
|
---|
199 | g1.SetName("CurrentsMed");
|
---|
200 | g2.SetName("Prediction");
|
---|
201 | g3.SetName("CurrentsDev");
|
---|
202 | g4.SetName("CurrentsMax-4");
|
---|
203 | g5.SetName("CurrentsMax");
|
---|
204 |
|
---|
205 | while (file.GetNextRow())
|
---|
206 | if (Contains(vec, time))
|
---|
207 | {
|
---|
208 | // crazy pixels
|
---|
209 | I[66] = 0;
|
---|
210 | I[191] = 0;
|
---|
211 | I[193] = 0;
|
---|
212 |
|
---|
213 | sort(I, I+320);
|
---|
214 |
|
---|
215 | g1.SetPoint(g1.GetN(), time*24*3600, Imed);
|
---|
216 | g2.SetPoint(g2.GetN(), time*24*3600, Prediction(time));
|
---|
217 | g3.SetPoint(g3.GetN(), time*24*3600, Imed+Idev);
|
---|
218 | g4.SetPoint(g4.GetN(), time*24*3600, I[315]);
|
---|
219 | g5.SetPoint(g5.GetN(), time*24*3600, I[319]);
|
---|
220 | }
|
---|
221 |
|
---|
222 | g1.SetMinimum(0);
|
---|
223 | g1.SetMaximum(149);
|
---|
224 |
|
---|
225 | g1.SetMarkerStyle(kFullDotMedium);
|
---|
226 | g1.GetXaxis()->SetTimeDisplay(true);
|
---|
227 | g1.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
|
---|
228 | g1.GetXaxis()->SetLabelSize(0.12);
|
---|
229 | g1.GetYaxis()->SetLabelSize(0.1);
|
---|
230 | g1.GetYaxis()->SetTitle("CURRENT");
|
---|
231 | g1.GetYaxis()->SetTitleOffset(0.2);
|
---|
232 | g1.GetYaxis()->SetTitleSize(0.1);
|
---|
233 | g1.DrawClone("AP");
|
---|
234 |
|
---|
235 | g5.SetMarkerColor(kGray);
|
---|
236 | g5.DrawClone("P");
|
---|
237 |
|
---|
238 | g4.SetMarkerColor(kGray+1);
|
---|
239 | g4.DrawClone("P");
|
---|
240 |
|
---|
241 | g3.SetMarkerColor(kGray+2);
|
---|
242 | g3.DrawClone("P");
|
---|
243 |
|
---|
244 | g2.SetMarkerColor(kBlue);
|
---|
245 | g2.SetMarkerStyle(kFullDotMedium);
|
---|
246 | g2.DrawClone("P");
|
---|
247 |
|
---|
248 | g1.DrawClone("P");
|
---|
249 |
|
---|
250 | return 0;
|
---|
251 | }
|
---|
252 |
|
---|
253 | Int_t PlotRate(TArrayD **vec, TString fname)
|
---|
254 | {
|
---|
255 | fname += ".FTM_CONTROL_TRIGGER_RATES.fits";
|
---|
256 |
|
---|
257 | fits file(fname.Data());
|
---|
258 | if (!file)
|
---|
259 | {
|
---|
260 | cerr << fname << ": " << gSystem->GetError() << endl;
|
---|
261 | return -2;
|
---|
262 | }
|
---|
263 |
|
---|
264 | //cout << fname << endl;
|
---|
265 |
|
---|
266 | Double_t time;
|
---|
267 | Float_t rate;
|
---|
268 | Float_t ontime, elapsed;
|
---|
269 |
|
---|
270 | if (!file.SetPtrAddress("Time", &time))
|
---|
271 | return -1;
|
---|
272 |
|
---|
273 | if (!file.SetPtrAddress("TriggerRate", &rate))
|
---|
274 | return -1;
|
---|
275 | if (!file.SetPtrAddress("OnTime", &ontime))
|
---|
276 | return -1;
|
---|
277 | if (!file.SetPtrAddress("ElapsedTime", &elapsed))
|
---|
278 | return -1;
|
---|
279 |
|
---|
280 | TGraph g1, g2;
|
---|
281 | g1.SetName("TriggerRate");
|
---|
282 | g2.SetName("RelOnTime");
|
---|
283 |
|
---|
284 | while (file.GetNextRow())
|
---|
285 | if (Contains(vec, time))
|
---|
286 | {
|
---|
287 | if (rate>=0)
|
---|
288 | {
|
---|
289 | g1.SetPoint(g1.GetN(), time*24*3600, rate);
|
---|
290 | g2.SetPoint(g2.GetN(), time*24*3600, ontime/elapsed);
|
---|
291 | }
|
---|
292 | }
|
---|
293 |
|
---|
294 | g1.SetMinimum(0);
|
---|
295 | g1.SetMaximum(269);
|
---|
296 | g1.SetMarkerStyle(kFullDotMedium);
|
---|
297 | g1.GetXaxis()->SetTimeDisplay(true);
|
---|
298 | g1.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
|
---|
299 | g1.GetXaxis()->SetLabelSize(0.12);
|
---|
300 | g1.GetYaxis()->SetLabelSize(0.1);
|
---|
301 | g1.GetYaxis()->SetTitle("TRIGGER RATE");
|
---|
302 | g1.GetYaxis()->SetTitleOffset(0.2);
|
---|
303 | g1.GetYaxis()->SetTitleSize(0.1);
|
---|
304 | g1.DrawClone("AP");
|
---|
305 |
|
---|
306 | gROOT->SetSelectedPad(0);
|
---|
307 | gPad->GetCanvas()->cd(4);
|
---|
308 |
|
---|
309 | gPad->SetGrid();
|
---|
310 | gPad->SetTopMargin(0);
|
---|
311 | gPad->SetBottomMargin(0);
|
---|
312 | gPad->SetRightMargin(0.001);
|
---|
313 | gPad->SetLeftMargin(0.04);
|
---|
314 |
|
---|
315 | g2.SetMinimum(0);
|
---|
316 | g2.SetMaximum(1);
|
---|
317 | g2.SetMarkerStyle(kFullDotMedium);
|
---|
318 | g2.GetXaxis()->SetTimeDisplay(true);
|
---|
319 | g2.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
|
---|
320 | g2.GetXaxis()->SetLabelSize(0.12);
|
---|
321 | g2.GetYaxis()->SetLabelSize(0.1);
|
---|
322 | g2.GetYaxis()->SetTitle("RELATIVE ON TIME");
|
---|
323 | g2.GetYaxis()->SetTitleOffset(0.2);
|
---|
324 | g2.GetYaxis()->SetTitleSize(0.1);
|
---|
325 | g2.DrawClone("AP");
|
---|
326 |
|
---|
327 | return 0;
|
---|
328 | }
|
---|
329 |
|
---|
330 | void PlotRateQC(UInt_t night, MSQLServer &serv)
|
---|
331 | {
|
---|
332 | TString query =
|
---|
333 | "LEFT JOIN AnalysisResultsRunLP USING(fNight, fRunID) "
|
---|
334 | "WHERE fRunTypeKey=1 AND NOT ISNULL (AnalysisResultsRunLP.fNumEvtsAfterCleaning) AND fNight=";
|
---|
335 | query += night;
|
---|
336 |
|
---|
337 | TTree *t = serv.GetTree("RunInfo", query);
|
---|
338 | if (!t)
|
---|
339 | return;
|
---|
340 |
|
---|
341 | int save = gErrorIgnoreLevel;
|
---|
342 | gErrorIgnoreLevel = kFatal;
|
---|
343 |
|
---|
344 | gROOT->SetSelectedPad(0);
|
---|
345 | gPad->GetCanvas()->cd(3);
|
---|
346 |
|
---|
347 | t->Draw("AnalysisResultsRunLP.fNumEvtsAfterCleaning/AnalysisResultsRunLP.fOnTimeAfterCuts:(RunInfo.fRunStart+RunInfo.fRunStop)/2+9131*24*3600", "", "same");
|
---|
348 | TGraph *g = (TGraph*)gPad->GetPrimitive("Graph");
|
---|
349 | if (g)
|
---|
350 | {
|
---|
351 | g->SetName("CleaningRate");
|
---|
352 | g->SetMarkerColor(kRed);
|
---|
353 | g->SetMarkerStyle(29);//kFullDotMedium);
|
---|
354 | }
|
---|
355 |
|
---|
356 | t->Draw("AnalysisResultsRunLP.fNumEvtsAfterQualCuts/AnalysisResultsRunLP.fOnTimeAfterCuts:(RunInfo.fRunStart+RunInfo.fRunStop)/2+9131*24*3600", "", "same");
|
---|
357 | g = (TGraph*)gPad->GetPrimitive("Graph");
|
---|
358 | if (g)
|
---|
359 | {
|
---|
360 | g->SetName("RateAfterQC");
|
---|
361 | g->SetMarkerColor(kBlue);
|
---|
362 | g->SetMarkerStyle(29);//kFullDotMedium);
|
---|
363 | }
|
---|
364 |
|
---|
365 | gErrorIgnoreLevel = save;
|
---|
366 | }
|
---|
367 |
|
---|
368 |
|
---|
369 | Int_t PlotPointing(TArrayD **vec, TString fname)
|
---|
370 | {
|
---|
371 | fname += ".DRIVE_CONTROL_POINTING_POSITION.fits";
|
---|
372 |
|
---|
373 | fits file(fname.Data());
|
---|
374 | if (!file)
|
---|
375 | {
|
---|
376 | cerr << fname << ": " << gSystem->GetError() << endl;
|
---|
377 | return -2;
|
---|
378 | }
|
---|
379 |
|
---|
380 | //cout << fname << endl;
|
---|
381 |
|
---|
382 | Double_t time;
|
---|
383 | Double_t zd;
|
---|
384 |
|
---|
385 | if (!file.SetPtrAddress("Time", &time))
|
---|
386 | return -1;
|
---|
387 | if (!file.SetPtrAddress("Zd", &zd))
|
---|
388 | return -1;
|
---|
389 |
|
---|
390 | TGraph g;
|
---|
391 | g.SetName("Zd");
|
---|
392 |
|
---|
393 | while (file.GetNextRow())
|
---|
394 | if (Contains(vec, time))
|
---|
395 | g.SetPoint(g.GetN(), time*24*3600, 90-zd);
|
---|
396 |
|
---|
397 | g.SetMinimum(1);
|
---|
398 | g.SetMaximum(90);
|
---|
399 | g.SetMarkerStyle(kFullDotMedium);
|
---|
400 | g.GetXaxis()->SetTimeDisplay(true);
|
---|
401 | g.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
|
---|
402 | g.GetXaxis()->SetLabelSize(0.12);
|
---|
403 | g.GetYaxis()->SetLabelSize(0.1);
|
---|
404 | g.GetYaxis()->SetTitle("ELEVATION");
|
---|
405 | g.GetYaxis()->SetTitleOffset(0.2);
|
---|
406 | g.GetYaxis()->SetTitleSize(0.1);
|
---|
407 | g.DrawClone("AP");
|
---|
408 |
|
---|
409 | return 0;
|
---|
410 | }
|
---|
411 |
|
---|
412 | Int_t PlotTemperature1(TArrayD **vec, TString fname)
|
---|
413 | {
|
---|
414 | fname += ".TEMPERATURE_DATA.fits";
|
---|
415 |
|
---|
416 | fits file(fname.Data());
|
---|
417 | if (!file)
|
---|
418 | {
|
---|
419 | cerr << fname << ": " << gSystem->GetError() << endl;
|
---|
420 | return -2;
|
---|
421 | }
|
---|
422 |
|
---|
423 | //cout << fname << endl;
|
---|
424 |
|
---|
425 | Double_t time;
|
---|
426 | Float_t temp;
|
---|
427 |
|
---|
428 | if (!file.SetPtrAddress("Time", &time))
|
---|
429 | return -1;
|
---|
430 | if (!file.SetPtrAddress("T", &temp))
|
---|
431 | return -1;
|
---|
432 |
|
---|
433 | TGraph g;
|
---|
434 | g.SetName("ContainerTemp");
|
---|
435 |
|
---|
436 | while (file.GetNextRow())
|
---|
437 | if (Contains(vec, time))
|
---|
438 | g.SetPoint(g.GetN(), time*24*3600, temp);
|
---|
439 |
|
---|
440 | g.SetMinimum(-5);
|
---|
441 | g.SetMaximum(49);
|
---|
442 | g.SetMarkerStyle(kFullDotMedium);
|
---|
443 | g.SetMarkerColor(kRed);
|
---|
444 | g.GetXaxis()->SetTimeDisplay(true);
|
---|
445 | g.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
|
---|
446 | g.GetXaxis()->SetLabelSize(0.1);
|
---|
447 | g.GetYaxis()->SetLabelSize(0.1);
|
---|
448 | g.GetYaxis()->SetTitle("TEMP");
|
---|
449 | g.GetYaxis()->SetTitleOffset(0.2);
|
---|
450 | g.GetYaxis()->SetTitleSize(0.1);
|
---|
451 | g.DrawClone("AP");
|
---|
452 |
|
---|
453 | return 0;
|
---|
454 | }
|
---|
455 |
|
---|
456 | Int_t PlotTemperature2(TArrayD **vec, TString fname)
|
---|
457 | {
|
---|
458 | fname += ".MAGIC_WEATHER_DATA.fits";
|
---|
459 |
|
---|
460 | fits file(fname.Data());
|
---|
461 | if (!file)
|
---|
462 | {
|
---|
463 | cerr << fname << ": " << gSystem->GetError() << endl;
|
---|
464 | return -2;
|
---|
465 | }
|
---|
466 |
|
---|
467 | //cout << fname << endl;
|
---|
468 |
|
---|
469 | Double_t time;
|
---|
470 | Float_t temp;
|
---|
471 |
|
---|
472 | if (!file.SetPtrAddress("Time", &time))
|
---|
473 | return -1;
|
---|
474 | if (!file.SetPtrAddress("T", &temp))
|
---|
475 | return -1;
|
---|
476 |
|
---|
477 | TGraph g;
|
---|
478 | g.SetName("OutsideTemp");
|
---|
479 |
|
---|
480 | while (file.GetNextRow())
|
---|
481 | if (Contains(vec, time))
|
---|
482 | g.SetPoint(g.GetN(), time*24*3600, temp);
|
---|
483 |
|
---|
484 | g.SetMarkerStyle(kFullDotMedium);
|
---|
485 | g.SetMarkerColor(kBlue);
|
---|
486 | g.DrawClone("P");
|
---|
487 |
|
---|
488 | return 0;
|
---|
489 | }
|
---|
490 |
|
---|
491 | Int_t PlotTemperature3(TArrayD **vec, TString fname)
|
---|
492 | {
|
---|
493 | fname += ".FSC_CONTROL_TEMPERATURE.fits";
|
---|
494 |
|
---|
495 | fits file(fname.Data());
|
---|
496 | if (!file)
|
---|
497 | {
|
---|
498 | cerr << fname << ": " << gSystem->GetError() << endl;
|
---|
499 | return -2;
|
---|
500 | }
|
---|
501 |
|
---|
502 | //cout << fname << endl;
|
---|
503 |
|
---|
504 | Double_t time;
|
---|
505 | Float_t temp[31];
|
---|
506 |
|
---|
507 | if (!file.SetPtrAddress("Time", &time))
|
---|
508 | return -1;
|
---|
509 | if (!file.SetPtrAddress("T_sens", temp))
|
---|
510 | return -1;
|
---|
511 |
|
---|
512 | TGraph g, g1, g2;
|
---|
513 | g.SetName("SensorTempAvg");
|
---|
514 | g1.SetName("SensorTempMin");
|
---|
515 | g2.SetName("SensorTempMax");
|
---|
516 |
|
---|
517 | while (file.GetNextRow())
|
---|
518 | if (Contains(vec, time))
|
---|
519 | {
|
---|
520 | float min = 100;
|
---|
521 | float max = -100;
|
---|
522 | double avg = 0;
|
---|
523 | int num = 0;
|
---|
524 | for (int i=0; i<31; i++)
|
---|
525 | if (temp[i]!=0)
|
---|
526 | {
|
---|
527 | avg += temp[i];
|
---|
528 | num++;
|
---|
529 |
|
---|
530 | min = TMath::Min(min, temp[i]);
|
---|
531 | max = TMath::Max(max, temp[i]);
|
---|
532 | }
|
---|
533 |
|
---|
534 | g.SetPoint(g.GetN(), time*24*3600, avg/num);
|
---|
535 | g1.SetPoint(g1.GetN(), time*24*3600, min);
|
---|
536 | g2.SetPoint(g2.GetN(), time*24*3600, max);
|
---|
537 | }
|
---|
538 |
|
---|
539 | g.SetMarkerStyle(kFullDotMedium);
|
---|
540 | g.DrawClone("P");
|
---|
541 |
|
---|
542 | /*
|
---|
543 | g1.SetLineWidth(1);
|
---|
544 | g1.DrawClone("L");
|
---|
545 |
|
---|
546 | g2.SetLineWidth(1);
|
---|
547 | g2.DrawClone("L");
|
---|
548 | */
|
---|
549 | return 0;
|
---|
550 | }
|
---|
551 |
|
---|
552 | Int_t PlotTemperature4(TArrayD **vec, TString fname)
|
---|
553 | {
|
---|
554 | fname += ".FAD_CONTROL_TEMPERATURE.fits";
|
---|
555 |
|
---|
556 | fits file(fname.Data());
|
---|
557 | if (!file)
|
---|
558 | {
|
---|
559 | cerr << fname << ": " << gSystem->GetError() << endl;
|
---|
560 | return -2;
|
---|
561 | }
|
---|
562 |
|
---|
563 | //cout << fname << endl;
|
---|
564 |
|
---|
565 | Double_t time;
|
---|
566 | Float_t temp[160];
|
---|
567 |
|
---|
568 | if (!file.SetPtrAddress("Time", &time))
|
---|
569 | return -1;
|
---|
570 | // if (!file.SetPtrAddress("Data1", temp) &&
|
---|
571 | // !file.SetPtrAddress("temp", temp))
|
---|
572 | if (!file.SetPtrAddress("temp", temp))
|
---|
573 | return -1;
|
---|
574 |
|
---|
575 | Int_t num = file.GetN("temp")==0 ? file.GetN("Data1") : file.GetN("temp");
|
---|
576 | Int_t beg = num==82 ? 2 : 0;
|
---|
577 |
|
---|
578 | TGraphErrors g1;
|
---|
579 | TGraph g2,g3;
|
---|
580 |
|
---|
581 | g1.SetName("FadTempAvg");
|
---|
582 | g2.SetName("FadTempMin");
|
---|
583 | g3.SetName("FadTempMax");
|
---|
584 |
|
---|
585 | while (file.GetNextRow())
|
---|
586 | if (Contains(vec, time))
|
---|
587 | {
|
---|
588 | double avg = 0;
|
---|
589 | double rms = 0;
|
---|
590 | float min = 100;
|
---|
591 | float max = -100;
|
---|
592 | for (int i=beg; i<num; i++)
|
---|
593 | {
|
---|
594 | avg += temp[i];
|
---|
595 | rms += temp[i]*temp[i];
|
---|
596 |
|
---|
597 | min = TMath::Min(min, temp[i]);
|
---|
598 | max = TMath::Max(max, temp[i]);
|
---|
599 | }
|
---|
600 |
|
---|
601 | avg /= num-beg;
|
---|
602 | rms /= num-beg;
|
---|
603 |
|
---|
604 | g1.SetPoint(g1.GetN(), time*24*3600, avg);
|
---|
605 | g1.SetPointError(g1.GetN()-1, 0, sqrt(rms-avg*avg));
|
---|
606 |
|
---|
607 | g2.SetPoint(g2.GetN(), time*24*3600, min);
|
---|
608 | g3.SetPoint(g3.GetN(), time*24*3600, max);
|
---|
609 | }
|
---|
610 |
|
---|
611 | g1.SetLineColor(kGreen);
|
---|
612 | g1.DrawClone("[]");
|
---|
613 |
|
---|
614 | g2.SetLineColor(kGreen);
|
---|
615 | g2.SetLineWidth(1);
|
---|
616 | g2.DrawClone("L");
|
---|
617 |
|
---|
618 | g3.SetLineColor(kGreen);
|
---|
619 | g3.SetLineWidth(1);
|
---|
620 | g3.DrawClone("L");
|
---|
621 |
|
---|
622 | return 0;
|
---|
623 | }
|
---|
624 |
|
---|
625 | int quality(UInt_t y=0, UInt_t m=0, UInt_t d=0, const char *outpath="quality")
|
---|
626 | {
|
---|
627 | // To get correct dates in the histogram you have to add
|
---|
628 | // the MJDREF offset (should be 40587) and 9131.
|
---|
629 |
|
---|
630 | if (y==0)
|
---|
631 | {
|
---|
632 | UInt_t nt = MTime(MTime(-1).GetMjd()-1.5).GetNightAsInt();
|
---|
633 | y = nt/10000;
|
---|
634 | m = (nt/100)%100;
|
---|
635 | d = nt%100;
|
---|
636 |
|
---|
637 | cout << y << "/" << m << "/" << d << endl;
|
---|
638 | }
|
---|
639 |
|
---|
640 | TString fname=Form("/fact/aux/%04d/%02d/%02d/%04d%02d%02d", y, m, d, y, m, d);
|
---|
641 |
|
---|
642 | UInt_t night = MTime(y, m, d, 0).GetNightAsInt();
|
---|
643 |
|
---|
644 | MSQLMagic serv("sql.rc");
|
---|
645 | Bool_t con = serv.IsConnected();
|
---|
646 |
|
---|
647 | cout << "quality" << endl;
|
---|
648 | cout << "-------" << endl;
|
---|
649 | cout << endl;
|
---|
650 | if (con)
|
---|
651 | {
|
---|
652 | cout << "Connected to " << serv.GetName() << endl;
|
---|
653 | cout << endl;
|
---|
654 | }
|
---|
655 | cout << "Night: " << Form("%04d-%02d-%02d", y, m, d) << endl;
|
---|
656 | cout << endl;
|
---|
657 |
|
---|
658 | TArrayD run, beg, end;
|
---|
659 |
|
---|
660 | TArrayD *runs[3] = { &run, &beg, &end };
|
---|
661 |
|
---|
662 | if (con)
|
---|
663 | {
|
---|
664 | TString query;
|
---|
665 | query += "SELECT fRunID, fRunStart, fRunStop FROM RunInfo";
|
---|
666 | query += " WHERE fNight=";
|
---|
667 | query += night;
|
---|
668 | query += " AND fRunTypeKey=1 ORDER BY fRunStart";
|
---|
669 |
|
---|
670 | TSQLResult *res = serv.Query(query);
|
---|
671 | if (!res)
|
---|
672 | return 1;
|
---|
673 |
|
---|
674 | run.Set(res->GetRowCount());
|
---|
675 | beg.Set(res->GetRowCount());
|
---|
676 | end.Set(res->GetRowCount());
|
---|
677 |
|
---|
678 | Int_t n = 0;
|
---|
679 |
|
---|
680 | TSQLRow *row = 0;
|
---|
681 | while ((row=res->Next()))
|
---|
682 | {
|
---|
683 | run[n] = atoi((*row)[0]);
|
---|
684 | beg[n] = MTime((*row)[1]).GetMjd()-40587;
|
---|
685 | end[n] = MTime((*row)[2]).GetMjd()-40587;
|
---|
686 | n++;
|
---|
687 | delete row;
|
---|
688 | }
|
---|
689 |
|
---|
690 | delete res;
|
---|
691 |
|
---|
692 | if (n==0)
|
---|
693 | cout << "WARNING - No data runs in db, displaying all data." << endl;
|
---|
694 | else
|
---|
695 | cout << "Num: " << n << "\n" << endl;
|
---|
696 | }
|
---|
697 |
|
---|
698 | TCanvas *c = new TCanvas("quality", Form("Quality %04d/%02d/%02d", y, m, d), 1280, 960);
|
---|
699 | c->Divide(1, 6, 1e-5, 1e-5);
|
---|
700 |
|
---|
701 | gROOT->SetSelectedPad(0);
|
---|
702 |
|
---|
703 | c->cd(1);
|
---|
704 | gPad->SetGrid();
|
---|
705 | gPad->SetTopMargin(0);
|
---|
706 | gPad->SetRightMargin(0.001);
|
---|
707 | gPad->SetLeftMargin(0.04);
|
---|
708 | gPad->SetBottomMargin(0);
|
---|
709 | cout << PlotThresholds(runs, fname) << endl;
|
---|
710 |
|
---|
711 | gROOT->SetSelectedPad(0);
|
---|
712 | c->cd(2);
|
---|
713 | gPad->SetGrid();
|
---|
714 | gPad->SetTopMargin(0);
|
---|
715 | gPad->SetRightMargin(0.001);
|
---|
716 | gPad->SetLeftMargin(0.04);
|
---|
717 | gPad->SetBottomMargin(0);
|
---|
718 | cout << PlotCurrent(runs, fname) << endl;
|
---|
719 |
|
---|
720 | gROOT->SetSelectedPad(0);
|
---|
721 | c->cd(3);
|
---|
722 | gPad->SetGrid();
|
---|
723 | gPad->SetTopMargin(0);
|
---|
724 | gPad->SetBottomMargin(0);
|
---|
725 | gPad->SetRightMargin(0.001);
|
---|
726 | gPad->SetLeftMargin(0.04);
|
---|
727 | cout << PlotRate(runs, fname) << endl;
|
---|
728 | cout << PlotRateQC(night, serv) << endl;
|
---|
729 |
|
---|
730 | gROOT->SetSelectedPad(0);
|
---|
731 | c->cd(5);
|
---|
732 | gPad->SetGrid();
|
---|
733 | gPad->SetTopMargin(0);
|
---|
734 | gPad->SetBottomMargin(0);
|
---|
735 | gPad->SetRightMargin(0.001);
|
---|
736 | gPad->SetLeftMargin(0.04);
|
---|
737 | cout << PlotPointing(runs, fname) << endl;
|
---|
738 |
|
---|
739 | gROOT->SetSelectedPad(0);
|
---|
740 | c->cd(6);
|
---|
741 | gPad->SetGrid();
|
---|
742 | gPad->SetTopMargin(0);
|
---|
743 | gPad->SetRightMargin(0.001);
|
---|
744 | gPad->SetLeftMargin(0.04);
|
---|
745 | cout << PlotTemperature1(runs, fname) << endl;
|
---|
746 | cout << PlotTemperature2(runs, fname) << endl;
|
---|
747 | cout << PlotTemperature3(runs, fname) << endl;
|
---|
748 | cout << PlotTemperature4(runs, fname) << endl;
|
---|
749 |
|
---|
750 | c->SaveAs(Form("%s/%04d%02d%02d.png", outpath, y, m, d));
|
---|
751 |
|
---|
752 | return 0;
|
---|
753 | }
|
---|