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

Last change on this file since 603 was 602, checked in by harald, 24 years ago
neccessary changes after the transformation MNphotEvent --> MCerPhotEvt
File size: 5.0 KB
Line 
1#include "MCamDisplay.h"
2
3#include <math.h>
4#include <TClonesArray.h>
5#include <TCanvas.h>
6#include <TStyle.h>
7#include <TBox.h>
8#include <TText.h>
9
10#include "MHexagon.h"
11#include "MCamGeom.h"
12
13#include "MCerPhotEvt.h"
14
15
16ClassImp(MCamDisplay)
17
18MCamDisplay::MCamDisplay (Int_t type )
19{
20 // default constructor
21
22 // set the color palette
23
24 gStyle->SetPalette(1,0) ;
25
26 fAutoScale = kTRUE ;
27
28 MCamGeom *geometry = new MCamGeom( type ) ;
29
30 fNbPixels = geometry->GetNbPixels() ;
31 fPixels = new TClonesArray("MHexagon", fNbPixels ) ;
32
33 // create the hexagons of the display
34
35 TClonesArray &obj = *fPixels ;
36
37 for (Int_t i=0; i< fNbPixels; i++ )
38 {
39 new (obj[i]) MHexagon(geometry->GetX(i) ,
40 geometry->GetY(i) ,
41 geometry->GetR(i) ) ;
42 }
43
44 // set the range to default
45
46 fMinPhe = -2. ;
47 fMaxPhe = 50. ;
48
49 // set up the Legend
50
51 fLegend = new TClonesArray("TBox", ITEMS_LEGEND ) ;
52 TClonesArray &obj1 = *fLegend ;
53
54 fLegText = new TClonesArray("TText", ITEMS_LEGEND ) ;
55 TClonesArray &obj2 = *fLegText ;
56
57 char text[100] ;
58
59 Float_t help ;
60
61 help = 50. / ITEMS_LEGEND ;
62
63 for ( Int_t il = 0 ; il < ITEMS_LEGEND ; il++ )
64 {
65 new ( obj1[il] ) TBox(650, il*40-500 , 700, il*40-460 ) ;
66 ( (TBox*) fLegend->At(il))->SetFillColor( GetColor ( (Float_t) help*il) ) ;
67
68 sprintf ( text, "%5.1f", (Float_t) help * il ) ;
69 new ( obj2[il] ) TText(720, il*40-480, text ) ;
70 ( (TText*) fLegText->At(il))->SetTextSize (0.025) ;
71 ( (TText*) fLegText->At(il))->SetTextAlign(12) ;
72 }
73}
74
75MCamDisplay::~MCamDisplay()
76{
77 delete fPixels ;
78}
79
80
81void MCamDisplay::Init()
82{
83
84 // Set the right colors
85
86 gStyle->SetPalette(1, 0) ;
87
88 if ( ! gPad ) new TCanvas("display", "MAGIC display", 0, 0, 650, 500) ;
89
90 for (Int_t i=0; i< fNbPixels; i++)
91 {
92 ( (MHexagon*) fPixels->At(i))->Draw() ;
93 }
94
95 for (Int_t i=0; i< ITEMS_LEGEND; i++)
96 {
97
98 ( (TBox*) fLegend->At(i))->Draw() ;
99
100 ( (TText*) fLegText->At(i))->Draw() ;
101 }
102
103}
104
105
106void MCamDisplay::Draw(Option_t *option )
107{
108 //
109
110 // check if there a pad exists
111
112 if ( ! gPad ) Init() ;
113
114 gPad->Range (-600, -600, 900, 600) ;
115 gPad->SetFillColor(22) ;
116
117 //
118
119 gPad->Modified() ;
120 gPad->Update() ;
121
122 //gPad->Update() ;
123}
124
125void MCamDisplay::Draw( MCerPhotEvt *event)
126{
127
128 // loop over all pixels in the MCerPhotEvt and
129 // determine the Pixel Id and the content
130
131 Reset() ;
132
133 // if the autoscale is true, set the values for the range for
134 // each event
135
136 if ( fAutoScale == kTRUE )
137 {
138 fMinPhe = event->GetMinimumPhoton() ;
139 fMaxPhe = event->GetMaximumPhoton() ;
140
141 if ( fMaxPhe < 20. ) fMaxPhe = 20. ;
142
143
144 UpdateLegend() ;
145 }
146
147 // update the picture
148
149 for (Int_t i=0 ; i<event->GetNbPixels() ; i++ )
150 {
151 if ( event->IsPixelUsed(i) == kTRUE )
152 ( (MHexagon*) fPixels->At( event->GetPixelId(i) ))->SetFillColor( GetColor(event->GetPhotons(i))) ;
153
154 }
155
156 Draw() ;
157
158}
159
160void MCamDisplay::DrawError( MCerPhotEvt *event)
161{
162 //
163
164 // loop over all pixels in the MCerPhotEvt and
165 // determine the Pixel Id and the content
166 Reset() ;
167
168 for (Int_t i=0 ; i<event->GetNbPixels() ; i++ )
169 {
170 ( (MHexagon*) fPixels->At( event->GetPixelId(i) ))->SetFillColor( GetColor(event->GetErrorPhot(i)) ) ;
171 }
172
173 Draw() ;
174
175}
176
177
178void MCamDisplay::Reset()
179{
180 for ( Int_t i=0 ; i< fNbPixels ; i++ )
181 {
182 ( (MHexagon*) fPixels->At(i))->SetFillColor(10) ;
183 }
184
185}
186
187Int_t MCamDisplay::GetColor(Float_t wert )
188{
189 // Here we calculate the color index for the current value.
190 // The color index is defined with the class TStyle and the
191 // Color palette inside. We use the command gStyle->SetPalette(1,0)
192 // for the display. So we have to convert the value "wert" into
193 // a color index that fits the color palette.
194 // The range of the color palette is defined by the values fMinPhe
195 // and fMaxRange. Between this values we have 50 color index, starting
196 // with 0 up to 49.
197 //
198
199 // first treat the over- and under-flows
200
201 if ( wert >= fMaxPhe )
202 return gStyle->GetColorPalette( 49 ) ;
203
204 if ( wert <= fMinPhe )
205 return gStyle->GetColorPalette( 0 ) ;
206
207 // calculate the color index
208
209 Int_t ColIndex ;
210
211 ColIndex = (Int_t) wert ;
212
213 ColIndex = (Int_t) ( .5 + ( (wert-fMinPhe) * 49. / (fMaxPhe-fMinPhe) ) ) ;
214
215 return (gStyle->GetColorPalette(ColIndex) ) ;
216
217}
218
219
220void MCamDisplay::UpdateLegend()
221{
222 // change the text on the legend according to the range of the
223 // Display
224
225 char text[100] ;
226
227 Float_t x, y, wert, help ;
228
229 help = 50./ITEMS_LEGEND ;
230
231 for (Int_t il=0; il < ITEMS_LEGEND; il++)
232 {
233 wert = fMinPhe + (il*help)/50 * (fMaxPhe-fMinPhe) ;
234
235 sprintf ( text, "%5.1f", wert ) ;
236
237 x = ( (TText*) fLegText->At(il))->GetX () ;
238 y = ( (TText*) fLegText->At(il))->GetY () ;
239 ( (TText*) fLegText->At(il))->SetText (x, y, text ) ;
240 }
241
242}
Note: See TracBrowser for help on using the repository browser.