source: branches/Mars_IncreaseNsb/mpointing/MHPointing.cc@ 20095

Last change on this file since 20095 was 9422, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 10.4 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// MHPointing
28//
29// Display drive information
30//
31// Class Version 2:
32// ----------------
33//
34// + TGraph fNumStarsCor; // Number of correlated stars identified by starguider
35//
36////////////////////////////////////////////////////////////////////////////
37#include "MHPointing.h"
38
39#include <TH1.h>
40#include <TPad.h>
41#include <TCanvas.h>
42#include <TGaxis.h>
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "MParList.h"
48
49#include "MTime.h"
50#include "MAstro.h"
51
52#include "MReportDrive.h"
53#include "MReportStarguider.h"
54
55ClassImp(MHPointing);
56
57using namespace std;
58
59void MHPointing::ResetGraph(TGraph &g) const
60{
61 g.Set(1);
62 g.SetPoint(0, 0, 0); // Dummy Point
63 g.SetEditable(); // Used as flag: First point? yes/no
64}
65
66void MHPointing::InitGraph(TGraph &g) const
67{
68 ResetGraph(g);
69 g.SetMarkerStyle(kFullDotMedium);
70}
71
72void MHPointing::AddPoint(TGraph &g, Double_t x, Double_t y) const
73{
74 if (g.IsEditable())
75 {
76 g.RemovePoint(0);
77 g.SetEditable(kFALSE);
78 }
79
80 g.SetPoint(g.GetN(), x, y);
81}
82
83// --------------------------------------------------------------------------
84//
85// Setup histograms
86//
87MHPointing::MHPointing(const char *name, const char *title)
88: /*fTime(0),*/ fReportCosy(0), fReportSG(0)
89{
90 fName = name ? name : "MHPointing";
91 fTitle = title ? title : "Graphs for rate data";
92
93 // Init Graphs
94 fDevTimeSG.SetNameTitle("DevSG", "Absolute deviation of drive (black) and starguider (blue)");
95 fDevTimeCosy.SetNameTitle("DevCosy", "Cosy deviation");
96 fBrightness.SetNameTitle("Brightness", "Arbitrary Sky Brightness (black), No. of stars identified by starguider (blue)");
97 fNumStars.SetNameTitle("NumStars", "Number of stars identified by starguider");
98 fNumStarsCor.SetNameTitle("NumStarsCor", "Number of stars correlated by starguider");
99 fDevZd.SetNameTitle("DevZd", "Starguider deviation Zd (blue), Az (black)");
100 fDevAz.SetNameTitle("DevAz", "Starguider Deviation Az");
101 fPosZd.SetNameTitle("PosZd", "Nominal position Zd");
102 //fPosAz.SetNameTitle("PosZd", "Position Az");
103
104 InitGraph(fDevTimeSG);
105 InitGraph(fDevTimeCosy);
106 InitGraph(fBrightness);
107 InitGraph(fNumStars);
108 InitGraph(fNumStarsCor);
109 InitGraph(fDevZd);
110 InitGraph(fDevAz);
111 InitGraph(fPosZd);
112 //InitGraph(fPosAz);
113
114 fDevTimeSG.SetMarkerColor(kBlue);
115 fDevZd.SetMarkerColor(kBlue);
116 fNumStars.SetMarkerColor(kBlue);
117 fNumStarsCor.SetMarkerColor(kMagenta);
118 //fPosAz.SetMarkerColor(kBlue);
119}
120
121// --------------------------------------------------------------------------
122//
123// Setup the Binning for the histograms automatically if the correct
124// instances of MBinning
125//
126Bool_t MHPointing::SetupFill(const MParList *plist)
127{
128 //fTime = (MTime*)plist->FindObject("MTime");
129 //if (!fTime)
130 //{
131 // *fLog << warn << "MTime not found... abort." << endl;
132 // return kFALSE;
133 //}
134 fReportSG = (MReportStarguider*)plist->FindObject("MReportStarguider");
135 if (!fReportSG)
136 *fLog << warn << "MReportStarguider not found..." << endl;
137
138 fReportCosy = (MReportDrive*)plist->FindObject("MReportDrive");
139 if (!fReportCosy)
140 *fLog << warn << "MReportDrive not found..." << endl;
141
142 // Reset Graphs
143 ResetGraph(fDevTimeSG);
144 ResetGraph(fDevTimeCosy);
145
146 return kTRUE;
147}
148
149// --------------------------------------------------------------------------
150//
151// Fill the histograms with data from a MMuonCalibPar and
152// MMuonSearchPar container.
153//
154Int_t MHPointing::Fill(const MParContainer *par, const Stat_t w)
155{
156 const MTime *t = dynamic_cast<const MTime*>(par);
157 if (!t)
158 {
159 *fLog << err <<"MHPointing::Fill - ERROR: MTime not given as argument... abort." << endl;
160 return kERROR;
161 }
162
163 const Double_t tm = t->GetAxisTime();
164
165 if (t->GetName()==(TString)"MTimeStarguider")
166 {
167 if (!fReportSG)
168 {
169 *fLog << err << "ERROR: fReportSG==NULL... abort." << endl;
170 return kERROR;
171 }
172
173 // Check for old files
174 if (fReportSG->GetSkyBrightness()>0)
175 {
176 AddPoint(fBrightness, tm, fReportSG->GetSkyBrightness());
177 AddPoint(fNumStars, tm, fReportSG->GetNumIdentifiedStars());
178 AddPoint(fNumStarsCor, tm, fReportSG->GetNumCorrelatedStars());
179 }
180
181 const Bool_t zdok = TMath::Abs(fReportSG->GetDevZd())<30;
182 const Bool_t azok = TMath::Abs(fReportSG->GetDevAz())<90;
183
184 const Double_t devzd = fReportSG->GetDevZd();
185 const Double_t devaz = fReportSG->GetDevAz();
186
187 if (zdok && azok)
188 AddPoint(fDevTimeSG, tm, fReportSG->GetDevAbs());
189 if (zdok)
190 AddPoint(fDevZd, tm, devzd);
191 if (azok)
192 AddPoint(fDevAz, tm, devaz);
193 return kTRUE;
194 }
195
196 if (fReportCosy && t->GetName()==(TString)"MTimeDrive")
197 {
198 if (!fReportCosy)
199 {
200 *fLog << err << "ERROR: fReportCosy==NULL... abort." << endl;
201 return kERROR;
202 }
203
204 AddPoint(fDevTimeCosy, tm, fReportCosy->GetAbsError()*60);
205 if (fPosZd.GetY()[fPosZd.GetN()-1] != fReportCosy->GetNominalZd())
206 AddPoint(fPosZd, tm, fReportCosy->GetNominalZd());
207 //if (fPosAz.GetY()[fPosAz.GetN()-1] != fReportCosy->GetNominalAz())
208 // AddPoint(fPosAz, tm, fReportCosy->GetNominalAz());
209 return kTRUE;
210 }
211
212 return kTRUE;
213}
214
215void MHPointing::DrawGraph(TGraph &g, const char *y) const
216{
217 // This is not done automatically anymore since root 5.12/00
218 // and it is necessary to force a proper update of the axis.
219 TH1 *h = g.GetHistogram();
220 if (h)
221 {
222 delete h;
223 g.SetHistogram(0);
224 h = g.GetHistogram();
225 }
226 if (h)
227 {
228 TAxis *axe = h->GetXaxis();
229 axe->SetLabelSize(0.033);
230 axe->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
231 axe->SetTimeDisplay(1);
232 axe->SetTitle("Time");
233 if (y)
234 h->SetYTitle(y);
235 }
236}
237
238// --------------------------------------------------------------------------
239//
240// Update position of an axis on the right side of the histogram
241//
242void MHPointing::UpdateRightAxis(TGraph &g1, TGraph &g2) const
243{
244 TH1 &h1 = *g1.GetHistogram();
245 TH1 &h2 = *g2.GetHistogram();
246
247 const Double_t max = TMath::Max(h1.GetMaximum(), h2.GetMaximum());
248 if (max==0)
249 return;
250
251 TGaxis *axis = (TGaxis*)gPad->FindObject("RightAxis");
252 if (!axis)
253 return;
254
255 axis->SetX1(g1.GetXaxis()->GetXmax());
256 axis->SetX2(g1.GetXaxis()->GetXmax());
257 axis->SetY1(gPad->GetUymin());
258 axis->SetY2(gPad->GetUymax());
259 axis->SetWmax(max);
260}
261
262// --------------------------------------------------------------------------
263//
264// Draw an axis on the right side of the histogram
265//
266
267void MHPointing::DrawRightAxis(const char *title) const
268{
269 TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(),
270 gPad->GetUxmax(), gPad->GetUymax(),
271 0, 1, 510, "+L");
272 axis->SetName("RightAxis");
273 axis->SetTitle(title);
274 axis->SetTitleOffset(0.9);
275 axis->SetTextColor(kBlue);
276 axis->SetBit(kCanDelete);
277 axis->Draw();
278}
279
280// --------------------------------------------------------------------------
281//
282// This displays the TGraph like you expect it to be (eg. time on the axis)
283// It should also make sure, that the displayed time always is UTC and
284// not local time...
285//
286void MHPointing::Draw(Option_t *opt)
287{
288 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
289 pad->SetBorderMode(0);
290
291 AppendPad();
292
293 pad->Divide(2,2);
294
295 pad->cd(1);
296 gPad->SetBorderMode(0);
297 gPad->SetGridx();
298 gPad->SetGridy();
299 fDevTimeSG.Draw("AP");
300 fDevTimeCosy.Draw("P");
301
302 pad->cd(2);
303 gPad->SetBorderMode(0);
304 gPad->SetGridx();
305 gPad->SetGridy();
306 fBrightness.Draw("AP");
307 fNumStars.Draw("P");
308 fNumStarsCor.Draw("P");
309 DrawRightAxis("N");
310
311 pad->cd(3);
312 gPad->SetBorderMode(0);
313 gPad->SetGridx();
314 gPad->SetGridy();
315 fDevZd.Draw("AP");
316 fDevAz.Draw("P");
317
318 pad->cd(4);
319 gPad->SetBorderMode(0);
320 gPad->SetGridx();
321 gPad->SetGridy();
322 fPosZd.Draw("AP");
323 //fPosAz.Draw("P");
324 //DrawRightAxis("Az [\\circ]");
325}
326
327void MHPointing::Paint(Option_t *o)
328{
329 // If this is set to early the plot remains empty in root 5.12/00
330 if (fDevTimeSG.GetN()>0)
331 fDevTimeSG.SetMinimum(0);
332 if (fDevTimeCosy.GetN()>0)
333 fDevTimeCosy.SetMinimum(0);
334
335
336 if (fBrightness.GetN()>0)
337 {
338 fBrightness.SetMinimum(0);
339 fBrightness.SetMaximum(95);
340 }
341 if (fNumStars.GetN()>0)
342 {
343 fNumStars.SetMinimum(0);
344 fNumStars.SetMaximum(95);
345 }
346 if (fNumStarsCor.GetN()>0)
347 {
348 fNumStarsCor.SetMinimum(0);
349 fNumStarsCor.SetMaximum(95);
350 }
351
352 DrawGraph(fDevTimeSG, "\\Delta [arcmin]");
353 DrawGraph(fDevTimeCosy, "\\Delta [arcmin]");
354 DrawGraph(fBrightness, "Brightness [au]");
355 DrawGraph(fNumStars, "N");
356 DrawGraph(fDevZd, "\\Delta [arcmin]");
357 DrawGraph(fDevAz, "\\Delta [arcmin]");
358 DrawGraph(fPosZd, "Zd [\\circ]");
359 //DrawGraph(fPosAz, "Az [\\circ]");
360
361 TVirtualPad *pad = gPad;
362
363 pad->cd(2);
364 if (gPad)
365 {
366 fNumStars.GetHistogram()->GetYaxis()->SetTitleColor(kBlue);
367 UpdateRightAxis(fNumStars, fNumStarsCor);
368 }
369/*
370 pad->cd(4);
371 if (gPad)
372 {
373 fPosAz.GetHistogram()->GetYaxis()->SetTitleColor(kBlue);
374 UpdateRightAxis(fPosAz);
375 }*/
376}
Note: See TracBrowser for help on using the repository browser.