source: tags/Mars-V2.2/mimage/MHHillas.cc

Last change on this file was 9271, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 11.0 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! 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
54ClassImp(MHHillas);
55
56using namespace std;
57
58// --------------------------------------------------------------------------
59//
60// Setup four histograms for Width, Length
61//
62MHHillas::MHHillas(const char *name, const char *title)
63 : fGeomCam(0), fMm2Deg(1), fUseMmScale(kTRUE)
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 [mm]");
84 fWidth->SetXTitle("Width [mm]");
85 fDistC->SetXTitle("Distance [mm]");
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//
122MHHillas::~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//
144Bool_t MHHillas::SetupFill(const MParList *plist)
145{
146 fGeomCam = (MGeomCam*)plist->FindObject("MGeomCam");
147 if (!fGeomCam)
148 *fLog << warn << GetDescriptor() << ": No Camera Geometry available. Using mm-scale for histograms." << endl;
149 else
150 {
151 fMm2Deg = fGeomCam->GetConvMm2Deg();
152 SetMmScale(kFALSE);
153 }
154
155 ApplyBinning(*plist, "Width", fWidth);
156 ApplyBinning(*plist, "Length", fLength);
157 ApplyBinning(*plist, "Dist", fDistC);
158 ApplyBinning(*plist, "Delta", fDelta);
159 ApplyBinning(*plist, "Size", fSize);
160
161 const MBinning *bins = (MBinning*)plist->FindObject("BinningCamera");
162 if (!bins)
163 {
164 float r = fGeomCam ? fGeomCam->GetMaxRadius() : 600;
165 if (!fUseMmScale)
166 r *= fMm2Deg;
167
168 MBinning b;
169 b.SetEdges(61, -r, r);
170 SetBinning(fCenter, &b, &b);
171 }
172 else
173 SetBinning(fCenter, bins, bins);
174
175
176 return kTRUE;
177}
178
179// --------------------------------------------------------------------------
180//
181// Use this function to setup your own conversion factor between degrees
182// and millimeters. The conversion factor should be the one calculated in
183// MGeomCam. Use this function with Caution: You could create wrong values
184// by setting up your own scale factor.
185//
186void MHHillas::SetMm2Deg(Float_t mmdeg)
187{
188 if (mmdeg<0)
189 {
190 *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
191 return;
192 }
193
194 if (fMm2Deg>=0)
195 *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
196
197 fMm2Deg = mmdeg;
198}
199
200// --------------------------------------------------------------------------
201//
202// With this function you can convert the histogram ('on the fly') between
203// degrees and millimeters.
204//
205void MHHillas::SetMmScale(Bool_t mmscale)
206{
207 if (fUseMmScale == mmscale)
208 return;
209
210 if (fMm2Deg<0)
211 {
212 *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
213 return;
214 }
215
216 const Double_t scale = mmscale ? 1./fMm2Deg : fMm2Deg;
217 MH::ScaleAxis(fLength, scale);
218 MH::ScaleAxis(fWidth, scale);
219 MH::ScaleAxis(fDistC, scale);
220 MH::ScaleAxis(fCenter, scale, scale);
221
222 if (mmscale)
223 {
224 fLength->SetXTitle("Length [mm]");
225 fWidth->SetXTitle("Width [mm]");
226 fDistC->SetXTitle("Distance [mm]");
227 fCenter->SetXTitle("x [mm]");
228 fCenter->SetYTitle("y [mm]");
229 }
230 else
231 {
232 fLength->SetXTitle("Length [\\circ]");
233 fWidth->SetXTitle("Width [\\circ]");
234 fDistC->SetXTitle("Distance [\\circ]");
235 fCenter->SetXTitle("x [\\circ]");
236 fCenter->SetYTitle("y [\\circ]");
237 }
238
239 fUseMmScale = mmscale;
240}
241
242// --------------------------------------------------------------------------
243//
244// Fill the histograms with data from a MHillas-Container.
245// Be careful: Only call this with an object of type MHillas
246//
247Int_t MHHillas::Fill(const MParContainer *par, const Stat_t w)
248{
249 if (!par)
250 {
251 *fLog << err << "MHHillas::Fill: Pointer (!=NULL) expected." << endl;
252 return kERROR;
253 }
254
255 const MHillas &h = *(MHillas*)par;
256
257 const Double_t d = sqrt(h.GetMeanX()*h.GetMeanX() + h.GetMeanY()*h.GetMeanY());
258 const Double_t scale = fUseMmScale ? 1 : fMm2Deg;
259
260 fLength->Fill(scale*h.GetLength(), w);
261 fWidth ->Fill(scale*h.GetWidth(), w);
262 fDistC ->Fill(scale*d, w);
263 fCenter->Fill(scale*h.GetMeanX(), scale*h.GetMeanY(), w);
264 fDelta ->Fill(kRad2Deg*h.GetDelta(), w);
265 fSize ->Fill(h.GetSize(), w);
266
267 return kTRUE;
268}
269
270// --------------------------------------------------------------------------
271//
272// Creates a new canvas and draws the four histograms into it.
273// Be careful: The histograms belongs to this object and won't get deleted
274// together with the canvas.
275//
276void MHHillas::Draw(Option_t *o)
277{
278 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
279 pad->SetBorderMode(0);
280
281 AppendPad("");
282
283 TString opt(o);
284 opt.ToLower();
285
286 // FIXME: If same-option given make two independant y-axis!
287 const Bool_t same = opt.Contains("same");
288
289 if (!same)
290 pad->Divide(2,3);
291 else
292 {
293 fLength->SetName("LengthSame");
294 fWidth->SetName("WidthSame");
295 fDistC->SetName("DistCSame");
296 fDelta->SetName("DeltaSame");
297 fSize->SetName("SizeSame");
298 fCenter->SetName("CenterSame");
299
300 fLength->SetDirectory(0);
301 fWidth->SetDirectory(0);
302 fDistC->SetDirectory(0);
303 fDelta->SetDirectory(0);
304 fSize->SetDirectory(0);
305 fCenter->SetDirectory(0);
306
307 fDistC->SetLineColor(kGreen);
308 fSize->SetLineColor(kGreen);
309 fDelta->SetLineColor(kGreen);
310 fWidth->SetLineColor(kMagenta);
311 fLength->SetLineColor(kCyan);
312 }
313
314 pad->cd(1);
315 gPad->SetBorderMode(0);
316 gPad->SetGridx();
317 gPad->SetGridy();
318 RemoveFromPad("WidthSame");
319 RemoveFromPad("LengthSame");
320 MH::DrawSame(*fWidth, *fLength, "Width'n'Length", same);
321
322 pad->cd(2);
323 gPad->SetBorderMode(0);
324 gPad->SetGridx();
325 gPad->SetGridy();
326 RemoveFromPad("DistCSame");
327 fDistC->Draw(same?"same":"");
328
329 pad->cd(3);
330 gPad->SetGridx();
331 gPad->SetGridy();
332 gPad->SetBorderMode(0);
333 gPad->SetLogx();
334 gPad->SetLogy();
335 RemoveFromPad("SizeSame");
336 fSize->Draw(same?"same":"");
337
338 pad->cd(4);
339 gPad->SetBorderMode(0);
340 gPad->SetGridx();
341 gPad->SetGridy();
342 gPad->SetPad(0.51, 0.01, 0.99, 0.65);
343 if (same)
344 {
345 TH2 *h=dynamic_cast<TH2*>(gPad->FindObject("Center"));
346 if (h)
347 {
348 // This causes crashes in THistPainter::PaintTable
349 // if the z-axis is not kept. No idea why...
350 h->SetDrawOption("z");
351 h->SetMarkerColor(kBlack);
352 }
353
354 RemoveFromPad("CenterSame");
355 fCenter->SetMarkerColor(kGreen);
356 fCenter->Draw("same");
357 }
358 else
359 fCenter->Draw("colz");
360
361 if (fGeomCam)
362 {
363 MHCamera *cam = new MHCamera(*fGeomCam);
364 cam->Draw("same");
365 cam->SetBit(kCanDelete);
366 }
367
368 pad->cd(5);
369 gPad->SetBorderMode(0);
370 gPad->SetGridx();
371 gPad->SetGridy();
372 RemoveFromPad("DeltaSame");
373 fDelta->Draw(same?"same":"");
374
375 pad->cd(6);
376 if (gPad && !same)
377 delete gPad;
378}
379
380TH1 *MHHillas::GetHistByName(const TString name) const
381{
382 if (name.Contains("Width", TString::kIgnoreCase))
383 return fWidth;
384 if (name.Contains("Length", TString::kIgnoreCase))
385 return fLength;
386 if (name.Contains("Size", TString::kIgnoreCase))
387 return fSize;
388 if (name.Contains("Delta", TString::kIgnoreCase))
389 return fDelta;
390 if (name.Contains("DistC", TString::kIgnoreCase))
391 return fDistC;
392 if (name.Contains("Center", TString::kIgnoreCase))
393 return fCenter;
394
395 return NULL;
396}
397
398void MHHillas::Paint(Option_t *opt)
399{
400 MH::SetPalette("pretty");
401 MH::Paint();
402}
Note: See TracBrowser for help on using the repository browser.