| 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@astro.uni-wuerzburg.de>
|
|---|
| 19 | ! Author(s): Harald Kornmayer 1/2001
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: MAGIC Software Development, 2000-2002
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | // //
|
|---|
| 28 | // MHexagon //
|
|---|
| 29 | // //
|
|---|
| 30 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 31 |
|
|---|
| 32 | #include "MHexagon.h"
|
|---|
| 33 |
|
|---|
| 34 | #include <fstream>
|
|---|
| 35 | #include <iostream>
|
|---|
| 36 |
|
|---|
| 37 | #include <TVirtualPad.h> // gPad
|
|---|
| 38 |
|
|---|
| 39 | #include "MGeomPix.h" // GetX
|
|---|
| 40 |
|
|---|
| 41 | ClassImp(MHexagon);
|
|---|
| 42 |
|
|---|
| 43 | using namespace std;
|
|---|
| 44 |
|
|---|
| 45 | // ------------------------------------------------------------------------
|
|---|
| 46 | //
|
|---|
| 47 | // default constructor for MHexagon
|
|---|
| 48 | //
|
|---|
| 49 | MHexagon::MHexagon()
|
|---|
| 50 | {
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | // ------------------------------------------------------------------------
|
|---|
| 54 | //
|
|---|
| 55 | // normal constructor for MHexagon
|
|---|
| 56 | //
|
|---|
| 57 | MHexagon::MHexagon(Float_t x, Float_t y, Float_t d)
|
|---|
| 58 | : TAttLine(1, 1, 1), TAttFill(0, 1001), fX(x), fY(y), fD(d)
|
|---|
| 59 | {
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | // ------------------------------------------------------------------------
|
|---|
| 63 | //
|
|---|
| 64 | // normal constructor for MHexagon
|
|---|
| 65 | //
|
|---|
| 66 | MHexagon::MHexagon(const MGeomPix &pix)
|
|---|
| 67 | : TAttLine(1, 1, 1), TAttFill(0, 1001)
|
|---|
| 68 | {
|
|---|
| 69 | fX = pix.GetX();
|
|---|
| 70 | fY = pix.GetY();
|
|---|
| 71 | fD = pix.GetD();
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | // ------------------------------------------------------------------------
|
|---|
| 75 | //
|
|---|
| 76 | // copy constructor for MHexagon
|
|---|
| 77 | //
|
|---|
| 78 | MHexagon::MHexagon(const MHexagon &hexagon) : TObject(hexagon), TAttLine(hexagon), TAttFill(hexagon)
|
|---|
| 79 | {
|
|---|
| 80 | fX = hexagon.fX;
|
|---|
| 81 | fY = hexagon.fY;
|
|---|
| 82 | fD = hexagon.fD;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | // ------------------------------------------------------------------------
|
|---|
| 86 | //
|
|---|
| 87 | // copy this hexagon to hexagon
|
|---|
| 88 | //
|
|---|
| 89 | void MHexagon::Copy(TObject &obj)
|
|---|
| 90 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,04,01)
|
|---|
| 91 | const
|
|---|
| 92 | #endif
|
|---|
| 93 | {
|
|---|
| 94 | MHexagon &hex = (MHexagon&) obj;
|
|---|
| 95 |
|
|---|
| 96 | TObject::Copy(obj);
|
|---|
| 97 | TAttLine::Copy(hex);
|
|---|
| 98 | TAttFill::Copy(hex);
|
|---|
| 99 |
|
|---|
| 100 | hex.fX = fX;
|
|---|
| 101 | hex.fY = fY;
|
|---|
| 102 | hex.fD = fD;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | // ------------------------------------------------------------------------
|
|---|
| 106 | //
|
|---|
| 107 | // compute the distance of a point (px,py) to the Hexagon
|
|---|
| 108 | // this functions needed for graphical primitives, that
|
|---|
| 109 | // means without this function you are not able to interact
|
|---|
| 110 | // with the graphical primitive with the mouse!!!
|
|---|
| 111 | //
|
|---|
| 112 | // All calcutations are running in pixel coordinates
|
|---|
| 113 | //
|
|---|
| 114 | Int_t MHexagon::DistancetoPrimitive(Int_t px, Int_t py, Float_t conv)
|
|---|
| 115 | {
|
|---|
| 116 | //
|
|---|
| 117 | // compute the distance of the Point to the center of the Hexagon
|
|---|
| 118 | //
|
|---|
| 119 | const Int_t pxhex = gPad->XtoAbsPixel(fX*conv);
|
|---|
| 120 | const Int_t pyhex = gPad->YtoAbsPixel(fY*conv);
|
|---|
| 121 |
|
|---|
| 122 | const Double_t x = TMath::Abs(px-pxhex);
|
|---|
| 123 | const Double_t y = TMath::Abs(py-pyhex);
|
|---|
| 124 |
|
|---|
| 125 | const Double_t disthex = TMath::Sqrt(x*x + y*y);
|
|---|
| 126 |
|
|---|
| 127 | if (disthex==0)
|
|---|
| 128 | return 0;
|
|---|
| 129 |
|
|---|
| 130 | const Double_t cosa = x / disthex;
|
|---|
| 131 | const Double_t sina = y / disthex;
|
|---|
| 132 |
|
|---|
| 133 | //
|
|---|
| 134 | // comput the distance of hexagon center to pixel border
|
|---|
| 135 | //
|
|---|
| 136 | const Double_t dx = fD/2 * cosa;
|
|---|
| 137 | const Double_t dy = fD/2 * sina;
|
|---|
| 138 |
|
|---|
| 139 | const Int_t pxborder = gPad->XtoAbsPixel((fX + dx)*conv);
|
|---|
| 140 | const Int_t pyborder = gPad->YtoAbsPixel((fY + dy)*conv);
|
|---|
| 141 |
|
|---|
| 142 | const Double_t bx = pxhex-pxborder;
|
|---|
| 143 | const Double_t by = pyhex-pyborder;
|
|---|
| 144 |
|
|---|
| 145 | const Double_t distborder = TMath::Sqrt(bx*bx + by*by);
|
|---|
| 146 |
|
|---|
| 147 | //
|
|---|
| 148 | // compute the distance from the border of Pixel
|
|---|
| 149 | // here in the first implementation is just circle inside
|
|---|
| 150 | //
|
|---|
| 151 | return distborder < disthex ? (int)((disthex-distborder)/conv+1) : 0;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | // ------------------------------------------------------------------------
|
|---|
| 155 | //
|
|---|
| 156 | // compute the distance of a point (px,py) to the Hexagon center in world
|
|---|
| 157 | // coordinates. Return -1 if inside.
|
|---|
| 158 | //
|
|---|
| 159 | Float_t MHexagon::DistanceToPrimitive(Float_t px, Float_t py)
|
|---|
| 160 | {
|
|---|
| 161 | //
|
|---|
| 162 | // compute the distance of the Point to the center of the Hexagon
|
|---|
| 163 | //
|
|---|
| 164 | const Double_t dx = px-fX;
|
|---|
| 165 | const Double_t dy = py-fY;
|
|---|
| 166 | const Double_t disthex = TMath::Sqrt(dx*dx + dy*dy);
|
|---|
| 167 |
|
|---|
| 168 | //
|
|---|
| 169 | // Now check if point is outside of hexagon; just check x coordinate
|
|---|
| 170 | // in three coordinate systems: the default one, in which two sides of
|
|---|
| 171 | // the hexagon are paralel to the y axis (see camera displays) and two
|
|---|
| 172 | // more, rotated with respect to that one by +- 60 degrees.
|
|---|
| 173 | //
|
|---|
| 174 |
|
|---|
| 175 | if (TMath::Abs(dx) > fD/2.)
|
|---|
| 176 | return disthex;
|
|---|
| 177 |
|
|---|
| 178 | const static Double_t cos60 = TMath::Cos(60/kRad2Deg);
|
|---|
| 179 | const static Double_t sin60 = TMath::Sin(60/kRad2Deg);
|
|---|
| 180 |
|
|---|
| 181 | const Double_t dx2 = dx*cos60 + dy*sin60;
|
|---|
| 182 |
|
|---|
| 183 | if (TMath::Abs(dx2) > fD/2.)
|
|---|
| 184 | return disthex;
|
|---|
| 185 |
|
|---|
| 186 | const Double_t dx3 = dx*cos60 - dy*sin60;
|
|---|
| 187 |
|
|---|
| 188 | if (TMath::Abs(dx3) > fD/2.)
|
|---|
| 189 | return disthex;
|
|---|
| 190 |
|
|---|
| 191 | return -1;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | /*
|
|---|
| 195 | Float_t MHexagon::DistanceToPrimitive(Float_t px, Float_t py)
|
|---|
| 196 | {
|
|---|
| 197 | //
|
|---|
| 198 | // compute the distance of the Point to the center of the Hexagon
|
|---|
| 199 | //
|
|---|
| 200 | const Double_t dx = px-fX;
|
|---|
| 201 | const Double_t dy = py-fY;
|
|---|
| 202 |
|
|---|
| 203 | const Double_t disthex = TMath::Sqrt(dx*dx + dy*dy);
|
|---|
| 204 |
|
|---|
| 205 | //
|
|---|
| 206 | // compute the distance from the border of Pixel
|
|---|
| 207 | // here in the first implementation is just circle outside
|
|---|
| 208 | //
|
|---|
| 209 | return fD*0.5772 < disthex ? disthex-fD*0.5772 : -1;
|
|---|
| 210 | //
|
|---|
| 211 | // FIXME: this approximate method results in some photons being
|
|---|
| 212 | // assigned to two or even three different pixels.
|
|---|
| 213 | //
|
|---|
| 214 | }
|
|---|
| 215 | */
|
|---|
| 216 |
|
|---|
| 217 | // ------------------------------------------------------------------------
|
|---|
| 218 | //
|
|---|
| 219 | // Draw this ellipse with new coordinate
|
|---|
| 220 | //
|
|---|
| 221 | void MHexagon::DrawHexagon(Float_t x, Float_t y, Float_t d)
|
|---|
| 222 | {
|
|---|
| 223 | MHexagon *newhexagon = new MHexagon(x, y, d);
|
|---|
| 224 |
|
|---|
| 225 | TAttLine::Copy(*newhexagon);
|
|---|
| 226 | TAttFill::Copy(*newhexagon);
|
|---|
| 227 |
|
|---|
| 228 | newhexagon->SetBit(kCanDelete);
|
|---|
| 229 | newhexagon->AppendPad();
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | /*
|
|---|
| 233 | // ------------------------------------------------------------------------
|
|---|
| 234 | //
|
|---|
| 235 | // This is the first test of implementing a clickable interface
|
|---|
| 236 | // for one pixel
|
|---|
| 237 | //
|
|---|
| 238 | void MHexagon::ExecuteEvent(Int_t event, Int_t px, Int_t py)
|
|---|
| 239 | {
|
|---|
| 240 | switch (event)
|
|---|
| 241 | {
|
|---|
| 242 | case kButton1Down:
|
|---|
| 243 | cout << endl << "kButton1Down" << endl;
|
|---|
| 244 | SetFillColor(2);
|
|---|
| 245 | gPad->Modified();
|
|---|
| 246 | break;
|
|---|
| 247 |
|
|---|
| 248 | case kButton1Double:
|
|---|
| 249 | SetFillColor(0);
|
|---|
| 250 | gPad->Modified();
|
|---|
| 251 | break;
|
|---|
| 252 | // case kMouseEnter:
|
|---|
| 253 | // printf ("\n Mouse inside object \n" ) ;
|
|---|
| 254 | // break;
|
|---|
| 255 | }
|
|---|
| 256 | }
|
|---|
| 257 | */
|
|---|
| 258 |
|
|---|
| 259 | // ------------------------------------------------------------------------
|
|---|
| 260 | //
|
|---|
| 261 | // list this hexagon with its attributes
|
|---|
| 262 | //
|
|---|
| 263 | void MHexagon::ls(const Option_t *) const
|
|---|
| 264 | {
|
|---|
| 265 | TROOT::IndentLevel();
|
|---|
| 266 | Print();
|
|---|
| 267 | }
|
|---|
| 268 |
|
|---|
| 269 | // ------------------------------------------------------------------------
|
|---|
| 270 | //
|
|---|
| 271 | // paint this hexagon with its attribute
|
|---|
| 272 | //
|
|---|
| 273 | void MHexagon::Paint(Option_t *)
|
|---|
| 274 | {
|
|---|
| 275 | PaintHexagon(fX, fY, fD);
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | // ------------------------------------------------------------------------
|
|---|
| 279 | //
|
|---|
| 280 | // draw this hexagon with the coordinates
|
|---|
| 281 | //
|
|---|
| 282 | void MHexagon::PaintHexagon(Float_t inX, Float_t inY, Float_t inD)
|
|---|
| 283 | {
|
|---|
| 284 | const Int_t np = 6;
|
|---|
| 285 |
|
|---|
| 286 | const Float_t dx[np+1] = { .5 , 0. , -.5 , -.5 , 0. , .5 , .5 };
|
|---|
| 287 | const Float_t dy[np+1] = { .2886, .5772, .2886, -.2886, -.5772, -.2886, .2886 };
|
|---|
| 288 |
|
|---|
| 289 | //
|
|---|
| 290 | // calculate the positions of the pixel corners
|
|---|
| 291 | //
|
|---|
| 292 | Float_t x[np+1], y[np+1];
|
|---|
| 293 | for (Int_t i=0; i<np+1; i++)
|
|---|
| 294 | {
|
|---|
| 295 | x[i] = inX + dx[i]*inD;
|
|---|
| 296 | y[i] = inY + dy[i]*inD;
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | TAttLine::Modify(); // Change line attributes only if neccessary
|
|---|
| 300 | TAttFill::Modify(); // Change fill attributes only if neccessary
|
|---|
| 301 |
|
|---|
| 302 | //
|
|---|
| 303 | // paint the pixel
|
|---|
| 304 | //
|
|---|
| 305 | if (GetFillColor())
|
|---|
| 306 | gPad->PaintFillArea(np, x, y);
|
|---|
| 307 |
|
|---|
| 308 | if (GetLineStyle())
|
|---|
| 309 | gPad->PaintPolyLine(np+1, x, y);
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | // ------------------------------------------------------------------------
|
|---|
| 313 | //
|
|---|
| 314 | // print/dump this hexagon with its attributes
|
|---|
| 315 | //
|
|---|
| 316 | void MHexagon::Print(Option_t *) const
|
|---|
| 317 | {
|
|---|
| 318 | cout << "MHexagon: ";
|
|---|
| 319 | cout << "x=" << fX << "mm y=" << fY << "mm r=" << fD << "mm" << endl;
|
|---|
| 320 |
|
|---|
| 321 | cout << " Line:";
|
|---|
| 322 | cout << " Color=" << GetLineColor() << ",";
|
|---|
| 323 | cout << " Style=" << GetLineStyle() << ",";
|
|---|
| 324 | cout << " Width=" << GetLineWidth() << endl;
|
|---|
| 325 | cout << " Fill:";
|
|---|
| 326 | cout << " Color=" << GetFillColor() << ",";
|
|---|
| 327 | cout << " Style=" << GetFillStyle() << endl;
|
|---|
| 328 | }
|
|---|
| 329 |
|
|---|
| 330 | // ------------------------------------------------------------------------
|
|---|
| 331 | //
|
|---|
| 332 | // Save primitive as a C++ statement(s) on output stream out
|
|---|
| 333 | //
|
|---|
| 334 | void MHexagon::SavePrimitive(ofstream &out, Option_t *)
|
|---|
| 335 | {
|
|---|
| 336 | if (gROOT->ClassSaved(Class()))
|
|---|
| 337 | out << " ";
|
|---|
| 338 | else
|
|---|
| 339 | out << " MHexagon *";
|
|---|
| 340 |
|
|---|
| 341 | out << "hexagon = new MHexagon(" << fX << "," << fY << "," << fD << ");" << endl;
|
|---|
| 342 |
|
|---|
| 343 | SaveFillAttributes(out, "hexagon");
|
|---|
| 344 | SaveLineAttributes(out, "hexagon");
|
|---|
| 345 |
|
|---|
| 346 | out << " hexagon->Draw();" << endl;
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|