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

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