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

Last change on this file since 1904 was 1904, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 23.3 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 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
183inline 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
197inline 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
211inline 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
220inline 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//
243void 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//
298void 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
389void MCamDisplay::SetPrettyPalette()
390{
391 SetPalette(1, 0);
392}
393
394void MCamDisplay::SetDeepBlueSeaPalette()
395{
396 SetPalette(51, 0);
397}
398
399void 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//
411void 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
523void MCamDisplay::SetPrettyPalette()
524{
525 SetPalette(1, 0);
526}
527
528void MCamDisplay::SetDeepBlueSeaPalette()
529{
530 SetPalette(51, 0);
531}
532
533void MCamDisplay::SetInvDeepBlueSeaPalette()
534{
535 SetPalette(52, 0);
536}
537
538void MCamDisplay::DrawPixelNumbers()
539{
540 if (!fDrawingPad)
541 Draw();
542
543 fDrawingPad->cd();
544
545 TText txt;
546 txt.SetTextFont(122);
547 txt.SetTextAlign(22); // centered/centered
548
549 for (UInt_t i=0; i<fNumPixels; i++)
550 {
551 TString num;
552 num += i;
553
554 const MHexagon &h = (*this)[i];
555 TText *nt = txt.DrawText(h.GetX(), h.GetY(), num);
556 nt->SetTextSize(0.3*h.GetD()/fGeomCam->GetMaxRadius());
557 }
558}
559
560// ------------------------------------------------------------------------
561//
562// Call this function to draw the number of photo electron into the
563// camera.
564//
565void MCamDisplay::DrawPhotNum(const MCerPhotEvt *event)
566{
567 if (!event)
568 return;
569
570 Draw();
571
572 fDrawingPad->cd();
573
574 for (int i=0; i<kItemsLegend; i++)
575 GetBox(i)->SetFillColor(fColors[i]);
576
577 //
578 // Reset pixel colors to default value
579 //
580 Reset();
581
582 //
583 // if the autoscale is true, set the values for the range for
584 // each event
585 //
586 Float_t min = 0;
587 Float_t max = 50;
588 if (fAutoScale)
589 {
590 min = event->GetNumPhotonsMin(fGeomCam);
591 max = event->GetNumPhotonsMax(fGeomCam);
592
593 if (max < 20.)
594 max = 20.;
595
596 UpdateLegend(min, max);
597 }
598
599 //
600 // update the colors in the picture
601 //
602 const Int_t entries = event->GetNumPixels();
603
604 for (Int_t i=0; i<entries; i++)
605 {
606 const MCerPhotPix &pix = (*event)[i];
607
608 if (!pix.IsPixelUsed())
609 continue;
610
611 SetPixColor(pix, i, min, max);
612 }
613
614 //
615 // Update display physically
616 //
617 fDrawingPad->Modified();
618 fDrawingPad->Update();
619}
620
621// ------------------------------------------------------------------------
622//
623// Call this function to draw the number of photo electron into the
624// camera.
625//
626void MCamDisplay::DrawPedestals(const MPedestalCam *event)
627{
628 if (!event)
629 return;
630
631 Draw();
632
633 fDrawingPad->cd();
634
635 for (int i=0; i<kItemsLegend; i++)
636 GetBox(i)->SetFillColor(fColors[i]);
637
638 //
639 // Reset pixel colors to default value
640 //
641 Reset();
642
643 //
644 // if the autoscale is true, set the values for the range for
645 // each event
646 //
647 Float_t min = 0;
648 Float_t max = 50;
649 if (fAutoScale)
650 {
651 min = event->GetMeanMin(fGeomCam);
652 max = event->GetMeanMax(fGeomCam);
653
654 if (max < 20.)
655 max = 20.;
656
657 UpdateLegend(min, max);
658 }
659
660 //
661 // update the colors in the picture
662 //
663 const Int_t entries = event->GetSize();
664
665 for (Int_t i=0; i<entries; i++)
666 SetPixColorPedestal((*event)[i], i, min, max);
667
668 //
669 // Update display physically
670 //
671 fDrawingPad->Modified();
672 fDrawingPad->Update();
673}
674
675// ------------------------------------------------------------------------
676//
677// Call this function to draw the error of number of photo electron
678// into the camera.
679//
680void MCamDisplay::DrawErrorPhot(const MCerPhotEvt *event)
681{
682 if (!event)
683 return;
684
685 if (!fDrawingPad)
686 Draw();
687
688 fDrawingPad->cd();
689
690 for (int i=0; i<kItemsLegend; i++)
691 GetBox(i)->SetFillColor(fColors[i]);
692
693 //
694 // Reset pixel colors to default value
695 //
696 Reset();
697
698 //
699 // if the autoscale is true, set the values for the range for
700 // each event
701 //
702 Float_t min = 0;
703 Float_t max = 50;
704 if (fAutoScale)
705 {
706 min = event->GetErrorPhotMin(fGeomCam);
707 max = event->GetErrorPhotMax(fGeomCam);
708
709 if (max < 20.)
710 max = 20.;
711
712 UpdateLegend(min, max);
713 }
714
715 //
716 // update the colors in the picture
717 //
718 const Int_t entries = event->GetNumPixels();
719
720 for (Int_t i=0; i<entries; i++)
721 {
722 const MCerPhotPix &pix = (*event)[i];
723
724 if (!pix.IsPixelUsed())
725 continue;
726
727 SetPixColorError(pix, i, min, max);
728 }
729
730 //
731 // Update display physically
732 //
733 fDrawingPad->Modified();
734 fDrawingPad->Update();
735}
736
737// ------------------------------------------------------------------------
738//
739// Call this function to draw the ratio of the number of photons
740// divided by its error
741//
742void MCamDisplay::DrawRatio(const MCerPhotEvt *event)
743{
744 if (!event)
745 return;
746
747 if (!fDrawingPad)
748 Draw();
749
750 fDrawingPad->cd();
751
752 for (int i=0; i<kItemsLegend; i++)
753 GetBox(i)->SetFillColor(fColors[i]);
754
755 //
756 // Reset pixel colors to default value
757 //
758 Reset();
759
760 //
761 // if the autoscale is true, set the values for the range for
762 // each event
763 //
764 Float_t min = 0;
765 Float_t max = 20;
766 if (fAutoScale)
767 {
768 min = event->GetRatioMin();
769 max = event->GetRatioMax();
770
771 UpdateLegend(min, max);
772 }
773
774 //
775 // update the colors in the picture
776 //
777 const Int_t entries = event->GetNumPixels();
778
779 for (Int_t i=0; i<entries; i++)
780 {
781 const MCerPhotPix &pix = (*event)[i];
782
783 if (!pix.IsPixelUsed())
784 continue;
785
786 SetPixColorRatio(pix, min, max);
787 }
788
789 //
790 // Update display physically
791 //
792 fDrawingPad->Modified();
793 fDrawingPad->Update();
794}
795
796// ------------------------------------------------------------------------
797//
798// Draw the colors in respect to the cleaning levels
799//
800void MCamDisplay::DrawLevels(const MCerPhotEvt *event, Float_t lvl1, Float_t lvl2)
801{
802 if (!event)
803 return;
804
805 if (!fDrawingPad)
806 Draw();
807
808 fDrawingPad->cd();
809
810 for (int i=0; i<kItemsLegend; i++)
811 GetBox(i)->SetFillColor(fColors[i]);
812
813 //
814 // Reset pixel colors to default value
815 //
816 Reset();
817
818 //
819 // update the colors in the picture
820 //
821 const Int_t entries = event->GetNumPixels();
822
823 for (Int_t i=0; i<entries; i++)
824 {
825 const MCerPhotPix &pix = (*event)[i];
826
827 if (!pix.IsPixelUsed())
828 continue;
829
830 SetPixColorLevel(pix, lvl1, lvl2);
831 }
832
833 //
834 // Update display physically
835 //
836 fDrawingPad->Modified();
837 fDrawingPad->Update();
838}
839
840// ------------------------------------------------------------------------
841//
842// Draw the colors in respect to the cleaning levels
843//
844void MCamDisplay::DrawLevels(const MCerPhotEvt *event, const MImgCleanStd &clean)
845{
846 DrawLevels(event, clean.GetCleanLvl1(), clean.GetCleanLvl2());
847}
848
849// ------------------------------------------------------------------------
850//
851// reset the all pixel colors to a default value
852//
853void MCamDisplay::Reset()
854{
855 for (UInt_t i=0; i<fNumPixels; i++)
856 (*this)[i].SetFillColor(10);
857}
858
859// ------------------------------------------------------------------------
860//
861// Here we calculate the color index for the current value.
862// The color index is defined with the class TStyle and the
863// Color palette inside. We use the command gStyle->SetPalette(1,0)
864// for the display. So we have to convert the value "wert" into
865// a color index that fits the color palette.
866// The range of the color palette is defined by the values fMinPhe
867// and fMaxRange. Between this values we have 50 color index, starting
868// with 0 up to 49.
869//
870Int_t MCamDisplay::GetColor(Float_t val, Float_t min, Float_t max)
871{
872 //
873 // first treat the over- and under-flows
874 //
875 const Int_t maxcolidx = kItemsLegend-1;
876
877 if (val >= max)
878 return fColors[maxcolidx];
879
880 if (val <= min)
881 return fColors[0];
882
883 //
884 // calculate the color index
885 //
886 const Float_t ratio = (val-min) / (max-min);
887 const Int_t colidx = (Int_t)(ratio*maxcolidx + .5);
888
889 return fColors[colidx];
890}
891
892// ------------------------------------------------------------------------
893//
894// change the text on the legend according to the range of the
895// Display
896//
897void MCamDisplay::UpdateLegend(Float_t minphe, Float_t maxphe)
898{
899 char text[10];
900
901 for (Int_t i=0; i<kItemsLegend; i+=3)
902 {
903 const Float_t val = minphe + (Float_t)i/kItemsLegend * (maxphe-minphe) ;
904
905 sprintf(text, "%5.1f", val);
906
907 TText &txt = *GetText(i);
908
909 txt.SetText(txt.GetX(), txt.GetY(), text);
910 }
911}
912
913// ------------------------------------------------------------------------
914//
915// Save primitive as a C++ statement(s) on output stream out
916//
917void MCamDisplay::SavePrimitive(ofstream &out, Option_t *opt)
918{
919 if (!gROOT->ClassSaved(TCanvas::Class()))
920 fDrawingPad->SavePrimitive(out, opt);
921
922 out << " " << fDrawingPad->GetName() << "->SetWindowSize(";
923 out << fDrawingPad->GetWw() << "," << fDrawingPad->GetWh() << ");" << endl;
924}
925
926// ------------------------------------------------------------------------
927//
928// compute the distance of a point (px,py) to the Camera
929// this functions needed for graphical primitives, that
930// means without this function you are not able to interact
931// with the graphical primitive with the mouse!!!
932//
933// All calcutations are running in pixel coordinates
934//
935Int_t MCamDisplay::DistancetoPrimitive(Int_t px, Int_t py)
936{
937 Int_t dist = 999999;
938
939 for (UInt_t i=0; i<fNumPixels; i++)
940 {
941 Int_t d = (*fPixels)[i]->DistancetoPrimitive(px, py);
942
943 if (d<dist)
944 dist=d;
945 }
946 return dist==0?0:999999;
947}
948
949// ------------------------------------------------------------------------
950//
951// Execute a mouse event on the camera
952//
953/*
954 void MCamDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
955 {
956 cout << "Execute Event Camera " << event << " @ " << px << " " << py << endl;
957 }
958 */
959
960
961// ------------------------------------------------------------------------
962//
963// Function introduced (31-01-03)
964//
965void MCamDisplay::SetPix(const Int_t pixnum, const Int_t color, Float_t min, Float_t max)
966{
967 (*this)[pixnum].SetFillColor(GetColor(color, min, max));
968
969}
Note: See TracBrowser for help on using the repository browser.