1 | /* ======================================================================== *\
|
---|
2 | ! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.50 2008-07-20 17:33:22 tbretz Exp $
|
---|
3 | ! --------------------------------------------------------------------------
|
---|
4 | !
|
---|
5 | ! *
|
---|
6 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
7 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
8 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
9 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
10 | ! *
|
---|
11 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
12 | ! * documentation for any purpose is hereby granted without fee,
|
---|
13 | ! * provided that the above copyright notice appear in all copies and
|
---|
14 | ! * that both that copyright notice and this permission notice appear
|
---|
15 | ! * in supporting documentation. It is provided "as is" without express
|
---|
16 | ! * or implied warranty.
|
---|
17 | ! *
|
---|
18 | !
|
---|
19 | !
|
---|
20 | ! Author(s): Thomas Bretz, 05/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
21 | ! Author(s): Daniela Dorner, 05/2005 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
22 | !
|
---|
23 | ! Copyright: MAGIC Software Development, 2000-2008
|
---|
24 | !
|
---|
25 | !
|
---|
26 | \* ======================================================================== */
|
---|
27 |
|
---|
28 | /////////////////////////////////////////////////////////////////////////////
|
---|
29 | //
|
---|
30 | // plotdb.C
|
---|
31 | // ========
|
---|
32 | //
|
---|
33 | // This macro is used to read quality parameters from the DB and plot them.
|
---|
34 | //
|
---|
35 | // The parameters are from the following files:
|
---|
36 | // calib*.root:mean conversion factor, mean arrival time, rms arrival time
|
---|
37 | // (each parameter for inner and outer camera)
|
---|
38 | // signal*.root: mean pedestal rms (for inner and outer camera)
|
---|
39 | // star*.root: PSF, # of Muons, Effective OnTime, Muon rate,
|
---|
40 | // Ratio MC/Data(MuonSize) and mean number of islands
|
---|
41 | //
|
---|
42 | // In the DB these values are stored in the tables Calibration and Star.
|
---|
43 | //
|
---|
44 | // Usage:
|
---|
45 | // .x plotdb.C --> all values in the DB are plotted
|
---|
46 | // You can chose are certain period:
|
---|
47 | // .x plotdb.C(25) --> all values from period 25 are plotted
|
---|
48 | // or a time period from a certain date to a certain date
|
---|
49 | // .x plotdb.C("2004-11-14 00:00:00", "2005-02-28 00:00:00")
|
---|
50 | // --> all values from 14.11.2004 0h to 28.2.2005 0h are plotted
|
---|
51 | // or all data, but with dataset data highlighted
|
---|
52 | // .x plotdb.C("dataset.txt")
|
---|
53 | // --> the sequences defined in dataset.txt are highlighted (blue:on, red:off)
|
---|
54 | // --> You can also add a dataset-name as last argument to one of the
|
---|
55 | // calls above
|
---|
56 | //
|
---|
57 | // Make sure, that database and password are corretly set in a resource
|
---|
58 | // file called sql.rc and the resource file is found.
|
---|
59 | //
|
---|
60 | /////////////////////////////////////////////////////////////////////////////
|
---|
61 | #include <iostream>
|
---|
62 | #include <iomanip>
|
---|
63 |
|
---|
64 | #include <TH1.h>
|
---|
65 | #include <TPad.h>
|
---|
66 | #include <TLine.h>
|
---|
67 | #include <TText.h>
|
---|
68 | #include <TFrame.h>
|
---|
69 | #include <TStyle.h>
|
---|
70 | #include <TCanvas.h>
|
---|
71 | #include <TPRegexp.h>
|
---|
72 | #include <TSQLRow.h>
|
---|
73 | #include <TSQLResult.h>
|
---|
74 | #include <TGraphErrors.h>
|
---|
75 |
|
---|
76 | #include "MTime.h"
|
---|
77 | #include "MAstro.h"
|
---|
78 | #include "MDataSet.h"
|
---|
79 | #include "MSQLMagic.h"
|
---|
80 | #include "MStatusDisplay.h"
|
---|
81 |
|
---|
82 | class MPlot : public MParContainer
|
---|
83 | {
|
---|
84 | public:
|
---|
85 | // Possible constants to group-by (average) over a certain period
|
---|
86 | enum GroupBy_t
|
---|
87 | {
|
---|
88 | kNone,
|
---|
89 | kGroupByPrimary,
|
---|
90 | kGroupByHour,
|
---|
91 | kGroupByDay,
|
---|
92 | kGroupByNight,
|
---|
93 | kGroupByWeek,
|
---|
94 | kGroupByMonth,
|
---|
95 | kGroupBySeason,
|
---|
96 | kGroupByYear
|
---|
97 | };
|
---|
98 |
|
---|
99 | private:
|
---|
100 | MSQLMagic &fServer; // Reference to the sql-server class
|
---|
101 |
|
---|
102 | MDataSet *fDataSet; // A possible dtaset to highlite single points
|
---|
103 |
|
---|
104 | TString fPrimaryDate; // The name of the data we plot
|
---|
105 | TString fPrimaryNumber; // The corresponding name for the key number
|
---|
106 | TString fSecondary; // The value versus which the second plot is made
|
---|
107 |
|
---|
108 | TString fRequestFrom; // Start of a requested date range
|
---|
109 | TString fRequestTo; // End of a requested date range
|
---|
110 | Int_t fRequestPeriod; // A possible requested period
|
---|
111 |
|
---|
112 | Float_t fPlotMin;
|
---|
113 | Float_t fPlotMax;
|
---|
114 |
|
---|
115 | Float_t fHistMin;
|
---|
116 | Float_t fHistMax;
|
---|
117 |
|
---|
118 | TString fDescription; // The description (title) of the plot
|
---|
119 | TString fNameTab; // The name of the tab in the display
|
---|
120 |
|
---|
121 | TString fCondition; // An additional condition added to the query
|
---|
122 | GroupBy_t fGroupBy; // A possible Group-By flag
|
---|
123 |
|
---|
124 | // --------------------------------------------------------------------------
|
---|
125 | //
|
---|
126 | // Function to plot the result of the query
|
---|
127 | //
|
---|
128 | void PlotTable(TSQLResult &res, TString name, Float_t fmin, Float_t fmax, Float_t resolution)
|
---|
129 | {
|
---|
130 | // Enable all otions in the statistics box
|
---|
131 | gStyle->SetOptStat(111111);
|
---|
132 |
|
---|
133 | // Create TGraph objects
|
---|
134 | TGraph > = res.GetFieldCount()>4 ? *new TGraphErrors : *new TGraph;
|
---|
135 | gt.SetNameTitle(Form("%s_time", res.GetFieldName(2)), Form("%s vs %s", res.GetFieldName(2), res.GetFieldName(0)));
|
---|
136 | gt.SetMarkerStyle(kFullDotMedium);
|
---|
137 |
|
---|
138 | TGraph gz;
|
---|
139 | gz.SetNameTitle(res.GetFieldName(2), Form("%s vs %s", res.GetFieldName(2), res.GetFieldName(1)));
|
---|
140 | gz.SetMarkerStyle(kFullDotMedium);
|
---|
141 |
|
---|
142 | TGraph gt0, gt1;
|
---|
143 | gt0.SetMarkerColor(kRed);
|
---|
144 | gt1.SetMarkerColor(kBlue);
|
---|
145 | gt0.SetMarkerStyle(kFullDotLarge);
|
---|
146 | gt1.SetMarkerStyle(kFullDotLarge);
|
---|
147 |
|
---|
148 | TGraph gz0, gz1;
|
---|
149 | gz0.SetMarkerColor(kRed);
|
---|
150 | gz1.SetMarkerColor(kBlue);
|
---|
151 | gz0.SetMarkerStyle(kFullDotLarge);
|
---|
152 | gz1.SetMarkerStyle(kFullDotLarge);
|
---|
153 |
|
---|
154 | Int_t first = -1;
|
---|
155 | Int_t last = -1;
|
---|
156 |
|
---|
157 | // Loop over the data
|
---|
158 | TSQLRow *row = 0;
|
---|
159 | while ((row=res.Next()))
|
---|
160 | {
|
---|
161 | Int_t pos=0;
|
---|
162 | // Get all fields of this row
|
---|
163 | const char *date = (*row)[pos++];
|
---|
164 | const char *zd = (*row)[pos++];
|
---|
165 | const char *val = (*row)[pos++];
|
---|
166 | const char *zderr = fGroupBy!=kNone ? (*row)[pos++] : 0;
|
---|
167 | const char *verr = fGroupBy!=kNone ? (*row)[pos++] : 0;
|
---|
168 | const char *snum = fDataSet ? (*row)[pos++] : 0;
|
---|
169 |
|
---|
170 | delete row;
|
---|
171 |
|
---|
172 | if (!date || !val || !zd)
|
---|
173 | continue;
|
---|
174 |
|
---|
175 | // check if date is valid
|
---|
176 | MTime t(date);
|
---|
177 | if (!t.SetSqlDateTime(date))
|
---|
178 | continue;
|
---|
179 |
|
---|
180 | // check if it belongs to the requested MAGIC period
|
---|
181 | if (fRequestPeriod>0 && MAstro::GetMagicPeriod(t.GetMjd())!=fRequestPeriod)
|
---|
182 | continue;
|
---|
183 |
|
---|
184 | // Get axis range
|
---|
185 | if (first<0)
|
---|
186 | first = TMath::Nint(TMath::Floor(t.GetMjd()));
|
---|
187 | last = TMath::Nint(TMath::Ceil(t.GetMjd()));
|
---|
188 |
|
---|
189 | // Convert a possible key number into a integer
|
---|
190 | UInt_t seq = snum ? atoi(snum) : 0;
|
---|
191 |
|
---|
192 | // convert primary and secondary value into floats
|
---|
193 | Float_t value = atof(val);
|
---|
194 | Float_t zenith = atof(zd);
|
---|
195 |
|
---|
196 | // If a datset is given add the point to the special TGraphs
|
---|
197 | // used for highliting these dates
|
---|
198 | if (fDataSet)
|
---|
199 | {
|
---|
200 | if (fDataSet->HasOnSequence(seq))
|
---|
201 | {
|
---|
202 | gt1.SetPoint(gt1.GetN(), t.GetAxisTime(), value);
|
---|
203 | gz1.SetPoint(gz1.GetN(), zenith, value);
|
---|
204 | }
|
---|
205 |
|
---|
206 | if (fDataSet->HasOffSequence(seq))
|
---|
207 | {
|
---|
208 | gt0.SetPoint(gt0.GetN(), t.GetAxisTime(), value);
|
---|
209 | gz0.SetPoint(gz0.GetN(), zenith, value);
|
---|
210 | }
|
---|
211 | }
|
---|
212 |
|
---|
213 | // Add Data to TGraph
|
---|
214 | gt.SetPoint(gt.GetN(), t.GetAxisTime(), value);
|
---|
215 | gz.SetPoint(gz.GetN(), zenith, value);
|
---|
216 |
|
---|
217 | // Set error-bar, if one
|
---|
218 | if (verr)
|
---|
219 | static_cast<TGraphErrors&>(gt).SetPointError(gt.GetN()-1, 0, atof(verr));
|
---|
220 | }
|
---|
221 |
|
---|
222 | // If this is done earlier the plots remain empty since root 5.12/00
|
---|
223 | if (fmax>fmin)
|
---|
224 | {
|
---|
225 | gt.SetMinimum(fmin);
|
---|
226 | gt.SetMaximum(fmax);
|
---|
227 | gz.SetMinimum(fmin);
|
---|
228 | gz.SetMaximum(fmax);
|
---|
229 | }
|
---|
230 |
|
---|
231 | gROOT->SetSelectedPad(0);
|
---|
232 |
|
---|
233 | TString cname = fNameTab.IsNull() ? name(name.First('.')+2, name.Length()) : fNameTab;
|
---|
234 | TString ctitle = fDescription.IsNull() ? name.Data() : fDescription.Data();
|
---|
235 | if (ctitle.First(';')>0)
|
---|
236 | ctitle.Remove(ctitle.First(';'), ctitle.Length());
|
---|
237 |
|
---|
238 | // Create a TCanvas or open a new tab
|
---|
239 | TCanvas &c = fDisplay ? fDisplay->AddTab(cname, ctitle) : *new TCanvas(cname, ctitle);
|
---|
240 | // Set fillcolor, remove border and divide pad
|
---|
241 | c.SetFillColor(kWhite);
|
---|
242 | c.SetFrameBorderMode(0);
|
---|
243 | c.SetBorderMode(0);
|
---|
244 | c.Divide(1,2);
|
---|
245 |
|
---|
246 | // Output mean and rms to console
|
---|
247 | cerr << setprecision(4) << setw(10) << cname << ": ";
|
---|
248 | if (gt.GetN()==0)
|
---|
249 | {
|
---|
250 | cerr << " <empty>" << endl;
|
---|
251 | return;
|
---|
252 | }
|
---|
253 | cerr << setw(8) << gt.GetMean(2) << "+-" << setw(8) << gt.GetRMS(2) << " ";
|
---|
254 | if (gt0.GetN()>0 || gt1.GetN()>0)
|
---|
255 | {
|
---|
256 | cerr << setw(8) << gt1.GetMean(2) << "+-" << setw(8) << gt1.GetRMS(2) << " ";
|
---|
257 | cerr << setw(8) << gt0.GetMean(2) << "+-" << setw(8) << gt0.GetRMS(2);
|
---|
258 | }
|
---|
259 | cerr << endl;
|
---|
260 |
|
---|
261 | // format axis
|
---|
262 | TH1 *h = gt.GetHistogram();
|
---|
263 |
|
---|
264 | const Double_t min = fHistMin>fHistMax ? h->GetMinimum()-resolution/2 : fHistMin;
|
---|
265 | const Double_t max = fHistMin>fHistMax ? h->GetMaximum()+resolution/2 : fHistMax;
|
---|
266 |
|
---|
267 | // Create histogram
|
---|
268 | const Int_t n = resolution>0 ? TMath::Nint((max-min)/resolution) : 50;
|
---|
269 |
|
---|
270 | TH1F hist("Hist", Form("Distribution of %s", fDescription.IsNull() ? name.Data() : fDescription.Data()), n, min, max);
|
---|
271 | hist.SetDirectory(0);
|
---|
272 |
|
---|
273 | // Fill data into histogra,
|
---|
274 | for (int i=0; i<gt.GetN(); i++)
|
---|
275 | hist.Fill(gt.GetY()[i]);
|
---|
276 |
|
---|
277 | // Format histogram
|
---|
278 | if (fDescription.IsNull())
|
---|
279 | hist.SetXTitle(name);
|
---|
280 | hist.SetYTitle("Counts");
|
---|
281 |
|
---|
282 | TVirtualPad *pad = gPad;
|
---|
283 |
|
---|
284 | // draw contants of pad 2 (counting starts at 0)
|
---|
285 | pad->cd(2);
|
---|
286 | gPad->SetBorderMode(0);
|
---|
287 | gPad->SetFrameBorderMode(0);
|
---|
288 | gPad->SetGridy();
|
---|
289 |
|
---|
290 | gPad->SetLeftMargin(0.06);
|
---|
291 | gPad->SetRightMargin(0.06);
|
---|
292 | gPad->SetBottomMargin(0.08);
|
---|
293 |
|
---|
294 | h->SetXTitle("Time");
|
---|
295 | h->SetYTitle(hist.GetXaxis()->GetTitle());
|
---|
296 | h->GetXaxis()->SetTimeDisplay(1);
|
---|
297 | h->GetYaxis()->SetTitleOffset(0.8);
|
---|
298 | h->GetXaxis()->SetTitleOffset(1.0);
|
---|
299 | h->GetXaxis()->SetLabelOffset(0.01);
|
---|
300 |
|
---|
301 | // draw TGraph
|
---|
302 | gROOT->SetSelectedPad(0);
|
---|
303 | gt.DrawClone("AP");
|
---|
304 | if (gt0.GetN()>0)
|
---|
305 | gt0.DrawClone("P");
|
---|
306 | if (gt1.GetN()>0)
|
---|
307 | gt1.DrawClone("P");
|
---|
308 |
|
---|
309 | // Add lines and text showing the MAGIC periods
|
---|
310 | TLine l;
|
---|
311 | TText t;
|
---|
312 | Int_t num=0;
|
---|
313 | l.SetLineStyle(kDotted);
|
---|
314 | l.SetLineColor(kBlue);
|
---|
315 | t.SetTextColor(kBlue);
|
---|
316 | l.SetLineWidth(1);
|
---|
317 | t.SetTextSize(h->GetXaxis()->GetLabelSize());
|
---|
318 | t.SetTextAlign(21);
|
---|
319 | Int_t p0 = MAstro::GetMagicPeriod(first);
|
---|
320 | for (Int_t p = first; p<last; p++)
|
---|
321 | {
|
---|
322 | Int_t p1 = MAstro::GetMagicPeriod(p);
|
---|
323 | if (p1!=p0)
|
---|
324 | {
|
---|
325 | l.DrawLine(MTime(p).GetAxisTime(), h->GetMinimum(), MTime(p).GetAxisTime(), h->GetMaximum());
|
---|
326 | t.DrawText(MTime(p+15).GetAxisTime(), h->GetMaximum(), Form("%d", p1));
|
---|
327 | num++;
|
---|
328 | }
|
---|
329 | p0 = p1;
|
---|
330 | }
|
---|
331 | if (num<4)
|
---|
332 | gPad->SetGridx();
|
---|
333 |
|
---|
334 | // Go back to first (upper) pad, format it and divide it again
|
---|
335 | pad->cd(1);
|
---|
336 | gPad->SetBorderMode(0);
|
---|
337 | gPad->SetFrameBorderMode(0);
|
---|
338 | gPad->Divide(2,1);
|
---|
339 |
|
---|
340 | TVirtualPad *pad2 = gPad;
|
---|
341 |
|
---|
342 | // format left pad
|
---|
343 | pad2->cd(1);
|
---|
344 | gPad->SetBorderMode(0);
|
---|
345 | gPad->SetFrameBorderMode(0);
|
---|
346 | gPad->SetGridx();
|
---|
347 | gPad->SetGridy();
|
---|
348 |
|
---|
349 | // plot histogram
|
---|
350 | hist.DrawCopy("");
|
---|
351 |
|
---|
352 | // format right pad
|
---|
353 | pad2->cd(2);
|
---|
354 | gPad->SetBorderMode(0);
|
---|
355 | gPad->SetFrameBorderMode(0);
|
---|
356 | gPad->SetGridy();
|
---|
357 |
|
---|
358 | // draw graph
|
---|
359 | gROOT->SetSelectedPad(0);
|
---|
360 | gz.GetXaxis()->SetTitle(res.GetFieldName(1));
|
---|
361 | gz.GetYaxis()->SetTitle(hist.GetXaxis()->GetTitle());
|
---|
362 | gz.DrawClone("AP");
|
---|
363 |
|
---|
364 | if (gz0.GetN()>0)
|
---|
365 | gz0.DrawClone("P");
|
---|
366 | if (gz1.GetN()>0)
|
---|
367 | gz1.DrawClone("P");
|
---|
368 | }
|
---|
369 |
|
---|
370 | public:
|
---|
371 | MPlot(MSQLMagic &server) : fServer(server), fDataSet(NULL),
|
---|
372 | fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1), fGroupBy(kNone)
|
---|
373 | {
|
---|
374 | }
|
---|
375 | ~MPlot()
|
---|
376 | {
|
---|
377 | if (fDataSet)
|
---|
378 | delete fDataSet;
|
---|
379 | }
|
---|
380 | void SetDataSet(const TString filename)
|
---|
381 | {
|
---|
382 | if (fDataSet)
|
---|
383 | {
|
---|
384 | delete fDataSet;
|
---|
385 | fDataSet = NULL;
|
---|
386 | }
|
---|
387 |
|
---|
388 | fPrimaryNumber="";
|
---|
389 |
|
---|
390 | if (filename.IsNull())
|
---|
391 | return;
|
---|
392 |
|
---|
393 | fDataSet = new MDataSet(filename);
|
---|
394 | fPrimaryNumber="Sequences.fSequenceFirst";
|
---|
395 | }
|
---|
396 | void SetPlotRange(Float_t min, Float_t max/*, Int_t n=5*/) { fPlotMin = min; fPlotMax = max; }
|
---|
397 | void SetHistRange(Float_t min, Float_t max) { fHistMin = min; fHistMax = max; }
|
---|
398 | void SetRequestRange(const char *from="", const char *to="") { fRequestFrom = from; fRequestTo = to; }
|
---|
399 | void SetRequestPeriod(Int_t n=-1) { fRequestPeriod = n; }
|
---|
400 | void SetCondition(const char *cond="") { fCondition = cond; }
|
---|
401 | void SetDescription(const char *d, const char *t=0) { fDescription = d; fNameTab = t; }
|
---|
402 | void SetTabName(const char *t) { fNameTab = t; }
|
---|
403 | void SetGroupBy(GroupBy_t b=kGroupByWeek) { fGroupBy=b; }
|
---|
404 | void SetPrimaryDate(const char *ts) { fPrimaryDate=ts; }
|
---|
405 | void SetPrimaryNumber(const char *ts) { }
|
---|
406 | void SetSecondary(const char *ts) { fSecondary=ts; }
|
---|
407 |
|
---|
408 | MStatusDisplay *GetDisplay() { return fDisplay; }
|
---|
409 | MSQLMagic &GetServer() { return fServer; }
|
---|
410 |
|
---|
411 | Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0)
|
---|
412 | {
|
---|
413 | TString named = fPrimaryDate;
|
---|
414 | TString named2 = fSecondary;
|
---|
415 | TString namev = value;
|
---|
416 |
|
---|
417 | TString tablev = namev(0, namev.First('.'));
|
---|
418 | TString valuev = namev(namev.First('.')+1, namev.Length());
|
---|
419 |
|
---|
420 | TString tabled = named(0, named.First('.'));
|
---|
421 | TString valued = named(named.First('.')+1, named.Length());
|
---|
422 |
|
---|
423 | TString query="SELECT ";
|
---|
424 | switch (fGroupBy)
|
---|
425 | {
|
---|
426 | case kNone:
|
---|
427 | case kGroupByPrimary:
|
---|
428 | query += Form("%s AS %s", valued.Data(), valued.Data()+1);
|
---|
429 | break;
|
---|
430 | case kGroupByHour:
|
---|
431 | query += Form("DATE_FORMAT(%s, '%%Y-%%m-%%d %%H:30:00') AS %s ", fPrimaryDate.Data(), valued.Data()+1);
|
---|
432 | break;
|
---|
433 | case kGroupByNight:
|
---|
434 | query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()+1);
|
---|
435 | break;
|
---|
436 | case kGroupByDay:
|
---|
437 | query += Form("DATE_FORMAT(%s, '%%Y-%%m-%%d 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()+1);
|
---|
438 | break;
|
---|
439 | case kGroupByWeek:
|
---|
440 | query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", fPrimaryDate.Data(), valued.Data()+1);
|
---|
441 | break;
|
---|
442 | case kGroupByMonth:
|
---|
443 | query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()+1);
|
---|
444 | break;
|
---|
445 | case kGroupBySeason:
|
---|
446 | //query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()+1);
|
---|
447 | break;
|
---|
448 | case kGroupByYear:
|
---|
449 | query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-08-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()+1);
|
---|
450 | break;
|
---|
451 | }
|
---|
452 |
|
---|
453 | if (fGroupBy==kNone)
|
---|
454 | {
|
---|
455 | query += ", ";
|
---|
456 | query += fSecondary;
|
---|
457 | query += ", ";
|
---|
458 | query += value;
|
---|
459 | }
|
---|
460 | else
|
---|
461 | {
|
---|
462 | TString v(value);
|
---|
463 | TPRegexp regexp(" +[aA][sS] +[a-zA-Z0-9]+ *$");
|
---|
464 |
|
---|
465 | TString as = v(regexp);
|
---|
466 | Ssiz_t p = v.Index(as);
|
---|
467 |
|
---|
468 | v.Prepend("(");
|
---|
469 | v.Insert(p<=0?v.Length():p+1, ")");
|
---|
470 |
|
---|
471 | query += ", AVG";
|
---|
472 | query += v;
|
---|
473 | query += ", AVG(";
|
---|
474 | query += fSecondary;
|
---|
475 | query += "), STD";
|
---|
476 | query += v;
|
---|
477 | query += ", STD(";
|
---|
478 | query += fSecondary;
|
---|
479 | query += ")";
|
---|
480 | }
|
---|
481 |
|
---|
482 | if (fDataSet)
|
---|
483 | {
|
---|
484 | query += ", ";
|
---|
485 | query += fPrimaryNumber;
|
---|
486 | }
|
---|
487 |
|
---|
488 | query += Form(" FROM %s ", tabled.Data());
|
---|
489 |
|
---|
490 | const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull();
|
---|
491 |
|
---|
492 | TString where(fCondition);
|
---|
493 | if (interval)
|
---|
494 | {
|
---|
495 | if (!where.IsNull())
|
---|
496 | where += " AND ";
|
---|
497 | where += Form("%s BETWEEN '%s' AND '%s' ",
|
---|
498 | fPrimaryDate.Data(), fRequestFrom.Data(), fRequestTo.Data());
|
---|
499 | }
|
---|
500 |
|
---|
501 | // ------------------------------
|
---|
502 |
|
---|
503 | query += fServer.GetJoins(tabled, query+" "+where);
|
---|
504 |
|
---|
505 | if (!where.IsNull())
|
---|
506 | {
|
---|
507 | query += "WHERE ";
|
---|
508 | query += where;
|
---|
509 | query += " ";
|
---|
510 | }
|
---|
511 |
|
---|
512 | if (fGroupBy!=kNone)
|
---|
513 | {
|
---|
514 | query += Form("GROUP BY %s ", valued.Data()+1);
|
---|
515 | //query += Form(" HAVING COUNT(%s)=(COUNT(*)+1)/2 ", valuev.Data());
|
---|
516 | }
|
---|
517 | query += Form("ORDER BY %s ", valued.Data()+1);
|
---|
518 |
|
---|
519 | // ------------------------------
|
---|
520 |
|
---|
521 | TSQLResult *res = fServer.Query(query);
|
---|
522 | if (!res)
|
---|
523 | {
|
---|
524 | cout << "ERROR - Query failed: " << query << endl;
|
---|
525 | return kFALSE;
|
---|
526 | }
|
---|
527 |
|
---|
528 | if (max>min)
|
---|
529 | PlotTable(*res, namev, min, max, resolution);
|
---|
530 | else
|
---|
531 | PlotTable(*res, namev, fPlotMin, fPlotMax, resolution);
|
---|
532 |
|
---|
533 |
|
---|
534 | delete res;
|
---|
535 | return kTRUE;
|
---|
536 | }
|
---|
537 | // ClassDef(MPlot, 0)
|
---|
538 | };
|
---|
539 |
|
---|
540 | //ClassImp(MPlot);
|
---|
541 |
|
---|
542 | void plotalldb(MPlot &plot)
|
---|
543 | {
|
---|
544 | //plot.SetGroupBy(MPlot::kGroupByNight);
|
---|
545 | //plot.SetDataSet("dataset.txt");
|
---|
546 |
|
---|
547 | plot.SetPrimaryDate("Sequences.fRunStart");
|
---|
548 | plot.SetSecondary("(Sequences.fZenithDistanceMin+Sequences.fZenithDistanceMax)/2 as '<Zd>'");
|
---|
549 |
|
---|
550 | //inner camera
|
---|
551 | //from calib*.root
|
---|
552 | plot.SetDescription("Conversion Factor inner Camera;C_{I} [phe/fadc cnts]", "ConvI");
|
---|
553 | plot.Plot("Calibration.fConvFactorInner", 0, 0.7, 0.002);
|
---|
554 | plot.SetDescription("Mean Arrival Time inner Camera;T_{I} [sl]", "ArrTmI");
|
---|
555 | plot.Plot("Calibration.fArrTimeMeanInner", 0, 40.0, 0.1);
|
---|
556 | plot.SetDescription("RMS Arrival Time inner Camera;\\sigma_{T,I} [sl]", "RmsArrTmI");
|
---|
557 | plot.Plot("Calibration.fArrTimeRmsInner", 0, 4.5, 0.01);
|
---|
558 | plot.SetDescription("Number of unsuitable pixels inner Camera;N_{I}", "UnsuitI");
|
---|
559 | plot.Plot("Calibration.fUnsuitableInner", 0, 75, 1);
|
---|
560 | plot.SetDescription("Number of unsuitable pixels >50%;N", "Unsuit50");
|
---|
561 | plot.Plot("Calibration.fUnsuitable50", 0, 75, 1);
|
---|
562 | plot.SetDescription("Number of unsuitable pixels >1%;N", "Unsuit01");
|
---|
563 | plot.Plot("Calibration.fUnsuitable01", 0, 200, 5);
|
---|
564 |
|
---|
565 | //from signal*.root
|
---|
566 | plot.SetDescription("Mean Pedestal RMS inner Camera;\\sigma_{P,I} [phe]", "PedRmsI");
|
---|
567 | plot.Plot("Calibration.fMeanPedRmsInner", 0, 3.5, 0.05);
|
---|
568 | plot.SetDescription("Mean Signal inner Camera;S_{I} [phe]", "SignalI");
|
---|
569 | plot.Plot("Calibration.fMeanSignalInner", 0, 7.0, 0.05);
|
---|
570 |
|
---|
571 | plot.SetDescription("Mean PulsePosCheck (maximum slice) inner camera;T [sl]", "ChkPos");
|
---|
572 | plot.Plot("Calibration.fPulsePosCheckMean", 1, 50.0, 0.1);
|
---|
573 | plot.SetDescription("Rms PulsePosCheck (maximum slice) inner camera;T [sl]", "ChkRms");
|
---|
574 | plot.Plot("Calibration.fPulsePosCheckRms", 0, 12.0, 0.1);
|
---|
575 | plot.SetDescription("Mean calibrated PulsePos (as extracted);T [ns]", "PulPos");
|
---|
576 | plot.Plot("Calibration.fPulsePosMean", 1, 40.0, 0.1);
|
---|
577 | plot.SetDescription("Rms calibrated PulsePos (as extracted);T [ns]", "PulRms");
|
---|
578 | plot.Plot("Calibration.fPulsePosRms", 0, 3.0, 0.02);
|
---|
579 |
|
---|
580 | plot.SetDescription("Ratio of accepted calibration events in cal-run;f [%]", "RatioCal");
|
---|
581 | plot.Plot("Calibration.fRatioCalEvents", 0, 105, 5);
|
---|
582 |
|
---|
583 | plot.SetDescription("Average rate of events with lvl1 trigger;R [Hz]", "RateTrig");
|
---|
584 | plot.Plot("Calibration.fRateTrigEvts", 0, 500, 5);
|
---|
585 | plot.SetDescription("Average rate of events with only Sum trigger;R [Hz]", "RateSum");
|
---|
586 | plot.Plot("Calibration.fRateSumEvts", 0, 1500, 5);
|
---|
587 | //plot.SetDescription("Ratio of only Sum to Lvl1 triggers;R [Hz]", "RateRatio");
|
---|
588 | //plot.Plot("100*Calibration.fRateSumEvts/Calibration.fRateTrigEvts", 0, 500, 1);
|
---|
589 | plot.SetDescription("Average rate of events with calibration trigger;R [Hz]", "RateCal");
|
---|
590 | plot.Plot("Calibration.fRateCalEvts", 0, 75, 1);
|
---|
591 | plot.SetDescription("Average rate of events with pedestal trigger;R [Hz]", "RatePed");
|
---|
592 | plot.Plot("Calibration.fRatePedEvts", 0, 50, 1);
|
---|
593 | plot.SetDescription("Average rate of events with ped+cosmics trigger;R [Hz]", "RatePT");
|
---|
594 | plot.Plot("Calibration.fRatePedTrigEvts", 0, 4.0, 0.1);
|
---|
595 | plot.SetDescription("Average rate of events without trigger pattern;R [Hz]", "Rate0");
|
---|
596 | plot.Plot("Calibration.fRateNullEvts", 0, 3.5, 0.1);
|
---|
597 | plot.SetDescription("Average rate of unknown trigger pattern;R [Hz]", "RateUnknown");
|
---|
598 | plot.Plot("Calibration.fRateUnknownEvts", 0, 3.5, 0.1);
|
---|
599 |
|
---|
600 | plot.SetDescription("Hi-/Lo-Gain offset;", "PulOff");
|
---|
601 | plot.Plot("Calibration.fPulsePosOffMed", -0.33, 0.5, 0.01);
|
---|
602 | plot.SetDescription("Hi-/Lo-Gain ratio;", "HiLoRatio");
|
---|
603 | plot.Plot("Calibration.fHiLoGainRatioMed", 10, 15, 0.05);
|
---|
604 |
|
---|
605 | //plot.SetDescription("Pulse Variance;", "PulVar");
|
---|
606 | //plot.Plot("Calibration.fPulsePosVar", 0, 0.03, 0.001);
|
---|
607 |
|
---|
608 |
|
---|
609 | //from star*.root
|
---|
610 | //muon
|
---|
611 | plot.SetCondition("Star.fMuonNumber>300");
|
---|
612 | plot.SetDescription("Point Spred Function;PSF [mm]");
|
---|
613 | plot.Plot("Star.fPSF", 0, 30, 0.5);
|
---|
614 | plot.SetDescription("Muon Calibration Ratio Data/MC;r [1]", "MuonCal");
|
---|
615 | plot.Plot("Star.fRatio", 0, 200, 0.5);
|
---|
616 | plot.SetDescription("Muon Rate after Muon Cuts;R [Hz]");
|
---|
617 | plot.Plot("Star.fMuonRate", 0, 2.0, 0.05);
|
---|
618 | plot.SetCondition();
|
---|
619 |
|
---|
620 | //quality
|
---|
621 | plot.SetDescription("Datarate [Hz]", "Rate");
|
---|
622 | plot.Plot("Star.fDataRate", 0, 600, 10);
|
---|
623 | plot.SetDescription("Camera Inhomogeneity;\\sigma [%]", "Inhom");
|
---|
624 | plot.Plot("Star.fInhomogeneity", 0, 100, 1);
|
---|
625 | plot.SetDescription("Camera Spark Rate;R [Hz]", "Sparks");
|
---|
626 | plot.Plot("Star.fSparkRate", 0.075, 2.425, 0.05);
|
---|
627 | plot.SetDescription("Relative effective on time;T_{eff}/T_{obs} [ratio]", "RelTime");
|
---|
628 | plot.Plot("Star.fEffOnTime/Sequences.fRunTime", 0.006, 1.506, 0.01);
|
---|
629 | //imgpar
|
---|
630 | plot.SetDescription("Mean Number of Islands after cleaning;N [#]", "NumIsl");
|
---|
631 | plot.Plot("Star.fMeanNumberIslands", 0.5, 4.5, 0.01);
|
---|
632 | //weather
|
---|
633 | plot.SetDescription("Average Temperature [\\circ C];T [\\circ C]", "Temp");
|
---|
634 | plot.Plot("Star.fAvgTemperature", -5, 25, 1);
|
---|
635 | plot.SetDescription("Average Cloudiness [%]", "AvgClouds");
|
---|
636 | plot.Plot("Star.fAvgCloudiness", 0, 100, 1);
|
---|
637 | plot.SetDescription("RMS Cloudiness [%]", "RmsClouds");
|
---|
638 | plot.Plot("Star.fRmsCloudiness", 0, 30, 1);
|
---|
639 | plot.SetDescription("Sky Temperature [K]", "SkyTemp");
|
---|
640 | plot.Plot("Star.fAvgTempSky", 180, 280, 1);
|
---|
641 | plot.SetDescription("Maximum Humidity [%]", "MaxHum");
|
---|
642 | plot.Plot("Star.fMaxHumidity", 0, 100, 1);
|
---|
643 | plot.SetDescription("Average Humidity [%]", "AvgHum");
|
---|
644 | plot.Plot("Star.fAvgHumidity", 0, 100, 1);
|
---|
645 | plot.SetDescription("Average Wind Speed [km/h];v [km/h]", "Wind");
|
---|
646 | plot.Plot("Star.fAvgWindSpeed", 0, 50, 1);
|
---|
647 |
|
---|
648 | //muon
|
---|
649 | //plot.SetDescription("Number of Muons after Muon Cuts;N [#]");
|
---|
650 | //plot.Plot("Star.fMuonNumber", 0, 10000, 100);
|
---|
651 |
|
---|
652 | // starguider
|
---|
653 | plot.SetDescription("Median No. Stars recognized by the starguider;N_{0}", "StarsMed");
|
---|
654 | plot.Plot("Star.fNumStarsMed", 0, 100, 1);
|
---|
655 | plot.SetDescription("RMS No. Stars recognized by the starguider;\\sigma_{N_{0}}", "StarsRMS");
|
---|
656 | plot.Plot("Star.fNumStarsRMS", 0, 25, 1);
|
---|
657 | plot.SetDescription("Median No. Stars correlated by the starguider;N", "CorMed");
|
---|
658 | plot.Plot("Star.fNumStarsCorMed", 0, 100, 1);
|
---|
659 | plot.SetDescription("RMS No. Stars correlated by the starguider;\\sigma_{N}", "CorRMS");
|
---|
660 | plot.Plot("Star.fNumStarsCorRMS", 0, 25, 1);
|
---|
661 | plot.SetDescription("Relative number of correlated stars;N/N_{0} [%]", "StarsRel");
|
---|
662 | plot.Plot("Star.fNumStarsCorMed/Star.fNumStarsMed*100", 0, 100, 10);
|
---|
663 | plot.SetDescription("Median skbrightess measured by the starguider;B [au]", "BrightMed");
|
---|
664 | plot.Plot("Star.fBrightnessMed", 0, 111, 1);
|
---|
665 | plot.SetDescription("RMS skybrightess measured by the starguider;\\sigma_{B} [au]", "BrightRMS");
|
---|
666 | plot.Plot("Star.fBrightnessRMS", 0, 64, 1);
|
---|
667 |
|
---|
668 | //outer camera
|
---|
669 | //from calib*.root
|
---|
670 | plot.SetDescription("Conversion Factor outer Camera;C_{O} [phe/fadc cnts]", "ConvO");
|
---|
671 | plot.Plot("Calibration.fConvFactorOuter", 0, 3.0, 0.01);
|
---|
672 | plot.SetDescription("Mean Arrival Time outer Camera;T_{O} [sl]", "ArrTmO");
|
---|
673 | plot.Plot("Calibration.fArrTimeMeanOuter", 0, 45, 0.1);
|
---|
674 | plot.SetDescription("RMS Arrival Time outer Camera;\\sigma_{T,O} [sl]", "RmsArrTmO");
|
---|
675 | plot.Plot("Calibration.fArrTimeRmsOuter", 0, 4.5, 0.01);
|
---|
676 | plot.SetDescription("Number of unsuitable pixels outer Camera;N_{O}", "UnsuitO");
|
---|
677 | plot.Plot("Calibration.fUnsuitableOuter", 0, 25, 1);
|
---|
678 | //from signal*.root
|
---|
679 | plot.SetDescription("Mean Pedestal RMS outer Camera;\\sigma_{P,O} [phe]", "PedRmsO");
|
---|
680 | plot.Plot("Calibration.fMeanPedRmsOuter", 0, 4.0, 0.05);
|
---|
681 | plot.SetDescription("Mean Signal outer Camera;S_{O} [phe]", "SignalO");
|
---|
682 | plot.Plot("Calibration.fMeanSignalOuter", 0, 4.0, 0.05);
|
---|
683 | }
|
---|
684 |
|
---|
685 | int plotdb(TString from, TString to, const char *dataset=0)
|
---|
686 | {
|
---|
687 | MSQLMagic serv("sql.rc");
|
---|
688 | if (!serv.IsConnected())
|
---|
689 | {
|
---|
690 | cout << "ERROR - Connection to database failed." << endl;
|
---|
691 | return 0;
|
---|
692 | }
|
---|
693 |
|
---|
694 | cout << "plotdb" << endl;
|
---|
695 | cout << "------" << endl;
|
---|
696 | cout << endl;
|
---|
697 | cout << "Connected to " << serv.GetName() << endl;
|
---|
698 | cout << endl;
|
---|
699 |
|
---|
700 | MStatusDisplay *d = new MStatusDisplay;
|
---|
701 | d->SetWindowName(serv.GetName());
|
---|
702 | d->SetTitle(serv.GetName());
|
---|
703 |
|
---|
704 | MPlot plot(serv);
|
---|
705 | plot.SetDataSet(dataset);
|
---|
706 | plot.SetDisplay(d);
|
---|
707 | plot.SetRequestRange(from, to);
|
---|
708 | plotalldb(plot);
|
---|
709 | d->SaveAsRoot("plotdb.root");
|
---|
710 | d->SaveAsPS("plotdb.ps");
|
---|
711 |
|
---|
712 | return 1;
|
---|
713 | }
|
---|
714 |
|
---|
715 | int plotdb(const char *ds)
|
---|
716 | {
|
---|
717 | MSQLMagic serv("sql.rc");
|
---|
718 | if (!serv.IsConnected())
|
---|
719 | {
|
---|
720 | cout << "ERROR - Connection to database failed." << endl;
|
---|
721 | return 0;
|
---|
722 | }
|
---|
723 |
|
---|
724 | cout << "plotdb" << endl;
|
---|
725 | cout << "------" << endl;
|
---|
726 | cout << endl;
|
---|
727 | cout << "Connected to " << serv.GetName() << endl;
|
---|
728 | cout << endl;
|
---|
729 |
|
---|
730 | MStatusDisplay *d = new MStatusDisplay;
|
---|
731 | d->SetWindowName(serv.GetName());
|
---|
732 | d->SetTitle(serv.GetName());
|
---|
733 |
|
---|
734 | MPlot plot(serv);
|
---|
735 | plot.SetDataSet(ds);
|
---|
736 | plot.SetDisplay(d);
|
---|
737 | plot.SetRequestRange("", "");
|
---|
738 | plotalldb(plot);
|
---|
739 | d->SaveAsRoot("plotdb.root");
|
---|
740 | d->SaveAsPS("plotdb.ps");
|
---|
741 |
|
---|
742 | return 1;
|
---|
743 | }
|
---|
744 |
|
---|
745 | int plotdb(Int_t period, const char *dataset="")
|
---|
746 | {
|
---|
747 | MSQLMagic serv("sql.rc");
|
---|
748 | if (!serv.IsConnected())
|
---|
749 | {
|
---|
750 | cout << "ERROR - Connection to database failed." << endl;
|
---|
751 | return 0;
|
---|
752 | }
|
---|
753 |
|
---|
754 | cout << "plotdb" << endl;
|
---|
755 | cout << "------" << endl;
|
---|
756 | cout << endl;
|
---|
757 | cout << "Connected to " << serv.GetName() << endl;
|
---|
758 | cout << endl;
|
---|
759 |
|
---|
760 | MStatusDisplay *d = new MStatusDisplay;
|
---|
761 | d->SetWindowName(serv.GetName());
|
---|
762 | d->SetTitle(serv.GetName());
|
---|
763 |
|
---|
764 | MPlot plot(serv);
|
---|
765 | plot.SetDataSet(dataset);
|
---|
766 | plot.SetDisplay(d);
|
---|
767 | plot.SetRequestPeriod(period);
|
---|
768 | plotalldb(plot);
|
---|
769 | d->SaveAsRoot("plotdb.root");
|
---|
770 | d->SaveAsPS("plotdb.ps");
|
---|
771 |
|
---|
772 | return 1;
|
---|
773 | }
|
---|
774 |
|
---|
775 | int plotdb()
|
---|
776 | {
|
---|
777 | return plotdb("", "");
|
---|
778 | }
|
---|