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

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