| 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 | // MHCamera
|
|---|
| 29 | //
|
|---|
| 30 | // Camera Display, based on a TH1D. Pleas be carefull using the
|
|---|
| 31 | // underlaying TH1D.
|
|---|
| 32 | //
|
|---|
| 33 | // To change the scale to a logarithmic scale SetLogy() of the Pad.
|
|---|
| 34 | //
|
|---|
| 35 | // Be carefull: Entries in this context means Entries/bin or Events
|
|---|
| 36 | //
|
|---|
| 37 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 38 | #include "MHCamera.h"
|
|---|
| 39 |
|
|---|
| 40 | #include <fstream>
|
|---|
| 41 | #include <iostream>
|
|---|
| 42 |
|
|---|
| 43 | #include <TBox.h>
|
|---|
| 44 | #include <TArrow.h>
|
|---|
| 45 | #include <TLatex.h>
|
|---|
| 46 | #include <TStyle.h>
|
|---|
| 47 | #include <TCanvas.h>
|
|---|
| 48 | #include <TArrayF.h>
|
|---|
| 49 | #include <TRandom.h>
|
|---|
| 50 | #include <TPaveText.h>
|
|---|
| 51 | #include <TPaveStats.h>
|
|---|
| 52 | #include <TClonesArray.h>
|
|---|
| 53 | #include <THistPainter.h>
|
|---|
| 54 |
|
|---|
| 55 | #include "MLog.h"
|
|---|
| 56 | #include "MLogManip.h"
|
|---|
| 57 |
|
|---|
| 58 | #include "MH.h"
|
|---|
| 59 | #include "MHexagon.h"
|
|---|
| 60 |
|
|---|
| 61 | #include "MGeomPix.h"
|
|---|
| 62 | #include "MGeomCam.h"
|
|---|
| 63 |
|
|---|
| 64 | #include "MCerPhotPix.h"
|
|---|
| 65 | #include "MCerPhotEvt.h"
|
|---|
| 66 |
|
|---|
| 67 | #include "MPedestalPix.h"
|
|---|
| 68 | #include "MPedestalCam.h"
|
|---|
| 69 |
|
|---|
| 70 | #include "MCurrents.h"
|
|---|
| 71 | #include "MCamEvent.h"
|
|---|
| 72 |
|
|---|
| 73 | #include "MImgCleanStd.h"
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 | #define kItemsLegend 48 // see SetPalette(1,0)
|
|---|
| 77 |
|
|---|
| 78 | ClassImp(MHCamera);
|
|---|
| 79 |
|
|---|
| 80 | using namespace std;
|
|---|
| 81 |
|
|---|
| 82 | void MHCamera::Init()
|
|---|
| 83 | {
|
|---|
| 84 | UseCurrentStyle();
|
|---|
| 85 |
|
|---|
| 86 | SetDirectory(NULL);
|
|---|
| 87 |
|
|---|
| 88 | SetLineColor(kGreen);
|
|---|
| 89 | SetMarkerStyle(kFullDotMedium);
|
|---|
| 90 | SetXTitle("Pixel Index");
|
|---|
| 91 |
|
|---|
| 92 | fNotify = new TList;
|
|---|
| 93 |
|
|---|
| 94 | #if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
|
|---|
| 95 | SetPalette(1, 0);
|
|---|
| 96 | #else
|
|---|
| 97 | SetInvDeepBlueSeaPalette();
|
|---|
| 98 | #endif
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | // ------------------------------------------------------------------------
|
|---|
| 102 | //
|
|---|
| 103 | // Default Constructor. To be used by the root system ONLY.
|
|---|
| 104 | //
|
|---|
| 105 | MHCamera::MHCamera() : TH1D(), fGeomCam(NULL), fColors(kItemsLegend)
|
|---|
| 106 | {
|
|---|
| 107 | Init();
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | // ------------------------------------------------------------------------
|
|---|
| 111 | //
|
|---|
| 112 | // Constructor. Makes a clone of MGeomCam. Removed the TH1D from the
|
|---|
| 113 | // current directory. Calls Sumw2(). Set the histogram line color
|
|---|
| 114 | // (for error bars) to Green and the marker style to kFullDotMedium.
|
|---|
| 115 | //
|
|---|
| 116 | MHCamera::MHCamera(const MGeomCam &geom, const char *name, const char *title)
|
|---|
| 117 | : fGeomCam(NULL), /*TH1D(name, title, geom.GetNumPixels(), -0.5, geom.GetNumPixels()-0.5),
|
|---|
| 118 | fUsed(geom.GetNumPixels()),*/ fColors(kItemsLegend)
|
|---|
| 119 | {
|
|---|
| 120 | //fGeomCam = (MGeomCam*)geom.Clone();
|
|---|
| 121 | SetGeometry(geom, name, title);
|
|---|
| 122 | Init();
|
|---|
| 123 |
|
|---|
| 124 | //
|
|---|
| 125 | // root 3.02
|
|---|
| 126 | // * base/inc/TObject.h:
|
|---|
| 127 | // register BIT(8) as kNoContextMenu. If an object has this bit set it will
|
|---|
| 128 | // not get an automatic context menu when clicked with the right mouse button.
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | void MHCamera::SetGeometry(const MGeomCam &geom, const char *name, const char *title)
|
|---|
| 132 | {
|
|---|
| 133 | SetNameTitle(name, title);
|
|---|
| 134 |
|
|---|
| 135 | TAxis &x = *GetXaxis();
|
|---|
| 136 |
|
|---|
| 137 | SetBins(geom.GetNumPixels(), 0, 1);
|
|---|
| 138 | x.Set(geom.GetNumPixels(), -0.5, geom.GetNumPixels()-0.5);
|
|---|
| 139 |
|
|---|
| 140 | //SetBins(geom.GetNumPixels(), -0.5, geom.GetNumPixels()-0.5);
|
|---|
| 141 | //Rebuild();
|
|---|
| 142 |
|
|---|
| 143 | Sumw2(); // necessary?
|
|---|
| 144 |
|
|---|
| 145 | if (fGeomCam)
|
|---|
| 146 | delete fGeomCam;
|
|---|
| 147 | fGeomCam = (MGeomCam*)geom.Clone();
|
|---|
| 148 |
|
|---|
| 149 | fUsed.Set(geom.GetNumPixels());
|
|---|
| 150 | for (Int_t i=0; i<fNcells-2; i++)
|
|---|
| 151 | ResetUsed(i);
|
|---|
| 152 |
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | // ------------------------------------------------------------------------
|
|---|
| 156 | //
|
|---|
| 157 | // Destructor. Deletes the cloned fGeomCam and the notification list.
|
|---|
| 158 | //
|
|---|
| 159 | MHCamera::~MHCamera()
|
|---|
| 160 | {
|
|---|
| 161 | if (fGeomCam)
|
|---|
| 162 | delete fGeomCam;
|
|---|
| 163 | if (fNotify)
|
|---|
| 164 | delete fNotify;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | // ------------------------------------------------------------------------
|
|---|
| 168 | //
|
|---|
| 169 | // Taken from TH1D::Fill(). Uses the argument directly as bin index.
|
|---|
| 170 | // Doesn't increment the number of entries.
|
|---|
| 171 | //
|
|---|
| 172 | // -*-*-*-*-*-*-*-*Increment bin with abscissa X by 1*-*-*-*-*-*-*-*-*-*-*
|
|---|
| 173 | // ==================================
|
|---|
| 174 | //
|
|---|
| 175 | // if x is less than the low-edge of the first bin, the Underflow bin is incremented
|
|---|
| 176 | // if x is greater than the upper edge of last bin, the Overflow bin is incremented
|
|---|
| 177 | //
|
|---|
| 178 | // If the storage of the sum of squares of weights has been triggered,
|
|---|
| 179 | // via the function Sumw2, then the sum of the squares of weights is incremented
|
|---|
| 180 | // by 1 in the bin corresponding to x.
|
|---|
| 181 | //
|
|---|
| 182 | // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
|---|
| 183 | Int_t MHCamera::Fill(Axis_t x)
|
|---|
| 184 | {
|
|---|
| 185 |
|
|---|
| 186 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,05,00)
|
|---|
| 187 | if (fBuffer) return BufferFill(x,1);
|
|---|
| 188 | #endif
|
|---|
| 189 | const Int_t bin = (Int_t)x+1;
|
|---|
| 190 | AddBinContent(bin);
|
|---|
| 191 | if (fSumw2.fN)
|
|---|
| 192 | fSumw2.fArray[bin]++;
|
|---|
| 193 |
|
|---|
| 194 | if (bin<=0 || bin>fNcells-2)
|
|---|
| 195 | return -1;
|
|---|
| 196 |
|
|---|
| 197 | fTsumw++;
|
|---|
| 198 | fTsumw2++;
|
|---|
| 199 | fTsumwx += x;
|
|---|
| 200 | fTsumwx2 += x*x;
|
|---|
| 201 | return bin;
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | // ------------------------------------------------------------------------
|
|---|
| 205 | //
|
|---|
| 206 | // Taken from TH1D::Fill(). Uses the argument directly as bin index.
|
|---|
| 207 | // Doesn't increment the number of entries.
|
|---|
| 208 | //
|
|---|
| 209 | // -*-*-*-*-*-*Increment bin with abscissa X with a weight w*-*-*-*-*-*-*-*
|
|---|
| 210 | // =============================================
|
|---|
| 211 | //
|
|---|
| 212 | // if x is less than the low-edge of the first bin, the Underflow bin is incremented
|
|---|
| 213 | // if x is greater than the upper edge of last bin, the Overflow bin is incremented
|
|---|
| 214 | //
|
|---|
| 215 | // If the storage of the sum of squares of weights has been triggered,
|
|---|
| 216 | // via the function Sumw2, then the sum of the squares of weights is incremented
|
|---|
| 217 | // by w^2 in the bin corresponding to x.
|
|---|
| 218 | //
|
|---|
| 219 | // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
|---|
| 220 | Int_t MHCamera::Fill(Axis_t x, Stat_t w)
|
|---|
| 221 | {
|
|---|
| 222 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,05,00)
|
|---|
| 223 | if (fBuffer) return BufferFill(x,w);
|
|---|
| 224 | #endif
|
|---|
| 225 | const Int_t bin = (Int_t)x+1;
|
|---|
| 226 | AddBinContent(bin, w);
|
|---|
| 227 | if (fSumw2.fN)
|
|---|
| 228 | fSumw2.fArray[bin] += w*w;
|
|---|
| 229 |
|
|---|
| 230 | if (bin<=0 || bin>fNcells-2)
|
|---|
| 231 | return -1;
|
|---|
| 232 |
|
|---|
| 233 | const Stat_t z = (w > 0 ? w : -w);
|
|---|
| 234 | fTsumw += z;
|
|---|
| 235 | fTsumw2 += z*z;
|
|---|
| 236 | fTsumwx += z*x;
|
|---|
| 237 | fTsumwx2 += z*x*x;
|
|---|
| 238 | return bin;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | // ------------------------------------------------------------------------
|
|---|
| 242 | //
|
|---|
| 243 | // Use x and y in millimeters
|
|---|
| 244 | //
|
|---|
| 245 | Int_t MHCamera::Fill(Axis_t x, Axis_t y, Stat_t w)
|
|---|
| 246 | {
|
|---|
| 247 | if (fNcells<=1 || IsFreezed())
|
|---|
| 248 | return -1;
|
|---|
| 249 |
|
|---|
| 250 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 251 | {
|
|---|
| 252 | MHexagon hex((*fGeomCam)[idx]);
|
|---|
| 253 | if (hex.DistanceToPrimitive(x, y)>0)
|
|---|
| 254 | continue;
|
|---|
| 255 |
|
|---|
| 256 | SetUsed(idx);
|
|---|
| 257 | return Fill(idx, w);
|
|---|
| 258 | }
|
|---|
| 259 | return -1;
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | Stat_t MHCamera::GetMean(Int_t axis) const
|
|---|
| 263 | {
|
|---|
| 264 | if (fNcells<=1)
|
|---|
| 265 | return 0;
|
|---|
| 266 |
|
|---|
| 267 | Stat_t mean = 0;
|
|---|
| 268 | for (int i=1; i<fNcells-1; i++)
|
|---|
| 269 | mean += fArray[i];
|
|---|
| 270 |
|
|---|
| 271 | return Profile(mean/(fNcells-2));
|
|---|
| 272 | }
|
|---|
| 273 |
|
|---|
| 274 | Stat_t MHCamera::GetRMS(Int_t axis) const
|
|---|
| 275 | {
|
|---|
| 276 | if (fNcells<=1)
|
|---|
| 277 | return -1;
|
|---|
| 278 |
|
|---|
| 279 | const Int_t n = fNcells-2;
|
|---|
| 280 |
|
|---|
| 281 | Stat_t sum = 0;
|
|---|
| 282 | Stat_t sq = 0;
|
|---|
| 283 | for (int i=1; i<n+1; i++)
|
|---|
| 284 | {
|
|---|
| 285 | sum += fArray[i];
|
|---|
| 286 | sq += fArray[i]*fArray[i];
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | sum /= n;
|
|---|
| 290 | sq /= n;
|
|---|
| 291 |
|
|---|
| 292 | return Profile(TMath::Sqrt(sq-sum*sum));
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | // ------------------------------------------------------------------------
|
|---|
| 296 | //
|
|---|
| 297 | // Return the minimum contents of all pixels (if all is set, otherwise
|
|---|
| 298 | // only of all 'used' pixels), fMinimum if fMinimum set
|
|---|
| 299 | //
|
|---|
| 300 | Double_t MHCamera::GetMinimum(Bool_t all) const
|
|---|
| 301 | {
|
|---|
| 302 | if (fMinimum != -1111)
|
|---|
| 303 | return fMinimum;
|
|---|
| 304 |
|
|---|
| 305 | if (fNcells<=1)
|
|---|
| 306 | return 0;
|
|---|
| 307 |
|
|---|
| 308 | Double_t minimum=FLT_MAX;
|
|---|
| 309 |
|
|---|
| 310 | if (all)
|
|---|
| 311 | {
|
|---|
| 312 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 313 | if (fArray[idx+1] < minimum)
|
|---|
| 314 | minimum = fArray[idx+1];
|
|---|
| 315 | }
|
|---|
| 316 | else
|
|---|
| 317 | {
|
|---|
| 318 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 319 | if (IsUsed(idx) && fArray[idx+1] < minimum)
|
|---|
| 320 | minimum = fArray[idx+1];
|
|---|
| 321 | }
|
|---|
| 322 | return Profile(minimum);
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | // ------------------------------------------------------------------------
|
|---|
| 326 | //
|
|---|
| 327 | // Return the maximum contents of all pixels (if all is set, otherwise
|
|---|
| 328 | // only of all 'used' pixels), fMaximum if fMaximum set
|
|---|
| 329 | //
|
|---|
| 330 | Double_t MHCamera::GetMaximum(Bool_t all) const
|
|---|
| 331 | {
|
|---|
| 332 | if (fMaximum!=-1111)
|
|---|
| 333 | return fMaximum;
|
|---|
| 334 |
|
|---|
| 335 | if (fNcells<=1)
|
|---|
| 336 | return 1;
|
|---|
| 337 |
|
|---|
| 338 | Double_t maximum=-FLT_MAX;
|
|---|
| 339 | if (all)
|
|---|
| 340 | {
|
|---|
| 341 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 342 | if (fArray[idx+1] > maximum)
|
|---|
| 343 | maximum = fArray[idx+1];
|
|---|
| 344 | }
|
|---|
| 345 | else
|
|---|
| 346 | {
|
|---|
| 347 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 348 | if (IsUsed(idx) && fArray[idx+1] > maximum)
|
|---|
| 349 | maximum = fArray[idx+1];
|
|---|
| 350 | }
|
|---|
| 351 | return Profile(maximum);
|
|---|
| 352 | }
|
|---|
| 353 |
|
|---|
| 354 | // ------------------------------------------------------------------------
|
|---|
| 355 | //
|
|---|
| 356 | // Call this function to draw the camera layout into your canvas.
|
|---|
| 357 | // Setup a drawing canvas. Add this object and all child objects
|
|---|
| 358 | // (hexagons, etc) to the current pad. If no pad exists a new one is
|
|---|
| 359 | // created. (To access the 'real' pad containing the camera you have
|
|---|
| 360 | // to do a cd(1) in the current layer.
|
|---|
| 361 | //
|
|---|
| 362 | // To draw a camera into its own pad do something like:
|
|---|
| 363 | //
|
|---|
| 364 | // MGeomCamMagic m;
|
|---|
| 365 | // MHCamera *d=new MHCamera(m);
|
|---|
| 366 | //
|
|---|
| 367 | // TCanvas *c = new TCanvas;
|
|---|
| 368 | // c->Divide(2,1);
|
|---|
| 369 | // c->cd(1);
|
|---|
| 370 | //
|
|---|
| 371 | // d->FillRandom();
|
|---|
| 372 | // d->Draw();
|
|---|
| 373 | // d->SetBit(kCanDelete);
|
|---|
| 374 | //
|
|---|
| 375 | // There are several drawing options:
|
|---|
| 376 | // 'hist' Draw as a standard TH1 histogram (value vs. pixel index)
|
|---|
| 377 | // 'box' Draw hexagons which size is in respect to its contents
|
|---|
| 378 | // 'nocol' Leave the 'boxed' hexagons empty
|
|---|
| 379 | // 'pixelindex' Display the pixel index in each pixel
|
|---|
| 380 | // 'sectorindex' Display the sector index in each pixel
|
|---|
| 381 | // 'content' Display the relative content aligned to GetMaximum() and
|
|---|
| 382 | // GeMinimum() ((val-min)/(max-min))
|
|---|
| 383 | //
|
|---|
| 384 | void MHCamera::Draw(Option_t *option)
|
|---|
| 385 | {
|
|---|
| 386 | // root 3.02:
|
|---|
| 387 | // gPad->SetFixedAspectRatio()
|
|---|
| 388 | const Color_t col = gPad ? gPad->GetFillColor() : 16;
|
|---|
| 389 | TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas("CamDisplay", "Mars Camera Display", 656, 600);
|
|---|
| 390 | pad->SetBorderMode(0);
|
|---|
| 391 | pad->SetFillColor(col);
|
|---|
| 392 |
|
|---|
| 393 | //
|
|---|
| 394 | // Create an own pad for the MHCamera-Object which can be
|
|---|
| 395 | // resized in paint to keep the correct aspect ratio
|
|---|
| 396 | //
|
|---|
| 397 | pad->Divide(1, 1, 0, 0, col);
|
|---|
| 398 | pad->cd(1);
|
|---|
| 399 | gPad->SetBorderMode(0);
|
|---|
| 400 |
|
|---|
| 401 | AppendPad(option);
|
|---|
| 402 |
|
|---|
| 403 | //
|
|---|
| 404 | // Do not change gPad. The user should not see, that Draw
|
|---|
| 405 | // changes gPad...
|
|---|
| 406 | //
|
|---|
| 407 | pad->cd();
|
|---|
| 408 | }
|
|---|
| 409 |
|
|---|
| 410 | // ------------------------------------------------------------------------
|
|---|
| 411 | //
|
|---|
| 412 | // This is TObject::DrawClone but completely ignores
|
|---|
| 413 | // gROOT->GetSelectedPad(). tbretz had trouble with this in the past.
|
|---|
| 414 | // If this makes trouble please write a bug report.
|
|---|
| 415 | //
|
|---|
| 416 | TObject *MHCamera::DrawClone(Option_t *option) const
|
|---|
| 417 | {
|
|---|
| 418 | // Draw a clone of this object in the current pad
|
|---|
| 419 |
|
|---|
| 420 | //TVirtualPad *pad = gROOT->GetSelectedPad();
|
|---|
| 421 | TVirtualPad *padsav = gPad;
|
|---|
| 422 | //if (pad) pad->cd();
|
|---|
| 423 |
|
|---|
| 424 | TObject *newobj = Clone();
|
|---|
| 425 | if (!newobj)
|
|---|
| 426 | return 0;
|
|---|
| 427 |
|
|---|
| 428 | /*
|
|---|
| 429 | if (pad) {
|
|---|
| 430 | if (strlen(option)) pad->GetListOfPrimitives()->Add(newobj,option);
|
|---|
| 431 | else pad->GetListOfPrimitives()->Add(newobj,GetDrawOption());
|
|---|
| 432 | pad->Modified(kTRUE);
|
|---|
| 433 | pad->Update();
|
|---|
| 434 | if (padsav) padsav->cd();
|
|---|
| 435 | return newobj;
|
|---|
| 436 | }
|
|---|
| 437 | */
|
|---|
| 438 |
|
|---|
| 439 | const TString opt(option);
|
|---|
| 440 | newobj->Draw(opt.IsNull() ? GetDrawOption() : option);
|
|---|
| 441 |
|
|---|
| 442 | if (padsav)
|
|---|
| 443 | padsav->cd();
|
|---|
| 444 |
|
|---|
| 445 | return newobj;
|
|---|
| 446 | }
|
|---|
| 447 |
|
|---|
| 448 | // ------------------------------------------------------------------------
|
|---|
| 449 | //
|
|---|
| 450 | // Resizes the current pad so that the camera is displayed in its
|
|---|
| 451 | // correct aspect ratio
|
|---|
| 452 | //
|
|---|
| 453 | void MHCamera::SetRange()
|
|---|
| 454 | {
|
|---|
| 455 | const Float_t range = fGeomCam->GetMaxRadius()*1.05;
|
|---|
| 456 |
|
|---|
| 457 | //
|
|---|
| 458 | // Maintain aspect ratio
|
|---|
| 459 | //
|
|---|
| 460 | const float ratio = TestBit(kNoLegend) ? 1 : 1.15;
|
|---|
| 461 |
|
|---|
| 462 | //
|
|---|
| 463 | // Calculate width and height of the current pad in pixels
|
|---|
| 464 | //
|
|---|
| 465 | Float_t w = gPad->GetWw();
|
|---|
| 466 | Float_t h = gPad->GetWh()*ratio;
|
|---|
| 467 |
|
|---|
| 468 | //
|
|---|
| 469 | // This prevents the pad from resizing itself wrongly
|
|---|
| 470 | //
|
|---|
| 471 | if (gPad->GetMother() != gPad)
|
|---|
| 472 | {
|
|---|
| 473 | w *= gPad->GetMother()->GetAbsWNDC();
|
|---|
| 474 | h *= gPad->GetMother()->GetAbsHNDC();
|
|---|
| 475 | }
|
|---|
| 476 |
|
|---|
| 477 | //
|
|---|
| 478 | // Set Range (coordinate system) of pad
|
|---|
| 479 | //
|
|---|
| 480 | gPad->Range(-range, -range, (2*ratio-1)*range, range);
|
|---|
| 481 |
|
|---|
| 482 | //
|
|---|
| 483 | // Resize Pad to given ratio
|
|---|
| 484 | //
|
|---|
| 485 | if (h<w)
|
|---|
| 486 | gPad->SetPad((1.-h/w)/2, 0, (h/w+1.)/2, 1);
|
|---|
| 487 | else
|
|---|
| 488 | gPad->SetPad(0, (1.-w/h)/2, 1, (w/h+1.)/2);
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 | // ------------------------------------------------------------------------
|
|---|
| 492 | //
|
|---|
| 493 | // Updates the pixel colors and paints the pixels
|
|---|
| 494 | //
|
|---|
| 495 | void MHCamera::Update(Bool_t islog, Bool_t isbox, Bool_t iscol)
|
|---|
| 496 | {
|
|---|
| 497 | Double_t min = GetMinimum(kFALSE);
|
|---|
| 498 | Double_t max = GetMaximum(kFALSE);
|
|---|
| 499 | if (min==FLT_MAX)
|
|---|
| 500 | {
|
|---|
| 501 | min = 0;
|
|---|
| 502 | max = 1;
|
|---|
| 503 | }
|
|---|
| 504 |
|
|---|
| 505 | if (min==max)
|
|---|
| 506 | max += 1;
|
|---|
| 507 |
|
|---|
| 508 | UpdateLegend(min, max, islog);
|
|---|
| 509 |
|
|---|
| 510 | MHexagon hex;
|
|---|
| 511 | for (Int_t i=0; i<fNcells-2; i++)
|
|---|
| 512 | {
|
|---|
| 513 | if (IsUsed(i) && iscol)
|
|---|
| 514 | {
|
|---|
| 515 | if (TMath::IsNaN(fArray[i+1]))
|
|---|
| 516 | gLog << warn << "MHCamera::Update: " << GetName() << " <" << GetTitle() << "> - Pixel Index #" << i << " contents is NaN (Not a Number)..." << endl;
|
|---|
| 517 |
|
|---|
| 518 | hex.SetFillColor(GetColor(GetBinContent(i+1), min, max, islog));
|
|---|
| 519 | }
|
|---|
| 520 | else
|
|---|
| 521 | hex.SetFillColor(10);
|
|---|
| 522 |
|
|---|
| 523 | MGeomPix &pix = (*fGeomCam)[i];
|
|---|
| 524 | if (!isbox)
|
|---|
| 525 | hex.PaintHexagon(pix.GetX(), pix.GetY(), pix.GetD());
|
|---|
| 526 | else
|
|---|
| 527 | if (IsUsed(i) && !TMath::IsNaN(fArray[i+1]))
|
|---|
| 528 | {
|
|---|
| 529 | Float_t size = pix.GetD()*(GetBinContent(i+1)-min)/(max-min);
|
|---|
| 530 | if (size>pix.GetD())
|
|---|
| 531 | size=pix.GetD();
|
|---|
| 532 | hex.PaintHexagon(pix.GetX(), pix.GetY(), size);
|
|---|
| 533 | }
|
|---|
| 534 | }
|
|---|
| 535 | }
|
|---|
| 536 |
|
|---|
| 537 | // ------------------------------------------------------------------------
|
|---|
| 538 | //
|
|---|
| 539 | // Print minimum and maximum
|
|---|
| 540 | //
|
|---|
| 541 | void MHCamera::Print(Option_t *) const
|
|---|
| 542 | {
|
|---|
| 543 | cout << "Minimum: " << GetMinimum();
|
|---|
| 544 | if (fMinimum==-1111)
|
|---|
| 545 | cout << " <autoscaled>";
|
|---|
| 546 | cout << endl;
|
|---|
| 547 | cout << "Maximum: " << GetMaximum();
|
|---|
| 548 | if (fMaximum==-1111)
|
|---|
| 549 | cout << " <autoscaled>";
|
|---|
| 550 | cout << endl;
|
|---|
| 551 | }
|
|---|
| 552 |
|
|---|
| 553 | // ------------------------------------------------------------------------
|
|---|
| 554 | //
|
|---|
| 555 | // Paint the y-axis title
|
|---|
| 556 | //
|
|---|
| 557 | void MHCamera::PaintAxisTitle()
|
|---|
| 558 | {
|
|---|
| 559 | const Float_t range = fGeomCam->GetMaxRadius()*1.05;
|
|---|
| 560 | const Float_t w = (1 + 1.5/sqrt((float)(fNcells-2)))*range;
|
|---|
| 561 |
|
|---|
| 562 | TLatex *ptitle = new TLatex(w, -.90*range, GetYaxis()->GetTitle());
|
|---|
| 563 |
|
|---|
| 564 | ptitle->SetTextSize(0.05);
|
|---|
| 565 | ptitle->SetTextAlign(21);
|
|---|
| 566 |
|
|---|
| 567 | // box with the histogram title
|
|---|
| 568 | ptitle->SetTextColor(gStyle->GetTitleTextColor());
|
|---|
| 569 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,05,01)
|
|---|
| 570 | ptitle->SetTextFont(gStyle->GetTitleFont(""));
|
|---|
| 571 | #endif
|
|---|
| 572 | ptitle->Paint();
|
|---|
| 573 | }
|
|---|
| 574 |
|
|---|
| 575 | // ------------------------------------------------------------------------
|
|---|
| 576 | //
|
|---|
| 577 | // Paints the camera.
|
|---|
| 578 | //
|
|---|
| 579 | void MHCamera::Paint(Option_t *o)
|
|---|
| 580 | {
|
|---|
| 581 | if (fNcells<=1)
|
|---|
| 582 | return;
|
|---|
| 583 |
|
|---|
| 584 | TString opt(o);
|
|---|
| 585 | opt.ToLower();
|
|---|
| 586 |
|
|---|
| 587 | if (opt.Contains("hist"))
|
|---|
| 588 | {
|
|---|
| 589 | opt.ReplaceAll("hist", "");
|
|---|
| 590 | TH1D::Paint(opt);
|
|---|
| 591 | return;
|
|---|
| 592 | }
|
|---|
| 593 |
|
|---|
| 594 | gPad->Clear();
|
|---|
| 595 |
|
|---|
| 596 | // Maintain aspect ratio
|
|---|
| 597 | SetRange();
|
|---|
| 598 |
|
|---|
| 599 | Bool_t isbox = opt.Contains("box");
|
|---|
| 600 | Bool_t iscol = isbox ? !opt.Contains("nocol") : 1;
|
|---|
| 601 |
|
|---|
| 602 | GetPainter();
|
|---|
| 603 | if (fPainter)
|
|---|
| 604 | {
|
|---|
| 605 | if (!TestBit(TH1::kNoStats))
|
|---|
| 606 | {
|
|---|
| 607 | fPainter->SetHistogram(this);
|
|---|
| 608 | fPainter->PaintStat(gStyle->GetOptStat(), NULL);
|
|---|
| 609 | }
|
|---|
| 610 |
|
|---|
| 611 | // Paint primitives (pixels, color legend, photons, ...)
|
|---|
| 612 | if (fPainter->InheritsFrom(THistPainter::Class()))
|
|---|
| 613 | ((THistPainter*)fPainter)->PaintTitle();
|
|---|
| 614 | }
|
|---|
| 615 |
|
|---|
| 616 | // Update Contents of the pixels and paint legend
|
|---|
| 617 | Update(gPad->GetLogy(), isbox, iscol);
|
|---|
| 618 | PaintAxisTitle();
|
|---|
| 619 |
|
|---|
| 620 | if (opt.Contains("pixelindex"))
|
|---|
| 621 | PaintIndices(0);
|
|---|
| 622 | if (opt.Contains("sectorindex"))
|
|---|
| 623 | PaintIndices(1);
|
|---|
| 624 | if (opt.Contains("content"))
|
|---|
| 625 | PaintIndices(2);
|
|---|
| 626 | }
|
|---|
| 627 |
|
|---|
| 628 | // ------------------------------------------------------------------------
|
|---|
| 629 | //
|
|---|
| 630 | // With this function you can change the color palette. For more
|
|---|
| 631 | // information see TStyle::SetPalette. Only palettes with 50 colors
|
|---|
| 632 | // are allowed.
|
|---|
| 633 | // In addition you can use SetPalette(52, 0) to create an inverse
|
|---|
| 634 | // deep blue sea palette
|
|---|
| 635 | //
|
|---|
| 636 | void MHCamera::SetPalette(Int_t ncolors, Int_t *colors)
|
|---|
| 637 | {
|
|---|
| 638 | //
|
|---|
| 639 | // If not enough colors are specified skip this.
|
|---|
| 640 | //
|
|---|
| 641 | if (ncolors>1 && ncolors<50)
|
|---|
| 642 | {
|
|---|
| 643 | cout << "MHCamera::SetPalette: Only default palettes with 50 colors are allowed... ignored." << endl;
|
|---|
| 644 | return;
|
|---|
| 645 | }
|
|---|
| 646 |
|
|---|
| 647 | //
|
|---|
| 648 | // If ncolors==52 create a reversed deep blue sea palette
|
|---|
| 649 | //
|
|---|
| 650 | if (ncolors==52)
|
|---|
| 651 | {
|
|---|
| 652 | gStyle->SetPalette(51, NULL);
|
|---|
| 653 | TArrayI c(kItemsLegend);
|
|---|
| 654 | for (int i=0; i<kItemsLegend; i++)
|
|---|
| 655 | c[kItemsLegend-i-1] = gStyle->GetColorPalette(i);
|
|---|
| 656 | gStyle->SetPalette(kItemsLegend, c.GetArray());
|
|---|
| 657 | }
|
|---|
| 658 | else
|
|---|
| 659 | gStyle->SetPalette(ncolors, colors);
|
|---|
| 660 |
|
|---|
| 661 | fColors.Set(kItemsLegend);
|
|---|
| 662 | for (int i=0; i<kItemsLegend; i++)
|
|---|
| 663 | fColors[i] = gStyle->GetColorPalette(i);
|
|---|
| 664 | }
|
|---|
| 665 |
|
|---|
| 666 |
|
|---|
| 667 | void MHCamera::SetPrettyPalette()
|
|---|
| 668 | {
|
|---|
| 669 | if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
|
|---|
| 670 | SetPalette(1, 0);
|
|---|
| 671 | }
|
|---|
| 672 |
|
|---|
| 673 | void MHCamera::SetDeepBlueSeaPalette()
|
|---|
| 674 | {
|
|---|
| 675 | if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
|
|---|
| 676 | SetPalette(51, 0);
|
|---|
| 677 | }
|
|---|
| 678 |
|
|---|
| 679 | void MHCamera::SetInvDeepBlueSeaPalette()
|
|---|
| 680 | {
|
|---|
| 681 | if (!TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
|
|---|
| 682 | SetPalette(52, 0);
|
|---|
| 683 | }
|
|---|
| 684 |
|
|---|
| 685 | void MHCamera::PaintIndices(Int_t type)
|
|---|
| 686 | {
|
|---|
| 687 | if (fNcells<=1)
|
|---|
| 688 | return;
|
|---|
| 689 |
|
|---|
| 690 | const Double_t min = GetMinimum();
|
|---|
| 691 | const Double_t max = GetMaximum();
|
|---|
| 692 |
|
|---|
| 693 | if (type==2 && max==min)
|
|---|
| 694 | return;
|
|---|
| 695 |
|
|---|
| 696 | TText txt;
|
|---|
| 697 | txt.SetTextFont(122);
|
|---|
| 698 | txt.SetTextAlign(22); // centered/centered
|
|---|
| 699 |
|
|---|
| 700 | for (Int_t i=0; i<fNcells-2; i++)
|
|---|
| 701 | {
|
|---|
| 702 | const MGeomPix &h = (*fGeomCam)[i];
|
|---|
| 703 |
|
|---|
| 704 | TString num;
|
|---|
| 705 | switch (type)
|
|---|
| 706 | {
|
|---|
| 707 | case 0: num += i; break;
|
|---|
| 708 | case 1: num += h.GetSector(); break;
|
|---|
| 709 | case 2: num += (Int_t)((fArray[i+1]-min)/(max-min)); break;
|
|---|
| 710 | }
|
|---|
| 711 |
|
|---|
| 712 | // FIXME: Should depend on the color of the pixel...
|
|---|
| 713 | //(GetColor(GetBinContent(i+1), min, max, 0));
|
|---|
| 714 | txt.SetTextColor(kRed);
|
|---|
| 715 | txt.SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius()/1.05);
|
|---|
| 716 | txt.PaintText(h.GetX(), h.GetY(), num);
|
|---|
| 717 | }
|
|---|
| 718 | }
|
|---|
| 719 |
|
|---|
| 720 | // ------------------------------------------------------------------------
|
|---|
| 721 | //
|
|---|
| 722 | // Call this function to add a MCamEvent on top of the present contents.
|
|---|
| 723 | //
|
|---|
| 724 | void MHCamera::AddCamContent(const MCamEvent &event, Int_t type)
|
|---|
| 725 | {
|
|---|
| 726 | if (fNcells<=1 || IsFreezed())
|
|---|
| 727 | return;
|
|---|
| 728 |
|
|---|
| 729 | // FIXME: Security check missing!
|
|---|
| 730 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 731 | {
|
|---|
| 732 | Double_t val=0;
|
|---|
| 733 | if (event.GetPixelContent(val, idx, *fGeomCam, type)/* && !IsUsed(idx)*/)
|
|---|
| 734 | SetUsed(idx);
|
|---|
| 735 |
|
|---|
| 736 | Fill(idx, val); // FIXME: Slow!
|
|---|
| 737 | }
|
|---|
| 738 | fEntries++;
|
|---|
| 739 | }
|
|---|
| 740 |
|
|---|
| 741 | // ------------------------------------------------------------------------
|
|---|
| 742 | //
|
|---|
| 743 | // Call this function to add a MCamEvent on top of the present contents.
|
|---|
| 744 | //
|
|---|
| 745 | void MHCamera::SetCamError(const MCamEvent &evt, Int_t type)
|
|---|
| 746 | {
|
|---|
| 747 |
|
|---|
| 748 | if (fNcells<=1 || IsFreezed())
|
|---|
| 749 | return;
|
|---|
| 750 |
|
|---|
| 751 | // FIXME: Security check missing!
|
|---|
| 752 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 753 | {
|
|---|
| 754 | Double_t val=0;
|
|---|
| 755 | if (evt.GetPixelContent(val, idx, *fGeomCam, type)/* && !IsUsed(idx)*/)
|
|---|
| 756 | SetUsed(idx);
|
|---|
| 757 |
|
|---|
| 758 | SetBinError(idx+1, val); // FIXME: Slow!
|
|---|
| 759 | }
|
|---|
| 760 | }
|
|---|
| 761 |
|
|---|
| 762 | Stat_t MHCamera::GetBinError(Int_t bin) const
|
|---|
| 763 | {
|
|---|
| 764 | Double_t rc = 0;
|
|---|
| 765 | if (TestBit(kVariance) && GetEntries()>0) // error on the mean
|
|---|
| 766 | {
|
|---|
| 767 | const Double_t error = fSumw2.fArray[bin]/GetEntries();
|
|---|
| 768 | const Double_t val = fArray[bin]/GetEntries();
|
|---|
| 769 | rc = TMath::Sqrt(error - val*val);
|
|---|
| 770 | }
|
|---|
| 771 | else
|
|---|
| 772 | rc = TH1D::GetBinError(bin);
|
|---|
| 773 |
|
|---|
| 774 | return Profile(rc);
|
|---|
| 775 | }
|
|---|
| 776 |
|
|---|
| 777 | // ------------------------------------------------------------------------
|
|---|
| 778 | //
|
|---|
| 779 | // Call this function to add a MHCamera on top of the present contents.
|
|---|
| 780 | // Type:
|
|---|
| 781 | // 0) bin content
|
|---|
| 782 | // 1) errors
|
|---|
| 783 | // 2) rel. errors
|
|---|
| 784 | //
|
|---|
| 785 | void MHCamera::AddCamContent(const MHCamera &d, Int_t type)
|
|---|
| 786 | {
|
|---|
| 787 | if (fNcells!=d.fNcells || IsFreezed())
|
|---|
| 788 | return;
|
|---|
| 789 |
|
|---|
| 790 | // FIXME: Security check missing!
|
|---|
| 791 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 792 | if (d.IsUsed(idx))
|
|---|
| 793 | SetUsed(idx);
|
|---|
| 794 |
|
|---|
| 795 | switch (type)
|
|---|
| 796 | {
|
|---|
| 797 | case 1:
|
|---|
| 798 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 799 | Fill(idx, d.GetBinError(idx+1));
|
|---|
| 800 | break;
|
|---|
| 801 | case 2:
|
|---|
| 802 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 803 | if (d.GetBinContent(idx+1)!=0)
|
|---|
| 804 | Fill(idx, TMath::Abs(d.GetBinError(idx+1)/d.GetBinContent(idx+1)));
|
|---|
| 805 | break;
|
|---|
| 806 | default:
|
|---|
| 807 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 808 | Fill(idx, d.GetBinContent(idx+1));
|
|---|
| 809 | break;
|
|---|
| 810 | }
|
|---|
| 811 | fEntries++;
|
|---|
| 812 | }
|
|---|
| 813 |
|
|---|
| 814 | // ------------------------------------------------------------------------
|
|---|
| 815 | //
|
|---|
| 816 | // Call this function to add a TArrayD on top of the present contents.
|
|---|
| 817 | //
|
|---|
| 818 | void MHCamera::AddCamContent(const TArrayD &event, const TArrayC *used)
|
|---|
| 819 | {
|
|---|
| 820 | if (event.GetSize()!=fNcells-2 || IsFreezed())
|
|---|
| 821 | return;
|
|---|
| 822 |
|
|---|
| 823 | if (used && used->GetSize()!=fNcells-2)
|
|---|
| 824 | return;
|
|---|
| 825 |
|
|---|
| 826 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 827 | {
|
|---|
| 828 | Fill(idx, const_cast<TArrayD&>(event)[idx]); // FIXME: Slow!
|
|---|
| 829 |
|
|---|
| 830 | if (!used || (*const_cast<TArrayC*>(used))[idx])
|
|---|
| 831 | SetUsed(idx);
|
|---|
| 832 | }
|
|---|
| 833 | fEntries++;
|
|---|
| 834 | }
|
|---|
| 835 |
|
|---|
| 836 | // ------------------------------------------------------------------------
|
|---|
| 837 | //
|
|---|
| 838 | // Call this function to add a MCamEvent on top of the present contents.
|
|---|
| 839 | // 1 is added to each pixel if the contents of MCamEvent>threshold
|
|---|
| 840 | //
|
|---|
| 841 | void MHCamera::CntCamContent(const MCamEvent &event, Double_t threshold, Int_t type)
|
|---|
| 842 | {
|
|---|
| 843 | if (fNcells<=1 || IsFreezed())
|
|---|
| 844 | return;
|
|---|
| 845 |
|
|---|
| 846 | // FIXME: Security check missing!
|
|---|
| 847 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 848 | {
|
|---|
| 849 | Double_t val=threshold;
|
|---|
| 850 | if (event.GetPixelContent(val, idx, *fGeomCam, type)/* && !IsUsed(idx)*/)
|
|---|
| 851 | SetUsed(idx);
|
|---|
| 852 |
|
|---|
| 853 | if (val>threshold)
|
|---|
| 854 | Fill(idx);
|
|---|
| 855 | }
|
|---|
| 856 | fEntries++;
|
|---|
| 857 | }
|
|---|
| 858 |
|
|---|
| 859 | // ------------------------------------------------------------------------
|
|---|
| 860 | //
|
|---|
| 861 | // Call this function to add a TArrayD on top of the present contents.
|
|---|
| 862 | // 1 is added to each pixel if the contents of MCamEvent>threshold
|
|---|
| 863 | //
|
|---|
| 864 | void MHCamera::CntCamContent(const TArrayD &event, Double_t threshold, Bool_t ispos)
|
|---|
| 865 | {
|
|---|
| 866 | if (event.GetSize()!=fNcells-2 || IsFreezed())
|
|---|
| 867 | return;
|
|---|
| 868 |
|
|---|
| 869 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 870 | {
|
|---|
| 871 | if (const_cast<TArrayD&>(event)[idx]>threshold)
|
|---|
| 872 | Fill(idx);
|
|---|
| 873 |
|
|---|
| 874 | if (!ispos || fArray[idx+1]>0)
|
|---|
| 875 | SetUsed(idx);
|
|---|
| 876 | }
|
|---|
| 877 | fEntries++;
|
|---|
| 878 | }
|
|---|
| 879 |
|
|---|
| 880 | // ------------------------------------------------------------------------
|
|---|
| 881 | //
|
|---|
| 882 | // Fill the pixels with random contents.
|
|---|
| 883 | //
|
|---|
| 884 | void MHCamera::FillRandom()
|
|---|
| 885 | {
|
|---|
| 886 | if (fNcells<=1 || IsFreezed())
|
|---|
| 887 | return;
|
|---|
| 888 |
|
|---|
| 889 | Reset();
|
|---|
| 890 |
|
|---|
| 891 | // FIXME: Security check missing!
|
|---|
| 892 | for (Int_t idx=0; idx<fNcells-2; idx++)
|
|---|
| 893 | {
|
|---|
| 894 | Fill(idx, gRandom->Uniform()*fGeomCam->GetPixRatio(idx));
|
|---|
| 895 | SetUsed(idx);
|
|---|
| 896 | }
|
|---|
| 897 | fEntries=1;
|
|---|
| 898 | }
|
|---|
| 899 |
|
|---|
| 900 |
|
|---|
| 901 | // ------------------------------------------------------------------------
|
|---|
| 902 | //
|
|---|
| 903 | // The array must be in increasing order, eg: 2.5, 3.7, 4.9
|
|---|
| 904 | // The values in each bin are replaced by the interval in which the value
|
|---|
| 905 | // fits. In the example we have four intervals
|
|---|
| 906 | // (<2.5, 2.5-3.7, 3.7-4.9, >4.9). Maximum and minimum are set
|
|---|
| 907 | // accordingly.
|
|---|
| 908 | //
|
|---|
| 909 | void MHCamera::SetLevels(const TArrayF &arr)
|
|---|
| 910 | {
|
|---|
| 911 | if (fNcells<=1)
|
|---|
| 912 | return;
|
|---|
| 913 |
|
|---|
| 914 | for (Int_t i=0; i<fNcells-2; i++)
|
|---|
| 915 | {
|
|---|
| 916 | if (!IsUsed(i))
|
|---|
| 917 | continue;
|
|---|
| 918 |
|
|---|
| 919 | Int_t j = arr.GetSize();
|
|---|
| 920 | while (j && fArray[i+1]<arr[j-1])
|
|---|
| 921 | j--;
|
|---|
| 922 |
|
|---|
| 923 | fArray[i+1] = j;
|
|---|
| 924 | }
|
|---|
| 925 | SetMaximum(arr.GetSize());
|
|---|
| 926 | SetMinimum(0);
|
|---|
| 927 | }
|
|---|
| 928 |
|
|---|
| 929 | // ------------------------------------------------------------------------
|
|---|
| 930 | //
|
|---|
| 931 | // Reset the all pixel colors to a default value
|
|---|
| 932 | //
|
|---|
| 933 | void MHCamera::Reset(Option_t *opt)
|
|---|
| 934 | {
|
|---|
| 935 | if (fNcells<=1 || IsFreezed())
|
|---|
| 936 | return;
|
|---|
| 937 |
|
|---|
| 938 | TH1::Reset(opt);
|
|---|
| 939 |
|
|---|
| 940 | for (Int_t i=0; i<fNcells-2; i++)
|
|---|
| 941 | {
|
|---|
| 942 | fArray[i+1]=0;
|
|---|
| 943 | ResetUsed(i);
|
|---|
| 944 | }
|
|---|
| 945 | fArray[0] = 0;
|
|---|
| 946 | fArray[fNcells-1] = 0;
|
|---|
| 947 | }
|
|---|
| 948 |
|
|---|
| 949 | // ------------------------------------------------------------------------
|
|---|
| 950 | //
|
|---|
| 951 | // Here we calculate the color index for the current value.
|
|---|
| 952 | // The color index is defined with the class TStyle and the
|
|---|
| 953 | // Color palette inside. We use the command gStyle->SetPalette(1,0)
|
|---|
| 954 | // for the display. So we have to convert the value "wert" into
|
|---|
| 955 | // a color index that fits the color palette.
|
|---|
| 956 | // The range of the color palette is defined by the values fMinPhe
|
|---|
| 957 | // and fMaxRange. Between this values we have 50 color index, starting
|
|---|
| 958 | // with 0 up to 49.
|
|---|
| 959 | //
|
|---|
| 960 | Int_t MHCamera::GetColor(Float_t val, Float_t min, Float_t max, Bool_t islog)
|
|---|
| 961 | {
|
|---|
| 962 | if (TMath::IsNaN(val)) // FIXME: gLog!
|
|---|
| 963 | return 10;
|
|---|
| 964 |
|
|---|
| 965 | //
|
|---|
| 966 | // first treat the over- and under-flows
|
|---|
| 967 | //
|
|---|
| 968 | const Int_t maxcolidx = kItemsLegend-1;
|
|---|
| 969 |
|
|---|
| 970 | if (val >= max)
|
|---|
| 971 | return fColors[maxcolidx];
|
|---|
| 972 |
|
|---|
| 973 | if (val <= min)
|
|---|
| 974 | return fColors[0];
|
|---|
| 975 |
|
|---|
| 976 | //
|
|---|
| 977 | // calculate the color index
|
|---|
| 978 | //
|
|---|
| 979 | Float_t ratio;
|
|---|
| 980 | if (islog && min>0)
|
|---|
| 981 | ratio = log10(val/min) / log10(max/min);
|
|---|
| 982 | else
|
|---|
| 983 | ratio = (val-min) / (max-min);
|
|---|
| 984 |
|
|---|
| 985 | const Int_t colidx = (Int_t)(ratio*maxcolidx + .5);
|
|---|
| 986 | return fColors[colidx];
|
|---|
| 987 | }
|
|---|
| 988 |
|
|---|
| 989 | TPaveStats *MHCamera::GetStatisticBox()
|
|---|
| 990 | {
|
|---|
| 991 | TObject *obj = 0;
|
|---|
| 992 |
|
|---|
| 993 | TIter Next(fFunctions);
|
|---|
| 994 | while ((obj = Next()))
|
|---|
| 995 | if (obj->InheritsFrom(TPaveStats::Class()))
|
|---|
| 996 | return static_cast<TPaveStats*>(obj);
|
|---|
| 997 |
|
|---|
| 998 | return NULL;
|
|---|
| 999 | }
|
|---|
| 1000 |
|
|---|
| 1001 | // ------------------------------------------------------------------------
|
|---|
| 1002 | //
|
|---|
| 1003 | // Change the text on the legend according to the range of the Display
|
|---|
| 1004 | //
|
|---|
| 1005 | void MHCamera::UpdateLegend(Float_t min, Float_t max, Bool_t islog)
|
|---|
| 1006 | {
|
|---|
| 1007 | const Float_t range = fGeomCam->GetMaxRadius()*1.05;
|
|---|
| 1008 |
|
|---|
| 1009 | TArrow arr;
|
|---|
| 1010 | arr.PaintArrow(-range*.9, -range*.9, -range*.6, -range*.9, 0.025);
|
|---|
| 1011 | arr.PaintArrow(-range*.9, -range*.9, -range*.9, -range*.6, 0.025);
|
|---|
| 1012 |
|
|---|
| 1013 | TString text;
|
|---|
| 1014 | text += (int)(range*.3);
|
|---|
| 1015 | text += "mm";
|
|---|
| 1016 |
|
|---|
| 1017 | TText newtxt2;
|
|---|
| 1018 | newtxt2.SetTextSize(0.04);
|
|---|
| 1019 | newtxt2.PaintText(-range*.85, -range*.85, text);
|
|---|
| 1020 |
|
|---|
| 1021 | text = "";
|
|---|
| 1022 | text += (float)((int)(range*.3*fGeomCam->GetConvMm2Deg()*10))/10;
|
|---|
| 1023 | text += "\\circ";
|
|---|
| 1024 | text = text.Strip(TString::kLeading);
|
|---|
| 1025 |
|
|---|
| 1026 | TLatex latex;
|
|---|
| 1027 | latex.PaintLatex(-range*.85, -range*.75, 0, 0.04, text);
|
|---|
| 1028 |
|
|---|
| 1029 | if (TestBit(kNoLegend))
|
|---|
| 1030 | return;
|
|---|
| 1031 |
|
|---|
| 1032 | TPaveStats *stats = GetStatisticBox();
|
|---|
| 1033 |
|
|---|
| 1034 | const Float_t hndc = 0.92 - (stats ? stats->GetY1NDC() : 1);
|
|---|
| 1035 | const Float_t H = (0.75-hndc)*range;
|
|---|
| 1036 | const Float_t offset = hndc*range;
|
|---|
| 1037 |
|
|---|
| 1038 | const Float_t h = 2./kItemsLegend;
|
|---|
| 1039 | const Float_t w = range/sqrt((float)(fNcells-2));
|
|---|
| 1040 |
|
|---|
| 1041 | TBox newbox;
|
|---|
| 1042 | TText newtxt;
|
|---|
| 1043 | newtxt.SetTextSize(0.03);
|
|---|
| 1044 | newtxt.SetTextAlign(12);
|
|---|
| 1045 | #if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
|
|---|
| 1046 | newtxt.SetBit(/*kNoContextMenu|*/kCannotPick);
|
|---|
| 1047 | newbox.SetBit(/*kNoContextMenu|*/kCannotPick);
|
|---|
| 1048 | #endif
|
|---|
| 1049 |
|
|---|
| 1050 | const Float_t step = (islog && min>0 ? log10(max/min) : max-min) / kItemsLegend;
|
|---|
| 1051 | const Int_t firsts = step*3 < 1e-8 ? 8 : (Int_t)floor(log10(step*3));
|
|---|
| 1052 | const TString opt = Form("%%.%if", firsts>0 ? 0 : TMath::Abs(firsts));
|
|---|
| 1053 |
|
|---|
| 1054 | for (Int_t i=0; i<kItemsLegend+1; i+=3)
|
|---|
| 1055 | {
|
|---|
| 1056 | Float_t val;
|
|---|
| 1057 | if (islog && min>0)
|
|---|
| 1058 | val = pow(10, step*i) * min;
|
|---|
| 1059 | else
|
|---|
| 1060 | val = min + step*i;
|
|---|
| 1061 |
|
|---|
| 1062 | //const bool dispexp = max-min>1.5 && fabs(val)>0.1 && fabs(val)<1e6;
|
|---|
| 1063 | newtxt.PaintText(range+1.5*w, H*(i*h-1)-offset, Form(opt, val));
|
|---|
| 1064 | }
|
|---|
| 1065 |
|
|---|
| 1066 | for (Int_t i=0; i<kItemsLegend; i++)
|
|---|
| 1067 | {
|
|---|
| 1068 | newbox.SetFillColor(fColors[i]);
|
|---|
| 1069 | newbox.PaintBox(range, H*(i*h-1)-offset, range+w, H*((i+1)*h-1)-offset);
|
|---|
| 1070 | }
|
|---|
| 1071 | }
|
|---|
| 1072 |
|
|---|
| 1073 | // ------------------------------------------------------------------------
|
|---|
| 1074 | //
|
|---|
| 1075 | // Save primitive as a C++ statement(s) on output stream out
|
|---|
| 1076 | //
|
|---|
| 1077 | void MHCamera::SavePrimitive(ofstream &out, Option_t *opt)
|
|---|
| 1078 | {
|
|---|
| 1079 | cout << "MHCamera::SavePrimitive: Must be rewritten!" << endl;
|
|---|
| 1080 | /*
|
|---|
| 1081 | if (!gROOT->ClassSaved(TCanvas::Class()))
|
|---|
| 1082 | fDrawingPad->SavePrimitive(out, opt);
|
|---|
| 1083 |
|
|---|
| 1084 | out << " " << fDrawingPad->GetName() << "->SetWindowSize(";
|
|---|
| 1085 | out << fDrawingPad->GetWw() << "," << fDrawingPad->GetWh() << ");" << endl;
|
|---|
| 1086 | */
|
|---|
| 1087 | }
|
|---|
| 1088 |
|
|---|
| 1089 | // ------------------------------------------------------------------------
|
|---|
| 1090 | //
|
|---|
| 1091 | // compute the distance of a point (px,py) to the Camera
|
|---|
| 1092 | // this functions needed for graphical primitives, that
|
|---|
| 1093 | // means without this function you are not able to interact
|
|---|
| 1094 | // with the graphical primitive with the mouse!!!
|
|---|
| 1095 | //
|
|---|
| 1096 | // All calcutations are done in pixel coordinates
|
|---|
| 1097 | //
|
|---|
| 1098 | Int_t MHCamera::DistancetoPrimitive(Int_t px, Int_t py)
|
|---|
| 1099 | {
|
|---|
| 1100 | if (fNcells<=1)
|
|---|
| 1101 | return 999999;
|
|---|
| 1102 |
|
|---|
| 1103 | const Int_t kMaxDiff = 7;
|
|---|
| 1104 |
|
|---|
| 1105 | TPaveStats *box = (TPaveStats*)gPad->GetPrimitive("stats");
|
|---|
| 1106 | if (box)
|
|---|
| 1107 | {
|
|---|
| 1108 | const Double_t w = box->GetY2NDC()-box->GetY1NDC();
|
|---|
| 1109 | box->SetX1NDC(gStyle->GetStatX()-gStyle->GetStatW());
|
|---|
| 1110 | box->SetY1NDC(gStyle->GetStatY()-w);
|
|---|
| 1111 | box->SetX2NDC(gStyle->GetStatX());
|
|---|
| 1112 | box->SetY2NDC(gStyle->GetStatY());
|
|---|
| 1113 | }
|
|---|
| 1114 |
|
|---|
| 1115 | if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
|
|---|
| 1116 | return TH1D::DistancetoPrimitive(px, py);
|
|---|
| 1117 |
|
|---|
| 1118 | for (Int_t i=0; i<fNcells-2; i++)
|
|---|
| 1119 | {
|
|---|
| 1120 | MHexagon hex((*fGeomCam)[i]);
|
|---|
| 1121 | if (hex.DistancetoPrimitive(px, py)==0)
|
|---|
| 1122 | return 0;
|
|---|
| 1123 | }
|
|---|
| 1124 |
|
|---|
| 1125 | if (!box)
|
|---|
| 1126 | return 999999;
|
|---|
| 1127 |
|
|---|
| 1128 | const Int_t dist = box->DistancetoPrimitive(px, py);
|
|---|
| 1129 | if (dist > kMaxDiff)
|
|---|
| 1130 | return 999999;
|
|---|
| 1131 |
|
|---|
| 1132 | gPad->SetSelected(box);
|
|---|
| 1133 | return dist;
|
|---|
| 1134 | }
|
|---|
| 1135 |
|
|---|
| 1136 | // ------------------------------------------------------------------------
|
|---|
| 1137 | //
|
|---|
| 1138 | // Function introduced (31-01-03) WILL BE REMOVED IN THE FUTURE! DON'T
|
|---|
| 1139 | // USE IT!
|
|---|
| 1140 | //
|
|---|
| 1141 | void MHCamera::SetPix(const Int_t idx, const Int_t color, Float_t min, Float_t max)
|
|---|
| 1142 | {
|
|---|
| 1143 | fArray[idx+1] = color;
|
|---|
| 1144 | SetUsed(idx);
|
|---|
| 1145 | }
|
|---|
| 1146 |
|
|---|
| 1147 | // ------------------------------------------------------------------------
|
|---|
| 1148 | //
|
|---|
| 1149 | //
|
|---|
| 1150 | Int_t MHCamera::GetPixelIndex(Int_t px, Int_t py) const
|
|---|
| 1151 | {
|
|---|
| 1152 | if (fNcells<=1)
|
|---|
| 1153 | return -1;
|
|---|
| 1154 |
|
|---|
| 1155 | Int_t i;
|
|---|
| 1156 | for (i=0; i<fNcells-2; i++)
|
|---|
| 1157 | {
|
|---|
| 1158 | MHexagon hex((*fGeomCam)[i]);
|
|---|
| 1159 | if (hex.DistancetoPrimitive(px, py)>0)
|
|---|
| 1160 | continue;
|
|---|
| 1161 |
|
|---|
| 1162 | return i;
|
|---|
| 1163 | }
|
|---|
| 1164 | return -1;
|
|---|
| 1165 | }
|
|---|
| 1166 |
|
|---|
| 1167 | // ------------------------------------------------------------------------
|
|---|
| 1168 | //
|
|---|
| 1169 | // Returns string containing info about the object at position (px,py).
|
|---|
| 1170 | // Returned string will be re-used (lock in MT environment).
|
|---|
| 1171 | //
|
|---|
| 1172 | char *MHCamera::GetObjectInfo(Int_t px, Int_t py) const
|
|---|
| 1173 | {
|
|---|
| 1174 | if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
|
|---|
| 1175 | return TH1D::GetObjectInfo(px, py);
|
|---|
| 1176 |
|
|---|
| 1177 | static char info[128];
|
|---|
| 1178 |
|
|---|
| 1179 | const Int_t idx=GetPixelIndex(px, py);
|
|---|
| 1180 |
|
|---|
| 1181 | if (idx<0)
|
|---|
| 1182 | return TObject::GetObjectInfo(px, py);
|
|---|
| 1183 |
|
|---|
| 1184 | sprintf(info, "Software Pixel Index: %d (Hardware Id=%d)", idx, idx+1);
|
|---|
| 1185 | return info;
|
|---|
| 1186 | }
|
|---|
| 1187 |
|
|---|
| 1188 | // ------------------------------------------------------------------------
|
|---|
| 1189 | //
|
|---|
| 1190 | // Execute a mouse event on the camera
|
|---|
| 1191 | //
|
|---|
| 1192 | void MHCamera::ExecuteEvent(Int_t event, Int_t px, Int_t py)
|
|---|
| 1193 | {
|
|---|
| 1194 | if (TString(GetDrawOption()).Contains("hist", TString::kIgnoreCase))
|
|---|
| 1195 | {
|
|---|
| 1196 | TH1D::ExecuteEvent(event, px, py);
|
|---|
| 1197 | return;
|
|---|
| 1198 | }
|
|---|
| 1199 | //if (event==kMouseMotion && fStatusBar)
|
|---|
| 1200 | // fStatusBar->SetText(GetObjectInfo(px, py), 0);
|
|---|
| 1201 | if (event!=kButton1Down)
|
|---|
| 1202 | return;
|
|---|
| 1203 |
|
|---|
| 1204 | const Int_t idx = GetPixelIndex(px, py);
|
|---|
| 1205 | if (idx<0)
|
|---|
| 1206 | return;
|
|---|
| 1207 |
|
|---|
| 1208 | cout << GetTitle() << " <" << GetName() << ">" << endl;
|
|---|
| 1209 | cout << "Software Pixel Index: " << idx << endl;
|
|---|
| 1210 | cout << "Hardware Pixel Id: " << idx+1 << endl;
|
|---|
| 1211 | cout << "Contents: " << GetBinContent(idx+1);
|
|---|
| 1212 | if (GetBinError(idx+1)>0)
|
|---|
| 1213 | cout << " +/- " << GetBinError(idx+1);
|
|---|
| 1214 | cout << " <" << (IsUsed(idx)?"on":"off") << ">" << endl;
|
|---|
| 1215 |
|
|---|
| 1216 | if (fNotify && fNotify->GetSize()>0)
|
|---|
| 1217 | {
|
|---|
| 1218 | // FIXME: Is there a simpler and more convinient way?
|
|---|
| 1219 |
|
|---|
| 1220 | // The name which is created here depends on the instance of
|
|---|
| 1221 | // MHCamera and on the pad on which it is drawn --> The name
|
|---|
| 1222 | // is unique. For ExecuteEvent gPad is always correctly set.
|
|---|
| 1223 | const TString name = Form("%p;%p;PixelContent", this, gPad);
|
|---|
| 1224 |
|
|---|
| 1225 | TCanvas *old = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(name);
|
|---|
| 1226 | if (old)
|
|---|
| 1227 | old->cd();
|
|---|
| 1228 | else
|
|---|
| 1229 | new TCanvas(name);
|
|---|
| 1230 |
|
|---|
| 1231 | /*
|
|---|
| 1232 | TIter Next(gPad->GetListOfPrimitives());
|
|---|
| 1233 | TObject *o;
|
|---|
| 1234 | while (o=Next()) cout << o << ": " << o->GetName() << " " << o->IsA()->GetName() << endl;
|
|---|
| 1235 | */
|
|---|
| 1236 |
|
|---|
| 1237 | // FIXME: Make sure, that the old histograms are really deleted.
|
|---|
| 1238 | // Are they already deleted?
|
|---|
| 1239 | fNotify->ForEach(MCamEvent, DrawPixelContent)(idx);
|
|---|
| 1240 | gPad->Modified();
|
|---|
| 1241 | gPad->Update();
|
|---|
| 1242 | }
|
|---|
| 1243 | }
|
|---|
| 1244 |
|
|---|
| 1245 | UInt_t MHCamera::GetNumPixels() const
|
|---|
| 1246 | {
|
|---|
| 1247 | return fGeomCam->GetNumPixels();
|
|---|
| 1248 | }
|
|---|
| 1249 |
|
|---|
| 1250 | TH1 *MHCamera::DrawCopy() const
|
|---|
| 1251 | {
|
|---|
| 1252 | gPad=NULL;
|
|---|
| 1253 | return TH1D::DrawCopy(fName+";cpy");
|
|---|
| 1254 | }
|
|---|