source: trunk/MagicSoft/Mars/mgui/MCamDisplay.cc@ 1600

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