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

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