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 |
|
---|
47 | ClassImp(MHRate);
|
---|
48 |
|
---|
49 | using namespace std;
|
---|
50 |
|
---|
51 | void 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 |
|
---|
58 | void MHRate::InitGraph(TGraph &g) const
|
---|
59 | {
|
---|
60 | ResetGraph(g);
|
---|
61 | g.SetMarkerStyle(kFullDotMedium);
|
---|
62 | }
|
---|
63 |
|
---|
64 | void 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 | //
|
---|
79 | MHRate::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 | fRate.SetDirectory(0);
|
---|
99 | fRateZd.SetDirectory(0);
|
---|
100 |
|
---|
101 | fRateZd.SetMarkerStyle(kFullDotMedium);
|
---|
102 | fRateZd.SetBit(TH1::kNoStats);
|
---|
103 |
|
---|
104 | MBinning b;
|
---|
105 | b.SetEdges(120, 0, 1200);
|
---|
106 | b.Apply(fRate);
|
---|
107 |
|
---|
108 | b.SetEdgesASin(67, -0.005, 0.665);
|
---|
109 | b.Apply(fRateZd);
|
---|
110 | }
|
---|
111 |
|
---|
112 | // --------------------------------------------------------------------------
|
---|
113 | //
|
---|
114 | // Setup the Binning for the histograms automatically if the correct
|
---|
115 | // instances of MBinning
|
---|
116 | //
|
---|
117 | Bool_t MHRate::SetupFill(const MParList *plist)
|
---|
118 | {
|
---|
119 | fEvtRate = (MEventRate*)plist->FindObject("MEventRate");
|
---|
120 | if (!fEvtRate)
|
---|
121 | {
|
---|
122 | *fLog << err << "MEventRate not found... abort." << endl;
|
---|
123 | return kFALSE;
|
---|
124 | }
|
---|
125 | fPointPos = (MPointingPos*)plist->FindObject("MPointingPos");
|
---|
126 | if (!fPointPos)
|
---|
127 | {
|
---|
128 | *fLog << err << "MPointingPos not found... abort." << endl;
|
---|
129 | return kFALSE;
|
---|
130 | }
|
---|
131 |
|
---|
132 | // Reset Graphs
|
---|
133 | ResetGraph(fRateTime);
|
---|
134 |
|
---|
135 | fCounter = 0;
|
---|
136 | fMean = 0;
|
---|
137 | fLast = MTime();
|
---|
138 |
|
---|
139 | return kTRUE;
|
---|
140 | }
|
---|
141 |
|
---|
142 | // --------------------------------------------------------------------------
|
---|
143 | //
|
---|
144 | // Fill the histograms with data from a MMuonCalibPar and
|
---|
145 | // MMuonSearchPar container.
|
---|
146 | //
|
---|
147 | Int_t MHRate::Fill(const MParContainer *par, const Stat_t w)
|
---|
148 | {
|
---|
149 | const MTime *t = dynamic_cast<const MTime*>(par);
|
---|
150 | if (!t)
|
---|
151 | {
|
---|
152 | *fLog << err <<"MHRate::Fill - ERROR: MTime not given as argument... abort." << endl;
|
---|
153 | return kERROR;
|
---|
154 | }
|
---|
155 |
|
---|
156 | const Double_t rate = fEvtRate->GetRate();
|
---|
157 | if (rate<0)
|
---|
158 | return kTRUE;
|
---|
159 |
|
---|
160 | const Double_t tm = t->GetAxisTime();
|
---|
161 |
|
---|
162 | if (fLast==MTime())
|
---|
163 | fLast = MTime();
|
---|
164 |
|
---|
165 | fMean += rate;
|
---|
166 | fCounter++;
|
---|
167 |
|
---|
168 | if ((double)*t > (double)fLast+5 && fCounter>0)
|
---|
169 | {
|
---|
170 | AddPoint(fRateTime, tm, fMean/fCounter);
|
---|
171 | fMean = 0;
|
---|
172 | fCounter = 0;
|
---|
173 | fLast = *t;
|
---|
174 | }
|
---|
175 |
|
---|
176 | fRateZd.Fill(fPointPos->GetZd(), rate);
|
---|
177 | fRate.Fill(rate);
|
---|
178 |
|
---|
179 | return kTRUE;
|
---|
180 | }
|
---|
181 |
|
---|
182 | void MHRate::DrawGraph(TGraph &g, const char *y) const
|
---|
183 | {
|
---|
184 | // If this is set to early the plot remains empty in root 5.12/00
|
---|
185 | if (g.GetN()>0)
|
---|
186 | g.SetMinimum(0);
|
---|
187 |
|
---|
188 | // This is not done automatically anymore since root 5.12/00
|
---|
189 | // and it is necessary to force a proper update of the axis.
|
---|
190 | TH1 *h = g.GetHistogram();
|
---|
191 | if (h)
|
---|
192 | {
|
---|
193 | delete h;
|
---|
194 | g.SetHistogram(0);
|
---|
195 | h = g.GetHistogram();
|
---|
196 | }
|
---|
197 |
|
---|
198 | if (h)
|
---|
199 | {
|
---|
200 | TAxis *axe = h->GetXaxis();
|
---|
201 | axe->SetLabelSize(0.033);
|
---|
202 | axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
|
---|
203 | axe->SetTimeDisplay(1);
|
---|
204 | axe->SetTitle("Time");
|
---|
205 | if (y)
|
---|
206 | h->SetYTitle(y);
|
---|
207 | }
|
---|
208 | }
|
---|
209 |
|
---|
210 | // --------------------------------------------------------------------------
|
---|
211 | //
|
---|
212 | // Update position of an axis on the right side of the histogram
|
---|
213 | /*
|
---|
214 | void MHRate::UpdateRightAxis(TGraph &g) const
|
---|
215 | {
|
---|
216 | TH1 &h = *g.GetHistogram();
|
---|
217 |
|
---|
218 | const Double_t max = h.GetMaximum();
|
---|
219 | if (max==0)
|
---|
220 | return;
|
---|
221 |
|
---|
222 | TGaxis *axis = (TGaxis*)gPad->FindObject("RightAxis");
|
---|
223 | if (!axis)
|
---|
224 | return;
|
---|
225 |
|
---|
226 | axis->SetX1(g.GetXaxis()->GetXmax());
|
---|
227 | axis->SetX2(g.GetXaxis()->GetXmax());
|
---|
228 | axis->SetY1(gPad->GetUymin());
|
---|
229 | axis->SetY2(gPad->GetUymax());
|
---|
230 | axis->SetWmax(max);
|
---|
231 | }
|
---|
232 | */
|
---|
233 | // --------------------------------------------------------------------------
|
---|
234 | //
|
---|
235 | // Draw an axis on the right side of the histogram
|
---|
236 | //
|
---|
237 | /*
|
---|
238 | void MHRate::DrawRightAxis(const char *title) const
|
---|
239 | {
|
---|
240 | TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(),
|
---|
241 | gPad->GetUxmax(), gPad->GetUymax(),
|
---|
242 | 0, 1, 510, "+L");
|
---|
243 | axis->SetName("RightAxis");
|
---|
244 | axis->SetTitle(title);
|
---|
245 | axis->SetTitleOffset(0.9);
|
---|
246 | axis->SetTextColor(kRed);
|
---|
247 | axis->SetBit(kCanDelete);
|
---|
248 | axis->Draw();
|
---|
249 | }
|
---|
250 | */
|
---|
251 | // --------------------------------------------------------------------------
|
---|
252 | //
|
---|
253 | // This displays the TGraph like you expect it to be (eg. time on the axis)
|
---|
254 | // It should also make sure, that the displayed time always is UTC and
|
---|
255 | // not local time...
|
---|
256 | //
|
---|
257 | void MHRate::Draw(Option_t *opt)
|
---|
258 | {
|
---|
259 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
---|
260 | pad->SetBorderMode(0);
|
---|
261 |
|
---|
262 | AppendPad();
|
---|
263 |
|
---|
264 | pad->Divide(2,2);
|
---|
265 |
|
---|
266 | pad->cd(1);
|
---|
267 | gPad->SetBorderMode(0);
|
---|
268 | gPad->SetGridx();
|
---|
269 | gPad->SetGridy();
|
---|
270 | gPad->SetLogy();
|
---|
271 | fRate.Draw();
|
---|
272 | //fHumidity.Draw("AP");
|
---|
273 | //fTemperature.Draw("P");
|
---|
274 | //DrawRightAxis("T [\\circ C]");
|
---|
275 |
|
---|
276 | pad->cd(2);
|
---|
277 | gPad->SetBorderMode(0);
|
---|
278 | gPad->SetGridx();
|
---|
279 | gPad->SetGridy();
|
---|
280 | fRateTime.Draw("AP");
|
---|
281 | //fSolarRadiation.Draw("AP");
|
---|
282 |
|
---|
283 | pad->cd(3);
|
---|
284 | gPad->SetBorderMode(0);
|
---|
285 | gPad->SetGridx();
|
---|
286 | gPad->SetGridy();
|
---|
287 | fRateZd.Draw();
|
---|
288 |
|
---|
289 | if (pad->GetPad(4))
|
---|
290 | delete pad->GetPad(4);
|
---|
291 |
|
---|
292 | /*
|
---|
293 | pad->cd(4);
|
---|
294 | gPad->SetBorderMode(0);
|
---|
295 | gPad->SetGridx();
|
---|
296 | gPad->SetGridy();
|
---|
297 | fWindSpeed.Draw("AP");*/
|
---|
298 | }
|
---|
299 |
|
---|
300 | void MHRate::Paint(Option_t *o)
|
---|
301 | {
|
---|
302 | DrawGraph(fRateTime, "f [Hz]");
|
---|
303 | /*
|
---|
304 | gPad->cd(1);
|
---|
305 |
|
---|
306 | if (gPad)
|
---|
307 | {
|
---|
308 | fHumidity.GetHistogram()->GetYaxis()->SetTitleColor(kBlue);
|
---|
309 | UpdateRightAxis(fTemperature);
|
---|
310 | }*/
|
---|
311 | }
|
---|