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

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