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 | Bool_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 | TH1 *h = g.GetHistogram();
|
---|
185 | if (h)
|
---|
186 | {
|
---|
187 | TAxis *axe = h->GetXaxis();
|
---|
188 | axe->SetLabelSize(0.033);
|
---|
189 | axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
|
---|
190 | axe->SetTimeDisplay(1);
|
---|
191 | axe->SetTitle("Time");
|
---|
192 | if (y)
|
---|
193 | h->SetYTitle(y);
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | // --------------------------------------------------------------------------
|
---|
198 | //
|
---|
199 | // Update position of an axis on the right side of the histogram
|
---|
200 | /*
|
---|
201 | void MHRate::UpdateRightAxis(TGraph &g) const
|
---|
202 | {
|
---|
203 | TH1 &h = *g.GetHistogram();
|
---|
204 |
|
---|
205 | const Double_t max = h.GetMaximum();
|
---|
206 | if (max==0)
|
---|
207 | return;
|
---|
208 |
|
---|
209 | TGaxis *axis = (TGaxis*)gPad->FindObject("RightAxis");
|
---|
210 | if (!axis)
|
---|
211 | return;
|
---|
212 |
|
---|
213 | axis->SetX1(g.GetXaxis()->GetXmax());
|
---|
214 | axis->SetX2(g.GetXaxis()->GetXmax());
|
---|
215 | axis->SetY1(gPad->GetUymin());
|
---|
216 | axis->SetY2(gPad->GetUymax());
|
---|
217 | axis->SetWmax(max);
|
---|
218 | }
|
---|
219 | */
|
---|
220 | // --------------------------------------------------------------------------
|
---|
221 | //
|
---|
222 | // Draw an axis on the right side of the histogram
|
---|
223 | //
|
---|
224 | /*
|
---|
225 | void MHRate::DrawRightAxis(const char *title) const
|
---|
226 | {
|
---|
227 | TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(),
|
---|
228 | gPad->GetUxmax(), gPad->GetUymax(),
|
---|
229 | 0, 1, 510, "+L");
|
---|
230 | axis->SetName("RightAxis");
|
---|
231 | axis->SetTitle(title);
|
---|
232 | axis->SetTitleOffset(0.9);
|
---|
233 | axis->SetTextColor(kRed);
|
---|
234 | axis->SetBit(kCanDelete);
|
---|
235 | axis->Draw();
|
---|
236 | }
|
---|
237 | */
|
---|
238 | // --------------------------------------------------------------------------
|
---|
239 | //
|
---|
240 | // This displays the TGraph like you expect it to be (eg. time on the axis)
|
---|
241 | // It should also make sure, that the displayed time always is UTC and
|
---|
242 | // not local time...
|
---|
243 | //
|
---|
244 | void MHRate::Draw(Option_t *opt)
|
---|
245 | {
|
---|
246 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
---|
247 | pad->SetBorderMode(0);
|
---|
248 |
|
---|
249 | AppendPad();
|
---|
250 |
|
---|
251 | pad->Divide(2,2);
|
---|
252 |
|
---|
253 | pad->cd(1);
|
---|
254 | gPad->SetBorderMode(0);
|
---|
255 | gPad->SetGridx();
|
---|
256 | gPad->SetGridy();
|
---|
257 | gPad->SetLogy();
|
---|
258 | fRate.Draw();
|
---|
259 | //fHumidity.Draw("AP");
|
---|
260 | //fTemperature.Draw("P");
|
---|
261 | //DrawRightAxis("T [\\circ C]");
|
---|
262 |
|
---|
263 | pad->cd(2);
|
---|
264 | gPad->SetBorderMode(0);
|
---|
265 | gPad->SetGridx();
|
---|
266 | gPad->SetGridy();
|
---|
267 | fRateTime.Draw("AP");
|
---|
268 | //fSolarRadiation.Draw("AP");
|
---|
269 |
|
---|
270 | pad->cd(3);
|
---|
271 | gPad->SetBorderMode(0);
|
---|
272 | gPad->SetGridx();
|
---|
273 | gPad->SetGridy();
|
---|
274 | fRateZd.Draw();
|
---|
275 |
|
---|
276 | if (pad->GetPad(4))
|
---|
277 | delete pad->GetPad(4);
|
---|
278 |
|
---|
279 | /*
|
---|
280 | pad->cd(4);
|
---|
281 | gPad->SetBorderMode(0);
|
---|
282 | gPad->SetGridx();
|
---|
283 | gPad->SetGridy();
|
---|
284 | fWindSpeed.Draw("AP");*/
|
---|
285 | }
|
---|
286 |
|
---|
287 | void MHRate::Paint(Option_t *o)
|
---|
288 | {
|
---|
289 | // If this is set to early the plot remains empty in root 5.12/00
|
---|
290 | if (fRateTime.GetN()>0)
|
---|
291 | fRateTime.SetMinimum(0);
|
---|
292 |
|
---|
293 | DrawGraph(fRateTime, "f [Hz]");
|
---|
294 | /*
|
---|
295 | gPad->cd(1);
|
---|
296 |
|
---|
297 | if (gPad)
|
---|
298 | {
|
---|
299 | fHumidity.GetHistogram()->GetYaxis()->SetTitleColor(kBlue);
|
---|
300 | UpdateRightAxis(fTemperature);
|
---|
301 | }*/
|
---|
302 | }
|
---|