source: trunk/MagicSoft/Mars/mhist/MHHillas.cc@ 1604

Last change on this file since 1604 was 1574, checked in by tbretz, 22 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 10.9 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
34#include "MHHillas.h"
35
36#include <math.h>
37
38#include <TH1.h>
39#include <TH2.h>
40#include <TPad.h>
41#include <TStyle.h>
42#include <TCanvas.h>
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "MParList.h"
48
49#include "MHillas.h"
50#include "MGeomCam.h"
51#include "MBinning.h"
52
53
54ClassImp(MHHillas);
55
56// --------------------------------------------------------------------------
57//
58// Setup four histograms for Width, Length
59//
60MHHillas::MHHillas(const char *name, const char *title)
61 : fMm2Deg(1), fUseMmScale(kTRUE)
62{
63 //
64 // set the name and title of this object
65 //
66 fName = name ? name : "MHHillas";
67 fTitle = title ? title : "Source independent image parameters";
68
69 fLength = new TH1F("Length", "Length of Ellipse", 100, 0, 296.7);
70 fWidth = new TH1F("Width", "Width of Ellipse", 100, 0, 296.7);
71 fDistC = new TH1F("DistC", "Distance from center of camera", 100, 0, 445);
72 fDelta = new TH1F("Delta", "Angle (Main axis - x-axis)", 101, -90, 90);
73 fUsedPix = new TH1F("UsedPix", "Number of used pixels", 150, 0, 150);
74 fCorePix = new TH1F("CorePix", "Number of core pixels", 150, 0, 150);
75
76 fLength->SetLineColor(kBlue);
77 fCorePix->SetLineColor(kRed);
78 fUsedPix->SetLineColor(kGreen);
79
80 fLength->SetDirectory(NULL);
81 fWidth->SetDirectory(NULL);
82 fDistC->SetDirectory(NULL);
83 fDelta->SetDirectory(NULL);
84 fUsedPix->SetDirectory(NULL);
85 fCorePix->SetDirectory(NULL);
86
87 fLength->SetXTitle("Length [mm]");
88 fWidth->SetXTitle("Width [mm]");
89 fDistC->SetXTitle("Distance [mm]");
90 fDelta->SetXTitle("Delta [\\circ]");
91 fUsedPix->SetXTitle("Number of Pixels");
92 fCorePix->SetXTitle("Number of Pixels");
93
94 fLength->SetYTitle("Counts");
95 fWidth->SetYTitle("Counts");
96 fDistC->SetYTitle("Counts");
97 fDelta->SetYTitle("Counts");
98 fUsedPix->SetYTitle("Counts");
99 fCorePix->SetYTitle("Counts");
100
101 MBinning bins;
102 bins.SetEdgesLog(50, 1, 1e7);
103
104 fSize = new TH1F;
105 fSize->SetName("Size");
106 fSize->SetTitle("Number of Photons");
107 fSize->SetDirectory(NULL);
108 fSize->SetXTitle("Size");
109 fSize->SetYTitle("Counts");
110 fSize->GetXaxis()->SetTitleOffset(1.2);
111 fSize->GetXaxis()->SetLabelOffset(-0.015);
112
113 bins.Apply(*fSize);
114
115 fCenter = new TH2F("Center", "Center of Ellipse", 51, -445, 445, 51, -445, 445);
116 fCenter->SetDirectory(NULL);
117 fCenter->SetXTitle("x [mm]");
118 fCenter->SetYTitle("y [mm]");
119 fCenter->SetZTitle("Counts");
120}
121
122// --------------------------------------------------------------------------
123//
124// Delete the histograms
125//
126MHHillas::~MHHillas()
127{
128 delete fLength;
129 delete fWidth;
130
131 delete fDistC;
132 delete fDelta;
133
134 delete fSize;
135 delete fCenter;
136
137 delete fUsedPix;
138 delete fCorePix;
139}
140
141// --------------------------------------------------------------------------
142//
143// Setup the Binning for the histograms automatically if the correct
144// instances of MBinning (with the names 'BinningWidth' and 'BinningLength')
145// are found in the parameter list
146// Use this function if you want to set the conversion factor which
147// is used to convert the mm-scale in the camera plain into the deg-scale
148// used for histogram presentations. The conversion factor is part of
149// the camera geometry. Please create a corresponding MGeomCam container.
150//
151Bool_t MHHillas::SetupFill(const MParList *plist)
152{
153 const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
154 if (!geom)
155 *fLog << warn << GetDescriptor() << ": No Camera Geometry available. Using mm-scale for histograms." << endl;
156 else
157 {
158 fMm2Deg = geom->GetConvMm2Deg();
159 SetMmScale(kFALSE);
160 }
161
162 ApplyBinning(*plist, "Width", fWidth);
163 ApplyBinning(*plist, "Length", fLength);
164 ApplyBinning(*plist, "Dist", fDistC);
165 ApplyBinning(*plist, "Delta", fDelta);
166 ApplyBinning(*plist, "Size", fSize);
167 ApplyBinning(*plist, "Pixels", fUsedPix);
168 ApplyBinning(*plist, "Pixels", fCorePix);
169
170 const MBinning *bins = (MBinning*)plist->FindObject("BinningCamera");
171 if (!bins)
172 {
173 float r = geom ? geom->GetMaxRadius() : 600;
174 r *= 0.9;
175 if (!fUseMmScale)
176 r *= fMm2Deg;
177
178 MBinning b;
179 b.SetEdges(61, -r, r);
180 SetBinning(fCenter, &b, &b);
181 }
182 else
183 SetBinning(fCenter, bins, bins);
184
185
186 return kTRUE;
187}
188
189// --------------------------------------------------------------------------
190//
191// Use this function to setup your own conversion factor between degrees
192// and millimeters. The conversion factor should be the one calculated in
193// MGeomCam. Use this function with Caution: You could create wrong values
194// by setting up your own scale factor.
195//
196void MHHillas::SetMm2Deg(Float_t mmdeg)
197{
198 if (mmdeg<0)
199 {
200 *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
201 return;
202 }
203
204 if (fMm2Deg>=0)
205 *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
206
207 fMm2Deg = mmdeg;
208}
209
210// --------------------------------------------------------------------------
211//
212// With this function you can convert the histogram ('on the fly') between
213// degrees and millimeters.
214//
215void MHHillas::SetMmScale(Bool_t mmscale)
216{
217 if (fUseMmScale == mmscale)
218 return;
219
220 if (fMm2Deg<0)
221 {
222 *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
223 return;
224 }
225
226 const Double_t scale = mmscale ? 1./fMm2Deg : fMm2Deg;
227 MH::ScaleAxis(fLength, scale);
228 MH::ScaleAxis(fWidth, scale);
229 MH::ScaleAxis(fDistC, scale);
230 MH::ScaleAxis(fCenter, scale, scale);
231
232 if (mmscale)
233 {
234 fLength->SetXTitle("Length [mm]");
235 fWidth->SetXTitle("Width [mm]");
236 fDistC->SetXTitle("Distance [mm]");
237 fCenter->SetXTitle("x [mm]");
238 fCenter->SetYTitle("y [mm]");
239 }
240 else
241 {
242 fLength->SetXTitle("Length [\\circ]");
243 fWidth->SetXTitle("Width [\\circ]");
244 fDistC->SetXTitle("Distance [\\circ]");
245 fCenter->SetXTitle("x [\\circ]");
246 fCenter->SetYTitle("y [\\circ]");
247 }
248
249 fUseMmScale = mmscale;
250}
251
252// --------------------------------------------------------------------------
253//
254// Fill the histograms with data from a MHillas-Container.
255// Be careful: Only call this with an object of type MHillas
256//
257Bool_t MHHillas::Fill(const MParContainer *par)
258{
259 const MHillas &h = *(MHillas*)par;
260
261 const Double_t d = sqrt(h.GetMeanX()*h.GetMeanX() + h.GetMeanY()*h.GetMeanY());
262 const Double_t scale = fUseMmScale ? 1 : fMm2Deg;
263
264 fLength ->Fill(scale*h.GetLength());
265 fWidth ->Fill(scale*h.GetWidth());
266 fDistC ->Fill(scale*d);
267 fCenter ->Fill(scale*h.GetMeanX(), scale*h.GetMeanY());
268 fDelta ->Fill(kRad2Deg*h.GetDelta());
269 fSize ->Fill(h.GetSize());
270 fUsedPix->Fill(h.GetNumUsedPixels());
271 fCorePix->Fill(h.GetNumCorePixels());
272
273 return kTRUE;
274}
275
276// --------------------------------------------------------------------------
277//
278// Setup a inversed deep blue sea palette for the fCenter histogram.
279//
280void MHHillas::SetColors() const
281{
282 // FIXME: This must be redone each time the canvas is repainted....
283 gStyle->SetPalette(51, NULL);
284 Int_t c[50];
285 for (int i=0; i<50; i++)
286 c[49-i] = gStyle->GetColorPalette(i);
287 gStyle->SetPalette(50, c);
288}
289
290// --------------------------------------------------------------------------
291//
292// Draw clones of four histograms. So that the object can be deleted
293// and the histograms are still visible in the canvas.
294// The cloned object are deleted together with the canvas if the canvas is
295// destroyed. If you want to handle dostroying the canvas you can get a
296// pointer to it from this function
297//
298TObject *MHHillas::DrawClone(Option_t *opt) const
299{
300 TCanvas *c = MakeDefCanvas(this, 720, 810);
301 c->Divide(2,3);
302
303 gROOT->SetSelectedPad(NULL);
304
305 c->cd(1);
306 DrawCopy(*fWidth, *fLength, "Width / Length");
307
308 c->cd(2);
309 gPad->SetLogx();
310 fSize->DrawCopy();
311
312 c->cd(3);
313 DrawCopy(*fCorePix, *fUsedPix, "Number of core/used Pixels");
314
315 c->cd(4);
316 fDelta->DrawCopy();
317
318 c->cd(5);
319 fDistC->DrawCopy();
320
321 c->cd(6);
322 SetColors();
323 fCenter->DrawCopy("colz");
324
325 c->Modified();
326 c->Update();
327
328 return c;
329}
330
331// --------------------------------------------------------------------------
332//
333// Creates a new canvas and draws the four histograms into it.
334// Be careful: The histograms belongs to this object and won't get deleted
335// together with the canvas.
336//
337void MHHillas::Draw(Option_t *)
338{
339 if (!gPad)
340 MakeDefCanvas(this, 720, 810);
341
342 gPad->Divide(2,3);
343
344 gPad->cd(1);
345 MH::Draw(*fWidth, *fLength, "Width / Length");
346
347 gPad->cd(2);
348 gPad->SetLogx();
349 fSize->Draw();
350
351 gPad->cd(3);
352 MH::Draw(*fCorePix, *fUsedPix, "Number of core/used Pixels");
353
354 gPad->cd(4);
355 fDelta->Draw();
356
357 gPad->cd(5);
358 fDistC->Draw();
359
360 gPad->cd(6);
361 SetColors();
362 fCenter->Draw("colz");
363
364 gPad->Modified();
365 gPad->Update();
366}
367
368TH1 *MHHillas::GetHistByName(const TString name)
369{
370 if (name.Contains("Width", TString::kIgnoreCase))
371 return fWidth;
372 if (name.Contains("Length", TString::kIgnoreCase))
373 return fLength;
374 if (name.Contains("Size", TString::kIgnoreCase))
375 return fSize;
376 if (name.Contains("Core", TString::kIgnoreCase))
377 return fCorePix;
378 if (name.Contains("Used", TString::kIgnoreCase))
379 return fUsedPix;
380 if (name.Contains("Delta", TString::kIgnoreCase))
381 return fDelta;
382 if (name.Contains("DistC", TString::kIgnoreCase))
383 return fDistC;
384 if (name.Contains("Center", TString::kIgnoreCase))
385 return fCenter;
386
387 return NULL;
388}
Note: See TracBrowser for help on using the repository browser.