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

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