1 | /* ======================================================================== *\
|
---|
2 | ! $Name: not supported by cvs2svn $:$Id: plotrundb.C,v 1.2 2006-11-03 10:52:36 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-2006
|
---|
24 | !
|
---|
25 | !
|
---|
26 | \* ======================================================================== */
|
---|
27 |
|
---|
28 | /////////////////////////////////////////////////////////////////////////////
|
---|
29 | //
|
---|
30 | // plotundb.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 plotundb.C --> all values in the DB are plotted
|
---|
46 | // You can chose are certain period:
|
---|
47 | // .x plotrundb.C(25) --> all values from period 25 are plotted
|
---|
48 | // or a time period from a certain date to a certain date
|
---|
49 | // .x plotrundb.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 plotrundb.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 | TSQLRow *row;
|
---|
134 |
|
---|
135 | // Create TGraph objects
|
---|
136 | TGraph > = res.GetFieldCount()>4 ? *new TGraphErrors : *new TGraph;
|
---|
137 | gt.SetNameTitle(name, Form("%s vs Time", name.Data()));
|
---|
138 | gt.SetMarkerStyle(kFullDotMedium);
|
---|
139 |
|
---|
140 | TGraph gz;
|
---|
141 | gz.SetNameTitle(name, Form("%s vs <Zd>", name.Data()));
|
---|
142 | gz.SetMarkerStyle(kFullDotMedium);
|
---|
143 |
|
---|
144 | TGraph gt0, gt1;
|
---|
145 | gt0.SetMarkerColor(kRed);
|
---|
146 | gt1.SetMarkerColor(kBlue);
|
---|
147 | gt0.SetMarkerStyle(kFullDotLarge);
|
---|
148 | gt1.SetMarkerStyle(kFullDotLarge);
|
---|
149 |
|
---|
150 | TGraph gz0, gz1;
|
---|
151 | gz0.SetMarkerColor(kRed);
|
---|
152 | gz1.SetMarkerColor(kBlue);
|
---|
153 | gz0.SetMarkerStyle(kFullDotLarge);
|
---|
154 | gz1.SetMarkerStyle(kFullDotLarge);
|
---|
155 |
|
---|
156 | Int_t first = -1;
|
---|
157 | Int_t last = -1;
|
---|
158 |
|
---|
159 | // Loop over the data
|
---|
160 | while ((row=res.Next()))
|
---|
161 | {
|
---|
162 | // Get all fields of this row
|
---|
163 | const char *date = (*row)[0];
|
---|
164 | const char *zd = (*row)[1];
|
---|
165 | const char *val = (*row)[2];
|
---|
166 | const char *snum = res.GetFieldCount()>3 ? (*row)[3] : 0;
|
---|
167 | const char *verr = res.GetFieldCount()>4 ? (*row)[5] : 0;
|
---|
168 | if (!date || !val || !zd)
|
---|
169 | continue;
|
---|
170 |
|
---|
171 | // check if date is valid
|
---|
172 | MTime t(date);
|
---|
173 | if (!t.SetSqlDateTime(date))
|
---|
174 | continue;
|
---|
175 |
|
---|
176 | // check if it belongs to the requested MAGIC period
|
---|
177 | if (fRequestPeriod>0 && MAstro::GetMagicPeriod(t.GetMjd())!=fRequestPeriod)
|
---|
178 | continue;
|
---|
179 |
|
---|
180 | // Get axis range
|
---|
181 | if (first<0)
|
---|
182 | first = TMath::Nint(TMath::Floor(t.GetMjd()));
|
---|
183 | last = TMath::Nint(TMath::Ceil(t.GetMjd()));
|
---|
184 |
|
---|
185 | // Convert a possible key number into a integer
|
---|
186 | UInt_t seq = snum ? atoi(snum) : 0;
|
---|
187 |
|
---|
188 | // convert primary and secondary value into floats
|
---|
189 | Float_t value = atof(val);
|
---|
190 | Float_t zenith = atof(zd);
|
---|
191 |
|
---|
192 | // If a datset is given add the point to the special TGraphs
|
---|
193 | // used for highliting these dates
|
---|
194 | if (fDataSet)
|
---|
195 | {
|
---|
196 | if (fDataSet->HasOnSequence(seq))
|
---|
197 | {
|
---|
198 | gt1.SetPoint(gt1.GetN(), t.GetAxisTime(), value);
|
---|
199 | gz1.SetPoint(gz1.GetN(), zenith, value);
|
---|
200 | }
|
---|
201 |
|
---|
202 | if (fDataSet->HasOffSequence(seq))
|
---|
203 | {
|
---|
204 | gt0.SetPoint(gt0.GetN(), t.GetAxisTime(), value);
|
---|
205 | gz0.SetPoint(gz0.GetN(), zenith, value);
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | // Add Data to TGraph
|
---|
210 | gt.SetPoint(gt.GetN(), t.GetAxisTime(), value);
|
---|
211 | gz.SetPoint(gz.GetN(), zenith, value);
|
---|
212 |
|
---|
213 | // Set error-bar, if one
|
---|
214 | if (verr)
|
---|
215 | static_cast<TGraphErrors&>(gt).SetPointError(gt.GetN()-1, 0, atof(verr));
|
---|
216 | }
|
---|
217 |
|
---|
218 | // If this is done earlier the plots remain empty since root 5.12/00
|
---|
219 | if (fmax>fmin)
|
---|
220 | {
|
---|
221 | gt.SetMinimum(fmin);
|
---|
222 | gt.SetMaximum(fmax);
|
---|
223 | gz.SetMinimum(fmin);
|
---|
224 | gz.SetMaximum(fmax);
|
---|
225 | }
|
---|
226 |
|
---|
227 | gROOT->SetSelectedPad(0);
|
---|
228 |
|
---|
229 | // Create a TCanvas or open a new tab
|
---|
230 | TString title = fNameTab.IsNull() ? name(name.First('.')+2, name.Length()) : fNameTab;
|
---|
231 | TCanvas &c = fDisplay ? fDisplay->AddTab(title) : *new TCanvas;
|
---|
232 | // Set fillcolor, remove border and divide pad
|
---|
233 | c.SetFillColor(kWhite);
|
---|
234 | c.SetBorderMode(0);
|
---|
235 | c.Divide(1,2);
|
---|
236 |
|
---|
237 | // Output mean and rms to console
|
---|
238 | cerr << setprecision(4) << setw(10) << title << ": ";
|
---|
239 | if (gt.GetN()==0)
|
---|
240 | {
|
---|
241 | cerr << " <empty>" << endl;
|
---|
242 | return;
|
---|
243 | }
|
---|
244 | cerr << setw(8) << gt.GetMean(2) << "+-" << setw(8) << gt.GetRMS(2) << " ";
|
---|
245 | if (gt0.GetN()>0 || gt1.GetN()>0)
|
---|
246 | {
|
---|
247 | cerr << setw(8) << gt1.GetMean(2) << "+-" << setw(8) << gt1.GetRMS(2) << " ";
|
---|
248 | cerr << setw(8) << gt0.GetMean(2) << "+-" << setw(8) << gt0.GetRMS(2);
|
---|
249 | }
|
---|
250 | cerr << endl;
|
---|
251 |
|
---|
252 | TVirtualPad *pad = gPad;
|
---|
253 |
|
---|
254 | // draw contants of pad 2 (counting starts at 0)
|
---|
255 | pad->cd(2);
|
---|
256 | gPad->SetBorderMode(0);
|
---|
257 | gPad->SetFrameBorderMode(0);
|
---|
258 | gPad->SetGridy();
|
---|
259 |
|
---|
260 | gPad->SetLeftMargin(0.06);
|
---|
261 | gPad->SetRightMargin(0.06);
|
---|
262 | gPad->SetBottomMargin(0.08);
|
---|
263 |
|
---|
264 | // format axis
|
---|
265 | TH1 *h = gt.GetHistogram();
|
---|
266 |
|
---|
267 | h->SetXTitle("Time");
|
---|
268 | h->SetYTitle(name);
|
---|
269 | h->GetXaxis()->SetTimeDisplay(1);
|
---|
270 | h->GetYaxis()->SetTitleOffset(0.8);
|
---|
271 | h->GetXaxis()->SetTitleOffset(1.0);
|
---|
272 | h->GetXaxis()->SetLabelOffset(0.01);
|
---|
273 |
|
---|
274 | // draw TGraph
|
---|
275 | gt.DrawClone("AP");
|
---|
276 | if (gt0.GetN()>0)
|
---|
277 | gt0.DrawClone("P");
|
---|
278 | if (gt1.GetN()>0)
|
---|
279 | gt1.DrawClone("P");
|
---|
280 |
|
---|
281 | // Add lines and text showing the MAGIC periods
|
---|
282 | TLine l;
|
---|
283 | TText t;
|
---|
284 | Int_t num=0;
|
---|
285 | l.SetLineStyle(kDotted);
|
---|
286 | l.SetLineColor(kBlue);
|
---|
287 | t.SetTextColor(kBlue);
|
---|
288 | l.SetLineWidth(1);
|
---|
289 | t.SetTextSize(h->GetXaxis()->GetLabelSize());
|
---|
290 | t.SetTextAlign(21);
|
---|
291 | Int_t p0 = MAstro::GetMagicPeriod(first);
|
---|
292 | for (Int_t p = first; p<last; p++)
|
---|
293 | {
|
---|
294 | Int_t p1 = MAstro::GetMagicPeriod(p);
|
---|
295 | if (p1!=p0)
|
---|
296 | {
|
---|
297 | l.DrawLine(MTime(p).GetAxisTime(), h->GetMinimum(), MTime(p).GetAxisTime(), h->GetMaximum());
|
---|
298 | t.DrawText(MTime(p+15).GetAxisTime(), h->GetMaximum(), Form("%d", p1));
|
---|
299 | num++;
|
---|
300 | }
|
---|
301 | p0 = p1;
|
---|
302 | }
|
---|
303 | if (num<4)
|
---|
304 | gPad->SetGridx();
|
---|
305 |
|
---|
306 | const Double_t min = fHistMin>fHistMax ? h->GetMinimum()-resolution/2 : fHistMin;
|
---|
307 | const Double_t max = fHistMin>fHistMax ? h->GetMaximum()+resolution/2 : fHistMax;
|
---|
308 |
|
---|
309 | // Use this to save the pad with the time development to a file
|
---|
310 | //gPad->SaveAs(Form("plotdb-%s.eps", title.Data()));
|
---|
311 |
|
---|
312 | // Go back to first (upper) pad, format it and divide it again
|
---|
313 | pad->cd(1);
|
---|
314 | gPad->SetBorderMode(0);
|
---|
315 | gPad->SetFrameBorderMode(0);
|
---|
316 | gPad->Divide(2,1);
|
---|
317 |
|
---|
318 | TVirtualPad *pad2 = gPad;
|
---|
319 |
|
---|
320 | // format left pad
|
---|
321 | pad2->cd(1);
|
---|
322 | gPad->SetBorderMode(0);
|
---|
323 | gPad->SetFrameBorderMode(0);
|
---|
324 | gPad->SetGridx();
|
---|
325 | gPad->SetGridy();
|
---|
326 |
|
---|
327 | // Create histogram
|
---|
328 | const Int_t n = resolution>0 ? TMath::Nint((max-min)/resolution) : 50;
|
---|
329 |
|
---|
330 | TH1F hist("Hist", Form("Distribution of %s", fDescription.IsNull() ? name.Data() : fDescription.Data()), n, min, max);
|
---|
331 | hist.SetDirectory(0);
|
---|
332 |
|
---|
333 | // Fill data into histogra,
|
---|
334 | for (int i=0; i<gt.GetN(); i++)
|
---|
335 | hist.Fill(gt.GetY()[i]);
|
---|
336 |
|
---|
337 | // Format histogram
|
---|
338 | if (fDescription.IsNull())
|
---|
339 | hist.SetXTitle(name);
|
---|
340 | hist.SetYTitle("Counts");
|
---|
341 |
|
---|
342 | // plot histogram
|
---|
343 | hist.DrawCopy("");
|
---|
344 |
|
---|
345 | // format right pad
|
---|
346 | pad2->cd(2);
|
---|
347 | gPad->SetBorderMode(0);
|
---|
348 | gPad->SetFrameBorderMode(0);
|
---|
349 | gPad->SetGridy();
|
---|
350 |
|
---|
351 | // format graph
|
---|
352 | TH1 *h2 = gz.GetHistogram();
|
---|
353 |
|
---|
354 | h2->SetXTitle("Zd");
|
---|
355 | h2->SetYTitle(name);
|
---|
356 |
|
---|
357 | // draw graph
|
---|
358 | gz.DrawClone("AP");
|
---|
359 |
|
---|
360 | if (gz0.GetN()>0)
|
---|
361 | gz0.DrawClone("P");
|
---|
362 | if (gz1.GetN()>0)
|
---|
363 | gz1.DrawClone("P");
|
---|
364 | }
|
---|
365 |
|
---|
366 | public:
|
---|
367 | MPlot(MSQLMagic &server) : fServer(server), fDataSet(NULL),
|
---|
368 | fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1), fGroupBy(kNone)
|
---|
369 | {
|
---|
370 | }
|
---|
371 | ~MPlot()
|
---|
372 | {
|
---|
373 | if (fDataSet)
|
---|
374 | delete fDataSet;
|
---|
375 | }
|
---|
376 | void SetDataSet(const TString filename)
|
---|
377 | {
|
---|
378 | if (fDataSet)
|
---|
379 | {
|
---|
380 | delete fDataSet;
|
---|
381 | fDataSet = NULL;
|
---|
382 | }
|
---|
383 | if (!filename.IsNull())
|
---|
384 | fDataSet = new MDataSet(filename);
|
---|
385 | }
|
---|
386 | void SetPlotRange(Float_t min, Float_t max, Int_t n=5) { fPlotMin = min; fPlotMax = max; }
|
---|
387 | void SetHistRange(Float_t min, Float_t max) { fHistMin = min; fHistMax = max; }
|
---|
388 | void SetRequestRange(const char *from="", const char *to="") { fRequestFrom = from; fRequestTo = to; }
|
---|
389 | void SetRequestPeriod(Int_t n=-1) { fRequestPeriod = n; }
|
---|
390 | void SetCondition(const char *cond="") { fCondition = cond; }
|
---|
391 | void SetDescription(const char *d, const char *t=0) { fDescription = d; fNameTab = t; }
|
---|
392 | void SetGroupBy(GroupBy_t b=kGroupByWeek) { fGroupBy=b; }
|
---|
393 | void SetPrimaryDate(const char *ts) { fPrimaryDate=ts; }
|
---|
394 | void SetPrimaryNumber(const char *ts) { fPrimaryNumber=ts; }
|
---|
395 | void SetSecondary(const char *ts) { fSecondary=ts; }
|
---|
396 |
|
---|
397 | Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0)
|
---|
398 | {
|
---|
399 | TString named = fPrimaryDate;
|
---|
400 | TString named2 = fSecondary;
|
---|
401 | TString namev = value;
|
---|
402 |
|
---|
403 | TString tablev = namev(0, namev.First('.'));
|
---|
404 | TString valuev = namev(namev.First('.')+1, namev.Length());
|
---|
405 |
|
---|
406 | TString tabled = named(0, named.First('.'));
|
---|
407 | TString valued = named(named.First('.')+1, named.Length());
|
---|
408 |
|
---|
409 | TString query="SELECT ";
|
---|
410 | switch (fGroupBy)
|
---|
411 | {
|
---|
412 | case kNone:
|
---|
413 | case kGroupByPrimary:
|
---|
414 | query += valued;
|
---|
415 | break;
|
---|
416 | case kGroupByHour:
|
---|
417 | query += Form("DATE_FORMAT(%s, '%%Y-%%m-%%d %%H:30:00') AS %s ", fPrimaryDate.Data(), valued.Data());
|
---|
418 | break;
|
---|
419 | case kGroupByNight:
|
---|
420 | query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data());
|
---|
421 | break;
|
---|
422 | case kGroupByWeek:
|
---|
423 | query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", fPrimaryDate.Data(), valued.Data());
|
---|
424 | break;
|
---|
425 | case kGroupByMonth:
|
---|
426 | query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data());
|
---|
427 | break;
|
---|
428 | case kGroupBySeason:
|
---|
429 | //query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data());
|
---|
430 | break;
|
---|
431 | case kGroupByYear:
|
---|
432 | query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-08-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data());
|
---|
433 | break;
|
---|
434 | }
|
---|
435 |
|
---|
436 | if (fGroupBy==kNone)
|
---|
437 | {
|
---|
438 | query += ", ";
|
---|
439 | query += fSecondary;
|
---|
440 | query += ", ";
|
---|
441 | query += value;
|
---|
442 | query += ", ";
|
---|
443 | query += fPrimaryNumber;
|
---|
444 | query += " ";
|
---|
445 | }
|
---|
446 | else
|
---|
447 | {
|
---|
448 | query += ", AVG(";
|
---|
449 | query += fSecondary;
|
---|
450 | query += "), AVG(";
|
---|
451 | query += value;
|
---|
452 | query += "), ";
|
---|
453 | query += fPrimaryNumber;
|
---|
454 | query += ", STD(";
|
---|
455 | query += fSecondary;
|
---|
456 | query += "), STD(";
|
---|
457 | query += value;
|
---|
458 | query += ") ";
|
---|
459 | }
|
---|
460 |
|
---|
461 | query += Form("FROM %s ", tabled.Data());
|
---|
462 |
|
---|
463 | const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull();
|
---|
464 |
|
---|
465 | TString where(fCondition);
|
---|
466 | if (!where.IsNull())
|
---|
467 | where += " AND ";
|
---|
468 | where += "RunData.fExcludedFDAKEY=1 ";
|
---|
469 |
|
---|
470 | if (interval)
|
---|
471 | {
|
---|
472 | if (!where.IsNull())
|
---|
473 | where += " AND ";
|
---|
474 | where += Form("%s BETWEEN '%s' AND '%s' ",
|
---|
475 | fPrimaryDate.Data(), fRequestFrom.Data(), fRequestTo.Data());
|
---|
476 | }
|
---|
477 |
|
---|
478 | // ------------------------------
|
---|
479 |
|
---|
480 | query += fServer.GetJoins(tabled, query+" "+where);
|
---|
481 |
|
---|
482 | if (!where.IsNull())
|
---|
483 | {
|
---|
484 | query += "WHERE ";
|
---|
485 | query += where;
|
---|
486 | }
|
---|
487 |
|
---|
488 | if (fGroupBy!=kNone)
|
---|
489 | {
|
---|
490 | query += Form("GROUP BY %s ", valued.Data());
|
---|
491 | //query += Form(" HAVING COUNT(%s)=(COUNT(*)+1)/2 ", valuev.Data());
|
---|
492 | }
|
---|
493 | query += Form("ORDER BY %s ", valued.Data());
|
---|
494 |
|
---|
495 |
|
---|
496 | // ------------------------------
|
---|
497 |
|
---|
498 | TSQLResult *res = fServer.Query(query);
|
---|
499 | if (!res)
|
---|
500 | {
|
---|
501 | cout << "ERROR - Query failed: " << query << endl;
|
---|
502 | return kFALSE;
|
---|
503 | }
|
---|
504 |
|
---|
505 | if (max>min)
|
---|
506 | PlotTable(*res, namev, min, max, resolution);
|
---|
507 | else
|
---|
508 | PlotTable(*res, namev, fPlotMin, fPlotMax, resolution);
|
---|
509 |
|
---|
510 |
|
---|
511 | delete res;
|
---|
512 | return kTRUE;
|
---|
513 | }
|
---|
514 | };
|
---|
515 |
|
---|
516 | void plotall(MPlot &plot)
|
---|
517 | {
|
---|
518 | plot.SetGroupBy(MPlot::kGroupByNight);
|
---|
519 |
|
---|
520 | plot.SetPrimaryDate("RunData.fRunStart");
|
---|
521 | plot.SetPrimaryNumber("RunData.fRunNumber");
|
---|
522 | plot.SetSecondary("RunData.fZenithDistance");
|
---|
523 |
|
---|
524 | //inner camera
|
---|
525 | //from calib*.root
|
---|
526 | plot.SetDescription("DAQ Storage Rate;R_{DAQ,S} [Hz]", "StoreRate");
|
---|
527 | plot.Plot("RunData.fDaqStoreRate", -0.5, 999.5, 5);
|
---|
528 | plot.SetDescription("DAQ Trigger Rate;R_{DAQ,T} [Hz]", "TrigRate");
|
---|
529 | plot.Plot("RunData.fDaqTriggerRate", -0.5, 999.5, 5);
|
---|
530 | plot.SetDescription("Mean Trigger Rate;<R> [Hz]", "MeanTrig");
|
---|
531 | plot.Plot("RunData.fMeanTriggerRate", -0.5, 999.5, 5);
|
---|
532 | plot.SetDescription("L2 Trigger rate after prescaler;R_{L2,P}", "Presc");
|
---|
533 | plot.Plot("RunData.fL2RatePresc", -0.5, 999.5, 5);
|
---|
534 | plot.SetDescription("L2 Trigger rate before prescaler;R_{L2,U}", "Unpresc");
|
---|
535 | plot.Plot("RunData.fL2RateUnpresc", -0.5, 999.5, 5);
|
---|
536 |
|
---|
537 | //from signal*.root
|
---|
538 | plot.SetDescription("Signal Position;<T_{S}> [sl]", "PosMean");
|
---|
539 | plot.Plot("DataCheck.fPositionSignal", -0.5, 29.5, 1);
|
---|
540 | plot.SetDescription("Signal Position FWHM;\\sigma_{S} [sl]", "PosFWHM");
|
---|
541 | plot.Plot("DataCheck.fPositionFWHM", -0.5, 29.5, 1);
|
---|
542 | plot.SetDescription("Signal Height;<H_{s}> [counts]", "SigMean");
|
---|
543 | plot.Plot("DataCheck.fHeightSignal", -0.5, 256.5, 1);
|
---|
544 | plot.SetDescription("Signal Height FWHM;\\sigma_{H} [counts]", "SigFWHM");
|
---|
545 | plot.Plot("DataCheck.fHeightFWHM", -0.5, 155.5, 1);
|
---|
546 |
|
---|
547 | plot.SetDescription("Interleaved Signal Position;<T_{S}> [sl]", "IPosMean");
|
---|
548 | plot.Plot("DataCheck.fPositionSignalInterlaced", -0.5, 29.5, 1);
|
---|
549 | plot.SetDescription("Interleaved Signal Position FWHM;\\sigma_{S} [sl]", "IPosFWHM");
|
---|
550 | plot.Plot("DataCheck.fPositionFWHMInterlaced", -0.5, 29.5, 1);
|
---|
551 | plot.SetDescription("Interleaved Signal Height;<H_{s}> [counts]", "ISigMean");
|
---|
552 | plot.Plot("DataCheck.fHeightSignalInterlaced", -0.5, 256.5, 1);
|
---|
553 | plot.SetDescription("Interleaved Signal Height FWHM;\\sigma_{H} [counts]", "ISigFWHM");
|
---|
554 | plot.Plot("DataCheck.fHeightFWHMInterlaced", -0.5, 155.5, 1);
|
---|
555 | }
|
---|
556 |
|
---|
557 | int plotrundb(TString from, TString to, const char *dataset=0)
|
---|
558 | {
|
---|
559 | TEnv env("sql.rc");
|
---|
560 |
|
---|
561 | MSQLMagic serv(env);
|
---|
562 | if (!serv.IsConnected())
|
---|
563 | {
|
---|
564 | cout << "ERROR - Connection to database failed." << endl;
|
---|
565 | return 0;
|
---|
566 | }
|
---|
567 |
|
---|
568 | cout << "plotrundb" << endl;
|
---|
569 | cout << "---------" << endl;
|
---|
570 | cout << endl;
|
---|
571 | cout << "Connected to " << serv.GetName() << endl;
|
---|
572 | cout << endl;
|
---|
573 |
|
---|
574 | MStatusDisplay *d = new MStatusDisplay;
|
---|
575 | d->SetWindowName(serv.GetName());
|
---|
576 | d->SetTitle(serv.GetName());
|
---|
577 |
|
---|
578 | MPlot plot(serv);
|
---|
579 | plot.SetDataSet(dataset);
|
---|
580 | plot.SetDisplay(d);
|
---|
581 | plot.SetRequestRange(from, to);
|
---|
582 | plotall(plot);
|
---|
583 | d->SaveAsRoot("plotrundb.root");
|
---|
584 | d->SaveAsPS("plotrundb.ps");
|
---|
585 |
|
---|
586 | return 1;
|
---|
587 | }
|
---|
588 |
|
---|
589 | int plotrundb(const char *ds)
|
---|
590 | {
|
---|
591 | TEnv env("sql.rc");
|
---|
592 |
|
---|
593 | MSQLMagic serv(env);
|
---|
594 | if (!serv.IsConnected())
|
---|
595 | {
|
---|
596 | cout << "ERROR - Connection to database failed." << endl;
|
---|
597 | return 0;
|
---|
598 | }
|
---|
599 |
|
---|
600 | cout << "plotrundb" << endl;
|
---|
601 | cout << "---------" << endl;
|
---|
602 | cout << endl;
|
---|
603 | cout << "Connected to " << serv.GetName() << endl;
|
---|
604 | cout << endl;
|
---|
605 |
|
---|
606 | MStatusDisplay *d = new MStatusDisplay;
|
---|
607 | d->SetWindowName(serv.GetName());
|
---|
608 | d->SetTitle(serv.GetName());
|
---|
609 |
|
---|
610 | MPlot plot(serv);
|
---|
611 | plot.SetDataSet(ds);
|
---|
612 | plot.SetDisplay(d);
|
---|
613 | plot.SetRequestRange("", "");
|
---|
614 | plotall(plot);
|
---|
615 | d->SaveAsRoot("plotrundb.root");
|
---|
616 | d->SaveAsPS("plotrundb.ps");
|
---|
617 |
|
---|
618 | return 1;
|
---|
619 | }
|
---|
620 |
|
---|
621 | int plotrundb(Int_t period, const char *dataset="")
|
---|
622 | {
|
---|
623 | TEnv env("sql.rc");
|
---|
624 |
|
---|
625 | MSQLMagic serv(env);
|
---|
626 | if (!serv.IsConnected())
|
---|
627 | {
|
---|
628 | cout << "ERROR - Connection to database failed." << endl;
|
---|
629 | return 0;
|
---|
630 | }
|
---|
631 |
|
---|
632 | cout << "plotrundb" << endl;
|
---|
633 | cout << "---------" << endl;
|
---|
634 | cout << endl;
|
---|
635 | cout << "Connected to " << serv.GetName() << endl;
|
---|
636 | cout << endl;
|
---|
637 |
|
---|
638 | MStatusDisplay *d = new MStatusDisplay;
|
---|
639 | d->SetWindowName(serv.GetName());
|
---|
640 | d->SetTitle(serv.GetName());
|
---|
641 |
|
---|
642 | MPlot plot(serv);
|
---|
643 | plot.SetDataSet(dataset);
|
---|
644 | plot.SetDisplay(d);
|
---|
645 | plot.SetRequestPeriod(period);
|
---|
646 | plotall(plot);
|
---|
647 | d->SaveAsRoot("plotrundb.root");
|
---|
648 | d->SaveAsPS("plotrundb.ps");
|
---|
649 |
|
---|
650 | return 1;
|
---|
651 | }
|
---|
652 |
|
---|
653 | int plotrundb()
|
---|
654 | {
|
---|
655 | return plotrundb("", "");
|
---|
656 | }
|
---|