source: tags/Mars-V0.9.5/mhist/MHEvent.cc

Last change on this file was 7297, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 9.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
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
193Bool_t MHEvent::Fill(const MParContainer *par, const Stat_t weight)
194{
195 if (fHist->IsFreezed())
196 return kTRUE;
197
198 if (!par)
199 return kFALSE;
200
201 const MCamEvent *event = dynamic_cast<const MCamEvent*>(par);
202 if (!event)
203 {
204 *fLog << err << par->GetDescriptor() << " doesn't inherit from MCamEvent... abort." << endl;
205 return kFALSE;
206 }
207
208 if (fRawEvtData)
209 fRawEvtData->Copy(*fClone);
210
211 switch (fType)
212 {
213 case kEvtSignalRaw: // Get Content without pixel-size scaling
214 fHist->SetCamContent(*event, 3);
215 break;
216 case kEvtSignalDensity:
217 fHist->SetCamContent(*event, 0);
218 break;
219 case kEvtPedestal:
220 fHist->SetCamContent(*event, 0);
221 break;
222 case kEvtPedestalRMS:
223 fHist->SetCamContent(*event, 2);
224 break;
225 case kEvtPedPhot:
226 fHist->SetCamContent(*event, 4);
227 break;
228 case kEvtPedPhotRMS:
229 fHist->SetCamContent(*event, 5);
230 break;
231 case kEvtCleaningLevels:
232 {
233 TArrayF lvl(2);
234 lvl[0] = fImgCleanStd->GetCleanLvl2();
235 lvl[1] = fImgCleanStd->GetCleanLvl1();
236 fHist->SetCamContent(*event, 0);
237 fHist->SetLevels(lvl);
238 }
239 break;
240 case kEvtCleaningData:
241 fHist->SetCamContent(*event, 0);
242 break;
243 case kEvtIdxMax:
244 fHist->SetCamContent(*event, 5);
245 break;
246 case kEvtArrTime:
247 fHist->SetCamContent(*event, 6);
248 break;
249 case kEvtArrTimeCleaned:
250 fHist->SetCamContent(*event, 8);
251 break;
252 case kEvtTrigPix:
253 fHist->SetCamContent(*event, 0);
254 break;
255 case kEvtIslandIndex:
256 fHist->SetCamContent(*event, 5);
257 break;
258 }
259
260 TString s;
261 if (fRawEvtHeader)
262 {
263 s += "Event #";
264 s += fRawEvtHeader->GetDAQEvtNumber();
265 }
266 if (fRawEvtHeader && fRawRunHeader)
267 s += " of ";
268
269 if (fRawRunHeader)
270 {
271 s += "Run #";
272 s += fRawRunHeader->GetRunNumber();
273 }
274 if (fTime)
275 {
276 s += " (";
277 s += fTime->GetString();
278 s += ")";
279 }
280
281 if (fMcEvt)
282 {
283 TString txt("#splitline{");
284
285 txt += fMcEvt->GetParticleName();
286 txt += " ";
287
288 s.Insert(0, txt);
289
290 s += "}{ E=";
291
292 s+= fMcEvt->GetEnergyStr();
293
294 s += " r=";
295 s += (int)(fMcEvt->GetImpact()/100+.5);
296 s += "m Zd=";
297 s += (int)(fMcEvt->GetTheta()*180/TMath::Pi()+.5);
298 s += "\\circ ";
299 if (fMcEvt->GetPhotElfromShower()>=10000)
300 s += Form("%dk", (Int_t)(fMcEvt->GetPhotElfromShower()/1000.+.5));
301 else
302 if (fMcEvt->GetPhotElfromShower()>=1000)
303 s += Form("%.1fk", fMcEvt->GetPhotElfromShower()/1000.);
304 else
305 s += fMcEvt->GetPhotElfromShower();
306 s += "PhEl}";
307 }
308
309 gPad=NULL;
310 fHist->SetTitle(s);
311
312 return kTRUE;
313}
314
315void MHEvent::Paint(Option_t *)
316{
317 TVirtualPad *pad = gPad;
318
319 pad->GetPad(2)->cd(1);
320 if (gPad->FindObject(Form("Proj_%p", this)))
321 {
322 TH1 *h=fHist->Projection(Form("Proj_%p", this));
323 if (h->GetMaximum()>0)
324 gPad->SetLogy();
325 }
326
327 pad->GetPad(2)->cd(2);
328 if (gPad->FindObject(Form("ProfR_%p", this)))
329 fHist->RadialProfile(Form("ProfR_%p", this));
330
331 pad->GetPad(2)->cd(3);
332 if (gPad->FindObject(Form("ProfA_%p", this)))
333 fHist->AzimuthProfile(Form("ProfA_%p", this));
334}
335
336void MHEvent::Draw(Option_t *)
337{
338 if (!fHist)
339 {
340 *fLog << warn << "MHEvent::Draw - fHist==NULL not initialized." << endl;
341 return;
342 }
343
344 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
345 pad->SetBorderMode(0);
346
347 AppendPad();
348
349 pad->Divide(2,1);
350
351 pad->cd(1);
352 gPad->SetPad(0.01, 0.01, 0.75, 0.99);
353 gPad->SetBorderMode(0);
354 fHist->Draw();
355
356 pad->cd(2);
357 gPad->SetPad(0.75, 0.01, 0.99, 0.99);
358 gPad->SetBorderMode(0);
359 gPad->Divide(1,3);
360
361 pad = gPad;
362
363 pad->cd(1);
364 gPad->SetBorderMode(0);
365
366 TH1 *h = fHist->Projection(Form("Proj_%p", this), 50);
367 h->SetTitle("Projection");
368 h->SetBit(kCanDelete);
369 h->Draw();
370
371 pad->cd(2);
372 gPad->SetBorderMode(0);
373
374 h = (TH1*)fHist->RadialProfile(Form("ProfR_%p", this), 20);
375 h->SetTitle("Radial Profile");
376 h->SetBit(kCanDelete|TH1::kNoStats);
377 h->Draw();
378
379 pad->cd(3);
380 gPad->SetBorderMode(0);
381 h = (TH1*)fHist->AzimuthProfile(Form("ProfA_%p", this), 30);
382 h->SetTitle("Azimuth Profile");
383 h->SetBit(kCanDelete|TH1::kNoStats);
384 h->Draw();
385}
Note: See TracBrowser for help on using the repository browser.