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

Last change on this file since 5347 was 5158, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 8.9 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
93// --------------------------------------------------------------------------
94//
95// Initialize the name and title of the task. Set fType to 0
96//
97MHCamEvent::MHCamEvent(const char *name, const char *title)
98 : fSum(NULL), fEvt(NULL), fType(0), fThreshold(0), fUseThreshold(0)
99{
100 Init(name, title);
101}
102
103// --------------------------------------------------------------------------
104//
105// Initialize the name and title of the task. Set fType to type
106//
107MHCamEvent::MHCamEvent(Int_t type, const char *name, const char *title)
108 : fSum(NULL), fEvt(NULL), fType(type), fThreshold(0), fUseThreshold(0)
109{
110 Init(name, title);
111}
112
113// --------------------------------------------------------------------------
114//
115// Delete the corresponding camera display if available
116//
117MHCamEvent::~MHCamEvent()
118{
119 if (fSum)
120 delete fSum;
121}
122
123// --------------------------------------------------------------------------
124//
125// use this to display the variance instead of the rms.
126//
127void MHCamEvent::EnableVariance(Bool_t b)
128{
129 b ? SetBit(MHCamera::kVariance) : ResetBit(MHCamera::kVariance);
130}
131
132// --------------------------------------------------------------------------
133//
134// Get the event (MCamEvent) the histogram might be filled with. If
135// it is not given, it is assumed, that it is filled with the argument
136// of the Fill function.
137// Looks for the camera geometry MGeomCam and resets the sum histogram.
138//
139Bool_t MHCamEvent::SetupFill(const MParList *plist)
140{
141 fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
142 if (!fEvt)
143 {
144 if (!fNameEvt.IsNull())
145 {
146 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
147 return kFALSE;
148 }
149 *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
150 }
151
152 MGeomCam *cam = (MGeomCam*)plist->FindObject("MGeomCam");
153 if (!cam)
154 {
155 *fLog << err << GetDescriptor() << ": No MGeomCam found." << endl;
156 return kFALSE;
157 }
158
159 // Delete a posible old histogram from a previous loop
160 if (fSum)
161 delete (fSum);
162
163 // combine name
164 const TString name = fNameEvt.IsNull() ? fName : fNameEvt;
165
166 // create and setup MHCamera
167 fSum = new MHCamera(*cam, name+";avg");
168 if (fTitle!=gsDefTitle)
169 fSum->SetTitle(fTitle);
170 if (!fTitle.Contains(";"))
171 fSum->SetYTitle("a.u.");
172 fSum->SetBit(MHCamera::kProfile);
173 if (TestBit(MHCamera::kVariance))
174 fSum->SetBit(MHCamera::kVariance);
175
176 return kTRUE;
177}
178
179// --------------------------------------------------------------------------
180//
181// Fill the histograms with data from a MCamEvent-Container.
182//
183Bool_t MHCamEvent::Fill(const MParContainer *par, const Stat_t w)
184{
185 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
186 if (!evt)
187 {
188 *fLog << err << dbginf << "Got no MCamEvent as argument of Fill()..." << endl;
189 return kFALSE;
190 }
191 if (fUseThreshold)
192 fSum->CntCamContent(*evt, fThreshold, fType, fUseThreshold>0);
193 else
194 fSum->AddCamContent(*evt, fType);
195 return kTRUE;
196}
197
198// --------------------------------------------------------------------------
199//
200// Take the mean of the sum histogram and print all pixel indices
201// which are above sum+s*rms
202//
203void MHCamEvent::PrintOutliers(Float_t s) const
204{
205 const Double_t mean = fSum->GetMean();
206 const Double_t rms = fSum->GetRMS();
207
208 *fLog << all << underline << GetDescriptor() << ": Mean=" << mean << ", Rms=" << rms << endl;
209
210 for (UInt_t i=0; i<fSum->GetNumPixels(); i++)
211 {
212 if (!fSum->IsUsed(i))
213 continue;
214
215 if ((*fSum)[i+1]>mean+s*rms)
216 *fLog << "Contents of Pixel-Index #" << i << ": " << (*fSum)[i+1] << " > " << s << "*rms" << endl;
217 }
218}
219
220// --------------------------------------------------------------------------
221//
222// Return fSum for "sum" and fRms for "rms"
223//
224TH1 *MHCamEvent::GetHistByName(const TString name)
225{
226 return fSum;
227}
228
229void MHCamEvent::Paint(Option_t *)
230{
231 TVirtualPad *pad = gPad;
232
233 pad->cd(2);
234 if (gPad->FindObject(Form("Proj_%p", this)))
235 {
236 TH1 *h=fSum->Projection(Form("Proj_%p", this));
237 if (h->GetMaximum()>0)
238 gPad->SetLogy();
239 }
240
241 pad->cd(5);
242 if (gPad->FindObject(Form("ProfR_%p", this)))
243 fSum->RadialProfile(Form("ProfR_%p", this));
244
245 pad->cd(6);
246 if (gPad->FindObject(Form("ProfA_%p", this)))
247 fSum->AzimuthProfile(Form("ProfA_%p", this));
248
249 pad->cd(4);
250 gPad->cd(1);
251 MHCamera *cam = (MHCamera*)gPad->FindObject(Form("Err_%p", this));
252 if (cam)
253 cam->SetCamContent(*fSum, 1);
254}
255
256void MHCamEvent::Draw(Option_t *)
257{
258 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
259 pad->SetBorderMode(0);
260
261 AppendPad();
262
263 TString name = Form("%s_5", pad->GetName());
264 TPad *p = new TPad(name,name,6./8,0.25,0.99,0.5,pad->GetFillColor(),0,0);
265 p->SetNumber(5);
266 p->Draw();
267
268 name = Form("%s_6", pad->GetName());
269 p = new TPad(name,name,6./8,0.01,0.99,0.25,pad->GetFillColor(),0,0);
270 p->SetNumber(6);
271 p->Draw();
272
273 pad->Divide(2,2);
274
275 pad->cd(1);
276 gPad->SetBorderMode(0);
277 gPad->SetPad(0.01, 0.5, 0.66, 0.99);
278 fSum->Draw("EPhist");
279
280 pad->cd(2);
281 gPad->SetBorderMode(0);
282 gPad->SetPad(0.66, 0.5, 0.99, 0.99);
283 TH1 *h = fSum->Projection(Form("Proj_%p", this), 50);
284 h->SetTitle("Projection");
285 h->SetBit(kCanDelete);
286 h->Draw();
287
288 pad->cd(3);
289 gPad->SetPad(0.01, 0.01, 3./8, 0.5);
290 gPad->SetBorderMode(0);
291 fSum->Draw();
292
293 pad->cd(4);
294 gPad->SetPad(3./8, 0.01, 6./8, 0.5);
295 gPad->SetBorderMode(0);
296
297 MHCamera *cam = new MHCamera(*fSum->GetGeometry());
298 cam->SetName(Form("Err_%p", this));
299 cam->SetTitle(fSum->TestBit(MHCamera::kVariance)?"Variance":"Root Mean Squared (rms)");
300 cam->SetYTitle(fSum->GetYaxis()->GetTitle());
301 cam->SetCamContent(*fSum, 1);
302 cam->SetBit(kCanDelete);
303 cam->Draw();
304
305 pad->cd(5);
306 h = (TH1*)fSum->RadialProfile(Form("ProfR_%p", this), 20);
307 h->SetTitle("Radial Profile");
308 h->SetBit(kCanDelete|TH1::kNoStats);
309 h->Draw();
310
311 pad->cd(6);
312 h = (TH1*)fSum->AzimuthProfile(Form("ProfA_%p", this), 30);
313 h->SetTitle("Azimuth Profile");
314 h->SetBit(kCanDelete|TH1::kNoStats);
315 h->Draw();
316}
317
Note: See TracBrowser for help on using the repository browser.