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

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