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

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