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

Last change on this file since 7726 was 7726, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 9.8 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.SetMinimum(0);
114 fDevTimeCosy.SetMinimum(0);
115 fBrightness.SetMinimum(0);
116 fNumStars.SetMinimum(0);
117 fNumStarsCor.SetMinimum(0);
118
119 fDevTimeSG.SetMarkerColor(kBlue);
120 fDevZd.SetMarkerColor(kBlue);
121 fNumStars.SetMarkerColor(kBlue);
122 fNumStarsCor.SetMarkerColor(kMagenta);
123 //fPosAz.SetMarkerColor(kBlue);
124}
125
126// --------------------------------------------------------------------------
127//
128// Setup the Binning for the histograms automatically if the correct
129// instances of MBinning
130//
131Bool_t MHPointing::SetupFill(const MParList *plist)
132{
133 //fTime = (MTime*)plist->FindObject("MTime");
134 //if (!fTime)
135 //{
136 // *fLog << warn << "MTime not found... abort." << endl;
137 // return kFALSE;
138 //}
139 fReportSG = (MReportStarguider*)plist->FindObject("MReportStarguider");
140 if (!fReportSG)
141 *fLog << warn << "MReportStarguider not found..." << endl;
142
143 fReportCosy = (MReportDrive*)plist->FindObject("MReportDrive");
144 if (!fReportCosy)
145 *fLog << warn << "MReportDrive not found..." << endl;
146
147 // Reset Graphs
148 ResetGraph(fDevTimeSG);
149 ResetGraph(fDevTimeCosy);
150
151 return kTRUE;
152}
153
154// --------------------------------------------------------------------------
155//
156// Fill the histograms with data from a MMuonCalibPar and
157// MMuonSearchPar container.
158//
159Bool_t MHPointing::Fill(const MParContainer *par, const Stat_t w)
160{
161 const MTime *t = dynamic_cast<const MTime*>(par);
162 if (!t)
163 {
164 *fLog << err <<"MHPointing::Fill - ERROR: MTime not given as argument... abort." << endl;
165 return kERROR;
166 }
167
168 const Double_t tm = t->GetAxisTime();
169
170 if (t->GetName()==(TString)"MTimeStarguider")
171 {
172 if (!fReportSG)
173 {
174 *fLog << err << "ERROR: fReportSG==NULL... abort." << endl;
175 return kFALSE;
176 }
177
178 // Check for old files
179 if (fReportSG->GetSkyBrightness()>0)
180 {
181 AddPoint(fBrightness, tm, fReportSG->GetSkyBrightness());
182 AddPoint(fNumStars, tm, fReportSG->GetNumIdentifiedStars());
183 AddPoint(fNumStarsCor, tm, fReportSG->GetNumCorrelatedStars());
184 }
185
186 const Bool_t zdok = TMath::Abs(fReportSG->GetDevZd())<30;
187 const Bool_t azok = TMath::Abs(fReportSG->GetDevAz())<90;
188
189 const Double_t devzd = fReportSG->GetDevZd();
190 const Double_t devaz = fReportSG->GetDevAz();
191
192 if (zdok && azok)
193 AddPoint(fDevTimeSG, tm, fReportSG->GetDevAbs());
194 if (zdok)
195 AddPoint(fDevZd, tm, devzd);
196 if (azok)
197 AddPoint(fDevAz, tm, devaz);
198 return kTRUE;
199 }
200
201 if (fReportCosy && t->GetName()==(TString)"MTimeDrive")
202 {
203 if (!fReportCosy)
204 {
205 *fLog << err << "ERROR: fReportCosy==NULL... abort." << endl;
206 return kFALSE;
207 }
208
209 AddPoint(fDevTimeCosy, tm, fReportCosy->GetAbsError()*60);
210 if (fPosZd.GetY()[fPosZd.GetN()-1] != fReportCosy->GetNominalZd())
211 AddPoint(fPosZd, tm, fReportCosy->GetNominalZd());
212 //if (fPosAz.GetY()[fPosAz.GetN()-1] != fReportCosy->GetNominalAz())
213 // AddPoint(fPosAz, tm, fReportCosy->GetNominalAz());
214 return kTRUE;
215 }
216
217 return kTRUE;
218}
219
220void MHPointing::DrawGraph(TGraph &g, const char *y) const
221{
222 TH1 *h = g.GetHistogram();
223 if (h)
224 {
225 TAxis *axe = h->GetXaxis();
226 axe->SetLabelSize(0.033);
227 axe->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
228 axe->SetTimeDisplay(1);
229 axe->SetTitle("Time");
230 if (y)
231 h->SetYTitle(y);
232 }
233}
234
235// --------------------------------------------------------------------------
236//
237// Update position of an axis on the right side of the histogram
238//
239void MHPointing::UpdateRightAxis(TGraph &g1, TGraph &g2) const
240{
241 TH1 &h1 = *g1.GetHistogram();
242 TH1 &h2 = *g2.GetHistogram();
243
244 const Double_t max = TMath::Max(h1.GetMaximum(), h2.GetMaximum());
245 if (max==0)
246 return;
247
248 TGaxis *axis = (TGaxis*)gPad->FindObject("RightAxis");
249 if (!axis)
250 return;
251
252 axis->SetX1(g1.GetXaxis()->GetXmax());
253 axis->SetX2(g1.GetXaxis()->GetXmax());
254 axis->SetY1(gPad->GetUymin());
255 axis->SetY2(gPad->GetUymax());
256 axis->SetWmax(max);
257}
258
259// --------------------------------------------------------------------------
260//
261// Draw an axis on the right side of the histogram
262//
263
264void MHPointing::DrawRightAxis(const char *title) const
265{
266 TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(),
267 gPad->GetUxmax(), gPad->GetUymax(),
268 0, 1, 510, "+L");
269 axis->SetName("RightAxis");
270 axis->SetTitle(title);
271 axis->SetTitleOffset(0.9);
272 axis->SetTextColor(kBlue);
273 axis->SetBit(kCanDelete);
274 axis->Draw();
275}
276
277// --------------------------------------------------------------------------
278//
279// This displays the TGraph like you expect it to be (eg. time on the axis)
280// It should also make sure, that the displayed time always is UTC and
281// not local time...
282//
283void MHPointing::Draw(Option_t *opt)
284{
285 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
286 pad->SetBorderMode(0);
287
288 AppendPad();
289
290 pad->Divide(2,2);
291
292 pad->cd(1);
293 gPad->SetBorderMode(0);
294 gPad->SetGridx();
295 gPad->SetGridy();
296 fDevTimeSG.Draw("AP");
297 fDevTimeCosy.Draw("P");
298
299 pad->cd(2);
300 gPad->SetBorderMode(0);
301 gPad->SetGridx();
302 gPad->SetGridy();
303 fBrightness.Draw("AP");
304 fNumStars.Draw("P");
305 fNumStarsCor.Draw("P");
306 DrawRightAxis("N");
307
308 pad->cd(3);
309 gPad->SetBorderMode(0);
310 gPad->SetGridx();
311 gPad->SetGridy();
312 fDevZd.Draw("AP");
313 fDevAz.Draw("P");
314
315 pad->cd(4);
316 gPad->SetBorderMode(0);
317 gPad->SetGridx();
318 gPad->SetGridy();
319 fPosZd.Draw("AP");
320 //fPosAz.Draw("P");
321 //DrawRightAxis("Az [\\circ]");
322}
323
324void MHPointing::Paint(Option_t *o)
325{
326 DrawGraph(fDevTimeSG, "\\Delta [arcmin]");
327 DrawGraph(fDevTimeCosy, "\\Delta [arcmin]");
328 DrawGraph(fBrightness, "Brightness [au]");
329 DrawGraph(fNumStars, "N");
330 DrawGraph(fDevZd, "\\Delta [arcmin]");
331 DrawGraph(fDevAz, "\\Delta [arcmin]");
332 DrawGraph(fPosZd, "Zd [\\circ]");
333 //DrawGraph(fPosAz, "Az [\\circ]");
334
335 TVirtualPad *pad = gPad;
336
337 pad->cd(2);
338 if (gPad)
339 {
340 fNumStars.GetHistogram()->GetYaxis()->SetTitleColor(kBlue);
341 UpdateRightAxis(fNumStars, fNumStarsCor);
342 }
343/*
344 pad->cd(4);
345 if (gPad)
346 {
347 fPosAz.GetHistogram()->GetYaxis()->SetTitleColor(kBlue);
348 UpdateRightAxis(fPosAz);
349 }*/
350}
Note: See TracBrowser for help on using the repository browser.