source: branches/MarsGapdTimeJitter/mhist/MHEvent.cc@ 18301

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