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

Last change on this file since 7970 was 7832, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 8.8 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), 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), 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
159 fSum->SetXTitle("Pixel Idx");
160
161 return kTRUE;
162}
163
164// --------------------------------------------------------------------------
165//
166// Fill the histograms with data from a MCamEvent-Container.
167//
168Bool_t MHCamEvent::Fill(const MParContainer *par, const Stat_t w)
169{
170 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
171 if (!evt)
172 {
173 *fLog << err << dbginf << "Got no MCamEvent as argument of Fill()..." << endl;
174 return kFALSE;
175 }
176 if (fUseThreshold)
177 fSum->CntCamContent(*evt, fThreshold, fType, fUseThreshold>0);
178 else
179 fSum->AddCamContent(*evt, fType);
180 return kTRUE;
181}
182
183// --------------------------------------------------------------------------
184//
185// Take the mean of the sum histogram and print all pixel indices
186// which are above sum+s*rms
187//
188void MHCamEvent::PrintOutliers(Float_t s) const
189{
190 const Double_t mean = fSum->GetMean();
191 const Double_t rms = fSum->GetRMS();
192
193 *fLog << all << underline << GetDescriptor() << ": Mean=" << mean << ", Rms=" << rms << endl;
194
195 for (UInt_t i=0; i<fSum->GetNumPixels(); i++)
196 {
197 if (!fSum->IsUsed(i))
198 continue;
199
200 if ((*fSum)[i+1]>mean+s*rms)
201 *fLog << "Contents of Pixel-Index #" << i << ": " << (*fSum)[i+1] << " > " << s << "*rms" << endl;
202 }
203}
204
205// --------------------------------------------------------------------------
206//
207// Return fSum for "sum" and fRms for "rms"
208//
209TH1 *MHCamEvent::GetHistByName(const TString name) const
210{
211 return fSum;
212}
213
214void MHCamEvent::Paint(Option_t *)
215{
216 TVirtualPad *pad = gPad;
217
218 pad->cd(2);
219 if (gPad->FindObject(Form("%s;proj", fName.Data())))
220 {
221 TH1 *h=fSum->Projection(Form("%s;proj", fName.Data()));
222 if (h->GetMaximum()>0)
223 gPad->SetLogy();
224 }
225
226 pad->cd(5);
227 if (gPad->FindObject(Form("%s;rad", fName.Data())))
228 fSum->RadialProfile(Form("%s;rad", fName.Data()));
229
230 pad->cd(6);
231 if (gPad->FindObject(Form("%s;az", fName.Data())))
232 fSum->AzimuthProfile(Form("%s;az", fName.Data()));
233
234 pad->cd(4);
235 gPad->cd(1);
236 MHCamera *cam = (MHCamera*)gPad->FindObject(Form("%s;err", fName.Data()));
237 if (cam)
238 cam->SetCamContent(*fSum, 1);
239}
240
241void MHCamEvent::Draw(Option_t *)
242{
243 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
244 const Int_t col = pad->GetFillColor();
245 pad->SetBorderMode(0);
246
247 AppendPad();
248
249 TString name = Form("%s_1", pad->GetName());
250 TPad *p = new TPad(name,name,0.005, 0.5, 0.66, 0.995,col,0,0);
251 p->SetNumber(1);
252 p->Draw();
253 p->cd();
254 fSum->Draw("EPhist");
255
256 pad->cd();
257 name = Form("%s_2", pad->GetName());
258 p = new TPad(name,name,0.66, 0.5, 0.995, 0.995,col,0,0);
259 p->SetNumber(2);
260 p->Draw();
261 p->cd();
262 TH1 *h = fSum->Projection(Form("%s;proj", fName.Data()), 50);
263 h->SetTitle("Projection");
264 h->SetBit(kCanDelete);
265 h->Draw();
266
267 pad->cd();
268 name = Form("%s_3", pad->GetName());
269 p = new TPad(name,name,0.005, 0.005, 3./8, 0.5,col,0,0);
270 p->SetNumber(3);
271 p->Draw();
272 p->cd();
273 fSum->Draw();
274
275 pad->cd();
276 name = Form("%s_4", pad->GetName());
277 p = new TPad(name,name,3./8, 0.005, 6./8-0.005, 0.5,col,0,0);
278 p->SetNumber(4);
279 p->Draw();
280 p->cd();
281
282 MHCamera *cam = new MHCamera(*fSum->GetGeometry());
283 cam->SetName(Form("%s;err", fName.Data()));
284 cam->SetTitle("Sqrt(Variance)");
285 cam->SetYTitle(fSum->GetYaxis()->GetTitle());
286 cam->SetCamContent(*fSum, 1);
287 cam->SetBit(kCanDelete);
288 cam->Draw();
289
290 pad->cd();
291 name = Form("%s_5", pad->GetName());
292 p = new TPad(name,name,6./8,0.25,0.995,0.5,col,0,0);
293 p->SetNumber(5);
294 p->Draw();
295 p->cd();
296 h = (TH1*)fSum->RadialProfile(Form("%s;rad", fName.Data()), 20);
297 h->SetTitle("Radial Profile");
298 h->SetBit(kCanDelete|TH1::kNoStats);
299 h->Draw();
300
301 pad->cd();
302 name = Form("%s_6", pad->GetName());
303 p = new TPad(name,name,6./8,0.005,0.995,0.25,col,0,0);
304 p->SetNumber(6);
305 p->Draw();
306 p->cd();
307 h = (TH1*)fSum->AzimuthProfile(Form("%s;az", fName.Data()), 30);
308 h->SetTitle("Azimuth Profile");
309 h->SetBit(kCanDelete|TH1::kNoStats);
310 h->Draw();
311}
312
Note: See TracBrowser for help on using the repository browser.