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

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