| 1 | /* ======================================================================== *\
|
|---|
| 2 | ! $Name: not supported by cvs2svn $:$Id: MHexagon.cc,v 1.31 2009-01-21 14:34:48 tbretz Exp $
|
|---|
| 3 | ! --------------------------------------------------------------------------
|
|---|
| 4 | !
|
|---|
| 5 | ! *
|
|---|
| 6 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 7 | ! * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 8 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 9 | ! * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 10 | ! *
|
|---|
| 11 | ! * Permission to use, copy, modify and distribute this software and its
|
|---|
| 12 | ! * documentation for any purpose is hereby granted without fee,
|
|---|
| 13 | ! * provided that the above copyright notice appear in all copies and
|
|---|
| 14 | ! * that both that copyright notice and this permission notice appear
|
|---|
| 15 | ! * in supporting documentation. It is provided "as is" without express
|
|---|
| 16 | ! * or implied warranty.
|
|---|
| 17 | ! *
|
|---|
| 18 | !
|
|---|
| 19 | !
|
|---|
| 20 | ! Author(s): Thomas Bretz 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 21 | ! Author(s): Harald Kornmayer 1/2001
|
|---|
| 22 | !
|
|---|
| 23 | ! Copyright: Software Development, 2000-2009
|
|---|
| 24 | !
|
|---|
| 25 | !
|
|---|
| 26 | \* ======================================================================== */
|
|---|
| 27 |
|
|---|
| 28 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 29 | //
|
|---|
| 30 | // MHexagon
|
|---|
| 31 | //
|
|---|
| 32 | // Class Version 2:
|
|---|
| 33 | // - added fPhi
|
|---|
| 34 | //
|
|---|
| 35 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 36 |
|
|---|
| 37 | #include "MHexagon.h"
|
|---|
| 38 |
|
|---|
| 39 | #include <fstream>
|
|---|
| 40 | #include <iostream>
|
|---|
| 41 |
|
|---|
| 42 | #include <TVector2.h> // TVector2
|
|---|
| 43 | #include <TVirtualPad.h> // gPad
|
|---|
| 44 | #include <TOrdCollection.h> // TOrdCollection
|
|---|
| 45 |
|
|---|
| 46 | #include "MLog.h"
|
|---|
| 47 | #include "MLogManip.h"
|
|---|
| 48 |
|
|---|
| 49 | #include "MMath.h"
|
|---|
| 50 | #include "MGeomPix.h" // GetX
|
|---|
| 51 |
|
|---|
| 52 | ClassImp(MHexagon);
|
|---|
| 53 |
|
|---|
| 54 | using namespace std;
|
|---|
| 55 |
|
|---|
| 56 | const Double_t MHexagon::fgCos60 = 0.5; // TMath::Cos(60/TMath::RadToDeg());
|
|---|
| 57 | const Double_t MHexagon::fgSin60 = sqrt(3.)/2; // TMath::Sin(60/TMath::RadToDeg());
|
|---|
| 58 |
|
|---|
| 59 | const Double_t MHexagon::fgDx[6] = { fgCos60, 0., -fgCos60, -fgCos60, 0., fgCos60 };
|
|---|
| 60 | const Double_t MHexagon::fgDy[6] = { fgSin60/3, fgSin60*2/3, fgSin60/3, -fgSin60/3, -fgSin60*2/3, -fgSin60/3 };
|
|---|
| 61 |
|
|---|
| 62 | // ------------------------------------------------------------------------
|
|---|
| 63 | //
|
|---|
| 64 | // default constructor for MHexagon
|
|---|
| 65 | //
|
|---|
| 66 | MHexagon::MHexagon()
|
|---|
| 67 | {
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | // ------------------------------------------------------------------------
|
|---|
| 71 | //
|
|---|
| 72 | // normal constructor for MHexagon
|
|---|
| 73 | //
|
|---|
| 74 | MHexagon::MHexagon(Float_t x, Float_t y, Float_t d, Float_t phi)
|
|---|
| 75 | : TAttLine(1, 1, 1), TAttFill(0, 1001), fX(x), fY(y), fD(d), fPhi(phi)
|
|---|
| 76 | {
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | // ------------------------------------------------------------------------
|
|---|
| 80 | //
|
|---|
| 81 | // normal constructor for MHexagon
|
|---|
| 82 | //
|
|---|
| 83 | MHexagon::MHexagon(const MGeomPix &pix)
|
|---|
| 84 | : TAttLine(1, 1, 1), TAttFill(0, 1001), fPhi(0)
|
|---|
| 85 | {
|
|---|
| 86 | fX = pix.GetX();
|
|---|
| 87 | fY = pix.GetY();
|
|---|
| 88 | fD = pix.GetD();
|
|---|
| 89 |
|
|---|
| 90 | // fPhi = pix.GetPhi();
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | // ------------------------------------------------------------------------
|
|---|
| 94 | //
|
|---|
| 95 | // copy constructor for MHexagon
|
|---|
| 96 | //
|
|---|
| 97 | MHexagon::MHexagon(const MHexagon &hexagon) : TObject(hexagon), TAttLine(hexagon), TAttFill(hexagon)
|
|---|
| 98 | {
|
|---|
| 99 | fX = hexagon.fX;
|
|---|
| 100 | fY = hexagon.fY;
|
|---|
| 101 | fD = hexagon.fD;
|
|---|
| 102 | fPhi = hexagon.fPhi;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | // ------------------------------------------------------------------------
|
|---|
| 106 | //
|
|---|
| 107 | // copy this hexagon to hexagon
|
|---|
| 108 | //
|
|---|
| 109 | void MHexagon::Copy(TObject &obj)
|
|---|
| 110 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,04,01)
|
|---|
| 111 | const
|
|---|
| 112 | #endif
|
|---|
| 113 | {
|
|---|
| 114 | MHexagon &hex = (MHexagon&) obj;
|
|---|
| 115 |
|
|---|
| 116 | TObject::Copy(obj);
|
|---|
| 117 | TAttLine::Copy(hex);
|
|---|
| 118 | TAttFill::Copy(hex);
|
|---|
| 119 |
|
|---|
| 120 | hex.fX = fX;
|
|---|
| 121 | hex.fY = fY;
|
|---|
| 122 | hex.fD = fD;
|
|---|
| 123 | hex.fPhi = fPhi;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | // ------------------------------------------------------------------------
|
|---|
| 127 | //
|
|---|
| 128 | // compute the distance of a point (px,py) to the Hexagon
|
|---|
| 129 | // this functions needed for graphical primitives, that
|
|---|
| 130 | // means without this function you are not able to interact
|
|---|
| 131 | // with the graphical primitive with the mouse!!!
|
|---|
| 132 | //
|
|---|
| 133 | // All calcutations are running in pixel coordinates
|
|---|
| 134 | //
|
|---|
| 135 | Int_t MHexagon::DistancetoPrimitive(Int_t px, Int_t py, Float_t conv)
|
|---|
| 136 | {
|
|---|
| 137 | //FIXME: Rotation phi missing!
|
|---|
| 138 |
|
|---|
| 139 | //
|
|---|
| 140 | // compute the distance of the Point to the center of the Hexagon
|
|---|
| 141 | //
|
|---|
| 142 | const Int_t pxhex = gPad->XtoAbsPixel(fX*conv);
|
|---|
| 143 | const Int_t pyhex = gPad->YtoAbsPixel(fY*conv);
|
|---|
| 144 |
|
|---|
| 145 | //const Double_t x = TMath::Abs(px-pxhex);
|
|---|
| 146 | //const Double_t y = TMath::Abs(py-pyhex);
|
|---|
| 147 |
|
|---|
| 148 | TVector2 v(TMath::Abs(px-pxhex), TMath::Abs(py-pyhex));
|
|---|
| 149 | // FIXME: fPhi or -fPhi?
|
|---|
| 150 | v = v.Rotate(-fPhi); // FIXME: Replace with a precalculates sin/cos vector
|
|---|
| 151 |
|
|---|
| 152 | const Double_t x = TMath::Abs(v.X());
|
|---|
| 153 | const Double_t y = TMath::Abs(v.Y());
|
|---|
| 154 |
|
|---|
| 155 | const Double_t disthex = TMath::Sqrt(x*x + y*y);
|
|---|
| 156 |
|
|---|
| 157 | if (disthex==0)
|
|---|
| 158 | return 0;
|
|---|
| 159 |
|
|---|
| 160 | const Double_t cosa = x / disthex;
|
|---|
| 161 | const Double_t sina = y / disthex;
|
|---|
| 162 |
|
|---|
| 163 | //
|
|---|
| 164 | // comput the distance of hexagon center to pixel border
|
|---|
| 165 | //
|
|---|
| 166 | const Double_t dx = fD/2 * cosa;
|
|---|
| 167 | const Double_t dy = fD/2 * sina;
|
|---|
| 168 |
|
|---|
| 169 | const Int_t pxborder = gPad->XtoAbsPixel((fX + dx)*conv);
|
|---|
| 170 | const Int_t pyborder = gPad->YtoAbsPixel((fY + dy)*conv);
|
|---|
| 171 |
|
|---|
| 172 | const Double_t bx = pxhex-pxborder;
|
|---|
| 173 | const Double_t by = pyhex-pyborder;
|
|---|
| 174 |
|
|---|
| 175 | const Double_t distborder = TMath::Sqrt(bx*bx + by*by);
|
|---|
| 176 |
|
|---|
| 177 | //
|
|---|
| 178 | // compute the distance from the border of Pixel
|
|---|
| 179 | // here in the first implementation is just circle inside
|
|---|
| 180 | //
|
|---|
| 181 | return distborder < disthex ? (int)((disthex-distborder)/conv+1) : 0;
|
|---|
| 182 | }
|
|---|
| 183 | /*
|
|---|
| 184 | // ------------------------------------------------------------------------
|
|---|
| 185 | //
|
|---|
| 186 | // compute the distance of a point (px,py) to the Hexagon center in world
|
|---|
| 187 | // coordinates. Return -1 if inside.
|
|---|
| 188 | //
|
|---|
| 189 | Float_t MHexagon::DistanceToPrimitive(Float_t px, Float_t py) const
|
|---|
| 190 | {
|
|---|
| 191 | //FIXME: Rotation phi missing!
|
|---|
| 192 |
|
|---|
| 193 | //
|
|---|
| 194 | // compute the distance of the Point to the center of the Hexagon
|
|---|
| 195 | //
|
|---|
| 196 | //const Double_t dx = px-fX;
|
|---|
| 197 | //const Double_t dy = py-fY;
|
|---|
| 198 |
|
|---|
| 199 | TVector2 v(px-fX, py-fY);
|
|---|
| 200 | // FIXME: fPhi or -fPhi?
|
|---|
| 201 | v = v.Rotate(-fPhi); // FIXME: Replace with a precalculates sin/cos vector
|
|---|
| 202 |
|
|---|
| 203 | const Double_t dx = v.X();
|
|---|
| 204 | const Double_t dy = v.Y();
|
|---|
| 205 |
|
|---|
| 206 | const Double_t disthex = TMath::Sqrt(dx*dx + dy*dy);
|
|---|
| 207 |
|
|---|
| 208 | //
|
|---|
| 209 | // Now check if point is outside of hexagon; just check x coordinate
|
|---|
| 210 | // in three coordinate systems: the default one, in which two sides of
|
|---|
| 211 | // the hexagon are paralel to the y axis (see camera displays) and two
|
|---|
| 212 | // more, rotated with respect to that one by +- 60 degrees.
|
|---|
| 213 | //
|
|---|
| 214 |
|
|---|
| 215 | if (TMath::Abs(dx) > fD/2.)
|
|---|
| 216 | return disthex;
|
|---|
| 217 |
|
|---|
| 218 | const Double_t dx2 = dx*fgCos60 + dy*fgSin60;
|
|---|
| 219 |
|
|---|
| 220 | if (TMath::Abs(dx2) > fD/2.)
|
|---|
| 221 | return disthex;
|
|---|
| 222 |
|
|---|
| 223 | const Double_t dx3 = dx*fgCos60 - dy*fgSin60;
|
|---|
| 224 |
|
|---|
| 225 | if (TMath::Abs(dx3) > fD/2.)
|
|---|
| 226 | return disthex;
|
|---|
| 227 |
|
|---|
| 228 | return -1;
|
|---|
| 229 | }
|
|---|
| 230 | */
|
|---|
| 231 | /*
|
|---|
| 232 | Float_t MHexagon::DistanceToPrimitive(Float_t px, Float_t py)
|
|---|
| 233 | {
|
|---|
| 234 | //
|
|---|
| 235 | // compute the distance of the Point to the center of the Hexagon
|
|---|
| 236 | //
|
|---|
| 237 | const Double_t dx = px-fX;
|
|---|
| 238 | const Double_t dy = py-fY;
|
|---|
| 239 |
|
|---|
| 240 | const Double_t disthex = TMath::Sqrt(dx*dx + dy*dy);
|
|---|
| 241 |
|
|---|
| 242 | //
|
|---|
| 243 | // compute the distance from the border of Pixel
|
|---|
| 244 | // here in the first implementation is just circle outside
|
|---|
| 245 | //
|
|---|
| 246 | return fD*0.5772 < disthex ? disthex-fD*0.5772 : -1;
|
|---|
| 247 | //
|
|---|
| 248 | // FIXME: this approximate method results in some photons being
|
|---|
| 249 | // assigned to two or even three different pixels.
|
|---|
| 250 | //
|
|---|
| 251 | }
|
|---|
| 252 | */
|
|---|
| 253 |
|
|---|
| 254 | // ------------------------------------------------------------------------
|
|---|
| 255 | //
|
|---|
| 256 | // Draw this ellipse with new coordinate
|
|---|
| 257 | //
|
|---|
| 258 | void MHexagon::DrawHexagon(Float_t x, Float_t y, Float_t d, Float_t phi)
|
|---|
| 259 | {
|
|---|
| 260 | MHexagon *newhexagon = new MHexagon(x, y, d, phi);
|
|---|
| 261 |
|
|---|
| 262 | TAttLine::Copy(*newhexagon);
|
|---|
| 263 | TAttFill::Copy(*newhexagon);
|
|---|
| 264 |
|
|---|
| 265 | newhexagon->SetBit(kCanDelete);
|
|---|
| 266 | newhexagon->AppendPad();
|
|---|
| 267 | }
|
|---|
| 268 |
|
|---|
| 269 | /*
|
|---|
| 270 | // ------------------------------------------------------------------------
|
|---|
| 271 | //
|
|---|
| 272 | // This is the first test of implementing a clickable interface
|
|---|
| 273 | // for one pixel
|
|---|
| 274 | //
|
|---|
| 275 | void MHexagon::ExecuteEvent(Int_t event, Int_t px, Int_t py)
|
|---|
| 276 | {
|
|---|
| 277 | switch (event)
|
|---|
| 278 | {
|
|---|
| 279 | case kButton1Down:
|
|---|
| 280 | cout << endl << "kButton1Down" << endl;
|
|---|
| 281 | SetFillColor(2);
|
|---|
| 282 | gPad->Modified();
|
|---|
| 283 | break;
|
|---|
| 284 |
|
|---|
| 285 | case kButton1Double:
|
|---|
| 286 | SetFillColor(0);
|
|---|
| 287 | gPad->Modified();
|
|---|
| 288 | break;
|
|---|
| 289 | // case kMouseEnter:
|
|---|
| 290 | // printf ("\n Mouse inside object \n" ) ;
|
|---|
| 291 | // break;
|
|---|
| 292 | }
|
|---|
| 293 | }
|
|---|
| 294 | */
|
|---|
| 295 |
|
|---|
| 296 | // ------------------------------------------------------------------------
|
|---|
| 297 | //
|
|---|
| 298 | // list this hexagon with its attributes
|
|---|
| 299 | //
|
|---|
| 300 | void MHexagon::ls(const Option_t *) const
|
|---|
| 301 | {
|
|---|
| 302 | TROOT::IndentLevel();
|
|---|
| 303 | Print();
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 306 | // ------------------------------------------------------------------------
|
|---|
| 307 | //
|
|---|
| 308 | // paint this hexagon with its attribute
|
|---|
| 309 | //
|
|---|
| 310 | void MHexagon::Paint(Option_t *)
|
|---|
| 311 | {
|
|---|
| 312 | PaintHexagon(fX, fY, fD, fPhi);
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| 315 | // ------------------------------------------------------------------------
|
|---|
| 316 | //
|
|---|
| 317 | // draw this hexagon with the coordinates
|
|---|
| 318 | //
|
|---|
| 319 | void MHexagon::PaintHexagon(Float_t inX, Float_t inY, Float_t inD, Float_t phi)
|
|---|
| 320 | {
|
|---|
| 321 | //
|
|---|
| 322 | // calculate the positions of the pixel corners
|
|---|
| 323 | //
|
|---|
| 324 | Double_t x[7], y[7];
|
|---|
| 325 | for (Int_t i=0; i<7; i++)
|
|---|
| 326 | {
|
|---|
| 327 | TVector2 v(fgDx[i%6], fgDy[i%6]);
|
|---|
| 328 |
|
|---|
| 329 | v = v.Rotate(phi); // FIXME: Replace with a precalculates sin/cos vector
|
|---|
| 330 |
|
|---|
| 331 | x[i] = inX + v.X()*inD;
|
|---|
| 332 | y[i] = inY + v.Y()*inD;
|
|---|
| 333 | }
|
|---|
| 334 |
|
|---|
| 335 | TAttLine::Modify(); // Change line attributes only if neccessary
|
|---|
| 336 | TAttFill::Modify(); // Change fill attributes only if neccessary
|
|---|
| 337 |
|
|---|
| 338 | //
|
|---|
| 339 | // paint the pixel
|
|---|
| 340 | //
|
|---|
| 341 | if (GetFillColor())
|
|---|
| 342 | gPad->PaintFillArea(6, x, y);
|
|---|
| 343 |
|
|---|
| 344 | if (GetLineStyle())
|
|---|
| 345 | gPad->PaintPolyLine(7, x, y);
|
|---|
| 346 | }
|
|---|
| 347 |
|
|---|
| 348 | // ------------------------------------------------------------------------
|
|---|
| 349 | //
|
|---|
| 350 | // print/dump this hexagon with its attributes
|
|---|
| 351 | //
|
|---|
| 352 | void MHexagon::Print(Option_t *) const
|
|---|
| 353 | {
|
|---|
| 354 | cout << "MHexagon: ";
|
|---|
| 355 | cout << "x=" << fX << "mm y=" << fY << "mm r=" << fD << "mm phi=" << TMath::RadToDeg() << "deg" << endl;
|
|---|
| 356 |
|
|---|
| 357 | cout << " Line:";
|
|---|
| 358 | cout << " Color=" << GetLineColor() << ",";
|
|---|
| 359 | cout << " Style=" << GetLineStyle() << ",";
|
|---|
| 360 | cout << " Width=" << GetLineWidth() << endl;
|
|---|
| 361 | cout << " Fill:";
|
|---|
| 362 | cout << " Color=" << GetFillColor() << ",";
|
|---|
| 363 | cout << " Style=" << GetFillStyle() << endl;
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | // ------------------------------------------------------------------------
|
|---|
| 367 | //
|
|---|
| 368 | // Save primitive as a C++ statement(s) on output stream out
|
|---|
| 369 | //
|
|---|
| 370 | void MHexagon::SavePrimitive(ostream &out, Option_t *)
|
|---|
| 371 | {
|
|---|
| 372 | #if ROOT_VERSION_CODE >= ROOT_VERSION(5,12,00)
|
|---|
| 373 | if (gROOT->ClassSaved(Class()))
|
|---|
| 374 | out << " ";
|
|---|
| 375 | else
|
|---|
| 376 | out << " MHexagon *";
|
|---|
| 377 |
|
|---|
| 378 | out << "hexagon = new MHexagon(" << fX << "," << fY << "," << fD << "," << fPhi << ");" << endl;
|
|---|
| 379 |
|
|---|
| 380 | SaveFillAttributes(out, "hexagon");
|
|---|
| 381 | SaveLineAttributes(out, "hexagon");
|
|---|
| 382 |
|
|---|
| 383 | out << " hexagon->Draw();" << endl;
|
|---|
| 384 | #endif
|
|---|
| 385 | }
|
|---|
| 386 |
|
|---|
| 387 | void MHexagon::SavePrimitive(ofstream &out, Option_t *)
|
|---|
| 388 | {
|
|---|
| 389 | #if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
|
|---|
| 390 | if (gROOT->ClassSaved(Class()))
|
|---|
| 391 | out << " ";
|
|---|
| 392 | else
|
|---|
| 393 | out << " MHexagon *";
|
|---|
| 394 |
|
|---|
| 395 | out << "hexagon = new MHexagon(" << fX << "," << fY << "," << fD << "," << fPhi << ");" << endl;
|
|---|
| 396 |
|
|---|
| 397 | SaveFillAttributes(out, "hexagon");
|
|---|
| 398 | SaveLineAttributes(out, "hexagon");
|
|---|
| 399 |
|
|---|
| 400 | out << " hexagon->Draw();" << endl;
|
|---|
| 401 | #else
|
|---|
| 402 | MHexagon::SavePrimitive(static_cast<ostream&>(out), "");
|
|---|
| 403 | #endif
|
|---|
| 404 | }
|
|---|