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