| 1 | /* ======================================================================== *\
|
|---|
| 2 | ! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.31 2006-11-01 08:53:26 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 | // 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 | enum GroupBy_t
|
|---|
| 87 | {
|
|---|
| 88 | kNone,
|
|---|
| 89 | kGroupByPrimary,
|
|---|
| 90 | kGroupByHour,
|
|---|
| 91 | kGroupByNight,
|
|---|
| 92 | kGroupByWeek,
|
|---|
| 93 | kGroupByMonth,
|
|---|
| 94 | kGroupByYear
|
|---|
| 95 | };
|
|---|
| 96 | private:
|
|---|
| 97 | MSQLMagic &fServer;
|
|---|
| 98 |
|
|---|
| 99 | MDataSet *fDataSet;
|
|---|
| 100 |
|
|---|
| 101 | TString fPrimaryDate;
|
|---|
| 102 | TString fPrimaryNumber;
|
|---|
| 103 | TString fSecondary;
|
|---|
| 104 |
|
|---|
| 105 | TString fRequestFrom;
|
|---|
| 106 | TString fRequestTo;
|
|---|
| 107 | Int_t fRequestPeriod;
|
|---|
| 108 |
|
|---|
| 109 | Float_t fPlotMin;
|
|---|
| 110 | Float_t fPlotMax;
|
|---|
| 111 |
|
|---|
| 112 | Float_t fHistMin;
|
|---|
| 113 | Float_t fHistMax;
|
|---|
| 114 |
|
|---|
| 115 | TString fDescription;
|
|---|
| 116 | TString fNameTab;
|
|---|
| 117 |
|
|---|
| 118 | TString fCondition;
|
|---|
| 119 | GroupBy_t fGroupBy;
|
|---|
| 120 |
|
|---|
| 121 | void PlotTable(TSQLResult &res, TString name, Float_t fmin, Float_t fmax, Float_t resolution)
|
|---|
| 122 | {
|
|---|
| 123 | gStyle->SetOptStat(111111);
|
|---|
| 124 |
|
|---|
| 125 | TSQLRow *row;
|
|---|
| 126 |
|
|---|
| 127 | TGraph > = res.GetFieldCount()>4 ? *new TGraphErrors : *new TGraph;
|
|---|
| 128 | gt.SetNameTitle(name, Form("%s vs Time", name.Data()));
|
|---|
| 129 | gt.SetMarkerStyle(kFullDotMedium);
|
|---|
| 130 |
|
|---|
| 131 | TGraph gz;
|
|---|
| 132 | gz.SetNameTitle(name, Form("%s vs <Zd>", name.Data()));
|
|---|
| 133 | gz.SetMarkerStyle(kFullDotMedium);
|
|---|
| 134 |
|
|---|
| 135 | TGraph gt0, gt1;
|
|---|
| 136 | gt0.SetMarkerColor(kRed);
|
|---|
| 137 | gt1.SetMarkerColor(kBlue);
|
|---|
| 138 | gt0.SetMarkerStyle(kFullDotLarge);
|
|---|
| 139 | gt1.SetMarkerStyle(kFullDotLarge);
|
|---|
| 140 |
|
|---|
| 141 | TGraph gz0, gz1;
|
|---|
| 142 | gz0.SetMarkerColor(kRed);
|
|---|
| 143 | gz1.SetMarkerColor(kBlue);
|
|---|
| 144 | gz0.SetMarkerStyle(kFullDotLarge);
|
|---|
| 145 | gz1.SetMarkerStyle(kFullDotLarge);
|
|---|
| 146 |
|
|---|
| 147 | Int_t first = -1;
|
|---|
| 148 | Int_t last = -1;
|
|---|
| 149 |
|
|---|
| 150 | while ((row=res.Next()))
|
|---|
| 151 | {
|
|---|
| 152 | const char *date = (*row)[0];
|
|---|
| 153 | const char *zd = (*row)[1];
|
|---|
| 154 | const char *val = (*row)[2];
|
|---|
| 155 | const char *snum = res.GetFieldCount()>3 ? (*row)[3] : 0;
|
|---|
| 156 | const char *verr = res.GetFieldCount()>4 ? (*row)[5] : 0;
|
|---|
| 157 | if (!date || !val || !zd)
|
|---|
| 158 | continue;
|
|---|
| 159 |
|
|---|
| 160 | MTime t(date);
|
|---|
| 161 | if (!t.SetSqlDateTime(date))
|
|---|
| 162 | continue;
|
|---|
| 163 |
|
|---|
| 164 | if (fRequestPeriod>0 && MAstro::GetMagicPeriod(t.GetMjd())!=fRequestPeriod)
|
|---|
| 165 | continue;
|
|---|
| 166 |
|
|---|
| 167 | if (first<0)
|
|---|
| 168 | first = TMath::Nint(TMath::Floor(t.GetMjd()));
|
|---|
| 169 | last = TMath::Nint(TMath::Ceil(t.GetMjd()));
|
|---|
| 170 |
|
|---|
| 171 | UInt_t seq = snum ? atoi(snum) : 0;
|
|---|
| 172 |
|
|---|
| 173 | Float_t value = atof(val);
|
|---|
| 174 | Float_t zenith = atof(zd);
|
|---|
| 175 |
|
|---|
| 176 | if (fDataSet)
|
|---|
| 177 | {
|
|---|
| 178 | if (fDataSet->HasOnSequence(seq))
|
|---|
| 179 | {
|
|---|
| 180 | gt1.SetPoint(gt1.GetN(), t.GetAxisTime(), value);
|
|---|
| 181 | gz1.SetPoint(gz1.GetN(), zenith, value);
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | if (fDataSet->HasOffSequence(seq))
|
|---|
| 185 | {
|
|---|
| 186 | gt0.SetPoint(gt0.GetN(), t.GetAxisTime(), value);
|
|---|
| 187 | gz0.SetPoint(gz0.GetN(), zenith, value);
|
|---|
| 188 | }
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | gt.SetPoint(gt.GetN(), t.GetAxisTime(), value);
|
|---|
| 192 | gz.SetPoint(gz.GetN(), zenith, value);
|
|---|
| 193 |
|
|---|
| 194 | if (verr)
|
|---|
| 195 | static_cast<TGraphErrors&>(gt).SetPointError(gt.GetN()-1, 0, atof(verr));
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | // If this is done earlier the plots remain empty since root 5.12/00
|
|---|
| 199 | if (fmax>fmin)
|
|---|
| 200 | {
|
|---|
| 201 | gt.SetMinimum(fmin);
|
|---|
| 202 | gt.SetMaximum(fmax);
|
|---|
| 203 | gz.SetMinimum(fmin);
|
|---|
| 204 | gz.SetMaximum(fmax);
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | gROOT->SetSelectedPad(0);
|
|---|
| 208 |
|
|---|
| 209 | TString title = fNameTab.IsNull() ? name(name.First('.')+2, name.Length()) : fNameTab;
|
|---|
| 210 | TCanvas &c = fDisplay ? fDisplay->AddTab(title) : *new TCanvas;
|
|---|
| 211 | c.SetFillColor(kWhite);
|
|---|
| 212 | c.SetBorderMode(0);
|
|---|
| 213 | c.Divide(1,2);
|
|---|
| 214 |
|
|---|
| 215 | cerr << setprecision(4) << setw(10) << title << ": ";
|
|---|
| 216 | if (gt.GetN()==0)
|
|---|
| 217 | {
|
|---|
| 218 | cerr << " <empty>" << endl;
|
|---|
| 219 | return;
|
|---|
| 220 | }
|
|---|
| 221 | cerr << setw(8) << gt.GetMean(2) << "+-" << setw(8) << gt.GetRMS(2) << " ";
|
|---|
| 222 | if (gt0.GetN()>0 || gt1.GetN()>0)
|
|---|
| 223 | {
|
|---|
| 224 | cerr << setw(8) << gt1.GetMean(2) << "+-" << setw(8) << gt1.GetRMS(2) << " ";
|
|---|
| 225 | cerr << setw(8) << gt0.GetMean(2) << "+-" << setw(8) << gt0.GetRMS(2);
|
|---|
| 226 | }
|
|---|
| 227 | cerr << endl;
|
|---|
| 228 |
|
|---|
| 229 | TVirtualPad *pad = gPad;
|
|---|
| 230 | pad->cd(2);
|
|---|
| 231 | gPad->SetBorderMode(0);
|
|---|
| 232 | gPad->SetFrameBorderMode(0);
|
|---|
| 233 | gPad->SetGridy();
|
|---|
| 234 |
|
|---|
| 235 | gPad->SetLeftMargin(0.06);
|
|---|
| 236 | gPad->SetRightMargin(0.06);
|
|---|
| 237 | gPad->SetBottomMargin(0.08);
|
|---|
| 238 |
|
|---|
| 239 | TH1 *h = gt.GetHistogram();
|
|---|
| 240 |
|
|---|
| 241 | h->SetXTitle("Time");
|
|---|
| 242 | h->SetYTitle(name);
|
|---|
| 243 | h->GetXaxis()->SetTimeDisplay(1);
|
|---|
| 244 | h->GetYaxis()->SetTitleOffset(0.8);
|
|---|
| 245 | h->GetXaxis()->SetTitleOffset(1.0);
|
|---|
| 246 | h->GetXaxis()->SetLabelOffset(0.01);
|
|---|
| 247 |
|
|---|
| 248 | gt.DrawClone("AP");
|
|---|
| 249 | if (gt0.GetN()>0)
|
|---|
| 250 | gt0.DrawClone("P");
|
|---|
| 251 | if (gt1.GetN()>0)
|
|---|
| 252 | gt1.DrawClone("P");
|
|---|
| 253 |
|
|---|
| 254 | TLine l;
|
|---|
| 255 | TText t;
|
|---|
| 256 | Int_t num=0;
|
|---|
| 257 | l.SetLineStyle(kDotted);
|
|---|
| 258 | l.SetLineColor(kBlue);
|
|---|
| 259 | t.SetTextColor(kBlue);
|
|---|
| 260 | l.SetLineWidth(1);
|
|---|
| 261 | t.SetTextSize(h->GetXaxis()->GetLabelSize());
|
|---|
| 262 | t.SetTextAlign(21);
|
|---|
| 263 | Int_t p0 = MAstro::GetMagicPeriod(first);
|
|---|
| 264 | for (Int_t p = first; p<last; p++)
|
|---|
| 265 | {
|
|---|
| 266 | Int_t p1 = MAstro::GetMagicPeriod(p);
|
|---|
| 267 | if (p1!=p0)
|
|---|
| 268 | {
|
|---|
| 269 | l.DrawLine(MTime(p).GetAxisTime(), h->GetMinimum(), MTime(p).GetAxisTime(), h->GetMaximum());
|
|---|
| 270 | t.DrawText(MTime(p+15).GetAxisTime(), h->GetMaximum(), Form("%d", p1));
|
|---|
| 271 | num++;
|
|---|
| 272 | }
|
|---|
| 273 | p0 = p1;
|
|---|
| 274 | }
|
|---|
| 275 | if (num<4)
|
|---|
| 276 | gPad->SetGridx();
|
|---|
| 277 |
|
|---|
| 278 | const Double_t min = fHistMin>fHistMax ? h->GetMinimum()-resolution/2 : fHistMin;
|
|---|
| 279 | const Double_t max = fHistMin>fHistMax ? h->GetMaximum()+resolution/2 : fHistMax;
|
|---|
| 280 |
|
|---|
| 281 | // Use this to save the pad with the time development to a file
|
|---|
| 282 | //gPad->SaveAs(Form("plotdb-%s.eps", title.Data()));
|
|---|
| 283 |
|
|---|
| 284 | pad->cd(1);
|
|---|
| 285 | gPad->SetBorderMode(0);
|
|---|
| 286 | gPad->SetFrameBorderMode(0);
|
|---|
| 287 | gPad->Divide(2,1);
|
|---|
| 288 |
|
|---|
| 289 | TVirtualPad *pad2 = gPad;
|
|---|
| 290 | pad2->cd(1);
|
|---|
| 291 | gPad->SetBorderMode(0);
|
|---|
| 292 | gPad->SetFrameBorderMode(0);
|
|---|
| 293 | gPad->SetGridx();
|
|---|
| 294 | gPad->SetGridy();
|
|---|
| 295 |
|
|---|
| 296 | const Int_t n = resolution>0 ? TMath::Nint((max-min)/resolution) : 50;
|
|---|
| 297 |
|
|---|
| 298 | TH1F hist("Hist", Form("Distribution of %s", fDescription.IsNull() ? name.Data() : fDescription.Data()), n, min, max);
|
|---|
| 299 | hist.SetDirectory(0);
|
|---|
| 300 |
|
|---|
| 301 | for (int i=0; i<gt.GetN(); i++)
|
|---|
| 302 | hist.Fill(gt.GetY()[i]);
|
|---|
| 303 |
|
|---|
| 304 | if (fDescription.IsNull())
|
|---|
| 305 | hist.SetXTitle(name);
|
|---|
| 306 | hist.SetYTitle("Counts");
|
|---|
| 307 |
|
|---|
| 308 | hist.DrawCopy("");
|
|---|
| 309 |
|
|---|
| 310 | pad2->cd(2);
|
|---|
| 311 | gPad->SetBorderMode(0);
|
|---|
| 312 | gPad->SetFrameBorderMode(0);
|
|---|
| 313 | gPad->SetGridy();
|
|---|
| 314 |
|
|---|
| 315 | TH1 *h2 = gz.GetHistogram();
|
|---|
| 316 |
|
|---|
| 317 | h2->SetXTitle("Zd");
|
|---|
| 318 | h2->SetYTitle(name);
|
|---|
| 319 |
|
|---|
| 320 | gz.DrawClone("AP");
|
|---|
| 321 | if (gz0.GetN()>0)
|
|---|
| 322 | gz0.DrawClone("P");
|
|---|
| 323 | if (gz1.GetN()>0)
|
|---|
| 324 | gz1.DrawClone("P");
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | public:
|
|---|
| 328 | MPlot(MSQLMagic &server) : fServer(server), fDataSet(NULL),
|
|---|
| 329 | fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1), fGroupBy(kNone)
|
|---|
| 330 | {
|
|---|
| 331 | }
|
|---|
| 332 | ~MPlot()
|
|---|
| 333 | {
|
|---|
| 334 | if (fDataSet)
|
|---|
| 335 | delete fDataSet;
|
|---|
| 336 | }
|
|---|
| 337 | void SetDataSet(const TString filename)
|
|---|
| 338 | {
|
|---|
| 339 | if (fDataSet)
|
|---|
| 340 | {
|
|---|
| 341 | delete fDataSet;
|
|---|
| 342 | fDataSet = NULL;
|
|---|
| 343 | }
|
|---|
| 344 | if (!filename.IsNull())
|
|---|
| 345 | fDataSet = new MDataSet(filename);
|
|---|
| 346 | }
|
|---|
| 347 | void SetPlotRange(Float_t min, Float_t max, Int_t n=5) { fPlotMin = min; fPlotMax = max; }
|
|---|
| 348 | void SetHistRange(Float_t min, Float_t max) { fHistMin = min; fHistMax = max; }
|
|---|
| 349 | void SetRequestRange(const char *from="", const char *to="") { fRequestFrom = from; fRequestTo = to; }
|
|---|
| 350 | void SetRequestPeriod(Int_t n=-1) { fRequestPeriod = n; }
|
|---|
| 351 | void SetCondition(const char *cond="") { fCondition = cond; }
|
|---|
| 352 | void SetDescription(const char *d, const char *t=0) { fDescription = d; fNameTab = t; }
|
|---|
| 353 | void SetGroupBy(GroupBy_t b=kGroupByWeek) { fGroupBy=b; }
|
|---|
| 354 | void SetPrimaryDate(const char *ts) { fPrimaryDate=ts; }
|
|---|
| 355 | void SetPrimaryNumber(const char *ts) { fPrimaryNumber=ts; }
|
|---|
| 356 | void SetSecondary(const char *ts) { fSecondary=ts; }
|
|---|
| 357 |
|
|---|
| 358 | Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0)
|
|---|
| 359 | {
|
|---|
| 360 | TString named = fPrimaryDate;
|
|---|
| 361 | TString named2 = fSecondary;
|
|---|
| 362 | TString namev = value;
|
|---|
| 363 |
|
|---|
| 364 | TString tablev = namev(0, namev.First('.'));
|
|---|
| 365 | TString valuev = namev(namev.First('.')+1, namev.Length());
|
|---|
| 366 |
|
|---|
| 367 | TString tabled = named(0, named.First('.'));
|
|---|
| 368 | TString valued = named(named.First('.')+1, named.Length());
|
|---|
| 369 |
|
|---|
| 370 | TString query="SELECT ";
|
|---|
| 371 | query += valued;
|
|---|
| 372 | if (fGroupBy==kNone)
|
|---|
| 373 | {
|
|---|
| 374 | query += ", ";
|
|---|
| 375 | query += fSecondary;
|
|---|
| 376 | query += ", ";
|
|---|
| 377 | query += value;
|
|---|
| 378 | query += ", ";
|
|---|
| 379 | query += fPrimaryNumber;
|
|---|
| 380 | query += " ";
|
|---|
| 381 | }
|
|---|
| 382 | else
|
|---|
| 383 | {
|
|---|
| 384 | query += ", AVG(";
|
|---|
| 385 | query += fSecondary;
|
|---|
| 386 | query += "), AVG(";
|
|---|
| 387 | query += value;
|
|---|
| 388 | query += "), ";
|
|---|
| 389 | query += fPrimaryNumber;
|
|---|
| 390 | query += ", STD(";
|
|---|
| 391 | query += fSecondary;
|
|---|
| 392 | query += "), STD(";
|
|---|
| 393 | query += value;
|
|---|
| 394 | query += ") ";
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | switch (fGroupBy)
|
|---|
| 398 | {
|
|---|
| 399 | case kNone:
|
|---|
| 400 | case kGroupByPrimary:
|
|---|
| 401 | break;
|
|---|
| 402 | case kGroupByHour:
|
|---|
| 403 | query += Form(", DATE_FORMAT(%s, '%%Y-%%m-%%d %%H') AS %s ", named.Data(), valued.Data());
|
|---|
| 404 | break;
|
|---|
| 405 | case kGroupByNight:
|
|---|
| 406 | query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d') AS %s ", named.Data(), valued.Data());
|
|---|
| 407 | break;
|
|---|
| 408 | case kGroupByWeek:
|
|---|
| 409 | query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", named.Data(), valued.Data());
|
|---|
| 410 | break;
|
|---|
| 411 | case kGroupByMonth:
|
|---|
| 412 | query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m') AS %s ", named.Data(), valued.Data());
|
|---|
| 413 | break;
|
|---|
| 414 | case kGroupByYear:
|
|---|
| 415 | query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y') AS %s ", named.Data(), valued.Data());
|
|---|
| 416 | break;
|
|---|
| 417 | }
|
|---|
| 418 |
|
|---|
| 419 | query += Form("FROM %s ", tabled.Data());
|
|---|
| 420 |
|
|---|
| 421 | const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull();
|
|---|
| 422 |
|
|---|
| 423 | TString where(fCondition);
|
|---|
| 424 | if (!fDataSet && !interval && tablev=="Star")
|
|---|
| 425 | {
|
|---|
| 426 | if (!where.IsNull())
|
|---|
| 427 | where += " AND ";
|
|---|
| 428 | where += "Star.fMuonNumber>300 ";
|
|---|
| 429 | }
|
|---|
| 430 |
|
|---|
| 431 | if (interval)
|
|---|
| 432 | {
|
|---|
| 433 | if (!where.IsNull())
|
|---|
| 434 | where += " AND ";
|
|---|
| 435 | where += Form("%s BETWEEN '%s' AND '%s' ",
|
|---|
| 436 | fPrimaryDate.Data(), fRequestFrom.Data(), fRequestTo.Data());
|
|---|
| 437 | }
|
|---|
| 438 |
|
|---|
| 439 | // ------------------------------
|
|---|
| 440 |
|
|---|
| 441 | query += fServer.GetJoins(tabled, query+" "+where);
|
|---|
| 442 |
|
|---|
| 443 | if (!where.IsNull())
|
|---|
| 444 | {
|
|---|
| 445 | query += "WHERE ";
|
|---|
| 446 | query += where;
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | if (fGroupBy!=kNone)
|
|---|
| 450 | {
|
|---|
| 451 | query += Form("GROUP BY %s ", valued.Data());
|
|---|
| 452 | //query += Form(" HAVING COUNT(%s)=(COUNT(*)+1)/2 ", valuev.Data());
|
|---|
| 453 | }
|
|---|
| 454 | query += Form("ORDER BY %s ", fPrimaryDate.Data());
|
|---|
| 455 |
|
|---|
| 456 |
|
|---|
| 457 | // ------------------------------
|
|---|
| 458 |
|
|---|
| 459 | TSQLResult *res = fServer.Query(query);
|
|---|
| 460 | if (!res)
|
|---|
| 461 | {
|
|---|
| 462 | cout << "ERROR - Query failed: " << query << endl;
|
|---|
| 463 | return kFALSE;
|
|---|
| 464 | }
|
|---|
| 465 |
|
|---|
| 466 | if (max>min)
|
|---|
| 467 | PlotTable(*res, namev, min, max, resolution);
|
|---|
| 468 | else
|
|---|
| 469 | PlotTable(*res, namev, fPlotMin, fPlotMax, resolution);
|
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 | delete res;
|
|---|
| 473 | return kTRUE;
|
|---|
| 474 | }
|
|---|
| 475 | };
|
|---|
| 476 |
|
|---|
| 477 | void plotall(MPlot &plot)
|
|---|
| 478 | {
|
|---|
| 479 | //plot.SetGroupBy(MPlot::kGroupByWeek);
|
|---|
| 480 |
|
|---|
| 481 | plot.SetPrimaryDate("Sequences.fRunStart");
|
|---|
| 482 | plot.SetPrimaryNumber("Sequences.fSequenceFirst");
|
|---|
| 483 | plot.SetSecondary("(Sequences.fZenithDistanceMin+Sequences.fZenithDistanceMax)/2");
|
|---|
| 484 |
|
|---|
| 485 | //inner camera
|
|---|
| 486 | //from calib*.root
|
|---|
| 487 | plot.SetDescription("Conversion Factor inner Camera;C_{I} [phe/fadc cnts]", "ConvI");
|
|---|
| 488 | plot.Plot("Calibration.fConvFactorInner", 0, 0.5, 0.002);
|
|---|
| 489 | plot.SetDescription("Mean Arrival Time inner Camera;T_{I} [sl]", "ArrTmI");
|
|---|
| 490 | plot.Plot("Calibration.fArrTimeMeanInner", 0, 9.0, 0.1);
|
|---|
| 491 | plot.SetDescription("RMS Arrival Time inner Camera;\\sigma_{T,I} [sl]", "RmsArrTmI");
|
|---|
| 492 | plot.Plot("Calibration.fArrTimeRmsInner", 0, 0.8, 0.01);
|
|---|
| 493 | plot.SetDescription("Number of unsuitable pixels inner Camera;N{I}", "UnsuitI");
|
|---|
| 494 | plot.Plot("Calibration.fUnsuitableInner", 0, 25, 1);
|
|---|
| 495 |
|
|---|
| 496 | //from signal*.root
|
|---|
| 497 | plot.SetDescription("Mean Pedestal RMS inner Camera;\\sigma_{P,I} [phe]", "PedRmsI");
|
|---|
| 498 | plot.Plot("Calibration.fMeanPedRmsInner", 0, 3.5, 0.05);
|
|---|
| 499 | plot.SetDescription("Mean Signal inner Camera;S_{I} [phe]", "SignalI");
|
|---|
| 500 | plot.Plot("Calibration.fMeanSignalInner", 0, 7.0, 0.05);
|
|---|
| 501 | plot.SetDescription("Mean PulsePosCheck (falling edge) inner camera;T [sl]", "ChkPos");
|
|---|
| 502 | plot.Plot("Calibration.fPulsePosCheckMean", 1, 15.0, 0.1);
|
|---|
| 503 | plot.SetDescription("Rms PulsePosCheck (falling edge) inner camera;T [sl]", "ChkRms");
|
|---|
| 504 | plot.Plot("Calibration.fPulsePosCheckRms", 0, 5.0, 0.1);
|
|---|
| 505 | plot.SetDescription("Mean calibrated PulsePos;T", "PulPos");
|
|---|
| 506 | plot.Plot("Calibration.fPulsePosMean", 1, 15.0, 0.1);
|
|---|
| 507 | plot.SetDescription("Rms calibrated PulsePos;T", "PulRms");
|
|---|
| 508 | plot.Plot("Calibration.fPulsePosRms", 0, 2.0, 0.02);
|
|---|
| 509 |
|
|---|
| 510 | plot.SetDescription("Hi-/Lo-Gain offset;", "PulOff");
|
|---|
| 511 | plot.Plot("Calibration.fPulsePosOffMed", -0.33, 0.33, 0.01);
|
|---|
| 512 | plot.SetDescription("Hi-/Lo-Gain ratio;", "HiLoRatio");
|
|---|
| 513 | plot.Plot("Calibration.fHiLoGainRatioMed", 10, 12.5, 0.05);
|
|---|
| 514 |
|
|---|
| 515 | //plot.SetDescription("Pulse Variance;", "PulVar");
|
|---|
| 516 | //plot.Plot("Calibration.fPulsePosVar", 0, 0.03, 0.001);
|
|---|
| 517 |
|
|---|
| 518 | //from star*.root
|
|---|
| 519 | //muon
|
|---|
| 520 | plot.SetDescription("Point Spred Function;PSF [mm]");
|
|---|
| 521 | plot.Plot("Star.fPSF", 0, 30, 0.5);
|
|---|
| 522 | plot.SetDescription("Muon Calibration Ratio Data/MC;r [1]", "MuonCal");
|
|---|
| 523 | plot.Plot("Star.fRatio", 0, 200, 0.5);
|
|---|
| 524 | plot.SetDescription("Muon Rate after Muon Cuts;R [Hz]");
|
|---|
| 525 | plot.Plot("Star.fMuonRate", 0, 2.0, 0.05);
|
|---|
| 526 | //quality
|
|---|
| 527 | plot.SetDescription("Camera Inhomogeneity;\\sigma [%]", "Inhom");
|
|---|
| 528 | plot.Plot("Star.fInhomogeneity", 0, 100, 1);
|
|---|
| 529 | //imgpar
|
|---|
| 530 | plot.SetDescription("Mean Number of Islands after cleaning;N [#]", "NumIsl");
|
|---|
| 531 | plot.Plot("Star.fMeanNumberIslands", 0.5, 4.5, 0.01);
|
|---|
| 532 | plot.SetDescription("Measures effective on time;T_{eff} [s]", "EffOn");
|
|---|
| 533 | plot.Plot("Star.fEffOnTime", 0, 10000, 150);
|
|---|
| 534 | plot.SetDescription("Relative effective on time;T_{eff}/T_{obs} [ratio]", "RelTime");
|
|---|
| 535 | plot.Plot("Star.fEffOnTime/Sequences.fRunTime", 0.006, 1.506, 0.01);
|
|---|
| 536 | plot.SetDescription("Datarate [Hz]", "Rate");
|
|---|
| 537 | plot.Plot("Star.fDataRate", 0, 600, 10);
|
|---|
| 538 | plot.SetDescription("Maximum Humidity [%]", "Hum");
|
|---|
| 539 | plot.Plot("Star.fMaxHumidity", 0, 100, 1);
|
|---|
| 540 |
|
|---|
| 541 | //muon
|
|---|
| 542 | //plot.SetDescription("Number of Muons after Muon Cuts;N [#]");
|
|---|
| 543 | //plot.Plot("Star.fMuonNumber", 0, 10000, 100);
|
|---|
| 544 |
|
|---|
| 545 | // starguider
|
|---|
| 546 | plot.SetDescription("Median No. Stars recognized by the starguider;N_{0}", "StarsMed");
|
|---|
| 547 | plot.Plot("Star.fNumStarsMed", 0, 100, 1);
|
|---|
| 548 | plot.SetDescription("RMS No. Stars recognized by the starguider;\\sigma_{N_{0}}", "StarsRMS");
|
|---|
| 549 | plot.Plot("Star.fNumStarsRMS", 0, 25, 1);
|
|---|
| 550 | plot.SetDescription("Median No. Stars correlated by the starguider;N", "CorMed");
|
|---|
| 551 | plot.Plot("Star.fNumStarsCorMed", 0, 100, 1);
|
|---|
| 552 | plot.SetDescription("RMS No. Stars correlated by the starguider;\\sigma_{N}", "CorRMS");
|
|---|
| 553 | plot.Plot("Star.fNumStarsCorRMS", 0, 25, 1);
|
|---|
| 554 | plot.SetDescription("Relative number of correlated stars;N/N_{0} [%]", "StarsRel");
|
|---|
| 555 | plot.Plot("Star.fNumStarsCorMed/Star.fNumStarsMed*100", 0, 100, 10);
|
|---|
| 556 | plot.SetDescription("Median skbrightess measured by the starguider;B [au]", "BrightMed");
|
|---|
| 557 | plot.Plot("Star.fBrightnessMed", 0, 111, 1);
|
|---|
| 558 | plot.SetDescription("RMS skybrightess measured by the starguider;\\sigma_{B} [au]", "BrightRMS");
|
|---|
| 559 | plot.Plot("Star.fBrightnessRMS", 0, 64, 1);
|
|---|
| 560 |
|
|---|
| 561 | //outer camera
|
|---|
| 562 | //from calib*.root
|
|---|
| 563 | plot.SetDescription("Conversion Factor outer Camera;C_{O} [phe/fadc cnts]", "ConvO");
|
|---|
| 564 | plot.Plot("Calibration.fConvFactorOuter", 0, 2.0, 0.01);
|
|---|
| 565 | plot.SetDescription("Mean Arrival Time outer Camera;T_{O} [sl]", "ArrTmO");
|
|---|
| 566 | plot.Plot("Calibration.fArrTimeMeanOuter", 0, 8.5, 0.1);
|
|---|
| 567 | plot.SetDescription("RMS Arrival Time outer Camera;\\sigma_{T,O} [sl]", "RmsArrTmO");
|
|---|
| 568 | plot.Plot("Calibration.fArrTimeRmsOuter", 0, 1.0, 0.01);
|
|---|
| 569 | plot.SetDescription("Number of unsuitable pixels outer Camera;N{O}", "UnsuitO");
|
|---|
| 570 | plot.Plot("Calibration.fUnsuitableOuter", 0, 25, 1);
|
|---|
| 571 | //from signal*.root
|
|---|
| 572 | plot.SetDescription("Mean Pedestal RMS outer Camera;\\sigma_{P,O} [phe]", "PedRmsO");
|
|---|
| 573 | plot.Plot("Calibration.fMeanPedRmsOuter", 0, 4.0, 0.05);
|
|---|
| 574 | plot.SetDescription("Mean Signal outer Camera;S_{O} [phe]", "SignalO");
|
|---|
| 575 | plot.Plot("Calibration.fMeanSignalOuter", 0, 4.0, 0.05);
|
|---|
| 576 | }
|
|---|
| 577 |
|
|---|
| 578 | int plotdb(TString from, TString to, const char *dataset=0)
|
|---|
| 579 | {
|
|---|
| 580 | TEnv env("sql.rc");
|
|---|
| 581 |
|
|---|
| 582 | MSQLMagic serv(env);
|
|---|
| 583 | if (!serv.IsConnected())
|
|---|
| 584 | {
|
|---|
| 585 | cout << "ERROR - Connection to database failed." << endl;
|
|---|
| 586 | return 0;
|
|---|
| 587 | }
|
|---|
| 588 |
|
|---|
| 589 | cout << "plotdb" << endl;
|
|---|
| 590 | cout << "------" << endl;
|
|---|
| 591 | cout << endl;
|
|---|
| 592 | cout << "Connected to " << serv.GetName() << endl;
|
|---|
| 593 | cout << endl;
|
|---|
| 594 |
|
|---|
| 595 | MStatusDisplay *d = new MStatusDisplay;
|
|---|
| 596 | d->SetWindowName(serv.GetName());
|
|---|
| 597 | d->SetTitle(serv.GetName());
|
|---|
| 598 |
|
|---|
| 599 | MPlot plot(serv);
|
|---|
| 600 | plot.SetDataSet(dataset);
|
|---|
| 601 | plot.SetDisplay(d);
|
|---|
| 602 | plot.SetRequestRange(from, to);
|
|---|
| 603 | plotall(plot);
|
|---|
| 604 | d->SaveAsRoot("plotdb.root");
|
|---|
| 605 | d->SaveAsPS("plotdb.ps");
|
|---|
| 606 |
|
|---|
| 607 | return 1;
|
|---|
| 608 | }
|
|---|
| 609 |
|
|---|
| 610 | int plotdb(const char *ds)
|
|---|
| 611 | {
|
|---|
| 612 | TEnv env("sql.rc");
|
|---|
| 613 |
|
|---|
| 614 | MSQLMagic serv(env);
|
|---|
| 615 | if (!serv.IsConnected())
|
|---|
| 616 | {
|
|---|
| 617 | cout << "ERROR - Connection to database failed." << endl;
|
|---|
| 618 | return 0;
|
|---|
| 619 | }
|
|---|
| 620 |
|
|---|
| 621 | cout << "plotdb" << endl;
|
|---|
| 622 | cout << "------" << endl;
|
|---|
| 623 | cout << endl;
|
|---|
| 624 | cout << "Connected to " << serv.GetName() << endl;
|
|---|
| 625 | cout << endl;
|
|---|
| 626 |
|
|---|
| 627 | MStatusDisplay *d = new MStatusDisplay;
|
|---|
| 628 | d->SetWindowName(serv.GetName());
|
|---|
| 629 | d->SetTitle(serv.GetName());
|
|---|
| 630 |
|
|---|
| 631 | MPlot plot(serv);
|
|---|
| 632 | plot.SetDataSet(ds);
|
|---|
| 633 | plot.SetDisplay(d);
|
|---|
| 634 | plot.SetRequestRange("", "");
|
|---|
| 635 | plotall(plot);
|
|---|
| 636 | d->SaveAsRoot("plotdb.root");
|
|---|
| 637 | d->SaveAsPS("plotdb.ps");
|
|---|
| 638 |
|
|---|
| 639 | return 1;
|
|---|
| 640 | }
|
|---|
| 641 |
|
|---|
| 642 | int plotdb(Int_t period, const char *dataset="")
|
|---|
| 643 | {
|
|---|
| 644 | TEnv env("sql.rc");
|
|---|
| 645 |
|
|---|
| 646 | MSQLMagic serv(env);
|
|---|
| 647 | if (!serv.IsConnected())
|
|---|
| 648 | {
|
|---|
| 649 | cout << "ERROR - Connection to database failed." << endl;
|
|---|
| 650 | return 0;
|
|---|
| 651 | }
|
|---|
| 652 |
|
|---|
| 653 | cout << "plotdb" << endl;
|
|---|
| 654 | cout << "------" << endl;
|
|---|
| 655 | cout << endl;
|
|---|
| 656 | cout << "Connected to " << serv.GetName() << endl;
|
|---|
| 657 | cout << endl;
|
|---|
| 658 |
|
|---|
| 659 | MStatusDisplay *d = new MStatusDisplay;
|
|---|
| 660 | d->SetWindowName(serv.GetName());
|
|---|
| 661 | d->SetTitle(serv.GetName());
|
|---|
| 662 |
|
|---|
| 663 | MPlot plot(serv);
|
|---|
| 664 | plot.SetDataSet(dataset);
|
|---|
| 665 | plot.SetDisplay(d);
|
|---|
| 666 | plot.SetRequestPeriod(period);
|
|---|
| 667 | plotall(plot);
|
|---|
| 668 | d->SaveAsRoot("plotdb.root");
|
|---|
| 669 | d->SaveAsPS("plotdb.ps");
|
|---|
| 670 |
|
|---|
| 671 | return 1;
|
|---|
| 672 | }
|
|---|
| 673 |
|
|---|
| 674 | int plotdb()
|
|---|
| 675 | {
|
|---|
| 676 | return plotdb("", "");
|
|---|
| 677 | }
|
|---|