source: branches/Mars_IncreaseNsb/mimage/MHImagePar.cc@ 20046

Last change on this file since 20046 was 9851, checked in by tbretz, 14 years ago
Changed MH::SetBinning and similar functions to take references instead of pointers as arguments. For convenience wrappers for the old style functions are provided.
File size: 9.6 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): Wolfgang Wittek, 03/2003 <mailto:wittek@mppmu.mpg.de>
19! Author(s): Thomas Bretz, 04/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MHImagePar
29//
30////////////////////////////////////////////////////////////////////////////
31#include "MHImagePar.h"
32
33#include <math.h>
34
35#include <TH1.h>
36#include <TPad.h>
37#include <TCanvas.h>
38
39#include "MLog.h"
40#include "MLogManip.h"
41
42#include "MGeomCam.h"
43#include "MBinning.h"
44#include "MParList.h"
45
46#include "MHillas.h"
47#include "MImagePar.h"
48
49ClassImp(MHImagePar);
50
51using namespace std;
52
53// --------------------------------------------------------------------------
54//
55// Setup histograms
56//
57MHImagePar::MHImagePar(const char *name, const char *title)
58{
59 fName = name ? name : "MHImagePar";
60 fTitle = title ? title : "Histograms of image parameters";
61
62 fHistSatHi.SetName("SatHi");
63 fHistSatHi.SetTitle("Number of pixels with saturating hi-gains");
64 fHistSatHi.SetXTitle("Pixels");
65 fHistSatHi.SetYTitle("Counts");
66 fHistSatHi.SetDirectory(NULL);
67 fHistSatHi.UseCurrentStyle();
68 fHistSatHi.SetLineColor(kBlue);
69 fHistSatHi.SetFillStyle(4000);
70
71 fHistSatLo.SetName("SatLo");
72 fHistSatLo.SetTitle("Number of pixels with saturating lo-gains");
73 fHistSatLo.SetXTitle("Pixels");
74 fHistSatLo.SetYTitle("Counts");
75 fHistSatLo.SetDirectory(NULL);
76 fHistSatLo.UseCurrentStyle();
77 fHistSatLo.SetFillStyle(4000);
78
79 fHistIslands.SetName("Islands");
80 fHistIslands.SetTitle("Number of Islands");
81 fHistIslands.SetXTitle("N");
82 fHistIslands.SetYTitle("Counts");
83 fHistIslands.SetDirectory(NULL);
84 fHistIslands.UseCurrentStyle();
85 //fHistIslands.SetLineColor(kBlue);
86 fHistIslands.SetFillStyle(4000);
87
88 fHistSizeSubIslands.SetName("SizeSub");
89 fHistSizeSubIslands.SetTitle("Size of Sub Islands");
90 fHistSizeSubIslands.SetXTitle("S [phe]");
91 fHistSizeSubIslands.SetYTitle("Counts");
92 fHistSizeSubIslands.SetDirectory(NULL);
93 fHistSizeSubIslands.UseCurrentStyle();
94 fHistSizeSubIslands.SetLineColor(kBlue);
95 fHistSizeSubIslands.SetFillStyle(4000);
96
97 fHistSizeMainIsland.SetName("SizeMain");
98 fHistSizeMainIsland.SetTitle("Size of Main Island");
99 fHistSizeMainIsland.SetXTitle("S [phe]");
100 fHistSizeMainIsland.SetYTitle("Counts");
101 fHistSizeMainIsland.SetDirectory(NULL);
102 fHistSizeMainIsland.UseCurrentStyle();
103 fHistSizeMainIsland.SetFillStyle(4000);
104
105 fHistNumSP.SetName("NumSP");
106 fHistNumSP.SetTitle("Number of single core pixels");
107 fHistNumSP.SetXTitle("N");
108 fHistNumSP.SetYTitle("Counts");
109 fHistNumSP.SetDirectory(NULL);
110 fHistNumSP.UseCurrentStyle();
111 //fHistNumSP.SetLineColor(kBlue);
112 fHistNumSP.SetFillStyle(4000);
113
114 fHistSizeSP.SetName("SizeSP");
115 fHistSizeSP.SetTitle("Size of single core pixels");
116 fHistSizeSP.SetXTitle("S [phe]");
117 fHistSizeSP.SetYTitle("Counts");
118 fHistSizeSP.SetDirectory(NULL);
119 fHistSizeSP.UseCurrentStyle();
120 //fHistSizeSP.SetLineColor(kBlue);
121 fHistSizeSP.SetFillStyle(4000);
122
123
124 MBinning bins;
125
126 bins.SetEdges(60, -0.5, 59.5);
127 bins.Apply(fHistSatLo);
128 bins.Apply(fHistSatHi);
129 bins.Apply(fHistNumSP);
130
131 bins.SetEdgesLog(50, 1, 1e7);
132 bins.Apply(fHistSizeSubIslands);
133 bins.Apply(fHistSizeMainIsland);
134 bins.Apply(fHistSizeSP);
135
136 bins.SetEdges(15, 0.5, 15.5);
137 bins.Apply(fHistIslands);
138}
139
140// --------------------------------------------------------------------------
141//
142// Setup the Binning for the histograms automatically if the correct
143// instances of MBinning
144//
145Bool_t MHImagePar::SetupFill(const MParList *plist)
146{
147 ApplyBinning(*plist, "Pixels", fHistSatLo);
148 ApplyBinning(*plist, "Pixels", fHistSatHi);
149 ApplyBinning(*plist, "Pixels", fHistNumSP);
150
151 ApplyBinning(*plist, "Islands", fHistIslands);
152
153 ApplyBinning(*plist, "Size", fHistSizeSubIslands);
154 ApplyBinning(*plist, "Size", fHistSizeMainIsland);
155 ApplyBinning(*plist, "Size", fHistSizeSP);
156
157 return kTRUE;
158}
159
160
161// --------------------------------------------------------------------------
162//
163// Fill the histograms with data from a MNewImagePar container.
164//
165Int_t MHImagePar::Fill(const MParContainer *par, const Stat_t w)
166{
167 if (!par)
168 {
169 *fLog << err << "MImagePar::Fill: Pointer (!=NULL) expected." << endl;
170 return kERROR;
171 }
172
173 const MImagePar &h = *(MImagePar*)par;
174
175 fHistSatHi.Fill(h.GetNumSatPixelsHG(), w);
176 fHistSatLo.Fill(h.GetNumSatPixelsLG(), w);
177 fHistNumSP.Fill(h.GetNumSinglePixels(), w);
178 fHistSizeSP.Fill(h.GetSizeSinglePixels(), w);
179 fHistSizeSubIslands.Fill(h.GetSizeSubIslands(), w);
180 fHistSizeMainIsland.Fill(h.GetSizeMainIsland(), w);
181 fHistIslands.Fill(h.GetNumIslands(), w);
182
183 return kTRUE;
184}
185
186void MHImagePar::Paint(Option_t *o)
187{
188 if (fHistSatHi.GetMaximum()>0 && gPad->GetPad(1))
189 gPad->GetPad(1)->SetLogy();
190 if (fHistIslands.GetMaximum()>0 && gPad->GetPad(3))
191 gPad->GetPad(3)->SetLogy();
192
193 TVirtualPad *pad = gPad->GetPad(2);
194 if (pad)
195 {
196 if (fHistNumSP.GetMaximum()>0 && pad->GetPad(1))
197 pad->GetPad(1)->SetLogy();
198 if (fHistSizeSP.GetMaximum()>0 && pad->GetPad(2))
199 {
200 pad->GetPad(2)->SetLogx();
201 pad->GetPad(2)->SetLogy();
202 }
203 }
204 if (fHistSizeMainIsland.GetMaximum()>0 && gPad->GetPad(4))
205 {
206 gPad->GetPad(4)->SetLogx();
207 gPad->GetPad(4)->SetLogy();
208 }
209}
210
211// --------------------------------------------------------------------------
212//
213// Creates a new canvas and draws the two histograms into it.
214// Be careful: The histograms belongs to this object and won't get deleted
215// together with the canvas.
216//
217void MHImagePar::Draw(Option_t *o)
218{
219 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
220 pad->SetBorderMode(0);
221
222 AppendPad("");
223
224 TString opt(o);
225 opt.ToLower();
226
227 // FIXME: If same-option given make two independant y-axis!
228 const Bool_t same = opt.Contains("same");
229
230 if (!same)
231 pad->Divide(2,2);
232 else
233 {
234 fHistSatHi.SetName("SatHiSame");
235 fHistSatLo.SetName("SatLoSame");
236 fHistIslands.SetName("IslandsSame");
237 fHistSizeSubIslands.SetName("SizeSubSame");
238 fHistSizeMainIsland.SetName("SizeMainSame");
239 fHistNumSP.SetName("NumSPSame");
240 fHistSizeSP.SetName("SizeSPSame");
241
242 fHistSatHi.SetDirectory(0);
243 fHistSatLo.SetDirectory(0);
244 fHistIslands.SetDirectory(0);
245 fHistSizeSubIslands.SetDirectory(0);
246 fHistSizeMainIsland.SetDirectory(0);
247 fHistNumSP.SetDirectory(0);
248 fHistSizeSP.SetDirectory(0);
249
250 fHistSatHi.SetLineColor(kMagenta);
251 fHistSatLo.SetLineColor(kCyan);
252 fHistSizeMainIsland.SetLineColor(kMagenta);
253 fHistSizeSubIslands.SetLineColor(kCyan);
254 fHistIslands.SetLineColor(kBlue);
255 fHistNumSP.SetLineColor(kBlue);
256 fHistSizeSP.SetLineColor(kBlue);
257 }
258
259 pad->cd(1);
260 gPad->SetBorderMode(0);
261 gPad->SetGridx();
262 gPad->SetGridy();
263 RemoveFromPad("SatHiSame");
264 RemoveFromPad("SatLoSame");
265 MH::DrawSame(fHistSatHi, fHistSatLo, "Saturating Pixels", same);
266 fHistSatHi.SetMinimum(); // switch off to allow log-scale
267 fHistSatLo.SetMinimum(); // switch off to allow log-scale
268 fHistSatLo.SetMaximum(0.1); // dummy value to allow log-scale
269
270 pad->cd(4);
271 gPad->SetBorderMode(0);
272 gPad->SetGridx();
273 gPad->SetGridy();
274 RemoveFromPad("SizeSubSame");
275 RemoveFromPad("SizeMainSame");
276 MH::DrawSame(fHistSizeMainIsland, fHistSizeSubIslands, "Sizes...", same);
277 fHistSizeMainIsland.SetMinimum(); // switch off to allow log-scale
278 fHistSizeSubIslands.SetMinimum(); // switch off to allow log-scale
279 fHistSizeSubIslands.SetMaximum(0.1); // dummy value to allow log-scale
280
281 pad->cd(2);
282 gPad->SetBorderMode(0);
283 gPad->SetGridx();
284 gPad->SetGridy();
285 if (!same)
286 pad->GetPad(2)->Divide(1,2,1e-10,1e-10);
287 if (pad->GetPad(2))
288 {
289 pad->GetPad(2)->cd(1);
290 gPad->SetBorderMode(0);
291 RemoveFromPad("NumSPSame");
292 fHistNumSP.Draw(same?"same":"");
293 pad->GetPad(2)->cd(2);
294 gPad->SetBorderMode(0);
295 RemoveFromPad("SizeSPSame");
296 fHistSizeSP.Draw(same?"same":"");
297 }
298
299 pad->cd(3);
300 gPad->SetBorderMode(0);
301 gPad->SetGridx();
302 gPad->SetGridy();
303 RemoveFromPad("IslandsSame");
304 fHistIslands.Draw(same?"same":"");
305}
306
307TH1 *MHImagePar::GetHistByName(const TString name) const
308{
309 if (name.Contains("SatHi", TString::kIgnoreCase))
310 return const_cast<TH1F*>(&fHistSatHi);
311 if (name.Contains("SatLo", TString::kIgnoreCase))
312 return const_cast<TH1F*>(&fHistSatLo);
313 if (name.Contains("Islands", TString::kIgnoreCase))
314 return const_cast<TH1F*>(&fHistIslands);
315
316 return NULL;
317}
Note: See TracBrowser for help on using the repository browser.