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

Last change on this file since 7953 was 7841, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 7.5 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-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
47ClassImp(MHWeather);
48
49using namespace std;
50
51void 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
58void MHWeather::InitGraph(TGraph &g) const
59{
60 ResetGraph(g);
61 g.SetMarkerStyle(kFullDotMedium);
62}
63
64void 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//
79MHWeather::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//
107Bool_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//
137Bool_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
157void MHWeather::DrawGraph(TGraph &g, const char *y) const
158{
159 TH1 *h = g.GetHistogram();
160 if (h)
161 {
162 TAxis *axe = h->GetXaxis();
163 axe->SetLabelSize(0.033);
164 axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
165 axe->SetTimeDisplay(1);
166 axe->SetTitle("Time");
167 if (y)
168 h->SetYTitle(y);
169 }
170}
171
172// --------------------------------------------------------------------------
173//
174// Update position of an axis on the right side of the histogram
175//
176void MHWeather::UpdateRightAxis(TGraph &g) const
177{
178 TH1 &h = *g.GetHistogram();
179
180 const Double_t max = h.GetMaximum();
181 if (max==0)
182 return;
183
184 TGaxis *axis = (TGaxis*)gPad->FindObject("RightAxis");
185 if (!axis)
186 return;
187
188 axis->SetX1(g.GetXaxis()->GetXmax());
189 axis->SetX2(g.GetXaxis()->GetXmax());
190 axis->SetY1(gPad->GetUymin());
191 axis->SetY2(gPad->GetUymax());
192 axis->SetWmax(max);
193}
194
195// --------------------------------------------------------------------------
196//
197// Draw an axis on the right side of the histogram
198//
199void MHWeather::DrawRightAxis(const char *title) const
200{
201 TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(),
202 gPad->GetUxmax(), gPad->GetUymax(),
203 0, 1, 510, "+L");
204 axis->SetName("RightAxis");
205 axis->SetTitle(title);
206 axis->SetTitleOffset(0.9);
207 axis->SetTextColor(kRed);
208 axis->SetBit(kCanDelete);
209 axis->Draw();
210}
211
212// --------------------------------------------------------------------------
213//
214// This displays the TGraph like you expect it to be (eg. time on the axis)
215// It should also make sure, that the displayed time always is UTC and
216// not local time...
217//
218void MHWeather::Draw(Option_t *opt)
219{
220 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
221 pad->SetBorderMode(0);
222
223 AppendPad();
224
225 pad->Divide(2,2);
226
227 pad->cd(1);
228 gPad->SetBorderMode(0);
229 gPad->SetGridx();
230 gPad->SetGridy();
231 fHumidity.Draw("AP");
232 fTemperature.Draw("P");
233 DrawRightAxis("T [\\circ C]");
234
235 pad->cd(2);
236 gPad->SetBorderMode(0);
237 gPad->SetGridx();
238 gPad->SetGridy();
239 fSolarRadiation.Draw("AP");
240
241 pad->cd(3);
242 gPad->SetBorderMode(0);
243 gPad->SetGridx();
244 gPad->SetGridy();
245 fEventRate.Draw("AP");
246
247 pad->cd(4);
248 gPad->SetBorderMode(0);
249 gPad->SetGridx();
250 gPad->SetGridy();
251 fWindSpeed.Draw("AP");
252}
253
254void MHWeather::Paint(Option_t *o)
255{
256 // If this is set to early the plot remains empty in root 5.12/00
257 if (fHumidity.GetN()>0)
258 {
259 fHumidity.SetMinimum(0);
260 fHumidity.SetMaximum(100);
261 }
262 if (fTemperature.GetN()>0)
263 {
264 fTemperature.SetMinimum(-25);
265 fTemperature.SetMaximum(45);
266 }
267 if (fWindSpeed.GetN()>0)
268 fWindSpeed.SetMinimum(0);
269 if (fSolarRadiation.GetN()>0)
270 fSolarRadiation.SetMinimum(0);
271 if (fEventRate.GetN()>0)
272 fEventRate.SetMinimum(0);
273
274 DrawGraph(fHumidity, "H [%]");
275 DrawGraph(fSolarRadiation, "R [W/m^{2}]");
276 DrawGraph(fTemperature, "T [\\circ C]");
277 DrawGraph(fWindSpeed, "km/h");
278 DrawGraph(fEventRate, "f [Hz]");
279
280 gPad->cd(1);
281
282 if (gPad)
283 {
284 fHumidity.GetHistogram()->GetYaxis()->SetTitleColor(kBlue);
285 UpdateRightAxis(fTemperature);
286 }
287}
Note: See TracBrowser for help on using the repository browser.