1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz, 05/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Author(s): Daniela Dorner, 05/2005 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2005
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // plotdb.C
|
---|
29 | // ========
|
---|
30 | //
|
---|
31 | // This macro is used to read quality parameters from the DB and plot them.
|
---|
32 | //
|
---|
33 | // The parameters are from the following files:
|
---|
34 | // calib*.root:mean conversion factor, mean arrival time, rms arrival time
|
---|
35 | // (each parameter for inner and outer camera)
|
---|
36 | // signal*.root: mean pedestal rms (for inner and outer camera)
|
---|
37 | // star*.root: PSF, # of Muons, Effective OnTime, Muon rate,
|
---|
38 | // Ratio MC/Data(MuonSize) and mean number of islands
|
---|
39 | //
|
---|
40 | // In the DB these values are stored in the tables Calibration and Star.
|
---|
41 | //
|
---|
42 | // Usage:
|
---|
43 | // .x plotdb.C --> all values in the DB are plotted
|
---|
44 | // You can chose are certain period:
|
---|
45 | // .x plotdb.C(25) --> all values from period 25 are plotted
|
---|
46 | // or a time period from a certain date to a certain date
|
---|
47 | // .x plotdb.C("2004-11-14 00:00:00", "2005-02-28 00:00:00")
|
---|
48 | // --> all values from 14.11.2004 0h to 28.2.2005 0h are plotted
|
---|
49 | //
|
---|
50 | // Make sure, that database and password are corretly set in a resource
|
---|
51 | // file called sql.rc and the resource file is found.
|
---|
52 | //
|
---|
53 | /////////////////////////////////////////////////////////////////////////////
|
---|
54 | #include <iostream>
|
---|
55 |
|
---|
56 | #include <TH1.h>
|
---|
57 | #include <TEnv.h>
|
---|
58 | #include <TPad.h>
|
---|
59 | #include <TLine.h>
|
---|
60 | #include <TText.h>
|
---|
61 | #include <TStyle.h>
|
---|
62 | #include <TGraph.h>
|
---|
63 | #include <TCanvas.h>
|
---|
64 | #include <TSQLRow.h>
|
---|
65 | #include <TSQLResult.h>
|
---|
66 |
|
---|
67 | #include "MTime.h"
|
---|
68 | #include "MAstro.h"
|
---|
69 | #include "MSQLServer.h"
|
---|
70 | #include "MStatusDisplay.h"
|
---|
71 |
|
---|
72 | class MPlot : public MParContainer
|
---|
73 | {
|
---|
74 | private:
|
---|
75 | MSQLServer &fServer;
|
---|
76 |
|
---|
77 | TString fRequestFrom;
|
---|
78 | TString fRequestTo;
|
---|
79 | Int_t fRequestPeriod;
|
---|
80 |
|
---|
81 | Float_t fPlotMin;
|
---|
82 | Float_t fPlotMax;
|
---|
83 |
|
---|
84 | Float_t fHistMin;
|
---|
85 | Float_t fHistMax;
|
---|
86 |
|
---|
87 | TString fDescription;
|
---|
88 | TString fNameTab;
|
---|
89 |
|
---|
90 | void PlotTable(TSQLResult &res, TString name, Float_t fmin, Float_t fmax, Float_t resolution)
|
---|
91 | {
|
---|
92 | gStyle->SetOptStat(111111);
|
---|
93 |
|
---|
94 | TSQLRow *row;
|
---|
95 |
|
---|
96 | TGraph g;
|
---|
97 | g.SetNameTitle(name, Form("%s vs Time", name.Data()));
|
---|
98 | g.SetMarkerStyle(kFullDotMedium);
|
---|
99 | if (fmax>fmin)
|
---|
100 | {
|
---|
101 | g.SetMinimum(fmin);
|
---|
102 | g.SetMaximum(fmax);
|
---|
103 | }
|
---|
104 |
|
---|
105 | TGraph g2;
|
---|
106 | g2.SetNameTitle(name, Form("%s vs ZdMin", name.Data()));
|
---|
107 | g2.SetMarkerStyle(kFullDotMedium);
|
---|
108 |
|
---|
109 | Int_t first = -1;
|
---|
110 | Int_t last = -1;
|
---|
111 |
|
---|
112 | while ((row=res.Next()))
|
---|
113 | {
|
---|
114 | const char *date = (*row)[0];
|
---|
115 | const char *zd = (*row)[1];
|
---|
116 | const char *val = (*row)[2];
|
---|
117 | if (!date || !val || !zd)
|
---|
118 | continue;
|
---|
119 |
|
---|
120 | MTime t(date);
|
---|
121 | if (!t.SetSqlDateTime(date))
|
---|
122 | continue;
|
---|
123 |
|
---|
124 | if (fRequestPeriod>0 && MAstro::GetMagicPeriod(t.GetMjd())!=fRequestPeriod)
|
---|
125 | continue;
|
---|
126 |
|
---|
127 | if (first<0)
|
---|
128 | first = TMath::Nint(TMath::Floor(t.GetMjd()));
|
---|
129 | last = TMath::Nint(TMath::Ceil(t.GetMjd()));
|
---|
130 |
|
---|
131 | Float_t value = atof(val);
|
---|
132 | Float_t zenith = atof(zd);
|
---|
133 | g.SetPoint(g.GetN(), t.GetAxisTime(), value);
|
---|
134 | g2.SetPoint(g2.GetN(), zenith, value);
|
---|
135 | }
|
---|
136 |
|
---|
137 | gROOT->SetSelectedPad(0);
|
---|
138 |
|
---|
139 | TString title = fNameTab.IsNull() ? name(name.First('.')+2, name.Length()) : fNameTab;
|
---|
140 | TCanvas &c = fDisplay ? fDisplay->AddTab(title) : *new TCanvas;
|
---|
141 | c.Divide(1,2);
|
---|
142 |
|
---|
143 | TVirtualPad *pad = gPad;
|
---|
144 | pad->cd(2);
|
---|
145 | gPad->SetBorderMode(0);
|
---|
146 | gPad->SetGridy();
|
---|
147 |
|
---|
148 | TH1 *h = g.GetHistogram();
|
---|
149 |
|
---|
150 | h->SetXTitle("Time");
|
---|
151 | h->SetYTitle(name);
|
---|
152 | h->GetXaxis()->SetTimeDisplay(1);
|
---|
153 |
|
---|
154 | g.DrawClone("AP");
|
---|
155 |
|
---|
156 | TLine l;
|
---|
157 | TText t;
|
---|
158 | Int_t num=0;
|
---|
159 | l.SetLineStyle(kDotted);
|
---|
160 | l.SetLineColor(kBlue);
|
---|
161 | t.SetTextColor(kBlue);
|
---|
162 | l.SetLineWidth(1);
|
---|
163 | t.SetTextSize(h->GetXaxis()->GetLabelSize());
|
---|
164 | t.SetTextAlign(21);
|
---|
165 | Int_t p0 = MAstro::GetMagicPeriod(first);
|
---|
166 | for (Int_t p = first; p<last; p++)
|
---|
167 | {
|
---|
168 | Int_t p1 = MAstro::GetMagicPeriod(p);
|
---|
169 | if (p1!=p0)
|
---|
170 | {
|
---|
171 | l.DrawLine(MTime(p).GetAxisTime(), h->GetMinimum(), MTime(p).GetAxisTime(), h->GetMaximum());
|
---|
172 | t.DrawText(MTime(p+15).GetAxisTime(), h->GetMaximum(), Form("%d", p1));
|
---|
173 | num++;
|
---|
174 | }
|
---|
175 | p0 = p1;
|
---|
176 | }
|
---|
177 | if (num<4)
|
---|
178 | gPad->SetGridx();
|
---|
179 |
|
---|
180 | const Double_t min = fHistMin>fHistMax ? h->GetMinimum()-resolution/2 : fHistMin;
|
---|
181 | const Double_t max = fHistMin>fHistMax ? h->GetMaximum()+resolution/2 : fHistMax;
|
---|
182 |
|
---|
183 | pad->cd(1);
|
---|
184 | gPad->SetBorderMode(0);
|
---|
185 | gPad->Divide(2,1);
|
---|
186 |
|
---|
187 | TVirtualPad *pad2 = gPad;
|
---|
188 | pad2->cd(1);
|
---|
189 | gPad->SetBorderMode(0);
|
---|
190 | gPad->SetGridx();
|
---|
191 | gPad->SetGridy();
|
---|
192 |
|
---|
193 | const Int_t n = resolution>0 ? TMath::Nint((max-min)/resolution) : 50;
|
---|
194 |
|
---|
195 | TH1F hist("Hist", Form("Distribution of %s", fDescription.IsNull() ? name.Data() : fDescription.Data()), n, min, max);
|
---|
196 | hist.SetDirectory(0);
|
---|
197 |
|
---|
198 | for (int i=0; i<g.GetN(); i++)
|
---|
199 | hist.Fill(g.GetY()[i]);
|
---|
200 |
|
---|
201 | if (fDescription.IsNull())
|
---|
202 | hist.SetXTitle(name);
|
---|
203 | hist.SetYTitle("Counts");
|
---|
204 |
|
---|
205 | hist.DrawCopy("");
|
---|
206 |
|
---|
207 | pad2->cd(2);
|
---|
208 | gPad->SetBorderMode(0);
|
---|
209 | gPad->SetGridy();
|
---|
210 |
|
---|
211 | TH1 *h2 = g2.GetHistogram();
|
---|
212 |
|
---|
213 | h2->SetXTitle("Zd");
|
---|
214 | h2->SetYTitle(name);
|
---|
215 |
|
---|
216 | g2.DrawClone("AP");
|
---|
217 |
|
---|
218 | }
|
---|
219 |
|
---|
220 | public:
|
---|
221 | MPlot(MSQLServer &server) : fServer(server), fRequestPeriod(-1),
|
---|
222 | fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1)
|
---|
223 | {
|
---|
224 | }
|
---|
225 | void SetPlotRange(Float_t min, Float_t max, Int_t n=5)
|
---|
226 | { fPlotMin = min; fPlotMax = max; }
|
---|
227 | void SetHistRange(Float_t min, Float_t max)
|
---|
228 | { fHistMin = min; fHistMax = max; }
|
---|
229 | void SetRequestRange(const char *from="", const char *to="")
|
---|
230 | { fRequestFrom = from; fRequestTo = to; }
|
---|
231 | void SetRequestPeriod(Int_t n=-1)
|
---|
232 | { fRequestPeriod = n; }
|
---|
233 | void SetDescription(const char *d, const char *t=0) { fDescription = d; fNameTab = t; }
|
---|
234 |
|
---|
235 | Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0)
|
---|
236 | {
|
---|
237 | TString named = "Sequences.fRunStart";
|
---|
238 | TString named2 = "Sequences.fZenithDistanceMin";
|
---|
239 | TString namev = value;
|
---|
240 | TString join = "fSequenceFirst";
|
---|
241 |
|
---|
242 | TString tablev = namev(0, namev.First('.'));
|
---|
243 | TString valuev = namev(namev.First('.')+1, namev.Length());
|
---|
244 |
|
---|
245 | TString tabled = named(0, named.First('.'));
|
---|
246 | TString valued = named(named.First('.')+1, named.Length());
|
---|
247 |
|
---|
248 | TString tabled2 = named2(0, named2.First('.'));
|
---|
249 | TString valued2 = named2(named2.First('.')+1, named2.Length());
|
---|
250 |
|
---|
251 | TString query;
|
---|
252 | query = Form("select %s, %s, %s ", valued.Data(), valued2.Data(), valuev.Data());
|
---|
253 | query += Form("from %s left join %s ", tabled.Data(), tablev.Data());
|
---|
254 | query += Form("on %s.%s=%s.%s ", tabled.Data(), join.Data(), tablev.Data(), join.Data());
|
---|
255 |
|
---|
256 | if (!fRequestFrom.IsNull() && !fRequestTo.IsNull())
|
---|
257 | query += Form("where fRunStart between '%s' and '%s' ",
|
---|
258 | fRequestFrom.Data(), fRequestTo.Data());
|
---|
259 |
|
---|
260 | query += "order by fRunStart";
|
---|
261 |
|
---|
262 | cout << "q: " << query << endl;
|
---|
263 |
|
---|
264 | TSQLResult *res = fServer.Query(query);
|
---|
265 | if (!res)
|
---|
266 | {
|
---|
267 | cout << "ERROR - Query failed: " << query << endl;
|
---|
268 | return kFALSE;
|
---|
269 | }
|
---|
270 |
|
---|
271 | if (max>min)
|
---|
272 | PlotTable(*res, namev, min, max, resolution);
|
---|
273 | else
|
---|
274 | PlotTable(*res, namev, fPlotMin, fPlotMax, resolution);
|
---|
275 |
|
---|
276 |
|
---|
277 | delete res;
|
---|
278 | return kTRUE;
|
---|
279 | }
|
---|
280 | };
|
---|
281 |
|
---|
282 | void plotall(MPlot &plot)
|
---|
283 | {
|
---|
284 | //inner camera
|
---|
285 | //from calib*.root
|
---|
286 | plot.SetDescription("Conversion Factor inner Camera;C_{I} [phe/fadc cnts]", "ConvI");
|
---|
287 | plot.Plot("Calibration.fConvFactorInner", 0, 0.5, 0.001);
|
---|
288 | plot.SetDescription("Mean Arrival Time inner Camera;T_{I} [sl]", "ArrTmI");
|
---|
289 | plot.Plot("Calibration.fArrTimeMeanInner", 0, 9.0, 0.1);
|
---|
290 | plot.SetDescription("RMS Arrival Time inner Camera;\\sigma_{T,I} [sl]", "RmsArrTmI");
|
---|
291 | plot.Plot("Calibration.fArrTimeRmsInner", 0, 2.5, 0.1);
|
---|
292 | //from signal*.root
|
---|
293 | plot.SetDescription("Mean Pedestal RMS inner Camera;\\sigma_{P,I} [phe]", "PedRmsI");
|
---|
294 | plot.Plot("Calibration.fMeanPedRmsInner", 0, 3.5, 0.1);
|
---|
295 | //from star*.root
|
---|
296 | //muon
|
---|
297 | plot.SetDescription("Point Spred Function;PSF [mm]");
|
---|
298 | plot.Plot("Star.fPSF", 0, 40, 0.5);
|
---|
299 | plot.SetDescription("Muon Calibration Ratio Data/MC;r [1]", "MuonCal");
|
---|
300 | plot.Plot("Star.fRatio", 0, 200, 0.5);
|
---|
301 | plot.SetDescription("Muon Rate after Muon Cuts;R [Hz]");
|
---|
302 | plot.Plot("Star.fMuonRate", 0, 2.0, 0.05);
|
---|
303 | //imgpar
|
---|
304 | plot.SetDescription("Mean Number of Islands after cleaning;N [#]", "NumIsl");
|
---|
305 | plot.Plot("Star.fMeanNumberIslands", 0.5, 4.5, 0.1);
|
---|
306 | plot.SetDescription("Measures effective on time;T_{eff} [s]", "EffOn");
|
---|
307 | plot.Plot("Star.fEffOnTime", 0, 10000, 60);
|
---|
308 | //muon
|
---|
309 | plot.SetDescription("Number of Muons after Muon Cuts;N [#]");
|
---|
310 | plot.Plot("Star.fMuonNumber", 0, 10000, 100);
|
---|
311 | //outer camera
|
---|
312 | //from calib*.root
|
---|
313 | plot.SetDescription("Conversion Factor outer Camera;C_{O} [phe/fadc cnts]", "ConvO");
|
---|
314 | plot.Plot("Calibration.fConvFactorOuter", 0, 2.0, 0.01);
|
---|
315 | plot.SetDescription("Mean Arrival Time outer Camera;T_{O} [sl]", "ArrTmO");
|
---|
316 | plot.Plot("Calibration.fArrTimeMeanOuter", 0, 8.5, 0.1);
|
---|
317 | plot.SetDescription("RMS Arrival Time outer Camera;\\sigma_{T,O} [sl]", "RmsArrTmO");
|
---|
318 | plot.Plot("Calibration.fArrTimeRmsOuter", 0, 2.5, 0.1);
|
---|
319 | //from signal*.root
|
---|
320 | plot.SetDescription("Mean Pedestal RMS outer Camera;\\sigma_{P,O} [phe]", "PedRmsO");
|
---|
321 | plot.Plot("Calibration.fMeanPedRmsOuter", 0, 4.0, 0.1);
|
---|
322 | }
|
---|
323 |
|
---|
324 | void plotdb(TString from="", TString to="")
|
---|
325 | {
|
---|
326 | TEnv env("sql.rc");
|
---|
327 |
|
---|
328 | MSQLServer serv(env);
|
---|
329 | if (!serv.IsConnected())
|
---|
330 | {
|
---|
331 | cout << "ERROR - Connection to database failed." << endl;
|
---|
332 | return;
|
---|
333 | }
|
---|
334 |
|
---|
335 | cout << "plotdb" << endl;
|
---|
336 | cout << "------" << endl;
|
---|
337 | cout << endl;
|
---|
338 | cout << "Connected to " << serv.GetName() << endl;
|
---|
339 | cout << endl;
|
---|
340 |
|
---|
341 | MStatusDisplay *d = new MStatusDisplay;
|
---|
342 |
|
---|
343 | MPlot plot(serv);
|
---|
344 | plot.SetDisplay(d);
|
---|
345 | plot.SetRequestRange(from, to);
|
---|
346 | plotall(plot);
|
---|
347 | }
|
---|
348 |
|
---|
349 | void plotdb(Int_t period)
|
---|
350 | {
|
---|
351 | TEnv env("sql.rc");
|
---|
352 |
|
---|
353 | MSQLServer serv(env);
|
---|
354 | if (!serv.IsConnected())
|
---|
355 | {
|
---|
356 | cout << "ERROR - Connection to database failed." << endl;
|
---|
357 | return;
|
---|
358 | }
|
---|
359 |
|
---|
360 | cout << "plotdb" << endl;
|
---|
361 | cout << "------" << endl;
|
---|
362 | cout << endl;
|
---|
363 | cout << "Connected to " << serv.GetName() << endl;
|
---|
364 | cout << endl;
|
---|
365 |
|
---|
366 | MStatusDisplay *d = new MStatusDisplay;
|
---|
367 |
|
---|
368 | MPlot plot(serv);
|
---|
369 | plot.SetDisplay(d);
|
---|
370 | plot.SetRequestPeriod(period);
|
---|
371 | plotall(plot);
|
---|
372 | }
|
---|