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

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