source: trunk/MagicSoft/Mars/mmain/MOnlineDisplay.cc@ 2576

Last change on this file since 2576 was 2564, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 14.9 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, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24#include "MOnlineDisplay.h"
25
26//
27// C-lib
28//
29#include <stdlib.h> // atoi
30
31//
32// root
33//
34#include <TList.h> // TList::Add
35#include <TStyle.h> // gStyle->SetOptStat
36#include <TCanvas.h> // TCanvas::cd
37
38//
39// root GUI
40//
41#include <TGLabel.h> // TGLabel
42#include <TGButton.h> // TGPictureButton
43#include <TGSlider.h> // TGSlider
44#include <TG3DLine.h> // TGHorizontal3DLine
45#include <TGTextEntry.h> // TGTextEntry
46#include <TGButtonGroup.h> // TGVButtonGroup
47#include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
48
49//
50// General
51//
52#include "MGList.h" // MGList
53
54#include "MParList.h" // MParList::AddToList
55#include "MEvtLoop.h" // MEvtLoop::GetParList
56#include "MTaskList.h" // MTaskList::AddToList
57
58//
59// Tasks
60//
61#include "MReadMarsFile.h" // MReadMarsFile
62#include "MGeomApply.h" // MGeomApply
63#include "MFDataMember.h" // MFDataMember
64#include "MMcPedestalCopy.h" // MMcPedestalCopy
65#include "MMcPedestalNSBAdd.h" // MMcPedestalNSBAdd
66#include "MCerPhotCalc.h" // MCerPhotCalc
67#include "MCerPhotAnal2.h" // MCerPhotAnal2
68#include "MImgCleanStd.h" // MImgCleanStd
69#include "MHillasCalc.h" // MHillasCalc
70#include "MHillasSrcCalc.h" // MHillasSrcCalc
71#include "MBlindPixelCalc.h" // MBlindPixelCalc
72#include "MFillH.h" // MFillH
73#include "MGTask.h" // MGTask
74
75//
76// Container
77//
78#include "MHEvent.h" // MHEvent
79#include "MHCamera.h" // MHCamera
80#include "MRawEvtData.h" // MRawEvtData
81
82ClassImp(MOnlineDisplay);
83
84// --------------------------------------------------------------------------
85//
86// Constructor.
87//
88MOnlineDisplay::MOnlineDisplay() : MStatusDisplay(), fTask(0)
89{
90 //
91 // Setup Task list for hillas calculation
92 //
93 //SetupTaskList("Events", filename);
94
95 //
96 // Add MOnlineDisplay GUI elements to the display
97 //
98 AddUserFrame("");
99
100 //
101 // Show new part of the window, resize to correct aspect ratio
102 //
103 // FIXME: This should be done by MStatusDisplay automatically
104 Resize(GetWidth(), GetHeight() + fUserFrame->GetDefaultHeight());
105 //SetWindowName("Online Display");
106 MapSubwindows();
107 //MapWindow();
108
109 //
110 // Readin foirst event and display it
111 //
112 //ReadFirstEvent();
113}
114
115// --------------------------------------------------------------------------
116//
117// Destructor: PostProcess eventloop, delete eventloop with all containers
118//
119MOnlineDisplay::~MOnlineDisplay()
120{
121 //fEvtLoop->PostProcess();
122 //delete fEvtLoop;
123}
124
125// --------------------------------------------------------------------------
126//
127// Return reading task
128//
129/*
130MReadTree *MOnlineDisplay::GetReader() const
131{
132 MParList *plist = (MParList*)fEvtLoop->GetParList();
133 MTaskList *tlist = (MTaskList*)plist->FindObject("MTaskList");
134 MReadTree *reader = (MReadTree*)tlist->FindObject("MRead");
135 return reader;
136}
137
138// --------------------------------------------------------------------------
139//
140// Setup Task and parameter list for hillas calculation,
141// preprocess tasks and read in first event (process)
142//
143void MOnlineDisplay::SetupTaskList(const char *tname, const char *fname)
144{
145 //
146 // Setup an empty job, with a reader task only.
147 // All tasks and parameter containers are deleted automatically
148 // (via SetOwner())
149 //
150 MTaskList *tlist = new MTaskList;
151 tlist->SetOwner();
152
153 MReadMarsFile *read = new MReadMarsFile(tname, fname);
154 read->DisableAutoScheme();
155 tlist->AddToList(read);
156
157 MGeomApply *apl = new MGeomApply;
158 tlist->AddToList(apl);
159
160 MParList *plist = new MParList;
161 plist->SetOwner();
162 plist->AddToList(tlist);
163
164 fEvtLoop = new MEvtLoop;
165 fEvtLoop->SetOwner();
166 fEvtLoop->SetParList(plist);
167
168 MHEvent *evt1 = new MHEvent(MHEvent::kEvtSignal);
169 MHEvent *evt2 = new MHEvent(MHEvent::kEvtSignal);
170 MHEvent *evt3 = new MHEvent(MHEvent::kEvtPedestal);
171 MHEvent *evt4 = new MHEvent(MHEvent::kEvtPedestalRMS);
172 MHEvent *evt5 = new MHEvent(MHEvent::kEvtRelativeSignal);
173 MHEvent *evt6 = new MHEvent(MHEvent::kEvtCleaningLevels);
174 evt1->SetName("Signal");
175 evt2->SetName("Cleaned");
176 evt3->SetName("Pedestal");
177 evt4->SetName("PedRMS");
178 evt5->SetName("Signal/PedRMS");
179 evt6->SetName("CleanLevels");
180 plist->AddToList(evt1);
181 plist->AddToList(evt2);
182 plist->AddToList(evt3);
183 plist->AddToList(evt4);
184 plist->AddToList(evt5);
185 plist->AddToList(evt6);
186
187 MMcPedestalCopy *pcopy = new MMcPedestalCopy;
188 MMcPedestalNSBAdd *pdnsb = new MMcPedestalNSBAdd;
189 MCerPhotCalc *ncalc = new MCerPhotCalc;
190 MCerPhotAnal2 *nanal = new MCerPhotAnal2;
191 MFillH *fill1 = new MFillH(evt1, "MCerPhotEvt", "MFillH1");
192 MImgCleanStd *clean = new MImgCleanStd;
193 MFillH *fill2 = new MFillH(evt2, "MCerPhotEvt", "MFillH2");
194 MFillH *fill3 = new MFillH(evt3, "MPedestalCam", "MFillH3");
195 MFillH *fill4 = new MFillH(evt4, "MPedestalCam", "MFillH4");
196 MFillH *fill5 = new MFillH(evt5, "MCameraData", "MFillH5");
197 MFillH *fill6 = new MFillH(evt6, "MCameraData", "MFillH6");
198 MBlindPixelCalc *blind = new MBlindPixelCalc;
199 MHillasCalc *hcalc = new MHillasCalc;
200 MHillasSrcCalc *scalc = new MHillasSrcCalc;
201
202 MFilter *f1=new MFDataMember("MRawRunHeader.fRunType", '>', 255.5);
203 MFilter *f2=new MFDataMember("MRawRunHeader.fRunType", '<', 255.5);
204
205 ncalc->SetFilter(f1);
206 nanal->SetFilter(f2);
207
208 tlist->AddToList(f1);
209 tlist->AddToList(f2);
210 tlist->AddToList(pcopy);
211 tlist->AddToList(pdnsb);
212 tlist->AddToList(ncalc);
213 tlist->AddToList(nanal);
214 tlist->AddToList(fill1);
215 tlist->AddToList(clean);
216 tlist->AddToList(fill2);
217 tlist->AddToList(fill3);
218 tlist->AddToList(fill4);
219 tlist->AddToList(fill5);
220 tlist->AddToList(fill6);
221 tlist->AddToList(blind);
222 tlist->AddToList(hcalc);
223 tlist->AddToList(scalc);
224
225 //
226 // Now distribute Display to all tasks
227 //
228 tlist->SetDisplay(this);
229}
230*/
231// --------------------------------------------------------------------------
232//
233// Add the top part of the frame: This is filename and treename display
234//
235void MOnlineDisplay::AddTopFramePart1(TGCompositeFrame *vf1)
236{/*
237 //
238 // --- the top1 part of the window ---
239 //
240 TGHorizontalFrame *top1 = new TGHorizontalFrame(frame, 1, 1);
241 fList->Add(top1);
242
243 //
244 // create gui elements
245 //
246 TGLabel *file = new TGLabel(top1, new TGString(Form("%s#%s", filename, treename)));
247 fList->Add(file);
248
249 //
250 // layout and add gui elements in/to frame
251 //
252 TGLayoutHints *laystd = new TGLayoutHints(kLHintsCenterX, 5, 5);
253 fList->Add(laystd);
254
255 top1->AddFrame(file, laystd);
256
257 //
258 // --- the top1 part of the window ---
259 //
260 TGHorizontalFrame *top2 = new TGHorizontalFrame(frame, 1, 1);
261 fList->Add(top2);
262
263 //
264 // layout and add frames
265 //
266 TGLayoutHints *laytop1 = new TGLayoutHints(kLHintsCenterX, 5, 5, 5);
267 fList->Add(laytop1);
268 frame->AddFrame(top1, laytop1);
269 frame->AddFrame(top2, laytop1);*/
270 TGLabel *file = new TGLabel(vf1, new TGString("Magic Online Display -- MONA"));
271 TGLayoutHints *laystd = new TGLayoutHints(kLHintsCenterX, 5, 5);
272 fList->Add(file);
273 fList->Add(laystd);
274 vf1->AddFrame(file, laystd);
275}
276
277// --------------------------------------------------------------------------
278//
279// Add the second part of the top frame: This are the event number controls
280//
281void MOnlineDisplay::AddTopFramePart2(TGCompositeFrame *vf1)
282{
283 //
284 // --- the top2 part of the window ---
285 //
286 TGHorizontalFrame *top2 = new TGHorizontalFrame(vf1, 1, 1);
287 fList->Add(top2);
288
289 //
290 // Create the gui elements
291 //
292 TGTextButton *freeze = new TGTextButton(top2, " Freeze ", kFreeze);
293 freeze->SetUserData(freeze);
294 freeze->Associate(this);
295 freeze->SetToolTipText("Freeze the current Event");
296
297 fList->Add(freeze);
298
299 //
300 // add the gui elements to the frame
301 //
302 TGLayoutHints *laystd = new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 5, 5);
303 fList->Add(laystd);
304
305 top2->AddFrame(freeze, laystd);
306
307 TGLayoutHints *laystd2 = new TGLayoutHints(kLHintsCenterX, 5, 5, 5, 5);
308 fList->Add(laystd2);
309 vf1->AddFrame(top2, laystd2);
310
311 //
312 // Add trailing line...
313 //
314 TGHorizontal3DLine *line = new TGHorizontal3DLine(vf1);
315 TGLayoutHints *layline = new TGLayoutHints(kLHintsExpandX);
316 fList->Add(line);
317 fList->Add(layline);
318 vf1->AddFrame(line, layline);
319}
320
321// --------------------------------------------------------------------------
322//
323// Add the user frame part of the display
324//
325void MOnlineDisplay::AddUserFrame(const char* filename)
326{
327 fUserFrame->ChangeOptions(kHorizontalFrame);
328
329 // Slider
330 TGVSlider *slider = new TGVSlider(fUserFrame, 1, kSlider1, kSlider);
331 slider->SetRange(10, 300);
332 slider->SetScale(15);
333 slider->SetPosition(10);
334 slider->Associate(this);
335 //slider->SetToolTipText("Change the update frequency of the event display (1-30s)");
336
337 // frame1/2
338 TGCompositeFrame *vf1 = new TGVerticalFrame(fUserFrame, 1, 1);
339 TGCompositeFrame *vf2 = new TGVerticalFrame(fUserFrame, 1, 1);
340
341 AddTopFramePart1(vf1);
342 AddTopFramePart2(vf1);
343
344 // create root embedded canvas and add it to the tab
345 TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas("Slices", vf2, vf1->GetDefaultHeight()*3/2, vf1->GetDefaultHeight(), 0);
346 vf2->AddFrame(ec);
347 fList->Add(ec);
348
349 // set background and border mode of the canvas
350 fCanvas = ec->GetCanvas();
351 fCanvas->SetBorderMode(0);
352 gROOT->GetListOfCanvases()->Add(fCanvas);
353 //fCanvas->SetBorderSize(1);
354 //fCanvas->SetBit(kNoContextMenu);
355 //fCanvas->SetFillColor(16);
356
357 // layout
358 TGLayoutHints *lays = new TGLayoutHints(kLHintsExpandY);
359 TGLayoutHints *lay = new TGLayoutHints(kLHintsExpandX);
360 fUserFrame->AddFrame(slider, lays);
361 fUserFrame->AddFrame(vf1, lay);
362 fUserFrame->AddFrame(vf2);
363
364 fList->Add(lay);
365 fList->Add(lays);
366 fList->Add(vf1);
367 fList->Add(vf2);
368 fList->Add(slider);
369}
370
371/*
372// --------------------------------------------------------------------------
373//
374// Checks if the event number is valid, and if so reads the new event
375// and updates the display
376//
377void MOnlineDisplay::ReadinEvent(Int_t dir)
378{
379 MParList *plist = (MParList*)fEvtLoop->GetParList();
380 MTaskList *tlist = (MTaskList*)plist->FindObject("MTaskList");
381 MRawEvtData *raw = (MRawEvtData*)plist->FindObject("MRawEvtData");
382 if (!raw)
383 return;
384
385 //
386 // Read first event.
387 //
388 MReadTree *reader = GetReader();
389
390 const Int_t num = reader->GetNumEntry();
391
392 do
393 {
394 if (dir<0 && !reader->DecEventNum())
395 {
396 reader->SetEventNum(num);
397 return;
398 }
399 if (dir>0 && !reader->IncEventNum())
400 {
401 reader->SetEventNum(num);
402 return;
403 }
404
405 if (!tlist->Process())
406 return;
407
408 reader->DecEventNum();
409
410 } while (raw->GetNumPixels()<1 && dir!=0);
411
412 //
413 // Cleare the 'FADC canvas'
414 //
415 fCanvas->Clear();
416 fCanvas->Modified();
417 fCanvas->Update();
418
419 //
420 // Print parameters
421 //
422 plist->FindObject("MHillas")->Print();
423 plist->FindObject("MHillasExt")->Print();
424 plist->FindObject("MHillasSrc")->Print();
425 plist->FindObject("MNewImagePar")->Print();
426
427 //
428 // UpdateDisplay
429 //
430 gStyle->SetOptStat(1101);
431 Update();
432
433 TGTextEntry *entry = (TGTextEntry*)fList->FindWidget(kEvtNumber);
434 entry->SetText(Form("%d", reader->GetNumEntry()+1));
435}
436
437// --------------------------------------------------------------------------
438//
439// Read first event to get display booted
440//
441void MOnlineDisplay::ReadFirstEvent()
442{
443 if (!fEvtLoop->PreProcess())
444 return;
445
446 //
447 // Get parlist
448 //
449 MParList *plist = (MParList*)fEvtLoop->GetParList();
450
451 //
452 // Add Geometry tab
453 //
454 MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
455
456 TCanvas &c=AddTab("Geometry");
457
458 c.SetFillColor(16);
459
460 MHCamera *cam = new MHCamera(*geom);
461 cam->SetBit(TH1::kNoStats|MHCamera::kNoLegend);
462 cam->Draw();
463 cam->DrawPixelIndices();
464 fList->Add(cam);
465
466 c.Modified();
467 c.Update();
468
469 //
470 // Now read event...
471 //
472 ReadinEvent();
473
474 TGString *txt = new TGString(Form("of %d", GetReader()->GetEntries()));
475 fNumOfEvts->SetText(txt);
476
477 //
478 // Set name for 'FADC canvas'. The name is the anchor for MHCamera.
479 // and clear the canvas
480 //
481 MHEvent *o = (MHEvent*)plist->FindObject("Signal");
482 fCanvas->SetName(Form("%p;%p;PixelContent", o->GetHist(),
483 GetCanvas(1)->GetPad(1)));
484
485 //
486 // Draw ellipse on top of all pads
487 //
488 TObject *hillas = plist->FindObject("MHillas");
489 for (int i=1; i<7;i++)
490 {
491 TCanvas *c = GetCanvas(i);
492 c->GetPad(1)->cd(1);
493 hillas->Draw();
494 }
495}
496*/
497// --------------------------------------------------------------------------
498//
499// Adds the geometry tab
500//
501void MOnlineDisplay::AddGeometryTab()
502{
503 /*
504 MGeomCam *geom = (MGeomCam*)fEvtLoop->GetParList()->FindObject("MGeomCam");
505 if (!geom)
506 return;
507
508 TCanvas &c=AddTab("Geometry");
509
510 MHCamera *cam = new MHCamera(*geom);
511 cam->SetBit(TH1::kNoStats);
512 cam->Draw();
513 cam->DrawPixelIndices();
514 fList->Add(cam);
515
516 c.Modified();
517 c.Update();
518 */
519}
520
521// --------------------------------------------------------------------------
522//
523// ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
524//
525// Processes information from all GUI items.
526// Selecting an item usually generates an event with 4 parameters.
527// The first two are packed into msg (first and second bytes).
528// The other two are parm1 and parm2.
529//
530Bool_t MOnlineDisplay::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
531{
532 if (fTask && fTask->ProcessMessage(GET_MSG(msg), GET_SUBMSG(msg), mp1, mp2))
533 return kTRUE;
534
535 return MStatusDisplay::ProcessMessage(msg, mp1, mp2);
536}
Note: See TracBrowser for help on using the repository browser.