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

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