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