source: trunk/Mars/mhist/MHWeather.cc@ 13831

Last change on this file since 13831 was 9153, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 9.3 KB
Line 
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-2008
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHWeather
28//
29// Display weather and pyrometer data and the corresponding event rate
30//
31// Class Version 2:
32// ----------------
33// - fSolarRadiation
34// + fCloudiness
35// + fTempSky
36// + fTempAir
37//
38////////////////////////////////////////////////////////////////////////////
39#include "MHWeather.h"
40
41#include <TH1.h>
42#include <TPad.h>
43#include <TCanvas.h>
44#include <TGaxis.h>
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49#include "MParList.h"
50
51#include "MTime.h"
52#include "MReportCC.h"
53#include "MReportPyrometer.h"
54#include "MEventRate.h"
55
56ClassImp(MHWeather);
57
58using namespace std;
59
60void MHWeather::ResetGraph(TGraph &g) const
61{
62 g.Set(1);
63 g.SetPoint(0, 0, 0); // Dummy Point
64 g.SetEditable(); // Used as flag: First point? yes/no
65}
66
67void MHWeather::InitGraph(TGraph &g) const
68{
69 ResetGraph(g);
70 g.SetMarkerStyle(kFullDotMedium);
71}
72
73void MHWeather::AddPoint(TGraph &g, Double_t x, Double_t y) const
74{
75 if (g.IsEditable())
76 {
77 g.RemovePoint(0);
78 g.SetEditable(kFALSE);
79 }
80
81 g.SetPoint(g.GetN(), x, y);
82}
83
84// --------------------------------------------------------------------------
85//
86// Setup histograms
87//
88MHWeather::MHWeather(const char *name, const char *title)
89: fReportCC(0), fReportPyro(0), fRate(0)
90{
91 fName = name ? name : "MHWeather";
92 fTitle = title ? title : "Graphs for weather data";
93
94 // Init Graphs
95
96 fHumidity.SetNameTitle("Humidity", "Humidity");
97 fTemperature.SetNameTitle("Temperature", "Temperature (red=weather station, black=pyrometer, blue=sky)");
98 fWindSpeed.SetNameTitle("WindSpeed", "Wind Speed");
99
100 fEventRate.SetNameTitle("EventRate", "Event Rate at CC-REPORT time");
101
102 fCloudiness.SetNameTitle("Cloudiness", "Cloudiness / Humidity");
103 fTempAir.SetNameTitle("TempAir", "Air temperature from Pyrometer");
104 fTempSky.SetNameTitle("TempSky", "Sky temperature from Pyrometer");
105
106 InitGraph(fHumidity);
107 InitGraph(fTemperature);
108 InitGraph(fWindSpeed);
109
110 InitGraph(fEventRate);
111
112 InitGraph(fCloudiness);
113 InitGraph(fTempAir);
114 InitGraph(fTempSky);
115
116 fHumidity.SetMarkerColor(kBlue);
117 fTemperature.SetMarkerColor(kRed);
118 fTempSky.SetMarkerColor(kBlue);
119}
120
121// --------------------------------------------------------------------------
122//
123// Setup the Binning for the histograms automatically if the correct
124// instances of MBinning
125//
126Bool_t MHWeather::SetupFill(const MParList *plist)
127{
128 // Remark: This is called twice in the star-eventloop!
129 fReportCC = (MReportCC*)plist->FindObject("MReportCC");
130 if (!fReportCC)
131 {
132 *fLog << warn << "MReportCC not found... abort." << endl;
133 return kFALSE;
134 }
135 fRate = (MEventRate*)plist->FindObject("MEventRate");
136 if (!fRate)
137 {
138 *fLog << warn << "MEventRate not found... abort." << endl;
139 return kFALSE;
140 }
141
142 fReportPyro = (MReportPyrometer*)plist->FindObject("MReportPyrometer");
143 if (!fReportPyro)
144 *fLog << warn << "MReportPyrometer not found..." << endl;
145
146 // Reset Graphs
147 ResetGraph(fHumidity);
148 ResetGraph(fTemperature);
149 ResetGraph(fWindSpeed);
150 ResetGraph(fEventRate);
151 ResetGraph(fCloudiness);
152 ResetGraph(fTempAir);
153 ResetGraph(fTempSky);
154
155 return kTRUE;
156}
157
158// --------------------------------------------------------------------------
159//
160// Fill the histograms with data from a MMuonCalibPar and
161// MMuonSearchPar container.
162//
163Int_t MHWeather::Fill(const MParContainer *par, const Stat_t w)
164{
165 const MTime *t = dynamic_cast<const MTime*>(par);
166 if (!t)
167 {
168 *fLog << err <<"MHWeather::Fill - ERROR: MTime not given as argument... abort." << endl;
169 return kERROR;
170 }
171
172 const Double_t tm = t->GetAxisTime();
173
174 AddPoint(fEventRate, tm, fRate->GetRate());
175
176 if (TString(t->GetName())=="MTimeCC")
177 {
178 AddPoint(fTemperature, tm, fReportCC->GetTemperature());
179 AddPoint(fHumidity, tm, fReportCC->GetHumidity());
180 AddPoint(fWindSpeed, tm, fReportCC->GetWindSpeed());
181 }
182
183 if (TString(t->GetName())=="MTimePyrometer" && fReportPyro)
184 {
185 AddPoint(fCloudiness, tm, fReportPyro->GetCloudiness());
186 AddPoint(fTempAir, tm, fReportPyro->GetTempAir());
187 AddPoint(fTempSky, tm, fReportPyro->GetTempSky()-200);
188 }
189
190 return kTRUE;
191}
192
193void MHWeather::DrawGraph(TGraph &g, const char *y) const
194{
195 TH1 *h = g.GetHistogram();
196 if (h)
197 {
198 delete h;
199 g.SetHistogram(0);
200 h = g.GetHistogram();
201 }
202 if (h)
203 {
204 TAxis *axe = h->GetXaxis();
205 axe->SetLabelSize(0.033);
206 axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
207 axe->SetTimeDisplay(1);
208 axe->SetTitle("Time");
209 if (y)
210 h->SetYTitle(y);
211 }
212}
213
214// --------------------------------------------------------------------------
215//
216// Update position of an axis on the right side of the histogram
217//
218void MHWeather::UpdateRightAxis(TGraph &g) const
219{
220 TH1 &h = *g.GetHistogram();
221
222 const Double_t max = h.GetMaximum();
223 if (max==0)
224 return;
225
226 TGaxis *axis = (TGaxis*)gPad->FindObject("RightAxis");
227 if (!axis)
228 return;
229
230 axis->SetX1(g.GetXaxis()->GetXmax());
231 axis->SetX2(g.GetXaxis()->GetXmax());
232 axis->SetY1(gPad->GetUymin());
233 axis->SetY2(gPad->GetUymax());
234 axis->SetWmax(max);
235}
236
237// --------------------------------------------------------------------------
238//
239// Draw an axis on the right side of the histogram
240//
241void MHWeather::DrawRightAxis(const char *title, Int_t col) const
242{
243 TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(),
244 gPad->GetUxmax(), gPad->GetUymax(),
245 0, 1, 510, "+L");
246 axis->SetBit(TAxis::kRotateTitle);
247 axis->SetName("RightAxis");
248 axis->SetTitle(title);
249 axis->SetTitleOffset(1.2);
250 axis->SetTextColor(col);
251 axis->SetLabelColor(col);
252 axis->SetBit(kCanDelete);
253 axis->Draw();
254}
255
256// --------------------------------------------------------------------------
257//
258// This displays the TGraph like you expect it to be (eg. time on the axis)
259// It should also make sure, that the displayed time always is UTC and
260// not local time...
261//
262void MHWeather::Draw(Option_t *opt)
263{
264 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
265 pad->SetBorderMode(0);
266
267 AppendPad();
268
269 pad->Divide(2,2);
270
271 pad->cd(1);
272 gPad->SetBorderMode(0);
273 gPad->SetGridx();
274 gPad->SetGridy();
275 fTemperature.Draw("AP");
276 fTempAir.Draw("P");
277 fTempSky.Draw("P");
278 DrawRightAxis("T_{sky}-200 [K]", kBlue);
279
280 pad->cd(2);
281 gPad->SetBorderMode(0);
282 gPad->SetGridx();
283 gPad->SetGridy();
284 fHumidity.Draw("AP");
285 fCloudiness.Draw("P");
286 DrawRightAxis("Cloudiness [%]");
287
288 pad->cd(3);
289 gPad->SetBorderMode(0);
290 gPad->SetGridx();
291 gPad->SetGridy();
292 fWindSpeed.Draw("AP");
293
294 pad->cd(4);
295 gPad->SetBorderMode(0);
296 gPad->SetGridx();
297 gPad->SetGridy();
298 fEventRate.Draw("AP");
299}
300
301void MHWeather::Paint(Option_t *o)
302{
303 // If this is set to early the plot remains empty in root 5.12/00
304 if (fHumidity.GetN()>0)
305 {
306 fHumidity.SetMinimum(0);
307 fHumidity.SetMaximum(100);
308 }
309 if (fCloudiness.GetN()>0)
310 {
311 fCloudiness.SetMinimum(0);
312 fCloudiness.SetMaximum(100);
313 }
314
315 if (fTemperature.GetN()>0)
316 {
317 fTemperature.SetMinimum(-2.5);
318 fTemperature.SetMaximum(27.5);
319 }
320 if (fTempSky.GetN()>0)
321 {
322 fTempSky.SetMinimum(-2.5);
323 fTempSky.SetMaximum(27.5);
324 }
325 if (fWindSpeed.GetN()>0)
326 fWindSpeed.SetMinimum(0);
327 if (fEventRate.GetN()>0)
328 fEventRate.SetMinimum(0);
329
330 DrawGraph(fHumidity, "Humidity [%]");
331 DrawGraph(fTemperature, "T [\\circ C]");
332 DrawGraph(fWindSpeed, "km/h");
333 DrawGraph(fEventRate, "f [Hz]");
334 DrawGraph(fCloudiness, "Cloudiness [%]");
335 DrawGraph(fTempAir, "T [\\circ C]");
336 DrawGraph(fTempSky, "T_{sky}-200 [K]");
337
338 TVirtualPad *p = gPad;
339
340 p->cd(1);
341 if (gPad)
342 {
343 fTemperature.GetYaxis()->SetLabelColor(kRed);
344 fTemperature.GetYaxis()->SetTitleColor(kRed);
345 UpdateRightAxis(fTemperature); // Primary axis
346 }
347
348 p->cd(2);
349 if (gPad)
350 {
351 fHumidity.GetYaxis()->SetLabelColor(kBlue);
352 fHumidity.GetYaxis()->SetTitleColor(kBlue);
353 fHumidity.GetYaxis()->SetTitleOffset(1.2);
354 UpdateRightAxis(fHumidity); // Primary axis
355 }
356}
Note: See TracBrowser for help on using the repository browser.