source: trunk/Mars/fact/plots/quality.C@ 19344

Last change on this file since 19344 was 19266, checked in by tbretz, 6 years ago
Fixed some minor issues with the cling based interpreter - this should not have any effect at runtime maybe except stability
File size: 25.5 KB
Line 
1#ifndef __CLING__
2#include <algorithm>
3#include <functional>
4#include <vector>
5#include <pair>
6#endif
7
8Bool_t Contains(TArrayD **vec, Double_t t0, Double_t range=0)
9{
10 TArrayD *arr0 = vec[0];
11 TArrayD *arr1 = vec[1];
12 TArrayD *arr2 = vec[2];
13
14 for (int i=0; i<arr0->GetSize(); i++)
15 {
16 Double_t start = (*arr1)[i];
17 Double_t stop = (*arr2)[i];
18
19 if (stop>start+305./24/3600)
20 stop = start+305./24/3600;
21
22 if (t0>start-range && t0<stop+range)
23 //{
24 // if (fmod(t0, 1)>4./24 && fmod(t0,1)<4.1/24)
25 // cout << t0-start << " " <<t0 << " " << stop-t0 << " " << start-15779 << " " << stop-15779 << " " << (*arr0)[i] << endl;
26 return kTRUE;
27 //}
28 }
29
30 return arr0->GetSize()==0;
31}
32
33Int_t PlotThresholds(TArrayD **vec, TString fname)
34{
35 fname += ".RATE_CONTROL_THRESHOLD.fits";
36
37 fits file(fname.Data());
38 if (!file)
39 {
40 cerr << fname << ": " << gSystem->GetError() << endl;
41 return -2;
42 }
43
44 //cout << fname << endl;
45
46 Double_t time;
47 UShort_t th;
48
49 if (!file.SetPtrAddress("Time", &time))
50 return -1;
51
52 if (!file.SetPtrAddress("threshold", &th))
53 return -1;
54
55 TGraph g;
56 g.SetName("Threshold");
57
58 while (file.GetNextRow())
59 {
60 if (Contains(vec, time, 10./(24*3600)))
61 g.SetPoint(g.GetN(), time*24*3600, th);
62 }
63
64 g.SetMinimum(281);
65 g.SetMarkerStyle(kFullDotMedium);
66 g.GetXaxis()->SetTimeDisplay(true);
67 g.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
68 g.GetXaxis()->SetLabelSize(0.12);
69 g.GetYaxis()->SetLabelSize(0.1);
70 g.GetYaxis()->SetTitle("THRESHOLD");
71 g.GetYaxis()->SetTitleOffset(0.2);
72 g.GetYaxis()->SetTitleSize(0.1);
73 g.DrawClone("AP");
74
75 return 0;
76}
77
78vector<pair<double, Nova::EquPosn>> vecp;
79
80Nova::EquPosn FindPointing(Double_t time)
81{
82 for (int i=0; i<vecp.size(); i++)
83 if (time<vecp[i].first)
84 {
85 if (i==0)
86 return Nova::EquPosn();
87 else
88 return vecp[i-1].second;
89 }
90
91 return vecp[vecp.size()-1].second;
92}
93
94Float_t Prediction(Double_t time)
95{
96 Double_t jd = time + 40587 + 2400000.5;
97
98 // Sun properties
99 Nova::EquPosn sun = Nova::GetSolarEquCoords(jd);
100 Nova::ZdAzPosn hrzs = Nova::GetHrzFromEqu(sun, jd);
101
102 // Get source position
103 Nova::EquPosn pos = FindPointing(time);
104
105
106 // Moon properties
107 Nova::EquPosn moon = Nova::GetLunarEquCoords(jd, 0.01);
108 Nova::HrzPosn hrzm = Nova::GetHrzFromEqu(moon, jd);
109 double disk = Nova::GetLunarDisk(jd);
110
111 // Derived moon properties
112 double angle = Nova::GetAngularSeparation(moon, pos);
113 double edist = Nova::GetLunarEarthDist(jd)/384400;
114
115 // Current prediction
116 double sin_malt = hrzm.alt<0 ? 0 : sin(hrzm.alt*TMath::DegToRad());
117 double cos_mdist = cos(angle*TMath::DegToRad());
118 double sin_szd = sin(hrzs.zd*TMath::DegToRad());
119
120 double c0 = pow(disk, 2.63);
121 double c1 = pow(sin_malt, 0.60);
122 double c2 = pow(edist, -2.00);
123 double c3 = exp(0.67*cos_mdist*cos_mdist*cos_mdist*cos_mdist);
124 double c4 = exp(-97.8+105.8*sin_szd*sin_szd);
125
126 double cur = 6.2 + 95.7*c0*c1*c2*c3 + c4;
127
128 return cur;
129}
130
131Int_t ReadSources(TString fname)
132{
133 fname += ".DRIVE_CONTROL_SOURCE_POSITION.fits";
134
135 fits file(fname.Data());
136 if (!file)
137 {
138 cerr << fname << ": " << gSystem->GetError() << endl;
139 return -2;
140 }
141
142 Double_t time, ra, dec;
143 if (!file.SetPtrAddress("Time", &time))
144 return -1;
145 if (!file.SetPtrAddress("Ra_cmd", &ra))
146 return -1;
147 if (!file.SetPtrAddress("Dec_cmd", &dec))
148 return -1;
149
150 while (file.GetNextRow())
151 {
152 Nova::EquPosn p;
153 p.ra = ra*15;
154 p.dec = dec;
155
156 vecp.push_back(make_pair(time, p));
157 }
158
159 return 0;
160}
161
162Int_t PlotCurrent(TArrayD **vec, TString fname)
163{
164 Int_t rc = ReadSources(fname);
165 if (rc<0)
166 return rc;
167
168 fname += ".FEEDBACK_CALIBRATED_CURRENTS.fits";
169
170 fits file(fname.Data());
171 if (!file)
172 {
173 cerr << fname << ": " << gSystem->GetError() << endl;
174 return -2;
175 }
176
177 //cout << fname << endl;
178
179 Double_t time;
180 Float_t Imed;
181 Float_t Idev;
182 Float_t I[416];
183
184 if (!file.SetPtrAddress("Time", &time))
185 return -1;
186
187 if (!file.SetPtrAddress("I_med", &Imed))
188 return -1;
189
190 if (!file.SetPtrAddress("I_dev", &Idev))
191 return -1;
192
193 if (!file.SetPtrAddress("I", I))
194 return -1;
195
196 TGraph g1;
197 TGraph g2;
198 TGraph g3;
199 TGraph g4;
200 TGraph g5;
201 g1.SetName("CurrentsMed");
202 g2.SetName("Prediction");
203 g3.SetName("CurrentsDev");
204 g4.SetName("CurrentsMax-4");
205 g5.SetName("CurrentsMax");
206
207 while (file.GetNextRow())
208 if (Contains(vec, time))
209 {
210 // crazy pixels
211 I[66] = 0;
212 I[191] = 0;
213 I[193] = 0;
214
215 sort(I, I+320);
216
217 g1.SetPoint(g1.GetN(), time*24*3600, Imed);
218 g2.SetPoint(g2.GetN(), time*24*3600, Prediction(time));
219 g3.SetPoint(g3.GetN(), time*24*3600, Imed+Idev);
220 g4.SetPoint(g4.GetN(), time*24*3600, I[315]);
221 g5.SetPoint(g5.GetN(), time*24*3600, I[319]);
222 }
223
224 g1.SetMinimum(0);
225 g1.SetMaximum(149);
226
227 g1.SetMarkerStyle(kFullDotMedium);
228 g1.GetXaxis()->SetTimeDisplay(true);
229 g1.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
230 g1.GetXaxis()->SetLabelSize(0.12);
231 g1.GetYaxis()->SetLabelSize(0.1);
232 g1.GetYaxis()->SetTitle("CURRENT");
233 g1.GetYaxis()->SetTitleOffset(0.2);
234 g1.GetYaxis()->SetTitleSize(0.1);
235 g1.DrawClone("AP");
236
237 g5.SetMarkerColor(kGray);
238 g5.DrawClone("P");
239
240 g4.SetMarkerColor(kGray+1);
241 g4.DrawClone("P");
242
243 g3.SetMarkerColor(kGray+2);
244 g3.DrawClone("P");
245
246 g2.SetMarkerColor(kBlue);
247 g2.SetMarkerStyle(kFullDotMedium);
248 g2.DrawClone("P");
249
250 g1.DrawClone("P");
251
252 return 0;
253}
254
255Int_t PlotRate(TArrayD **vec, TString fname)
256{
257 fname += ".FTM_CONTROL_TRIGGER_RATES.fits";
258
259 fits file(fname.Data());
260 if (!file)
261 {
262 cerr << fname << ": " << gSystem->GetError() << endl;
263 return -2;
264 }
265
266 //cout << fname << endl;
267
268 Double_t time;
269 Float_t rate;
270 Float_t ontime, elapsed;
271
272 if (!file.SetPtrAddress("Time", &time))
273 return -1;
274
275 if (!file.SetPtrAddress("TriggerRate", &rate))
276 return -1;
277 if (!file.SetPtrAddress("OnTime", &ontime))
278 return -1;
279 if (!file.SetPtrAddress("ElapsedTime", &elapsed))
280 return -1;
281
282 TGraph g1, g2;
283 g1.SetName("TriggerRate");
284 g2.SetName("RelOnTime");
285
286 while (file.GetNextRow())
287 if (Contains(vec, time))
288 {
289 if (rate>=0)
290 {
291 g1.SetPoint(g1.GetN(), time*24*3600, rate);
292 g2.SetPoint(g2.GetN(), time*24*3600, ontime/elapsed);
293 }
294 }
295
296 g1.SetMinimum(0);
297 g1.SetMaximum(269);
298 g1.SetMarkerStyle(kFullDotMedium);
299 g1.GetXaxis()->SetTimeDisplay(true);
300 g1.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
301 g1.GetXaxis()->SetLabelSize(0.12);
302 g1.GetYaxis()->SetLabelSize(0.1);
303 g1.GetYaxis()->SetTitle("TRIGGER RATE");
304 g1.GetYaxis()->SetTitleOffset(0.2);
305 g1.GetYaxis()->SetTitleSize(0.1);
306 g1.DrawClone("AP");
307
308 gROOT->SetSelectedPad(0);
309 gPad->GetCanvas()->cd(4);
310
311 gPad->SetGrid();
312 gPad->SetTopMargin(0);
313 gPad->SetBottomMargin(0);
314 gPad->SetRightMargin(0.001);
315 gPad->SetLeftMargin(0.04);
316
317 g2.SetMinimum(0);
318 g2.SetMaximum(1);
319 g2.SetMarkerStyle(kFullDotMedium);
320 g2.GetXaxis()->SetTimeDisplay(true);
321 g2.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
322 g2.GetXaxis()->SetLabelSize(0.12);
323 g2.GetYaxis()->SetLabelSize(0.1);
324 g2.GetYaxis()->SetTitle("RELATIVE ON TIME");
325 g2.GetYaxis()->SetTitleOffset(0.2);
326 g2.GetYaxis()->SetTitleSize(0.1);
327 g2.DrawClone("AP");
328
329 return 0;
330}
331
332void PlotRateQC(UInt_t night, MSQLServer &serv)
333{
334 TString query =
335 "LEFT JOIN AnalysisResultsRunLP USING(fNight, fRunID) "
336 "WHERE fRunTypeKey=1 AND NOT ISNULL (AnalysisResultsRunLP.fNumEvtsAfterCleaning) AND fNight=";
337 query += night;
338
339 TTree *t = serv.GetTree("RunInfo", query);
340 if (!t)
341 return;
342
343 int save = gErrorIgnoreLevel;
344 gErrorIgnoreLevel = kFatal;
345
346 gROOT->SetSelectedPad(0);
347 gPad->GetCanvas()->cd(3);
348
349 t->Draw("AnalysisResultsRunLP.fNumEvtsAfterCleaning/AnalysisResultsRunLP.fOnTimeAfterCuts:(RunInfo.fRunStart+RunInfo.fRunStop)/2+9131*24*3600", "", "same");
350 TGraph *g = (TGraph*)gPad->GetPrimitive("Graph");
351 if (g)
352 {
353 g->SetName("CleaningRate");
354 g->SetMarkerColor(kRed);
355 g->SetMarkerStyle(29);//kFullDotMedium);
356 }
357
358 t->Draw("AnalysisResultsRunLP.fNumEvtsAfterQualCuts/AnalysisResultsRunLP.fOnTimeAfterCuts:(RunInfo.fRunStart+RunInfo.fRunStop)/2+9131*24*3600", "", "same");
359 g = (TGraph*)gPad->GetPrimitive("Graph");
360 if (g)
361 {
362 g->SetName("RateAfterQC");
363 g->SetMarkerColor(kBlue);
364 g->SetMarkerStyle(29);//kFullDotMedium);
365 }
366
367 gErrorIgnoreLevel = save;
368}
369
370Int_t PlotSqm(TArrayD **vec, TString fname)
371{
372 fname += ".SQM_CONTROL_DATA.fits";
373
374 fits file(fname.Data());
375 if (!file)
376 {
377 cerr << fname << ": " << gSystem->GetError() << endl;
378 return -2;
379 }
380
381 //cout << fname << endl;
382
383 Double_t time;
384 Float_t mag; // magnitude
385
386 if (!file.SetPtrAddress("Time", &time))
387 return -1;
388 if (!file.SetPtrAddress("Mag", &mag))
389 return -1;
390
391 //const int marker_style = kFullDotMedium;
392 const int marker_style = kDot;
393
394 TGraph g1;
395 g1.SetName("SQM");
396
397
398 bool found_first_time = false;
399 while (file.GetNextRow())
400 if (Contains(vec, time))
401 {
402 g1.SetPoint(g1.GetN(), time*24*3600, mag);
403 }
404
405
406 g1.SetMinimum(19.0);
407 g1.SetMaximum(21.5);
408 g1.SetMarkerColor(kBlack);
409 g1.SetMarkerStyle(marker_style);
410 g1.GetXaxis()->SetTimeDisplay(true);
411 g1.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
412 g1.GetXaxis()->SetLabelSize(0.12);
413 g1.GetYaxis()->SetLabelSize(0.1);
414 g1.GetYaxis()->SetTitle("SQM [mag]");
415 g1.GetYaxis()->SetTitleOffset(0.2);
416 g1.GetYaxis()->SetTitleSize(0.1);
417 g1.DrawClone("AP");
418
419 return 0;
420}
421
422Int_t PlotSqmLinear(TArrayD **vec, TString fname)
423{
424 fname += ".SQM_CONTROL_DATA.fits";
425
426 fits file(fname.Data());
427 if (!file)
428 {
429 cerr << fname << ": " << gSystem->GetError() << endl;
430 return -2;
431 }
432
433 //cout << fname << endl;
434
435 Double_t time;
436 Float_t mag; // magnitude
437
438 if (!file.SetPtrAddress("Time", &time))
439 return -1;
440 if (!file.SetPtrAddress("Mag", &mag))
441 return -1;
442
443 //const int marker_style = kFullDotMedium;
444 const int marker_style = kDot;
445
446 TGraph g1;
447 g1.SetName("SQM");
448
449
450 bool found_first_time = false;
451 while (file.GetNextRow())
452 if (Contains(vec, time))
453 {
454 Double_t mag_double = 4.4 * pow(10, 20) * pow( 10, mag*(-0.4));
455 g1.SetPoint(g1.GetN(), time*24*3600, mag_double);
456 }
457
458
459 g1.SetMinimum(1.e12);
460 g1.SetMaximum(5.e12);
461 g1.SetMarkerColor(kBlack);
462 g1.SetMarkerStyle(marker_style);
463 g1.GetXaxis()->SetTimeDisplay(true);
464 g1.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
465 g1.GetXaxis()->SetLabelSize(0.12);
466 g1.GetYaxis()->SetLabelSize(0.1);
467 g1.GetYaxis()->SetTitle("SQM lin [phot./(s sr m^2)]");
468 g1.GetYaxis()->SetTitleOffset(0.2);
469 g1.GetYaxis()->SetTitleSize(0.1);
470 g1.DrawClone("AP");
471
472 return 0;
473}
474
475Int_t PlotHumidity(TArrayD **vec, TString fname)
476{
477 fname += ".FSC_CONTROL_HUMIDITY.fits";
478
479 fits file(fname.Data());
480 if (!file)
481 {
482 cerr << fname << ": " << gSystem->GetError() << endl;
483 return -2;
484 }
485
486 //cout << fname << endl;
487
488 Double_t time;
489 Float_t H[4];
490
491 if (!file.SetPtrAddress("Time", &time))
492 return -1;
493 if (!file.SetPtrAddress("H", H))
494 return -1;
495
496 //const int marker_style = kFullDotMedium;
497 const int marker_style = kDot;
498
499 TGraph g1;
500 TGraph g2;
501 TGraph g3;
502 TGraph g4;
503 //TGraph g5;
504 g1.SetName("H0");
505 g2.SetName("H1");
506 g3.SetName("H2");
507 g4.SetName("H3");
508 //g5.SetName("PFmini");
509
510
511 Double_t first_time, last_time;
512 bool found_first_time = false;
513 while (file.GetNextRow())
514 if (Contains(vec, time))
515 {
516 if (!found_first_time){
517 first_time = time*24*3600;
518 found_first_time = true;
519 }
520 g1.SetPoint(g1.GetN(), time*24*3600, H[0]);
521 g2.SetPoint(g2.GetN(), time*24*3600, H[1]);
522 g3.SetPoint(g3.GetN(), time*24*3600, H[2]);
523 g4.SetPoint(g4.GetN(), time*24*3600, H[3]);
524 //g5.SetPoint(g5.GetN(), time*24*3600, I[319]);
525 last_time = time*24*3600;
526 }
527
528
529 g1.SetMinimum(10);
530 g1.SetMaximum(80);
531 g1.SetMarkerColor(kAzure);
532 g1.SetMarkerStyle(marker_style);
533 g1.GetXaxis()->SetTimeDisplay(true);
534 g1.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
535 g1.GetXaxis()->SetLabelSize(0.12);
536 g1.GetYaxis()->SetLabelSize(0.1);
537 g1.GetYaxis()->SetTitle("HUMITIDY");
538 g1.GetYaxis()->SetTitleOffset(0.2);
539 g1.GetYaxis()->SetTitleSize(0.1);
540 g1.DrawClone("AP");
541
542 g2.SetMarkerColor(kAzure+1);
543 g2.SetMarkerStyle(marker_style);
544 g2.DrawClone("P");
545
546 g3.SetMarkerColor(kAzure+3);
547 g3.SetMarkerStyle(marker_style);
548 g3.DrawClone("P");
549
550 g4.SetMarkerColor(kAzure+6);
551 g4.SetMarkerStyle(marker_style);
552 g4.DrawClone("P");
553
554 //g5.SetMarkerColor(kAzure+1);
555 //g5.SetMarkerStyle(kFullDotMedium);
556 //g5.DrawClone("P");
557
558 g1.DrawClone("P");
559
560 TLine l1(first_time-600, 40, last_time+600, 40);
561 l1.SetLineColor(kOrange);
562 l1.DrawClone();
563 TText t1(first_time-600, 41, "Please, note in logbook");
564 t1.SetTextSize(0.1);
565 t1.DrawClone();
566
567
568 TLine l2(first_time-600, 55, last_time+600, 55);
569 l2.SetLineColor(kRed);
570 l2.DrawClone();
571 TText t2(first_time-600, 56, "Please, report to fact-online");
572 t2.SetTextSize(0.1);
573 t2.DrawClone();
574
575
576 return 0;
577}
578
579Int_t PlotHumidity2(TArrayD **vec, TString fname)
580{
581 fname += ".PFMINI_CONTROL_DATA.fits";
582
583 fits file(fname.Data());
584 if (!file)
585 {
586 cerr << fname << ": " << gSystem->GetError() << endl;
587 return -2;
588 }
589
590 //cout << fname << endl;
591
592 Double_t time;
593 Float_t H;
594
595 if (!file.SetPtrAddress("Time", &time))
596 return -1;
597 if (!file.SetPtrAddress("Humidity", &H))
598 return -1;
599
600 const int marker_style = kFullDotMedium;
601 //const int marker_style = kDot;
602
603 TGraph g1;
604 g1.SetName("PFmini");
605
606
607 while (file.GetNextRow())
608 if (Contains(vec, time))
609 {
610 g1.SetPoint(g1.GetN(), time*24*3600, H);
611 }
612
613 g1.SetMarkerStyle(marker_style);
614 g1.SetMarkerColor(kGreen);
615 g1.DrawClone("P");
616 return 0;
617}
618
619Int_t PlotPointing(TArrayD **vec, TString fname)
620{
621 fname += ".DRIVE_CONTROL_POINTING_POSITION.fits";
622
623 fits file(fname.Data());
624 if (!file)
625 {
626 cerr << fname << ": " << gSystem->GetError() << endl;
627 return -2;
628 }
629
630 //cout << fname << endl;
631
632 Double_t time;
633 Double_t zd;
634
635 if (!file.SetPtrAddress("Time", &time))
636 return -1;
637 if (!file.SetPtrAddress("Zd", &zd))
638 return -1;
639
640 TGraph g;
641 g.SetName("Zd");
642
643 while (file.GetNextRow())
644 if (Contains(vec, time))
645 g.SetPoint(g.GetN(), time*24*3600, 90-zd);
646
647 g.SetMinimum(1);
648 g.SetMaximum(90);
649 g.SetMarkerStyle(kFullDotMedium);
650 g.GetXaxis()->SetTimeDisplay(true);
651 g.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
652 g.GetXaxis()->SetLabelSize(0.12);
653 g.GetYaxis()->SetLabelSize(0.1);
654 g.GetYaxis()->SetTitle("ELEVATION");
655 g.GetYaxis()->SetTitleOffset(0.2);
656 g.GetYaxis()->SetTitleSize(0.1);
657 g.DrawClone("AP");
658
659 return 0;
660}
661
662Int_t PlotTemperature1(TArrayD **vec, TString fname)
663{
664 fname += ".TEMPERATURE_DATA.fits";
665
666 fits file(fname.Data());
667 if (!file)
668 {
669 cerr << fname << ": " << gSystem->GetError() << endl;
670 return -2;
671 }
672
673 //cout << fname << endl;
674
675 Double_t time;
676 Float_t temp;
677
678 if (!file.SetPtrAddress("Time", &time))
679 return -1;
680 if (!file.SetPtrAddress("T", &temp))
681 return -1;
682
683 TGraph g;
684 g.SetName("ContainerTemp");
685
686 while (file.GetNextRow())
687 if (Contains(vec, time))
688 g.SetPoint(g.GetN(), time*24*3600, temp);
689
690 g.SetMinimum(-5);
691 g.SetMaximum(49);
692 g.SetMarkerStyle(kFullDotMedium);
693 g.SetMarkerColor(kRed);
694 g.GetXaxis()->SetTimeDisplay(true);
695 g.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
696 g.GetXaxis()->SetLabelSize(0.1);
697 g.GetYaxis()->SetLabelSize(0.1);
698 g.GetYaxis()->SetTitle("TEMPERATURE");
699 g.GetYaxis()->SetTitleOffset(0.2);
700 g.GetYaxis()->SetTitleSize(0.1);
701 g.DrawClone("AP");
702
703 return 0;
704}
705
706Int_t PlotTemperature2(TArrayD **vec, TString fname)
707{
708 fname += ".MAGIC_WEATHER_DATA.fits";
709
710 fits file(fname.Data());
711 if (!file)
712 {
713 cerr << fname << ": " << gSystem->GetError() << endl;
714 return -2;
715 }
716
717 //cout << fname << endl;
718
719 Double_t time;
720 Float_t temp;
721
722 if (!file.SetPtrAddress("Time", &time))
723 return -1;
724 if (!file.SetPtrAddress("T", &temp))
725 return -1;
726
727 TGraph g;
728 g.SetName("OutsideTemp");
729
730 while (file.GetNextRow())
731 if (Contains(vec, time))
732 g.SetPoint(g.GetN(), time*24*3600, temp);
733
734 g.SetMarkerStyle(kFullDotMedium);
735 g.SetMarkerColor(kBlue);
736 g.DrawClone("P");
737
738 return 0;
739}
740
741Int_t PlotTemperature3(TArrayD **vec, TString fname)
742{
743 fname += ".FSC_CONTROL_TEMPERATURE.fits";
744
745 fits file(fname.Data());
746 if (!file)
747 {
748 cerr << fname << ": " << gSystem->GetError() << endl;
749 return -2;
750 }
751
752 //cout << fname << endl;
753
754 Double_t time;
755 Float_t temp[31];
756
757 if (!file.SetPtrAddress("Time", &time))
758 return -1;
759 if (!file.SetPtrAddress("T_sens", temp))
760 return -1;
761
762 TGraph g, g1, g2;
763 g.SetName("SensorTempAvg");
764 g1.SetName("SensorTempMin");
765 g2.SetName("SensorTempMax");
766
767 while (file.GetNextRow())
768 if (Contains(vec, time))
769 {
770 float min = 100;
771 float max = -100;
772 double avg = 0;
773 int num = 0;
774 for (int i=0; i<31; i++)
775 if (temp[i]!=0)
776 {
777 avg += temp[i];
778 num++;
779
780 min = TMath::Min(min, temp[i]);
781 max = TMath::Max(max, temp[i]);
782 }
783
784 g.SetPoint(g.GetN(), time*24*3600, avg/num);
785 g1.SetPoint(g1.GetN(), time*24*3600, min);
786 g2.SetPoint(g2.GetN(), time*24*3600, max);
787 }
788
789 g.SetMarkerStyle(kFullDotMedium);
790 g.DrawClone("P");
791
792 /*
793 g1.SetLineWidth(1);
794 g1.DrawClone("L");
795
796 g2.SetLineWidth(1);
797 g2.DrawClone("L");
798 */
799 return 0;
800}
801
802Int_t PlotTemperature4(TArrayD **vec, TString fname)
803{
804 fname += ".FAD_CONTROL_TEMPERATURE.fits";
805
806 fits file(fname.Data());
807 if (!file)
808 {
809 cerr << fname << ": " << gSystem->GetError() << endl;
810 return -2;
811 }
812
813 //cout << fname << endl;
814
815 Double_t time;
816 Float_t temp[160];
817
818 if (!file.SetPtrAddress("Time", &time))
819 return -1;
820// if (!file.SetPtrAddress("Data1", temp) &&
821// !file.SetPtrAddress("temp", temp))
822 if (!file.SetPtrAddress("temp", temp))
823 return -1;
824
825 Int_t num = file.GetN("temp")==0 ? file.GetN("Data1") : file.GetN("temp");
826 Int_t beg = num==82 ? 2 : 0;
827
828 TGraphErrors g1;
829 TGraph g2,g3;
830
831 g1.SetName("FadTempAvg");
832 g2.SetName("FadTempMin");
833 g3.SetName("FadTempMax");
834
835 while (file.GetNextRow())
836 if (Contains(vec, time))
837 {
838 double avg = 0;
839 double rms = 0;
840 float min = 100;
841 float max = -100;
842 for (int i=beg; i<num; i++)
843 {
844 avg += temp[i];
845 rms += temp[i]*temp[i];
846
847 min = TMath::Min(min, temp[i]);
848 max = TMath::Max(max, temp[i]);
849 }
850
851 avg /= num-beg;
852 rms /= num-beg;
853
854 g1.SetPoint(g1.GetN(), time*24*3600, avg);
855 g1.SetPointError(g1.GetN()-1, 0, sqrt(rms-avg*avg));
856
857 g2.SetPoint(g2.GetN(), time*24*3600, min);
858 g3.SetPoint(g3.GetN(), time*24*3600, max);
859 }
860
861 g1.SetLineColor(kGreen);
862 g1.DrawClone("[]");
863
864 g2.SetLineColor(kGreen);
865 g2.SetLineWidth(1);
866 g2.DrawClone("L");
867
868 g3.SetLineColor(kGreen);
869 g3.SetLineWidth(1);
870 g3.DrawClone("L");
871
872 return 0;
873}
874
875int quality(UInt_t y=0, UInt_t m=0, UInt_t d=0, const char *outpath="quality")
876{
877 // To get correct dates in the histogram you have to add
878 // the MJDREF offset (should be 40587) and 9131.
879
880 if (y==0)
881 {
882 UInt_t nt = MTime(MTime(-1).GetMjd()-1.5).GetNightAsInt();
883 y = nt/10000;
884 m = (nt/100)%100;
885 d = nt%100;
886
887 cout << y << "/" << m << "/" << d << endl;
888 }
889
890 TString fname=Form("/fact/aux/%04d/%02d/%02d/%04d%02d%02d", y, m, d, y, m, d);
891
892 UInt_t night = MTime(y, m, d, 0).GetNightAsInt();
893
894 MSQLMagic serv("sql.rc");
895 Bool_t con = serv.IsConnected();
896
897 cout << "quality" << endl;
898 cout << "-------" << endl;
899 cout << endl;
900 if (con)
901 {
902 cout << "Connected to " << serv.GetName() << endl;
903 cout << endl;
904 }
905 cout << "Night: " << Form("%04d-%02d-%02d", y, m, d) << endl;
906 cout << endl;
907
908 TArrayD run, beg, end;
909
910 TArrayD *runs[3] = { &run, &beg, &end };
911
912 if (con)
913 {
914 TString query;
915 query += "SELECT fRunID, fRunStart, fRunStop FROM RunInfo";
916 query += " WHERE fNight=";
917 query += night;
918 query += " AND fRunTypeKey=1 ORDER BY fRunStart";
919
920 TSQLResult *res = serv.Query(query);
921 if (!res)
922 return 1;
923
924 run.Set(res->GetRowCount());
925 beg.Set(res->GetRowCount());
926 end.Set(res->GetRowCount());
927
928 Int_t n = 0;
929
930 TSQLRow *row = 0;
931 while ((row=res->Next()))
932 {
933 run[n] = atoi((*row)[0]);
934 beg[n] = MTime((*row)[1]).GetMjd()-40587;
935 end[n] = MTime((*row)[2]).GetMjd()-40587;
936 n++;
937 delete row;
938 }
939
940 delete res;
941
942 if (n==0)
943 cout << "WARNING - No data runs in db, displaying all data." << endl;
944 else
945 cout << "Num: " << n << "\n" << endl;
946 }
947
948 //check if the sqm was already installed on the telescope
949 TCanvas *c = NULL;
950 TString datestring = Form("%04d%02d%02d", y, m, d);
951 if (datestring.Atoi() > 20140723)
952 {
953 c = new TCanvas("quality", Form("Quality %04d/%02d/%02d", y, m, d), 1280, 1280);
954 c->Divide(1, 8, 1e-5, 1e-5);
955 }
956 else
957 {
958 c = new TCanvas("quality", Form("Quality %04d/%02d/%02d", y, m, d), 1280, 1120);
959 c->Divide(1, 7, 1e-5, 1e-5);
960 }
961
962 gROOT->SetSelectedPad(0);
963
964 c->cd(1);
965 gPad->SetGrid();
966 gPad->SetTopMargin(0);
967 gPad->SetRightMargin(0.001);
968 gPad->SetLeftMargin(0.04);
969 gPad->SetBottomMargin(0);
970 cout << PlotThresholds(runs, fname) << endl;
971
972 gROOT->SetSelectedPad(0);
973 c->cd(2);
974 gPad->SetGrid();
975 gPad->SetTopMargin(0);
976 gPad->SetRightMargin(0.001);
977 gPad->SetLeftMargin(0.04);
978 gPad->SetBottomMargin(0);
979 cout << PlotCurrent(runs, fname) << endl;
980
981 gROOT->SetSelectedPad(0);
982 c->cd(3);
983 gPad->SetGrid();
984 gPad->SetTopMargin(0);
985 gPad->SetBottomMargin(0);
986 gPad->SetRightMargin(0.001);
987 gPad->SetLeftMargin(0.04);
988 cout << PlotRate(runs, fname) << endl;
989 PlotRateQC(night, serv);
990
991 gROOT->SetSelectedPad(0);
992 c->cd(5);
993 gPad->SetGrid();
994 gPad->SetTopMargin(0);
995 gPad->SetBottomMargin(0);
996 gPad->SetRightMargin(0.001);
997 gPad->SetLeftMargin(0.04);
998 cout << PlotPointing(runs, fname) << endl;
999
1000 gROOT->SetSelectedPad(0);
1001 c->cd(6);
1002 gPad->SetGrid();
1003 gPad->SetTopMargin(0);
1004 gPad->SetRightMargin(0.001);
1005 gPad->SetLeftMargin(0.04);
1006 gPad->SetBottomMargin(0);
1007 cout << PlotTemperature1(runs, fname) << endl;
1008 cout << PlotTemperature2(runs, fname) << endl;
1009 cout << PlotTemperature3(runs, fname) << endl;
1010 cout << PlotTemperature4(runs, fname) << endl;
1011
1012 gROOT->SetSelectedPad(0);
1013 c->cd(7);
1014 gPad->SetGrid();
1015 gPad->SetTopMargin(0);
1016 gPad->SetBottomMargin(0);
1017 gPad->SetRightMargin(0.001);
1018 gPad->SetLeftMargin(0.04);
1019 cout << PlotHumidity(runs, fname) << endl;
1020 cout << PlotHumidity2(runs, fname) << endl;
1021
1022 //check if the sqm was already installed
1023 if( datestring.Atoi() > 20140723 ) {
1024 gROOT->SetSelectedPad(0);
1025 c->cd(7);
1026 gPad->SetGrid();
1027 gPad->SetTopMargin(0);
1028 gPad->SetBottomMargin(0);
1029 gPad->SetRightMargin(0.001);
1030 gPad->SetLeftMargin(0.04);
1031 cout << PlotHumidity(runs, fname) << endl;
1032 cout << PlotHumidity2(runs, fname) << endl;
1033
1034 gROOT->SetSelectedPad(0);
1035 c->cd(8);
1036 gPad->SetGrid();
1037 gPad->SetTopMargin(0);
1038 gPad->SetRightMargin(0.001);
1039 gPad->SetLeftMargin(0.04);
1040 cout << PlotSqm(runs, fname) << endl;
1041 }else{
1042
1043 gROOT->SetSelectedPad(0);
1044 c->cd(7);
1045 gPad->SetGrid();
1046 gPad->SetTopMargin(0);
1047 gPad->SetRightMargin(0.001);
1048 gPad->SetLeftMargin(0.04);
1049 cout << PlotHumidity(runs, fname) << endl;
1050 cout << PlotHumidity2(runs, fname) << endl;
1051 }
1052
1053 c->SaveAs(Form("%s/%04d%02d%02d.png", outpath, y, m, d));
1054
1055 return 0;
1056}
Note: See TracBrowser for help on using the repository browser.