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

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