| 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/2002 <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 | // MCamDisplay
|
|---|
| 29 | //
|
|---|
| 30 | // Camera Display. The Pixels are displayed in
|
|---|
| 31 | // contents/area [somthing/mm^2]
|
|---|
| 32 | //
|
|---|
| 33 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 34 | #include "MCamDisplay.h"
|
|---|
| 35 |
|
|---|
| 36 | #include <fstream.h>
|
|---|
| 37 | #include <iostream.h>
|
|---|
| 38 |
|
|---|
| 39 | #include <TBox.h>
|
|---|
| 40 | #include <TArrow.h>
|
|---|
| 41 | #include <TLatex.h>
|
|---|
| 42 | #include <TStyle.h>
|
|---|
| 43 | #include <TMarker.h>
|
|---|
| 44 | #include <TCanvas.h>
|
|---|
| 45 | #include <TArrayF.h>
|
|---|
| 46 | #include <TClonesArray.h>
|
|---|
| 47 |
|
|---|
| 48 | #include "MH.h"
|
|---|
| 49 | #include "MHexagon.h"
|
|---|
| 50 |
|
|---|
| 51 | #include "MGeomCam.h"
|
|---|
| 52 |
|
|---|
| 53 | #include "MRflEvtData.h"
|
|---|
| 54 |
|
|---|
| 55 | #include "MCerPhotPix.h"
|
|---|
| 56 | #include "MCerPhotEvt.h"
|
|---|
| 57 |
|
|---|
| 58 | #include "MPedestalPix.h"
|
|---|
| 59 | #include "MPedestalCam.h"
|
|---|
| 60 |
|
|---|
| 61 | #include "MImgCleanStd.h"
|
|---|
| 62 |
|
|---|
| 63 | #define kItemsLegend 50 // see SetPalette(1,0)
|
|---|
| 64 |
|
|---|
| 65 | ClassImp(MCamDisplay);
|
|---|
| 66 |
|
|---|
| 67 | // ------------------------------------------------------------------------
|
|---|
| 68 | //
|
|---|
| 69 | // Default Constructor. To be used by the root system ONLY.
|
|---|
| 70 | //
|
|---|
| 71 | MCamDisplay::MCamDisplay()
|
|---|
| 72 | : fGeomCam(NULL), fAutoScale(kTRUE), fW(0), fH(0)
|
|---|
| 73 | {
|
|---|
| 74 | fNumPixels = 0;
|
|---|
| 75 | fRange = 0;
|
|---|
| 76 |
|
|---|
| 77 | fPixels = NULL;
|
|---|
| 78 | fLegend = NULL;
|
|---|
| 79 | fLegText = NULL;
|
|---|
| 80 | fArrowX = NULL;
|
|---|
| 81 | fArrowY = NULL;
|
|---|
| 82 | fLegRadius = NULL;
|
|---|
| 83 | fLegDegree = NULL;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | // ------------------------------------------------------------------------
|
|---|
| 87 | //
|
|---|
| 88 | // Constructor. Makes a clone of MGeomCam.
|
|---|
| 89 | //
|
|---|
| 90 | MCamDisplay::MCamDisplay(MGeomCam *geom)
|
|---|
| 91 | : fGeomCam(NULL), fAutoScale(kTRUE), fW(0), fH(0)
|
|---|
| 92 | {
|
|---|
| 93 | fGeomCam = (MGeomCam*)geom->Clone();
|
|---|
| 94 |
|
|---|
| 95 | //
|
|---|
| 96 | // create the hexagons of the display
|
|---|
| 97 | //
|
|---|
| 98 | fNumPixels = fGeomCam->GetNumPixels();
|
|---|
| 99 | fRange = fGeomCam->GetMaxRadius();
|
|---|
| 100 |
|
|---|
| 101 | // root 3.02
|
|---|
| 102 | // * base/inc/TObject.h:
|
|---|
| 103 | // register BIT(8) as kNoContextMenu. If an object has this bit set it will
|
|---|
| 104 | // not get an automatic context menu when clicked with the right mouse button.
|
|---|
| 105 |
|
|---|
| 106 | fPhotons = new TClonesArray("TMarker", 0);
|
|---|
| 107 |
|
|---|
| 108 | //
|
|---|
| 109 | // Construct all hexagons. Use new-operator with placement
|
|---|
| 110 | //
|
|---|
| 111 | fPixels = new TClonesArray("MHexagon", fNumPixels);
|
|---|
| 112 | for (UInt_t i=0; i<fNumPixels; i++)
|
|---|
| 113 | {
|
|---|
| 114 | MHexagon &pix = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
|
|---|
| 115 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
|
|---|
| 116 | pix.SetBit(/*kNoContextMenu|*/kCannotPick);
|
|---|
| 117 | #endif
|
|---|
| 118 | pix.SetFillColor(16);
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | //
|
|---|
| 122 | // set up the Legend
|
|---|
| 123 | //
|
|---|
| 124 | const Float_t H = 0.9*fRange;
|
|---|
| 125 | const Float_t h = 2./kItemsLegend;
|
|---|
| 126 |
|
|---|
| 127 | const Float_t w = fRange/sqrt(fNumPixels);
|
|---|
| 128 |
|
|---|
| 129 | fLegend = new TClonesArray("TBox", kItemsLegend);
|
|---|
| 130 | fLegText = new TClonesArray("TText", kItemsLegend);
|
|---|
| 131 |
|
|---|
| 132 | for (Int_t i = 0; i<kItemsLegend; i++)
|
|---|
| 133 | {
|
|---|
| 134 | TBox &newbox = *new ((*fLegend)[i]) TBox;
|
|---|
| 135 | TText &newtxt = *new ((*fLegText)[i]) TText;
|
|---|
| 136 |
|
|---|
| 137 | newbox.SetX1(fRange);
|
|---|
| 138 | newbox.SetX2(fRange+w);
|
|---|
| 139 | newbox.SetY1(H*( i *h - 1.));
|
|---|
| 140 | newbox.SetY2(H*((i+1)*h - 1.));
|
|---|
| 141 | newbox.SetFillColor(16);
|
|---|
| 142 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
|
|---|
| 143 | newbox.SetBit(/*kNoContextMenu|*/kCannotPick);
|
|---|
| 144 | #endif
|
|---|
| 145 |
|
|---|
| 146 | newtxt.SetTextSize(0.025);
|
|---|
| 147 | newtxt.SetTextAlign(12);
|
|---|
| 148 | newtxt.SetX(fRange+1.5*w);
|
|---|
| 149 | newtxt.SetY(H*((i+0.5)*h - 1.));
|
|---|
| 150 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
|
|---|
| 151 | newtxt.SetBit(/*kNoContextMenu|*/kCannotPick);
|
|---|
| 152 | #endif
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | fArrowX = new TArrow(-fRange*.9, -fRange*.9, -fRange*.6, -fRange*.9, 0.025);
|
|---|
| 156 | fArrowY = new TArrow(-fRange*.9, -fRange*.9, -fRange*.9, -fRange*.6, 0.025);
|
|---|
| 157 |
|
|---|
| 158 | TString text;
|
|---|
| 159 | text += (int)(fRange*.3);
|
|---|
| 160 | text += "mm";
|
|---|
| 161 |
|
|---|
| 162 | fLegRadius = new TText(-fRange*.85, -fRange*.85, text);
|
|---|
| 163 | text = "";
|
|---|
| 164 | text += (float)((int)(fRange*.3*fGeomCam->GetConvMm2Deg()*10))/10;
|
|---|
| 165 | text += "\\circ";
|
|---|
| 166 | text = text.Strip(TString::kLeading);
|
|---|
| 167 | fLegDegree = new TLatex(-fRange*.85, -fRange*.75, text);
|
|---|
| 168 | fLegRadius->SetTextSize(0.04);
|
|---|
| 169 | fLegDegree->SetTextSize(0.04);
|
|---|
| 170 |
|
|---|
| 171 | #if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
|
|---|
| 172 | SetPalette(1, 0);
|
|---|
| 173 | #else
|
|---|
| 174 | SetPalette(51, 0);
|
|---|
| 175 | #endif
|
|---|
| 176 |
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | // ------------------------------------------------------------------------
|
|---|
| 180 | //
|
|---|
| 181 | // Destructor. Deletes TClonesArrays for hexagons and legend elements.
|
|---|
| 182 | //
|
|---|
| 183 | MCamDisplay::~MCamDisplay()
|
|---|
| 184 | {
|
|---|
| 185 | fPixels->Delete();
|
|---|
| 186 | fLegend->Delete();
|
|---|
| 187 | fLegText->Delete();
|
|---|
| 188 | fPhotons->Delete();
|
|---|
| 189 |
|
|---|
| 190 | delete fPixels;
|
|---|
| 191 | delete fLegend;
|
|---|
| 192 | delete fLegText;
|
|---|
| 193 | delete fPhotons;
|
|---|
| 194 |
|
|---|
| 195 | delete fArrowX;
|
|---|
| 196 | delete fArrowY;
|
|---|
| 197 |
|
|---|
| 198 | delete fLegRadius;
|
|---|
| 199 | delete fLegDegree;
|
|---|
| 200 |
|
|---|
| 201 | delete fGeomCam;
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | inline void MCamDisplay::SetPixColor(const MCerPhotPix &pix, const UInt_t i, Float_t min, Float_t max)
|
|---|
| 205 | {
|
|---|
| 206 | if (i>=fNumPixels)
|
|---|
| 207 | return;
|
|---|
| 208 |
|
|---|
| 209 | //
|
|---|
| 210 | // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
|
|---|
| 211 | //
|
|---|
| 212 | const Float_t ratio = fGeomCam->GetPixRatio(i);
|
|---|
| 213 | const Float_t pnum = ratio*pix.GetNumPhotons();
|
|---|
| 214 |
|
|---|
| 215 | (*this)[pix.GetPixId()].SetFillColor(GetColor(pnum, min, max));
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | inline void MCamDisplay::SetPixColorPedestal(const MPedestalPix &pix, const UInt_t i, Float_t min, Float_t max)
|
|---|
| 219 | {
|
|---|
| 220 | if (i>=fNumPixels)
|
|---|
| 221 | return;
|
|---|
| 222 |
|
|---|
| 223 | //
|
|---|
| 224 | // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
|
|---|
| 225 | //
|
|---|
| 226 | const Float_t ratio = fGeomCam->GetPixRatio(i);
|
|---|
| 227 | const Float_t pnum = ratio*pix.GetMean();
|
|---|
| 228 |
|
|---|
| 229 | (*this)[i].SetFillColor(GetColor(pnum, min, max));
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | inline void MCamDisplay::SetPixColorError(const MCerPhotPix &pix, const UInt_t i, Float_t min, Float_t max)
|
|---|
| 233 | {
|
|---|
| 234 | if (i>=fNumPixels)
|
|---|
| 235 | return;
|
|---|
| 236 |
|
|---|
| 237 | //
|
|---|
| 238 | // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
|
|---|
| 239 | //
|
|---|
| 240 | const Float_t ratio = fGeomCam->GetPixRatio(i);
|
|---|
| 241 | const Float_t pnum = sqrt(ratio)*pix.GetErrorPhot();
|
|---|
| 242 |
|
|---|
| 243 | (*this)[pix.GetPixId()].SetFillColor(GetColor(pnum, min, max));
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | inline void MCamDisplay::SetPixColorRatio(const MCerPhotPix &pix, Float_t min, Float_t max)
|
|---|
| 247 | {
|
|---|
| 248 | //
|
|---|
| 249 | // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
|
|---|
| 250 | //
|
|---|
| 251 | const Float_t pnum = pix.GetNumPhotons()/pix.GetErrorPhot();
|
|---|
| 252 | (*this)[pix.GetPixId()].SetFillColor(GetColor(pnum, min, max));
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | inline void MCamDisplay::SetPixColorLevel(const MCerPhotPix &pix, Float_t lvl1, Float_t lvl2)
|
|---|
| 256 | {
|
|---|
| 257 | const Int_t maxcolidx = kItemsLegend-1;
|
|---|
| 258 |
|
|---|
| 259 | MHexagon &hex = (*this)[pix.GetPixId()];
|
|---|
| 260 |
|
|---|
| 261 | const Float_t r = pix.GetNumPhotons()/pix.GetErrorPhot();
|
|---|
| 262 |
|
|---|
| 263 | if (r>lvl1)
|
|---|
| 264 | hex.SetFillColor(fColors[4*maxcolidx/5]);
|
|---|
| 265 | else
|
|---|
| 266 | if (r>lvl2)
|
|---|
| 267 | hex.SetFillColor(fColors[maxcolidx/2]);
|
|---|
| 268 | else
|
|---|
| 269 | hex.SetFillColor(fColors[maxcolidx/5]);
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | // ------------------------------------------------------------------------
|
|---|
| 273 | //
|
|---|
| 274 | // Call this function to draw the camera layout into your canvas.
|
|---|
| 275 | // Setup a drawing canvas. Add this object and all child objects
|
|---|
| 276 | // (hexagons, etc) to the current pad. If no pad exists a new one is
|
|---|
| 277 | // created.
|
|---|
| 278 | //
|
|---|
| 279 | void MCamDisplay::Draw(Option_t *option)
|
|---|
| 280 | {
|
|---|
| 281 | // root 3.02:
|
|---|
| 282 | // gPad->SetFixedAspectRatio()
|
|---|
| 283 |
|
|---|
| 284 | TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas("CamDisplay", "Mars Camera Display", 750, 600);
|
|---|
| 285 | pad->SetBorderMode(0);
|
|---|
| 286 | pad->SetFillColor(16);
|
|---|
| 287 |
|
|---|
| 288 | AppendPad("");
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 | void MCamDisplay::SetRange()
|
|---|
| 293 | {
|
|---|
| 294 | //
|
|---|
| 295 | // Maintain aspect ratio
|
|---|
| 296 | //
|
|---|
| 297 | const float ratio = 1.15;
|
|---|
| 298 |
|
|---|
| 299 | const float w = gPad->GetWw();
|
|---|
| 300 | const float h = gPad->GetWh()*ratio;
|
|---|
| 301 |
|
|---|
| 302 | gPad->Range(-fRange, -fRange, (2*ratio-1)*fRange, fRange);
|
|---|
| 303 |
|
|---|
| 304 | if (h<w)
|
|---|
| 305 | gPad->SetPad((1.-h/w)/2, 0, (h/w+1)/2, 0.9999999);
|
|---|
| 306 | else
|
|---|
| 307 | gPad->SetPad(0, (1.-w/h)/2, 1, (w/h+1)/2);
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | // ------------------------------------------------------------------------
|
|---|
| 311 | //
|
|---|
| 312 | // This is called at any time the canvas should get repainted.
|
|---|
| 313 | // Here we maintain an aspect ratio of 1.15. This makes sure,
|
|---|
| 314 | // that the camera image doesn't get distorted by resizing the canvas.
|
|---|
| 315 | //
|
|---|
| 316 | void MCamDisplay::Paint(Option_t *opt)
|
|---|
| 317 | {
|
|---|
| 318 | if (!fPixels)
|
|---|
| 319 | return;
|
|---|
| 320 |
|
|---|
| 321 | //
|
|---|
| 322 | // Maintain aspect ratio
|
|---|
| 323 | //
|
|---|
| 324 | SetRange();
|
|---|
| 325 |
|
|---|
| 326 | //
|
|---|
| 327 | // Maintain colors
|
|---|
| 328 | //
|
|---|
| 329 | SetPalette();
|
|---|
| 330 |
|
|---|
| 331 | //
|
|---|
| 332 | // Paint Legend
|
|---|
| 333 | //
|
|---|
| 334 | fArrowX->Paint(">");
|
|---|
| 335 | fArrowY->Paint(">");
|
|---|
| 336 |
|
|---|
| 337 | fLegRadius->Paint();
|
|---|
| 338 | fLegDegree->Paint();
|
|---|
| 339 |
|
|---|
| 340 | //
|
|---|
| 341 | // Paint primitives (pixels, color legend, photons, ...)
|
|---|
| 342 | //
|
|---|
| 343 | { fPixels->ForEach(TObject, Paint)(); }
|
|---|
| 344 | { fLegend->ForEach(TObject, Paint)(); }
|
|---|
| 345 | { fLegText->ForEach(TObject, Paint)(); }
|
|---|
| 346 | { fPhotons->ForEach(TObject, Paint)(); }
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|
| 349 | // ------------------------------------------------------------------------
|
|---|
| 350 | //
|
|---|
| 351 | // With this function you can change the color palette. For more
|
|---|
| 352 | // information see TStyle::SetPalette. Only palettes with 50 colors
|
|---|
| 353 | // are allowed.
|
|---|
| 354 | // In addition you can use SetPalette(52, 0) to create an inverse
|
|---|
| 355 | // deep blue sea palette
|
|---|
| 356 | //
|
|---|
| 357 | void MCamDisplay::SetPalette(Int_t ncolors, Int_t *colors)
|
|---|
| 358 | {
|
|---|
| 359 | //
|
|---|
| 360 | // If not enough colors are specified skip this.
|
|---|
| 361 | //
|
|---|
| 362 | if (ncolors>1 && ncolors<50)
|
|---|
| 363 | {
|
|---|
| 364 | cout << "MCamDisplay::SetPalette: Only default palettes with 50 colors are allowed... ignored." << endl;
|
|---|
| 365 | return;
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | //
|
|---|
| 369 | // If ncolors==52 create a reversed deep blue sea palette
|
|---|
| 370 | //
|
|---|
| 371 | if (ncolors==52)
|
|---|
| 372 | {
|
|---|
| 373 | gStyle->SetPalette(51, NULL);
|
|---|
| 374 | Int_t c[50];
|
|---|
| 375 | for (int i=0; i<50; i++)
|
|---|
| 376 | c[49-i] = gStyle->GetColorPalette(i);
|
|---|
| 377 | gStyle->SetPalette(50, c);
|
|---|
| 378 | }
|
|---|
| 379 | else
|
|---|
| 380 | gStyle->SetPalette(ncolors, colors);
|
|---|
| 381 |
|
|---|
| 382 | //
|
|---|
| 383 | // Change the colors of the pixels
|
|---|
| 384 | //
|
|---|
| 385 | for (unsigned int i=0; i<fNumPixels; i++)
|
|---|
| 386 | {
|
|---|
| 387 | //
|
|---|
| 388 | // Get the old color index and check whether it is
|
|---|
| 389 | // background or transparent
|
|---|
| 390 | //
|
|---|
| 391 | Int_t col = (*this)[i].GetFillColor();
|
|---|
| 392 | if (col==10 || col==16)
|
|---|
| 393 | continue;
|
|---|
| 394 |
|
|---|
| 395 | //
|
|---|
| 396 | // Search for the color index (level) in the color table
|
|---|
| 397 | //
|
|---|
| 398 | int idx;
|
|---|
| 399 | for (idx=0; idx<kItemsLegend; idx++)
|
|---|
| 400 | if (col==fColors[idx])
|
|---|
| 401 | break;
|
|---|
| 402 |
|
|---|
| 403 | //
|
|---|
| 404 | // Should not happen
|
|---|
| 405 | //
|
|---|
| 406 | if (idx==kItemsLegend)
|
|---|
| 407 | {
|
|---|
| 408 | cout << "MCamDisplay::SetPalette: Strange... FIXME!" << endl;
|
|---|
| 409 | continue;
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | //
|
|---|
| 413 | // Convert the old color index (level) into the new one
|
|---|
| 414 | //
|
|---|
| 415 | (*this)[i].SetFillColor(gStyle->GetColorPalette(idx));
|
|---|
| 416 | }
|
|---|
| 417 |
|
|---|
| 418 | //
|
|---|
| 419 | // Store the color palette used for a leter reverse lookup
|
|---|
| 420 | //
|
|---|
| 421 | for (int i=0; i<kItemsLegend; i++)
|
|---|
| 422 | {
|
|---|
| 423 | fColors[i] = gStyle->GetColorPalette(i);
|
|---|
| 424 | GetBox(i)->SetFillColor(fColors[i]);
|
|---|
| 425 | }
|
|---|
| 426 | }
|
|---|
| 427 |
|
|---|
| 428 | void MCamDisplay::SetPrettyPalette()
|
|---|
| 429 | {
|
|---|
| 430 | SetPalette(1, 0);
|
|---|
| 431 | }
|
|---|
| 432 |
|
|---|
| 433 | void MCamDisplay::SetDeepBlueSeaPalette()
|
|---|
| 434 | {
|
|---|
| 435 | SetPalette(51, 0);
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | void MCamDisplay::SetInvDeepBlueSeaPalette()
|
|---|
| 439 | {
|
|---|
| 440 | SetPalette(52, 0);
|
|---|
| 441 | }
|
|---|
| 442 |
|
|---|
| 443 | void MCamDisplay::SetPalette()
|
|---|
| 444 | {
|
|---|
| 445 | for (int i=0; i<kItemsLegend; i++)
|
|---|
| 446 | GetBox(i)->SetFillColor(fColors[i]);
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | void MCamDisplay::DrawPixelNumbers()
|
|---|
| 450 | {
|
|---|
| 451 | for (int i=0; i<kItemsLegend; i++)
|
|---|
| 452 | fColors[i] = 16;
|
|---|
| 453 |
|
|---|
| 454 | if (!gPad)
|
|---|
| 455 | Draw();
|
|---|
| 456 |
|
|---|
| 457 | TText txt;
|
|---|
| 458 | txt.SetTextFont(122);
|
|---|
| 459 | txt.SetTextAlign(22); // centered/centered
|
|---|
| 460 |
|
|---|
| 461 | for (UInt_t i=0; i<fNumPixels; i++)
|
|---|
| 462 | {
|
|---|
| 463 | TString num;
|
|---|
| 464 | num += i;
|
|---|
| 465 |
|
|---|
| 466 | const MHexagon &h = (*this)[i];
|
|---|
| 467 | TText *nt = txt.DrawText(h.GetX(), h.GetY(), num);
|
|---|
| 468 | nt->SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius());
|
|---|
| 469 | }
|
|---|
| 470 | }
|
|---|
| 471 |
|
|---|
| 472 | // ------------------------------------------------------------------------
|
|---|
| 473 | //
|
|---|
| 474 | // Call this function to fill the number of photo electron into the
|
|---|
| 475 | // camera.
|
|---|
| 476 | //
|
|---|
| 477 | void MCamDisplay::FillPhotNum(const MCerPhotEvt &event)
|
|---|
| 478 | {
|
|---|
| 479 | //
|
|---|
| 480 | // Reset pixel colors to default value
|
|---|
| 481 | //
|
|---|
| 482 | Reset();
|
|---|
| 483 |
|
|---|
| 484 | //
|
|---|
| 485 | // if the autoscale is true, set the values for the range for
|
|---|
| 486 | // each event
|
|---|
| 487 | //
|
|---|
| 488 | Float_t min = 0;
|
|---|
| 489 | Float_t max = 50;
|
|---|
| 490 | if (fAutoScale)
|
|---|
| 491 | {
|
|---|
| 492 | min = event.GetNumPhotonsMin(fGeomCam);
|
|---|
| 493 | max = event.GetNumPhotonsMax(fGeomCam);
|
|---|
| 494 |
|
|---|
| 495 | if (max==min)
|
|---|
| 496 | max = min +1;
|
|---|
| 497 |
|
|---|
| 498 | UpdateLegend(min, max);
|
|---|
| 499 | }
|
|---|
| 500 |
|
|---|
| 501 | //
|
|---|
| 502 | // update the colors in the picture
|
|---|
| 503 | //
|
|---|
| 504 | const Int_t entries = event.GetNumPixels();
|
|---|
| 505 |
|
|---|
| 506 | for (Int_t i=0; i<entries; i++)
|
|---|
| 507 | {
|
|---|
| 508 | const MCerPhotPix &pix = event[i];
|
|---|
| 509 |
|
|---|
| 510 | if (!pix.IsPixelUsed())
|
|---|
| 511 | continue;
|
|---|
| 512 |
|
|---|
| 513 | SetPixColor(pix, i, min, max);
|
|---|
| 514 | }
|
|---|
| 515 | }
|
|---|
| 516 |
|
|---|
| 517 | // ------------------------------------------------------------------------
|
|---|
| 518 | //
|
|---|
| 519 | // Call this function to fill the number of photo electron into the
|
|---|
| 520 | // camera.
|
|---|
| 521 | //
|
|---|
| 522 | void MCamDisplay::FillPedestals(const MPedestalCam &event)
|
|---|
| 523 | {
|
|---|
| 524 | //
|
|---|
| 525 | // Reset pixel colors to default value
|
|---|
| 526 | //
|
|---|
| 527 | Reset();
|
|---|
| 528 |
|
|---|
| 529 | //
|
|---|
| 530 | // if the autoscale is true, set the values for the range for
|
|---|
| 531 | // each event
|
|---|
| 532 | //
|
|---|
| 533 | Float_t min = 0;
|
|---|
| 534 | Float_t max = 50;
|
|---|
| 535 | if (fAutoScale)
|
|---|
| 536 | {
|
|---|
| 537 | min = event.GetMeanMin(fGeomCam);
|
|---|
| 538 | max = event.GetMeanMax(fGeomCam);
|
|---|
| 539 |
|
|---|
| 540 | if (max==min)
|
|---|
| 541 | max = min +1;
|
|---|
| 542 |
|
|---|
| 543 | UpdateLegend(min, max);
|
|---|
| 544 | }
|
|---|
| 545 |
|
|---|
| 546 | //
|
|---|
| 547 | // update the colors in the picture
|
|---|
| 548 | //
|
|---|
| 549 | const Int_t entries = event.GetSize();
|
|---|
| 550 |
|
|---|
| 551 | for (Int_t i=0; i<entries; i++)
|
|---|
| 552 | SetPixColorPedestal(event[i], i, min, max);
|
|---|
| 553 | }
|
|---|
| 554 |
|
|---|
| 555 | // ------------------------------------------------------------------------
|
|---|
| 556 | //
|
|---|
| 557 | // Call this function to fill the error of number of photo electron
|
|---|
| 558 | // into the camera.
|
|---|
| 559 | //
|
|---|
| 560 | void MCamDisplay::FillErrorPhot(const MCerPhotEvt &event)
|
|---|
| 561 | {
|
|---|
| 562 | //
|
|---|
| 563 | // Reset pixel colors to default value
|
|---|
| 564 | //
|
|---|
| 565 | Reset();
|
|---|
| 566 |
|
|---|
| 567 | //
|
|---|
| 568 | // if the autoscale is true, set the values for the range for
|
|---|
| 569 | // each event
|
|---|
| 570 | //
|
|---|
| 571 | Float_t min = 0;
|
|---|
| 572 | Float_t max = 50;
|
|---|
| 573 | if (fAutoScale)
|
|---|
| 574 | {
|
|---|
| 575 | min = event.GetErrorPhotMin(fGeomCam);
|
|---|
| 576 | max = event.GetErrorPhotMax(fGeomCam);
|
|---|
| 577 |
|
|---|
| 578 | if (max==min)
|
|---|
| 579 | max = min +1;
|
|---|
| 580 |
|
|---|
| 581 | UpdateLegend(min, max);
|
|---|
| 582 | }
|
|---|
| 583 |
|
|---|
| 584 | //
|
|---|
| 585 | // update the colors in the picture
|
|---|
| 586 | //
|
|---|
| 587 | const Int_t entries = event.GetNumPixels();
|
|---|
| 588 |
|
|---|
| 589 | for (Int_t i=0; i<entries; i++)
|
|---|
| 590 | {
|
|---|
| 591 | const MCerPhotPix &pix = event[i];
|
|---|
| 592 |
|
|---|
| 593 | if (!pix.IsPixelUsed())
|
|---|
| 594 | continue;
|
|---|
| 595 |
|
|---|
| 596 | SetPixColorError(pix, i, min, max);
|
|---|
| 597 | }
|
|---|
| 598 | }
|
|---|
| 599 |
|
|---|
| 600 | // ------------------------------------------------------------------------
|
|---|
| 601 | //
|
|---|
| 602 | // Call this function to fill the ratio of the number of photons
|
|---|
| 603 | // divided by its error
|
|---|
| 604 | //
|
|---|
| 605 | void MCamDisplay::FillRatio(const MCerPhotEvt &event)
|
|---|
| 606 | {
|
|---|
| 607 | //
|
|---|
| 608 | // Reset pixel colors to default value
|
|---|
| 609 | //
|
|---|
| 610 | Reset();
|
|---|
| 611 |
|
|---|
| 612 | //
|
|---|
| 613 | // if the autoscale is true, set the values for the range for
|
|---|
| 614 | // each event
|
|---|
| 615 | //
|
|---|
| 616 | Float_t min = 0;
|
|---|
| 617 | Float_t max = 20;
|
|---|
| 618 | if (fAutoScale)
|
|---|
| 619 | {
|
|---|
| 620 | min = event.GetRatioMin();
|
|---|
| 621 | max = event.GetRatioMax();
|
|---|
| 622 |
|
|---|
| 623 | UpdateLegend(min, max);
|
|---|
| 624 | }
|
|---|
| 625 |
|
|---|
| 626 | //
|
|---|
| 627 | // update the colors in the picture
|
|---|
| 628 | //
|
|---|
| 629 | const Int_t entries = event.GetNumPixels();
|
|---|
| 630 |
|
|---|
| 631 | for (Int_t i=0; i<entries; i++)
|
|---|
| 632 | {
|
|---|
| 633 | const MCerPhotPix &pix = event[i];
|
|---|
| 634 |
|
|---|
| 635 | if (!pix.IsPixelUsed())
|
|---|
| 636 | continue;
|
|---|
| 637 |
|
|---|
| 638 | SetPixColorRatio(pix, min, max);
|
|---|
| 639 | }
|
|---|
| 640 | }
|
|---|
| 641 |
|
|---|
| 642 | // ------------------------------------------------------------------------
|
|---|
| 643 | //
|
|---|
| 644 | // Fill the colors in respect to the cleaning levels
|
|---|
| 645 | //
|
|---|
| 646 | void MCamDisplay::FillLevels(const MCerPhotEvt &event, Float_t lvl1, Float_t lvl2)
|
|---|
| 647 | {
|
|---|
| 648 | //
|
|---|
| 649 | // Reset pixel colors to default value
|
|---|
| 650 | //
|
|---|
| 651 | Reset();
|
|---|
| 652 |
|
|---|
| 653 | //
|
|---|
| 654 | // update the colors in the picture
|
|---|
| 655 | //
|
|---|
| 656 | const Int_t entries = event.GetNumPixels();
|
|---|
| 657 |
|
|---|
| 658 | for (Int_t i=0; i<entries; i++)
|
|---|
| 659 | {
|
|---|
| 660 | const MCerPhotPix &pix = event[i];
|
|---|
| 661 |
|
|---|
| 662 | if (!pix.IsPixelUsed())
|
|---|
| 663 | continue;
|
|---|
| 664 |
|
|---|
| 665 | SetPixColorLevel(pix, lvl1, lvl2);
|
|---|
| 666 | }
|
|---|
| 667 | }
|
|---|
| 668 |
|
|---|
| 669 | // ------------------------------------------------------------------------
|
|---|
| 670 | //
|
|---|
| 671 | // Fill the colors in respect to the cleaning levels
|
|---|
| 672 | //
|
|---|
| 673 | void MCamDisplay::FillLevels(const MCerPhotEvt &event, const MImgCleanStd &clean)
|
|---|
| 674 | {
|
|---|
| 675 | FillLevels(event, clean.GetCleanLvl1(), clean.GetCleanLvl2());
|
|---|
| 676 | }
|
|---|
| 677 |
|
|---|
| 678 | // ------------------------------------------------------------------------
|
|---|
| 679 | //
|
|---|
| 680 | // Show a reflector event. EMarkerStyle is defined in root/include/Gtypes.h
|
|---|
| 681 | // To remove the photons from the display call FillRflEvent(NULL)
|
|---|
| 682 | //
|
|---|
| 683 | void MCamDisplay::ShowRflEvent(const MRflEvtData *event, EMarkerStyle ms)
|
|---|
| 684 | {
|
|---|
| 685 | const Int_t num = event ? event->GetNumPhotons() : 0;
|
|---|
| 686 |
|
|---|
| 687 | fPhotons->ExpandCreate(num);
|
|---|
| 688 | if (num < 1)
|
|---|
| 689 | return;
|
|---|
| 690 |
|
|---|
| 691 | Int_t i=num-1;
|
|---|
| 692 | do
|
|---|
| 693 | {
|
|---|
| 694 | const MRflSinglePhoton &ph = event->GetPhoton(i);
|
|---|
| 695 | TMarker &m = (TMarker&)*fPhotons->UncheckedAt(i);
|
|---|
| 696 | m.SetX(ph.GetX());
|
|---|
| 697 | m.SetY(ph.GetY());
|
|---|
| 698 | m.SetMarkerStyle(ms);
|
|---|
| 699 | } while (i--);
|
|---|
| 700 | }
|
|---|
| 701 |
|
|---|
| 702 | // ------------------------------------------------------------------------
|
|---|
| 703 | //
|
|---|
| 704 | // Fill a reflector event. Sums all pixels in each pixel as the
|
|---|
| 705 | // pixel contents.
|
|---|
| 706 | //
|
|---|
| 707 | // WARNING: Due to the estimation in DistanceToPrimitive and the
|
|---|
| 708 | // calculation in pixels instead of x, y this is only a
|
|---|
| 709 | // rough estimate.
|
|---|
| 710 | //
|
|---|
| 711 | void MCamDisplay::FillRflEvent(const MRflEvtData &event)
|
|---|
| 712 | {
|
|---|
| 713 | //
|
|---|
| 714 | // reset pixel colors to background color
|
|---|
| 715 | //
|
|---|
| 716 | Reset();
|
|---|
| 717 |
|
|---|
| 718 | //
|
|---|
| 719 | // sum the photons content in each pixel
|
|---|
| 720 | //
|
|---|
| 721 | const Int_t entries = event.GetNumPhotons();
|
|---|
| 722 |
|
|---|
| 723 | TArrayF arr(fNumPixels);
|
|---|
| 724 | for (Int_t i=0; i<entries; i++)
|
|---|
| 725 | {
|
|---|
| 726 | const MRflSinglePhoton &ph = event.GetPhoton(i);
|
|---|
| 727 |
|
|---|
| 728 | UInt_t id;
|
|---|
| 729 | for (id=0; id<fNumPixels; id++)
|
|---|
| 730 | {
|
|---|
| 731 | if ((*this)[id].DistanceToPrimitive(ph.GetX(), ph.GetY())<0)
|
|---|
| 732 | break;
|
|---|
| 733 | }
|
|---|
| 734 | if (id==fNumPixels)
|
|---|
| 735 | continue;
|
|---|
| 736 |
|
|---|
| 737 | arr[id] += 1;
|
|---|
| 738 | }
|
|---|
| 739 |
|
|---|
| 740 | //
|
|---|
| 741 | // Scale with the area and determin maximum
|
|---|
| 742 | //
|
|---|
| 743 | Float_t max = 0;
|
|---|
| 744 | for (UInt_t id=0; id<fNumPixels; id++)
|
|---|
| 745 | {
|
|---|
| 746 | arr[id] *= fGeomCam->GetPixRatio(id);
|
|---|
| 747 | if (arr[id]>max)
|
|---|
| 748 | max = arr[id];
|
|---|
| 749 | }
|
|---|
| 750 |
|
|---|
| 751 | //
|
|---|
| 752 | // Update legend
|
|---|
| 753 | //
|
|---|
| 754 | if (fAutoScale)
|
|---|
| 755 | UpdateLegend(0, max==0 ? 1 : max);
|
|---|
| 756 |
|
|---|
| 757 | //
|
|---|
| 758 | // Set color of pixels
|
|---|
| 759 | //
|
|---|
| 760 | for (UInt_t id=0; id<fNumPixels; id++)
|
|---|
| 761 | if (arr[id]>0)
|
|---|
| 762 | (*this)[id].SetFillColor(GetColor(arr[id], 0, max));
|
|---|
| 763 | }
|
|---|
| 764 |
|
|---|
| 765 | // ------------------------------------------------------------------------
|
|---|
| 766 | //
|
|---|
| 767 | // Reset the all pixel colors to a default value
|
|---|
| 768 | //
|
|---|
| 769 | void MCamDisplay::Reset()
|
|---|
| 770 | {
|
|---|
| 771 | for (UInt_t i=0; i<fNumPixels; i++)
|
|---|
| 772 | (*this)[i].SetFillColor(10);
|
|---|
| 773 | }
|
|---|
| 774 |
|
|---|
| 775 | // ------------------------------------------------------------------------
|
|---|
| 776 | //
|
|---|
| 777 | // Here we calculate the color index for the current value.
|
|---|
| 778 | // The color index is defined with the class TStyle and the
|
|---|
| 779 | // Color palette inside. We use the command gStyle->SetPalette(1,0)
|
|---|
| 780 | // for the display. So we have to convert the value "wert" into
|
|---|
| 781 | // a color index that fits the color palette.
|
|---|
| 782 | // The range of the color palette is defined by the values fMinPhe
|
|---|
| 783 | // and fMaxRange. Between this values we have 50 color index, starting
|
|---|
| 784 | // with 0 up to 49.
|
|---|
| 785 | //
|
|---|
| 786 | Int_t MCamDisplay::GetColor(Float_t val, Float_t min, Float_t max)
|
|---|
| 787 | {
|
|---|
| 788 | //
|
|---|
| 789 | // first treat the over- and under-flows
|
|---|
| 790 | //
|
|---|
| 791 | const Int_t maxcolidx = kItemsLegend-1;
|
|---|
| 792 |
|
|---|
| 793 | if (val >= max)
|
|---|
| 794 | return fColors[maxcolidx];
|
|---|
| 795 |
|
|---|
| 796 | if (val <= min)
|
|---|
| 797 | return fColors[0];
|
|---|
| 798 |
|
|---|
| 799 | //
|
|---|
| 800 | // calculate the color index
|
|---|
| 801 | //
|
|---|
| 802 | const Float_t ratio = (val-min) / (max-min);
|
|---|
| 803 | const Int_t colidx = (Int_t)(ratio*maxcolidx + .5);
|
|---|
| 804 |
|
|---|
| 805 | return fColors[colidx];
|
|---|
| 806 | }
|
|---|
| 807 |
|
|---|
| 808 | // ------------------------------------------------------------------------
|
|---|
| 809 | //
|
|---|
| 810 | // Change the text on the legend according to the range of the Display
|
|---|
| 811 | //
|
|---|
| 812 | void MCamDisplay::UpdateLegend(Float_t minphe, Float_t maxphe)
|
|---|
| 813 | {
|
|---|
| 814 | for (Int_t i=0; i<kItemsLegend; i+=3)
|
|---|
| 815 | {
|
|---|
| 816 | const Float_t val = minphe + (Float_t)i/kItemsLegend * (maxphe-minphe) ;
|
|---|
| 817 |
|
|---|
| 818 | TText &txt = *GetText(i);
|
|---|
| 819 | txt.SetText(txt.GetX(), txt.GetY(), Form(val<1e6?"%5.1f":"%5.1e", val));
|
|---|
| 820 | }
|
|---|
| 821 | }
|
|---|
| 822 |
|
|---|
| 823 | // ------------------------------------------------------------------------
|
|---|
| 824 | //
|
|---|
| 825 | // Save primitive as a C++ statement(s) on output stream out
|
|---|
| 826 | //
|
|---|
| 827 | void MCamDisplay::SavePrimitive(ofstream &out, Option_t *opt)
|
|---|
| 828 | {
|
|---|
| 829 | cout << "MCamDisplay::SavePrimitive: Must be rewritten!" << endl;
|
|---|
| 830 | /*
|
|---|
| 831 | if (!gROOT->ClassSaved(TCanvas::Class()))
|
|---|
| 832 | fDrawingPad->SavePrimitive(out, opt);
|
|---|
| 833 |
|
|---|
| 834 | out << " " << fDrawingPad->GetName() << "->SetWindowSize(";
|
|---|
| 835 | out << fDrawingPad->GetWw() << "," << fDrawingPad->GetWh() << ");" << endl;
|
|---|
| 836 | */
|
|---|
| 837 | }
|
|---|
| 838 |
|
|---|
| 839 | // ------------------------------------------------------------------------
|
|---|
| 840 | //
|
|---|
| 841 | // compute the distance of a point (px,py) to the Camera
|
|---|
| 842 | // this functions needed for graphical primitives, that
|
|---|
| 843 | // means without this function you are not able to interact
|
|---|
| 844 | // with the graphical primitive with the mouse!!!
|
|---|
| 845 | //
|
|---|
| 846 | // All calcutations are running in pixel coordinates
|
|---|
| 847 | //
|
|---|
| 848 | Int_t MCamDisplay::DistancetoPrimitive(Int_t px, Int_t py)
|
|---|
| 849 | {
|
|---|
| 850 | Int_t dist = 999999;
|
|---|
| 851 |
|
|---|
| 852 | for (UInt_t i=0; i<fNumPixels; i++)
|
|---|
| 853 | {
|
|---|
| 854 | Int_t d = (*fPixels)[i]->DistancetoPrimitive(px, py);
|
|---|
| 855 |
|
|---|
| 856 | if (d<dist)
|
|---|
| 857 | dist=d;
|
|---|
| 858 | }
|
|---|
| 859 | return dist==0?0:999999;
|
|---|
| 860 | }
|
|---|
| 861 |
|
|---|
| 862 | // ------------------------------------------------------------------------
|
|---|
| 863 | //
|
|---|
| 864 | // Execute a mouse event on the camera
|
|---|
| 865 | //
|
|---|
| 866 | /*
|
|---|
| 867 | void MCamDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
|
|---|
| 868 | {
|
|---|
| 869 | cout << "Execute Event Camera " << event << " @ " << px << " " << py << endl;
|
|---|
| 870 | }
|
|---|
| 871 | */
|
|---|
| 872 |
|
|---|
| 873 |
|
|---|
| 874 | // ------------------------------------------------------------------------
|
|---|
| 875 | //
|
|---|
| 876 | // Function introduced (31-01-03)
|
|---|
| 877 | //
|
|---|
| 878 | void MCamDisplay::SetPix(const Int_t pixnum, const Int_t color, Float_t min, Float_t max)
|
|---|
| 879 | {
|
|---|
| 880 | (*this)[pixnum].SetFillColor(GetColor(color, min, max));
|
|---|
| 881 | }
|
|---|
| 882 |
|
|---|
| 883 | // ------------------------------------------------------------------------
|
|---|
| 884 | //
|
|---|
| 885 | // Returns string containing info about the object at position (px,py).
|
|---|
| 886 | // Returned string will be re-used (lock in MT environment).
|
|---|
| 887 | //
|
|---|
| 888 | char *MCamDisplay::GetObjectInfo(Int_t px, Int_t py) const
|
|---|
| 889 | {
|
|---|
| 890 | static char info[64];
|
|---|
| 891 |
|
|---|
| 892 | UInt_t i;
|
|---|
| 893 | for (i=0; i<fNumPixels; i++)
|
|---|
| 894 | {
|
|---|
| 895 | if ((*fPixels)[i]->DistancetoPrimitive(px, py)>0)
|
|---|
| 896 | continue;
|
|---|
| 897 |
|
|---|
| 898 | sprintf(info, "Pixel Id: %d", i);
|
|---|
| 899 | return info;
|
|---|
| 900 | }
|
|---|
| 901 | return TObject::GetObjectInfo(px, py);
|
|---|
| 902 | }
|
|---|