| 1 | /* ======================================================================== *\
|
|---|
| 2 | ! $Name: not supported by cvs2svn $:$Id: plotoptical.C,v 1.11 2009-01-27 13:56:15 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 "plotdb.C"
|
|---|
| 81 |
|
|---|
| 82 | void plotalloptical(MPlot &plot, TString source)
|
|---|
| 83 | {
|
|---|
| 84 | // Setup here the values for timestamp and secondary (upper/right) plot
|
|---|
| 85 | plot.SetPrimaryDate("OpticalData.fTimestamp");
|
|---|
| 86 | plot.SetPrimaryNumber("OpticalData.fTimestamp");
|
|---|
| 87 | plot.SetSecondary("OpticalData.fZenithDistance");
|
|---|
| 88 |
|
|---|
| 89 | // This is the condition to take only the "ok" flagged data
|
|---|
| 90 | // and to restrict the query to a given source (if any)
|
|---|
| 91 | TString cond = "fStatusKEY=1 AND fTelescopeKEY=1 AND fCCDKEY=1 AND fFilterKEY=1";
|
|---|
| 92 | if (!source.IsNull())
|
|---|
| 93 | {
|
|---|
| 94 | const Int_t key = plot.GetServer().QueryKeyOfName("Object", source, kFALSE);
|
|---|
| 95 | if (key<0)
|
|---|
| 96 | return;
|
|---|
| 97 | cond += Form(" AND Object.fObjectKEY=%d", key);
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | plot.SetCondition(cond);
|
|---|
| 101 |
|
|---|
| 102 | // Plot exposure
|
|---|
| 103 | plot.SetDescription("Exposure;T_{E} [s]", "Expo");
|
|---|
| 104 | plot.Plot("OpticalData.fExposure", 0, 900, 60);
|
|---|
| 105 |
|
|---|
| 106 | // plot sky level
|
|---|
| 107 | plot.SetDescription("Sky Level;B [s^{-1}]", "SkyLvl");
|
|---|
| 108 | plot.Plot("OpticalData.fSkyLevel/OpticalData.fExposure", 0, 5.0, 0.01);
|
|---|
| 109 |
|
|---|
| 110 | // plot FWHM
|
|---|
| 111 | plot.SetDescription("Full Width Half Maximum;FWHM [s^{-1}]", "Fwhm");
|
|---|
| 112 | plot.Plot("OpticalData.fFWHM/OpticalData.fExposure", 0, 0.05, 0.001);
|
|---|
| 113 |
|
|---|
| 114 | // plot Aperture Radius
|
|---|
| 115 | plot.SetDescription("Aperture Radius;R_{A}", "ApRad");
|
|---|
| 116 | plot.Plot("OpticalData.fApertureRadius", 0, 10, 1);
|
|---|
| 117 |
|
|---|
| 118 | /*
|
|---|
| 119 | // Plot instrumental magnitude
|
|---|
| 120 | plot.SetDescription("Instrumental Magnitude;M_{I}", "InstMag");
|
|---|
| 121 | plot.Plot("OpticalData.fInstrumentalMag", 0, 30, 0.5);
|
|---|
| 122 |
|
|---|
| 123 | // Plot error of instrumental magnitude
|
|---|
| 124 | plot.SetDescription("Instrumental Magnitude Error;\\sigma_{M}", "MagErr");
|
|---|
| 125 | plot.Plot("OpticalData.fInstrumentalMagErr", 0, 1, 0.01);
|
|---|
| 126 | */
|
|---|
| 127 |
|
|---|
| 128 | // Plot magnitude corrected for the exposure
|
|---|
| 129 | plot.SetDescription("m_{1};m_{1}", "M1");
|
|---|
| 130 | plot.Plot("OpticalData.fInstrumentalMag+2.5*log10(OpticalData.fExposure)", 10, 35, 0.2);
|
|---|
| 131 |
|
|---|
| 132 | // Now take out all points named */BL from further queries
|
|---|
| 133 | // And skip all sources the magnitude is not known
|
|---|
| 134 | cond += " AND Object.fObjectName NOT LIKE '%/BL' AND NOT ISNULL(Object.fMagnitude) ";
|
|---|
| 135 | plot.SetCondition(cond);
|
|---|
| 136 |
|
|---|
| 137 | // Formula to calculate the extinction
|
|---|
| 138 | TString ext("3080/25.0*pow(10, (OpticalData.fInstrumentalMag+2.5*log10(OpticalData.fExposure)-Object.fMagnitude)/-2.5)");
|
|---|
| 139 | // Add this to correct for the ZA dependancy
|
|---|
| 140 | // ext += "+0.0028*fZenithDistance-0.08";
|
|---|
| 141 |
|
|---|
| 142 | // Group all data of one image together and plot extinction
|
|---|
| 143 | plot.SetGroupBy(MPlot::kGroupByPrimary);
|
|---|
| 144 | plot.SetDescription("m_{1}-m_{true} (Extinction per Image);m_{1}-m_{true}", "ExtImg");
|
|---|
| 145 | plot.Plot(ext, 0.05, 1.2, 0.01);
|
|---|
| 146 |
|
|---|
| 147 | // Group data hourly together and plot extinction
|
|---|
| 148 | plot.SetGroupBy(MPlot::kGroupByHour);
|
|---|
| 149 | plot.SetDescription("m_{1}-m_{true} (Extinction per Hour);m_{1}-m_{true}", "ExtHour");
|
|---|
| 150 | plot.Plot(ext, 0.5, 1.2, 0.01);
|
|---|
| 151 |
|
|---|
| 152 | // Group data hourly together and plot extinction
|
|---|
| 153 | plot.SetGroupBy(MPlot::kGroupByNight);
|
|---|
| 154 | plot.SetDescription("m_{1}-m_{true} (Extinction per Night);m_{1}-m_{true}", "ExtNight");
|
|---|
| 155 | plot.Plot(ext, 0.5, 1.2, 0.01);
|
|---|
| 156 |
|
|---|
| 157 | // Group data monthly together and plot extinction
|
|---|
| 158 | plot.SetGroupBy(MPlot::kGroupByMonth);
|
|---|
| 159 | plot.SetDescription("m_{1}-m_{true} (Extinction per Month);m_{1}-m_{true}", "ExtMonth");
|
|---|
| 160 | plot.Plot(ext, 0.5, 1.2, 0.01);
|
|---|
| 161 |
|
|---|
| 162 | // Group data yearly together and plot extinction
|
|---|
| 163 | plot.SetGroupBy(MPlot::kGroupByYear);
|
|---|
| 164 | plot.SetDescription("m_{1}-m_{true} (Extinction per Year);m_{1}-m_{true}", "ExtYear");
|
|---|
| 165 | plot.Plot(ext, 0.5, 1.2, 0.01);
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | int plotoptical(TString from, TString to, const char *source=0)
|
|---|
| 169 | {
|
|---|
| 170 | MSQLMagic serv("sql.rc");
|
|---|
| 171 | if (!serv.IsConnected())
|
|---|
| 172 | {
|
|---|
| 173 | cout << "ERROR - Connection to database failed." << endl;
|
|---|
| 174 | return 0;
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | cout << "plotoptical" << endl;
|
|---|
| 178 | cout << "-----------" << endl;
|
|---|
| 179 | cout << endl;
|
|---|
| 180 | cout << "Connected to " << serv.GetName() << endl;
|
|---|
| 181 | cout << endl;
|
|---|
| 182 |
|
|---|
| 183 | MStatusDisplay *d = new MStatusDisplay;
|
|---|
| 184 | d->SetWindowName(serv.GetName());
|
|---|
| 185 | d->SetTitle(serv.GetName());
|
|---|
| 186 |
|
|---|
| 187 | MPlot plot(serv);
|
|---|
| 188 | // plot.SetDataSet(dataset);
|
|---|
| 189 | plot.SetDisplay(d);
|
|---|
| 190 | plot.SetRequestRange(from, to);
|
|---|
| 191 | plotalloptical(plot, source);
|
|---|
| 192 | // Use this to create output plots automatically
|
|---|
| 193 | d->SaveAsRoot("plotoptical.root");
|
|---|
| 194 | // d->SaveAsPS("plotoptical.ps");
|
|---|
| 195 |
|
|---|
| 196 | return 1;
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | int plotoptical(const char *source, TString path)
|
|---|
| 200 | {
|
|---|
| 201 | MSQLMagic serv("sql.rc");
|
|---|
| 202 | if (!serv.IsConnected())
|
|---|
| 203 | {
|
|---|
| 204 | cout << "ERROR - Connection to database failed." << endl;
|
|---|
| 205 | return 0;
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | cout << "plotoptical" << endl;
|
|---|
| 209 | cout << "-----------" << endl;
|
|---|
| 210 | cout << endl;
|
|---|
| 211 | cout << "Connected to " << serv.GetName() << endl;
|
|---|
| 212 | cout << endl;
|
|---|
| 213 |
|
|---|
| 214 | MStatusDisplay *d = new MStatusDisplay;
|
|---|
| 215 | d->SetWindowName(serv.GetName());
|
|---|
| 216 | d->SetTitle(serv.GetName());
|
|---|
| 217 |
|
|---|
| 218 | MPlot plot(serv);
|
|---|
| 219 | // plot.SetDataSet(ds);
|
|---|
| 220 | plot.SetDisplay(d);
|
|---|
| 221 | plot.SetRequestRange("", "");
|
|---|
| 222 | plotalloptical(plot, source);
|
|---|
| 223 | // Use this to create output plots automatically
|
|---|
| 224 | d->SaveAsRoot("plotoptical.root");
|
|---|
| 225 | // d->SaveAsPS("plotoptical.ps");
|
|---|
| 226 |
|
|---|
| 227 | return 1;
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | int plotoptical(Int_t period, const char *source="")
|
|---|
| 231 | {
|
|---|
| 232 | MSQLMagic serv("sql.rc");
|
|---|
| 233 | if (!serv.IsConnected())
|
|---|
| 234 | {
|
|---|
| 235 | cout << "ERROR - Connection to database failed." << endl;
|
|---|
| 236 | return 0;
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | cout << "plotoptical" << endl;
|
|---|
| 240 | cout << "-----------" << endl;
|
|---|
| 241 | cout << endl;
|
|---|
| 242 | cout << "Connected to " << serv.GetName() << endl;
|
|---|
| 243 | cout << endl;
|
|---|
| 244 |
|
|---|
| 245 | MStatusDisplay *d = new MStatusDisplay;
|
|---|
| 246 | d->SetWindowName(serv.GetName());
|
|---|
| 247 | d->SetTitle(serv.GetName());
|
|---|
| 248 |
|
|---|
| 249 | MPlot plot(serv);
|
|---|
| 250 | // plot.SetDataSet(dataset);
|
|---|
| 251 | plot.SetDisplay(d);
|
|---|
| 252 | plot.SetRequestPeriod(period);
|
|---|
| 253 | plotalloptical(plot, source);
|
|---|
| 254 |
|
|---|
| 255 | // Use this to create output plots automatically
|
|---|
| 256 | d->SaveAsRoot("plotoptical.root");
|
|---|
| 257 | // d->SaveAsPS("plotoptical.ps");
|
|---|
| 258 |
|
|---|
| 259 | return 1;
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | int plotoptical(TString path)
|
|---|
| 263 | {
|
|---|
| 264 | MSQLMagic serv("sql.rc");
|
|---|
| 265 | if (!serv.IsConnected())
|
|---|
| 266 | {
|
|---|
| 267 | cout << "ERROR - Connection to database failed." << endl;
|
|---|
| 268 | return 0;
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | cout << "plotoptical" << endl;
|
|---|
| 272 | cout << "-----------" << endl;
|
|---|
| 273 | cout << endl;
|
|---|
| 274 | cout << "Connected to " << serv.GetName() << endl;
|
|---|
| 275 | cout << endl;
|
|---|
| 276 |
|
|---|
| 277 | MStatusDisplay *d = new MStatusDisplay;
|
|---|
| 278 | d->SetWindowName(serv.GetName());
|
|---|
| 279 | d->SetTitle(serv.GetName());
|
|---|
| 280 |
|
|---|
| 281 | MPlot plot(serv);
|
|---|
| 282 | // plot.SetDataSet(dataset);
|
|---|
| 283 | plot.SetDisplay(d);
|
|---|
| 284 | //plot.SetRequestPeriod(period);
|
|---|
| 285 | plotalloptical(plot, 0);
|
|---|
| 286 |
|
|---|
| 287 | // Use this to create output plots automatically
|
|---|
| 288 | d->SaveAsRoot(path+"plotoptical.root");
|
|---|
| 289 | // d->SaveAsPS("plotoptical.ps");
|
|---|
| 290 |
|
|---|
| 291 | return 1;
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | int plotoptical()
|
|---|
| 295 | {
|
|---|
| 296 | return plotoptical("", "");
|
|---|
| 297 | }
|
|---|