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

Last change on this file since 8284 was 8284, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 9.2 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), fThreshold(0), fUseThreshold(0)
93{
94 Init(name, title);
95}
96
97// --------------------------------------------------------------------------
98//
99// Initialize the name and title of the task. Set fType to type
100//
101MHCamEvent::MHCamEvent(Int_t type, const char *name, const char *title)
102 : fSum(NULL), fEvt(NULL), fType(type), fErrorSpread(kTRUE), fThreshold(0), fUseThreshold(0)
103{
104 Init(name, title);
105}
106
107// --------------------------------------------------------------------------
108//
109// Delete the corresponding camera display if available
110//
111MHCamEvent::~MHCamEvent()
112{
113 if (fSum)
114 delete fSum;
115}
116
117// --------------------------------------------------------------------------
118//
119// Get the event (MCamEvent) the histogram might be filled with. If
120// it is not given, it is assumed, that it is filled with the argument
121// of the Fill function.
122// Looks for the camera geometry MGeomCam and resets the sum histogram.
123//
124Bool_t MHCamEvent::SetupFill(const MParList *plist)
125{
126 fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
127 if (!fEvt)
128 {
129 if (!fNameEvt.IsNull())
130 {
131 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
132 return kFALSE;
133 }
134 *fLog << inf << GetDescriptor() << ": Assuming to get MCamEvent from Fill()..." << endl;
135 }
136
137 MGeomCam *cam = (MGeomCam*)plist->FindObject(fNameGeom, "MGeomCam");
138 if (!cam)
139 {
140 *fLog << err << fNameGeom << " [MGeomCam] not found... abort." << endl;
141 return kFALSE;
142 }
143
144 // Delete a possible old histogram from a previous loop
145 if (fSum)
146 delete (fSum);
147
148 // combine name
149 const TString name = fNameEvt.IsNull() ? fName : fNameEvt;
150
151 // create and setup MHCamera
152 fSum = new MHCamera(*cam, name+";avg");
153 if (fTitle!=gsDefTitle)
154 fSum->SetTitle(fTitle);
155 if (!fTitle.Contains(";"))
156 fSum->SetYTitle("a.u.");
157 fSum->SetBit(MHCamera::kProfile);
158 if (!fErrorSpread)
159 fSum->SetBit(MHCamera::kErrorMean);
160
161 fSum->SetXTitle("Pixel Idx");
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, 1);
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->SetNumber(1);
266 p->Draw();
267 p->cd();
268 fSum->Draw("EPhist");
269
270 pad->cd();
271 name = Form("%s_2", pad->GetName());
272 p = new TPad(name,name,0.66, 0.5, 0.995, 0.995,col,0,0);
273 p->SetNumber(2);
274 p->Draw();
275 p->cd();
276 TH1 *h = fSum->Projection(Form("%s;proj", fName.Data()), 50);
277 h->SetTitle("Projection");
278 h->SetBit(kCanDelete);
279 h->Draw();
280
281 pad->cd();
282 name = Form("%s_3", pad->GetName());
283 p = new TPad(name,name,0.005, 0.005, 3./8, 0.5,col,0,0);
284 p->SetNumber(3);
285 p->Draw();
286 p->cd();
287 fSum->Draw();
288
289 pad->cd();
290 name = Form("%s_4", pad->GetName());
291 p = new TPad(name,name,3./8, 0.005, 6./8-0.005, 0.5,col,0,0);
292 p->SetNumber(4);
293 p->Draw();
294 p->cd();
295
296 MHCamera *cam = new MHCamera(*fSum->GetGeometry());
297 cam->SetName(Form("%s;err", fName.Data()));
298 cam->SetTitle(fErrorSpread?"Sqrt(Variance)":"Sqrt(Variance)/Sqrt(n_{i})");
299 cam->SetYTitle(fSum->GetYaxis()->GetTitle());
300 cam->SetCamContent(*fSum, 1);
301 cam->SetBit(kCanDelete);
302 cam->Draw();
303
304 pad->cd();
305 name = Form("%s_5", pad->GetName());
306 p = new TPad(name,name,6./8,0.25,0.995,0.5,col,0,0);
307 p->SetNumber(5);
308 p->Draw();
309 p->cd();
310 h = (TH1*)fSum->RadialProfile(Form("%s;rad", fName.Data()), 20);
311 h->SetTitle("Radial Profile");
312 h->SetBit(kCanDelete|TH1::kNoStats);
313 h->Draw();
314
315 pad->cd();
316 name = Form("%s_6", pad->GetName());
317 p = new TPad(name,name,6./8,0.005,0.995,0.25,col,0,0);
318 p->SetNumber(6);
319 p->Draw();
320 p->cd();
321 h = (TH1*)fSum->AzimuthProfile(Form("%s;az", fName.Data()), 30);
322 h->SetTitle("Azimuth Profile");
323 h->SetBit(kCanDelete|TH1::kNoStats);
324 h->Draw();
325}
326
Note: See TracBrowser for help on using the repository browser.