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