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

Last change on this file since 1958 was 1956, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 9.2 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
35#include "MHStarMap.h"
36
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
52// --------------------------------------------------------------------------
53//
54// Create the star map histogram
55//
56MHStarMap::MHStarMap(const char *name, const char *title)
57 : fMm2Deg(-1), fUseMmScale(kTRUE)
58{
59 //
60 // default constructor
61 // creates an a list of histograms for all pixels and both gain channels
62 //
63
64 //
65 // set the name and title of this object
66 //
67 fName = name ? name : "MHStarMap" ;
68 fTitle = title ? title : "Container for a Star Map" ;
69
70 *fLog << warn << "WARNING - Using MHStarMap doesn't take care of the Source Position!" << endl;
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 return kTRUE;
141}
142
143// --------------------------------------------------------------------------
144//
145// Fill the four histograms with data from a MHillas-Container.
146// Be careful: Only call this with an object of type MHillas
147//
148Bool_t MHStarMap::Fill(const MParContainer *par)
149{
150 const MHillas &h = *(MHillas*)par;
151
152 const float delta = h.GetDelta();
153
154 const float m = tan(delta);
155 const float cosd = 1.0/sqrt(1.0+m*m);
156 const float sind = sqrt(1.0-cosd*cosd);
157
158 float t = h.GetMeanY() - m*h.GetMeanX();
159
160 if (!fUseMmScale)
161 t *= fMm2Deg;
162
163 // get step size ds along the main axis of the ellipse
164 const TAxis &axex = *fStarMap->GetXaxis();
165 const float xmin = axex.GetXmin();
166 const float xmax = axex.GetXmax();
167
168 // FIXME: Fixed number?
169 const float ds = (xmax-xmin) / 200.0;
170
171 if (m>-1 && m<1)
172 {
173 const float dx = ds * cosd;
174
175 for (float x=xmin+dx/2; x<(xmax-xmin)+dx; x+=dx)
176 fStarMap->Fill(x, m*x+t);
177 }
178 else
179 {
180 const TAxis &axey = *fStarMap->GetYaxis();
181 const float ymin = axey.GetXmin();
182 const float ymax = axey.GetXmax();
183
184 const float dy = ds * sind;
185
186 for (float y=ymin+dy/2; y<(ymax-ymin)+dy; y+=dy)
187 fStarMap->Fill((y-t)/m, y);
188 }
189
190 return kTRUE;
191}
192
193// --------------------------------------------------------------------------
194//
195// Use this function to setup your own conversion factor between degrees
196// and millimeters. The conversion factor should be the one calculated in
197// MGeomCam. Use this function with Caution: You could create wrong values
198// by setting up your own scale factor.
199//
200void MHStarMap::SetMm2Deg(Float_t mmdeg)
201{
202 if (mmdeg<0)
203 {
204 *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
205 return;
206 }
207
208 if (fMm2Deg>=0)
209 *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
210
211 fMm2Deg = mmdeg;
212}
213
214// --------------------------------------------------------------------------
215//
216// With this function you can convert the histogram ('on the fly') between
217// degrees and millimeters.
218//
219void MHStarMap::SetMmScale(Bool_t mmscale)
220{
221 if (fUseMmScale == mmscale)
222 return;
223
224 if (fMm2Deg<0)
225 {
226 *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
227 return;
228 }
229
230 if (fUseMmScale)
231 {
232 fStarMap->SetXTitle("x [mm]");
233 fStarMap->SetYTitle("y [mm]");
234
235 fStarMap->Scale(1./fMm2Deg);
236 }
237 else
238 {
239 fStarMap->SetXTitle("x [\\circ]");
240 fStarMap->SetYTitle("y [\\circ]");
241
242 fStarMap->Scale(1./fMm2Deg);
243 }
244
245 fUseMmScale = mmscale;
246}
247
248// --------------------------------------------------------------------------
249//
250// Set the palette you wanna use:
251// - you could set the root "Pretty Palette Violet->Red" by
252// gStyle->SetPalette(1, 0), but in some cases this may look
253// confusing
254// - The maximum colors root allowes us to set by ourself
255// is 50 (idx: 51-100). This colors are set to a grayscaled
256// palette
257// - the number of contours must be two less than the number
258// of palette entries
259//
260void MHStarMap::PrepareDrawing() const
261{
262 const Int_t numg = 32; // number of gray scaled colors
263 const Int_t numw = 32; // number of white
264
265 Int_t palette[numg+numw];
266
267 //
268 // The first half of the colors are white.
269 // This is some kind of optical background supression
270 //
271 gROOT->GetColor(51)->SetRGB(1, 1, 1);
272
273 Int_t i;
274 for (i=0; i<numw; i++)
275 palette[i] = 51;
276
277 //
278 // now the (gray) scaled part is coming
279 //
280 for (;i<numw+numg; i++)
281 {
282 const Float_t gray = 1.0-(float)(i-numw)/(numg-1.0);
283
284 gROOT->GetColor(52+i)->SetRGB(gray, gray, gray);
285 palette[i] = 52+i;
286 }
287
288 //
289 // Set the palette and the number of contour levels
290 //
291 gStyle->SetPalette(numg+numw, palette);
292 fStarMap->SetContour(numg+numw-2);
293}
294
295
296// --------------------------------------------------------------------------
297//
298// Draw clones of the histograms, so that the object can be deleted
299// and the histogram is still visible in the canvas.
300// The cloned object is deleted together with the canvas if the canvas is
301// destroyed. If you want to handle destroying the canvas you can get a
302// pointer to it from this function
303//
304TObject *MHStarMap::DrawClone(Option_t *opt) const
305{
306 TCanvas *c=MakeDefCanvas(fStarMap, 500, 500);
307
308 //
309 // This is necessary to get the expected bahviour of DrawClone
310 //
311 gROOT->SetSelectedPad(NULL);
312
313 PrepareDrawing();
314
315 fStarMap->DrawCopy("colz");
316
317 c->Modified();
318 c->Update();
319
320 return c;
321}
322
323// --------------------------------------------------------------------------
324//
325// Creates a new canvas and draw the histogram into it.
326// Be careful: The histogram belongs to this object and won't get deleted
327// together with the canvas.
328//
329void MHStarMap::Draw(Option_t *)
330{
331 if (!gPad)
332 MakeDefCanvas(fStarMap, 500, 500);
333
334 PrepareDrawing();
335
336 fStarMap->Draw("colz");
337
338 gPad->Modified();
339 gPad->Update();
340}
Note: See TracBrowser for help on using the repository browser.