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

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