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 | ! Author(s): Wolfgang Wittek 2002 <mailto:wittek@mppmu.mpg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
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 | #include "MHCamera.h"
|
---|
53 |
|
---|
54 | ClassImp(MHHillas);
|
---|
55 |
|
---|
56 | using namespace std;
|
---|
57 |
|
---|
58 | // --------------------------------------------------------------------------
|
---|
59 | //
|
---|
60 | // Setup four histograms for Width, Length
|
---|
61 | //
|
---|
62 | MHHillas::MHHillas(const char *name, const char *title)
|
---|
63 | : fGeomCam(0)
|
---|
64 | {
|
---|
65 | //
|
---|
66 | // set the name and title of this object
|
---|
67 | //
|
---|
68 | fName = name ? name : "MHHillas";
|
---|
69 | fTitle = title ? title : "Source independent image parameters";
|
---|
70 |
|
---|
71 | fLength = new TH1F("Length", "Length of Ellipse", 100, 0, 296.7);
|
---|
72 | fWidth = new TH1F("Width", "Width of Ellipse", 100, 0, 296.7);
|
---|
73 | fDistC = new TH1F("DistC", "Distance from center of camera", 100, 0, 445);
|
---|
74 | fDelta = new TH1F("Delta", "Angle (Main axis - x-axis)", 101, -90, 90);
|
---|
75 |
|
---|
76 | fLength->SetLineColor(kBlue);
|
---|
77 |
|
---|
78 | fLength->SetDirectory(NULL);
|
---|
79 | fWidth->SetDirectory(NULL);
|
---|
80 | fDistC->SetDirectory(NULL);
|
---|
81 | fDelta->SetDirectory(NULL);
|
---|
82 |
|
---|
83 | fLength->SetXTitle("Length [\\circ]");
|
---|
84 | fWidth->SetXTitle("Width [\\circ]");
|
---|
85 | fDistC->SetXTitle("Distance [\\circ]");
|
---|
86 | fDelta->SetXTitle("Delta [\\circ]");
|
---|
87 |
|
---|
88 | fLength->SetYTitle("Counts");
|
---|
89 | fWidth->SetYTitle("Counts");
|
---|
90 | fDistC->SetYTitle("Counts");
|
---|
91 | fDelta->SetYTitle("Counts");
|
---|
92 |
|
---|
93 | fDelta->SetMinimum(0);
|
---|
94 |
|
---|
95 | MBinning bins;
|
---|
96 | bins.SetEdgesLog(50, 1, 1e7);
|
---|
97 |
|
---|
98 | fSize = new TH1F;
|
---|
99 | fSize->SetName("Size");
|
---|
100 | fSize->SetTitle("Number of Photons");
|
---|
101 | fSize->SetDirectory(NULL);
|
---|
102 | fSize->SetXTitle("Size");
|
---|
103 | fSize->SetYTitle("Counts");
|
---|
104 | fSize->GetXaxis()->SetTitleOffset(1.2);
|
---|
105 | fSize->GetXaxis()->SetLabelOffset(-0.015);
|
---|
106 | fSize->SetFillStyle(4000);
|
---|
107 | fSize->UseCurrentStyle();
|
---|
108 |
|
---|
109 | bins.Apply(*fSize);
|
---|
110 |
|
---|
111 | fCenter = new TH2F("Center", "Center of gravity", 51, -445, 445, 51, -445, 445);
|
---|
112 | fCenter->SetDirectory(NULL);
|
---|
113 | fCenter->SetXTitle("x [mm]");
|
---|
114 | fCenter->SetYTitle("y [mm]");
|
---|
115 | fCenter->SetZTitle("Counts");
|
---|
116 | }
|
---|
117 |
|
---|
118 | // --------------------------------------------------------------------------
|
---|
119 | //
|
---|
120 | // Delete the histograms
|
---|
121 | //
|
---|
122 | MHHillas::~MHHillas()
|
---|
123 | {
|
---|
124 | delete fLength;
|
---|
125 | delete fWidth;
|
---|
126 |
|
---|
127 | delete fDistC;
|
---|
128 | delete fDelta;
|
---|
129 |
|
---|
130 | delete fSize;
|
---|
131 | delete fCenter;
|
---|
132 | }
|
---|
133 |
|
---|
134 | // --------------------------------------------------------------------------
|
---|
135 | //
|
---|
136 | // Setup the Binning for the histograms automatically if the correct
|
---|
137 | // instances of MBinning (with the names 'BinningWidth' and 'BinningLength')
|
---|
138 | // are found in the parameter list
|
---|
139 | // Use this function if you want to set the conversion factor which
|
---|
140 | // is used to convert the mm-scale in the camera plain into the deg-scale
|
---|
141 | // used for histogram presentations. The conversion factor is part of
|
---|
142 | // the camera geometry. Please create a corresponding MGeomCam container.
|
---|
143 | //
|
---|
144 | Bool_t MHHillas::SetupFill(const MParList *plist)
|
---|
145 | {
|
---|
146 | fGeomCam = (MGeomCam*)plist->FindObject("MGeomCam");
|
---|
147 | if (!fGeomCam)
|
---|
148 | {
|
---|
149 | *fLog << err << "MGeomCam not found... abort." << endl;
|
---|
150 | return kFALSE;
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 | ApplyBinning(*plist, "Width", fWidth);
|
---|
155 | ApplyBinning(*plist, "Length", fLength);
|
---|
156 | ApplyBinning(*plist, "Dist", fDistC);
|
---|
157 | ApplyBinning(*plist, "Delta", fDelta);
|
---|
158 | ApplyBinning(*plist, "Size", fSize);
|
---|
159 |
|
---|
160 | const MBinning *bins = (MBinning*)plist->FindObject("BinningCamera");
|
---|
161 | if (!bins)
|
---|
162 | {
|
---|
163 | const Float_t r = fGeomCam->GetMaxRadius()*fGeomCam->GetConvMm2Deg();
|
---|
164 |
|
---|
165 | MBinning b;
|
---|
166 | b.SetEdges(61, -r, r);
|
---|
167 | SetBinning(fCenter, &b, &b);
|
---|
168 | }
|
---|
169 | else
|
---|
170 | SetBinning(fCenter, bins, bins);
|
---|
171 |
|
---|
172 |
|
---|
173 | return kTRUE;
|
---|
174 | }
|
---|
175 |
|
---|
176 | // --------------------------------------------------------------------------
|
---|
177 | //
|
---|
178 | // Fill the histograms with data from a MHillas-Container.
|
---|
179 | // Be careful: Only call this with an object of type MHillas
|
---|
180 | //
|
---|
181 | Int_t MHHillas::Fill(const MParContainer *par, const Stat_t w)
|
---|
182 | {
|
---|
183 | if (!par)
|
---|
184 | {
|
---|
185 | *fLog << err << "MHHillas::Fill: Pointer (!=NULL) expected." << endl;
|
---|
186 | return kERROR;
|
---|
187 | }
|
---|
188 |
|
---|
189 | const MHillas &h = *(MHillas*)par;
|
---|
190 |
|
---|
191 | const Double_t scale = fGeomCam->GetConvMm2Deg();
|
---|
192 |
|
---|
193 | fLength->Fill(scale*h.GetLength(), w);
|
---|
194 | fWidth ->Fill(scale*h.GetWidth(), w);
|
---|
195 | fDistC ->Fill(scale*h.GetDist0(), w);
|
---|
196 | fCenter->Fill(scale*h.GetMeanX(), scale*h.GetMeanY(), w);
|
---|
197 | fDelta ->Fill(kRad2Deg*h.GetDelta(), w);
|
---|
198 | fSize ->Fill(h.GetSize(), w);
|
---|
199 |
|
---|
200 | return kTRUE;
|
---|
201 | }
|
---|
202 |
|
---|
203 | // --------------------------------------------------------------------------
|
---|
204 | //
|
---|
205 | // Creates a new canvas and draws the four histograms into it.
|
---|
206 | // Be careful: The histograms belongs to this object and won't get deleted
|
---|
207 | // together with the canvas.
|
---|
208 | //
|
---|
209 | void MHHillas::Draw(Option_t *o)
|
---|
210 | {
|
---|
211 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
---|
212 | pad->SetBorderMode(0);
|
---|
213 |
|
---|
214 | AppendPad("");
|
---|
215 |
|
---|
216 | TString opt(o);
|
---|
217 | opt.ToLower();
|
---|
218 |
|
---|
219 | // FIXME: If same-option given make two independant y-axis!
|
---|
220 | const Bool_t same = opt.Contains("same");
|
---|
221 |
|
---|
222 | if (!same)
|
---|
223 | pad->Divide(2,3);
|
---|
224 | else
|
---|
225 | {
|
---|
226 | fLength->SetName("LengthSame");
|
---|
227 | fWidth->SetName("WidthSame");
|
---|
228 | fDistC->SetName("DistCSame");
|
---|
229 | fDelta->SetName("DeltaSame");
|
---|
230 | fSize->SetName("SizeSame");
|
---|
231 | fCenter->SetName("CenterSame");
|
---|
232 |
|
---|
233 | fLength->SetDirectory(0);
|
---|
234 | fWidth->SetDirectory(0);
|
---|
235 | fDistC->SetDirectory(0);
|
---|
236 | fDelta->SetDirectory(0);
|
---|
237 | fSize->SetDirectory(0);
|
---|
238 | fCenter->SetDirectory(0);
|
---|
239 |
|
---|
240 | fDistC->SetLineColor(kGreen);
|
---|
241 | fSize->SetLineColor(kGreen);
|
---|
242 | fDelta->SetLineColor(kGreen);
|
---|
243 | fWidth->SetLineColor(kMagenta);
|
---|
244 | fLength->SetLineColor(kCyan);
|
---|
245 | }
|
---|
246 |
|
---|
247 | pad->cd(1);
|
---|
248 | gPad->SetBorderMode(0);
|
---|
249 | gPad->SetGridx();
|
---|
250 | gPad->SetGridy();
|
---|
251 | RemoveFromPad("WidthSame");
|
---|
252 | RemoveFromPad("LengthSame");
|
---|
253 | MH::DrawSame(*fWidth, *fLength, "Width'n'Length", same);
|
---|
254 |
|
---|
255 | pad->cd(2);
|
---|
256 | gPad->SetBorderMode(0);
|
---|
257 | gPad->SetGridx();
|
---|
258 | gPad->SetGridy();
|
---|
259 | RemoveFromPad("DistCSame");
|
---|
260 | fDistC->Draw(same?"same":"");
|
---|
261 |
|
---|
262 | pad->cd(3);
|
---|
263 | gPad->SetGridx();
|
---|
264 | gPad->SetGridy();
|
---|
265 | gPad->SetBorderMode(0);
|
---|
266 | gPad->SetLogx();
|
---|
267 | gPad->SetLogy();
|
---|
268 | RemoveFromPad("SizeSame");
|
---|
269 | fSize->Draw(same?"same":"");
|
---|
270 |
|
---|
271 | pad->cd(4);
|
---|
272 | gPad->SetBorderMode(0);
|
---|
273 | gPad->SetGridx();
|
---|
274 | gPad->SetGridy();
|
---|
275 | gPad->SetPad(0.51, 0.01, 0.99, 0.65);
|
---|
276 | if (same)
|
---|
277 | {
|
---|
278 | TH2 *h=dynamic_cast<TH2*>(gPad->FindObject("Center"));
|
---|
279 | if (h)
|
---|
280 | {
|
---|
281 | // This causes crashes in THistPainter::PaintTable
|
---|
282 | // if the z-axis is not kept. No idea why...
|
---|
283 | h->SetDrawOption("z");
|
---|
284 | h->SetMarkerColor(kBlack);
|
---|
285 | }
|
---|
286 |
|
---|
287 | RemoveFromPad("CenterSame");
|
---|
288 | fCenter->SetMarkerColor(kGreen);
|
---|
289 | fCenter->Draw("same");
|
---|
290 | }
|
---|
291 | else
|
---|
292 | fCenter->Draw("colz");
|
---|
293 |
|
---|
294 | if (fGeomCam)
|
---|
295 | {
|
---|
296 | MHCamera *cam = new MHCamera(*fGeomCam);
|
---|
297 | cam->Draw("same");
|
---|
298 | cam->SetBit(kCanDelete);
|
---|
299 | }
|
---|
300 |
|
---|
301 | pad->cd(5);
|
---|
302 | gPad->SetBorderMode(0);
|
---|
303 | gPad->SetGridx();
|
---|
304 | gPad->SetGridy();
|
---|
305 | RemoveFromPad("DeltaSame");
|
---|
306 | fDelta->Draw(same?"same":"");
|
---|
307 |
|
---|
308 | pad->cd(6);
|
---|
309 | if (gPad && !same)
|
---|
310 | delete gPad;
|
---|
311 | }
|
---|
312 |
|
---|
313 | TH1 *MHHillas::GetHistByName(const TString name) const
|
---|
314 | {
|
---|
315 | if (name.Contains("Width", TString::kIgnoreCase))
|
---|
316 | return fWidth;
|
---|
317 | if (name.Contains("Length", TString::kIgnoreCase))
|
---|
318 | return fLength;
|
---|
319 | if (name.Contains("Size", TString::kIgnoreCase))
|
---|
320 | return fSize;
|
---|
321 | if (name.Contains("Delta", TString::kIgnoreCase))
|
---|
322 | return fDelta;
|
---|
323 | if (name.Contains("DistC", TString::kIgnoreCase))
|
---|
324 | return fDistC;
|
---|
325 | if (name.Contains("Center", TString::kIgnoreCase))
|
---|
326 | return fCenter;
|
---|
327 |
|
---|
328 | return NULL;
|
---|
329 | }
|
---|
330 |
|
---|
331 | void MHHillas::Paint(Option_t *opt)
|
---|
332 | {
|
---|
333 | MH::SetPalette("pretty");
|
---|
334 | MH::Paint();
|
---|
335 | }
|
---|