source: trunk/MagicSoft/Mars/mimage/MHImagePar.cc@ 6948

Last change on this file since 6948 was 6948, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 9.1 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//
165Bool_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 kFALSE;
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.SetLineColor(kMagenta);
243 fHistSatLo.SetLineColor(kCyan);
244 fHistSizeMainIsland.SetLineColor(kMagenta);
245 fHistSizeSubIslands.SetLineColor(kCyan);
246 fHistIslands.SetLineColor(kGreen);
247 fHistNumSP.SetLineColor(kGreen);
248 fHistSizeSP.SetLineColor(kGreen);
249 }
250
251 pad->cd(1);
252 gPad->SetBorderMode(0);
253 RemoveFromPad("SatHiSame");
254 RemoveFromPad("SatLoSame");
255 MH::DrawSame(fHistSatHi, fHistSatLo, "Saturating Pixels", same);
256 fHistSatHi.SetMinimum(); // switch off to allow log-scale
257 fHistSatLo.SetMinimum(); // switch off to allow log-scale
258 fHistSatLo.SetMaximum(0.1); // dummy value to allow log-scale
259
260 pad->cd(4);
261 gPad->SetBorderMode(0);
262 RemoveFromPad("SizeSubSame");
263 RemoveFromPad("SizeMainSame");
264 MH::DrawSame(fHistSizeMainIsland, fHistSizeSubIslands, "Sizes...", same);
265 fHistSizeMainIsland.SetMinimum(); // switch off to allow log-scale
266 fHistSizeSubIslands.SetMinimum(); // switch off to allow log-scale
267 fHistSizeSubIslands.SetMaximum(0.1); // dummy value to allow log-scale
268
269 pad->cd(2);
270 gPad->SetBorderMode(0);
271 if (!same)
272 pad->GetPad(2)->Divide(1,2,1e-10,1e-10);
273 if (pad->GetPad(2))
274 {
275 pad->GetPad(2)->cd(1);
276 gPad->SetBorderMode(0);
277 RemoveFromPad("NumSPSame");
278 fHistNumSP.Draw(same?"same":"");
279 pad->GetPad(2)->cd(2);
280 gPad->SetBorderMode(0);
281 RemoveFromPad("SizeSPSame");
282 fHistSizeSP.Draw(same?"same":"");
283 }
284
285 pad->cd(3);
286 gPad->SetBorderMode(0);
287 RemoveFromPad("IslandsSame");
288 fHistIslands.Draw(same?"same":"");
289}
290
291TH1 *MHImagePar::GetHistByName(const TString name)
292{
293 if (name.Contains("SatHi", TString::kIgnoreCase))
294 return &fHistSatHi;
295 if (name.Contains("SatLo", TString::kIgnoreCase))
296 return &fHistSatLo;
297 if (name.Contains("Islands", TString::kIgnoreCase))
298 return &fHistIslands;
299
300 return NULL;
301}
Note: See TracBrowser for help on using the repository browser.