| 1 | /* ======================================================================== *\
|
|---|
| 2 | ! $Name: not supported by cvs2svn $:$Id: plotoptical.C,v 1.6 2006-11-17 11:45:29 dorner 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 | // plotoptical.C
|
|---|
| 31 | // =============
|
|---|
| 32 | //
|
|---|
| 33 | // This macro is used to read optical data from the DB and plot them.
|
|---|
| 34 | //
|
|---|
| 35 | // In the DB these values are stored in the tables Calibration and Star.
|
|---|
| 36 | //
|
|---|
| 37 | //
|
|---|
| 38 | // To plot the whole database simple use:
|
|---|
| 39 | // .x plotdb.C+
|
|---|
| 40 | //
|
|---|
| 41 | // Plot only data for one source. For the available sources see the database
|
|---|
| 42 | // .x plotdb.C+("source")
|
|---|
| 43 | //
|
|---|
| 44 | // You can chose are certain MAGIC-period:
|
|---|
| 45 | // .x plotdb.C+(25) --> all values from period 25 are plotted
|
|---|
| 46 | //
|
|---|
| 47 | // MAGIC periods correspond to one moon-phase and are defined as
|
|---|
| 48 | // moon period-284. For details see MAstro::MoonPeriod and
|
|---|
| 49 | // MAstro::MagicPeriod.
|
|---|
| 50 | //
|
|---|
| 51 | // or a time period from a certain date to a certain date
|
|---|
| 52 | // .x plotdb.C+("2004-11-14 00:00:00", "2005-02-28 00:00:00")
|
|---|
| 53 | // --> all values from 14.11.2004 0h to 28.2.2005 0h are plotted
|
|---|
| 54 | // .x plotdb.C+("2004-11-14 00:00:00", "2005-02-28 00:00:00", "source")
|
|---|
| 55 | // --> all values from 14.11.2004 0h to 28.2.2005 0h of "source" are plotted
|
|---|
| 56 | //
|
|---|
| 57 | //
|
|---|
| 58 | // For details of the plots produced see the function plotall() below.
|
|---|
| 59 | //
|
|---|
| 60 | //
|
|---|
| 61 | // The plot title and axis-titles are created by:
|
|---|
| 62 | // plot.SetDescription("Title;x", "TabName");
|
|---|
| 63 | //
|
|---|
| 64 | // Drawing the plot is initiated by
|
|---|
| 65 | // plot.Plot("OpticalData.fExposure", min, max, width);
|
|---|
| 66 | //
|
|---|
| 67 | // While OpticalData.fExposure can be any kind of variable to plot.
|
|---|
| 68 | // min and max are the minimum and maximum of the histogram which is
|
|---|
| 69 | // filled and width is the bin-width of this histogram.
|
|---|
| 70 | //
|
|---|
| 71 | // To group data (average) of a certain period use:
|
|---|
| 72 | // plot.GroupBy(MPlot::kGroupByNight);
|
|---|
| 73 | // before initiating the plot.
|
|---|
| 74 | //
|
|---|
| 75 | //
|
|---|
| 76 | // Make sure, that database and password are corretly set in a resource
|
|---|
| 77 | // file called sql.rc and the resource file is found.
|
|---|
| 78 | //
|
|---|
| 79 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 80 | #include <iostream>
|
|---|
| 81 | #include <iomanip>
|
|---|
| 82 |
|
|---|
| 83 | #include <TH1.h>
|
|---|
| 84 | #include <TEnv.h>
|
|---|
| 85 | #include <TPad.h>
|
|---|
| 86 | #include <TLine.h>
|
|---|
| 87 | #include <TText.h>
|
|---|
| 88 | #include <TFrame.h>
|
|---|
| 89 | #include <TStyle.h>
|
|---|
| 90 | #include <TCanvas.h>
|
|---|
| 91 | #include <TPRegexp.h>
|
|---|
| 92 | #include <TSQLRow.h>
|
|---|
| 93 | #include <TSQLResult.h>
|
|---|
| 94 | #include <TGraphErrors.h>
|
|---|
| 95 |
|
|---|
| 96 | #include "MTime.h"
|
|---|
| 97 | #include "MAstro.h"
|
|---|
| 98 | #include "MDataSet.h"
|
|---|
| 99 | #include "MSQLMagic.h"
|
|---|
| 100 | #include "MStatusDisplay.h"
|
|---|
| 101 |
|
|---|
| 102 | class MPlot : public MParContainer
|
|---|
| 103 | {
|
|---|
| 104 | public:
|
|---|
| 105 | // Possible constants to group-by (average) over a certain period
|
|---|
| 106 | enum GroupBy_t
|
|---|
| 107 | {
|
|---|
| 108 | kNone,
|
|---|
| 109 | kGroupByPrimary,
|
|---|
| 110 | kGroupByHour,
|
|---|
| 111 | kGroupByNight,
|
|---|
| 112 | kGroupByWeek,
|
|---|
| 113 | kGroupByMonth,
|
|---|
| 114 | kGroupBySeason,
|
|---|
| 115 | kGroupByYear
|
|---|
| 116 | };
|
|---|
| 117 |
|
|---|
| 118 | private:
|
|---|
| 119 | MSQLMagic &fServer; // Reference to the sql-server class
|
|---|
| 120 |
|
|---|
| 121 | MDataSet *fDataSet; // A possible dtaset to highlite single points
|
|---|
| 122 |
|
|---|
| 123 | TString fPrimaryDate; // The name of the data we plot
|
|---|
| 124 | TString fPrimaryNumber; // The corresponding name for the key number
|
|---|
| 125 | TString fSecondary; // The value versus which the second plot is made
|
|---|
| 126 |
|
|---|
| 127 | TString fRequestFrom; // Start of a requested date range
|
|---|
| 128 | TString fRequestTo; // End of a requested date range
|
|---|
| 129 | Int_t fRequestPeriod; // A possible requested period
|
|---|
| 130 |
|
|---|
| 131 | Float_t fPlotMin;
|
|---|
| 132 | Float_t fPlotMax;
|
|---|
| 133 |
|
|---|
| 134 | Float_t fHistMin;
|
|---|
| 135 | Float_t fHistMax;
|
|---|
| 136 |
|
|---|
| 137 | TString fDescription; // The description (title) of the plot
|
|---|
| 138 | TString fNameTab; // The name of the tab in the display
|
|---|
| 139 |
|
|---|
| 140 | TString fCondition; // An additional condition added to the query
|
|---|
| 141 | GroupBy_t fGroupBy; // A possible Group-By flag
|
|---|
| 142 |
|
|---|
| 143 | // --------------------------------------------------------------------------
|
|---|
| 144 | //
|
|---|
| 145 | // Function to plot the result of the query
|
|---|
| 146 | //
|
|---|
| 147 | void PlotTable(TSQLResult &res, TString name, Float_t fmin, Float_t fmax, Float_t resolution)
|
|---|
| 148 | {
|
|---|
| 149 | // Enable all otions in the statistics box
|
|---|
| 150 | gStyle->SetOptStat(111111);
|
|---|
| 151 |
|
|---|
| 152 | TSQLRow *row;
|
|---|
| 153 |
|
|---|
| 154 | // Create TGraph objects
|
|---|
| 155 | TGraph > = res.GetFieldCount()>4 ? *new TGraphErrors : *new TGraph;
|
|---|
| 156 | gt.SetNameTitle(name, Form("%s vs Time", name.Data()));
|
|---|
| 157 | gt.SetMarkerStyle(kFullDotMedium);
|
|---|
| 158 |
|
|---|
| 159 | TGraph gz;
|
|---|
| 160 | gz.SetNameTitle(name, Form("%s vs <Zd>", name.Data()));
|
|---|
| 161 | gz.SetMarkerStyle(kFullDotMedium);
|
|---|
| 162 |
|
|---|
| 163 | TGraph gt0, gt1;
|
|---|
| 164 | gt0.SetMarkerColor(kRed);
|
|---|
| 165 | gt1.SetMarkerColor(kBlue);
|
|---|
| 166 | gt0.SetMarkerStyle(kFullDotLarge);
|
|---|
| 167 | gt1.SetMarkerStyle(kFullDotLarge);
|
|---|
| 168 |
|
|---|
| 169 | TGraph gz0, gz1;
|
|---|
| 170 | gz0.SetMarkerColor(kRed);
|
|---|
| 171 | gz1.SetMarkerColor(kBlue);
|
|---|
| 172 | gz0.SetMarkerStyle(kFullDotLarge);
|
|---|
| 173 | gz1.SetMarkerStyle(kFullDotLarge);
|
|---|
| 174 |
|
|---|
| 175 | Int_t first = -1;
|
|---|
| 176 | Int_t last = -1;
|
|---|
| 177 |
|
|---|
| 178 | // Loop over the data
|
|---|
| 179 | while ((row=res.Next()))
|
|---|
| 180 | {
|
|---|
| 181 | // Get all fields of this row
|
|---|
| 182 | const char *date = (*row)[0];
|
|---|
| 183 | const char *zd = (*row)[1];
|
|---|
| 184 | const char *val = (*row)[2];
|
|---|
| 185 | const char *snum = res.GetFieldCount()>3 ? (*row)[3] : 0;
|
|---|
| 186 | const char *verr = res.GetFieldCount()>4 ? (*row)[5] : 0;
|
|---|
| 187 | if (!date || !val || !zd)
|
|---|
| 188 | continue;
|
|---|
| 189 |
|
|---|
| 190 | // check if date is valid
|
|---|
| 191 | MTime t(date);
|
|---|
| 192 | if (!t.SetSqlDateTime(date))
|
|---|
| 193 | continue;
|
|---|
| 194 |
|
|---|
| 195 | // check if it belongs to the requested MAGIC period
|
|---|
| 196 | if (fRequestPeriod>0 && MAstro::GetMagicPeriod(t.GetMjd())!=fRequestPeriod)
|
|---|
| 197 | continue;
|
|---|
| 198 |
|
|---|
| 199 | // Get axis range
|
|---|
| 200 | if (first<0)
|
|---|
| 201 | first = TMath::Nint(TMath::Floor(t.GetMjd()));
|
|---|
| 202 | last = TMath::Nint(TMath::Ceil(t.GetMjd()));
|
|---|
| 203 |
|
|---|
| 204 | // Convert a possible key number into a integer
|
|---|
| 205 | UInt_t seq = snum ? atoi(snum) : 0;
|
|---|
| 206 |
|
|---|
| 207 | // convert primary and secondary value into floats
|
|---|
| 208 | Float_t value = atof(val);
|
|---|
| 209 | Float_t zenith = atof(zd);
|
|---|
| 210 |
|
|---|
| 211 | // If a datset is given add the point to the special TGraphs
|
|---|
| 212 | // used for highliting these dates
|
|---|
| 213 | if (fDataSet)
|
|---|
| 214 | {
|
|---|
| 215 | if (fDataSet->HasOnSequence(seq))
|
|---|
| 216 | {
|
|---|
| 217 | gt1.SetPoint(gt1.GetN(), t.GetAxisTime(), value);
|
|---|
| 218 | gz1.SetPoint(gz1.GetN(), zenith, value);
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | if (fDataSet->HasOffSequence(seq))
|
|---|
| 222 | {
|
|---|
| 223 | gt0.SetPoint(gt0.GetN(), t.GetAxisTime(), value);
|
|---|
| 224 | gz0.SetPoint(gz0.GetN(), zenith, value);
|
|---|
| 225 | }
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | // Add Data to TGraph
|
|---|
| 229 | gt.SetPoint(gt.GetN(), t.GetAxisTime(), value);
|
|---|
| 230 | gz.SetPoint(gz.GetN(), zenith, value);
|
|---|
| 231 |
|
|---|
| 232 | // Set error-bar, if one
|
|---|
| 233 | if (verr)
|
|---|
| 234 | static_cast<TGraphErrors&>(gt).SetPointError(gt.GetN()-1, 0, atof(verr));
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | // If this is done earlier the plots remain empty since root 5.12/00
|
|---|
| 238 | if (fmax>fmin)
|
|---|
| 239 | {
|
|---|
| 240 | gt.SetMinimum(fmin);
|
|---|
| 241 | gt.SetMaximum(fmax);
|
|---|
| 242 | gz.SetMinimum(fmin);
|
|---|
| 243 | gz.SetMaximum(fmax);
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | gROOT->SetSelectedPad(0);
|
|---|
| 247 |
|
|---|
| 248 | // Create a TCanvas or open a new tab
|
|---|
| 249 | TString title = fNameTab.IsNull() ? name(name.First('.')+2, name.Length()) : fNameTab;
|
|---|
| 250 | TCanvas &c = fDisplay ? fDisplay->AddTab(title) : *new TCanvas;
|
|---|
| 251 | // Set fillcolor, remove border and divide pad
|
|---|
| 252 | c.SetFillColor(kWhite);
|
|---|
| 253 | c.SetBorderMode(0);
|
|---|
| 254 | c.Divide(1,2);
|
|---|
| 255 |
|
|---|
| 256 | // Output mean and rms to console
|
|---|
| 257 | cerr << setprecision(4) << setw(10) << title << ": ";
|
|---|
| 258 | if (gt.GetN()==0)
|
|---|
| 259 | {
|
|---|
| 260 | cerr << " <empty>" << endl;
|
|---|
| 261 | return;
|
|---|
| 262 | }
|
|---|
| 263 | cerr << setw(8) << gt.GetMean(2) << "+-" << setw(8) << gt.GetRMS(2) << " ";
|
|---|
| 264 | if (gt0.GetN()>0 || gt1.GetN()>0)
|
|---|
| 265 | {
|
|---|
| 266 | cerr << setw(8) << gt1.GetMean(2) << "+-" << setw(8) << gt1.GetRMS(2) << " ";
|
|---|
| 267 | cerr << setw(8) << gt0.GetMean(2) << "+-" << setw(8) << gt0.GetRMS(2);
|
|---|
| 268 | }
|
|---|
| 269 | cerr << endl;
|
|---|
| 270 |
|
|---|
| 271 | TVirtualPad *pad = gPad;
|
|---|
| 272 |
|
|---|
| 273 | // draw contants of pad 2 (counting starts at 0)
|
|---|
| 274 | pad->cd(2);
|
|---|
| 275 | gPad->SetBorderMode(0);
|
|---|
| 276 | gPad->SetFrameBorderMode(0);
|
|---|
| 277 | gPad->SetGridy();
|
|---|
| 278 |
|
|---|
| 279 | gPad->SetLeftMargin(0.06);
|
|---|
| 280 | gPad->SetRightMargin(0.06);
|
|---|
| 281 | gPad->SetBottomMargin(0.08);
|
|---|
| 282 |
|
|---|
| 283 | // format axis
|
|---|
| 284 | TH1 *h = gt.GetHistogram();
|
|---|
| 285 |
|
|---|
| 286 | h->SetXTitle("Time");
|
|---|
| 287 | h->SetYTitle(name);
|
|---|
| 288 | h->GetXaxis()->SetTimeDisplay(1);
|
|---|
| 289 | h->GetYaxis()->SetTitleOffset(0.8);
|
|---|
| 290 | h->GetXaxis()->SetTitleOffset(1.0);
|
|---|
| 291 | h->GetXaxis()->SetLabelOffset(0.01);
|
|---|
| 292 |
|
|---|
| 293 | // draw TGraph
|
|---|
| 294 | gt.DrawClone("AP");
|
|---|
| 295 | if (gt0.GetN()>0)
|
|---|
| 296 | gt0.DrawClone("P");
|
|---|
| 297 | if (gt1.GetN()>0)
|
|---|
| 298 | gt1.DrawClone("P");
|
|---|
| 299 |
|
|---|
| 300 | // Add lines and text showing the MAGIC periods
|
|---|
| 301 | TLine l;
|
|---|
| 302 | TText t;
|
|---|
| 303 | Int_t num=0;
|
|---|
| 304 | l.SetLineStyle(kDotted);
|
|---|
| 305 | l.SetLineColor(kBlue);
|
|---|
| 306 | t.SetTextColor(kBlue);
|
|---|
| 307 | l.SetLineWidth(1);
|
|---|
| 308 | t.SetTextSize(h->GetXaxis()->GetLabelSize());
|
|---|
| 309 | t.SetTextAlign(21);
|
|---|
| 310 | Int_t p0 = MAstro::GetMagicPeriod(first);
|
|---|
| 311 | for (Int_t p = first; p<last; p++)
|
|---|
| 312 | {
|
|---|
| 313 | Int_t p1 = MAstro::GetMagicPeriod(p);
|
|---|
| 314 | if (p1!=p0)
|
|---|
| 315 | {
|
|---|
| 316 | l.DrawLine(MTime(p).GetAxisTime(), h->GetMinimum(), MTime(p).GetAxisTime(), h->GetMaximum());
|
|---|
| 317 | t.DrawText(MTime(p+15).GetAxisTime(), h->GetMaximum(), Form("%d", p1));
|
|---|
| 318 | num++;
|
|---|
| 319 | }
|
|---|
| 320 | p0 = p1;
|
|---|
| 321 | }
|
|---|
| 322 | if (num<4)
|
|---|
| 323 | gPad->SetGridx();
|
|---|
| 324 |
|
|---|
| 325 | const Double_t min = fHistMin>fHistMax ? h->GetMinimum()-resolution/2 : fHistMin;
|
|---|
| 326 | const Double_t max = fHistMin>fHistMax ? h->GetMaximum()+resolution/2 : fHistMax;
|
|---|
| 327 |
|
|---|
| 328 | // Use this to save the pad with the time development to a file
|
|---|
| 329 | //gPad->SaveAs(Form("plotdb-%s.eps", title.Data()));
|
|---|
| 330 |
|
|---|
| 331 | // Go back to first (upper) pad, format it and divide it again
|
|---|
| 332 | pad->cd(1);
|
|---|
| 333 | gPad->SetBorderMode(0);
|
|---|
| 334 | gPad->SetFrameBorderMode(0);
|
|---|
| 335 | gPad->Divide(2,1);
|
|---|
| 336 |
|
|---|
| 337 | TVirtualPad *pad2 = gPad;
|
|---|
| 338 |
|
|---|
| 339 | // format left pad
|
|---|
| 340 | pad2->cd(1);
|
|---|
| 341 | gPad->SetBorderMode(0);
|
|---|
| 342 | gPad->SetFrameBorderMode(0);
|
|---|
| 343 | gPad->SetGridx();
|
|---|
| 344 | gPad->SetGridy();
|
|---|
| 345 |
|
|---|
| 346 | // Create histogram
|
|---|
| 347 | const Int_t n = resolution>0 ? TMath::Nint((max-min)/resolution) : 50;
|
|---|
| 348 |
|
|---|
| 349 | TH1F hist("Hist", Form("Distribution of %s", fDescription.IsNull() ? name.Data() : fDescription.Data()), n, min, max);
|
|---|
| 350 | hist.SetDirectory(0);
|
|---|
| 351 |
|
|---|
| 352 | // Fill data into histogra,
|
|---|
| 353 | for (int i=0; i<gt.GetN(); i++)
|
|---|
| 354 | hist.Fill(gt.GetY()[i]);
|
|---|
| 355 |
|
|---|
| 356 | // Format histogram
|
|---|
| 357 | if (fDescription.IsNull())
|
|---|
| 358 | hist.SetXTitle(name);
|
|---|
| 359 | hist.SetYTitle("Counts");
|
|---|
| 360 |
|
|---|
| 361 | // plot histogram
|
|---|
| 362 | hist.DrawCopy("");
|
|---|
| 363 |
|
|---|
| 364 | // format right pad
|
|---|
| 365 | pad2->cd(2);
|
|---|
| 366 | gPad->SetBorderMode(0);
|
|---|
| 367 | gPad->SetFrameBorderMode(0);
|
|---|
| 368 | gPad->SetGridy();
|
|---|
| 369 |
|
|---|
| 370 | // format graph
|
|---|
| 371 | TH1 *h2 = gz.GetHistogram();
|
|---|
| 372 |
|
|---|
| 373 | h2->SetXTitle("Zd");
|
|---|
| 374 | h2->SetYTitle(name);
|
|---|
| 375 |
|
|---|
| 376 | // draw graph
|
|---|
| 377 | gz.DrawClone("AP");
|
|---|
| 378 |
|
|---|
| 379 | if (gz0.GetN()>0)
|
|---|
| 380 | gz0.DrawClone("P");
|
|---|
| 381 | if (gz1.GetN()>0)
|
|---|
| 382 | gz1.DrawClone("P");
|
|---|
| 383 | }
|
|---|
| 384 |
|
|---|
| 385 | public:
|
|---|
| 386 | MPlot(MSQLMagic &server) : fServer(server), fDataSet(NULL),
|
|---|
| 387 | fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1), fGroupBy(kNone)
|
|---|
| 388 | {
|
|---|
| 389 | }
|
|---|
| 390 | ~MPlot()
|
|---|
| 391 | {
|
|---|
| 392 | if (fDataSet)
|
|---|
| 393 | delete fDataSet;
|
|---|
| 394 | }
|
|---|
| 395 | void SetDataSet(const TString filename)
|
|---|
| 396 | {
|
|---|
| 397 | if (fDataSet)
|
|---|
| 398 | {
|
|---|
| 399 | delete fDataSet;
|
|---|
| 400 | fDataSet = NULL;
|
|---|
| 401 | }
|
|---|
| 402 | if (!filename.IsNull())
|
|---|
| 403 | fDataSet = new MDataSet(filename);
|
|---|
| 404 | }
|
|---|
| 405 | void SetPlotRange(Float_t min, Float_t max, Int_t n=5) { fPlotMin = min; fPlotMax = max; }
|
|---|
| 406 | void SetHistRange(Float_t min, Float_t max) { fHistMin = min; fHistMax = max; }
|
|---|
| 407 | void SetRequestRange(const char *from="", const char *to="") { fRequestFrom = from; fRequestTo = to; }
|
|---|
| 408 | void SetRequestPeriod(Int_t n=-1) { fRequestPeriod = n; }
|
|---|
| 409 | void SetCondition(const char *cond="") { fCondition = cond; }
|
|---|
| 410 | void SetDescription(const char *d, const char *t=0) { fDescription = d; fNameTab = t; }
|
|---|
| 411 | void SetGroupBy(GroupBy_t b=kGroupByWeek) { fGroupBy=b; }
|
|---|
| 412 | void SetPrimaryDate(const char *ts) { fPrimaryDate=ts; }
|
|---|
| 413 | void SetPrimaryNumber(const char *ts) { fPrimaryNumber=ts; }
|
|---|
| 414 | void SetSecondary(const char *ts) { fSecondary=ts; }
|
|---|
| 415 |
|
|---|
| 416 | Int_t QueryKeyOfSource(TString src)
|
|---|
| 417 | {
|
|---|
| 418 | return fServer.QueryKeyOfName("Object", src, kFALSE);
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0)
|
|---|
| 422 | {
|
|---|
| 423 | TString named = fPrimaryDate;
|
|---|
| 424 | TString named2 = fSecondary;
|
|---|
| 425 | TString namev = value;
|
|---|
| 426 |
|
|---|
| 427 | TString tablev = namev(0, namev.First('.'));
|
|---|
| 428 | TString valuev = namev(namev.First('.')+1, namev.Length());
|
|---|
| 429 |
|
|---|
| 430 | TString tabled = named(0, named.First('.'));
|
|---|
| 431 | TString valued = named(named.First('.')+1, named.Length());
|
|---|
| 432 |
|
|---|
| 433 | TString query="SELECT ";
|
|---|
| 434 | switch (fGroupBy)
|
|---|
| 435 | {
|
|---|
| 436 | case kNone:
|
|---|
| 437 | case kGroupByPrimary:
|
|---|
| 438 | query += valued;
|
|---|
| 439 | break;
|
|---|
| 440 | case kGroupByHour:
|
|---|
| 441 | query += Form("DATE_FORMAT(%s, '%%Y-%%m-%%d %%H:30:00') AS %s ", fPrimaryDate.Data(), valued.Data());
|
|---|
| 442 | break;
|
|---|
| 443 | case kGroupByNight:
|
|---|
| 444 | query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data());
|
|---|
| 445 | break;
|
|---|
| 446 | case kGroupByWeek:
|
|---|
| 447 | query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", fPrimaryDate.Data(), valued.Data());
|
|---|
| 448 | break;
|
|---|
| 449 | case kGroupByMonth:
|
|---|
| 450 | query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data());
|
|---|
| 451 | break;
|
|---|
| 452 | case kGroupBySeason:
|
|---|
| 453 | //query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data());
|
|---|
| 454 | break;
|
|---|
| 455 | case kGroupByYear:
|
|---|
| 456 | query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-08-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data());
|
|---|
| 457 | break;
|
|---|
| 458 | }
|
|---|
| 459 |
|
|---|
| 460 | if (fGroupBy==kNone)
|
|---|
| 461 | {
|
|---|
| 462 | query += ", ";
|
|---|
| 463 | query += fSecondary;
|
|---|
| 464 | query += ", ";
|
|---|
| 465 | query += value;
|
|---|
| 466 | query += ", ";
|
|---|
| 467 | query += fPrimaryNumber;
|
|---|
| 468 | query += " ";
|
|---|
| 469 | }
|
|---|
| 470 | else
|
|---|
| 471 | {
|
|---|
| 472 | query += ", AVG(";
|
|---|
| 473 | query += fSecondary;
|
|---|
| 474 | query += "), AVG(";
|
|---|
| 475 | query += value;
|
|---|
| 476 | query += "), ";
|
|---|
| 477 | query += fPrimaryNumber;
|
|---|
| 478 | query += ", STD(";
|
|---|
| 479 | query += fSecondary;
|
|---|
| 480 | query += "), STD(";
|
|---|
| 481 | query += value;
|
|---|
| 482 | query += ") ";
|
|---|
| 483 | }
|
|---|
| 484 |
|
|---|
| 485 | query += Form("FROM %s ", tabled.Data());
|
|---|
| 486 |
|
|---|
| 487 | TString where(fCondition);
|
|---|
| 488 |
|
|---|
| 489 | const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull();
|
|---|
| 490 | if (interval)
|
|---|
| 491 | {
|
|---|
| 492 | if (!where.IsNull())
|
|---|
| 493 | where += " AND ";
|
|---|
| 494 | where += Form("%s BETWEEN '%s' AND '%s' ",
|
|---|
| 495 | fPrimaryDate.Data(), fRequestFrom.Data(), fRequestTo.Data());
|
|---|
| 496 | }
|
|---|
| 497 |
|
|---|
| 498 | if (!where.IsNull())
|
|---|
| 499 | where += " AND ";
|
|---|
| 500 | where += fCondition;
|
|---|
| 501 | where += " ";
|
|---|
| 502 |
|
|---|
| 503 | // ------------------------------
|
|---|
| 504 |
|
|---|
| 505 | query += fServer.GetJoins(tabled, query+" "+where);
|
|---|
| 506 |
|
|---|
| 507 | if (!where.IsNull())
|
|---|
| 508 | {
|
|---|
| 509 | query += "WHERE ";
|
|---|
| 510 | query += where;
|
|---|
| 511 | }
|
|---|
| 512 |
|
|---|
| 513 | if (fGroupBy!=kNone)
|
|---|
| 514 | {
|
|---|
| 515 | query += Form("GROUP BY %s ", valued.Data());
|
|---|
| 516 | //query += Form(" HAVING COUNT(%s)=(COUNT(*)+1)/2 ", valuev.Data());
|
|---|
| 517 | }
|
|---|
| 518 | query += Form("ORDER BY %s ", valued.Data());
|
|---|
| 519 |
|
|---|
| 520 | // ------------------------------
|
|---|
| 521 |
|
|---|
| 522 | TSQLResult *res = fServer.Query(query);
|
|---|
| 523 | if (!res)
|
|---|
| 524 | return kFALSE;
|
|---|
| 525 |
|
|---|
| 526 | if (max>min)
|
|---|
| 527 | PlotTable(*res, namev, min, max, resolution);
|
|---|
| 528 | else
|
|---|
| 529 | PlotTable(*res, namev, fPlotMin, fPlotMax, resolution);
|
|---|
| 530 |
|
|---|
| 531 | delete res;
|
|---|
| 532 | return kTRUE;
|
|---|
| 533 | }
|
|---|
| 534 | };
|
|---|
| 535 |
|
|---|
| 536 | void plotall(MPlot &plot, TString source)
|
|---|
| 537 | {
|
|---|
| 538 | // Setup here the values for timestamp and secondary (upper/right) plot
|
|---|
| 539 | plot.SetPrimaryDate("OpticalData.fTimestamp");
|
|---|
| 540 | plot.SetPrimaryNumber("OpticalData.fTimestamp");
|
|---|
| 541 | plot.SetSecondary("OpticalData.fZenithDistance");
|
|---|
| 542 |
|
|---|
| 543 | // This is the condition to take only the "ok" flagged data
|
|---|
| 544 | // and to restrict the query to a given source (if any)
|
|---|
| 545 | TString cond = "fStatusKEY=1";
|
|---|
| 546 | if (!source.IsNull())
|
|---|
| 547 | {
|
|---|
| 548 | const Int_t key = plot.QueryKeyOfSource(source);
|
|---|
| 549 | if (key<0)
|
|---|
| 550 | return;
|
|---|
| 551 | cond += Form(" AND Object.fObjectKEY=%d", key);
|
|---|
| 552 |
|
|---|
| 553 | }
|
|---|
| 554 | plot.SetCondition(cond);
|
|---|
| 555 |
|
|---|
| 556 | // Plot exposure
|
|---|
| 557 | plot.SetDescription("Exposure;T_{E} [s]", "Expo");
|
|---|
| 558 | plot.Plot("OpticalData.fExposure", 0, 900, 60);
|
|---|
| 559 |
|
|---|
| 560 | // plot sky level
|
|---|
| 561 | plot.SetDescription("Sky Level;B [s^{-1}]", "SkyLvl");
|
|---|
| 562 | plot.Plot("OpticalData.fSkyLevel/OpticalData.fExposure", 0, 5.0, 0.01);
|
|---|
| 563 |
|
|---|
| 564 | // plot FWHM
|
|---|
| 565 | plot.SetDescription("Full Width Half Maximum;FWHM [s^{-1}]", "Fwhm");
|
|---|
| 566 | plot.Plot("OpticalData.fFWHM/OpticalData.fExposure", 0, 0.05, 0.001);
|
|---|
| 567 |
|
|---|
| 568 | // plot Aperture Radius
|
|---|
| 569 | plot.SetDescription("Aperture Radius;R_{A}", "ApRad");
|
|---|
| 570 | plot.Plot("OpticalData.fApertureRadius", 0, 10, 1);
|
|---|
| 571 |
|
|---|
| 572 | /*
|
|---|
| 573 | // Plot instrumental magnitude
|
|---|
| 574 | plot.SetDescription("Instrumental Magnitude;M_{I}", "InstMag");
|
|---|
| 575 | plot.Plot("OpticalData.fInstrumentalMag", 0, 30, 0.5);
|
|---|
| 576 |
|
|---|
| 577 | // Plot error of instrumental magnitude
|
|---|
| 578 | plot.SetDescription("Instrumental Magnitude Error;\\sigma_{M}", "MagErr");
|
|---|
| 579 | plot.Plot("OpticalData.fInstrumentalMagErr", 0, 1, 0.01);
|
|---|
| 580 | */
|
|---|
| 581 |
|
|---|
| 582 | // Plot magnitude corrected for the exposure
|
|---|
| 583 | plot.SetDescription("m_{1};m_{1}", "M1");
|
|---|
| 584 | plot.Plot("OpticalData.fInstrumentalMag+2.5*log10(OpticalData.fExposure)", 10, 35, 0.2);
|
|---|
| 585 |
|
|---|
| 586 | // Now take out all points named */BL from further queries
|
|---|
| 587 | // And skip all sources the magnitude is not known
|
|---|
| 588 | cond += " AND Object.fObjectName NOT LIKE '%/BL' AND NOT ISNULL(Object.fMagnitude) ";
|
|---|
| 589 | plot.SetCondition(cond);
|
|---|
| 590 |
|
|---|
| 591 | // Formula to calculate the extinction
|
|---|
| 592 | TString ext("3080/25.0*pow(10, (OpticalData.fInstrumentalMag+2.5*log10(OpticalData.fExposure)-Object.fMagnitude)/-2.5)");
|
|---|
| 593 | // Add this to correct for the ZA dependancy
|
|---|
| 594 | // ext += "+0.0028*fZenithDistance-0.08";
|
|---|
| 595 |
|
|---|
| 596 | // Group all data of one image together and plot extinction
|
|---|
| 597 | plot.SetGroupBy(MPlot::kGroupByPrimary);
|
|---|
| 598 | plot.SetDescription("m_{1}-m_{true} (Extinction per Image);m_{1}-m_{true}", "ExtImg");
|
|---|
| 599 | plot.Plot(ext, 0.05, 1.2, 0.01);
|
|---|
| 600 |
|
|---|
| 601 | // Group data hourly together and plot extinction
|
|---|
| 602 | plot.SetGroupBy(MPlot::kGroupByHour);
|
|---|
| 603 | plot.SetDescription("m_{1}-m_{true} (Extinction per Hour);m_{1}-m_{true}", "ExtHour");
|
|---|
| 604 | plot.Plot(ext, 0.5, 1.2, 0.01);
|
|---|
| 605 |
|
|---|
| 606 | // Group data hourly together and plot extinction
|
|---|
| 607 | plot.SetGroupBy(MPlot::kGroupByNight);
|
|---|
| 608 | plot.SetDescription("m_{1}-m_{true} (Extinction per Night);m_{1}-m_{true}", "ExtNight");
|
|---|
| 609 | plot.Plot(ext, 0.5, 1.2, 0.01);
|
|---|
| 610 |
|
|---|
| 611 | // Group data monthly together and plot extinction
|
|---|
| 612 | plot.SetGroupBy(MPlot::kGroupByMonth);
|
|---|
| 613 | plot.SetDescription("m_{1}-m_{true} (Extinction per Month);m_{1}-m_{true}", "ExtMonth");
|
|---|
| 614 | plot.Plot(ext, 0.5, 1.2, 0.01);
|
|---|
| 615 |
|
|---|
| 616 | // Group data yearly together and plot extinction
|
|---|
| 617 | plot.SetGroupBy(MPlot::kGroupByYear);
|
|---|
| 618 | plot.SetDescription("m_{1}-m_{true} (Extinction per Year);m_{1}-m_{true}", "ExtYear");
|
|---|
| 619 | plot.Plot(ext, 0.5, 1.2, 0.01);
|
|---|
| 620 | }
|
|---|
| 621 |
|
|---|
| 622 | int plotoptical(TString from, TString to, const char *source=0)
|
|---|
| 623 | {
|
|---|
| 624 | TEnv env("sql.rc");
|
|---|
| 625 |
|
|---|
| 626 | MSQLMagic serv(env);
|
|---|
| 627 | if (!serv.IsConnected())
|
|---|
| 628 | {
|
|---|
| 629 | cout << "ERROR - Connection to database failed." << endl;
|
|---|
| 630 | return 0;
|
|---|
| 631 | }
|
|---|
| 632 |
|
|---|
| 633 | cout << "plotoptical" << endl;
|
|---|
| 634 | cout << "-----------" << endl;
|
|---|
| 635 | cout << endl;
|
|---|
| 636 | cout << "Connected to " << serv.GetName() << endl;
|
|---|
| 637 | cout << endl;
|
|---|
| 638 |
|
|---|
| 639 | MStatusDisplay *d = new MStatusDisplay;
|
|---|
| 640 | d->SetWindowName(serv.GetName());
|
|---|
| 641 | d->SetTitle(serv.GetName());
|
|---|
| 642 |
|
|---|
| 643 | MPlot plot(serv);
|
|---|
| 644 | // plot.SetDataSet(dataset);
|
|---|
| 645 | plot.SetDisplay(d);
|
|---|
| 646 | plot.SetRequestRange(from, to);
|
|---|
| 647 | plotall(plot, source);
|
|---|
| 648 | // Use this to create output plots automatically
|
|---|
| 649 | // d->SaveAsRoot("plotoptical.root");
|
|---|
| 650 | // d->SaveAsPS("plotoptical.ps");
|
|---|
| 651 |
|
|---|
| 652 | return 1;
|
|---|
| 653 | }
|
|---|
| 654 |
|
|---|
| 655 | int plotoptical(const char *source)
|
|---|
| 656 | {
|
|---|
| 657 | TEnv env("sql.rc");
|
|---|
| 658 |
|
|---|
| 659 | MSQLMagic serv(env);
|
|---|
| 660 | if (!serv.IsConnected())
|
|---|
| 661 | {
|
|---|
| 662 | cout << "ERROR - Connection to database failed." << endl;
|
|---|
| 663 | return 0;
|
|---|
| 664 | }
|
|---|
| 665 |
|
|---|
| 666 | cout << "plotoptical" << endl;
|
|---|
| 667 | cout << "-----------" << endl;
|
|---|
| 668 | cout << endl;
|
|---|
| 669 | cout << "Connected to " << serv.GetName() << endl;
|
|---|
| 670 | cout << endl;
|
|---|
| 671 |
|
|---|
| 672 | MStatusDisplay *d = new MStatusDisplay;
|
|---|
| 673 | d->SetWindowName(serv.GetName());
|
|---|
| 674 | d->SetTitle(serv.GetName());
|
|---|
| 675 |
|
|---|
| 676 | MPlot plot(serv);
|
|---|
| 677 | // plot.SetDataSet(ds);
|
|---|
| 678 | plot.SetDisplay(d);
|
|---|
| 679 | plot.SetRequestRange("", "");
|
|---|
| 680 | plotall(plot, source);
|
|---|
| 681 | // Use this to create output plots automatically
|
|---|
| 682 | // d->SaveAsRoot("plotoptical.root");
|
|---|
| 683 | // d->SaveAsPS("plotoptical.ps");
|
|---|
| 684 |
|
|---|
| 685 | return 1;
|
|---|
| 686 | }
|
|---|
| 687 |
|
|---|
| 688 | int plotoptical(Int_t period, const char *source="")
|
|---|
| 689 | {
|
|---|
| 690 | TEnv env("sql.rc");
|
|---|
| 691 |
|
|---|
| 692 | MSQLMagic serv(env);
|
|---|
| 693 | if (!serv.IsConnected())
|
|---|
| 694 | {
|
|---|
| 695 | cout << "ERROR - Connection to database failed." << endl;
|
|---|
| 696 | return 0;
|
|---|
| 697 | }
|
|---|
| 698 |
|
|---|
| 699 | cout << "plotoptical" << endl;
|
|---|
| 700 | cout << "-----------" << endl;
|
|---|
| 701 | cout << endl;
|
|---|
| 702 | cout << "Connected to " << serv.GetName() << endl;
|
|---|
| 703 | cout << endl;
|
|---|
| 704 |
|
|---|
| 705 | MStatusDisplay *d = new MStatusDisplay;
|
|---|
| 706 | d->SetWindowName(serv.GetName());
|
|---|
| 707 | d->SetTitle(serv.GetName());
|
|---|
| 708 |
|
|---|
| 709 | MPlot plot(serv);
|
|---|
| 710 | // plot.SetDataSet(dataset);
|
|---|
| 711 | plot.SetDisplay(d);
|
|---|
| 712 | plot.SetRequestPeriod(period);
|
|---|
| 713 | plotall(plot, source);
|
|---|
| 714 |
|
|---|
| 715 | // Use this to create output plots automatically
|
|---|
| 716 | // d->SaveAsRoot("plotoptical.root");
|
|---|
| 717 | // d->SaveAsPS("plotoptical.ps");
|
|---|
| 718 |
|
|---|
| 719 | return 1;
|
|---|
| 720 | }
|
|---|
| 721 |
|
|---|
| 722 | int plotoptical()
|
|---|
| 723 | {
|
|---|
| 724 | return plotoptical("", "");
|
|---|
| 725 | }
|
|---|