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

Last change on this file since 8389 was 8364, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 9.9 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, 3/*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 default:
259 *fLog << "ERROR - Case " << (int)fType << " not implemented..." << endl;
260 }
261
262 TString s;
263 if (fRawEvtHeader)
264 {
265 s += "Event #";
266 s += fRawEvtHeader->GetDAQEvtNumber();
267 }
268 if (fRawEvtHeader && fRawRunHeader)
269 s += " of ";
270
271 if (fRawRunHeader)
272 {
273 s += "Run #";
274 s += fRawRunHeader->GetRunNumber();
275 }
276 if (fTime)
277 {
278 s += " (";
279 s += fTime->GetString();
280 s += ")";
281 }
282
283 if (fMcEvt)
284 {
285 TString txt("#splitline{");
286
287 txt += fMcEvt->GetParticleName();
288 txt += " ";
289
290 s.Insert(0, txt);
291
292 s += "}{ E=";
293
294 s+= fMcEvt->GetEnergyStr();
295
296 s += " r=";
297 s += (int)(fMcEvt->GetImpact()/100+.5);
298 s += "m Zd=";
299 s += 0.1*TMath::Nint(fMcEvt->GetTelescopeTheta()*180/TMath::Pi()*10);
300 s += "\\circ ";
301 if (fMcEvt->GetPhotElfromShower()>=10000)
302 s += Form("%dk", (Int_t)(fMcEvt->GetPhotElfromShower()/1000.+.5));
303 else
304 if (fMcEvt->GetPhotElfromShower()>=1000)
305 s += Form("%.1fk", fMcEvt->GetPhotElfromShower()/1000.);
306 else
307 s += fMcEvt->GetPhotElfromShower();
308 s += "PhEl}";
309 }
310
311 gPad=NULL;
312 fHist->SetTitle(s);
313
314 return kTRUE;
315}
316
317void MHEvent::Paint(Option_t *)
318{
319 TVirtualPad *pad = gPad;
320
321 pad->GetPad(2)->cd(1);
322 if (gPad->FindObject(Form("Proj_%p", this)))
323 {
324 TH1 *h=fHist->Projection(Form("Proj_%p", this));
325 if (h->GetMaximum()>0)
326 gPad->SetLogy();
327 }
328
329 pad->GetPad(2)->cd(2);
330 if (gPad->FindObject(Form("ProfR_%p", this)))
331 fHist->RadialProfile(Form("ProfR_%p", this));
332
333 pad->GetPad(2)->cd(3);
334 if (gPad->FindObject(Form("ProfA_%p", this)))
335 fHist->AzimuthProfile(Form("ProfA_%p", this));
336}
337
338void MHEvent::Draw(Option_t *)
339{
340 if (!fHist)
341 {
342 *fLog << warn << "MHEvent::Draw - fHist==NULL not initialized." << endl;
343 return;
344 }
345
346 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
347 pad->SetBorderMode(0);
348
349 AppendPad();
350
351 pad->Divide(2,1);
352
353 pad->cd(1);
354 gPad->SetPad(0.01, 0.01, 0.75, 0.99);
355 gPad->SetBorderMode(0);
356 fHist->Draw();
357
358 pad->cd(2);
359 gPad->SetPad(0.75, 0.01, 0.99, 0.99);
360 gPad->SetBorderMode(0);
361 gPad->Divide(1,3);
362
363 pad = gPad;
364
365 pad->cd(1);
366 gPad->SetBorderMode(0);
367
368 TH1 *h = fHist->Projection(Form("Proj_%p", this), 50);
369 h->SetTitle("Projection");
370 h->SetBit(kCanDelete);
371 h->Draw();
372
373 pad->cd(2);
374 gPad->SetBorderMode(0);
375
376 h = (TH1*)fHist->RadialProfile(Form("ProfR_%p", this), 20);
377 h->SetTitle("Radial Profile");
378 h->SetBit(kCanDelete|TH1::kNoStats);
379 h->Draw();
380
381 pad->cd(3);
382 gPad->SetBorderMode(0);
383 h = (TH1*)fHist->AzimuthProfile(Form("ProfA_%p", this), 30);
384 h->SetTitle("Azimuth Profile");
385 h->SetBit(kCanDelete|TH1::kNoStats);
386 h->Draw();
387}
Note: See TracBrowser for help on using the repository browser.