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

Last change on this file since 2750 was 2728, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 16.3 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::kEvtArrTime);
165
166 evt1->SetName("Signal");
167 evt2->SetName("Cleaned");
168 evt3->SetName("Pedestal");
169 evt4->SetName("PedRMS");
170 evt5->SetName("Signal/PedRMS");
171 evt6->SetName("CleanLevels");
172 evt7->SetName("ArrivalTime");
173
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 plist->AddToList(evt7);
181
182
183 MMcPedestalCopy *pcopy = new MMcPedestalCopy;
184 MMcPedestalNSBAdd *pdnsb = new MMcPedestalNSBAdd;
185 MCerPhotCalc *ncalc = new MCerPhotCalc;
186 MCerPhotAnal2 *nanal = new MCerPhotAnal2;
187 MFillH *fill1 = new MFillH(evt1, "MCerPhotEvt", "MFillH1");
188 MImgCleanStd *clean = new MImgCleanStd;
189 MFillH *fill2 = new MFillH(evt2, "MCerPhotEvt", "MFillH2");
190 MFillH *fill3 = new MFillH(evt3, "MPedestalCam", "MFillH3");
191 MFillH *fill4 = new MFillH(evt4, "MPedestalCam", "MFillH4");
192 MFillH *fill5 = new MFillH(evt5, "MCameraData", "MFillH5");
193 MFillH *fill6 = new MFillH(evt6, "MCameraData", "MFillH6");
194 MBlindPixelCalc *blind = new MBlindPixelCalc;
195 MHillasCalc *hcalc = new MHillasCalc;
196 MHillasSrcCalc *scalc = new MHillasSrcCalc;
197 MArrivalTimeCalc *tcalc = new MArrivalTimeCalc;
198 MFillH *fill7 = new MFillH(evt7, "MRawEvtData", "MFillH7");
199
200
201 MFilter *f1=new MFDataMember("MRawRunHeader.fRunType", '>', 255.5);
202 MFilter *f2=new MFDataMember("MRawRunHeader.fRunType", '<', 255.5);
203
204 ncalc->SetFilter(f1);
205 nanal->SetFilter(f2);
206
207 tlist->AddToList(f1);
208 tlist->AddToList(f2);
209 tlist->AddToList(pcopy);
210 tlist->AddToList(pdnsb);
211 tlist->AddToList(ncalc);
212 tlist->AddToList(nanal);
213 tlist->AddToList(fill1);
214 tlist->AddToList(clean);
215 tlist->AddToList(fill2);
216 tlist->AddToList(fill3);
217 tlist->AddToList(fill4);
218 tlist->AddToList(fill5);
219 tlist->AddToList(fill6);
220 tlist->AddToList(blind);
221 tlist->AddToList(hcalc);
222 tlist->AddToList(scalc);
223 tlist->AddToList(tcalc);
224 tlist->AddToList(fill7);
225
226
227 //
228 // Now distribute Display to all tasks
229 //
230 tlist->SetDisplay(this);
231}
232
233// --------------------------------------------------------------------------
234//
235// Add the top part of the frame: This is filename and treename display
236//
237void MEventDisplay::AddTopFramePart1(TGCompositeFrame *frame,
238 const char *filename,
239 const char *treename)
240{
241 //
242 // --- the top1 part of the window ---
243 //
244 TGHorizontalFrame *top1 = new TGHorizontalFrame(frame, 1, 1);
245 fList->Add(top1);
246
247 //
248 // create gui elements
249 //
250 TGLabel *file = new TGLabel(top1, new TGString(Form("%s#%s", filename, treename)));
251 fList->Add(file);
252
253 //
254 // layout and add gui elements in/to frame
255 //
256 TGLayoutHints *laystd = new TGLayoutHints(kLHintsCenterX, 5, 5);
257 fList->Add(laystd);
258
259 top1->AddFrame(file, laystd);
260
261 //
262 // --- the top1 part of the window ---
263 //
264 TGHorizontalFrame *top2 = new TGHorizontalFrame(frame, 1, 1);
265 fList->Add(top2);
266
267 //
268 // layout and add frames
269 //
270 TGLayoutHints *laytop1 = new TGLayoutHints(kLHintsCenterX, 5, 5, 5);
271 fList->Add(laytop1);
272 frame->AddFrame(top1, laytop1);
273 frame->AddFrame(top2, laytop1);
274}
275
276// --------------------------------------------------------------------------
277//
278// Add the second part of the top frame: This are the event number controls
279//
280void MEventDisplay::AddTopFramePart2(TGCompositeFrame *frame)
281{
282 //
283 // --- the top2 part of the window ---
284 //
285 TGHorizontalFrame *top2 = new TGHorizontalFrame(frame, 1, 1);
286 fList->Add(top2);
287
288 //
289 // Create the gui elements
290 //
291 TGTextButton *prevevt = new TGTextButton(top2, " << ", kEvtPrev);
292 prevevt->Associate(this);
293
294 TGLabel *evtnr = new TGLabel(top2, new TGString("Event:"));
295
296 TGTextEntry *entry=new TGTextEntry(top2, new TGTextBuffer(100), kEvtNumber);
297 entry->Resize(60, entry->GetDefaultHeight());
298 entry->Associate(this);
299
300 fNumOfEvts = new TGLabel(top2, "of .");
301
302 TGTextButton *nextevt = new TGTextButton (top2, " >> ", kEvtNext);
303 nextevt->Associate(this);
304
305 //
306 // Add gui elements to 'atotodel'
307 //
308 fList->Add(prevevt);
309 fList->Add(evtnr);
310 fList->Add(entry);
311 fList->Add(fNumOfEvts);
312 fList->Add(nextevt);
313
314 //
315 // add the gui elements to the frame
316 //
317 TGLayoutHints *laystd = new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 5, 5);
318 fList->Add(laystd);
319
320 top2->AddFrame(prevevt, laystd);
321 top2->AddFrame(evtnr, laystd);
322 top2->AddFrame(entry, laystd);
323 top2->AddFrame(fNumOfEvts, laystd);
324 top2->AddFrame(nextevt, laystd);
325
326 TGLayoutHints *laystd2 = new TGLayoutHints(kLHintsCenterX, 5, 5, 5, 5);
327 fList->Add(laystd2);
328 frame->AddFrame(top2, laystd2);
329
330 //
331 // Add trailing line...
332 //
333 TGHorizontal3DLine *line = new TGHorizontal3DLine(frame);
334 TGLayoutHints *layline = new TGLayoutHints(kLHintsExpandX);
335 fList->Add(line);
336 fList->Add(layline);
337 frame->AddFrame(line, layline);
338}
339
340// --------------------------------------------------------------------------
341//
342// Add the user frame part of the display
343//
344void MEventDisplay::AddUserFrame(const char* filename)
345{
346 fUserFrame->ChangeOptions(kHorizontalFrame);
347
348 TGCompositeFrame *vf1 = new TGVerticalFrame(fUserFrame, 1, 1);
349 TGCompositeFrame *vf2 = new TGVerticalFrame(fUserFrame, 1, 1);
350
351 AddTopFramePart1(vf1, filename, "Events");
352 AddTopFramePart2(vf1);
353
354 // create root embedded canvas and add it to the tab
355 TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas("Slices", vf2, vf1->GetDefaultHeight()*3/2, vf1->GetDefaultHeight(), 0);
356 vf2->AddFrame(ec);
357 fList->Add(ec);
358
359 // set background and border mode of the canvas
360 fCanvas = ec->GetCanvas();
361 fCanvas->SetBorderMode(0);
362 gROOT->GetListOfCanvases()->Add(fCanvas);
363 //fCanvas->SetBorderSize(1);
364 //fCanvas->SetBit(kNoContextMenu);
365 //fCanvas->SetFillColor(16);
366
367 TGLayoutHints *lay = new TGLayoutHints(kLHintsExpandX);
368 fUserFrame->AddFrame(vf1, lay);
369 fUserFrame->AddFrame(vf2);
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 MEventDisplay::ReadinEvent(Int_t dir)
378{
379 MParList *plist = (MParList*) fEvtLoop->GetParList();
380 MTaskList *tlist = (MTaskList*) fEvtLoop->GetTaskList();
381 MGeomCam *geom = (MGeomCam*) plist->FindObject("MGeomCam");
382 MRawEvtData *raw = (MRawEvtData*)plist->FindObject("MRawEvtData");
383 if (!raw)
384 return;
385
386 //
387 // Read first event.
388 //
389 MReadTree *reader = (MReadTree*)fEvtLoop->FindTask("MRead");
390
391 const Int_t num = reader->GetNumEntry();
392
393 do
394 {
395 if (dir<0 && !reader->DecEventNum())
396 {
397 reader->SetEventNum(num);
398 return;
399 }
400 if (dir>0 && !reader->IncEventNum())
401 {
402 reader->SetEventNum(num);
403 return;
404 }
405
406 if (!tlist->Process())
407 return;
408
409 reader->DecEventNum();
410
411 } while (raw->GetNumPixels()<1 && dir!=0);
412
413 //
414 // Cleare the 'FADC canvas'
415 //
416 fCanvas->Clear();
417 fCanvas->Modified();
418 fCanvas->Update();
419
420 //
421 // Print parameters
422 //
423 ((MHillas*) plist->FindObject("MHillas"))->Print(*geom);
424 ((MHillasExt*)plist->FindObject("MHillasExt"))->Print(*geom);
425 ((MHillasSrc*)plist->FindObject("MHillasSrc"))->Print(*geom);
426 plist->FindObject("MNewImagePar")->Print();
427
428 //
429 // UpdateDisplay
430 //
431 gStyle->SetOptStat(1101);
432 Update();
433
434 TGTextEntry *entry = (TGTextEntry*)fList->FindWidget(kEvtNumber);
435 entry->SetText(Form("%d", reader->GetNumEntry()+1));
436}
437
438// --------------------------------------------------------------------------
439//
440// Read first event to get display booted
441//
442void MEventDisplay::ReadFirstEvent()
443{
444 if (!fEvtLoop->PreProcess())
445 return;
446
447 //
448 // Get parlist
449 //
450 MParList *plist = (MParList*)fEvtLoop->GetParList();
451
452 //
453 // Add Geometry tab
454 //
455 AddGeometryTabs();
456
457 //
458 // Now read event...
459 //
460 ReadinEvent();
461
462 MReadTree *reader = (MReadTree*)fEvtLoop->FindTask("MRead");
463 TGString *txt = new TGString(Form("of %d", reader->GetEntries()));
464 fNumOfEvts->SetText(txt);
465
466 //
467 // Draw ellipse on top of all pads
468 //
469 TObject *hillas = plist->FindObject("MHillas");
470 for (int i=1; i<7;i++)
471 {
472 TCanvas *c = GetCanvas(i);
473 c->GetPad(1)->cd(1);
474 hillas->Draw();
475 }
476}
477
478// --------------------------------------------------------------------------
479//
480// Adds the geometry tab
481//
482void MEventDisplay::AddGeometryTabs()
483{
484 MGeomCam *geom = (MGeomCam*)fEvtLoop->GetParList()->FindObject("MGeomCam");
485 if (!geom)
486 return;
487
488 TCanvas &c1=AddTab("Geometry");
489
490 MHCamera *cam = new MHCamera(*geom);
491 cam->SetBit(TH1::kNoStats|MHCamera::kNoLegend|kCanDelete);
492 cam->Draw("pixelindex");
493 fList->Add(cam);
494
495 c1.Modified();
496 c1.Update();
497
498 TCanvas &c2=AddTab("Sectors");
499
500 cam = new MHCamera(*geom);
501 cam->SetBit(TH1::kNoStats|MHCamera::kNoLegend|kCanDelete);
502 cam->Draw("sectorindex");
503 fList->Add(cam);
504
505 c2.Modified();
506 c2.Update();
507}
508
509// --------------------------------------------------------------------------
510//
511// ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
512//
513// Processes information from all GUI items.
514// Selecting an item usually generates an event with 4 parameters.
515// The first two are packed into msg (first and second bytes).
516// The other two are parm1 and parm2.
517//
518Bool_t MEventDisplay::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
519{
520 switch (GET_MSG(msg))
521 {
522 case kC_TEXTENTRY:
523 switch(GET_SUBMSG(msg))
524 {
525 case kTE_ENTER:
526 switch(GET_SUBMSG(msg))
527 {
528 case kTE_ENTER:
529 {
530 TGTextEntry *entry = (TGTextEntry*)fList->FindWidget(kEvtNumber);
531 MReadTree *reader = (MReadTree*)fEvtLoop->FindTask("MRead");
532 if (reader->SetEventNum(atoi(entry->GetText())-1))
533 ReadinEvent();
534 }
535 return kTRUE;
536 }
537 return kTRUE;
538 }
539 break;
540
541 case kC_COMMAND:
542 switch (GET_SUBMSG(msg))
543 {
544 case kCM_TAB:
545 {
546 //
547 // Set name for 'FADC canvas'. The name is the anchor for MHCamera.
548 // and clear the canvas
549 TCanvas *c = GetCanvas(mp1);
550 if (!c)
551 break;
552 MHEvent *o = (MHEvent*)fEvtLoop->GetParList()->FindObject(c->GetName());
553 if (!o)
554 break;
555 fCanvas->SetName(Form("%p;%p;PixelContent", o->GetHist(), c->GetPad(1)));
556 }
557 break;
558
559 case kCM_BUTTON:
560 switch (mp1)
561 {
562 case kEvtPrev:
563 ReadinEvent(-1);
564 return kTRUE;
565
566 case kEvtNext:
567 ReadinEvent(+1);
568 return kTRUE;
569 }
570 return kTRUE;
571 }
572 break;
573 }
574
575 return MStatusDisplay::ProcessMessage(msg, mp1, mp2);
576}
Note: See TracBrowser for help on using the repository browser.