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

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