source: trunk/MagicSoft/Mars/mimage/MHNewImagePar.cc@ 9453

Last change on this file since 9453 was 9343, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 12.2 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-2009
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MHNewImagePar
29//
30//
31// ClassVersion 2:
32// ----------
33// + TH1F fHistConcCOG; // [ratio] concentration around the center of gravity (all pixels)
34// + TH1F fHistConcCore; // [ratio] concentration of signals inside ellipse (used pixels)
35//
36// ClassVersion 3:
37// ---------------
38// - fMm2Deg
39// - fUseMmScale
40//
41////////////////////////////////////////////////////////////////////////////
42#include "MHNewImagePar.h"
43
44#include <math.h>
45
46#include <TH1.h>
47#include <TPad.h>
48#include <TCanvas.h>
49
50#include "MLog.h"
51#include "MLogManip.h"
52
53#include "MGeomCam.h"
54#include "MBinning.h"
55#include "MParList.h"
56
57#include "MHillas.h"
58#include "MNewImagePar.h"
59
60ClassImp(MHNewImagePar);
61
62using namespace std;
63
64// --------------------------------------------------------------------------
65//
66// Setup histograms
67//
68MHNewImagePar::MHNewImagePar(const char *name, const char *title)
69 : fGeom(0)
70{
71 fName = name ? name : "MHNewImagePar";
72 fTitle = title ? title : "Histograms of new image parameters";
73
74 fHistLeakage1.SetName("Leakage1");
75 fHistLeakage1.SetTitle("Leakage_{1}");
76 fHistLeakage1.SetXTitle("Leakage");
77 fHistLeakage1.SetYTitle("Counts");
78 fHistLeakage1.SetDirectory(NULL);
79 fHistLeakage1.UseCurrentStyle();
80 fHistLeakage1.SetFillStyle(4000);
81
82 fHistLeakage2.SetName("Leakage2");
83 fHistLeakage2.SetTitle("Leakage_{2}");
84 fHistLeakage2.SetXTitle("Leakage");
85 fHistLeakage2.SetYTitle("Counts");
86 fHistLeakage2.SetDirectory(NULL);
87 fHistLeakage2.UseCurrentStyle();
88 fHistLeakage2.SetLineColor(kBlue);
89 fHistLeakage2.SetFillStyle(4000);
90
91 fHistUsedPix.SetName("UsedPix");
92 fHistUsedPix.SetTitle("Number of used pixels");
93 fHistUsedPix.SetXTitle("Number of Pixels");
94 fHistUsedPix.SetYTitle("Counts");
95 fHistUsedPix.SetDirectory(NULL);
96 fHistUsedPix.UseCurrentStyle();
97 fHistUsedPix.SetLineColor(kBlue);
98 fHistUsedPix.SetFillStyle(4000);
99
100 fHistCorePix.SetName("CorePix");
101 fHistCorePix.SetTitle("Number of core pixels");
102 fHistCorePix.SetXTitle("Number of Pixels");
103 fHistCorePix.SetYTitle("Counts");
104 fHistCorePix.SetDirectory(NULL);
105 fHistCorePix.UseCurrentStyle();
106 fHistCorePix.SetLineColor(kBlack);
107 fHistCorePix.SetFillStyle(4000);
108
109 fHistUsedArea.SetName("UsedArea");
110 fHistUsedArea.SetTitle("Area of used pixels");
111 fHistUsedArea.SetXTitle("Area [\\circ^{2}]");
112 fHistUsedArea.SetYTitle("Counts");
113 fHistUsedArea.SetDirectory(NULL);
114 fHistUsedArea.UseCurrentStyle();
115 fHistUsedArea.SetLineColor(kBlue);
116 fHistUsedArea.SetFillStyle(4000);
117
118 fHistCoreArea.SetName("CoreArea");
119 fHistCoreArea.SetTitle("Area of core pixels");
120 fHistCoreArea.SetXTitle("Area [\\circ^{2}]");
121 fHistCoreArea.SetYTitle("Counts");
122 fHistCoreArea.SetDirectory(NULL);
123 fHistCoreArea.UseCurrentStyle();
124 fHistCoreArea.SetLineColor(kBlack);
125 fHistCoreArea.SetFillStyle(4000);
126
127 fHistConc.SetDirectory(NULL);
128 fHistConc1.SetDirectory(NULL);
129 fHistConcCOG.SetDirectory(NULL);
130 fHistConcCore.SetDirectory(NULL);
131 fHistConc.SetName("Conc2");
132 fHistConc1.SetName("Conc1");
133 fHistConcCOG.SetName("ConcCOG");
134 fHistConcCore.SetName("ConcCore");
135 fHistConc.SetTitle("Ratio: Conc");
136 fHistConc1.SetTitle("Ratio: Conc1");
137 fHistConcCOG.SetTitle("Ratio: ConcCOG");
138 fHistConcCore.SetTitle("Ratio: ConcCore");
139 fHistConc.SetXTitle("Ratio");
140 fHistConc1.SetXTitle("Ratio");
141 fHistConcCOG.SetXTitle("Ratio");
142 fHistConcCore.SetXTitle("Ratio");
143 fHistConc.SetYTitle("Counts");
144 fHistConc1.SetYTitle("Counts");
145 fHistConcCOG.SetYTitle("Counts");
146 fHistConcCore.SetYTitle("Counts");
147 fHistConc.UseCurrentStyle();
148 fHistConc1.UseCurrentStyle();
149 fHistConcCOG.UseCurrentStyle();
150 fHistConcCore.UseCurrentStyle();
151 fHistConc.SetFillStyle(4000);
152 fHistConc1.SetFillStyle(4000);
153 fHistConcCOG.SetFillStyle(4000);
154 fHistConcCore.SetFillStyle(4000);
155 fHistConc1.SetLineColor(kBlue);
156 fHistConcCOG.SetLineColor(kBlue);
157
158 MBinning bins;
159
160 bins.SetEdges(100, 0, 1);
161 bins.Apply(fHistLeakage1);
162 bins.Apply(fHistLeakage2);
163 bins.Apply(fHistConc);
164 bins.Apply(fHistConc1);
165 bins.Apply(fHistConcCOG);
166 bins.Apply(fHistConcCore);
167
168 bins.SetEdges(75, 0.5, 150.5);
169 bins.Apply(fHistUsedPix);
170 bins.Apply(fHistCorePix);
171
172 MBinning b;
173 b.SetEdges(50, 0, 1.5);
174 b.Apply(fHistUsedArea);
175 b.Apply(fHistCoreArea);
176}
177
178// --------------------------------------------------------------------------
179//
180// Setup the Binning for the histograms automatically if the correct
181// instances of MBinning
182//
183Bool_t MHNewImagePar::SetupFill(const MParList *plist)
184{
185 fGeom = (MGeomCam*)plist->FindObject("MGeomCam");
186 if (!fGeom)
187 {
188 *fLog << err << "MGeomCam not found... abort." << endl;
189 return kFALSE;
190 }
191
192 const MBinning *bins = (MBinning*)plist->FindObject("BinningArea");
193 if (bins)
194 {
195 bins->Apply(fHistUsedArea);
196 bins->Apply(fHistCoreArea);
197 }
198
199 ApplyBinning(*plist, "Leakage", &fHistLeakage1);
200 ApplyBinning(*plist, "Leakage", &fHistLeakage2);
201
202 ApplyBinning(*plist, "Pixels", &fHistUsedPix);
203 ApplyBinning(*plist, "Pixels", &fHistCorePix);
204
205 //ApplyBinning(*plist, "Area", &fHistUsedArea);
206 //ApplyBinning(*plist, "Area", &fHistCoreArea);
207
208 ApplyBinning(*plist, "Conc", &fHistConc);
209 ApplyBinning(*plist, "Conc1", &fHistConc1);
210 ApplyBinning(*plist, "ConcCOG", &fHistConcCOG);
211 ApplyBinning(*plist, "ConcCore", &fHistConcCore);
212
213 return kTRUE;
214}
215
216
217// --------------------------------------------------------------------------
218//
219// Fill the histograms with data from a MNewImagePar container.
220//
221Int_t MHNewImagePar::Fill(const MParContainer *par, const Stat_t w)
222{
223 if (!par)
224 {
225 *fLog << err << "MHNewImagePar::Fill: Pointer (!=NULL) expected." << endl;
226 return kERROR;
227 }
228
229 const Double_t scale = fGeom->GetConvMm2Deg()*fGeom->GetConvMm2Deg();
230
231 const MNewImagePar &h = *(MNewImagePar*)par;
232
233 fHistLeakage1.Fill(h.GetLeakage1(), w);
234 fHistLeakage2.Fill(h.GetLeakage2(), w);
235
236 fHistUsedPix.Fill(h.GetNumUsedPixels(), w);
237 fHistCorePix.Fill(h.GetNumCorePixels(), w);
238
239 fHistUsedArea.Fill(h.GetUsedArea()*scale, w);
240 fHistCoreArea.Fill(h.GetCoreArea()*scale, w);
241
242 fHistConc.Fill(h.GetConc(), w);
243 fHistConc1.Fill(h.GetConc1(), w);
244 fHistConcCOG.Fill(h.GetConcCOG(), w);
245 fHistConcCore.Fill(h.GetConcCore(), w);
246
247 return kTRUE;
248}
249
250void MHNewImagePar::Paint(Option_t *o)
251{
252 if (fHistLeakage1.GetMaximum()>0 && gPad->GetPad(1) && gPad->GetPad(1)->GetPad(1))
253 gPad->GetPad(1)->GetPad(1)->SetLogy();
254}
255
256// --------------------------------------------------------------------------
257//
258// Creates a new canvas and draws the two histograms into it.
259// Be careful: The histograms belongs to this object and won't get deleted
260// together with the canvas.
261//
262void MHNewImagePar::Draw(Option_t *o)
263{
264 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
265 pad->SetBorderMode(0);
266
267 AppendPad("");
268
269 // FIXME: If same-option given make two independant y-axis!
270 const TString opt(o);
271 const Bool_t same = opt.Contains("same");
272
273 if (!same)
274 pad->Divide(2, 1);
275 else
276 {
277 fHistLeakage1.SetName("Leakage1Same");
278 fHistLeakage2.SetName("Leakage2Same");
279 fHistUsedPix.SetName("UsedPixSame");
280 fHistCorePix.SetName("CorePixSame");
281 fHistUsedArea.SetName("UsedAreaSame");
282 fHistCoreArea.SetName("CoreAreaSame");
283 fHistConcCOG.SetName("ConcCOGSame");
284 fHistConcCore.SetName("ConcCoreSame");
285 fHistConc1.SetName("Conc1Same");
286 fHistConc.SetName("Conc2Same");
287
288 fHistLeakage1.SetDirectory(0);
289 fHistLeakage2.SetDirectory(0);
290 fHistUsedPix.SetDirectory(0);
291 fHistCorePix.SetDirectory(0);
292 fHistUsedArea.SetDirectory(0);
293 fHistCoreArea.SetDirectory(0);
294 fHistConcCOG.SetDirectory(0);
295 fHistConcCore.SetDirectory(0);
296 fHistConc1.SetDirectory(0);
297 fHistConc.SetDirectory(0);
298
299 fHistLeakage1.SetLineColor(kMagenta);
300 fHistLeakage1.SetLineColor(kCyan);
301 fHistCorePix.SetLineColor(kMagenta);
302 fHistUsedPix.SetLineColor(kCyan);
303 fHistConc1.SetLineColor(kMagenta);
304 fHistConc.SetLineColor(kCyan);
305 fHistConcCOG.SetLineColor(kMagenta);
306 fHistConcCore.SetLineColor(kCyan);
307 fHistCoreArea.SetLineColor(kMagenta);
308 fHistUsedArea.SetLineColor(kCyan);
309 }
310
311 pad->cd(1);
312 TVirtualPad *pad1=gPad;
313 pad1->SetBorderMode(0);
314 if (!same)
315 pad1->Divide(1,3, 0.001, 0.001);
316
317 pad1->cd(1);
318 gPad->SetBorderMode(0);
319 gPad->SetGridx();
320 gPad->SetGridy();
321 TAxis &x = *fHistLeakage1.GetXaxis();
322 x.SetRangeUser(0.0, x.GetXmax());
323 RemoveFromPad("Leakage1Same");
324 RemoveFromPad("Leakage2Same");
325 MH::DrawSame(fHistLeakage1, fHistLeakage2, "Leakage1 and Leakage2", same);
326 fHistLeakage1.SetMinimum();
327 fHistLeakage2.SetMinimum();
328 fHistLeakage2.SetMaximum(0.1); // dummy value to allow log-scale
329
330 pad1->cd(2);
331 gPad->SetBorderMode(0);
332 gPad->SetGridx();
333 gPad->SetGridy();
334 RemoveFromPad("UsedPixSame");
335 RemoveFromPad("CorePixSame");
336 MH::DrawSame(fHistCorePix, fHistUsedPix, "Number of core/used Pixels", same);
337
338 pad1->cd(3);
339 gPad->SetBorderMode(0);
340 gPad->SetGridx();
341 gPad->SetGridy();
342 RemoveFromPad("CoreAreaSame");
343 RemoveFromPad("UsedAreaSame");
344 MH::DrawSame(fHistCoreArea, fHistUsedArea, "Area of core/used Pixels", same);
345
346 pad->cd(2);
347 TVirtualPad *pad2=gPad;
348 pad2->SetBorderMode(0);
349 if (!same)
350 pad2->Divide(1, 2, 0.001, 0.001);
351
352 pad2->cd(1);
353 gPad->SetBorderMode(0);
354 gPad->SetGridx();
355 gPad->SetGridy();
356 RemoveFromPad("Conc1Same");
357 RemoveFromPad("Conc2Same");
358 MH::DrawSame(fHistConc1, fHistConc, "Concentrations", same);
359
360 pad2->cd(2);
361 gPad->SetBorderMode(0);
362 gPad->SetGridx();
363 gPad->SetGridy();
364 RemoveFromPad("ConcCOGSame");
365 RemoveFromPad("ConcCoreSame");
366 MH::DrawSame(fHistConcCore, fHistConcCOG, "Concentrations", same);
367}
368
369TH1 *MHNewImagePar::GetHistByName(const TString name) const
370{
371 if (name.Contains("Leakage1", TString::kIgnoreCase))
372 return const_cast<TH1F*>(&fHistLeakage1);
373 if (name.Contains("Leakage2", TString::kIgnoreCase))
374 return const_cast<TH1F*>(&fHistLeakage2);
375 if (name.Contains("ConcCOG", TString::kIgnoreCase))
376 return const_cast<TH1F*>(&fHistConcCOG);
377 if (name.Contains("ConcCore", TString::kIgnoreCase))
378 return const_cast<TH1F*>(&fHistConcCore);
379 if (name.Contains("Conc1", TString::kIgnoreCase)) // must be first!
380 return const_cast<TH1F*>(&fHistConc1);
381 if (name.Contains("Conc", TString::kIgnoreCase))
382 return const_cast<TH1F*>(&fHistConc);
383 if (name.Contains("UsedPix", TString::kIgnoreCase))
384 return const_cast<TH1F*>(&fHistUsedPix);
385 if (name.Contains("CorePix", TString::kIgnoreCase))
386 return const_cast<TH1F*>(&fHistCorePix);
387 if (name.Contains("UsedArea", TString::kIgnoreCase))
388 return const_cast<TH1F*>(&fHistUsedArea);
389 if (name.Contains("CoreArea", TString::kIgnoreCase))
390 return const_cast<TH1F*>(&fHistCoreArea);
391
392 return NULL;
393}
Note: See TracBrowser for help on using the repository browser.