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@uni-sw.gwdg.de>
|
---|
19 | ! Wolfgang Wittek 2002 <mailto:wittek@mppmu.mpg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2002
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MHHillas
|
---|
29 | //
|
---|
30 | // This class contains histograms for the source independent image parameters
|
---|
31 | //
|
---|
32 | /////////////////////////////////////////////////////////////////////////////
|
---|
33 | #include "MHHillas.h"
|
---|
34 |
|
---|
35 | #include <math.h>
|
---|
36 |
|
---|
37 | #include <TH1.h>
|
---|
38 | #include <TH2.h>
|
---|
39 | #include <TPad.h>
|
---|
40 | #include <TStyle.h>
|
---|
41 | #include <TCanvas.h>
|
---|
42 |
|
---|
43 | #include "MLog.h"
|
---|
44 | #include "MLogManip.h"
|
---|
45 |
|
---|
46 | #include "MParList.h"
|
---|
47 |
|
---|
48 | #include "MHillas.h"
|
---|
49 | #include "MGeomCam.h"
|
---|
50 | #include "MBinning.h"
|
---|
51 |
|
---|
52 |
|
---|
53 | ClassImp(MHHillas);
|
---|
54 |
|
---|
55 | // --------------------------------------------------------------------------
|
---|
56 | //
|
---|
57 | // Setup four histograms for Width, Length
|
---|
58 | //
|
---|
59 | MHHillas::MHHillas(const char *name, const char *title)
|
---|
60 | : fMm2Deg(1), fUseMmScale(kTRUE)
|
---|
61 | {
|
---|
62 | //
|
---|
63 | // set the name and title of this object
|
---|
64 | //
|
---|
65 | fName = name ? name : "MHHillas";
|
---|
66 | fTitle = title ? title : "Source independent image parameters";
|
---|
67 |
|
---|
68 | fLength = new TH1F("Length", "Length of Ellipse", 100, 0, 296.7);
|
---|
69 | fWidth = new TH1F("Width", "Width of Ellipse", 100, 0, 296.7);
|
---|
70 | fDistC = new TH1F("DistC", "Distance from center of camera", 100, 0, 445);
|
---|
71 | fDelta = new TH1F("Delta", "Angle (Main axis - x-axis)", 101, -90, 90);
|
---|
72 |
|
---|
73 | fLength->SetLineColor(kBlue);
|
---|
74 |
|
---|
75 | fLength->SetDirectory(NULL);
|
---|
76 | fWidth->SetDirectory(NULL);
|
---|
77 | fDistC->SetDirectory(NULL);
|
---|
78 | fDelta->SetDirectory(NULL);
|
---|
79 |
|
---|
80 | fLength->SetXTitle("Length [mm]");
|
---|
81 | fWidth->SetXTitle("Width [mm]");
|
---|
82 | fDistC->SetXTitle("Distance [mm]");
|
---|
83 | fDelta->SetXTitle("Delta [\\circ]");
|
---|
84 |
|
---|
85 | fLength->SetYTitle("Counts");
|
---|
86 | fWidth->SetYTitle("Counts");
|
---|
87 | fDistC->SetYTitle("Counts");
|
---|
88 | fDelta->SetYTitle("Counts");
|
---|
89 |
|
---|
90 | MBinning bins;
|
---|
91 | bins.SetEdgesLog(50, 1, 1e7);
|
---|
92 |
|
---|
93 | fSize = new TH1F;
|
---|
94 | fSize->SetName("Size");
|
---|
95 | fSize->SetTitle("Number of Photons");
|
---|
96 | fSize->SetDirectory(NULL);
|
---|
97 | fSize->SetXTitle("Size");
|
---|
98 | fSize->SetYTitle("Counts");
|
---|
99 | fSize->GetXaxis()->SetTitleOffset(1.2);
|
---|
100 | fSize->GetXaxis()->SetLabelOffset(-0.015);
|
---|
101 | fSize->SetFillStyle(4000);
|
---|
102 |
|
---|
103 | bins.Apply(*fSize);
|
---|
104 |
|
---|
105 | fCenter = new TH2F("Center", "Center of Ellipse", 51, -445, 445, 51, -445, 445);
|
---|
106 | fCenter->SetDirectory(NULL);
|
---|
107 | fCenter->SetXTitle("x [mm]");
|
---|
108 | fCenter->SetYTitle("y [mm]");
|
---|
109 | fCenter->SetZTitle("Counts");
|
---|
110 | }
|
---|
111 |
|
---|
112 | // --------------------------------------------------------------------------
|
---|
113 | //
|
---|
114 | // Delete the histograms
|
---|
115 | //
|
---|
116 | MHHillas::~MHHillas()
|
---|
117 | {
|
---|
118 | delete fLength;
|
---|
119 | delete fWidth;
|
---|
120 |
|
---|
121 | delete fDistC;
|
---|
122 | delete fDelta;
|
---|
123 |
|
---|
124 | delete fSize;
|
---|
125 | delete fCenter;
|
---|
126 | }
|
---|
127 |
|
---|
128 | // --------------------------------------------------------------------------
|
---|
129 | //
|
---|
130 | // Setup the Binning for the histograms automatically if the correct
|
---|
131 | // instances of MBinning (with the names 'BinningWidth' and 'BinningLength')
|
---|
132 | // are found in the parameter list
|
---|
133 | // Use this function if you want to set the conversion factor which
|
---|
134 | // is used to convert the mm-scale in the camera plain into the deg-scale
|
---|
135 | // used for histogram presentations. The conversion factor is part of
|
---|
136 | // the camera geometry. Please create a corresponding MGeomCam container.
|
---|
137 | //
|
---|
138 | Bool_t MHHillas::SetupFill(const MParList *plist)
|
---|
139 | {
|
---|
140 | const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
|
---|
141 | if (!geom)
|
---|
142 | *fLog << warn << GetDescriptor() << ": No Camera Geometry available. Using mm-scale for histograms." << endl;
|
---|
143 | else
|
---|
144 | {
|
---|
145 | fMm2Deg = geom->GetConvMm2Deg();
|
---|
146 | SetMmScale(kFALSE);
|
---|
147 | }
|
---|
148 |
|
---|
149 | ApplyBinning(*plist, "Width", fWidth);
|
---|
150 | ApplyBinning(*plist, "Length", fLength);
|
---|
151 | ApplyBinning(*plist, "Dist", fDistC);
|
---|
152 | ApplyBinning(*plist, "Delta", fDelta);
|
---|
153 | ApplyBinning(*plist, "Size", fSize);
|
---|
154 |
|
---|
155 | const MBinning *bins = (MBinning*)plist->FindObject("BinningCamera");
|
---|
156 | if (!bins)
|
---|
157 | {
|
---|
158 | float r = geom ? geom->GetMaxRadius() : 600;
|
---|
159 | r *= 0.9;
|
---|
160 | if (!fUseMmScale)
|
---|
161 | r *= fMm2Deg;
|
---|
162 |
|
---|
163 | MBinning b;
|
---|
164 | b.SetEdges(61, -r, r);
|
---|
165 | SetBinning(fCenter, &b, &b);
|
---|
166 | }
|
---|
167 | else
|
---|
168 | SetBinning(fCenter, bins, bins);
|
---|
169 |
|
---|
170 |
|
---|
171 | return kTRUE;
|
---|
172 | }
|
---|
173 |
|
---|
174 | // --------------------------------------------------------------------------
|
---|
175 | //
|
---|
176 | // Use this function to setup your own conversion factor between degrees
|
---|
177 | // and millimeters. The conversion factor should be the one calculated in
|
---|
178 | // MGeomCam. Use this function with Caution: You could create wrong values
|
---|
179 | // by setting up your own scale factor.
|
---|
180 | //
|
---|
181 | void MHHillas::SetMm2Deg(Float_t mmdeg)
|
---|
182 | {
|
---|
183 | if (mmdeg<0)
|
---|
184 | {
|
---|
185 | *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
|
---|
186 | return;
|
---|
187 | }
|
---|
188 |
|
---|
189 | if (fMm2Deg>=0)
|
---|
190 | *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
|
---|
191 |
|
---|
192 | fMm2Deg = mmdeg;
|
---|
193 | }
|
---|
194 |
|
---|
195 | // --------------------------------------------------------------------------
|
---|
196 | //
|
---|
197 | // With this function you can convert the histogram ('on the fly') between
|
---|
198 | // degrees and millimeters.
|
---|
199 | //
|
---|
200 | void MHHillas::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(fLength, scale);
|
---|
213 | MH::ScaleAxis(fWidth, scale);
|
---|
214 | MH::ScaleAxis(fDistC, scale);
|
---|
215 | MH::ScaleAxis(fCenter, scale, scale);
|
---|
216 |
|
---|
217 | if (mmscale)
|
---|
218 | {
|
---|
219 | fLength->SetXTitle("Length [mm]");
|
---|
220 | fWidth->SetXTitle("Width [mm]");
|
---|
221 | fDistC->SetXTitle("Distance [mm]");
|
---|
222 | fCenter->SetXTitle("x [mm]");
|
---|
223 | fCenter->SetYTitle("y [mm]");
|
---|
224 | }
|
---|
225 | else
|
---|
226 | {
|
---|
227 | fLength->SetXTitle("Length [\\circ]");
|
---|
228 | fWidth->SetXTitle("Width [\\circ]");
|
---|
229 | fDistC->SetXTitle("Distance [\\circ]");
|
---|
230 | fCenter->SetXTitle("x [\\circ]");
|
---|
231 | fCenter->SetYTitle("y [\\circ]");
|
---|
232 | }
|
---|
233 |
|
---|
234 | fUseMmScale = mmscale;
|
---|
235 | }
|
---|
236 |
|
---|
237 | // --------------------------------------------------------------------------
|
---|
238 | //
|
---|
239 | // Fill the histograms with data from a MHillas-Container.
|
---|
240 | // Be careful: Only call this with an object of type MHillas
|
---|
241 | //
|
---|
242 | Bool_t MHHillas::Fill(const MParContainer *par, Double_t w)
|
---|
243 | {
|
---|
244 | const MHillas &h = *(MHillas*)par;
|
---|
245 |
|
---|
246 | const Double_t d = sqrt(h.GetMeanX()*h.GetMeanX() + h.GetMeanY()*h.GetMeanY());
|
---|
247 | const Double_t scale = fUseMmScale ? 1 : fMm2Deg;
|
---|
248 |
|
---|
249 | fLength ->Fill(scale*h.GetLength(), w);
|
---|
250 | fWidth ->Fill(scale*h.GetWidth(), w);
|
---|
251 | fDistC ->Fill(scale*d, w);
|
---|
252 | fCenter ->Fill(scale*h.GetMeanX(), scale*h.GetMeanY(), w);
|
---|
253 | fDelta ->Fill(kRad2Deg*h.GetDelta(), w);
|
---|
254 | fSize ->Fill(h.GetSize(), w);
|
---|
255 |
|
---|
256 | return kTRUE;
|
---|
257 | }
|
---|
258 |
|
---|
259 | // --------------------------------------------------------------------------
|
---|
260 | //
|
---|
261 | // Setup a inversed deep blue sea palette for the fCenter histogram.
|
---|
262 | //
|
---|
263 | void MHHillas::SetColors() const
|
---|
264 | {
|
---|
265 | gStyle->SetPalette(51, NULL);
|
---|
266 | Int_t c[50];
|
---|
267 | for (int i=0; i<50; i++)
|
---|
268 | c[49-i] = gStyle->GetColorPalette(i);
|
---|
269 | gStyle->SetPalette(50, c);
|
---|
270 | }
|
---|
271 |
|
---|
272 | // --------------------------------------------------------------------------
|
---|
273 | //
|
---|
274 | // Creates a new canvas and draws the four histograms into it.
|
---|
275 | // Be careful: The histograms belongs to this object and won't get deleted
|
---|
276 | // together with the canvas.
|
---|
277 | //
|
---|
278 | void MHHillas::Draw(Option_t *)
|
---|
279 | {
|
---|
280 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
---|
281 | pad->SetBorderMode(0);
|
---|
282 |
|
---|
283 | AppendPad("");
|
---|
284 |
|
---|
285 | pad->Divide(2,3);
|
---|
286 |
|
---|
287 | pad->cd(1);
|
---|
288 | gPad->SetBorderMode(0);
|
---|
289 | MH::Draw(*fWidth, *fLength, "Width'n'Length");
|
---|
290 |
|
---|
291 | pad->cd(2);
|
---|
292 | gPad->SetBorderMode(0);
|
---|
293 | fDistC->Draw();
|
---|
294 |
|
---|
295 | pad->cd(3);
|
---|
296 | gPad->SetBorderMode(0);
|
---|
297 | gPad->SetLogx();
|
---|
298 | fSize->Draw();
|
---|
299 |
|
---|
300 | pad->cd(4);
|
---|
301 | gPad->SetBorderMode(0);
|
---|
302 | gPad->SetPad(0.51, 0.01, 0.99, 0.65);
|
---|
303 | SetColors();
|
---|
304 | fCenter->Draw("colz");
|
---|
305 |
|
---|
306 | pad->cd(5);
|
---|
307 | gPad->SetBorderMode(0);
|
---|
308 | fDelta->Draw();
|
---|
309 |
|
---|
310 | pad->cd(6);
|
---|
311 | delete gPad;
|
---|
312 |
|
---|
313 | pad->Modified();
|
---|
314 | pad->Update();
|
---|
315 | }
|
---|
316 |
|
---|
317 | TH1 *MHHillas::GetHistByName(const TString name)
|
---|
318 | {
|
---|
319 | if (name.Contains("Width", TString::kIgnoreCase))
|
---|
320 | return fWidth;
|
---|
321 | if (name.Contains("Length", TString::kIgnoreCase))
|
---|
322 | return fLength;
|
---|
323 | if (name.Contains("Size", TString::kIgnoreCase))
|
---|
324 | return fSize;
|
---|
325 | if (name.Contains("Delta", TString::kIgnoreCase))
|
---|
326 | return fDelta;
|
---|
327 | if (name.Contains("DistC", TString::kIgnoreCase))
|
---|
328 | return fDistC;
|
---|
329 | if (name.Contains("Center", TString::kIgnoreCase))
|
---|
330 | return fCenter;
|
---|
331 |
|
---|
332 | return NULL;
|
---|
333 | }
|
---|
334 |
|
---|
335 | void MHHillas::Paint(Option_t *opt="")
|
---|
336 | {
|
---|
337 | SetColors();
|
---|
338 | MH::Paint();
|
---|
339 | }
|
---|