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

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