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 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
|
---|
19 | ! Author(s): Harald Kornmayer 1/2001
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | //
|
---|
27 | // The class MHexagon is needed for the Event Display of
|
---|
28 | // MAGIC.
|
---|
29 | //
|
---|
30 | #include "MHexagon.h"
|
---|
31 |
|
---|
32 | #include <fstream.h>
|
---|
33 | #include <iostream.h>
|
---|
34 |
|
---|
35 | #include <TVirtualPad.h> // gPad
|
---|
36 |
|
---|
37 | #include "MGeomPix.h" // GetX
|
---|
38 |
|
---|
39 | ClassImp(MHexagon);
|
---|
40 |
|
---|
41 | // ------------------------------------------------------------------------
|
---|
42 | //
|
---|
43 | // default constructor for MHexagon
|
---|
44 | //
|
---|
45 | MHexagon::MHexagon()
|
---|
46 | {
|
---|
47 | }
|
---|
48 |
|
---|
49 | // ------------------------------------------------------------------------
|
---|
50 | //
|
---|
51 | // normal constructor for MHexagon
|
---|
52 | //
|
---|
53 | MHexagon::MHexagon(Float_t x, Float_t y, Float_t d)
|
---|
54 | : TAttLine(1, 1, 1), TAttFill(0, 1001), fX(x), fY(y), fD(d)
|
---|
55 | {
|
---|
56 | }
|
---|
57 |
|
---|
58 | // ------------------------------------------------------------------------
|
---|
59 | //
|
---|
60 | // normal constructor for MHexagon
|
---|
61 | //
|
---|
62 | MHexagon::MHexagon(MGeomPix &pix)
|
---|
63 | : TAttLine(1, 1, 1), TAttFill(0, 1001)
|
---|
64 | {
|
---|
65 | fX = pix.GetX();
|
---|
66 | fY = pix.GetY();
|
---|
67 | fD = pix.GetR();
|
---|
68 | }
|
---|
69 |
|
---|
70 | // ------------------------------------------------------------------------
|
---|
71 | //
|
---|
72 | // copy constructor for MHexagon
|
---|
73 | //
|
---|
74 | MHexagon::MHexagon(const MHexagon &hexagon)
|
---|
75 | {
|
---|
76 | ((MHexagon&) hexagon).Copy(*this);
|
---|
77 | }
|
---|
78 |
|
---|
79 | // ------------------------------------------------------------------------
|
---|
80 | //
|
---|
81 | // default destructor for MHexagon
|
---|
82 | //
|
---|
83 | MHexagon::~MHexagon()
|
---|
84 | {
|
---|
85 | }
|
---|
86 |
|
---|
87 | // ------------------------------------------------------------------------
|
---|
88 | //
|
---|
89 | // copy this hexagon to hexagon
|
---|
90 | //
|
---|
91 | void MHexagon::Copy(TObject &obj)
|
---|
92 | {
|
---|
93 | MHexagon &hex = (MHexagon&) obj;
|
---|
94 |
|
---|
95 | TObject::Copy(obj);
|
---|
96 | TAttLine::Copy(hex);
|
---|
97 | TAttFill::Copy(hex);
|
---|
98 |
|
---|
99 | hex.fX = fX;
|
---|
100 | hex.fY = fY;
|
---|
101 | hex.fD = fD;
|
---|
102 | }
|
---|
103 |
|
---|
104 | // ------------------------------------------------------------------------
|
---|
105 | //
|
---|
106 | // compute the distance of a point (px,py) to the Hexagon
|
---|
107 | // this functions needed for graphical primitives, that
|
---|
108 | // means without this function you are not able to interact
|
---|
109 | // with the graphical primitive with the mouse!!!
|
---|
110 | //
|
---|
111 | // All calcutations are running in pixel coordinates
|
---|
112 | //
|
---|
113 | Int_t MHexagon::DistancetoPrimitive(Int_t px, Int_t py)
|
---|
114 | {
|
---|
115 | //
|
---|
116 | // compute the distance of the Point to the center of the Hexagon
|
---|
117 | //
|
---|
118 | const Int_t pxhex = gPad->XtoAbsPixel(fX);
|
---|
119 | const Int_t pyhex = gPad->YtoAbsPixel(fY);
|
---|
120 |
|
---|
121 | const Double_t disthex = TMath::Sqrt((Double_t)((pxhex-px)*(pxhex-px) + (pyhex-py)*(pyhex-py)));
|
---|
122 |
|
---|
123 | const Double_t cosa = TMath::Abs(px-pxhex) / disthex;
|
---|
124 | const Double_t sina = TMath::Abs(py-pyhex) / disthex;
|
---|
125 |
|
---|
126 | //
|
---|
127 | // comput the distance to pixel border
|
---|
128 | //
|
---|
129 | const Double_t dx = fD * cosa / 2;
|
---|
130 | const Double_t dy = fD * sina / 2;
|
---|
131 |
|
---|
132 | const Double_t xborder = fX + dx;
|
---|
133 | const Double_t yborder = fY + dy;
|
---|
134 |
|
---|
135 | const Int_t pxborder = gPad->XtoAbsPixel(xborder);
|
---|
136 | const Int_t pyborder = gPad->YtoAbsPixel(yborder);
|
---|
137 |
|
---|
138 | const Double_t distborder = TMath::Sqrt((Double_t)((pxborder-pxhex)*(pxborder-pxhex)+(pyborder-pyhex)*(pyborder-pyhex)));
|
---|
139 |
|
---|
140 | //
|
---|
141 | // compute the distance from the border of Pixel
|
---|
142 | // here in the first implementation is just circle inside
|
---|
143 | //
|
---|
144 | return distborder < disthex ? 999999 : 0;
|
---|
145 | }
|
---|
146 |
|
---|
147 | // ------------------------------------------------------------------------
|
---|
148 | //
|
---|
149 | // Draw this ellipse with new coordinate
|
---|
150 | //
|
---|
151 | void MHexagon::DrawHexagon(Float_t x, Float_t y, Float_t d)
|
---|
152 | {
|
---|
153 | MHexagon *newhexagon = new MHexagon(x, y, d);
|
---|
154 |
|
---|
155 | TAttLine::Copy(*newhexagon);
|
---|
156 | TAttFill::Copy(*newhexagon);
|
---|
157 |
|
---|
158 | newhexagon->SetBit(kCanDelete);
|
---|
159 | newhexagon->AppendPad();
|
---|
160 | }
|
---|
161 |
|
---|
162 | /*
|
---|
163 | // ------------------------------------------------------------------------
|
---|
164 | //
|
---|
165 | // This is the first test of implementing a clickable interface
|
---|
166 | // for one pixel
|
---|
167 | //
|
---|
168 | void MHexagon::ExecuteEvent(Int_t event, Int_t px, Int_t py)
|
---|
169 | {
|
---|
170 | switch (event)
|
---|
171 | {
|
---|
172 | case kButton1Down:
|
---|
173 | cout << endl << "kButton1Down" << endl;
|
---|
174 | SetFillColor(2);
|
---|
175 | gPad->Modified();
|
---|
176 | break;
|
---|
177 |
|
---|
178 | case kButton1Double:
|
---|
179 | SetFillColor(0);
|
---|
180 | gPad->Modified();
|
---|
181 | break;
|
---|
182 | // case kMouseEnter:
|
---|
183 | // printf ("\n Mouse inside object \n" ) ;
|
---|
184 | // break;
|
---|
185 | }
|
---|
186 | }
|
---|
187 | */
|
---|
188 |
|
---|
189 | // ------------------------------------------------------------------------
|
---|
190 | //
|
---|
191 | // list this hexagon with its attributes
|
---|
192 | //
|
---|
193 | void MHexagon::ls(const Option_t *) const
|
---|
194 | {
|
---|
195 | TROOT::IndentLevel();
|
---|
196 | Print();
|
---|
197 | }
|
---|
198 |
|
---|
199 | // ------------------------------------------------------------------------
|
---|
200 | //
|
---|
201 | // paint this hexagon with its attribute
|
---|
202 | //
|
---|
203 | void MHexagon::Paint(Option_t *)
|
---|
204 | {
|
---|
205 | PaintHexagon(fX, fY, fD);
|
---|
206 | }
|
---|
207 |
|
---|
208 | // ------------------------------------------------------------------------
|
---|
209 | //
|
---|
210 | // draw this hexagon with the coordinates
|
---|
211 | //
|
---|
212 | void MHexagon::PaintHexagon(Float_t inX, Float_t inY, Float_t inD)
|
---|
213 | {
|
---|
214 |
|
---|
215 | const Int_t np = 6;
|
---|
216 |
|
---|
217 | const Float_t dx[np+1] = { .5 , 0. , -.5 , -.5 , 0. , .5 , .5 };
|
---|
218 | const Float_t dy[np+1] = { .2886, .5772, .2886, -.2886, -.5772, -.2886, .2886 };
|
---|
219 |
|
---|
220 | static Float_t x[np+1], y[np+1];
|
---|
221 |
|
---|
222 | TAttLine::Modify(); // Change line attributes only if neccessary
|
---|
223 | TAttFill::Modify(); // Change fill attributes only if neccessary
|
---|
224 |
|
---|
225 | // calculate the positions of the pixel corners
|
---|
226 |
|
---|
227 | for (Int_t i=0; i<=np; i++)
|
---|
228 | {
|
---|
229 | x[i] = inX + dx[i]* inD;
|
---|
230 | y[i] = inY + dy[i]* inD;
|
---|
231 | }
|
---|
232 |
|
---|
233 | // paint the pixel (hopefully)
|
---|
234 |
|
---|
235 | if (GetFillColor())
|
---|
236 | gPad->PaintFillArea(np, x, y);
|
---|
237 |
|
---|
238 | if (GetLineStyle())
|
---|
239 | gPad->PaintPolyLine(np+1, x, y);
|
---|
240 |
|
---|
241 | }
|
---|
242 |
|
---|
243 | // ------------------------------------------------------------------------
|
---|
244 | //
|
---|
245 | // print/dump this hexagon with its attributes
|
---|
246 | //
|
---|
247 | void MHexagon::Print(Option_t *) const
|
---|
248 | {
|
---|
249 | cout << "MHexagon: ";
|
---|
250 | cout << "x=" << fX << "mm y=" << fY << "mm r=" << fD << "mm" << endl;
|
---|
251 |
|
---|
252 | cout << " Line:";
|
---|
253 | cout << " Color=" << GetLineColor() << ",";
|
---|
254 | cout << " Style=" << GetLineStyle() << ",";
|
---|
255 | cout << " Width=" << GetLineWidth() << endl;
|
---|
256 | cout << " Fill:";
|
---|
257 | cout << " Color=" << GetFillColor() << ",";
|
---|
258 | cout << " Style=" << GetFillStyle() << endl;
|
---|
259 | }
|
---|
260 |
|
---|
261 | // ------------------------------------------------------------------------
|
---|
262 | //
|
---|
263 | // Save primitive as a C++ statement(s) on output stream out
|
---|
264 | //
|
---|
265 | void MHexagon::SavePrimitive(ofstream &out, Option_t *)
|
---|
266 | {
|
---|
267 |
|
---|
268 | if (gROOT->ClassSaved(MHexagon::Class()))
|
---|
269 | out << " ";
|
---|
270 | else
|
---|
271 | out << " MHexagon *";
|
---|
272 |
|
---|
273 | out << "hexagon = new MHexagon(" << fX << "," << fY << "," << fD << ");" << endl;
|
---|
274 |
|
---|
275 | SaveFillAttributes(out, "hexagon");
|
---|
276 | SaveLineAttributes(out, "hexagon");
|
---|
277 |
|
---|
278 | out << " hexagon->Draw();" << endl;
|
---|
279 | }
|
---|