1 | #include "MGNumStars.h"
|
---|
2 |
|
---|
3 | #include <iostream.h> // cout
|
---|
4 |
|
---|
5 | #include <TLine.h>
|
---|
6 | #include <TText.h>
|
---|
7 | #include <TWbox.h>
|
---|
8 | #include <TGaxis.h>
|
---|
9 | #include <TGraph.h>
|
---|
10 | #include <TCanvas.h>
|
---|
11 |
|
---|
12 | #include "MTime.h"
|
---|
13 |
|
---|
14 | ClassImp(MGNumStars);
|
---|
15 |
|
---|
16 | void MGNumStars::DrawText(const char*txt)
|
---|
17 | {
|
---|
18 | fCanvas->SetEditable(kTRUE);
|
---|
19 | fCanvas->cd();
|
---|
20 |
|
---|
21 | TText text;
|
---|
22 | text.SetTextAlign(22); // centered, centered (s.TAttText)
|
---|
23 | text.SetTextSize(0.12);
|
---|
24 | text.DrawText(275, 44, txt);
|
---|
25 |
|
---|
26 | fCanvas->SetEditable(kFALSE);
|
---|
27 | }
|
---|
28 |
|
---|
29 | void MGNumStars::DrawCoordinateSystem()
|
---|
30 | {
|
---|
31 | fCanvas->Range(-50, -4, 600, 50);
|
---|
32 |
|
---|
33 | TWbox box;
|
---|
34 | box.DrawWbox(325-150-50, 38, 325+150-50, 48, 18, 2, 1);
|
---|
35 |
|
---|
36 | TLine line;
|
---|
37 | line.DrawLine(0, 0, 600-25, 0);
|
---|
38 | line.SetLineStyle(kDashed);
|
---|
39 | line.SetLineColor(kRed);
|
---|
40 | line.DrawLine(0, 6.5, 600-25, 6.5);
|
---|
41 | line.SetLineColor(kYellow);
|
---|
42 | line.DrawLine(0, 10.5, 600-25, 10.5);
|
---|
43 |
|
---|
44 | TGaxis *axe;
|
---|
45 | axe = new TGaxis(0, 0, 0, 47.5, 0, 47.5, 304, "-");
|
---|
46 | axe->SetLabelSize(0.1);
|
---|
47 | axe->SetLabelOffset(0.02);
|
---|
48 | axe->SetBit(kCanDelete);
|
---|
49 | axe->Draw();
|
---|
50 | }
|
---|
51 |
|
---|
52 | void MGNumStars::InitText()
|
---|
53 | {
|
---|
54 | fTxt = new TText(600*0.97, 50*0.92, "0/0");
|
---|
55 | fTxt->SetTextAlign(33); // right, top
|
---|
56 | fTxt->SetTextColor(10);
|
---|
57 | fTxt->SetTextSize(0.12);
|
---|
58 | fTxt->Draw();
|
---|
59 |
|
---|
60 | fList->Add(fTxt);
|
---|
61 | }
|
---|
62 |
|
---|
63 | void MGNumStars::InitBar(TLine* &bar)
|
---|
64 | {
|
---|
65 | bar = new TLine(0, 0, 0, 0);
|
---|
66 | bar->SetLineColor(kBlack);
|
---|
67 | bar->SetLineStyle(1);
|
---|
68 | bar->SetLineWidth(5);
|
---|
69 | bar->Draw();
|
---|
70 |
|
---|
71 | fList->Add(bar);
|
---|
72 | }
|
---|
73 |
|
---|
74 | void MGNumStars::InitGraph(TGraph* &graph, Int_t col)
|
---|
75 | {
|
---|
76 | graph = new TGraph;
|
---|
77 | graph->SetPoint(0, 0, 0);
|
---|
78 | graph->SetLineColor(col);
|
---|
79 | graph->SetMarkerColor(col);
|
---|
80 | graph->SetMarkerStyle(kFullDotMedium);
|
---|
81 | graph->Draw("LP");
|
---|
82 | fList->Add(graph);
|
---|
83 | }
|
---|
84 |
|
---|
85 | MGNumStars::MGNumStars(const TGWindow* p, const UInt_t w)
|
---|
86 | : MGEmbeddedCanvas("NumStars", p, w, 300)
|
---|
87 | {
|
---|
88 | DrawCoordinateSystem();
|
---|
89 |
|
---|
90 | InitGraph(fGraph1, kBlue);
|
---|
91 | InitGraph(fGraph2, kCyan);
|
---|
92 |
|
---|
93 | InitText();
|
---|
94 | InitBar(fBar1);
|
---|
95 | InitBar(fBar2);
|
---|
96 |
|
---|
97 | InitCanvas();
|
---|
98 |
|
---|
99 | Resize(245, 100);
|
---|
100 |
|
---|
101 | SetNoContextMenu();
|
---|
102 |
|
---|
103 | MTime t(-1);
|
---|
104 | fTime = t.GetAxisTime();
|
---|
105 | }
|
---|
106 |
|
---|
107 | MGNumStars::~MGNumStars()
|
---|
108 | {
|
---|
109 | }
|
---|
110 |
|
---|
111 | // dist [deg]
|
---|
112 | void MGNumStars::UpdateBar(TLine &bar, UInt_t num)
|
---|
113 | {
|
---|
114 | bar.SetY2(num);
|
---|
115 | if (num<11)
|
---|
116 | bar.SetLineColor(kYellow);
|
---|
117 | else
|
---|
118 | if (num<7)
|
---|
119 | bar.SetLineColor(kRed);
|
---|
120 | else
|
---|
121 | bar.SetLineColor(kGreen);
|
---|
122 |
|
---|
123 | SetModified();
|
---|
124 | }
|
---|
125 |
|
---|
126 | // dist [deg]
|
---|
127 | void MGNumStars::UpdateGraph(TGraph &graph, Double_t dtime, UInt_t num)
|
---|
128 | {
|
---|
129 | graph.SetPoint(graph.GetN(), dtime, num);
|
---|
130 |
|
---|
131 | const Double_t ntime = dtime;
|
---|
132 | for (int i=0; i<graph.GetN(); i++)
|
---|
133 | {
|
---|
134 | Double_t x, y;
|
---|
135 | graph.GetPoint(i, x, y);
|
---|
136 | graph.SetPoint(i, x+ntime, y);
|
---|
137 | }
|
---|
138 | while (graph.GetN()>0)
|
---|
139 | {
|
---|
140 | Double_t x, y;
|
---|
141 | graph.GetPoint(0, x, y);
|
---|
142 |
|
---|
143 | if (x==+ntime && y==0)
|
---|
144 | {
|
---|
145 | graph.RemovePoint(0);
|
---|
146 | continue;
|
---|
147 | }
|
---|
148 |
|
---|
149 | if (x<2*4.75*60)
|
---|
150 | break;
|
---|
151 |
|
---|
152 | graph.RemovePoint(0);
|
---|
153 | }
|
---|
154 |
|
---|
155 | SetModified();
|
---|
156 | }
|
---|
157 |
|
---|
158 | void MGNumStars::Update(UInt_t det, UInt_t cor)
|
---|
159 | {
|
---|
160 | char txt[100];
|
---|
161 | sprintf(txt, "%d/%d", cor, det);
|
---|
162 | fTxt->SetText(fTxt->GetX(), fTxt->GetY(), txt);
|
---|
163 |
|
---|
164 | UpdateBar(*fBar1, det);
|
---|
165 | UpdateBar(*fBar2, cor);
|
---|
166 |
|
---|
167 | MTime t(-1);
|
---|
168 | const Double_t dtime = t.GetAxisTime()-fTime; // range [-0.5h, 0h]
|
---|
169 |
|
---|
170 | UpdateGraph(*fGraph1, dtime, det);
|
---|
171 | UpdateGraph(*fGraph2, dtime, cor);
|
---|
172 |
|
---|
173 | fTime = t.GetAxisTime();
|
---|
174 |
|
---|
175 | UpdateCanvas();
|
---|
176 | }
|
---|