source: trunk/MagicSoft/Mars/mimage/MHHillas.cc@ 2132

Last change on this file since 2132 was 2098, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 9.5 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@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
53ClassImp(MHHillas);
54
55// --------------------------------------------------------------------------
56//
57// Setup four histograms for Width, Length
58//
59MHHillas::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//
116MHHillas::~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//
138Bool_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//
181void 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//
200void 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//
242Bool_t MHHillas::Fill(const MParContainer *par, const Stat_t w)
243{
244 if (!par)
245 {
246 *fLog << err << "MHHillas::Fill: Pointer (!=NULL) expected." << endl;
247 return kFALSE;
248 }
249
250 const MHillas &h = *(MHillas*)par;
251
252 const Double_t d = sqrt(h.GetMeanX()*h.GetMeanX() + h.GetMeanY()*h.GetMeanY());
253 const Double_t scale = fUseMmScale ? 1 : fMm2Deg;
254
255 fLength->Fill(scale*h.GetLength(), w);
256 fWidth ->Fill(scale*h.GetWidth(), w);
257 fDistC ->Fill(scale*d, w);
258 fCenter->Fill(scale*h.GetMeanX(), scale*h.GetMeanY(), w);
259 fDelta ->Fill(kRad2Deg*h.GetDelta(), w);
260 fSize ->Fill(h.GetSize(), w);
261
262 return kTRUE;
263}
264
265// --------------------------------------------------------------------------
266//
267// Setup a inversed deep blue sea palette for the fCenter histogram.
268//
269void MHHillas::SetColors() const
270{
271 gStyle->SetPalette(51, NULL);
272 Int_t c[50];
273 for (int i=0; i<50; i++)
274 c[49-i] = gStyle->GetColorPalette(i);
275 gStyle->SetPalette(50, c);
276}
277
278// --------------------------------------------------------------------------
279//
280// Creates a new canvas and draws the four histograms into it.
281// Be careful: The histograms belongs to this object and won't get deleted
282// together with the canvas.
283//
284void MHHillas::Draw(Option_t *)
285{
286 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
287 pad->SetBorderMode(0);
288
289 AppendPad("");
290
291 pad->Divide(2,3);
292
293 pad->cd(1);
294 gPad->SetBorderMode(0);
295 MH::Draw(*fWidth, *fLength, "Width'n'Length");
296
297 pad->cd(2);
298 gPad->SetBorderMode(0);
299 fDistC->Draw();
300
301 pad->cd(3);
302 gPad->SetBorderMode(0);
303 gPad->SetLogx();
304 fSize->Draw();
305
306 pad->cd(4);
307 gPad->SetBorderMode(0);
308 gPad->SetPad(0.51, 0.01, 0.99, 0.65);
309 SetColors();
310 fCenter->Draw("colz");
311
312 pad->cd(5);
313 gPad->SetBorderMode(0);
314 fDelta->Draw();
315
316 pad->cd(6);
317 delete gPad;
318
319 pad->Modified();
320 pad->Update();
321}
322
323TH1 *MHHillas::GetHistByName(const TString name)
324{
325 if (name.Contains("Width", TString::kIgnoreCase))
326 return fWidth;
327 if (name.Contains("Length", TString::kIgnoreCase))
328 return fLength;
329 if (name.Contains("Size", TString::kIgnoreCase))
330 return fSize;
331 if (name.Contains("Delta", TString::kIgnoreCase))
332 return fDelta;
333 if (name.Contains("DistC", TString::kIgnoreCase))
334 return fDistC;
335 if (name.Contains("Center", TString::kIgnoreCase))
336 return fCenter;
337
338 return NULL;
339}
340
341void MHHillas::Paint(Option_t *opt)
342{
343 SetColors();
344 MH::Paint();
345}
Note: See TracBrowser for help on using the repository browser.