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

Last change on this file since 8517 was 8423, checked in by tbretz, 18 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
98// --------------------------------------------------------------------------
99//
100// Initialize the name and title of the task. Set fType to type
101//
102MHCamEvent::MHCamEvent(Int_t type, const char *name, const char *title)
103: fSum(NULL), fEvt(NULL), fType(type), fErrorSpread(kTRUE), fErrorRelative(kFALSE),
104fThreshold(0), fUseThreshold(0)
105{
106 Init(name, title);
107}
108
109// --------------------------------------------------------------------------
110//
111// Delete the corresponding camera display if available
112//
113MHCamEvent::~MHCamEvent()
114{
115 if (fSum)
116 delete fSum;
117}
118
119// --------------------------------------------------------------------------
120//
121// Get the event (MCamEvent) the histogram might be filled with. If
122// it is not given, it is assumed, that it is filled with the argument
123// of the Fill function.
124// Looks for the camera geometry MGeomCam and resets the sum histogram.
125//
126Bool_t MHCamEvent::SetupFill(const MParList *plist)
127{
128 fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
129 if (!fEvt)
130 {
131 if (!fNameEvt.IsNull())
132 {
133 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
134 return kFALSE;
135 }
136 *fLog << inf << GetDescriptor() << ": Assuming to get MCamEvent from Fill()..." << endl;
137 }
138
139 MGeomCam *cam = (MGeomCam*)plist->FindObject(fNameGeom, "MGeomCam");
140 if (!cam)
141 {
142 *fLog << err << fNameGeom << " [MGeomCam] not found... abort." << endl;
143 return kFALSE;
144 }
145
146 // Delete a possible old histogram from a previous loop
147 if (fSum)
148 delete (fSum);
149
150 // combine name
151 const TString name = fNameEvt.IsNull() ? fName : fNameEvt;
152
153 // create and setup MHCamera
154 fSum = new MHCamera(*cam, name+";avg");
155 if (fTitle!=gsDefTitle)
156 fSum->SetTitle(fTitle);
157 if (!fTitle.Contains(";"))
158 fSum->SetYTitle("a.u.");
159 fSum->SetBit(MHCamera::kProfile);
160 if (!fErrorSpread)
161 fSum->SetBit(MHCamera::kErrorMean);
162
163 return kTRUE;
164}
165
166// --------------------------------------------------------------------------
167//
168// Fill the histograms with data from a MCamEvent-Container.
169//
170Bool_t MHCamEvent::Fill(const MParContainer *par, const Stat_t w)
171{
172 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
173 if (!evt)
174 {
175 *fLog << err << dbginf << "Got no MCamEvent as argument of Fill()..." << endl;
176 return kFALSE;
177 }
178 if (fUseThreshold)
179 fSum->CntCamContent(*evt, fThreshold, fType, fUseThreshold>0);
180 else
181 fSum->AddCamContent(*evt, fType);
182 return kTRUE;
183}
184
185// --------------------------------------------------------------------------
186//
187// Take the mean of the sum histogram and print all pixel indices
188// which are above sum+s*rms
189//
190void MHCamEvent::PrintOutliers(Float_t s) const
191{
192 const Double_t mean = fSum->GetMean();
193 const Double_t rms = fSum->GetRMS();
194
195 *fLog << all << underline << GetDescriptor() << ": Mean=" << mean << ", Rms=" << rms << endl;
196
197 for (UInt_t i=0; i<fSum->GetNumPixels(); i++)
198 {
199 if (!fSum->IsUsed(i))
200 continue;
201
202 if ((*fSum)[i+1]>mean+s*rms)
203 *fLog << "Contents of Pixel-Index #" << i << ": " << (*fSum)[i+1] << " > " << s << "*rms" << endl;
204 }
205}
206
207// --------------------------------------------------------------------------
208//
209// Return fSum for "sum" and fRms for "rms"
210//
211TH1 *MHCamEvent::GetHistByName(const TString name) const
212{
213 return fSum;
214}
215
216// --------------------------------------------------------------------------
217//
218// Set the camera histogram to a clone of cam
219//
220void MHCamEvent::SetHist(const MHCamera &cam)
221{
222 if (fSum)
223 delete fSum;
224
225 fSum = static_cast<MHCamera*>(cam.Clone());
226}
227
228void MHCamEvent::Paint(Option_t *)
229{
230 TVirtualPad *pad = gPad;
231
232 pad->cd(2);
233 if (gPad->FindObject(Form("%s;proj", fName.Data())))
234 {
235 TH1 *h=fSum->Projection(Form("%s;proj", fName.Data()));
236 if (h->GetMaximum()>0)
237 gPad->SetLogy();
238 }
239
240 pad->cd(5);
241 if (gPad->FindObject(Form("%s;rad", fName.Data())))
242 fSum->RadialProfile(Form("%s;rad", fName.Data()));
243
244 pad->cd(6);
245 if (gPad->FindObject(Form("%s;az", fName.Data())))
246 fSum->AzimuthProfile(Form("%s;az", fName.Data()));
247
248 pad->cd(4);
249 gPad->cd(1);
250 MHCamera *cam = (MHCamera*)gPad->FindObject(Form("%s;err", fName.Data()));
251 if (cam)
252 cam->SetCamContent(*fSum, fErrorRelative ? 1 : 2);
253}
254
255void MHCamEvent::Draw(Option_t *)
256{
257 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
258 const Int_t col = pad->GetFillColor();
259 pad->SetBorderMode(0);
260
261 AppendPad();
262
263 TString name = Form("%s_1", pad->GetName());
264 TPad *p = new TPad(name,name,0.005, 0.5, 0.66, 0.995,col,0,0);
265 p->SetFrameBorderMode(0);
266 p->SetNumber(1);
267 p->Draw();
268 p->cd();
269 fSum->Draw("EPhist");
270
271 pad->cd();
272 name = Form("%s_2", pad->GetName());
273 p = new TPad(name,name,0.66, 0.5, 0.995, 0.995,col,0,0);
274 p->SetFrameBorderMode(0);
275 p->SetNumber(2);
276 p->Draw();
277 p->cd();
278 TH1 *h = fSum->Projection(Form("%s;proj", fName.Data()), 50);
279 h->SetTitle("Projection");
280 h->SetBit(kCanDelete);
281 h->Draw();
282
283 pad->cd();
284 name = Form("%s_3", pad->GetName());
285 p = new TPad(name,name,0.005, 0.005, 3./8, 0.5,col,0,0);
286 p->SetFrameBorderMode(0);
287 p->SetNumber(3);
288 p->Draw();
289 p->cd();
290 fSum->Draw();
291
292 pad->cd();
293 name = Form("%s_4", pad->GetName());
294 p = new TPad(name,name,3./8, 0.005, 6./8-0.005, 0.5,col,0,0);
295 p->SetFrameBorderMode(0);
296 p->SetNumber(4);
297 p->Draw();
298 p->cd();
299
300 TString e = "Sqrt(Variance)";
301 if (fSum->TestBit(MHCamera::kErrorMean))
302 e += "/Sqrt(n_{i})";
303 if (fErrorRelative)
304 e += "/v_{i}";
305
306 MHCamera *cam = new MHCamera(*fSum->GetGeometry());
307 cam->SetName(Form("%s;err", fName.Data()));
308 cam->SetTitle(e);
309 cam->SetYTitle(fSum->GetYaxis()->GetTitle());
310 cam->SetCamContent(*fSum, fErrorRelative ? 1 : 2);
311 cam->SetBit(kCanDelete);
312 cam->Draw();
313
314 pad->cd();
315 name = Form("%s_5", pad->GetName());
316 p = new TPad(name,name,6./8,0.25,0.995,0.5,col,0,0);
317 p->SetFrameBorderMode(0);
318 p->SetNumber(5);
319 p->Draw();
320 p->cd();
321 h = (TH1*)fSum->RadialProfile(Form("%s;rad", fName.Data()), 20);
322 h->SetTitle("Radial Profile");
323 h->SetBit(kCanDelete|TH1::kNoStats);
324 h->Draw();
325
326 pad->cd();
327 name = Form("%s_6", pad->GetName());
328 p = new TPad(name,name,6./8,0.005,0.995,0.25,col,0,0);
329 p->SetFrameBorderMode(0);
330 p->SetNumber(6);
331 p->Draw();
332 p->cd();
333 h = (TH1*)fSum->AzimuthProfile(Form("%s;az", fName.Data()), 30);
334 h->SetTitle("Azimuth Profile");
335 h->SetBit(kCanDelete|TH1::kNoStats);
336 h->Draw();
337}
338
Note: See TracBrowser for help on using the repository browser.