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

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