source: branches/Mars_use_drstimefiles/mhist/MHEvent.cc@ 18605

Last change on this file since 18605 was 13365, checked in by tbretz, 13 years ago
Added two more modes.
File size: 11.5 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 kEvtSignalUncleaned:
145 fHist->SetName("Signal");
146 fHist->SetYTitle("S [au]");
147 break;
148 case kEvtPedestal:
149 fHist->SetName("Pedestal");
150 fHist->SetYTitle("P [au]");
151 break;
152 case kEvtPedestalRMS:
153 fHist->SetName("Pedestal RMS");
154 fHist->SetYTitle("\\sigma_{P} [au]");
155 break;
156 case kEvtPedPhot:
157 fHist->SetName("Pedestal");
158 fHist->SetYTitle("P [\\gamma]");
159 break;
160 case kEvtPedPhotRMS:
161 fHist->SetName("Pedestal RMS");
162 fHist->SetYTitle("\\sigma_{P} [\\gamma]");
163 break;
164 case kEvtCleaningLevels:
165 if (!fImgCleanStd)
166 {
167 *fLog << err << "MImgCleanStd not found... aborting." << endl;
168 return kFALSE;
169 }
170 fHist->SetName("CleanLevels");
171 fHist->SetYTitle("L");
172 break;
173 case kEvtCleaningData:
174 fHist->SetName("CleanData");
175 fHist->SetYTitle("L");
176 break;
177 case kEvtIdxMax:
178 fHist->SetName("Max Slice Idx");
179 fHist->SetYTitle("t [slice id]");
180 fHist->SetPrettyPalette();
181 break;
182 case kEvtArrTime:
183 case kEvtArrTimeCleaned:
184 fHist->SetName("Arrival Time");
185 fHist->SetYTitle("t [slice id]");
186 fHist->SetPrettyPalette();
187 break;
188 case kEvtTrigPix:
189 fHist->SetName("Triggered pix");
190 fHist->SetYTitle("ON/OFF");
191 fHist->SetPrettyPalette();
192 break;
193 case kEvtIslandIndex:
194 fHist->SetName("Island Index");
195 fHist->SetYTitle("Index");
196 fHist->SetPrettyPalette();
197 break;
198 }
199
200 return kTRUE;
201}
202
203// --------------------------------------------------------------------------
204//
205// The geometry read from the RunHeaders might have changed. This does not
206// effect anything in PreProcess. So we set a new geometry. We don't move
207// this away from PreProcess to support also loops without calling ReInit.
208//
209Bool_t MHEvent::ReInit(MParList *plist)
210{
211 MGeomCam *cam = (MGeomCam*)plist->FindObject("MGeomCam");
212 if (!cam)
213 {
214 *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
215 return kFALSE;
216 }
217
218 fHist->SetGeometry(*cam);
219
220 return kTRUE;
221}
222
223Int_t MHEvent::Fill(const MParContainer *par, const Stat_t weight)
224{
225 if (fHist->IsFreezed())
226 return kTRUE;
227
228 if (!par)
229 {
230 *fLog << err << "ERROR - par==NULL... abort." << endl;
231 return kERROR;
232 }
233
234 const MCamEvent *event = dynamic_cast<const MCamEvent*>(par);
235 if (!event)
236 {
237 *fLog << err << par->GetDescriptor() << " doesn't inherit from MCamEvent... abort." << endl;
238 return kERROR;
239 }
240
241 if (fTrigger)
242 fTrigger->Copy(*fTrigCpy);
243
244 if (fRawEvtData)
245 fRawEvtData->Copy(*fClone);
246
247 switch (fType)
248 {
249 case kEvtSignalRaw: // Get Content without pixel-size scaling
250 fHist->SetCamContent(*event, 3);
251 break;
252 case kEvtSignalDensity:
253 fHist->SetCamContent(*event, 0);
254 break;
255 case kEvtSignalUncleaned:
256 fHist->SetCamContent(*event, 12);
257 break;
258 case kEvtPedestal:
259 fHist->SetCamContent(*event, 0);
260 break;
261 case kEvtPedestalRMS:
262 fHist->SetCamContent(*event, 2);
263 break;
264 case kEvtPedPhot:
265 fHist->SetCamContent(*event, 4);
266 break;
267 case kEvtPedPhotRMS:
268 fHist->SetCamContent(*event, 5);
269 break;
270 case kEvtCleaningLevels:
271 {
272 TArrayF lvl(2);
273 lvl[0] = fImgCleanStd->GetCleanLvl2();
274 lvl[1] = fImgCleanStd->GetCleanLvl1();
275 fHist->SetCamContent(*event, 0);
276 fHist->SetLevels(lvl);
277 }
278 break;
279 case kEvtCleaningData:
280 fHist->SetCamContent(*event, 0);
281 break;
282// case kEvtIdxMax:
283// fHist->SetCamContent(*event, 3/*5*/);
284// break;
285 case kEvtArrTime:
286 fHist->SetCamContent(*event, 6);
287 break;
288 case kEvtArrTimeCleaned:
289 fHist->SetCamContent(*event, 8);
290 break;
291 case kEvtTrigPix:
292 fHist->SetCamContent(*event, 0);
293 break;
294 case kEvtIslandIndex:
295 fHist->SetCamContent(*event, 5);
296 break;
297 default:
298 *fLog << "ERROR - Case " << (int)fType << " not implemented..." << endl;
299 }
300
301 TString s;
302 if (fRawEvtHeader)
303 {
304 s += "Event #";
305 s += fRawEvtHeader->GetDAQEvtNumber();
306 }
307
308 if (fRawEvtHeader && fRawRunHeader)
309 s += " FileId #";
310
311 if (fRawEvtHeader)
312 s += fRawRunHeader->GetStringID();
313
314 if (fTime)
315 {
316 s += " (";
317 s += fTime->GetString();
318 s += ")";
319 }
320
321 if (fMcEvt)
322 s = fMcEvt->GetDescription(s);
323
324 gPad=NULL;
325 fHist->SetTitle(s);
326
327 return kTRUE;
328}
329
330void MHEvent::Paint(Option_t *o)
331{
332 TVirtualPad *pad = gPad;
333
334 if (TString(o).IsNull())
335 {
336 pad->GetPad(2)->cd(1);
337 if (gPad->FindObject("Proj"))
338 {
339 TH1 *h=fHist->Projection("Proj");
340 if (h->GetMaximum()>0)
341 gPad->SetLogy();
342 }
343
344 pad->GetPad(2)->cd(2);
345 if (gPad->FindObject("ProfRad"))
346 fHist->RadialProfile("ProfRad");
347
348 pad->GetPad(2)->cd(3);
349 if (gPad->FindObject("ProfAz"))
350 fHist->AzimuthProfile("ProfAz");
351 }
352
353 if (TString(o)=="1")
354 {
355 const Double_t r = fHist->GetGeometry()->GetMaxRadius();
356 TPaveText s4(0.82*r, -r, 0.90*r, -0.92*r, "br");
357 TPaveText s3(0.74*r, -r, 0.82*r, -0.92*r, "br");
358 TPaveText s2(0.66*r, -r, 0.74*r, -0.92*r, "br");
359 TPaveText s1(0.58*r, -r, 0.66*r, -0.92*r, "br");
360 TPaveText s0(0.50*r, -r, 0.58*r, -0.92*r, "br");
361 s0.SetBorderSize(1);
362 s1.SetBorderSize(1);
363 s2.SetBorderSize(1);
364 s3.SetBorderSize(1);
365 s4.SetBorderSize(1);
366 s0.AddText("P");
367 s1.AddText("C");
368 s2.AddText("1");
369 s3.AddText("2");
370 s4.AddText("S");
371
372 const Byte_t pat = fTrigCpy->GetUnprescaled();
373
374 s0.SetFillColor(pat&MTriggerPattern::kPedestal ? kBlue : kWhite);
375 s1.SetFillColor(pat&MTriggerPattern::kCalibration ? kBlue : kWhite);
376 s2.SetFillColor(pat&MTriggerPattern::kTriggerLvl1 ? kBlue : kWhite);
377 s3.SetFillColor(pat&MTriggerPattern::kTriggerLvl2 ? kBlue : kWhite);
378 s4.SetFillColor(pat&MTriggerPattern::kSumTrigger ? kBlue : kWhite);
379
380 s0.Paint();
381 s1.Paint();
382 s2.Paint();
383 s3.Paint();
384 s4.Paint();
385 }
386}
387
388void MHEvent::Draw(Option_t *)
389{
390 if (!fHist)
391 {
392 *fLog << warn << "MHEvent::Draw - fHist==NULL not initialized." << endl;
393 return;
394 }
395
396 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
397 pad->SetBorderMode(0);
398
399 AppendPad();
400
401 pad->Divide(2,1);
402
403 pad->cd(1);
404 gPad->SetPad(0.01, 0.01, 0.75, 0.99);
405 gPad->SetBorderMode(0);
406 fHist->Draw();
407
408 AppendPad("1");
409
410 pad->cd(2);
411 gPad->SetPad(0.75, 0.01, 0.99, 0.99);
412 gPad->SetBorderMode(0);
413 gPad->Divide(1,3);
414
415 pad = gPad;
416
417 pad->cd(1);
418 gPad->SetBorderMode(0);
419
420 TH1 *h = fHist->Projection("Proj", 50);
421 h->SetTitle("Projection");
422 h->SetBit(kCanDelete);
423 h->Draw();
424
425 pad->cd(2);
426 gPad->SetBorderMode(0);
427
428 h = (TH1*)fHist->RadialProfile("ProfRad", 20);
429 h->SetTitle("Radial Profile");
430 h->SetBit(kCanDelete|TH1::kNoStats);
431 h->Draw();
432
433 pad->cd(3);
434 gPad->SetBorderMode(0);
435 h = (TH1*)fHist->AzimuthProfile("ProfAz", 30);
436 h->SetTitle("Azimuth Profile");
437 h->SetBit(kCanDelete|TH1::kNoStats);
438 h->Draw();
439}
440
Note: See TracBrowser for help on using the repository browser.