source: trunk/Mars/mmain/MEventDisplay.cc@ 10113

Last change on this file since 10113 was 9347, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 27.2 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MEventDisplay.cc,v 1.70 2009-02-18 12:06:39 tbretz Exp $
3! --------------------------------------------------------------------------
4!
5! *
6! * This file is part of MARS, the MAGIC Analysis and Reconstruction
7! * Software. It is distributed to you in the hope that it can be a useful
8! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
9! * It is distributed WITHOUT ANY WARRANTY.
10! *
11! * Permission to use, copy, modify and distribute this software and its
12! * documentation for any purpose is hereby granted without fee,
13! * provided that the above copyright notice appear in all copies and
14! * that both that copyright notice and this permission notice appear
15! * in supporting documentation. It is provided "as is" without express
16! * or implied warranty.
17! *
18!
19!
20! Author(s): Thomas Bretz, 10/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
21!
22! Copyright: MAGIC Software Development, 2000-2006
23!
24!
25\* ======================================================================== */
26#include "MEventDisplay.h"
27
28//
29// C-lib
30//
31#include <stdlib.h> // atoi
32
33//
34// root
35//
36#include <TFile.h> // TFile
37#include <TTree.h> // TTree
38#include <TList.h> // TList::Add
39#include <TStyle.h> // gStyle->SetOptStat
40#include <TCanvas.h> // TCanvas::cd
41#include <TSystem.h> // TSystem::BaseName
42
43//
44// root GUI
45//
46#include <TGLabel.h> // TGLabel
47#include <TGButton.h> // TGPictureButton
48#include <TG3DLine.h> // TGHorizontal3DLine
49#include <TGTextEntry.h> // TGTextEntry
50#include <TGButtonGroup.h> // TGVButtonGroup
51#include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
52
53//
54// General
55//
56#include "MGList.h" // MGList
57#include "MString.h"
58
59#include "MLog.h"
60#include "MLogManip.h"
61
62#include "MParList.h" // MParList::AddToList
63#include "MEvtLoop.h" // MEvtLoop::GetParList
64#include "MTaskList.h" // MTaskList::AddToList
65
66//
67// Tasks
68//
69#include "MReadMarsFile.h" // MReadMarsFile
70#include "MGeomApply.h" // MGeomApply
71#include "MPedestalSubtract.h" // MPedestalSubtract
72#include "MFDataMember.h" // MFDataMember
73#include "MFEvtNumber.h" // MFEvtNumber
74#include "MMcPedestalCopy.h" // MMcPedestalCopy
75#include "MMcPedestalNSBAdd.h" // MMcPedestalNSBAdd
76
77#include "MSignalCalc.h" // MPedestalCalc
78#include "MTaskEnv.h" // MTaskEnv
79#include "MExtractTimeAndChargeDigitalFilter.h"
80#include "MImgCleanStd.h" // MImgCleanStd
81#include "MHillasCalc.h" // MHillasCalc
82#include "MCalibrationRelTimeCalc.h" // MCalibrationRelTimeCalc
83#include "MCalibrationPatternDecode.h" // MCalibrationPatternDecode
84#include "MPrint.h"
85#include "MBadPixelsCalc.h" // MBadPixelsCalc
86#include "MBadPixelsTreat.h" // MBadPixelsTreat
87#include "MFillH.h" // MFillH
88#include "MMcCalibrationUpdate.h" // MMcCalibrationUpdate
89#include "MCalibrateData.h" // MCalibrateData
90#include "MMuonSearchParCalc.h" // MMuonSearchParCalc
91#include "MMuonCalibParCalc.h" // MMuonCalibParCalc
92#include "MContinue.h" // MContinue
93#include "MTriggerPatternDecode.h" // MTriggerPatternDecode
94#include "MSimSignalCam.h" // MSimSignalCam
95#include "MSimGeomCam.h" // MSimGeomCam
96//#include "MMcTriggerLvl2Calc.h" // MMcTriggerLvl2Calc
97
98//
99// Container
100//
101#include "MSequence.h" // MSequence
102#include "MDirIter.h" // MDirIter
103#include "MHillas.h" // MHillas::Print(const MGeomCam&)
104#include "MHillasExt.h" // MHillasExt::Print(const MGeomCam&)
105#include "MHillasSrc.h" // MHillasSrc::Print(const MGeomCam&)
106#include "MImagePar.h" // MImagePar::Print(const MGeomCam&)
107#include "MNewImagePar.h" // MNewImagePar::Print(const MGeomCam&)
108#include "MHEvent.h" // MHEvent
109#include "MHCamera.h" // MHCamera
110#include "MRawEvtData.h" // MRawEvtData
111#include "MArrivalTimeCam.h" // MArrivalTimeCam
112#include "MBadPixelsCam.h" // MBadPixelsCam
113#include "MPedPhotCam.h" // MPedPhotCam
114#include "MCalibrationChargeCam.h" // MCalibrationChargeCam
115#include "MMuonSearchPar.h" // MMuonCalibPar
116#include "MHPhotonEvent.h" // MHPhotonEvent
117//#include "MMcTriggerLvl2.h" // MMcTriggerLvl2
118
119using namespace std;
120
121ClassImp(MEventDisplay);
122
123// --------------------------------------------------------------------------
124//
125// Constructor.
126//
127MEventDisplay::MEventDisplay(const char *fname, const char *path) : MStatusDisplay(756), fEvtLoop(0)
128{
129 //
130 // Setup Task list for hillas calculation
131 //
132 SetupTaskList("Events", fname, path);
133
134 //
135 // Add MEventDisplay GUI elements to the display
136 //
137 AddUserFrame(fname);
138
139 //
140 // Show new part of the window, resize to correct aspect ratio
141 //
142 // FIXME: This should be done by MStatusDisplay automatically
143 Resize(768, 576 + fUserFrame->GetDefaultHeight());//TMath::Nint(GetWidth()*1.2), TMath::Nint(GetHeight()*1.2 + fUserFrame->GetDefaultHeight()));
144 SetWindowName("Event Display");
145 MapSubwindows();
146
147 //
148 // Readin first event and display it
149 //
150 if (fEvtLoop)
151 ReadFirstEvent();
152
153 SetNoContextMenu(kFALSE);
154}
155
156// --------------------------------------------------------------------------
157//
158// Destructor: PostProcess eventloop, delete eventloop with all containers
159//
160MEventDisplay::~MEventDisplay()
161{
162 if (fEvtLoop)
163 {
164 fEvtLoop->PostProcess();
165 delete fEvtLoop;
166 }
167}
168
169Int_t MEventDisplay::GetFileType(const char *tree, const char *fname) const
170{
171 TFile f(fname, "READ");
172 if (f.IsZombie())
173 return 0; // Not a root file
174
175 TTree *t = (TTree*)f.Get(tree);
176 if (!t)
177 return -1;
178
179 if (t->FindBranch("MSignalCam."))
180 return 1;
181
182 if (t->FindBranch("MRawEvtData."))
183 return 2;
184
185 if (t->FindBranch("MPhotonEvent."))
186 return 3;
187
188 return -2;
189}
190
191// --------------------------------------------------------------------------
192//
193// Setup Task and parameter list for hillas calculation,
194// preprocess tasks and read in first event (process)
195//
196void MEventDisplay::SetupTaskList(const char *tname, TString fname, const char *path)
197{
198 MBadPixelsCam *badpix = new MBadPixelsCam;
199
200 Int_t type = GetFileType(tname, fname);
201 switch (type)
202 {
203 case 1: gLog << all << "Calibrated Data File detected..." << endl; break;
204 case 2: gLog << all << "Raw Data File detected..." << endl; break;
205 case 3: gLog << all << "Ceres reflector file detected..." << endl; break;
206 case -2: gLog << err << "File type unknown... abort." << endl; return;
207 case -1: gLog << err << "Tree " << tname << " not found... abort." << endl; return;
208 case 0: gLog << inf << "Assuming Sequence file." << endl; break;
209 }
210
211 if (type==0 && !MSequence::InflateSeq(fname))
212 return;
213
214 // Check if file is a sequence...
215 MSequence *seq = type==0 ? new MSequence(fname, path) : new MSequence;
216 if (type==0)
217 type = 1;
218
219 //
220 // Setup an empty job, with a reader task only.
221 // All tasks and parameter containers are deleted automatically
222 // (via SetOwner())
223 //
224 MTaskList *tlist = new MTaskList;
225 tlist->SetOwner();
226
227 MParList *plist = new MParList;
228 plist->SetOwner();
229 plist->AddToList(tlist);
230 plist->AddToList(badpix);
231 plist->AddToList(seq);
232
233 MReadMarsFile *read = new MReadMarsFile(tname);
234 read->DisableAutoScheme();
235 if (seq->IsValid())
236 {
237 MDirIter iter;
238 if (seq->GetRuns(iter, MSequence::kCalibrated)<=0)
239 return;
240 read->AddFiles(iter);
241 }
242 else
243 read->AddFile(fname);
244 tlist->AddToList(read);
245
246 MGeomApply *apl = new MGeomApply;
247 tlist->AddToList(apl);
248
249 if (type==3)
250 {
251 MHPhotonEvent *phevt = new MHPhotonEvent;
252 phevt->PermanentReset();
253 plist->AddToList(phevt);
254
255 MFillH *fillh = new MFillH(phevt, "MPhotonEvent");
256 fillh->SetNameTab("Detector");
257 tlist->AddToList(fillh);
258
259 MSimGeomCam *simgeom = new MSimGeomCam;
260 tlist->AddToList(simgeom);
261
262 MSimSignalCam *sim = new MSimSignalCam;
263 tlist->AddToList(sim);
264 }
265
266 MContinue *mcevts = new MContinue("MRawEvtData.GetNumPixels==0", "ContEmpty");
267 if (type==2)
268 tlist->AddToList(mcevts);
269
270 MFEvtNumber *evtnum = new MFEvtNumber;
271 tlist->AddToList(evtnum);
272
273 MContinue *contevt = new MContinue(evtnum);
274 contevt->SetInverted();
275 tlist->AddToList(contevt);
276
277 MTriggerPatternDecode *decode = new MTriggerPatternDecode;
278 tlist->AddToList(decode);
279
280 //MArrivalTime *atime = new MArrivalTime;
281 //plist->AddToList(atime);
282
283 MHEvent *evt01 = new MHEvent(MHEvent::kEvtSignalDensity);
284 MHEvent *evt02 = new MHEvent(MHEvent::kEvtSignalDensity);
285 MHEvent *evt03 = new MHEvent(type==1?MHEvent::kEvtPedPhot:MHEvent::kEvtPedestal);
286 MHEvent *evt04 = new MHEvent(type==1?MHEvent::kEvtPedPhotRMS:MHEvent::kEvtPedestalRMS);
287 MHEvent *evt06a= new MHEvent(MHEvent::kEvtCleaningData);
288 MHEvent *evt06b= new MHEvent(MHEvent::kEvtCleaningLevels);
289 //MHEvent *evt07 = new MHEvent(MHEvent::kEvtIdxMax);
290 MHEvent *evt08 = new MHEvent(MHEvent::kEvtArrTime);
291 MHEvent *evt09 = new MHEvent(MHEvent::kEvtArrTimeCleaned);
292 //MHEvent *evt09 = new MHEvent(MHEvent::kEvtTrigPix);
293 MHEvent *evt10 = new MHEvent(MHEvent::kEvtIslandIndex);
294
295 evt01->SetName("Signal");
296 evt02->SetName("Cleaned");
297 evt03->SetName("Ped");
298 evt04->SetName("PedRMS");
299 evt06a->SetName("CleanData");
300 evt06b->SetName("Levels");
301 //evt07->SetName("MaxSliceIdx");
302 evt08->SetName("ArrTime");
303 evt09->SetName("Time");
304 evt10->SetName("Islands");
305
306 evt01->SetMinimum(0);
307 evt03->SetMinimum(0);
308 evt04->SetMinimum(0);
309 evt06a->SetMinimum(0);
310
311 // This makes sure, that the containers are deleted...
312 plist->AddToList(evt01);
313 plist->AddToList(evt02);
314 plist->AddToList(evt03);
315 plist->AddToList(evt04);
316 plist->AddToList(evt06a);
317 plist->AddToList(evt06b);
318 //plist->AddToList(evt07);
319 plist->AddToList(evt08);
320 plist->AddToList(evt09);
321 plist->AddToList(evt10);
322
323 MFillH *fill01 = new MFillH(evt01, "MSignalCam", "MFillH01");
324 MImgCleanStd *clean = new MImgCleanStd;
325 MFillH *fill02 = new MFillH(evt02, "MSignalCam", "MFillH02");
326 MFillH *fill03 = new MFillH(evt03, type==1?"MPedPhotFundamental":"MPedestalCam", "MFillH03");
327 MFillH *fill04 = new MFillH(evt04, type==1?"MPedPhotFromExtractorRndm":"MPedestalCam", "MFillH04");
328 MFillH *fill06a = new MFillH(evt06a, "MCameraData", "MFillH06a");
329 MFillH *fill06b = new MFillH(evt06b, "MCameraData", "MFillH06b");
330 MHillasCalc *hcalc = new MHillasCalc;
331 //MMcTriggerLvl2Calc *trcal = new MMcTriggerLvl2Calc;
332 //MFillH *fill09 = new MFillH(evt09, "MMcTriggerLvl2", "MFillH09");
333 MFillH *fill10 = new MFillH(evt10, "MSignalCam", "MFillH10");
334
335 MExtractTimeAndChargeDigitalFilter *digf = new MExtractTimeAndChargeDigitalFilter;
336 digf->SetNameWeightsFile("msignal/cosmics_weights46.dat");
337
338 MTaskEnv *taskenv1=new MTaskEnv("ExtractSignal");
339 taskenv1->SetDefault(digf);
340 taskenv1->SetOwner();
341
342 MSignalCalc *nanal = new MSignalCalc;
343
344 MBadPixelsCalc *bcalc = new MBadPixelsCalc;
345 MBadPixelsTreat *btreat = new MBadPixelsTreat;
346 btreat->SetProcessTimes(kFALSE);
347 if (type==1)
348 {
349 bcalc->SetNamePedPhotCam("MPedPhotFromExtractor");
350 btreat->AddNamePedPhotCam("MPedPhotFromExtractorRndm");
351 clean->SetNamePedPhotCam("MPedPhotFromExtractorRndm");
352 }
353
354 // If no pedestal or no calibration file is availble
355 if (type==2)
356 {
357 MFilter *f1=new MFDataMember("MRawRunHeader.fRunType", '>', 255.5);
358 f1->SetName("MFMonteCarlo");
359
360 MMcPedestalCopy *pcopy = new MMcPedestalCopy;
361 MMcPedestalNSBAdd *pdnsb = new MMcPedestalNSBAdd;
362
363 MCalibrationPatternDecode *decode = new MCalibrationPatternDecode;
364
365 MPedestalSubtract *pedsub1 = new MPedestalSubtract("PedSubstract1");
366 MPedestalSubtract *pedsub2 = new MPedestalSubtract("PedSubstract2");
367 pedsub2->SetNamePedestalCam();
368
369 MMcCalibrationUpdate* mcupd = new MMcCalibrationUpdate;
370 mcupd->SetOuterPixelsGainScaling(kFALSE);
371
372 MCalibrateData* calib = new MCalibrateData;
373 calib->SetCalibrationMode(MCalibrateData::kFlatCharge);
374 calib->SetPedestalFlag(MCalibrateData::kEvent);
375
376 // MPedestalCam is extracted using the simple MSignalCalc!
377
378 // MC
379 mcupd->SetFilter(f1);
380 //trcal->SetFilter(f1);
381
382 // TaskList
383 tlist->AddToList(f1);
384 tlist->AddToList(pcopy);
385 tlist->AddToList(pdnsb);
386
387 tlist->AddToList(decode);
388
389 tlist->AddToList(pedsub1); // Produce arrays
390 tlist->AddToList(nanal); // Estimate pedestal!
391 tlist->AddToList(pedsub2); // subtract pedestal
392
393 tlist->AddToList(taskenv1); // Calculates MExtractedSignalCam, MArrivalTimeCam
394 tlist->AddToList(mcupd);
395 tlist->AddToList(calib); // MExtractedSignalCam --> MSignalCam
396
397 //tlist->AddToList(bcalc); // Produce MBadPixelsCam
398 //tlist->AddToList(btreat); // Treat MBadPixelsCam
399 }
400
401 tlist->AddToList(fill01);
402 tlist->AddToList(clean);
403 tlist->AddToList(fill02);
404 if (type==2)
405 tlist->AddToList(fill03);
406 if (type!=3)
407 tlist->AddToList(fill04);
408 tlist->AddToList(fill06a);
409 tlist->AddToList(fill06b);
410 tlist->AddToList(fill10);
411 if (type==2)
412 {
413 //MFillH *fill07 = new MFillH(evt07, "MRawEvtData", "MFillH7");
414 MFillH *fill08 = new MFillH(evt08, "MArrivalTimeCam", "MFillH8");
415 //tlist->AddToList(fill07);
416 tlist->AddToList(fill08);
417
418 //tlist->AddToList(trcal);
419 //tlist->AddToList(fill09);
420 }
421 if (type==1 || type==3)
422 {
423 MFillH *fill08 = new MFillH(evt08, "MSignalCam", "MFillH8");
424 MFillH *fill09 = new MFillH(evt09, "MSignalCam", "MFillH9");
425 tlist->AddToList(fill08);
426 tlist->AddToList(fill09);
427 }
428 tlist->AddToList(hcalc);
429
430 // --------------------------------------------------
431 // Muon Analysis
432 MMuonSearchParCalc *muscalc = new MMuonSearchParCalc;
433 MMuonCalibParCalc *mcalc = new MMuonCalibParCalc;
434 MFillH *fillmuon = new MFillH("MHSingleMuon", "", "FillMuon");
435 fillmuon->SetNameTab("Muon");
436 tlist->AddToList(muscalc);
437 tlist->AddToList(fillmuon);
438 tlist->AddToList(mcalc);
439
440 // --------------------------------------------------
441 // Cut to steer the display
442 MContinue *cont0=new MContinue("", "Cut");
443 cont0->SetAllowEmpty();
444 tlist->AddToList(cont0);
445
446 //
447 // Now distribute Display to all tasks
448 //
449 fEvtLoop = new MEvtLoop(gSystem->BaseName(fname));
450 fEvtLoop->SetOwner();
451 fEvtLoop->SetParList(plist);
452 fEvtLoop->SetDisplay(this);
453 fEvtLoop->ReadEnv("mars.rc");
454
455}
456
457// --------------------------------------------------------------------------
458//
459// Add the top part of the frame: This is filename and treename display
460//
461void MEventDisplay::AddTopFramePart1(TGCompositeFrame *frame,
462 const char *filename,
463 const char *treename)
464{
465 //
466 // --- the top1 part of the window ---
467 //
468 TGHorizontalFrame *top1 = new TGHorizontalFrame(frame, 1, 1);
469 fList->Add(top1);
470
471 //
472 // create gui elements
473 //
474 TGLabel *file = new TGLabel(top1, new TGString(MString::Format("%s#%s", filename, treename)));
475 fList->Add(file);
476
477 //
478 // layout and add gui elements in/to frame
479 //
480 TGLayoutHints *laystd = new TGLayoutHints(kLHintsCenterX, 5, 5);
481 fList->Add(laystd);
482
483 top1->AddFrame(file, laystd);
484
485 //
486 // --- the top1 part of the window ---
487 //
488 TGHorizontalFrame *top2 = new TGHorizontalFrame(frame, 1, 1);
489 fList->Add(top2);
490
491 //
492 // layout and add frames
493 //
494 TGLayoutHints *laytop1 = new TGLayoutHints(kLHintsCenterX, 5, 5, 5);
495 fList->Add(laytop1);
496 frame->AddFrame(top1, laytop1);
497 frame->AddFrame(top2, laytop1);
498}
499
500// --------------------------------------------------------------------------
501//
502// Add the second part of the top frame: This are the event number controls
503//
504void MEventDisplay::AddTopFramePart2(TGCompositeFrame *frame)
505{
506 //
507 // --- the top2 part of the window ---
508 //
509 TGHorizontalFrame *top2 = new TGHorizontalFrame(frame, 1, 1);
510 fList->Add(top2);
511
512 //
513 // Create the gui elements
514 //
515 TGTextButton *prevevt = new TGTextButton(top2, " << ", kEvtPrev);
516 prevevt->Associate(this);
517
518 TGLabel *evtnr = new TGLabel(top2, new TGString("Event:"));
519
520 TGTextEntry *entry=new TGTextEntry(top2, new TGTextBuffer(100), kEvtNumber);
521 entry->Resize(60, entry->GetDefaultHeight());
522 entry->Associate(this);
523
524 fNumOfEvts = new TGLabel(top2, "of .");
525
526 TGTextButton *nextevt = new TGTextButton (top2, " >> ", kEvtNext);
527 nextevt->Associate(this);
528
529 //
530 // Add gui elements to 'atotodel'
531 //
532 fList->Add(prevevt);
533 fList->Add(evtnr);
534 fList->Add(entry);
535 fList->Add(fNumOfEvts);
536 fList->Add(nextevt);
537
538 //
539 // add the gui elements to the frame
540 //
541 TGLayoutHints *laystd = new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 5, 5);
542 fList->Add(laystd);
543
544 top2->AddFrame(prevevt, laystd);
545 top2->AddFrame(evtnr, laystd);
546 top2->AddFrame(entry, laystd);
547 top2->AddFrame(fNumOfEvts, laystd);
548 top2->AddFrame(nextevt, laystd);
549
550 TGLayoutHints *laystd2 = new TGLayoutHints(kLHintsCenterX, 5, 5, 5, 5);
551 fList->Add(laystd2);
552 frame->AddFrame(top2, laystd2);
553}
554
555void MEventDisplay::AddMiddleFrame(TGCompositeFrame *frame)
556{
557 //
558 // Create the gui elements
559 //
560 TGCheckButton *imgpar = new TGCheckButton(frame, "ImgPar", kShowImgPar);
561 imgpar->SetState(kButtonDown);
562 imgpar->Associate(this);
563 fList->Add(imgpar);
564
565 TGCheckButton *muon = new TGCheckButton(frame, "Muon", kShowMuon);
566 muon->Associate(this);
567 muon->SetState(kButtonDown);
568 fList->Add(muon);
569
570 //
571 // add the gui elements to the frame
572 //
573// TGLayoutHints *laystd = new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 5, 5);
574// fList->Add(laystd);
575// top2->AddFrame(prevevt, laystd);
576
577 frame->AddFrame(imgpar);
578 frame->AddFrame(muon);
579}
580
581// --------------------------------------------------------------------------
582//
583// Add the user frame part of the display
584//
585void MEventDisplay::AddUserFrame(const char* filename)
586{
587 fUserFrame->ChangeOptions(kHorizontalFrame);
588
589 TGCompositeFrame *vf1 = new TGVerticalFrame(fUserFrame, 1, 1);
590 TGCompositeFrame *vf2 = new TGVerticalFrame(fUserFrame, 1, 1);
591 TGCompositeFrame *hor = new TGHorizontalFrame(vf1, 1, 1);
592 TGCompositeFrame *ver = new TGVerticalFrame(hor, 1, 1);
593 TGCompositeFrame *vfb = new TGVerticalFrame(hor, 1, 1);
594
595 TGHorizontal3DLine *line = new TGHorizontal3DLine(vf1);
596 TGLayoutHints *expx = new TGLayoutHints(kLHintsExpandX);
597 TGLayoutHints *right = new TGLayoutHints(kLHintsRight|kLHintsTop);
598 fList->Add(line);
599 fList->Add(expx);
600 fList->Add(right);
601
602 hor->AddFrame(ver);
603 hor->AddFrame(vfb, right);
604
605 AddMiddleFrame(vfb);
606
607 //
608 // Add trailing line...
609 //
610 vf1->AddFrame(hor, expx);
611 vf1->AddFrame(line, expx);
612
613 AddTopFramePart1(ver, filename, "Events");
614 AddTopFramePart2(ver);
615
616 // create root embedded canvas and add it to the tab
617 TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas("Slices", vf2, vf1->GetDefaultHeight()*3/2, vf1->GetDefaultHeight(), 0);
618 vf2->AddFrame(ec);
619 fList->Add(ec);
620
621 // set background and border mode of the canvas
622 fCanvas = ec->GetCanvas();
623 fCanvas->SetBorderMode(0);
624 gROOT->GetListOfCanvases()->Add(fCanvas);
625 //fCanvas->SetBorderSize(1);
626 //fCanvas->SetBit(kNoContextMenu);
627 //fCanvas->SetFillColor(16);
628
629 fUserFrame->AddFrame(vf1, expx);
630 fUserFrame->AddFrame(vf2);
631}
632
633// --------------------------------------------------------------------------
634//
635// Checks if the event number is valid, and if so reads the new event
636// and updates the display
637//
638void MEventDisplay::ReadinEvent(Int_t dir)
639{
640 MParList *plist = (MParList*) fEvtLoop->GetParList();
641 MTaskList *tlist = (MTaskList*) fEvtLoop->GetTaskList();
642 MGeomCam *geom = (MGeomCam*) plist->FindObject("MGeomCam");
643 //MRawEvtData *raw = (MRawEvtData*)plist->FindObject("MRawEvtData");
644
645 //
646 // Read first event.
647 //
648 MReadTree *reader = (MReadTree*)fEvtLoop->FindTask("MRead");
649
650 const Int_t num = reader->GetNumEntry();
651
652 Int_t rc;
653 do
654 {
655 if (dir<0 && !reader->DecEventNum())
656 {
657 reader->SetEventNum(num);
658 return;
659 }
660 if (dir>0 && !reader->IncEventNum())
661 {
662 reader->SetEventNum(num);
663 return;
664 }
665
666 rc = tlist->Process();
667 if (rc==kFALSE || rc==kERROR)
668 return;
669
670 reader->DecEventNum();
671
672 // Define other continue conditions
673 //if (raw && raw->GetNumPixels()<1)
674 // rc = kCONTINUE;
675
676 } while (rc==kCONTINUE && dir!=0);
677
678 //
679 // Cleare the 'FADC canvas'
680 //
681 fCanvas->Clear();
682 fCanvas->Modified();
683 fCanvas->Update();
684
685 //
686 // Print parameters
687 //
688 *fLog << all;
689 fLog->Separator(MString::Format("Entry %d", reader->GetNumEntry()+1));
690
691 ((MHillas*) plist->FindObject("MHillas"))->Print(*geom);
692 ((MHillasExt*) plist->FindObject("MHillasExt"))->Print(*geom);
693 ((MHillasSrc*) plist->FindObject("MHillasSrc"))->Print(*geom);
694 plist->FindObject("MImagePar")->Print();
695 ((MNewImagePar*)plist->FindObject("MNewImagePar"))->Print(*geom);
696 plist->FindObject("MMuonCalibPar")->Print();
697 ((MMuonSearchPar*)plist->FindObject("MMuonSearchPar"))->Print(*geom);
698
699 //
700 // UpdateDisplay
701 //
702 gStyle->SetOptStat(1101);
703 Update();
704
705 TGTextEntry *entry = (TGTextEntry*)fList->FindWidget(kEvtNumber);
706 entry->SetText(MString::Format("%d", reader->GetNumEntry()+1));
707}
708
709void MEventDisplay::ShowHide()
710{
711 TGCheckButton *but1 = (TGCheckButton*)fList->FindWidget(kShowImgPar);
712 TGCheckButton *but2 = (TGCheckButton*)fList->FindWidget(kShowMuon);
713
714 const Bool_t imgpar = but1 && but1->IsDown();
715 const Bool_t muon = but2 && but2->IsDown();
716
717 //
718 // Get parlist
719 //
720 MParList *plist = fEvtLoop->GetParList();
721 if (!plist)
722 return;
723
724 //
725 // Draw ellipse on top of all pads
726 //
727 const Int_t n = 5;
728
729 TObject *obj[n] = {
730 plist->FindObject("MHillas"),
731 plist->FindObject("MHillasSrc"),
732 plist->FindObject("MHillasExt"),
733 plist->FindObject("MSrcPosCam"),
734 plist->FindObject("MMuonSearchPar")
735 };
736
737 const Bool_t state[n] = {
738 imgpar,
739 imgpar,
740 imgpar,
741 imgpar,
742 muon,
743 };
744
745 const Int_t ismc = plist->FindObject("MHPhotonEvent") ? 1 : 0;
746
747 for (int i=1; i<7; i++)
748 {
749 TCanvas *c = GetCanvas(i+ismc);
750 if (!c)
751 continue;
752
753 c->cd(1);
754
755 TList *list = gPad->GetListOfPrimitives();
756
757 for (int j=0;j<n; j++)
758 if (obj[j])
759 {
760 if (state[j] && !list->FindObject(obj[j]))
761 list->Add(obj[j]);
762 if (!state[j] && list->FindObject(obj[j]))
763 list->Remove(obj[j]);
764 }
765
766 gPad->Modified(kTRUE);
767 }
768}
769
770// --------------------------------------------------------------------------
771//
772// Read first event to get display booted
773//
774void MEventDisplay::ReadFirstEvent()
775{
776 const Int_t rc = fEvtLoop->PreProcess();
777 if (rc==kFALSE || rc==kERROR)
778 return;
779
780 UnLock();
781
782 //
783 // Now read event...
784 //
785 // FIXME: Can we safely replace ReadinEvent() by RedinEvent(1)?
786 ReadinEvent();
787
788 //
789 // After ReInit (MGeomCam might be read from RunHeaders): Add Geometry tab
790 //
791 AddGeometryTabs();
792
793 MReadTree *reader = (MReadTree*)fEvtLoop->FindTask("MRead");
794 TGString *txt = new TGString(MString::Format("of %d", reader->GetEntries()));
795 fNumOfEvts->SetText(txt);
796
797 ShowHide();
798}
799
800// --------------------------------------------------------------------------
801//
802// Adds the geometry tab
803//
804void MEventDisplay::AddGeometryTabs()
805{
806 MGeomCam *geom = (MGeomCam*)fEvtLoop->GetParList()->FindObject("MGeomCam");
807 if (!geom)
808 return;
809
810 TCanvas &c1=AddTab("Geometry");
811
812 MHCamera *cam = new MHCamera(*geom);
813 cam->SetBit(TH1::kNoStats|MHCamera::kNoLegend|kCanDelete);
814 cam->Draw("pixelindex");
815
816 c1.Modified();
817 c1.Update();
818
819 TCanvas &c2=AddTab("Sectors");
820
821 cam = new MHCamera(*geom);
822 cam->SetBit(TH1::kNoStats|MHCamera::kNoLegend|kCanDelete);
823 cam->Draw("sectorindex");
824
825 c2.Modified();
826 c2.Update();
827}
828
829// --------------------------------------------------------------------------
830//
831// ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
832//
833// Processes information from all GUI items.
834// Selecting an item usually generates an event with 4 parameters.
835// The first two are packed into msg (first and second bytes).
836// The other two are parm1 and parm2.
837//
838Bool_t MEventDisplay::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
839{
840 switch (GET_MSG(msg))
841 {
842 case kC_TEXTENTRY:
843 switch(GET_SUBMSG(msg))
844 {
845 case kTE_ENTER:
846 switch(GET_SUBMSG(msg))
847 {
848 case kTE_ENTER:
849 {
850 TGTextEntry *entry = (TGTextEntry*)fList->FindWidget(kEvtNumber);
851 MReadTree *reader = (MReadTree*)fEvtLoop->FindTask("MRead");
852 if (reader->SetEventNum(atoi(entry->GetText())-1))
853 ReadinEvent();
854 }
855 return kTRUE;
856 }
857 return kTRUE;
858 }
859 break;
860
861 case kC_COMMAND:
862 switch (GET_SUBMSG(msg))
863 {
864 case kCM_TAB:
865 {
866 //
867 // Set name for 'FADC canvas'. The name is the anchor for MHCamera.
868 // and clear the canvas
869 TCanvas *c = GetCanvas(mp1);
870 if (!c)
871 break;
872 MHEvent *o = (MHEvent*)fEvtLoop->GetParList()->FindObject(c->GetName());
873 if (!o)
874 break;
875 fCanvas->SetName(MString::Format("%p;%p;PixelContent", o->GetHist(), c->GetPad(1)));
876 }
877 break;
878
879 case kCM_BUTTON:
880 switch (mp1)
881 {
882 case kEvtPrev:
883 ReadinEvent(-1);
884 return kTRUE;
885
886 case kEvtNext:
887 ReadinEvent(+1);
888 return kTRUE;
889 }
890 return kTRUE;
891
892 case kCM_CHECKBUTTON:
893 switch (mp1)
894 {
895 case kShowMuon:
896 case kShowImgPar:
897 ShowHide();
898 return kTRUE;
899 }
900 return kTRUE;
901 }
902 break;
903 }
904
905 return MStatusDisplay::ProcessMessage(msg, mp1, mp2);
906}
Note: See TracBrowser for help on using the repository browser.