source: trunk/MagicSoft/Mars/mhist/MHCamEvent.cc@ 8993

Last change on this file since 8993 was 8964, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 9.5 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, 12/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHCamEvent
28//
29// A histogram to store the sum of camera events. This can be photons,
30// currents or enything else derived from MCamEvent
31//
32// Setup
33// =====
34//
35// To count how often a certain pixel is above or below a threshold do:
36// MHCamEvent::SetThreshold(5.5); // Default=LowerBound
37// MHCamEvent::SetThreshold(5.5, MHCamEvent::kIsUpperBound);
38//
39//
40// Axis titles
41// ===========
42//
43// 1) If no other title is given 'a.u.' is used.
44// 2) If the title of MHCamEvent is different from the default,
45// it is used as histogram title. You can use this to set the
46// axis title, too. For more information see TH1::SetTitle, eg.
47// SetTitle("MyHist;;y[cm];Counts");
48// Make sure to set an empty x-axis title.
49//
50// For example:
51// MHCamEvent myhist("Titele;;y [cm]");
52//
53/////////////////////////////////////////////////////////////////////////////
54#include "MHCamEvent.h"
55
56#include "MLog.h"
57#include "MLogManip.h"
58
59#include "MParList.h"
60#include "MCamEvent.h"
61#include "MHCamera.h"
62
63#include "MGeomCam.h"
64
65ClassImp(MHCamEvent);
66
67using namespace std;
68
69const TString MHCamEvent::gsDefName = "MHCamEvent";
70const TString MHCamEvent::gsDefTitle = "Average of MCamEvents";
71
72// --------------------------------------------------------------------------
73//
74// Initialize the name and title of the task
75//
76void MHCamEvent::Init(const char *name, const char *title)
77{
78 //
79 // set the name and title of this object
80 //
81 fName = name ? name : gsDefName.Data();
82 fTitle = title ? title : gsDefTitle.Data();
83
84 fNameGeom = "MGeomCam";
85}
86
87// --------------------------------------------------------------------------
88//
89// Initialize the name and title of the task. Set fType to 0
90//
91MHCamEvent::MHCamEvent(const char *name, const char *title)
92: fSum(NULL), fEvt(NULL), fType(0), fErrorSpread(kTRUE), fErrorRelative(kFALSE),
93fThreshold(0), fUseThreshold(0)
94{
95 Init(name, title);
96
97 fSum = new MHCamera;
98}
99
100// --------------------------------------------------------------------------
101//
102// Initialize the name and title of the task. Set fType to type
103//
104MHCamEvent::MHCamEvent(Int_t type, const char *name, const char *title)
105: fSum(NULL), fEvt(NULL), fType(type), fErrorSpread(kTRUE), fErrorRelative(kFALSE),
106fThreshold(0), fUseThreshold(0)
107{
108 Init(name, title);
109
110 fSum = new MHCamera;
111}
112
113// --------------------------------------------------------------------------
114//
115// Delete the corresponding camera display if available
116//
117MHCamEvent::~MHCamEvent()
118{
119 if (fSum)
120 delete fSum;
121}
122
123// --------------------------------------------------------------------------
124//
125// Get the event (MCamEvent) the histogram might be filled with. If
126// it is not given, it is assumed, that it is filled with the argument
127// of the Fill function.
128// Looks for the camera geometry MGeomCam and resets the sum histogram.
129//
130Bool_t MHCamEvent::SetupFill(const MParList *plist)
131{
132 fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
133 if (!fEvt)
134 {
135 if (!fNameEvt.IsNull())
136 {
137 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
138 return kFALSE;
139 }
140 *fLog << inf << GetDescriptor() << ": Assuming to get MCamEvent from Fill()..." << endl;
141 }
142
143 MGeomCam *cam = (MGeomCam*)plist->FindObject(fNameGeom, "MGeomCam");
144 if (!cam)
145 {
146 *fLog << err << fNameGeom << " [MGeomCam] not found... abort." << endl;
147 return kFALSE;
148 }
149
150 // combine name
151 const TString name = fNameEvt.IsNull() ? fName : fNameEvt;
152
153 fSum->Reset();
154 fSum->SetGeometry(*cam, name+";avg");
155
156 if (fTitle!=gsDefTitle)
157 fSum->SetTitle(fTitle);
158 if (!fTitle.Contains(";"))
159 fSum->SetYTitle("a.u.");
160 fSum->SetBit(MHCamera::kProfile);
161 if (!fErrorSpread)
162 fSum->SetBit(MHCamera::kErrorMean);
163
164 return kTRUE;
165}
166
167// --------------------------------------------------------------------------
168//
169// Fill the histograms with data from a MCamEvent-Container.
170//
171Bool_t MHCamEvent::Fill(const MParContainer *par, const Stat_t w)
172{
173 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
174 if (!evt)
175 {
176 *fLog << err << dbginf << "Got no MCamEvent as argument of Fill()..." << endl;
177 return kFALSE;
178 }
179 if (fUseThreshold)
180 fSum->CntCamContent(*evt, fThreshold, fType, fUseThreshold>0);
181 else
182 fSum->AddCamContent(*evt, fType);
183 return kTRUE;
184}
185
186// --------------------------------------------------------------------------
187//
188// Take the mean of the sum histogram and print all pixel indices
189// which are above sum+s*rms
190//
191void MHCamEvent::PrintOutliers(Float_t s) const
192{
193 const Double_t mean = fSum->GetMean();
194 const Double_t rms = fSum->GetRMS();
195
196 *fLog << all << underline << GetDescriptor() << ": Mean=" << mean << ", Rms=" << rms << endl;
197
198 for (UInt_t i=0; i<fSum->GetNumPixels(); i++)
199 {
200 if (!fSum->IsUsed(i))
201 continue;
202
203 if ((*fSum)[i+1]>mean+s*rms)
204 *fLog << "Contents of Pixel-Index #" << i << ": " << (*fSum)[i+1] << " > " << s << "*rms" << endl;
205 }
206}
207
208// --------------------------------------------------------------------------
209//
210// Return fSum for "sum" and fRms for "rms"
211//
212TH1 *MHCamEvent::GetHistByName(const TString name) const
213{
214 return fSum;
215}
216
217// --------------------------------------------------------------------------
218//
219// Set the camera histogram to a clone of cam
220//
221void MHCamEvent::SetHist(const MHCamera &cam)
222{
223 if (fSum)
224 delete fSum;
225
226 fSum = static_cast<MHCamera*>(cam.Clone());
227}
228
229void MHCamEvent::Paint(Option_t *)
230{
231 TVirtualPad *pad = gPad;
232
233 pad->cd(2);
234 if (gPad->FindObject(Form("%s;proj", fName.Data())))
235 {
236 TH1 *h=fSum->Projection(Form("%s;proj", fName.Data()));
237 if (h->GetMaximum()>0)
238 gPad->SetLogy();
239 }
240
241 pad->cd(5);
242 if (gPad->FindObject(Form("%s;rad", fName.Data())))
243 fSum->RadialProfile(Form("%s;rad", fName.Data()));
244
245 pad->cd(6);
246 if (gPad->FindObject(Form("%s;az", fName.Data())))
247 fSum->AzimuthProfile(Form("%s;az", fName.Data()));
248
249 pad->cd(4);
250 gPad->cd(1);
251 MHCamera *cam = (MHCamera*)gPad->FindObject(Form("%s;err", fName.Data()));
252 if (cam)
253 cam->SetCamContent(*fSum, fErrorRelative ? 1 : 2);
254}
255
256void MHCamEvent::Draw(Option_t *)
257{
258 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
259 const Int_t col = pad->GetFillColor();
260 pad->SetBorderMode(0);
261
262 AppendPad();
263
264 TString name = Form("%s_1", pad->GetName());
265 TPad *p = new TPad(name,name,0.005, 0.5, 0.66, 0.995,col,0,0);
266 p->SetFrameBorderMode(0);
267 p->SetNumber(1);
268 p->Draw();
269 p->cd();
270 fSum->Draw("EPhist");
271
272 pad->cd();
273 name = Form("%s_2", pad->GetName());
274 p = new TPad(name,name,0.66, 0.5, 0.995, 0.995,col,0,0);
275 p->SetFrameBorderMode(0);
276 p->SetNumber(2);
277 p->Draw();
278 p->cd();
279 TH1 *h = fSum->Projection(Form("%s;proj", fName.Data()), 50);
280 h->SetTitle("Projection");
281 h->SetBit(kCanDelete);
282 h->Draw();
283
284 pad->cd();
285 name = Form("%s_3", pad->GetName());
286 p = new TPad(name,name,0.005, 0.005, 3./8, 0.5,col,0,0);
287 p->SetFrameBorderMode(0);
288 p->SetNumber(3);
289 p->Draw();
290 p->cd();
291 fSum->Draw();
292
293 pad->cd();
294 name = Form("%s_4", pad->GetName());
295 p = new TPad(name,name,3./8, 0.005, 6./8-0.005, 0.5,col,0,0);
296 p->SetFrameBorderMode(0);
297 p->SetNumber(4);
298 p->Draw();
299 p->cd();
300
301 TString e = "Sqrt(Variance)";
302 if (fSum->TestBit(MHCamera::kErrorMean))
303 e += "/Sqrt(n_{i})";
304 if (fErrorRelative)
305 e += "/v_{i}";
306
307 MHCamera *cam = new MHCamera(*fSum->GetGeometry());
308 cam->SetName(Form("%s;err", fName.Data()));
309 cam->SetTitle(e);
310 cam->SetYTitle(fSum->GetYaxis()->GetTitle());
311 cam->SetCamContent(*fSum, fErrorRelative ? 1 : 2);
312 cam->SetBit(kCanDelete);
313 cam->Draw();
314
315 pad->cd();
316 name = Form("%s_5", pad->GetName());
317 p = new TPad(name,name,6./8,0.25,0.995,0.5,col,0,0);
318 p->SetFrameBorderMode(0);
319 p->SetNumber(5);
320 p->Draw();
321 p->cd();
322 h = (TH1*)fSum->RadialProfile(Form("%s;rad", fName.Data()), 20);
323 h->SetTitle("Radial Profile");
324 h->SetBit(kCanDelete|TH1::kNoStats);
325 h->Draw();
326
327 pad->cd();
328 name = Form("%s_6", pad->GetName());
329 p = new TPad(name,name,6./8,0.005,0.995,0.25,col,0,0);
330 p->SetFrameBorderMode(0);
331 p->SetNumber(6);
332 p->Draw();
333 p->cd();
334 h = (TH1*)fSum->AzimuthProfile(Form("%s;az", fName.Data()), 30);
335 h->SetTitle("Azimuth Profile");
336 h->SetBit(kCanDelete|TH1::kNoStats);
337 h->Draw();
338}
339
Note: See TracBrowser for help on using the repository browser.