source: trunk/MagicSoft/Mars/mhist/MHEvent.cc@ 9312

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