source: trunk/MagicSoft/Mars/meventdisp/MGCamDisplay.cc@ 2500

Last change on this file since 2500 was 2467, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 10.2 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, 10/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25#include "MGCamDisplay.h"
26
27#include <TList.h> // TList::Add
28#include <TStyle.h> // gStyle->SetOptStat
29#include <TCanvas.h> // TCanvas::cd
30#include <TGButton.h> // TGPictureButton
31#include <TGButtonGroup.h> // TGVButtonGroup
32
33#include "MGTask.h" // MGTask::CreateGui
34#include "MClone.h" // MClone
35#include "MHillas.h" // MHillas
36#include "MParList.h" // MParList::AddToList
37#include "MEvtLoop.h" // MEvtLoop::GetParList
38#include "MTaskList.h" // MTaskList::AddToList
39#include "MHCamera.h" // MHCamera
40#include "MHillasCalc.h" // MHillasCalc
41#include "MHillasSrcCalc.h" // MHillasSrcCalc
42#include "MPedestalPix.h" // MPedestalPix
43#include "MPedestalCam.h" // MPedestalCam
44#include "MCerPhotEvt.h" // MCerPhotEvt::GetPixById
45#include "MCerPhotCalc.h" // MCerPhotCalc
46#include "MMcPedestalCopy.h" // MMcPedestalCopy
47#include "MMcPedestalNSBAdd.h" // MMcPedestalNSBAdd
48#include "MBlindPixelCalc.h" // MBlindPixelCalc
49#include "MImgCleanStd.h" // MImgCleanStd
50#include "MRawEvtData.h" // MRawEvtData
51
52ClassImp(MGCamDisplay);
53
54enum
55{
56 kRButRawEvt,
57 kRButCleanedEvt,
58 kCButHillas
59};
60
61// --------------------------------------------------------------------------
62//
63// Add Setup elements to GUI.
64//
65void MGCamDisplay::AddSetupElements()
66{
67 //
68 // Create gui elements for vertical frame
69 //
70 TGGroupFrame *grp = new TGGroupFrame(fTab1, "Display");
71 TGVButtonGroup *group = new TGVButtonGroup(grp);
72 fList->Add(group);
73
74 TGRadioButton *but1 = new TGRadioButton(group, "Raw Events", kRButRawEvt);
75 TGRadioButton *but2 = new TGRadioButton(group, "Cleaned Events", kRButCleanedEvt);
76 TGCheckButton *but3 = new TGCheckButton(grp, "Display Ellipse", kCButHillas);
77
78 but2->SetState(kButtonDown);
79 but3->SetState(kButtonDown);
80
81 fDisplayRaw = kFALSE;
82 fDisplayHillas = kTRUE;
83
84 /*
85 WARNING:
86 Bacause of some strage and hidden dependencies the
87 GetMainFrame call in the destructor of TGButton may fail if some
88 of the other gui elements are deleted first.
89 AddFirst adds the buttons at the beginning of the deletion list,
90 this seems to work.
91 */
92 fList->AddFirst(but1);
93 fList->AddFirst(but2);
94
95 but1->Associate(this);
96 but2->Associate(this);
97 but3->Associate(this);
98
99 TGLayoutHints *laybut = new TGLayoutHints(kLHintsNormal, 15, 0);
100 fList->Add(laybut);
101
102 grp->AddFrame(group);
103 grp->AddFrame(but3, laybut);
104
105 TGLayoutHints *laygrp1 = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 10, 10, 5, 0);
106 TGLayoutHints *laygrp2 = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 10, 10, 5, 5);
107
108 fTab1->AddFrame(grp, laygrp1);
109 ((MGTask*)GetTaskList()->FindObject("MImgCleanStd"))->CreateGui(fTab1, laygrp2);
110}
111
112// --------------------------------------------------------------------------
113//
114// Setup Task and parameter list for hillas calculation,
115// preprocess tasks and read in first event (process)
116//
117void MGCamDisplay::SetupTaskList()
118{
119 MTaskList *tlist = GetTaskList();
120 MParList *plist = GetParList();
121
122 MMcPedestalCopy *pcopy = new MMcPedestalCopy;
123 MMcPedestalNSBAdd *pdnsb = new MMcPedestalNSBAdd;
124 MCerPhotCalc *ncalc = new MCerPhotCalc;
125 MClone *clone = new MClone("MCerPhotEvt");
126 MImgCleanStd *clean = new MImgCleanStd;
127 MBlindPixelCalc *blind = new MBlindPixelCalc;
128 MHillasCalc *hcalc = new MHillasCalc;
129 MHillasSrcCalc *scalc = new MHillasSrcCalc;
130
131 tlist->AddToList(pcopy);
132 tlist->AddToList(pdnsb);
133 tlist->AddToList(ncalc);
134 tlist->AddToList(clone);
135 tlist->AddToList(clean);
136 tlist->AddToList(blind);
137 tlist->AddToList(hcalc);
138 tlist->AddToList(scalc);
139
140 MPedestalCam *pedest = new MPedestalCam;
141 MRawEvtData *event = new MRawEvtData;
142
143 // plist->AddToList(geom);
144 plist->AddToList(pedest);
145 plist->AddToList(event);
146
147 // return NULL;
148}
149
150// --------------------------------------------------------------------------
151//
152// Constructor.
153//
154MGCamDisplay::MGCamDisplay(const char *filename, const TGWindow *p,
155 UInt_t w, UInt_t h)
156: MGEvtDisplay(filename, "Events", p, w, h)
157{
158 //
159 // Setup Task list for hillas calculation
160 //
161 SetupTaskList();
162
163 //
164 // Add missing setup elements to GUI
165 //
166 AddSetupElements();
167
168 fCanvas2[0] = fCanvas;
169 fCanvas2[1] = AddTab("PedRMS");
170 fCanvas2[2] = AddTab("Phot/PedRMS");
171 fCanvas2[3] = AddTab("Levels");
172 fCanvas2[4] = AddTab("Pedestals");
173
174 //
175 // Show camera display for the actual geometry
176 //
177 gStyle->SetOptStat(1100);
178 for (int i=0; i<5; i++)
179 {
180 fCanvas2[i]->cd();
181 fDisplay[i] = new MHCamera;//(*geom);
182 fDisplay[i]->Draw();
183 fDisplay[i]->AddNotify(*(MCamEvent*)GetParList()->FindObject("MRawEvtData"));
184 fCanvas2[i]->Update();
185 fList->Add(fDisplay[i]);
186 }
187
188 fDisplay[0]->SetNameTitle("photons", "Number of Photons");
189 fDisplay[1]->SetNameTitle("pedrms", "Pedestal RMS");
190 fDisplay[2]->SetNameTitle("photpedrms", "Number of Photons / Pedestal RMS");
191 fDisplay[3]->SetNameTitle("levels", "Cleaning Levels");
192 fDisplay[4]->SetNameTitle("pedestals", "Pedestals");
193
194 fDisplay[0]->SetYTitle("S [au]");
195 fDisplay[1]->SetYTitle("P_{rms} [au]");
196 fDisplay[2]->SetYTitle("S/P_{rms}");
197 fDisplay[3]->SetYTitle("L");
198 fDisplay[4]->SetYTitle("P [au]");
199
200 ReadFirstEvent();
201
202 //
203 // Map the window, set up the layout, etc.
204 //
205 MapSubwindows();
206
207 Layout();
208
209 SetWindowName("Image Event Display");
210 SetIconName("Image");
211
212 MapWindow();
213}
214
215// --------------------------------------------------------------------------
216//
217// Update event display:
218// dependent on the setup either the uncleaned or cleand data is shown
219// together with the hillas ellipse or not.
220//
221void MGCamDisplay::UpdateDisplay()
222{
223 if (!IsInitOk())
224 return;
225
226 const MParList *plist = fEvtLoop->GetParList();
227
228 if (!fDisplay[0]->GetGeometry())
229 {
230 MGeomCam *cam = (MGeomCam*)plist->FindObject("MGeomCam");
231 for (int i=0; i<5; i++)
232 fDisplay[i]->SetGeometry(*cam);
233 }
234
235 //
236 // Show Hillas ellipse
237 //
238 MHillas *hillas = (MHillas*)plist->FindObject("MHillas");
239
240 hillas->Print();
241 plist->FindObject("MHillasExt")->Print();
242 plist->FindObject("MHillasSrc")->Print();
243 plist->FindObject("MNewImagePar")->Print();
244
245 //
246 // Display the requested event. This does a Canvas update, too.
247 //
248 MCerPhotEvt *evt = NULL;
249 if (fDisplayRaw)
250 {
251 // Get a clone of MCerPhotEvt which is made before the image cleaning
252 const MClone *clone = (MClone*)GetTaskList()->FindObject("MClone");
253 evt = (MCerPhotEvt*)clone->GetClone();
254 }
255 else
256 {
257 // Get MCerPhotEvt which containes the cleaned data
258 evt = (MCerPhotEvt*)plist->FindObject("MCerPhotEvt");
259 }
260
261 const MImgCleanStd *clean = (MImgCleanStd*)GetTaskList()->FindObject("MImgCleanStd");
262 const MPedestalCam *ped = (MPedestalCam*)plist->FindObject("MPedestalCam");
263
264 const Int_t n = ped->GetSize();
265
266 // FIXME: Make this publicly available
267 TArrayD val(n);
268 TArrayC use(n);
269 for (int i=0; i<n;i++)
270 {
271 // FIXME: photon event first!
272 MCerPhotPix *pix = evt->GetPixById(i);
273 if (!pix)
274 continue;
275 MPedestalPix &ppix = (*ped)[i];
276 if (ppix.GetPedestalRms()<=0)
277 continue;
278 val[i] = pix->GetNumPhotons()/ppix.GetPedestalRms();
279 use[i] = 1;
280 }
281
282 TArrayF lvl(2);
283 lvl[0] = clean->GetCleanLvl2();
284 lvl[1] = clean->GetCleanLvl1();
285
286 fDisplay[0]->SetCamContent(*evt, 0);
287 fDisplay[1]->SetCamContent(*ped, 1);
288 fDisplay[2]->SetCamContent(val, &use);
289 fDisplay[3]->SetCamContent(val, &use);
290 fDisplay[3]->SetLevels(lvl);
291 fDisplay[4]->SetCamContent(*ped, 0);
292
293 if (fDisplayHillas)
294 for (int i=0; i<5; i++)
295 {
296 fCanvas2[i]->cd();
297 hillas->Draw();
298 fCanvas2[i]->Modified();
299 fCanvas2[i]->Update();
300 }
301 else
302 {
303 for (int i=0; i<5; i++)
304 {
305 fCanvas2[i]->GetListOfPrimitives()->Remove(hillas);
306 fCanvas2[i]->Modified();
307 fCanvas2[i]->Update();
308 }
309 }
310}
311
312// --------------------------------------------------------------------------
313//
314// Process the messages from the setup GUI elements.
315//
316Bool_t MGCamDisplay::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
317{
318 switch(GET_MSG(msg))
319 {
320 case kC_COMMAND:
321 switch(GET_SUBMSG(msg))
322 {
323 case kCM_CHECKBUTTON:
324 switch (parm1)
325 {
326 case kCButHillas:
327 fDisplayHillas = !fDisplayHillas;
328 UpdateDisplay();
329 return kTRUE;
330 }
331 break;
332
333 case kCM_RADIOBUTTON:
334 switch (parm1)
335 {
336 case kRButRawEvt:
337 fDisplayRaw = kTRUE;
338 UpdateDisplay();
339 return kTRUE;
340
341 case kRButCleanedEvt:
342 fDisplayRaw = kFALSE;
343 UpdateDisplay();
344 return kTRUE;
345 }
346 break;
347 }
348 break;
349 }
350 return MGEvtDisplay::ProcessMessage(msg, parm1, parm2);
351}
352
Note: See TracBrowser for help on using the repository browser.