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

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