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

Last change on this file since 4370 was 3926, checked in by moralejo, 21 years ago
*** empty log message ***
File size: 19.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 <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 *evt1 = new MHEvent(MHEvent::kEvtSignalRaw);
218 MHEvent *evt2 = new MHEvent(MHEvent::kEvtSignalRaw);
219 MHEvent *evt3 = new MHEvent(MHEvent::kEvtPedestal);
220 MHEvent *evt4 = new MHEvent(MHEvent::kEvtPedestalRMS);
221 MHEvent *evt5 = new MHEvent(MHEvent::kEvtRelativeSignal);
222 MHEvent *evt6 = new MHEvent(MHEvent::kEvtCleaningLevels);
223 MHEvent *evt7 = new MHEvent(MHEvent::kEvtIdxMax);
224 MHEvent *evt8 = new MHEvent(MHEvent::kEvtArrTime);
225 MHEvent *evt9 = new MHEvent(MHEvent::kEvtTrigPix);
226
227 evt1->SetName("Signal");
228 evt2->SetName("Cleaned");
229 evt3->SetName("Pedestal");
230 evt4->SetName("PedRMS");
231 evt5->SetName("Signal/PedRMS");
232 evt6->SetName("CleanLevels");
233 evt7->SetName("Max Slice Idx");
234 evt8->SetName("Arrival Time");
235 evt9->SetName("Trigger");
236
237 // This makes sure, that the containers are deleted...
238 plist->AddToList(evt1);
239 plist->AddToList(evt2);
240 plist->AddToList(evt3);
241 plist->AddToList(evt4);
242 plist->AddToList(evt5);
243 plist->AddToList(evt6);
244 plist->AddToList(evt7);
245 plist->AddToList(evt8);
246 plist->AddToList(evt9);
247
248 MCerPhotAnal2 *nanal = new MCerPhotAnal2;
249 MFillH *fill1 = new MFillH(evt1, "MCerPhotEvt", "MFillH1");
250 MImgCleanStd *clean = new MImgCleanStd;
251 MFillH *fill2 = new MFillH(evt2, "MCerPhotEvt", "MFillH2");
252 MFillH *fill3 = new MFillH(evt3, "MPedPhotCam", "MFillH3");
253 MFillH *fill4 = new MFillH(evt4, "MPedPhotCam", "MFillH4");
254 MFillH *fill5 = new MFillH(evt5, "MCameraData", "MFillH5");
255 MFillH *fill6 = new MFillH(evt6, "MCameraData", "MFillH6");
256 MBlindPixelCalc *blind = new MBlindPixelCalc;
257 MHillasCalc *hcalc = new MHillasCalc;
258 MHillasSrcCalc *scalc = new MHillasSrcCalc;
259 MMcTriggerLvl2Calc *trcal = new MMcTriggerLvl2Calc;
260 MFillH *fill9 = new MFillH(evt9, "MMcTriggerLvl2", "MFillH9");
261
262 // If no pedestal or no calibration file is availble
263 if (!pcam || !ccam)
264 {
265 MFilter *f1=new MFDataMember("MRawRunHeader.fRunType", '>', 255.5);
266 MFilter *f2=new MFDataMember("MRawRunHeader.fRunType", '<', 255.5);
267 f1->SetName("MFMonteCarlo");
268 f2->SetName("MFRealData");
269
270 MMcPedestalCopy *pcopy = new MMcPedestalCopy;
271 MMcPedestalNSBAdd *pdnsb = new MMcPedestalNSBAdd;
272
273 MExtractSignal* extra = new MExtractSignal();
274 extra->SetRange(0, 14, 0, 14);
275 extra->SetSaturationLimit(240);
276
277 MMcCalibrationUpdate* mcupd = new MMcCalibrationUpdate;
278 mcupd->SetOuterPixelsGainScaling(kFALSE);
279
280 MCalibrate* mccal = new MCalibrate;
281 mccal->SetCalibrationMode(MCalibrate::kFfactor);
282
283 // MC
284 extra->SetFilter(f1);
285 mcupd->SetFilter(f1);
286 mccal->SetFilter(f1);
287 trcal->SetFilter(f1);
288
289 // Data
290 nanal->SetFilter(f2);
291
292 // TaskList
293 tlist->AddToList(f1);
294 tlist->AddToList(f2);
295 tlist->AddToList(pcopy);
296 tlist->AddToList(pdnsb);
297
298 tlist->AddToList(extra);
299 tlist->AddToList(mcupd);
300 tlist->AddToList(mccal);
301
302
303 tlist->AddToList(nanal);
304 }
305 else
306 {
307 MCalibrate* calib = new MCalibrate;
308 tlist->AddToList(calib);
309 }
310
311 tlist->AddToList(fill1);
312 tlist->AddToList(clean);
313 tlist->AddToList(fill2);
314 tlist->AddToList(fill3);
315 tlist->AddToList(fill4);
316 tlist->AddToList(fill5);
317 tlist->AddToList(fill6);
318 tlist->AddToList(blind);
319 tlist->AddToList(hcalc);
320 tlist->AddToList(scalc);
321
322 if (!pcam || !ccam)
323 {
324 MArrivalTimeCalc *tcalc = new MArrivalTimeCalc;
325 MFillH *fill7 = new MFillH(evt7, "MRawEvtData", "MFillH7");
326 MFillH *fill8 = new MFillH(evt8, "MArrivalTimeCam", "MFillH8");
327 tlist->AddToList(tcalc);
328 tlist->AddToList(fill7);
329 tlist->AddToList(fill8);
330
331 tlist->AddToList(trcal);
332 tlist->AddToList(fill9);
333 }
334
335 //
336 // Now distribute Display to all tasks
337 //
338 tlist->SetDisplay(this);
339}
340
341// --------------------------------------------------------------------------
342//
343// Add the top part of the frame: This is filename and treename display
344//
345void MEventDisplay::AddTopFramePart1(TGCompositeFrame *frame,
346 const char *filename,
347 const char *treename)
348{
349 //
350 // --- the top1 part of the window ---
351 //
352 TGHorizontalFrame *top1 = new TGHorizontalFrame(frame, 1, 1);
353 fList->Add(top1);
354
355 //
356 // create gui elements
357 //
358 TGLabel *file = new TGLabel(top1, new TGString(Form("%s#%s", filename, treename)));
359 fList->Add(file);
360
361 //
362 // layout and add gui elements in/to frame
363 //
364 TGLayoutHints *laystd = new TGLayoutHints(kLHintsCenterX, 5, 5);
365 fList->Add(laystd);
366
367 top1->AddFrame(file, laystd);
368
369 //
370 // --- the top1 part of the window ---
371 //
372 TGHorizontalFrame *top2 = new TGHorizontalFrame(frame, 1, 1);
373 fList->Add(top2);
374
375 //
376 // layout and add frames
377 //
378 TGLayoutHints *laytop1 = new TGLayoutHints(kLHintsCenterX, 5, 5, 5);
379 fList->Add(laytop1);
380 frame->AddFrame(top1, laytop1);
381 frame->AddFrame(top2, laytop1);
382}
383
384// --------------------------------------------------------------------------
385//
386// Add the second part of the top frame: This are the event number controls
387//
388void MEventDisplay::AddTopFramePart2(TGCompositeFrame *frame)
389{
390 //
391 // --- the top2 part of the window ---
392 //
393 TGHorizontalFrame *top2 = new TGHorizontalFrame(frame, 1, 1);
394 fList->Add(top2);
395
396 //
397 // Create the gui elements
398 //
399 TGTextButton *prevevt = new TGTextButton(top2, " << ", kEvtPrev);
400 prevevt->Associate(this);
401
402 TGLabel *evtnr = new TGLabel(top2, new TGString("Event:"));
403
404 TGTextEntry *entry=new TGTextEntry(top2, new TGTextBuffer(100), kEvtNumber);
405 entry->Resize(60, entry->GetDefaultHeight());
406 entry->Associate(this);
407
408 fNumOfEvts = new TGLabel(top2, "of .");
409
410 TGTextButton *nextevt = new TGTextButton (top2, " >> ", kEvtNext);
411 nextevt->Associate(this);
412
413 //
414 // Add gui elements to 'atotodel'
415 //
416 fList->Add(prevevt);
417 fList->Add(evtnr);
418 fList->Add(entry);
419 fList->Add(fNumOfEvts);
420 fList->Add(nextevt);
421
422 //
423 // add the gui elements to the frame
424 //
425 TGLayoutHints *laystd = new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 5, 5);
426 fList->Add(laystd);
427
428 top2->AddFrame(prevevt, laystd);
429 top2->AddFrame(evtnr, laystd);
430 top2->AddFrame(entry, laystd);
431 top2->AddFrame(fNumOfEvts, laystd);
432 top2->AddFrame(nextevt, laystd);
433
434 TGLayoutHints *laystd2 = new TGLayoutHints(kLHintsCenterX, 5, 5, 5, 5);
435 fList->Add(laystd2);
436 frame->AddFrame(top2, laystd2);
437
438 //
439 // Add trailing line...
440 //
441 TGHorizontal3DLine *line = new TGHorizontal3DLine(frame);
442 TGLayoutHints *layline = new TGLayoutHints(kLHintsExpandX);
443 fList->Add(line);
444 fList->Add(layline);
445 frame->AddFrame(line, layline);
446}
447
448// --------------------------------------------------------------------------
449//
450// Add the user frame part of the display
451//
452void MEventDisplay::AddUserFrame(const char* filename)
453{
454 fUserFrame->ChangeOptions(kHorizontalFrame);
455
456 TGCompositeFrame *vf1 = new TGVerticalFrame(fUserFrame, 1, 1);
457 TGCompositeFrame *vf2 = new TGVerticalFrame(fUserFrame, 1, 1);
458
459 AddTopFramePart1(vf1, filename, "Events");
460 AddTopFramePart2(vf1);
461
462 // create root embedded canvas and add it to the tab
463 TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas("Slices", vf2, vf1->GetDefaultHeight()*3/2, vf1->GetDefaultHeight(), 0);
464 vf2->AddFrame(ec);
465 fList->Add(ec);
466
467 // set background and border mode of the canvas
468 fCanvas = ec->GetCanvas();
469 fCanvas->SetBorderMode(0);
470 gROOT->GetListOfCanvases()->Add(fCanvas);
471 //fCanvas->SetBorderSize(1);
472 //fCanvas->SetBit(kNoContextMenu);
473 //fCanvas->SetFillColor(16);
474
475 TGLayoutHints *lay = new TGLayoutHints(kLHintsExpandX);
476 fUserFrame->AddFrame(vf1, lay);
477 fUserFrame->AddFrame(vf2);
478}
479
480// --------------------------------------------------------------------------
481//
482// Checks if the event number is valid, and if so reads the new event
483// and updates the display
484//
485void MEventDisplay::ReadinEvent(Int_t dir)
486{
487 MParList *plist = (MParList*) fEvtLoop->GetParList();
488 MTaskList *tlist = (MTaskList*) fEvtLoop->GetTaskList();
489 MGeomCam *geom = (MGeomCam*) plist->FindObject("MGeomCam");
490 MRawEvtData *raw = (MRawEvtData*)plist->FindObject("MRawEvtData");
491
492 //
493 // Read first event.
494 //
495 MReadTree *reader = (MReadTree*)fEvtLoop->FindTask("MRead");
496
497 const Int_t num = reader->GetNumEntry();
498
499 do
500 {
501 if (dir<0 && !reader->DecEventNum())
502 {
503 reader->SetEventNum(num);
504 return;
505 }
506 if (dir>0 && !reader->IncEventNum())
507 {
508 reader->SetEventNum(num);
509 return;
510 }
511
512 if (!tlist->Process())
513 return;
514
515 reader->DecEventNum();
516
517 } while (raw && raw->GetNumPixels()<1 && dir!=0);
518
519 //
520 // Cleare the 'FADC canvas'
521 //
522 fCanvas->Clear();
523 fCanvas->Modified();
524 fCanvas->Update();
525
526 //
527 // Print parameters
528 //
529 ((MHillas*) plist->FindObject("MHillas"))->Print(*geom);
530 ((MHillasExt*) plist->FindObject("MHillasExt"))->Print(*geom);
531 ((MHillasSrc*) plist->FindObject("MHillasSrc"))->Print(*geom);
532 ((MNewImagePar*)plist->FindObject("MNewImagePar"))->Print(*geom);
533
534 //
535 // UpdateDisplay
536 //
537 gStyle->SetOptStat(1101);
538 Update();
539
540 TGTextEntry *entry = (TGTextEntry*)fList->FindWidget(kEvtNumber);
541 entry->SetText(Form("%d", reader->GetNumEntry()+1));
542}
543
544// --------------------------------------------------------------------------
545//
546// Read first event to get display booted
547//
548void MEventDisplay::ReadFirstEvent()
549{
550 if (!fEvtLoop->PreProcess())
551 return;
552
553 //
554 // Get parlist
555 //
556 MParList *plist = (MParList*)fEvtLoop->GetParList();
557
558 //
559 // Add Geometry tab
560 //
561 AddGeometryTabs();
562
563 //
564 // Now read event...
565 //
566 ReadinEvent();
567
568 MReadTree *reader = (MReadTree*)fEvtLoop->FindTask("MRead");
569 TGString *txt = new TGString(Form("of %d", reader->GetEntries()));
570 fNumOfEvts->SetText(txt);
571
572 //
573 // Draw ellipse on top of all pads
574 //
575 TObject *hillas = plist->FindObject("MHillas");
576 for (int i=1; i<7;i++)
577 {
578 TCanvas *c = GetCanvas(i);
579 c->GetPad(1)->cd(1);
580 hillas->Draw();
581 }
582}
583
584// --------------------------------------------------------------------------
585//
586// Adds the geometry tab
587//
588void MEventDisplay::AddGeometryTabs()
589{
590 MGeomCam *geom = (MGeomCam*)fEvtLoop->GetParList()->FindObject("MGeomCam");
591 if (!geom)
592 return;
593
594 TCanvas &c1=AddTab("Geometry");
595
596 MHCamera *cam = new MHCamera(*geom);
597 cam->SetBit(TH1::kNoStats|MHCamera::kNoLegend|kCanDelete);
598 cam->Draw("pixelindex");
599
600 c1.Modified();
601 c1.Update();
602
603 TCanvas &c2=AddTab("Sectors");
604
605 cam = new MHCamera(*geom);
606 cam->SetBit(TH1::kNoStats|MHCamera::kNoLegend|kCanDelete);
607 cam->Draw("sectorindex");
608
609 c2.Modified();
610 c2.Update();
611}
612
613// --------------------------------------------------------------------------
614//
615// ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
616//
617// Processes information from all GUI items.
618// Selecting an item usually generates an event with 4 parameters.
619// The first two are packed into msg (first and second bytes).
620// The other two are parm1 and parm2.
621//
622Bool_t MEventDisplay::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
623{
624 switch (GET_MSG(msg))
625 {
626 case kC_TEXTENTRY:
627 switch(GET_SUBMSG(msg))
628 {
629 case kTE_ENTER:
630 switch(GET_SUBMSG(msg))
631 {
632 case kTE_ENTER:
633 {
634 TGTextEntry *entry = (TGTextEntry*)fList->FindWidget(kEvtNumber);
635 MReadTree *reader = (MReadTree*)fEvtLoop->FindTask("MRead");
636 if (reader->SetEventNum(atoi(entry->GetText())-1))
637 ReadinEvent();
638 }
639 return kTRUE;
640 }
641 return kTRUE;
642 }
643 break;
644
645 case kC_COMMAND:
646 switch (GET_SUBMSG(msg))
647 {
648 case kCM_TAB:
649 {
650 //
651 // Set name for 'FADC canvas'. The name is the anchor for MHCamera.
652 // and clear the canvas
653 TCanvas *c = GetCanvas(mp1);
654 if (!c)
655 break;
656 MHEvent *o = (MHEvent*)fEvtLoop->GetParList()->FindObject(c->GetName());
657 if (!o)
658 break;
659 fCanvas->SetName(Form("%p;%p;PixelContent", o->GetHist(), c->GetPad(1)));
660 }
661 break;
662
663 case kCM_BUTTON:
664 switch (mp1)
665 {
666 case kEvtPrev:
667 ReadinEvent(-1);
668 return kTRUE;
669
670 case kEvtNext:
671 ReadinEvent(+1);
672 return kTRUE;
673 }
674 return kTRUE;
675 }
676 break;
677 }
678
679 return MStatusDisplay::ProcessMessage(msg, mp1, mp2);
680}
Note: See TracBrowser for help on using the repository browser.