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

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