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

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