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

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