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

Last change on this file since 8279 was 8279, checked in by tbretz, 18 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, 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
216void MHCamEvent::Paint(Option_t *)
217{
218 TVirtualPad *pad = gPad;
219
220 pad->cd(2);
221 if (gPad->FindObject(Form("%s;proj", fName.Data())))
222 {
223 TH1 *h=fSum->Projection(Form("%s;proj", fName.Data()));
224 if (h->GetMaximum()>0)
225 gPad->SetLogy();
226 }
227
228 pad->cd(5);
229 if (gPad->FindObject(Form("%s;rad", fName.Data())))
230 fSum->RadialProfile(Form("%s;rad", fName.Data()));
231
232 pad->cd(6);
233 if (gPad->FindObject(Form("%s;az", fName.Data())))
234 fSum->AzimuthProfile(Form("%s;az", fName.Data()));
235
236 pad->cd(4);
237 gPad->cd(1);
238 MHCamera *cam = (MHCamera*)gPad->FindObject(Form("%s;err", fName.Data()));
239 if (cam)
240 cam->SetCamContent(*fSum, 1);
241}
242
243void MHCamEvent::Draw(Option_t *)
244{
245 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
246 const Int_t col = pad->GetFillColor();
247 pad->SetBorderMode(0);
248
249 AppendPad();
250
251 TString name = Form("%s_1", pad->GetName());
252 TPad *p = new TPad(name,name,0.005, 0.5, 0.66, 0.995,col,0,0);
253 p->SetNumber(1);
254 p->Draw();
255 p->cd();
256 fSum->Draw("EPhist");
257
258 pad->cd();
259 name = Form("%s_2", pad->GetName());
260 p = new TPad(name,name,0.66, 0.5, 0.995, 0.995,col,0,0);
261 p->SetNumber(2);
262 p->Draw();
263 p->cd();
264 TH1 *h = fSum->Projection(Form("%s;proj", fName.Data()), 50);
265 h->SetTitle("Projection");
266 h->SetBit(kCanDelete);
267 h->Draw();
268
269 pad->cd();
270 name = Form("%s_3", pad->GetName());
271 p = new TPad(name,name,0.005, 0.005, 3./8, 0.5,col,0,0);
272 p->SetNumber(3);
273 p->Draw();
274 p->cd();
275 fSum->Draw();
276
277 pad->cd();
278 name = Form("%s_4", pad->GetName());
279 p = new TPad(name,name,3./8, 0.005, 6./8-0.005, 0.5,col,0,0);
280 p->SetNumber(4);
281 p->Draw();
282 p->cd();
283
284 MHCamera *cam = new MHCamera(*fSum->GetGeometry());
285 cam->SetName(Form("%s;err", fName.Data()));
286 cam->SetTitle(fErrorSpread?"Sqrt(Variance)":"Sqrt(Variance)/Sqrt(n_{i})");
287 cam->SetYTitle(fSum->GetYaxis()->GetTitle());
288 cam->SetCamContent(*fSum, 1);
289 cam->SetBit(kCanDelete);
290 cam->Draw();
291
292 pad->cd();
293 name = Form("%s_5", pad->GetName());
294 p = new TPad(name,name,6./8,0.25,0.995,0.5,col,0,0);
295 p->SetNumber(5);
296 p->Draw();
297 p->cd();
298 h = (TH1*)fSum->RadialProfile(Form("%s;rad", fName.Data()), 20);
299 h->SetTitle("Radial Profile");
300 h->SetBit(kCanDelete|TH1::kNoStats);
301 h->Draw();
302
303 pad->cd();
304 name = Form("%s_6", pad->GetName());
305 p = new TPad(name,name,6./8,0.005,0.995,0.25,col,0,0);
306 p->SetNumber(6);
307 p->Draw();
308 p->cd();
309 h = (TH1*)fSum->AzimuthProfile(Form("%s;az", fName.Data()), 30);
310 h->SetTitle("Azimuth Profile");
311 h->SetBit(kCanDelete|TH1::kNoStats);
312 h->Draw();
313}
314
Note: See TracBrowser for help on using the repository browser.