source: branches/Mars_McMismatchStudy/mmain/MEventDisplay.cc@ 18454

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