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

Last change on this file since 7822 was 7033, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 7.2 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.SetMinimum(0);
99 fHumidity.SetMaximum(100);
100 fTemperature.SetMinimum(-25);
101 fTemperature.SetMaximum(45);
102 fWindSpeed.SetMinimum(0);
103 fSolarRadiation.SetMinimum(0);
104 fEventRate.SetMinimum(0);
105
106 fHumidity.SetMarkerColor(kBlue);
107 fTemperature.SetMarkerColor(kRed);
108}
109
110// --------------------------------------------------------------------------
111//
112// Setup the Binning for the histograms automatically if the correct
113// instances of MBinning
114//
115Bool_t MHWeather::SetupFill(const MParList *plist)
116{
117 fReport = (MReportCC*)plist->FindObject("MReportCC");
118 if (!fReport)
119 {
120 *fLog << warn << "MReportCC not found... abort." << endl;
121 return kFALSE;
122 }
123 fRate = (MEventRate*)plist->FindObject("MEventRate");
124 if (!fRate)
125 {
126 *fLog << warn << "MEventRate not found... abort." << endl;
127 return kFALSE;
128 }
129
130 // Reset Graphs
131 ResetGraph(fHumidity);
132 ResetGraph(fTemperature);
133 ResetGraph(fSolarRadiation);
134 ResetGraph(fWindSpeed);
135 ResetGraph(fEventRate);
136
137 return kTRUE;
138}
139
140// --------------------------------------------------------------------------
141//
142// Fill the histograms with data from a MMuonCalibPar and
143// MMuonSearchPar container.
144//
145Bool_t MHWeather::Fill(const MParContainer *par, const Stat_t w)
146{
147 const MTime *t = dynamic_cast<const MTime*>(par);
148 if (!t)
149 {
150 *fLog << err <<"MHWeather::Fill - ERROR: MTime not given as argument... abort." << endl;
151 return kERROR;
152 }
153
154 const Double_t tm = t->GetAxisTime();
155
156 AddPoint(fTemperature, tm, fReport->GetTemperature());
157 AddPoint(fHumidity, tm, fReport->GetHumidity());
158 AddPoint(fSolarRadiation, tm, fReport->GetSolarRadiation());
159 AddPoint(fWindSpeed, tm, fReport->GetWindSpeed());
160 AddPoint(fEventRate, tm, fRate->GetRate());
161
162 return kTRUE;
163}
164
165void MHWeather::DrawGraph(TGraph &g, const char *y) const
166{
167 TH1 *h = g.GetHistogram();
168 if (h)
169 {
170 TAxis *axe = h->GetXaxis();
171 axe->SetLabelSize(0.033);
172 axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
173 axe->SetTimeDisplay(1);
174 axe->SetTitle("Time");
175 if (y)
176 h->SetYTitle(y);
177 }
178}
179
180// --------------------------------------------------------------------------
181//
182// Update position of an axis on the right side of the histogram
183//
184void MHWeather::UpdateRightAxis(TGraph &g) const
185{
186 TH1 &h = *g.GetHistogram();
187
188 const Double_t max = h.GetMaximum();
189 if (max==0)
190 return;
191
192 TGaxis *axis = (TGaxis*)gPad->FindObject("RightAxis");
193 if (!axis)
194 return;
195
196 axis->SetX1(g.GetXaxis()->GetXmax());
197 axis->SetX2(g.GetXaxis()->GetXmax());
198 axis->SetY1(gPad->GetUymin());
199 axis->SetY2(gPad->GetUymax());
200 axis->SetWmax(max);
201}
202
203// --------------------------------------------------------------------------
204//
205// Draw an axis on the right side of the histogram
206//
207void MHWeather::DrawRightAxis(const char *title) const
208{
209 TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(),
210 gPad->GetUxmax(), gPad->GetUymax(),
211 0, 1, 510, "+L");
212 axis->SetName("RightAxis");
213 axis->SetTitle(title);
214 axis->SetTitleOffset(0.9);
215 axis->SetTextColor(kRed);
216 axis->SetBit(kCanDelete);
217 axis->Draw();
218}
219
220// --------------------------------------------------------------------------
221//
222// This displays the TGraph like you expect it to be (eg. time on the axis)
223// It should also make sure, that the displayed time always is UTC and
224// not local time...
225//
226void MHWeather::Draw(Option_t *opt)
227{
228 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
229 pad->SetBorderMode(0);
230
231 AppendPad();
232
233 pad->Divide(2,2);
234
235 pad->cd(1);
236 gPad->SetBorderMode(0);
237 gPad->SetGridx();
238 gPad->SetGridy();
239 fHumidity.Draw("AP");
240 fTemperature.Draw("P");
241 DrawRightAxis("T [\\circ C]");
242
243 pad->cd(2);
244 gPad->SetBorderMode(0);
245 gPad->SetGridx();
246 gPad->SetGridy();
247 fSolarRadiation.Draw("AP");
248
249 pad->cd(3);
250 gPad->SetBorderMode(0);
251 gPad->SetGridx();
252 gPad->SetGridy();
253 fEventRate.Draw("AP");
254
255 pad->cd(4);
256 gPad->SetBorderMode(0);
257 gPad->SetGridx();
258 gPad->SetGridy();
259 fWindSpeed.Draw("AP");
260}
261
262void MHWeather::Paint(Option_t *o)
263{
264 DrawGraph(fHumidity, "H [%]");
265 DrawGraph(fSolarRadiation, "R [W/m^{2}]");
266 DrawGraph(fTemperature, "T [\\circ C]");
267 DrawGraph(fWindSpeed, "km/h");
268 DrawGraph(fEventRate, "f [Hz]");
269
270 gPad->cd(1);
271
272 if (gPad)
273 {
274 fHumidity.GetHistogram()->GetYaxis()->SetTitleColor(kBlue);
275 UpdateRightAxis(fTemperature);
276 }
277}
Note: See TracBrowser for help on using the repository browser.