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

Last change on this file since 972 was 961, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 5.7 KB
Line 
1#include "MCamDisplay.h"
2
3#include <math.h>
4
5#include <TClonesArray.h>
6#include <TCanvas.h>
7#include <TStyle.h>
8#include <TBox.h>
9#include <TText.h>
10
11#include "MHexagon.h"
12#include "MGeomCam.h"
13
14#include "MCerPhotEvt.h"
15
16#define kITEMS_LEGEND 25
17
18ClassImp(MCamDisplay);
19
20// ------------------------------------------------------------------------
21//
22// default constructor
23//
24MCamDisplay::MCamDisplay(MGeomCam *geom) : fAutoScale(kTRUE)
25{
26 //
27 // set the color palette
28 //
29 gStyle->SetPalette(1, 0);
30
31 //
32 // create the hexagons of the display
33 //
34 fNumPixels = geom->GetNumPixels();
35 fPixels = new TClonesArray("MHexagon", fNumPixels);
36
37 for (UInt_t i=0; i<fNumPixels; i++)
38 (*fPixels)[i] = new MHexagon((*geom)[i]);
39
40 //
41 // set the range to default
42 //
43 fMinPhe = -2.;
44 fMaxPhe = 50.;
45
46 //
47 // set up the Legend
48 //
49 fLegend = new TClonesArray("TBox", kITEMS_LEGEND);
50 fLegText = new TClonesArray("TText", kITEMS_LEGEND);
51
52 char text[10];
53 for (Int_t il = 0; il<kITEMS_LEGEND; il++)
54 {
55 const Int_t y = il*40;
56
57 TBox *newbox = new TBox (650, y-500, 700, y-460);
58 TText *newtxt = new TText(720, y-480, text);
59
60 const Float_t lvl = 50. / kITEMS_LEGEND * il;
61
62 newbox->SetFillColor(GetColor(lvl));
63
64 sprintf(text, "%5.1f", lvl);
65
66 newtxt->SetTextSize(0.025);
67 newtxt->SetTextAlign(12);
68
69 (*fLegend) [il] = newbox;
70 (*fLegText)[il] = newtxt;
71 }
72}
73
74// ------------------------------------------------------------------------
75//
76//
77MCamDisplay::~MCamDisplay()
78{
79 delete fPixels;
80}
81
82// ------------------------------------------------------------------------
83//
84//
85void MCamDisplay::Draw(Option_t *option)
86{
87 //
88 // if no canvas is yet existing to draw into, create a new one
89 //
90 if (!gPad)
91 fDrawingPad = new TCanvas("CamDisplay", "Magic Camera Display", 0, 0, 650, 500);
92 else
93 {
94 gPad->Clear();
95 fDrawingPad = gPad;
96 }
97
98 //
99 // Setup the correct environment
100 //
101 gStyle->SetPalette(1, 0);
102
103 gPad->Range(-600, -600, 900, 600);
104 gPad->SetFillColor(22);
105
106 //
107 // Draw all pixels of the camera
108 // (means apend all pixelobjects to the current pad)
109 //
110 for (UInt_t i=0; i<fNumPixels; i++)
111 (*this)[i].Draw();
112
113 //
114 // draw legend
115 //
116 for (Int_t i=0; i<kITEMS_LEGEND; i++)
117 {
118 GetBox(i)->Draw();
119 GetText(i)->Draw();
120 }
121}
122
123// ------------------------------------------------------------------------
124//
125//
126void MCamDisplay::DrawPhotNum(const MCerPhotEvt *event)
127{
128 fDrawingPad->cd();
129
130 //
131 // loop over all pixels in the MCerPhotEvt and
132 // determine the Pixel Id and the content
133 //
134 Reset();
135
136 //
137 // if the autoscale is true, set the values for the range for
138 // each event
139 //
140 if (fAutoScale)
141 {
142 fMinPhe = event->GetNumPhotonsMin();
143 fMaxPhe = event->GetNumPhotonsMax();
144
145 if (fMaxPhe < 20.)
146 fMaxPhe = 20.;
147
148 UpdateLegend();
149 }
150
151 //
152 // update the colors in the picture
153 //
154 const Int_t entries = event->GetNumPixels();
155
156 for (Int_t i=0; i<entries; i++)
157 {
158 MCerPhotPix &pix = (*event)[i];
159
160 if (!pix.IsPixelUsed())
161 continue;
162
163 SetPixColor(pix);
164 }
165
166 //
167 // Update display physically
168 //
169 gPad->Modified();
170 gPad->Update();
171}
172
173// ------------------------------------------------------------------------
174//
175//
176void MCamDisplay::DrawPhotErr(const MCerPhotEvt *event)
177{
178 fDrawingPad->cd();
179
180 //
181 // reset the all pixel colors to a default value
182 //
183 Reset();
184
185 //
186 // loop over all pixels in the MCerPhotEvt and
187 // determine the Pixel Id and the content
188 //
189 const Int_t entries = event->GetNumPixels();
190
191 for (Int_t i=0 ; i<entries; i++)
192 {
193 MCerPhotPix &pix = (*event)[i];
194
195 SetPixColor(pix);
196 }
197
198 //
199 // Update display physically
200 //
201 gPad->Modified();
202 gPad->Update();
203}
204
205
206// ------------------------------------------------------------------------
207//
208// reset the all pixel colors to a default value
209//
210void MCamDisplay::Reset()
211{
212 for (UInt_t i=0; i<fNumPixels; i++)
213 (*this)[i].SetFillColor(10);
214}
215
216// ------------------------------------------------------------------------
217//
218// Here we calculate the color index for the current value.
219// The color index is defined with the class TStyle and the
220// Color palette inside. We use the command gStyle->SetPalette(1,0)
221// for the display. So we have to convert the value "wert" into
222// a color index that fits the color palette.
223// The range of the color palette is defined by the values fMinPhe
224// and fMaxRange. Between this values we have 50 color index, starting
225// with 0 up to 49.
226//
227Int_t MCamDisplay::GetColor(Float_t val)
228{
229 //
230 // first treat the over- and under-flows
231 //
232 const Float_t maxcolidx = 49.0;
233
234 if (val >= fMaxPhe)
235 return gStyle->GetColorPalette(maxcolidx);
236
237 if (val <= fMinPhe)
238 return gStyle->GetColorPalette(0);
239
240 //
241 // calculate the color index
242 //
243 const Float_t ratio = (val-fMinPhe) / (fMaxPhe-fMinPhe);
244 const Int_t colidx = (Int_t)(maxcolidx*ratio + .5);
245
246 return gStyle->GetColorPalette(colidx);
247}
248
249// ------------------------------------------------------------------------
250//
251// change the text on the legend according to the range of the
252// Display
253//
254void MCamDisplay::UpdateLegend()
255{
256 char text[10];
257
258 for (Int_t il=0; il < kITEMS_LEGEND; il++)
259 {
260 const Float_t val = fMinPhe + (Float_t)il/kITEMS_LEGEND * (fMaxPhe-fMinPhe) ;
261
262 sprintf(text, "%5.1f", val);
263
264 TText &txt = *GetText(il);
265
266 txt.SetText(txt.GetX(), txt.GetY(), text);
267 }
268}
Note: See TracBrowser for help on using the repository browser.