source: trunk/MagicSoft/Mars/mhist/MHWeather.cc@ 8934

Last change on this file since 8934 was 8934, 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//
163Bool_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->SetBit(kCanDelete);
252 axis->Draw();
253}
254
255// --------------------------------------------------------------------------
256//
257// This displays the TGraph like you expect it to be (eg. time on the axis)
258// It should also make sure, that the displayed time always is UTC and
259// not local time...
260//
261void MHWeather::Draw(Option_t *opt)
262{
263 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
264 pad->SetBorderMode(0);
265
266 AppendPad();
267
268 pad->Divide(2,2);
269
270 pad->cd(1);
271 gPad->SetBorderMode(0);
272 gPad->SetGridx();
273 gPad->SetGridy();
274 fTemperature.Draw("AP");
275 fTempAir.Draw("P");
276 fTempSky.Draw("P");
277 DrawRightAxis("T_{sky}-200 [K]", kBlue);
278
279 pad->cd(2);
280 gPad->SetBorderMode(0);
281 gPad->SetGridx();
282 gPad->SetGridy();
283 fHumidity.Draw("AP");
284 fCloudiness.Draw("P");
285 DrawRightAxis("Cloudiness [%]");
286
287 pad->cd(3);
288 gPad->SetBorderMode(0);
289 gPad->SetGridx();
290 gPad->SetGridy();
291 fWindSpeed.Draw("AP");
292
293 pad->cd(4);
294 gPad->SetBorderMode(0);
295 gPad->SetGridx();
296 gPad->SetGridy();
297 fEventRate.Draw("AP");
298}
299
300void MHWeather::Paint(Option_t *o)
301{
302 // If this is set to early the plot remains empty in root 5.12/00
303 if (fHumidity.GetN()>0)
304 {
305 fHumidity.SetMinimum(0);
306 fHumidity.SetMaximum(100);
307 }
308 if (fCloudiness.GetN()>0)
309 {
310 fCloudiness.SetMinimum(0);
311 fCloudiness.SetMaximum(100);
312 }
313
314 if (fTemperature.GetN()>0)
315 {
316 fTemperature.SetMinimum(-2.5);
317 fTemperature.SetMaximum(27.5);
318 }
319 if (fTempSky.GetN()>0)
320 {
321 fTempSky.SetMinimum(-2.5);
322 fTempSky.SetMaximum(27.5);
323 }
324 if (fWindSpeed.GetN()>0)
325 fWindSpeed.SetMinimum(0);
326 if (fEventRate.GetN()>0)
327 fEventRate.SetMinimum(0);
328
329 DrawGraph(fHumidity, "Humidity [%]");
330 DrawGraph(fTemperature, "T [\\circ C]");
331 DrawGraph(fWindSpeed, "km/h");
332 DrawGraph(fEventRate, "f [Hz]");
333 DrawGraph(fCloudiness, "Cloudiness [%]");
334 DrawGraph(fTempAir, "T [\\circ C]");
335 DrawGraph(fTempSky, "T_{sky}-200 [K]");
336
337 TVirtualPad *p = gPad;
338
339 p->cd(1);
340 if (gPad)
341 {
342 fTemperature.GetHistogram()->GetYaxis()->SetTitleColor(kRed);
343 //fTempSky.GetHistogram()->GetYaxis()->SetTitleColor(kBlue);
344 UpdateRightAxis(fTemperature); // Primary axis
345 }
346
347 p->cd(2);
348 if (gPad)
349 {
350 fHumidity.GetHistogram()->GetYaxis()->SetTitleColor(kBlue);
351 fHumidity.GetHistogram()->GetYaxis()->SetTitleOffset(1.2);
352 UpdateRightAxis(fHumidity); // Primary axis
353 }
354}
Note: See TracBrowser for help on using the repository browser.