source: trunk/Mars/mimage/MHHillasExt.cc@ 20076

Last change on this file since 20076 was 19304, checked in by tbretz, 6 years ago
Replaced \circ by #circ because the old one looks weird.
File size: 11.3 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-2010
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// ClassVersion 3:
37// ---------------
38// - fMm2Deg
39// - fUseMmScale
40//
41// ClassVersion 4:
42// ---------------
43// + TH1F fHTimeSpread; // [ns] Spread (rms) of arrival time around mean
44// + TH1F fHTimeSpreadW; // [ns] Weighted spread (rms) of arrival time around weighted mean
45// + TH1F fHSlopeSpread; // [ns] Spread (rms) of arrival time around slope
46// + TH1F fHSlopeSpreadW; // [ns] Weighted spread (rms) of arrival time around slope
47//
48/////////////////////////////////////////////////////////////////////////////
49#include "MHHillasExt.h"
50
51#include <math.h>
52
53#include <TPad.h>
54#include <TLegend.h>
55#include <TCanvas.h>
56
57#include "MLog.h"
58#include "MLogManip.h"
59
60#include "MGeomCam.h"
61
62#include "MParList.h"
63
64#include "MBinning.h"
65
66#include "MHillas.h"
67#include "MHillasExt.h"
68#include "MHillasSrc.h"
69
70ClassImp(MHHillasExt);
71
72using namespace std;
73
74// --------------------------------------------------------------------------
75//
76// Setup four histograms for Width, Length
77//
78MHHillasExt::MHHillasExt(const char *name, const char *title)
79 : fGeom(0), fHillas(0), fHillasExt(0), fHilName("MHillasExt")
80{
81 //
82 // set the name and title of this object
83 //
84 fName = name ? name : "MHHillasExt";
85 fTitle = title ? title : "Container for extended Hillas histograms";
86
87 //
88 // loop over all Pixels and create two histograms
89 // one for the Low and one for the High gain
90 // connect all the histogram with the container fHist
91 //
92 fHAsym.UseCurrentStyle();
93 fHM3Long.UseCurrentStyle();
94 fHM3Trans.UseCurrentStyle();
95 fHSlopeL.UseCurrentStyle();
96 fHTimeSpread.UseCurrentStyle();
97 fHTimeSpreadW.UseCurrentStyle();
98 fHSlopeSpread.UseCurrentStyle();
99 fHSlopeSpreadW.UseCurrentStyle();
100
101 fHAsym.SetName("Asymmetry");
102 fHM3Long.SetName("M3l");
103 fHM3Trans.SetName("M3t");
104 fHSlopeL.SetName("SlopeL");
105 fHTimeSpread.SetName("TimeSpread");
106 fHTimeSpreadW.SetName("TimeSpreadW");
107 fHSlopeSpread.SetName("SlopeSpread");
108 fHSlopeSpreadW.SetName("SlopeSpreadW");
109
110 fHAsym.SetTitle("Asymmetry");
111 fHM3Long.SetTitle("3^{rd} Moment Longitudinal");
112 fHM3Trans.SetTitle("3^{rd} Moment Transverse");
113 fHSlopeL.SetTitle("Longitudinal time-slope vs. Dist");
114 fHTimeSpread.SetTitle("Time spread around mean");
115 fHTimeSpreadW.SetTitle("Weighted time spread around weighted mean");
116 fHSlopeSpread.SetTitle("Time spread around slope");
117 fHSlopeSpreadW.SetTitle("Weighted time spread around slope");
118
119 fHAsym.SetXTitle("Asym [#circ]");
120 fHM3Long.SetXTitle("3^{rd} M_{l} [#circ]");
121 fHM3Trans.SetXTitle("3^{rd} M_{t} [#circ]");
122 fHSlopeL.SetXTitle("D [#circ]");
123 fHTimeSpread.SetXTitle("T_{rms} [ns]");
124 fHTimeSpreadW.SetXTitle("T_{rms} [ns]");
125 fHSlopeSpread.SetXTitle("T_{rms} [ns]");
126 fHSlopeSpreadW.SetXTitle("T_{rms} [ns]");
127
128 fHAsym.SetYTitle("Counts");
129 fHM3Long.SetYTitle("Counts");
130 fHM3Trans.SetYTitle("Counts");
131 fHSlopeL.SetYTitle("S_{l} [ns/#circ]");
132 fHTimeSpread.SetYTitle("Counts");
133 fHTimeSpreadW.SetYTitle("Counts");
134 fHSlopeSpread.SetYTitle("Counts");
135 fHSlopeSpreadW.SetYTitle("Counts");
136
137 fHAsym.SetFillStyle(4000);
138 fHM3Long.SetFillStyle(4000);
139 fHM3Trans.SetFillStyle(4000);
140 //fHSlopeL.SetFillStyle(4000);
141
142 fHAsym.SetDirectory(NULL);
143 fHM3Long.SetDirectory(NULL);
144 fHM3Trans.SetDirectory(NULL);
145 fHSlopeL.SetDirectory(NULL);
146
147 fHTimeSpread.SetDirectory(NULL);
148 fHTimeSpreadW.SetDirectory(NULL);
149 fHSlopeSpread.SetDirectory(NULL);
150 fHSlopeSpreadW.SetDirectory(NULL);
151
152 fHM3Trans.SetLineColor(kBlue);
153
154 fHSlopeSpread.SetLineColor(kBlue);
155 fHSlopeSpreadW.SetLineColor(kBlue);
156
157 fHTimeSpreadW.SetLineStyle(kDashed);
158 fHSlopeSpreadW.SetLineStyle(kDashed);
159
160 MBinning binsx, binsy;
161
162 binsx.SetEdges(51, -1.1, 1.1);
163 binsx.Apply(fHM3Long);
164 binsx.Apply(fHM3Trans);
165
166 binsx.SetEdges(51, -2.0, 2.0);
167 binsx.Apply(fHAsym);
168
169 binsx.SetEdges(100, 0, 1.5);
170 binsy.SetEdges(100, -9, 9);
171 MH::SetBinning(fHSlopeL, binsx, binsy);
172
173 binsx.SetEdges( 50, 0, 1.5);
174 MH::SetBinning(fHTimeSpread, binsx);
175 MH::SetBinning(fHSlopeSpread, binsx);
176 MH::SetBinning(fHTimeSpreadW, binsx);
177 MH::SetBinning(fHSlopeSpreadW, binsx);
178}
179
180// --------------------------------------------------------------------------
181//
182// Setup the Binning for the histograms automatically if the correct
183// instances of MBinning (with the names 'BinningWidth' and 'BinningLength')
184// are found in the parameter list
185// Use this function if you want to set the conversion factor which
186// is used to convert the mm-scale in the camera plain into the deg-scale
187// used for histogram presentations. The conversion factor is part of
188// the camera geometry. Please create a corresponding MGeomCam container.
189//
190Bool_t MHHillasExt::SetupFill(const MParList *plist)
191{
192 fHillasExt = (MHillasExt*)plist->FindObject(fHilName, "MHillasExt");
193 if (!fHillasExt)
194 {
195 *fLog << err << fHilName << "[MHillasExt] not found in parameter list... aborting." << endl;
196 return kFALSE;
197 }
198
199 fHillas = (MHillas*)plist->FindObject("MHillas");
200 if (!fHillas)
201 {
202 *fLog << err << "MHillas not found in parameter list... aborting." << endl;
203 return kFALSE;
204 }
205
206 fGeom = (MGeomCam*)plist->FindObject("MGeomCam");
207 if (!fGeom)
208 {
209 *fLog << err << "MGeomCam not found... abort." << endl;
210 return kFALSE;
211 }
212
213 ApplyBinning(*plist, "Asym", fHAsym);
214 ApplyBinning(*plist, "M3Long", fHM3Long);
215 ApplyBinning(*plist, "M3Trans", fHM3Trans);
216 ApplyBinning(*plist, "Dist", "Slope", fHSlopeL);
217
218 ApplyBinning(*plist, "TimeSpread", fHTimeSpread);
219 ApplyBinning(*plist, "TimeSpread", fHTimeSpreadW);
220 ApplyBinning(*plist, "TimeSpread", fHSlopeSpread);
221 ApplyBinning(*plist, "TimeSpread", fHSlopeSpreadW);
222
223 return kTRUE;
224}
225
226// --------------------------------------------------------------------------
227//
228// Fill the four histograms with data from a MHillas-Container.
229// Be careful: Only call this with an object of type MHillas
230//
231Int_t MHHillasExt::Fill(const MParContainer *par, const Stat_t w)
232{
233 const MHillasSrc *src = (MHillasSrc*)par;
234
235 const Double_t scale = TMath::Sign(fGeom->GetConvMm2Deg(), (src ? src->GetCosDeltaAlpha() : 1));
236 const Double_t dist = src ? src->GetDist() : fHillas->GetDist0();
237
238 fHAsym.Fill(scale*fHillasExt->GetAsym(), w);
239 fHM3Long.Fill(scale*fHillasExt->GetM3Long(), w);
240 fHM3Trans.Fill(scale*fHillasExt->GetM3Trans(), w);
241 fHSlopeL.Fill(scale*dist, fHillasExt->GetSlopeLong()/scale, w);
242
243 fHTimeSpread.Fill(fHillasExt->GetTimeSpread(), w);
244 fHTimeSpreadW.Fill(fHillasExt->GetTimeSpreadWeighted(), w);
245 fHSlopeSpread.Fill(fHillasExt->GetSlopeSpread(), w);
246 fHSlopeSpreadW.Fill(fHillasExt->GetSlopeSpreadWeighted(), w);
247
248 return kTRUE;
249}
250
251// --------------------------------------------------------------------------
252//
253// Creates a new canvas and draws the four histograms into it.
254// Be careful: The histograms belongs to this object and won't get deleted
255// together with the canvas.
256//
257void MHHillasExt::Draw(Option_t *o)
258{
259 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
260 pad->SetBorderMode(0);
261
262 AppendPad("");
263
264 // FIXME: If same-option given make two independant y-axis!
265 const TString opt(o);
266 const Bool_t same = opt.Contains("same");
267
268 if (!same)
269 pad->Divide(2,2);
270 else
271 {
272 fHAsym.SetName("AsymmetrySame");
273 fHM3Long.SetName("M3lSame");
274 fHM3Trans.SetName("M3tSame");
275 fHSlopeL.SetName("SlopeLSame");
276
277 fHSlopeSpreadW.SetName("SlopeSpreadWSame");
278 fHSlopeSpread.SetName("SlopeSpreadSame");
279 fHTimeSpread.SetName("TimeSpreadSame");
280 fHTimeSpreadW.SetName("TimeSpreadWSame");
281
282 fHAsym.SetDirectory(0);
283 fHM3Long.SetDirectory(0);
284 fHM3Trans.SetDirectory(0);
285 fHSlopeL.SetDirectory(0);
286
287 fHSlopeSpreadW.SetDirectory(0);
288 fHSlopeSpread.SetDirectory(0);
289 fHTimeSpread.SetDirectory(0);
290 fHTimeSpreadW.SetDirectory(0);
291
292 fHM3Long.SetLineColor(kMagenta);
293 fHM3Trans.SetLineColor(kCyan);
294 fHAsym.SetLineColor(kBlue);
295 fHSlopeL.SetMarkerColor(kBlue);
296
297 fHSlopeSpreadW.SetLineColor(kMagenta);
298 fHSlopeSpread.SetLineColor(kMagenta);
299 fHTimeSpread.SetLineColor(kCyan);
300 fHTimeSpreadW.SetLineColor(kCyan);
301 }
302
303 pad->cd(1);
304 gPad->SetBorderMode(0);
305 gPad->SetGridx();
306 gPad->SetGridy();
307 RemoveFromPad("M3lSame");
308 RemoveFromPad("M3tSame");
309 MH::DrawSame(fHM3Long, fHM3Trans, "3^{rd} Moments", same);
310
311 pad->cd(3);
312 gPad->SetBorderMode(0);
313 gPad->SetGridx();
314 gPad->SetGridy();
315 RemoveFromPad("AsymmetrySame");
316 fHAsym.Draw(same?"same":"");
317
318 pad->cd(2);
319 gPad->SetBorderMode(0);
320 gPad->SetGridx();
321 gPad->SetGridy();
322 //RemoveFromPad("SlopeLSame");
323 //fHSlopeL.Draw(same?"same":"");
324 if (same)
325 {
326 TH2 *h=dynamic_cast<TH2*>(gPad->FindObject("SlopeL"));
327 if (h)
328 {
329 // This causes crashes in THistPainter::PaintTable
330 // if the z-axis is not kept. No idea why...
331 h->SetDrawOption("z");
332 h->SetMarkerColor(kBlack);
333 }
334
335 RemoveFromPad("SlopeLSame");
336 fHSlopeL.SetMarkerColor(kBlue);
337 fHSlopeL.Draw("same");
338 }
339 else
340 fHSlopeL.Draw("colz");
341
342 pad->cd(4);
343 gPad->SetBorderMode(0);
344 gPad->SetGridx();
345 gPad->SetGridy();
346
347 RemoveFromPad("SlopeSpreadSame");
348 RemoveFromPad("SlopeSpreadWSame");
349 RemoveFromPad("TimeSpreadSame");
350 RemoveFromPad("TimeSpreadWSame");
351
352 fHSlopeSpreadW.Draw(same?"same":"");
353 fHSlopeSpread.Draw("same");
354 fHTimeSpread.Draw("same");
355 fHTimeSpreadW.Draw("same");
356}
357
358TH1 *MHHillasExt::GetHistByName(const TString name) const
359{
360 if (name.Contains("Asym", TString::kIgnoreCase))
361 return const_cast<TH1F*>(&fHAsym);
362 if (name.Contains("M3L", TString::kIgnoreCase))
363 return const_cast<TH1F*>(&fHM3Long);
364 if (name.Contains("M3T", TString::kIgnoreCase))
365 return const_cast<TH1F*>(&fHM3Trans);
366 if (name.Contains("SlopeL", TString::kIgnoreCase))
367 return const_cast<TH2F*>(&fHSlopeL);
368
369 return NULL;
370}
Note: See TracBrowser for help on using the repository browser.