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