source: trunk/MagicSoft/Mars/mpointing/MHPointing.cc@ 8801

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