source: tags/Mars-V0.9.5/mhist/MHCamEvent.cc

Last change on this file was 6977, checked in by tbretz, 20 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 <TCanvas.h>
57#include <TPaveStats.h>
58
59#include "MLog.h"
60#include "MLogManip.h"
61
62#include "MParList.h"
63#include "MCamEvent.h"
64#include "MHCamera.h"
65
66#include "MGeomCam.h"
67
68ClassImp(MHCamEvent);
69
70using namespace std;
71
72const TString MHCamEvent::gsDefName = "MHCamEvent";
73const TString MHCamEvent::gsDefTitle = "Average of MCamEvents";
74
75// --------------------------------------------------------------------------
76//
77// Initialize the name and title of the task
78//
79void MHCamEvent::Init(const char *name, const char *title)
80{
81 //
82 // set the name and title of this object
83 //
84 fName = name ? name : gsDefName.Data();
85 fTitle = title ? title : gsDefTitle.Data();
86
87 fNameGeom = "MGeomCam";
88}
89
90// --------------------------------------------------------------------------
91//
92// Initialize the name and title of the task. Set fType to 0
93//
94MHCamEvent::MHCamEvent(const char *name, const char *title)
95 : fSum(NULL), fEvt(NULL), fType(0), fThreshold(0), fUseThreshold(0)
96{
97 Init(name, title);
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), fThreshold(0), fUseThreshold(0)
106{
107 Init(name, title);
108}
109
110// --------------------------------------------------------------------------
111//
112// Delete the corresponding camera display if available
113//
114MHCamEvent::~MHCamEvent()
115{
116 if (fSum)
117 delete fSum;
118}
119
120// --------------------------------------------------------------------------
121//
122// Get the event (MCamEvent) the histogram might be filled with. If
123// it is not given, it is assumed, that it is filled with the argument
124// of the Fill function.
125// Looks for the camera geometry MGeomCam and resets the sum histogram.
126//
127Bool_t MHCamEvent::SetupFill(const MParList *plist)
128{
129 fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
130 if (!fEvt)
131 {
132 if (!fNameEvt.IsNull())
133 {
134 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
135 return kFALSE;
136 }
137 *fLog << inf << GetDescriptor() << ": Assuming to get MCamEvent from Fill()..." << endl;
138 }
139
140 MGeomCam *cam = (MGeomCam*)plist->FindObject(fNameGeom, "MGeomCam");
141 if (!cam)
142 {
143 *fLog << err << fNameGeom << " [MGeomCam] not found... abort." << endl;
144 return kFALSE;
145 }
146
147 // Delete a possible old histogram from a previous loop
148 if (fSum)
149 delete (fSum);
150
151 // combine name
152 const TString name = fNameEvt.IsNull() ? fName : fNameEvt;
153
154 // create and setup MHCamera
155 fSum = new MHCamera(*cam, name+";avg");
156 if (fTitle!=gsDefTitle)
157 fSum->SetTitle(fTitle);
158 if (!fTitle.Contains(";"))
159 fSum->SetYTitle("a.u.");
160 fSum->SetBit(MHCamera::kProfile);
161
162 fSum->SetXTitle("Pixel Idx");
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
217void MHCamEvent::Paint(Option_t *)
218{
219 TVirtualPad *pad = gPad;
220
221 pad->cd(2);
222 if (gPad->FindObject(Form("%s;proj", fName.Data())))
223 {
224 TH1 *h=fSum->Projection(Form("%s;proj", fName.Data()));
225 if (h->GetMaximum()>0)
226 gPad->SetLogy();
227 }
228
229 pad->cd(5);
230 if (gPad->FindObject(Form("%s;rad", fName.Data())))
231 fSum->RadialProfile(Form("%s;rad", fName.Data()));
232
233 pad->cd(6);
234 if (gPad->FindObject(Form("%s;az", fName.Data())))
235 fSum->AzimuthProfile(Form("%s;az", fName.Data()));
236
237 pad->cd(4);
238 gPad->cd(1);
239 MHCamera *cam = (MHCamera*)gPad->FindObject(Form("%s;err", fName.Data()));
240 if (cam)
241 cam->SetCamContent(*fSum, 1);
242}
243
244void MHCamEvent::Draw(Option_t *)
245{
246 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
247 const Int_t col = pad->GetFillColor();
248 pad->SetBorderMode(0);
249
250 AppendPad();
251
252 TString name = Form("%s_1", pad->GetName());
253 TPad *p = new TPad(name,name,0.005, 0.5, 0.66, 0.995,col,0,0);
254 p->SetNumber(1);
255 p->Draw();
256 p->cd();
257 fSum->Draw("EPhist");
258
259 pad->cd();
260 name = Form("%s_2", pad->GetName());
261 p = new TPad(name,name,0.66, 0.5, 0.995, 0.995,col,0,0);
262 p->SetNumber(2);
263 p->Draw();
264 p->cd();
265 TH1 *h = fSum->Projection(Form("%s;proj", fName.Data()), 50);
266 h->SetTitle("Projection");
267 h->SetBit(kCanDelete);
268 h->Draw();
269
270 pad->cd();
271 name = Form("%s_3", pad->GetName());
272 p = new TPad(name,name,0.005, 0.005, 3./8, 0.5,col,0,0);
273 p->SetNumber(3);
274 p->Draw();
275 p->cd();
276 fSum->Draw();
277
278 pad->cd();
279 name = Form("%s_4", pad->GetName());
280 p = new TPad(name,name,3./8, 0.005, 6./8-0.005, 0.5,col,0,0);
281 p->SetNumber(4);
282 p->Draw();
283 p->cd();
284
285 MHCamera *cam = new MHCamera(*fSum->GetGeometry());
286 cam->SetName(Form("%s;err", fName.Data()));
287 cam->SetTitle("Sqrt(Variance)");
288 cam->SetYTitle(fSum->GetYaxis()->GetTitle());
289 cam->SetCamContent(*fSum, 1);
290 cam->SetBit(kCanDelete);
291 cam->Draw();
292
293 pad->cd();
294 name = Form("%s_5", pad->GetName());
295 p = new TPad(name,name,6./8,0.25,0.995,0.5,col,0,0);
296 p->SetNumber(5);
297 p->Draw();
298 p->cd();
299 h = (TH1*)fSum->RadialProfile(Form("%s;rad", fName.Data()), 20);
300 h->SetTitle("Radial Profile");
301 h->SetBit(kCanDelete|TH1::kNoStats);
302 h->Draw();
303
304 pad->cd();
305 name = Form("%s_6", pad->GetName());
306 p = new TPad(name,name,6./8,0.005,0.995,0.25,col,0,0);
307 p->SetNumber(6);
308 p->Draw();
309 p->cd();
310 h = (TH1*)fSum->AzimuthProfile(Form("%s;az", fName.Data()), 30);
311 h->SetTitle("Azimuth Profile");
312 h->SetBit(kCanDelete|TH1::kNoStats);
313 h->Draw();
314}
315
Note: See TracBrowser for help on using the repository browser.