source: trunk/MagicSoft/Mars/mimage/MHHillasExt.cc@ 9138

Last change on this file since 9138 was 8677, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 10.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): Thomas Bretz, 2001 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2007
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHHillasExt
28//
29// This class contains histograms for every Hillas parameter
30//
31// Class Version 2:
32// ----------------
33// - fHMaxDist
34// + fHSlopeL
35//
36/////////////////////////////////////////////////////////////////////////////
37#include "MHHillasExt.h"
38
39#include <math.h>
40
41#include <TPad.h>
42#include <TLegend.h>
43#include <TCanvas.h>
44
45#include "MLog.h"
46#include "MLogManip.h"
47
48#include "MGeomCam.h"
49
50#include "MParList.h"
51
52#include "MBinning.h"
53
54#include "MHillas.h"
55#include "MHillasExt.h"
56#include "MHillasSrc.h"
57
58ClassImp(MHHillasExt);
59
60using namespace std;
61
62// --------------------------------------------------------------------------
63//
64// Setup four histograms for Width, Length
65//
66MHHillasExt::MHHillasExt(const char *name, const char *title)
67 : fHillas(0), fHillasExt(0), fMm2Deg(1),
68 fUseMmScale(kTRUE), fHilName("MHillasExt")
69{
70 //
71 // set the name and title of this object
72 //
73 fName = name ? name : "MHHillasExt";
74 fTitle = title ? title : "Container for extended Hillas histograms";
75
76 //
77 // loop over all Pixels and create two histograms
78 // one for the Low and one for the High gain
79 // connect all the histogram with the container fHist
80 //
81 fHAsym.UseCurrentStyle();
82 fHM3Long.UseCurrentStyle();
83 fHM3Trans.UseCurrentStyle();
84 fHSlopeL.UseCurrentStyle();
85
86 fHAsym.SetName("Asymmetry");
87 fHM3Long.SetName("M3l");
88 fHM3Trans.SetName("M3t");
89 fHSlopeL.SetName("SlopeL");
90
91 fHAsym.SetTitle("Asymmetry");
92 fHM3Long.SetTitle("3^{rd} Moment Longitudinal");
93 fHM3Trans.SetTitle("3^{rd} Moment Transverse");
94 fHSlopeL.SetTitle("Longitudinal time-slope vs. Dist");
95
96 fHAsym.SetXTitle("Asym [mm]");
97 fHM3Long.SetXTitle("3^{rd} M_{l} [mm]");
98 fHM3Trans.SetXTitle("3^{rd} M_{t} [mm]");
99 fHSlopeL.SetXTitle("D [mm]");
100
101 fHAsym.SetYTitle("Counts");
102 fHM3Long.SetYTitle("Counts");
103 fHM3Trans.SetYTitle("Counts");
104 fHSlopeL.SetYTitle("S_{l} [ns/mm]");
105
106 fHAsym.SetFillStyle(4000);
107 fHM3Long.SetFillStyle(4000);
108 fHM3Trans.SetFillStyle(4000);
109 //fHSlopeL.SetFillStyle(4000);
110
111 fHAsym.SetDirectory(NULL);
112 fHM3Long.SetDirectory(NULL);
113 fHM3Trans.SetDirectory(NULL);
114 fHSlopeL.SetDirectory(NULL);
115
116 fHM3Trans.SetLineColor(kBlue);
117
118 MBinning binsx, binsy;
119
120 binsx.SetEdges(51, -326, 326);
121 binsx.Apply(fHM3Long);
122 binsx.Apply(fHM3Trans);
123
124 binsx.SetEdges(51, -593, 593);
125 binsx.Apply(fHAsym);
126
127 binsx.SetEdges(100, 0, 445);
128 binsy.SetEdges(100, -0.04, 0.04);
129 MH::SetBinning(&fHSlopeL, &binsx, &binsy);
130}
131
132// --------------------------------------------------------------------------
133//
134// Setup the Binning for the histograms automatically if the correct
135// instances of MBinning (with the names 'BinningWidth' and 'BinningLength')
136// are found in the parameter list
137// Use this function if you want to set the conversion factor which
138// is used to convert the mm-scale in the camera plain into the deg-scale
139// used for histogram presentations. The conversion factor is part of
140// the camera geometry. Please create a corresponding MGeomCam container.
141//
142Bool_t MHHillasExt::SetupFill(const MParList *plist)
143{
144 fHillasExt = (MHillasExt*)plist->FindObject(fHilName, "MHillasExt");
145 if (!fHillasExt)
146 {
147 *fLog << err << fHilName << "[MHillasExt] not found in parameter list... aborting." << endl;
148 return kFALSE;
149 }
150
151 fHillas = (MHillas*)plist->FindObject("MHillas");
152 if (!fHillas)
153 {
154 *fLog << err << "MHillas not found in parameter list... aborting." << endl;
155 return kFALSE;
156 }
157
158 const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
159 if (!geom)
160 *fLog << warn << GetDescriptor() << ": No Camera Geometry available. Using mm-scale for histograms." << endl;
161 else
162 {
163 fMm2Deg = geom->GetConvMm2Deg();
164 SetMmScale(kFALSE);
165 }
166
167 ApplyBinning(*plist, "Asym", &fHAsym);
168 ApplyBinning(*plist, "M3Long", &fHM3Long);
169 ApplyBinning(*plist, "M3Trans", &fHM3Trans);
170 ApplyBinning(*plist, "Dist", "Slope", &fHSlopeL);
171
172 return kTRUE;
173}
174
175// --------------------------------------------------------------------------
176//
177// Fill the four histograms with data from a MHillas-Container.
178// Be careful: Only call this with an object of type MHillas
179//
180Bool_t MHHillasExt::Fill(const MParContainer *par, const Stat_t w)
181{
182 const MHillasSrc *src = (MHillasSrc*)par;
183
184 const Double_t scale = TMath::Sign(fUseMmScale?1:fMm2Deg, (src ? src->GetCosDeltaAlpha() : 1));
185 const Double_t dist = src ? src->GetDist() : fHillas->GetDist0();
186
187 fHAsym.Fill(scale*fHillasExt->GetAsym(), w);
188 fHM3Long.Fill(scale*fHillasExt->GetM3Long(), w);
189 fHM3Trans.Fill(scale*fHillasExt->GetM3Trans(), w);
190 fHSlopeL.Fill(scale*dist, fHillasExt->GetSlopeLong()/scale, w);
191
192 return kTRUE;
193}
194
195// --------------------------------------------------------------------------
196//
197// With this function you can convert the histogram ('on the fly') between
198// degrees and millimeters.
199//
200void MHHillasExt::SetMmScale(Bool_t mmscale)
201{
202 if (fUseMmScale == mmscale)
203 return;
204
205 if (fMm2Deg<0)
206 {
207 *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
208 return;
209 }
210
211 const Double_t scale = mmscale ? 1./fMm2Deg : fMm2Deg;
212 MH::ScaleAxis(&fHAsym, scale);
213 MH::ScaleAxis(&fHM3Long, scale);
214 MH::ScaleAxis(&fHM3Trans, scale);
215 MH::ScaleAxis(&fHSlopeL, scale, 1./scale);
216
217 if (mmscale)
218 {
219 fHAsym.SetXTitle("Asym [mm]");
220 fHM3Long.SetXTitle("3^{rd} M_{l} [mm]");
221 fHM3Trans.SetXTitle("3^{rd} M_{t} [mm]");
222 fHSlopeL.SetXTitle("D [mm]");
223 fHSlopeL.SetYTitle("S_{l} [ns/mm]");
224 }
225 else
226 {
227 fHAsym.SetXTitle("Asym [\\circ]");
228 fHM3Long.SetXTitle("3^{rd} M_{l} [\\circ]");
229 fHM3Trans.SetXTitle("3^{rd} M_{t} [\\circ]");
230 fHSlopeL.SetXTitle("D [\\circ]");
231 fHSlopeL.SetYTitle("S_{l} [ns/\\circ]");
232 }
233
234 fUseMmScale = mmscale;
235}
236
237// --------------------------------------------------------------------------
238//
239// Use this function to setup your own conversion factor between degrees
240// and millimeters. The conversion factor should be the one calculated in
241// MGeomCam. Use this function with Caution: You could create wrong values
242// by setting up your own scale factor.
243//
244void MHHillasExt::SetMm2Deg(Float_t mmdeg)
245{
246 if (mmdeg<0)
247 {
248 *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
249 return;
250 }
251
252 if (fMm2Deg>=0)
253 *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
254
255 fMm2Deg = mmdeg;
256}
257
258// --------------------------------------------------------------------------
259//
260// Creates a new canvas and draws the four histograms into it.
261// Be careful: The histograms belongs to this object and won't get deleted
262// together with the canvas.
263//
264void MHHillasExt::Draw(Option_t *o)
265{
266 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
267 pad->SetBorderMode(0);
268
269 AppendPad("");
270
271 // FIXME: If same-option given make two independant y-axis!
272 const TString opt(o);
273 const Bool_t same = opt.Contains("same");
274
275 if (!same)
276 pad->Divide(2,2);
277 else
278 {
279 fHAsym.SetName("AsymmetrySame");
280 fHM3Long.SetName("M3lSame");
281 fHM3Trans.SetName("M3tSame");
282 fHSlopeL.SetName("SlopeLSame");
283
284 fHAsym.SetDirectory(0);
285 fHM3Long.SetDirectory(0);
286 fHM3Trans.SetDirectory(0);
287 fHSlopeL.SetDirectory(0);
288
289 fHM3Long.SetLineColor(kMagenta);
290 fHM3Trans.SetLineColor(kCyan);
291 fHAsym.SetLineColor(kBlue);
292 fHSlopeL.SetMarkerColor(kBlue);
293 }
294
295 pad->cd(1);
296 gPad->SetBorderMode(0);
297 gPad->SetGridx();
298 gPad->SetGridy();
299 RemoveFromPad("M3lSame");
300 RemoveFromPad("M3tSame");
301 MH::DrawSame(fHM3Long, fHM3Trans, "3^{rd} Moments", same);
302
303 pad->cd(3);
304 gPad->SetBorderMode(0);
305 gPad->SetGridx();
306 gPad->SetGridy();
307 RemoveFromPad("AsymmetrySame");
308 fHAsym.Draw(same?"same":"");
309
310 pad->cd(2);
311 gPad->SetBorderMode(0);
312 gPad->SetGridx();
313 gPad->SetGridy();
314 //RemoveFromPad("SlopeLSame");
315 //fHSlopeL.Draw(same?"same":"");
316 if (same)
317 {
318 TH2 *h=dynamic_cast<TH2*>(gPad->FindObject("SlopeL"));
319 if (h)
320 {
321 // This causes crashes in THistPainter::PaintTable
322 // if the z-axis is not kept. No idea why...
323 h->SetDrawOption("z");
324 h->SetMarkerColor(kBlack);
325 }
326
327 RemoveFromPad("SlopeLSame");
328 fHSlopeL.SetMarkerColor(kGreen);
329 fHSlopeL.Draw("same");
330 }
331 else
332 fHSlopeL.Draw("colz");
333
334 delete pad->GetPad(4);
335}
336
337TH1 *MHHillasExt::GetHistByName(const TString name) const
338{
339 if (name.Contains("Asym", TString::kIgnoreCase))
340 return const_cast<TH1F*>(&fHAsym);
341 if (name.Contains("M3L", TString::kIgnoreCase))
342 return const_cast<TH1F*>(&fHM3Long);
343 if (name.Contains("M3T", TString::kIgnoreCase))
344 return const_cast<TH1F*>(&fHM3Trans);
345 if (name.Contains("SlopeL", TString::kIgnoreCase))
346 return const_cast<TH2F*>(&fHSlopeL);
347
348 return NULL;
349}
Note: See TracBrowser for help on using the repository browser.