source: trunk/MagicSoft/Mars/mmain/MEventDisplay.cc@ 2483

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