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

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