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

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