source: trunk/MagicSoft/Mars/mhist/MHStarMap.cc@ 2658

Last change on this file since 2658 was 2297, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 9.4 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 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHStarMap
28//
29// This class contains a 2-dimensional histogram. It should show some
30// kind of star map. The algorith which calculates the star map
31// from the Hillas parameters (Fill) can be enhanced.
32//
33/////////////////////////////////////////////////////////////////////////////
34#include "MHStarMap.h"
35
36#include <TH2.h>
37#include <TStyle.h> // gStyle
38#include <TColor.h> // SetRGB
39#include <TCanvas.h> // TCanvas
40
41#include "MLog.h"
42#include "MLogManip.h"
43
44#include "MParList.h"
45
46#include "MGeomCam.h"
47#include "MHillas.h"
48#include "MBinning.h"
49
50ClassImp(MHStarMap);
51
52using namespace std;
53
54// --------------------------------------------------------------------------
55//
56// Create the star map histogram
57//
58MHStarMap::MHStarMap(const char *name, const char *title)
59 : fMm2Deg(-1), fUseMmScale(kTRUE)
60{
61 //
62 // default constructor
63 // creates an a list of histograms for all pixels and both gain channels
64 //
65
66 //
67 // set the name and title of this object
68 //
69 fName = name ? name : "MHStarMap" ;
70 fTitle = title ? title : "Container for a Star Map" ;
71
72 //
73 // loop over all Pixels and create two histograms
74 // one for the Low and one for the High gain
75 // connect all the histogram with the container fHist
76 //
77 fStarMap = new TH2F("StarMap", " 2D Hillas Star Map ",
78 150, -300, 300,
79 150, -300, 300);
80
81 fStarMap->SetDirectory(NULL);
82
83 fStarMap->SetXTitle("x [mm]");
84 fStarMap->SetYTitle("y [mm]");
85 fStarMap->SetZTitle("Counts");
86}
87
88// --------------------------------------------------------------------------
89//
90// delete the histogram instance
91//
92MHStarMap::~MHStarMap()
93{
94 delete fStarMap;
95}
96
97// --------------------------------------------------------------------------
98//
99// Setup the Binning for the histograms automatically if the correct
100// instances of MBinning (with the names 'BinningCamera')
101// are found in the parameter list
102// Use this function if you want to set the conversion factor which
103// is used to convert the mm-scale in the camera plain into the deg-scale
104// used for histogram presentations. The conversion factor is part of
105// the camera geometry. Please create a corresponding MGeomCam container.
106//
107Bool_t MHStarMap::SetupFill(const MParList *plist)
108{
109 const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
110 if (geom)
111 {
112 fMm2Deg = geom->GetConvMm2Deg();
113 fUseMmScale = kFALSE;
114
115 fStarMap->SetXTitle("x [\\circ]");
116 fStarMap->SetYTitle("y [\\circ]");
117 }
118
119 const MBinning *bins = (MBinning*)plist->FindObject("BinningStarMap");
120 if (!bins)
121 {
122 float r = geom ? geom->GetMaxRadius() : 600;
123 r *= 5./6;
124 if (!fUseMmScale)
125 r *= fMm2Deg;
126
127 MBinning b;
128 b.SetEdges(100, -r, r);
129 SetBinning(fStarMap, &b, &b);
130 }
131 else
132 SetBinning(fStarMap, bins, bins);
133
134 if (!geom)
135 {
136 *fLog << warn << dbginf << "No Camera Geometry available. Using mm-scale for histograms." << endl;
137 return kTRUE;
138 }
139
140 *fLog << warn << "WARNING - Using MHStarMap doesn't take care of the Source Position!" << endl;
141
142 return kTRUE;
143}
144
145// --------------------------------------------------------------------------
146//
147// Fill the four histograms with data from a MHillas-Container.
148// Be careful: Only call this with an object of type MHillas
149//
150Bool_t MHStarMap::Fill(const MParContainer *par, const Stat_t w)
151{
152 const MHillas &h = *(MHillas*)par;
153
154 const float delta = h.GetDelta();
155
156 const float m = tan(delta);
157 const float cosd = 1.0/sqrt(1.0+m*m);
158 const float sind = sqrt(1.0-cosd*cosd);
159
160 float t = h.GetMeanY() - m*h.GetMeanX();
161
162 if (!fUseMmScale)
163 t *= fMm2Deg;
164
165 // get step size ds along the main axis of the ellipse
166 const TAxis &axex = *fStarMap->GetXaxis();
167 const float xmin = axex.GetXmin();
168 const float xmax = axex.GetXmax();
169
170 // FIXME: Fixed number?
171 const float ds = (xmax-xmin) / 200.0;
172
173 if (m>-1 && m<1)
174 {
175 const float dx = ds * cosd;
176
177 for (float x=xmin+dx/2; x<(xmax-xmin)+dx; x+=dx)
178 fStarMap->Fill(x, m*x+t, w);
179 }
180 else
181 {
182 const TAxis &axey = *fStarMap->GetYaxis();
183 const float ymin = axey.GetXmin();
184 const float ymax = axey.GetXmax();
185
186 const float dy = ds * sind;
187
188 for (float y=ymin+dy/2; y<(ymax-ymin)+dy; y+=dy)
189 fStarMap->Fill((y-t)/m, y, w);
190 }
191
192 return kTRUE;
193}
194
195// --------------------------------------------------------------------------
196//
197// Use this function to setup your own conversion factor between degrees
198// and millimeters. The conversion factor should be the one calculated in
199// MGeomCam. Use this function with Caution: You could create wrong values
200// by setting up your own scale factor.
201//
202void MHStarMap::SetMm2Deg(Float_t mmdeg)
203{
204 if (mmdeg<0)
205 {
206 *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
207 return;
208 }
209
210 if (fMm2Deg>=0)
211 *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
212
213 fMm2Deg = mmdeg;
214}
215
216// --------------------------------------------------------------------------
217//
218// With this function you can convert the histogram ('on the fly') between
219// degrees and millimeters.
220//
221void MHStarMap::SetMmScale(Bool_t mmscale)
222{
223 if (fUseMmScale == mmscale)
224 return;
225
226 if (fMm2Deg<0)
227 {
228 *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
229 return;
230 }
231
232 if (fUseMmScale)
233 {
234 fStarMap->SetXTitle("x [mm]");
235 fStarMap->SetYTitle("y [mm]");
236
237 fStarMap->Scale(1./fMm2Deg);
238 }
239 else
240 {
241 fStarMap->SetXTitle("x [\\circ]");
242 fStarMap->SetYTitle("y [\\circ]");
243
244 fStarMap->Scale(1./fMm2Deg);
245 }
246
247 fUseMmScale = mmscale;
248}
249
250// --------------------------------------------------------------------------
251//
252// Set the palette you wanna use:
253// - you could set the root "Pretty Palette Violet->Red" by
254// gStyle->SetPalette(1, 0), but in some cases this may look
255// confusing
256// - The maximum colors root allowes us to set by ourself
257// is 50 (idx: 51-100). This colors are set to a grayscaled
258// palette
259// - the number of contours must be two less than the number
260// of palette entries
261//
262void MHStarMap::PrepareDrawing() const
263{
264 const Int_t numg = 32; // number of gray scaled colors
265 const Int_t numw = 32; // number of white
266
267 Int_t palette[numg+numw];
268
269 //
270 // The first half of the colors are white.
271 // This is some kind of optical background supression
272 //
273 gROOT->GetColor(51)->SetRGB(1, 1, 1);
274
275 Int_t i;
276 for (i=0; i<numw; i++)
277 palette[i] = 51;
278
279 //
280 // now the (gray) scaled part is coming
281 //
282 for (;i<numw+numg; i++)
283 {
284 const Float_t gray = 1.0-(float)(i-numw)/(numg-1.0);
285
286 gROOT->GetColor(52+i)->SetRGB(gray, gray, gray);
287 palette[i] = 52+i;
288 }
289
290 //
291 // Set the palette and the number of contour levels
292 //
293 gStyle->SetPalette(numg+numw, palette);
294 fStarMap->SetContour(numg+numw-2);
295}
296
297// --------------------------------------------------------------------------
298//
299// Draw clones of the histograms, so that the object can be deleted
300// and the histogram is still visible in the canvas.
301// The cloned object is deleted together with the canvas if the canvas is
302// destroyed. If you want to handle destroying the canvas you can get a
303// pointer to it from this function
304//
305TObject *MHStarMap::DrawClone(Option_t *opt) const
306{
307 return MH::DrawClone(opt, 500, 500);
308}
309
310// --------------------------------------------------------------------------
311//
312// Creates a new canvas and draw the histogram into it.
313// Be careful: The histogram belongs to this object and won't get deleted
314// together with the canvas.
315//
316void MHStarMap::Draw(Option_t *)
317{
318 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this, 500, 500);
319 pad->SetBorderMode(0);
320
321 pad->Divide(1,1);
322
323 pad->cd(1);
324 gPad->SetBorderMode(0);
325
326 AppendPad("");
327}
328
329void MHStarMap::Paint(Option_t *opt)
330{
331 //
332 // Maintain aspect ratio
333 //
334 const float w = gPad->GetWw();
335 const float h = gPad->GetWh();
336
337 if (h<w)
338 gPad->SetPad((1.-h/w)/2, 0, (h/w+1)/2, 1);
339 else
340 gPad->SetPad(0, (1.-w/h)/2, 1, (w/h+1)/2);
341
342 //
343 // Maintain colors
344 //
345 PrepareDrawing();
346
347 //
348 // Paint Histogram
349 //
350 fStarMap->Paint("colz");
351}
Note: See TracBrowser for help on using the repository browser.