source: trunk/MagicSoft/Mars/mhist/MHRate.cc@ 7562

Last change on this file since 7562 was 7224, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 7.1 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, 07/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2005
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHRate
28//
29// Display information about software trigger rate
30//
31////////////////////////////////////////////////////////////////////////////
32#include "MHRate.h"
33
34#include <TCanvas.h>
35#include <TGaxis.h>
36
37#include "MLog.h"
38#include "MLogManip.h"
39
40#include "MParList.h"
41
42#include "MTime.h"
43#include "MEventRate.h"
44#include "MPointingPos.h"
45#include "MBinning.h"
46
47ClassImp(MHRate);
48
49using namespace std;
50
51void MHRate::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 MHRate::InitGraph(TGraph &g) const
59{
60 ResetGraph(g);
61 g.SetMarkerStyle(kFullDotMedium);
62}
63
64void MHRate::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//
79MHRate::MHRate(const char *name, const char *title)
80: /*fTime(0),*/ fPointPos(0), fEvtRate(0)
81{
82 fName = name ? name : "MHRate";
83 fTitle = title ? title : "Graphs for rate data";
84
85 // Init Graphs
86 fRateTime.SetNameTitle("RateTime", "Rate vs Time");
87 fRateZd.SetNameTitle("RateZd", "Rate vs Zenith distance");
88 fRate.SetNameTitle("Rate", "Distribution of Rate");
89
90 InitGraph(fRateTime);
91
92 fRateZd.SetXTitle("Zd [\\circ]");
93 fRateZd.SetYTitle("Rate [Hz]");
94
95 fRate.SetXTitle("Rate [Hz]");
96 fRate.SetYTitle("Counts");
97
98 fRateTime.SetMinimum(0);
99
100 fRate.SetDirectory(0);
101 fRateZd.SetDirectory(0);
102
103 fRateZd.SetMarkerStyle(kFullDotMedium);
104 fRateZd.SetBit(TH1::kNoStats);
105
106 MBinning b;
107 b.SetEdges(120, 0, 1200);
108 b.Apply(fRate);
109
110 b.SetEdgesASin(67, -0.005, 0.665);
111 b.Apply(fRateZd);
112}
113
114// --------------------------------------------------------------------------
115//
116// Setup the Binning for the histograms automatically if the correct
117// instances of MBinning
118//
119Bool_t MHRate::SetupFill(const MParList *plist)
120{
121 fEvtRate = (MEventRate*)plist->FindObject("MEventRate");
122 if (!fEvtRate)
123 {
124 *fLog << err << "MEventRate not found... abort." << endl;
125 return kFALSE;
126 }
127 fPointPos = (MPointingPos*)plist->FindObject("MPointingPos");
128 if (!fPointPos)
129 {
130 *fLog << err << "MPointingPos not found... abort." << endl;
131 return kFALSE;
132 }
133
134 // Reset Graphs
135 ResetGraph(fRateTime);
136
137 fCounter = 0;
138 fMean = 0;
139 fLast = MTime();
140
141 return kTRUE;
142}
143
144// --------------------------------------------------------------------------
145//
146// Fill the histograms with data from a MMuonCalibPar and
147// MMuonSearchPar container.
148//
149Bool_t MHRate::Fill(const MParContainer *par, const Stat_t w)
150{
151 const MTime *t = dynamic_cast<const MTime*>(par);
152 if (!t)
153 {
154 *fLog << err <<"MHRate::Fill - ERROR: MTime not given as argument... abort." << endl;
155 return kERROR;
156 }
157
158 const Double_t rate = fEvtRate->GetRate();
159 if (rate<0)
160 return kTRUE;
161
162 const Double_t tm = t->GetAxisTime();
163
164 if (fLast==MTime())
165 fLast = MTime();
166
167 fMean += rate;
168 fCounter++;
169
170 if ((double)*t > (double)fLast+5 && fCounter>0)
171 {
172 AddPoint(fRateTime, tm, fMean/fCounter);
173 fMean = 0;
174 fCounter = 0;
175 fLast = *t;
176 }
177
178 fRateZd.Fill(fPointPos->GetZd(), rate);
179 fRate.Fill(rate);
180
181 return kTRUE;
182}
183
184void MHRate::DrawGraph(TGraph &g, const char *y) const
185{
186 TH1 *h = g.GetHistogram();
187 if (h)
188 {
189 TAxis *axe = h->GetXaxis();
190 axe->SetLabelSize(0.033);
191 axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
192 axe->SetTimeDisplay(1);
193 axe->SetTitle("Time");
194 if (y)
195 h->SetYTitle(y);
196 }
197}
198
199// --------------------------------------------------------------------------
200//
201// Update position of an axis on the right side of the histogram
202/*
203void MHRate::UpdateRightAxis(TGraph &g) const
204{
205 TH1 &h = *g.GetHistogram();
206
207 const Double_t max = h.GetMaximum();
208 if (max==0)
209 return;
210
211 TGaxis *axis = (TGaxis*)gPad->FindObject("RightAxis");
212 if (!axis)
213 return;
214
215 axis->SetX1(g.GetXaxis()->GetXmax());
216 axis->SetX2(g.GetXaxis()->GetXmax());
217 axis->SetY1(gPad->GetUymin());
218 axis->SetY2(gPad->GetUymax());
219 axis->SetWmax(max);
220}
221*/
222// --------------------------------------------------------------------------
223//
224// Draw an axis on the right side of the histogram
225//
226/*
227void MHRate::DrawRightAxis(const char *title) const
228{
229 TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(),
230 gPad->GetUxmax(), gPad->GetUymax(),
231 0, 1, 510, "+L");
232 axis->SetName("RightAxis");
233 axis->SetTitle(title);
234 axis->SetTitleOffset(0.9);
235 axis->SetTextColor(kRed);
236 axis->SetBit(kCanDelete);
237 axis->Draw();
238}
239*/
240// --------------------------------------------------------------------------
241//
242// This displays the TGraph like you expect it to be (eg. time on the axis)
243// It should also make sure, that the displayed time always is UTC and
244// not local time...
245//
246void MHRate::Draw(Option_t *opt)
247{
248 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
249 pad->SetBorderMode(0);
250
251 AppendPad();
252
253 pad->Divide(2,2);
254
255 pad->cd(1);
256 gPad->SetBorderMode(0);
257 gPad->SetGridx();
258 gPad->SetGridy();
259 gPad->SetLogy();
260 fRate.Draw();
261 //fHumidity.Draw("AP");
262 //fTemperature.Draw("P");
263 //DrawRightAxis("T [\\circ C]");
264
265 pad->cd(2);
266 gPad->SetBorderMode(0);
267 gPad->SetGridx();
268 gPad->SetGridy();
269 fRateTime.Draw("AP");
270 //fSolarRadiation.Draw("AP");
271
272 pad->cd(3);
273 gPad->SetBorderMode(0);
274 gPad->SetGridx();
275 gPad->SetGridy();
276 fRateZd.Draw();
277
278 if (pad->GetPad(4))
279 delete pad->GetPad(4);
280
281 /*
282 pad->cd(4);
283 gPad->SetBorderMode(0);
284 gPad->SetGridx();
285 gPad->SetGridy();
286 fWindSpeed.Draw("AP");*/
287}
288
289void MHRate::Paint(Option_t *o)
290{
291 DrawGraph(fRateTime, "f [Hz]");
292 /*
293 gPad->cd(1);
294
295 if (gPad)
296 {
297 fHumidity.GetHistogram()->GetYaxis()->SetTitleColor(kBlue);
298 UpdateRightAxis(fTemperature);
299 }*/
300}
Note: See TracBrowser for help on using the repository browser.