| 1 | /* ======================================================================== *\
|
|---|
| 2 | !
|
|---|
| 3 | ! *
|
|---|
| 4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 8 | ! *
|
|---|
| 9 | ! * Permission to use, copy, modify and distribute this software and its
|
|---|
| 10 | ! * documentation for any purpose is hereby granted without fee,
|
|---|
| 11 | ! * provided that the above copyright notice appear in all copies and
|
|---|
| 12 | ! * that both that copyright notice and this permission notice appear
|
|---|
| 13 | ! * in supporting documentation. It is provided "as is" without express
|
|---|
| 14 | ! * or implied warranty.
|
|---|
| 15 | ! *
|
|---|
| 16 | !
|
|---|
| 17 | !
|
|---|
| 18 | ! Author(s): Thomas Bretz, 05/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2005
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MHWeather
|
|---|
| 28 | //
|
|---|
| 29 | // Display weather data and the corresponding event rate
|
|---|
| 30 | //
|
|---|
| 31 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 32 | #include "MHWeather.h"
|
|---|
| 33 |
|
|---|
| 34 | #include <TPad.h>
|
|---|
| 35 | #include <TCanvas.h>
|
|---|
| 36 | #include <TGaxis.h>
|
|---|
| 37 |
|
|---|
| 38 | #include "MLog.h"
|
|---|
| 39 | #include "MLogManip.h"
|
|---|
| 40 |
|
|---|
| 41 | #include "MParList.h"
|
|---|
| 42 |
|
|---|
| 43 | #include "MTime.h"
|
|---|
| 44 | #include "MReportCC.h"
|
|---|
| 45 | #include "MEventRate.h"
|
|---|
| 46 |
|
|---|
| 47 | ClassImp(MHWeather);
|
|---|
| 48 |
|
|---|
| 49 | using namespace std;
|
|---|
| 50 |
|
|---|
| 51 | void MHWeather::ResetGraph(TGraph &g) const
|
|---|
| 52 | {
|
|---|
| 53 | g.Set(1);
|
|---|
| 54 | g.SetPoint(0, 0, 0); // Dummy Point
|
|---|
| 55 | g.SetEditable(); // Used as flag: First point? yes/no
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | void MHWeather::InitGraph(TGraph &g) const
|
|---|
| 59 | {
|
|---|
| 60 | ResetGraph(g);
|
|---|
| 61 | g.SetMarkerStyle(kFullDotMedium);
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | void MHWeather::AddPoint(TGraph &g, Double_t x, Double_t y) const
|
|---|
| 65 | {
|
|---|
| 66 | if (g.IsEditable())
|
|---|
| 67 | {
|
|---|
| 68 | g.RemovePoint(0);
|
|---|
| 69 | g.SetEditable(kFALSE);
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | g.SetPoint(g.GetN(), x, y);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | // --------------------------------------------------------------------------
|
|---|
| 76 | //
|
|---|
| 77 | // Setup histograms
|
|---|
| 78 | //
|
|---|
| 79 | MHWeather::MHWeather(const char *name, const char *title)
|
|---|
| 80 | {
|
|---|
| 81 | fName = name ? name : "MHWeather";
|
|---|
| 82 | fTitle = title ? title : "Graphs for weather data";
|
|---|
| 83 |
|
|---|
| 84 | // Init Graphs
|
|---|
| 85 |
|
|---|
| 86 | fHumidity.SetNameTitle("Humidity", "Humidity");
|
|---|
| 87 | fTemperature.SetNameTitle("Temperature", "Temperature");
|
|---|
| 88 | fSolarRadiation.SetNameTitle("SolarRadiation", "Solar Radiation");
|
|---|
| 89 | fWindSpeed.SetNameTitle("WindSpeed", "Wind Speed");
|
|---|
| 90 | fEventRate.SetNameTitle("EventRate", "Event Rate at CC-REPORT time");
|
|---|
| 91 |
|
|---|
| 92 | InitGraph(fHumidity);
|
|---|
| 93 | InitGraph(fTemperature);
|
|---|
| 94 | InitGraph(fSolarRadiation);
|
|---|
| 95 | InitGraph(fWindSpeed);
|
|---|
| 96 | InitGraph(fEventRate);
|
|---|
| 97 |
|
|---|
| 98 | fHumidity.SetMarkerColor(kBlue);
|
|---|
| 99 | fTemperature.SetMarkerColor(kRed);
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | // --------------------------------------------------------------------------
|
|---|
| 103 | //
|
|---|
| 104 | // Setup the Binning for the histograms automatically if the correct
|
|---|
| 105 | // instances of MBinning
|
|---|
| 106 | //
|
|---|
| 107 | Bool_t MHWeather::SetupFill(const MParList *plist)
|
|---|
| 108 | {
|
|---|
| 109 | fReport = (MReportCC*)plist->FindObject("MReportCC");
|
|---|
| 110 | if (!fReport)
|
|---|
| 111 | {
|
|---|
| 112 | *fLog << warn << "MReportCC not found... abort." << endl;
|
|---|
| 113 | return kFALSE;
|
|---|
| 114 | }
|
|---|
| 115 | fRate = (MEventRate*)plist->FindObject("MEventRate");
|
|---|
| 116 | if (!fRate)
|
|---|
| 117 | {
|
|---|
| 118 | *fLog << warn << "MEventRate not found... abort." << endl;
|
|---|
| 119 | return kFALSE;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | // Reset Graphs
|
|---|
| 123 | ResetGraph(fHumidity);
|
|---|
| 124 | ResetGraph(fTemperature);
|
|---|
| 125 | ResetGraph(fSolarRadiation);
|
|---|
| 126 | ResetGraph(fWindSpeed);
|
|---|
| 127 | ResetGraph(fEventRate);
|
|---|
| 128 |
|
|---|
| 129 | return kTRUE;
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | // --------------------------------------------------------------------------
|
|---|
| 133 | //
|
|---|
| 134 | // Fill the histograms with data from a MMuonCalibPar and
|
|---|
| 135 | // MMuonSearchPar container.
|
|---|
| 136 | //
|
|---|
| 137 | Bool_t MHWeather::Fill(const MParContainer *par, const Stat_t w)
|
|---|
| 138 | {
|
|---|
| 139 | const MTime *t = dynamic_cast<const MTime*>(par);
|
|---|
| 140 | if (!t)
|
|---|
| 141 | {
|
|---|
| 142 | *fLog << err <<"MHWeather::Fill - ERROR: MTime not given as argument... abort." << endl;
|
|---|
| 143 | return kERROR;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | const Double_t tm = t->GetAxisTime();
|
|---|
| 147 |
|
|---|
| 148 | AddPoint(fTemperature, tm, fReport->GetTemperature());
|
|---|
| 149 | AddPoint(fHumidity, tm, fReport->GetHumidity());
|
|---|
| 150 | AddPoint(fSolarRadiation, tm, fReport->GetSolarRadiation());
|
|---|
| 151 | AddPoint(fWindSpeed, tm, fReport->GetWindSpeed());
|
|---|
| 152 | AddPoint(fEventRate, tm, fRate->GetRate());
|
|---|
| 153 |
|
|---|
| 154 | return kTRUE;
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | void MHWeather::DrawGraph(TGraph &g, const char *y) const
|
|---|
| 158 | {
|
|---|
| 159 | TH1 *h = g.GetHistogram();
|
|---|
| 160 | if (h)
|
|---|
| 161 | {
|
|---|
| 162 | delete h;
|
|---|
| 163 | g.SetHistogram(0);
|
|---|
| 164 | h = g.GetHistogram();
|
|---|
| 165 | }
|
|---|
| 166 | if (h)
|
|---|
| 167 | {
|
|---|
| 168 | TAxis *axe = h->GetXaxis();
|
|---|
| 169 | axe->SetLabelSize(0.033);
|
|---|
| 170 | axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
|
|---|
| 171 | axe->SetTimeDisplay(1);
|
|---|
| 172 | axe->SetTitle("Time");
|
|---|
| 173 | if (y)
|
|---|
| 174 | h->SetYTitle(y);
|
|---|
| 175 | }
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | // --------------------------------------------------------------------------
|
|---|
| 179 | //
|
|---|
| 180 | // Update position of an axis on the right side of the histogram
|
|---|
| 181 | //
|
|---|
| 182 | void MHWeather::UpdateRightAxis(TGraph &g) const
|
|---|
| 183 | {
|
|---|
| 184 | TH1 &h = *g.GetHistogram();
|
|---|
| 185 |
|
|---|
| 186 | const Double_t max = h.GetMaximum();
|
|---|
| 187 | if (max==0)
|
|---|
| 188 | return;
|
|---|
| 189 |
|
|---|
| 190 | TGaxis *axis = (TGaxis*)gPad->FindObject("RightAxis");
|
|---|
| 191 | if (!axis)
|
|---|
| 192 | return;
|
|---|
| 193 |
|
|---|
| 194 | axis->SetX1(g.GetXaxis()->GetXmax());
|
|---|
| 195 | axis->SetX2(g.GetXaxis()->GetXmax());
|
|---|
| 196 | axis->SetY1(gPad->GetUymin());
|
|---|
| 197 | axis->SetY2(gPad->GetUymax());
|
|---|
| 198 | axis->SetWmax(max);
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | // --------------------------------------------------------------------------
|
|---|
| 202 | //
|
|---|
| 203 | // Draw an axis on the right side of the histogram
|
|---|
| 204 | //
|
|---|
| 205 | void MHWeather::DrawRightAxis(const char *title) const
|
|---|
| 206 | {
|
|---|
| 207 | TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(),
|
|---|
| 208 | gPad->GetUxmax(), gPad->GetUymax(),
|
|---|
| 209 | 0, 1, 510, "+L");
|
|---|
| 210 | axis->SetName("RightAxis");
|
|---|
| 211 | axis->SetTitle(title);
|
|---|
| 212 | axis->SetTitleOffset(0.9);
|
|---|
| 213 | axis->SetTextColor(kRed);
|
|---|
| 214 | axis->SetBit(kCanDelete);
|
|---|
| 215 | axis->Draw();
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | // --------------------------------------------------------------------------
|
|---|
| 219 | //
|
|---|
| 220 | // This displays the TGraph like you expect it to be (eg. time on the axis)
|
|---|
| 221 | // It should also make sure, that the displayed time always is UTC and
|
|---|
| 222 | // not local time...
|
|---|
| 223 | //
|
|---|
| 224 | void MHWeather::Draw(Option_t *opt)
|
|---|
| 225 | {
|
|---|
| 226 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
|---|
| 227 | pad->SetBorderMode(0);
|
|---|
| 228 |
|
|---|
| 229 | AppendPad();
|
|---|
| 230 |
|
|---|
| 231 | pad->Divide(2,2);
|
|---|
| 232 |
|
|---|
| 233 | pad->cd(1);
|
|---|
| 234 | gPad->SetBorderMode(0);
|
|---|
| 235 | gPad->SetGridx();
|
|---|
| 236 | gPad->SetGridy();
|
|---|
| 237 | fHumidity.Draw("AP");
|
|---|
| 238 | fTemperature.Draw("P");
|
|---|
| 239 | DrawRightAxis("T [\\circ C]");
|
|---|
| 240 |
|
|---|
| 241 | pad->cd(2);
|
|---|
| 242 | gPad->SetBorderMode(0);
|
|---|
| 243 | gPad->SetGridx();
|
|---|
| 244 | gPad->SetGridy();
|
|---|
| 245 | fSolarRadiation.Draw("AP");
|
|---|
| 246 |
|
|---|
| 247 | pad->cd(3);
|
|---|
| 248 | gPad->SetBorderMode(0);
|
|---|
| 249 | gPad->SetGridx();
|
|---|
| 250 | gPad->SetGridy();
|
|---|
| 251 | fEventRate.Draw("AP");
|
|---|
| 252 |
|
|---|
| 253 | pad->cd(4);
|
|---|
| 254 | gPad->SetBorderMode(0);
|
|---|
| 255 | gPad->SetGridx();
|
|---|
| 256 | gPad->SetGridy();
|
|---|
| 257 | fWindSpeed.Draw("AP");
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | void MHWeather::Paint(Option_t *o)
|
|---|
| 261 | {
|
|---|
| 262 | // If this is set to early the plot remains empty in root 5.12/00
|
|---|
| 263 | if (fHumidity.GetN()>0)
|
|---|
| 264 | {
|
|---|
| 265 | fHumidity.SetMinimum(0);
|
|---|
| 266 | fHumidity.SetMaximum(100);
|
|---|
| 267 | }
|
|---|
| 268 | if (fTemperature.GetN()>0)
|
|---|
| 269 | {
|
|---|
| 270 | fTemperature.SetMinimum(-25);
|
|---|
| 271 | fTemperature.SetMaximum(45);
|
|---|
| 272 | }
|
|---|
| 273 | if (fWindSpeed.GetN()>0)
|
|---|
| 274 | fWindSpeed.SetMinimum(0);
|
|---|
| 275 | if (fSolarRadiation.GetN()>0)
|
|---|
| 276 | fSolarRadiation.SetMinimum(0);
|
|---|
| 277 | if (fEventRate.GetN()>0)
|
|---|
| 278 | fEventRate.SetMinimum(0);
|
|---|
| 279 |
|
|---|
| 280 | DrawGraph(fHumidity, "H [%]");
|
|---|
| 281 | DrawGraph(fSolarRadiation, "R [W/m^{2}]");
|
|---|
| 282 | DrawGraph(fTemperature, "T [\\circ C]");
|
|---|
| 283 | DrawGraph(fWindSpeed, "km/h");
|
|---|
| 284 | DrawGraph(fEventRate, "f [Hz]");
|
|---|
| 285 |
|
|---|
| 286 | gPad->cd(1);
|
|---|
| 287 |
|
|---|
| 288 | if (gPad)
|
|---|
| 289 | {
|
|---|
| 290 | fHumidity.GetHistogram()->GetYaxis()->SetTitleColor(kBlue);
|
|---|
| 291 | UpdateRightAxis(fTemperature);
|
|---|
| 292 | }
|
|---|
| 293 | }
|
|---|