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

Last change on this file since 6086 was 6032, checked in by tbretz, 20 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 plot the variance instead of the rms use:
36// MHCamEvent::SetBit(MHCamera::kVariance);
37// or
38// MHCamEvent::EnableVariance()
39//
40// To count how often a certain pixel is above or below a threshold do:
41// MHCamEvent::SetThreshold(5.5); // Default=LowerBound
42// MHCamEvent::SetThreshold(5.5, MHCamEvent::kIsUpperBound);
43//
44//
45// Axis titles
46// ===========
47//
48// 1) If no other title is given 'a.u.' is used.
49// 2) If the title of MHCamEvent is different from the default,
50// it is used as histogram title. You can use this to set the
51// axis title, too. For more information see TH1::SetTitle, eg.
52// SetTitle("MyHist;;y[cm];Counts");
53// Make sure to set an empty x-axis title.
54//
55// For example:
56// MHCamEvent myhist("Titele;;y [cm]");
57//
58/////////////////////////////////////////////////////////////////////////////
59#include "MHCamEvent.h"
60
61#include <TCanvas.h>
62#include <TPaveStats.h>
63
64#include "MLog.h"
65#include "MLogManip.h"
66
67#include "MParList.h"
68#include "MCamEvent.h"
69#include "MHCamera.h"
70
71#include "MGeomCam.h"
72
73ClassImp(MHCamEvent);
74
75using namespace std;
76
77const TString MHCamEvent::gsDefName = "MHCamEvent";
78const TString MHCamEvent::gsDefTitle = "Average of MCamEvents";
79
80// --------------------------------------------------------------------------
81//
82// Initialize the name and title of the task
83//
84void MHCamEvent::Init(const char *name, const char *title)
85{
86 //
87 // set the name and title of this object
88 //
89 fName = name ? name : gsDefName.Data();
90 fTitle = title ? title : gsDefTitle.Data();
91
92 fNameGeom = "MGeomCam";
93}
94
95// --------------------------------------------------------------------------
96//
97// Initialize the name and title of the task. Set fType to 0
98//
99MHCamEvent::MHCamEvent(const char *name, const char *title)
100 : fSum(NULL), fEvt(NULL), fType(0), fThreshold(0), fUseThreshold(0)
101{
102 Init(name, title);
103}
104
105// --------------------------------------------------------------------------
106//
107// Initialize the name and title of the task. Set fType to type
108//
109MHCamEvent::MHCamEvent(Int_t type, const char *name, const char *title)
110 : fSum(NULL), fEvt(NULL), fType(type), fThreshold(0), fUseThreshold(0)
111{
112 Init(name, title);
113}
114
115// --------------------------------------------------------------------------
116//
117// Delete the corresponding camera display if available
118//
119MHCamEvent::~MHCamEvent()
120{
121 if (fSum)
122 delete fSum;
123}
124
125// --------------------------------------------------------------------------
126//
127// use this to display the variance instead of the rms.
128//
129void MHCamEvent::EnableVariance(Bool_t b)
130{
131 b ? SetBit(MHCamera::kVariance) : ResetBit(MHCamera::kVariance);
132}
133
134// --------------------------------------------------------------------------
135//
136// Get the event (MCamEvent) the histogram might be filled with. If
137// it is not given, it is assumed, that it is filled with the argument
138// of the Fill function.
139// Looks for the camera geometry MGeomCam and resets the sum histogram.
140//
141Bool_t MHCamEvent::SetupFill(const MParList *plist)
142{
143 fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
144 if (!fEvt)
145 {
146 if (!fNameEvt.IsNull())
147 {
148 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
149 return kFALSE;
150 }
151 *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
152 }
153
154 MGeomCam *cam = (MGeomCam*)plist->FindObject(fNameGeom, "MGeomCam");
155 if (!cam)
156 {
157 *fLog << err << fNameGeom << " [MGeomCam] not found... abort." << endl;
158 return kFALSE;
159 }
160
161 // Delete a possible old histogram from a previous loop
162 if (fSum)
163 delete (fSum);
164
165 // combine name
166 const TString name = fNameEvt.IsNull() ? fName : fNameEvt;
167
168 // create and setup MHCamera
169 fSum = new MHCamera(*cam, name+";avg");
170 if (fTitle!=gsDefTitle)
171 fSum->SetTitle(fTitle);
172 if (!fTitle.Contains(";"))
173 fSum->SetYTitle("a.u.");
174 fSum->SetBit(MHCamera::kProfile);
175 if (TestBit(MHCamera::kVariance))
176 fSum->SetBit(MHCamera::kVariance);
177
178 fSum->SetXTitle("Pixel Idx");
179
180 return kTRUE;
181}
182
183// --------------------------------------------------------------------------
184//
185// Fill the histograms with data from a MCamEvent-Container.
186//
187Bool_t MHCamEvent::Fill(const MParContainer *par, const Stat_t w)
188{
189 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
190 if (!evt)
191 {
192 *fLog << err << dbginf << "Got no MCamEvent as argument of Fill()..." << endl;
193 return kFALSE;
194 }
195 if (fUseThreshold)
196 fSum->CntCamContent(*evt, fThreshold, fType, fUseThreshold>0);
197 else
198 fSum->AddCamContent(*evt, fType);
199 return kTRUE;
200}
201
202// --------------------------------------------------------------------------
203//
204// Take the mean of the sum histogram and print all pixel indices
205// which are above sum+s*rms
206//
207void MHCamEvent::PrintOutliers(Float_t s) const
208{
209 const Double_t mean = fSum->GetMean();
210 const Double_t rms = fSum->GetRMS();
211
212 *fLog << all << underline << GetDescriptor() << ": Mean=" << mean << ", Rms=" << rms << endl;
213
214 for (UInt_t i=0; i<fSum->GetNumPixels(); i++)
215 {
216 if (!fSum->IsUsed(i))
217 continue;
218
219 if ((*fSum)[i+1]>mean+s*rms)
220 *fLog << "Contents of Pixel-Index #" << i << ": " << (*fSum)[i+1] << " > " << s << "*rms" << endl;
221 }
222}
223
224// --------------------------------------------------------------------------
225//
226// Return fSum for "sum" and fRms for "rms"
227//
228TH1 *MHCamEvent::GetHistByName(const TString name)
229{
230 return fSum;
231}
232
233void MHCamEvent::Paint(Option_t *)
234{
235 TVirtualPad *pad = gPad;
236
237 pad->cd(2);
238 if (gPad->FindObject(Form("%s;proj", fName.Data())))
239 {
240 TH1 *h=fSum->Projection(Form("%s;proj", fName.Data()));
241 if (h->GetMaximum()>0)
242 gPad->SetLogy();
243 }
244
245 pad->cd(5);
246 if (gPad->FindObject(Form("%s;rad", fName.Data())))
247 fSum->RadialProfile(Form("%s;rad", fName.Data()));
248
249 pad->cd(6);
250 if (gPad->FindObject(Form("%s;az", fName.Data())))
251 fSum->AzimuthProfile(Form("%s;az", fName.Data()));
252
253 pad->cd(4);
254 gPad->cd(1);
255 MHCamera *cam = (MHCamera*)gPad->FindObject(Form("%s;err", fName.Data()));
256 if (cam)
257 cam->SetCamContent(*fSum, 1);
258}
259
260void MHCamEvent::Draw(Option_t *)
261{
262 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
263 pad->SetBorderMode(0);
264
265 AppendPad();
266
267 TString name = Form("%s_5", pad->GetName());
268 TPad *p = new TPad(name,name,6./8,0.25,0.99,0.5,pad->GetFillColor(),0,0);
269 p->SetNumber(5);
270 p->Draw();
271
272 name = Form("%s_6", pad->GetName());
273 p = new TPad(name,name,6./8,0.01,0.99,0.25,pad->GetFillColor(),0,0);
274 p->SetNumber(6);
275 p->Draw();
276
277 pad->Divide(2,2);
278
279 pad->cd(1);
280 gPad->SetBorderMode(0);
281 gPad->SetPad(0.01, 0.5, 0.66, 0.99);
282 fSum->Draw("EPhist");
283
284 pad->cd(2);
285 gPad->SetBorderMode(0);
286 gPad->SetPad(0.66, 0.5, 0.99, 0.99);
287 TH1 *h = fSum->Projection(Form("%s;proj", fName.Data()), 50);
288 h->SetTitle("Projection");
289 h->SetBit(kCanDelete);
290 h->Draw();
291
292 pad->cd(3);
293 gPad->SetPad(0.01, 0.01, 3./8, 0.5);
294 gPad->SetBorderMode(0);
295 fSum->Draw();
296
297 pad->cd(4);
298 gPad->SetPad(3./8, 0.01, 6./8, 0.5);
299 gPad->SetBorderMode(0);
300
301 MHCamera *cam = new MHCamera(*fSum->GetGeometry());
302 cam->SetName(Form("%s;err", fName.Data()));
303 cam->SetTitle(fSum->TestBit(MHCamera::kVariance)?"Variance":"Root Mean Squared (rms)");
304 cam->SetYTitle(fSum->GetYaxis()->GetTitle());
305 cam->SetCamContent(*fSum, 1);
306 cam->SetBit(kCanDelete);
307 cam->Draw();
308
309 pad->cd(5);
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(6);
316 h = (TH1*)fSum->AzimuthProfile(Form("%s;az", fName.Data()), 30);
317 h->SetTitle("Azimuth Profile");
318 h->SetBit(kCanDelete|TH1::kNoStats);
319 h->Draw();
320}
321
Note: See TracBrowser for help on using the repository browser.