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