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

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