source: branches/Corsika7500Compatibility/mtools/MagicShow.cc@ 20114

Last change on this file since 20114 was 9369, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 8.3 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 07/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MagicShow
28// ---------
29//
30// Tool to visualize Next Neighbours.
31//
32// Start the show by:
33// MagicShow show;
34//
35// Use the following keys:
36// -----------------------
37//
38// * Space:
39// Toggle between auto increment and manual increment
40//
41// * Right/Left:
42// Increment/Decrement pixel number by 1
43//
44// * Right/Left:
45// Increment/Decrement pixel number by 1
46//
47// * Up/Down:
48// Increment/Decrement pixel number by 10
49//
50// * PageUp/PageDown:
51// Increment/Decrement pixel number by 100
52//
53// * Home/End:
54// Jump to first/last pixel
55//
56////////////////////////////////////////////////////////////////////////////
57#include "MagicShow.h"
58
59#include <iostream>
60
61#include <KeySymbols.h>
62
63#include <TCanvas.h>
64#include <TInterpreter.h>
65
66#include "MH.h"
67
68#include "MGeomPix.h"
69#include "MGeomCamCT1.h"
70#include "MGeomCamMagic.h"
71
72ClassImp(MagicShow);
73
74using namespace std;
75
76// ------------------------------------------------------------------------
77//
78// Free all onbects connected to a special camera geometry
79//
80void MagicShow::Free()
81{
82 if (!fGeomCam)
83 return;
84
85 delete fGeomCam;
86}
87
88// ------------------------------------------------------------------------
89//
90// Change camera from Magic to CT1 and back
91//
92void MagicShow::ChangeCamera()
93{
94 static Bool_t ct1=kFALSE;
95
96 cout << "Change to " << (ct1?"Magic":"CT1") << endl;
97
98 if (ct1)
99 SetNewCamera(new MGeomCamMagic);
100 else
101 SetNewCamera(new MGeomCamCT1);
102
103 ct1 = !ct1;
104
105 Update();
106
107 fColors.Reset();
108
109 // FIXME: Reset all texts
110
111 AppendPad();
112}
113
114// ------------------------------------------------------------------------
115//
116// Reset/set all veriables needed for a new camera geometry
117//
118void MagicShow::SetNewCamera(MGeomCam *geom)
119{
120 Free();
121
122 //
123 // Set new camera
124 //
125 fGeomCam = geom;
126
127 //
128 // create the hexagons of the display
129 //
130 fNumPixels = fGeomCam->GetNumPixels();
131 fRange = fGeomCam->GetMaxRadius();
132
133 fNumPixel = 0;//fNumPixels-1;
134
135 fColors.Set(fNumPixels);
136
137 for (int i=0; i<6; i++)
138 {
139 fText[i] = new TText(0, 0, "");
140 fText[i]->SetTextFont(122);
141 fText[i]->SetTextAlign(22); // centered/centered
142 }
143
144}
145
146void MagicShow::Init()
147{
148 //
149 // Make sure, that the object is destroyed when the canvas/pad is
150 // destroyed. Make also sure, that the interpreter doesn't try to
151 // delete it a second time.
152 //
153 SetBit(kCanDelete);
154 gInterpreter->DeleteGlobal(this);
155
156 Draw();
157
158 fTimer.TurnOn();
159}
160
161// ------------------------------------------------------------------------
162//
163// default constructor
164//
165MagicShow::MagicShow()
166 : fTimer(this, 250, kTRUE), fGeomCam(NULL), fNumPixel(-1), fAuto(kTRUE)
167{
168 SetNewCamera(new MGeomCamMagic);
169 Init();
170}
171
172// ------------------------------------------------------------------------
173//
174// default constructor
175//
176MagicShow::MagicShow(const MGeomCam &geom)
177 : fTimer(this, 250, kTRUE), fGeomCam(NULL), fNumPixel(-1), fAuto(kTRUE)
178{
179 SetNewCamera(static_cast<MGeomCam*>(geom.Clone()));
180 Init();
181}
182
183// ------------------------------------------------------------------------
184//
185// Destructor. Deletes TClonesArrays for hexagons and legend elements.
186//
187MagicShow::~MagicShow()
188{
189 Free();
190
191 for (int i=0; i<6; i++)
192 delete fText[i];
193}
194
195// ------------------------------------------------------------------------
196//
197// This is called at any time the canvas should get repainted.
198// Here we maintain an aspect ratio of 5/4=1.15. This makes sure,
199// that the camera image doesn't get distorted by resizing the canvas.
200//
201void MagicShow::Paint(Option_t *opt)
202{
203 const Float_t r = fGeomCam->GetMaxRadius();
204
205 MH::SetPadRange(-r, -r, r, r*1.1);
206
207 TAttLine line;
208 TAttFill fill;
209
210 // FIXME:
211 for (UInt_t i=0; i<fNumPixels; i++)
212 {
213 const MGeom &pix = (*fGeomCam)[i];
214
215 fill.SetFillColor(fColors[i]);
216 pix.PaintPrimitive(line, fill);
217 }
218
219 for (int i=0; i<6; i++)
220 fText[i]->Paint();
221}
222
223// ------------------------------------------------------------------------
224//
225// Call this function to draw the camera layout into your canvas.
226// Setup a drawing canvas. Add this object and all child objects
227// (hexagons, etc) to the current pad. If no pad exists a new one is
228// created.
229//
230void MagicShow::Draw(Option_t *option)
231{
232 //
233 // if no canvas is yet existing to draw into, create a new one
234 //
235 new TCanvas("MagicShow", "Magic Show Next Neighbours", 0, 0, 800, 800);
236
237 gPad->SetBorderMode(0);
238 gPad->SetFillColor(22);
239
240 //
241 // Append this object, so that the aspect ratio is maintained
242 // (Paint-function is called)
243 //
244 AppendPad(option);
245
246 fShow.SetTextAlign(23); // centered/bottom
247#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
248 fShow.SetBit(kNoContextMenu|kCannotPick);
249#endif
250 fShow.Draw();
251}
252
253// ------------------------------------------------------------------------
254//
255// Update Status text
256//
257void MagicShow::Update()
258{
259 TString txt = "Pixels: ";
260 txt += fNumPixels;
261 txt += " Pixel: ";
262 txt += fNumPixel;
263
264 if (fAuto)
265 txt += " (auto)";
266
267 fShow.SetText(0, fRange, txt);
268}
269
270// ------------------------------------------------------------------------
271//
272// Execute a mouse event on the camera
273//
274void MagicShow::ExecuteEvent(Int_t event, Int_t keycode, Int_t keysym)
275{
276 if (event!=kKeyPress)
277 return;
278
279 switch (keysym)
280 {
281 case kKey_Space:
282 fAuto = !fAuto;
283 Update();
284 gPad->Update();
285 return;
286
287 case kKey_Right:
288 ChangePixel(+1);
289 return;
290
291 case kKey_Left:
292 ChangePixel(-1);
293 return;
294
295 case kKey_Up:
296 ChangePixel(+10);
297 return;
298
299 case kKey_Down:
300 ChangePixel(-10);
301 return;
302
303 case kKey_PageUp:
304 ChangePixel(+100);
305 return;
306
307 case kKey_PageDown:
308 ChangePixel(-100);
309 return;
310
311 case kKey_Home:
312 ChangePixel(-fNumPixel);
313 return;
314
315 case kKey_End:
316 ChangePixel(fNumPixels-fNumPixel-1);
317 return;
318 }
319}
320
321// ------------------------------------------------------------------------
322//
323// Change the shown pixel by add indices
324//
325void MagicShow::ChangePixel(Int_t add)
326{
327 const MGeom &pix1=(*fGeomCam)[fNumPixel];
328
329 fColors[fNumPixel] = kBackground;
330 for (int i=0; i<pix1.GetNumNeighbors(); i++)
331 {
332 fColors[pix1.GetNeighbor(i)] = kBackground;
333 if (TString(fText[i]->GetTitle()).IsNull())
334 continue;
335
336 fText[i]->SetText(0, 0, "");
337 }
338
339 fNumPixel += add;
340
341 if (fNumPixel>=fNumPixels)
342 fNumPixel = 0;
343 if (fNumPixel<0)
344 fNumPixel = fNumPixels-1;
345
346 const MGeom &pix2=(*fGeomCam)[fNumPixel];
347
348 fColors[fNumPixel] = kBlue;
349
350 for (int i=0; i<pix2.GetNumNeighbors(); i++)
351 {
352 Int_t idx = pix2.GetNeighbor(i);
353
354 fColors[idx] = kMagenta;
355
356 TString num;
357 num += idx;
358
359 const MGeom &pix=(*fGeomCam)[idx];
360
361 fText[i]->SetText(pix.GetX(), pix.GetY(), num);
362 fText[i]->SetTextSize(0.3*pix.GetT()/fGeomCam->GetMaxRadius());
363 }
364
365 Update();
366
367 gPad->Update();
368}
369
370// ------------------------------------------------------------------------
371//
372// If automatic is switched on step one pixel forward
373//
374Bool_t MagicShow::HandleTimer(TTimer *timer)
375{
376 if (fAuto)
377 ChangePixel(+1);
378
379 return kTRUE;
380}
Note: See TracBrowser for help on using the repository browser.