source: trunk/Mars/mhist/MHEvent.cc@ 19427

Last change on this file since 19427 was 19360, checked in by tbretz, 6 years ago
Implemented the display of the hillas ellipse.
File size: 12.3 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, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MHEvent
28//
29// Display a single event in a canvas with as many informations as
30// possible, such as event number, run number, ...
31//
32// WARNING: This class is not yet ready!
33//
34// Input Containers:
35// MGeomCam
36// [MTaskList]
37// [MImgCleanStd]
38// [MRawEvtData]
39// [MRawRunHeader]
40// [MRawEvtHeader]
41//
42// Output Containers:
43// -/-
44//
45//////////////////////////////////////////////////////////////////////////////
46#include "MHEvent.h"
47
48#include <TStyle.h>
49#include <TCanvas.h>
50#include <TEllipse.h>
51#include <TPaveText.h>
52
53#include "MLog.h"
54#include "MLogManip.h"
55
56#include "MMcEvt.hxx"
57#include "MMcTrig.hxx"
58
59#include "MHillas.h"
60#include "MHCamera.h"
61#include "MParList.h"
62#include "MTaskList.h"
63#include "MParList.h"
64#include "MGeomCam.h"
65#include "MSignalCam.h"
66#include "MRawEvtHeader.h"
67#include "MRawRunHeader.h"
68#include "MRawEvtData.h"
69#include "MImgCleanStd.h"
70#include "MTriggerPattern.h"
71
72ClassImp(MHEvent);
73
74using namespace std;
75
76// --------------------------------------------------------------------------
77//
78MHEvent::MHEvent(EventType_t type) : fHist(NULL),
79 fType(type), fMinimum(-1111), fMaximum(-1111)
80{
81 fName = "MHEvent";
82 fTitle = "Single Event display task";
83
84 fClone = new MRawEvtData("MHEventData");
85 fTrigCpy = new MTriggerPattern;
86 fEllipse = new TEllipse;
87}
88
89// --------------------------------------------------------------------------
90//
91MHEvent::~MHEvent()
92{
93 if (fHist)
94 delete fHist;
95
96 delete fClone;
97 delete fTrigCpy;
98 delete fEllipse;
99}
100
101Bool_t MHEvent::SetupFill(const MParList *plist)
102{
103 MTaskList *tlist = (MTaskList*)plist->FindObject("MTaskList");
104
105 fImgCleanStd = tlist ? (MImgCleanStd*)tlist->FindObject("MImgCleanStd") : NULL;
106 fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
107 fTime = (MTime*)plist->FindObject("MTime");
108 fTrigger = (MTriggerPattern*)plist->FindObject("MTriggerPattern");
109 fHillas = (MHillas*)plist->FindObject("MHillas");
110
111 fRawEvtData = (MRawEvtData*)plist->FindObject("MRawEvtData");
112 if (!fRawEvtData)
113 *fLog << warn << "MRawEvtData not found..." << endl;
114
115 fRawRunHeader = (MRawRunHeader*)plist->FindObject("MRawRunHeader");
116 if (!fRawRunHeader)
117 *fLog << warn << dbginf << "MRawRunHeader not found..." << endl;
118
119 fRawEvtHeader = (MRawEvtHeader*)plist->FindObject("MRawEvtHeader");
120 if (!fRawEvtHeader)
121 *fLog << warn << dbginf << "MRawEvtHeader not found..." << endl;
122
123 MGeomCam *cam = (MGeomCam*)plist->FindObject("MGeomCam");
124 if (!cam)
125 {
126 *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
127 return kFALSE;
128 }
129
130 if (fHist)
131 delete (fHist);
132
133 fHist = new MHCamera(*cam);
134 fHist->AddNotify(fClone);
135
136 fHist->SetMinimum(fMinimum);
137 fHist->SetMaximum(fMaximum);
138
139 switch (fType)
140 {
141 case kEvtSignalRaw:
142 fHist->SetName("Signal (raw)");
143 fHist->SetYTitle("S [au]");
144 break;
145 case kEvtSignalDensity:
146 fHist->SetName("Signal density");
147 fHist->SetYTitle("S [au]");
148 break;
149 case kEvtSignalUncleaned:
150 fHist->SetName("Signal");
151 fHist->SetYTitle("S [au]");
152 break;
153 case kEvtPedestal:
154 fHist->SetName("Pedestal");
155 fHist->SetYTitle("P [au]");
156 break;
157 case kEvtPedestalRMS:
158 fHist->SetName("Pedestal RMS");
159 fHist->SetYTitle("\\sigma_{P} [au]");
160 break;
161 case kEvtPedPhot:
162 fHist->SetName("Pedestal");
163 fHist->SetYTitle("P [\\gamma]");
164 break;
165 case kEvtPedPhotRMS:
166 fHist->SetName("Pedestal RMS");
167 fHist->SetYTitle("\\sigma_{P} [\\gamma]");
168 break;
169 case kEvtCleaningLevels:
170 if (!fImgCleanStd)
171 {
172 *fLog << err << "MImgCleanStd not found... aborting." << endl;
173 return kFALSE;
174 }
175 fHist->SetName("CleanLevels");
176 fHist->SetYTitle("L");
177 break;
178 case kEvtCleaningData:
179 fHist->SetName("CleanData");
180 fHist->SetYTitle("L");
181 break;
182 case kEvtIdxMax:
183 fHist->SetName("Max Slice Idx");
184 fHist->SetYTitle("t [slice id]");
185 fHist->SetPrettyPalette();
186 break;
187 case kEvtArrTime:
188 case kEvtArrTimeCleaned:
189 fHist->SetName("Arrival Time");
190 fHist->SetYTitle("t [slice id]");
191 fHist->SetPrettyPalette();
192 break;
193 case kEvtTrigPix:
194 fHist->SetName("Triggered pix");
195 fHist->SetYTitle("ON/OFF");
196 fHist->SetPrettyPalette();
197 break;
198 case kEvtIslandIndex:
199 fHist->SetName("Island Index");
200 fHist->SetYTitle("Index");
201 fHist->SetPrettyPalette();
202 break;
203 case kEvtTimeSlope:
204 case kEvtTimeSlopeCleaned:
205 fHist->SetName("Time Slope");
206 fHist->SetYTitle("delta_t [ns]");
207 fHist->SetPrettyPalette();
208 break;
209 }
210
211 return kTRUE;
212}
213
214// --------------------------------------------------------------------------
215//
216// The geometry read from the RunHeaders might have changed. This does not
217// effect anything in PreProcess. So we set a new geometry. We don't move
218// this away from PreProcess to support also loops without calling ReInit.
219//
220Bool_t MHEvent::ReInit(MParList *plist)
221{
222 MGeomCam *cam = (MGeomCam*)plist->FindObject("MGeomCam");
223 if (!cam)
224 {
225 *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
226 return kFALSE;
227 }
228
229 fHist->SetGeometry(*cam);
230
231 return kTRUE;
232}
233
234Int_t MHEvent::Fill(const MParContainer *par, const Stat_t weight)
235{
236 if (fHist->IsFreezed())
237 return kTRUE;
238
239 if (!par)
240 {
241 *fLog << err << "ERROR - par==NULL... abort." << endl;
242 return kERROR;
243 }
244
245 const MCamEvent *event = dynamic_cast<const MCamEvent*>(par);
246 if (!event)
247 {
248 *fLog << err << par->GetDescriptor() << " doesn't inherit from MCamEvent... abort." << endl;
249 return kERROR;
250 }
251
252 if (fTrigger)
253 fTrigger->Copy(*fTrigCpy);
254
255 if (fRawEvtData)
256 fRawEvtData->Copy(*fClone);
257
258 if (fHillas && fEllipse)
259 {
260 TEllipse(fHillas->GetMeanX(), fHillas->GetMeanY(),
261 fHillas->GetLength(), fHillas->GetWidth(),
262 0, 360, fHillas->GetDelta()*TMath::RadToDeg()).Copy(*fEllipse);
263 fEllipse->SetLineWidth(2);
264 fEllipse->SetFillStyle(1);
265 }
266
267 switch (fType)
268 {
269 case kEvtSignalRaw: // Get Content without pixel-size scaling
270 fHist->SetCamContent(*event, 3);
271 break;
272 case kEvtSignalDensity:
273 fHist->SetCamContent(*event, 0);
274 break;
275 case kEvtSignalUncleaned:
276 fHist->SetCamContent(*event, 12);
277 break;
278 case kEvtPedestal:
279 fHist->SetCamContent(*event, 0);
280 break;
281 case kEvtPedestalRMS:
282 fHist->SetCamContent(*event, 2);
283 break;
284 case kEvtPedPhot:
285 fHist->SetCamContent(*event, 4);
286 break;
287 case kEvtPedPhotRMS:
288 fHist->SetCamContent(*event, 5);
289 break;
290 case kEvtCleaningLevels:
291 {
292 TArrayF lvl(2);
293 lvl[0] = fImgCleanStd->GetCleanLvl2();
294 lvl[1] = fImgCleanStd->GetCleanLvl1();
295 fHist->SetCamContent(*event, 0);
296 fHist->SetLevels(lvl);
297 }
298 break;
299 case kEvtCleaningData:
300 fHist->SetCamContent(*event, 0);
301 break;
302// case kEvtIdxMax:
303// fHist->SetCamContent(*event, 3/*5*/);
304// break;
305 case kEvtArrTime:
306 fHist->SetCamContent(*event, 6);
307 break;
308 case kEvtArrTimeCleaned:
309 fHist->SetCamContent(*event, 8);
310 break;
311 case kEvtTrigPix:
312 fHist->SetCamContent(*event, 0);
313 break;
314 case kEvtIslandIndex:
315 fHist->SetCamContent(*event, 5);
316 break;
317 case kEvtTimeSlope:
318 fHist->SetCamContent(*event, 13);
319 break;
320 case kEvtTimeSlopeCleaned:
321 fHist->SetCamContent(*event, 14);
322 break;
323 default:
324 *fLog << "ERROR - Case " << (int)fType << " not implemented..." << endl;
325 }
326
327 TString s;
328 if (fRawEvtHeader)
329 {
330 s += "Event #";
331 s += fRawEvtHeader->GetDAQEvtNumber();
332 }
333
334 if (fRawEvtHeader && fRawRunHeader)
335 s += " FileId #";
336
337 if (fRawEvtHeader)
338 s += fRawRunHeader->GetStringID();
339
340 if (fTime)
341 {
342 s += " (";
343 s += fTime->GetString();
344 s += ")";
345 }
346
347 if (fMcEvt)
348 s = fMcEvt->GetDescription(s);
349
350 gPad=NULL;
351 fHist->SetTitle(s);
352
353 return kTRUE;
354}
355
356void MHEvent::Paint(Option_t *o)
357{
358 TVirtualPad *pad = gPad;
359
360 if (TString(o).IsNull())
361 {
362 pad->GetPad(2)->cd(1);
363 if (gPad->FindObject("Proj"))
364 {
365 TH1 *h=fHist->Projection("Proj");
366 if (h->GetMaximum()>0)
367 gPad->SetLogy();
368 }
369
370 pad->GetPad(2)->cd(2);
371 if (gPad->FindObject("ProfRad"))
372 fHist->RadialProfile("ProfRad");
373
374 pad->GetPad(2)->cd(3);
375 if (gPad->FindObject("ProfAz"))
376 fHist->AzimuthProfile("ProfAz");
377 }
378
379 if (TString(o)=="1")
380 {
381 const Double_t r = fHist->GetGeometry()->GetMaxRadius();
382 TPaveText s4(0.82*r, -r, 0.90*r, -0.92*r, "br");
383 TPaveText s3(0.74*r, -r, 0.82*r, -0.92*r, "br");
384 TPaveText s2(0.66*r, -r, 0.74*r, -0.92*r, "br");
385 TPaveText s1(0.58*r, -r, 0.66*r, -0.92*r, "br");
386 TPaveText s0(0.50*r, -r, 0.58*r, -0.92*r, "br");
387 s0.SetBorderSize(1);
388 s1.SetBorderSize(1);
389 s2.SetBorderSize(1);
390 s3.SetBorderSize(1);
391 s4.SetBorderSize(1);
392 s0.AddText("P");
393 s1.AddText("C");
394 s2.AddText("1");
395 s3.AddText("2");
396 s4.AddText("S");
397
398 const Byte_t pat = fTrigCpy->GetUnprescaled();
399
400 s0.SetFillColor(pat&MTriggerPattern::kPedestal ? kBlue : kWhite);
401 s1.SetFillColor(pat&MTriggerPattern::kCalibration ? kBlue : kWhite);
402 s2.SetFillColor(pat&MTriggerPattern::kTriggerLvl1 ? kBlue : kWhite);
403 s3.SetFillColor(pat&MTriggerPattern::kTriggerLvl2 ? kBlue : kWhite);
404 s4.SetFillColor(pat&MTriggerPattern::kSumTrigger ? kBlue : kWhite);
405
406 s0.Paint();
407 s1.Paint();
408 s2.Paint();
409 s3.Paint();
410 s4.Paint();
411 }
412}
413
414void MHEvent::Draw(Option_t *)
415{
416 if (!fHist)
417 {
418 *fLog << warn << "MHEvent::Draw - fHist==NULL not initialized." << endl;
419 return;
420 }
421
422 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
423 pad->SetBorderMode(0);
424
425 AppendPad();
426
427 pad->Divide(2,1);
428
429 pad->cd(1);
430 gPad->SetPad(0.01, 0.01, 0.75, 0.99);
431 gPad->SetBorderMode(0);
432 fHist->Draw();
433 if (fEllipse && fHillas)
434 fEllipse->Draw();
435
436 AppendPad("1");
437
438 pad->cd(2);
439 gPad->SetPad(0.75, 0.01, 0.99, 0.99);
440 gPad->SetBorderMode(0);
441 gPad->Divide(1,3);
442
443 pad = gPad;
444
445 pad->cd(1);
446 gPad->SetBorderMode(0);
447
448 TH1 *h = fHist->Projection("Proj", 50);
449 h->SetTitle("Projection");
450 h->SetBit(kCanDelete);
451 h->Draw();
452
453 pad->cd(2);
454 gPad->SetBorderMode(0);
455
456 h = (TH1*)fHist->RadialProfile("ProfRad", 20);
457 h->SetTitle("Radial Profile");
458 h->SetBit(kCanDelete|TH1::kNoStats);
459 h->Draw();
460
461 pad->cd(3);
462 gPad->SetBorderMode(0);
463 h = (TH1*)fHist->AzimuthProfile("ProfAz", 30);
464 h->SetTitle("Azimuth Profile");
465 h->SetBit(kCanDelete|TH1::kNoStats);
466 h->Draw();
467}
468
Note: See TracBrowser for help on using the repository browser.