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 |
|
---|
50 | ClassImp(MHStarMap);
|
---|
51 |
|
---|
52 | // --------------------------------------------------------------------------
|
---|
53 | //
|
---|
54 | // Create the star map histogram
|
---|
55 | //
|
---|
56 | MHStarMap::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 | //
|
---|
92 | MHStarMap::~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 | //
|
---|
107 | Bool_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 | //
|
---|
148 | Bool_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 |
|
---|
159 | float t = h.GetMeanY() - m*h.GetMeanX();
|
---|
160 |
|
---|
161 | if (!fUseMmScale)
|
---|
162 | t *= fMm2Deg;
|
---|
163 |
|
---|
164 | // get step size ds along the main axis of the ellipse
|
---|
165 | TAxis &axe = *fStarMap->GetXaxis();
|
---|
166 | const int N = axe.GetNbins();
|
---|
167 | const float xmin = axe.GetBinLowEdge(1);
|
---|
168 | const float xmax = axe.GetBinLowEdge(N+1);
|
---|
169 | const float ds = (xmax-xmin) / 200.0;
|
---|
170 |
|
---|
171 | if (m>-1 && m<1)
|
---|
172 | {
|
---|
173 | float dx = ds * cosd;
|
---|
174 | float x = xmin + dx/2.0;
|
---|
175 | int N1 = (int) ((xmax-xmin)/dx+1.0);
|
---|
176 |
|
---|
177 | for (int i=0; i<N1; i++)
|
---|
178 | {
|
---|
179 | const float y = m*x+t;
|
---|
180 | fStarMap->Fill(x, y);
|
---|
181 | x += dx;
|
---|
182 | }
|
---|
183 | }
|
---|
184 | else
|
---|
185 | {
|
---|
186 | TAxis &axe = *fStarMap->GetYaxis();
|
---|
187 | const int M = axe.GetNbins();
|
---|
188 | const float ymin = axe.GetBinLowEdge(1);
|
---|
189 | const float ymax = axe.GetBinLowEdge(M+1);
|
---|
190 |
|
---|
191 | float dy = ds * sind;
|
---|
192 | float y = ymin + dy/2.0;
|
---|
193 | int M1 = (int) ((ymax-ymin)/dy+1.0);
|
---|
194 |
|
---|
195 | for (int i=0; i<M1; i++)
|
---|
196 | {
|
---|
197 | const float x = (y-t)/m;
|
---|
198 | fStarMap->Fill(x, y);
|
---|
199 | y += dy;
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | return kTRUE;
|
---|
204 | }
|
---|
205 |
|
---|
206 | // --------------------------------------------------------------------------
|
---|
207 | //
|
---|
208 | // Use this function to setup your own conversion factor between degrees
|
---|
209 | // and millimeters. The conversion factor should be the one calculated in
|
---|
210 | // MGeomCam. Use this function with Caution: You could create wrong values
|
---|
211 | // by setting up your own scale factor.
|
---|
212 | //
|
---|
213 | void MHStarMap::SetMm2Deg(Float_t mmdeg)
|
---|
214 | {
|
---|
215 | if (mmdeg<0)
|
---|
216 | {
|
---|
217 | *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
|
---|
218 | return;
|
---|
219 | }
|
---|
220 |
|
---|
221 | if (fMm2Deg>=0)
|
---|
222 | *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
|
---|
223 |
|
---|
224 | fMm2Deg = mmdeg;
|
---|
225 | }
|
---|
226 |
|
---|
227 | // --------------------------------------------------------------------------
|
---|
228 | //
|
---|
229 | // With this function you can convert the histogram ('on the fly') between
|
---|
230 | // degrees and millimeters.
|
---|
231 | //
|
---|
232 | void MHStarMap::SetMmScale(Bool_t mmscale)
|
---|
233 | {
|
---|
234 | if (fUseMmScale == mmscale)
|
---|
235 | return;
|
---|
236 |
|
---|
237 | if (fMm2Deg<0)
|
---|
238 | {
|
---|
239 | *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
|
---|
240 | return;
|
---|
241 | }
|
---|
242 |
|
---|
243 | if (fUseMmScale)
|
---|
244 | {
|
---|
245 | fStarMap->SetXTitle("x [mm]");
|
---|
246 | fStarMap->SetYTitle("y [mm]");
|
---|
247 |
|
---|
248 | fStarMap->Scale(1./fMm2Deg);
|
---|
249 | }
|
---|
250 | else
|
---|
251 | {
|
---|
252 | fStarMap->SetXTitle("x [\\circ]");
|
---|
253 | fStarMap->SetYTitle("y [\\circ]");
|
---|
254 |
|
---|
255 | fStarMap->Scale(1./fMm2Deg);
|
---|
256 | }
|
---|
257 |
|
---|
258 | fUseMmScale = mmscale;
|
---|
259 | }
|
---|
260 |
|
---|
261 | // --------------------------------------------------------------------------
|
---|
262 | //
|
---|
263 | // Set the palette you wanna use:
|
---|
264 | // - you could set the root "Pretty Palette Violet->Red" by
|
---|
265 | // gStyle->SetPalette(1, 0), but in some cases this may look
|
---|
266 | // confusing
|
---|
267 | // - The maximum colors root allowes us to set by ourself
|
---|
268 | // is 50 (idx: 51-100). This colors are set to a grayscaled
|
---|
269 | // palette
|
---|
270 | // - the number of contours must be two less than the number
|
---|
271 | // of palette entries
|
---|
272 | //
|
---|
273 | void MHStarMap::PrepareDrawing() const
|
---|
274 | {
|
---|
275 | const Int_t numg = 32; // number of gray scaled colors
|
---|
276 | const Int_t numw = 32; // number of white
|
---|
277 |
|
---|
278 | Int_t palette[numg+numw];
|
---|
279 |
|
---|
280 | //
|
---|
281 | // The first half of the colors are white.
|
---|
282 | // This is some kind of optical background supression
|
---|
283 | //
|
---|
284 | gROOT->GetColor(51)->SetRGB(1, 1, 1);
|
---|
285 |
|
---|
286 | Int_t i;
|
---|
287 | for (i=0; i<numw; i++)
|
---|
288 | palette[i] = 51;
|
---|
289 |
|
---|
290 | //
|
---|
291 | // now the (gray) scaled part is coming
|
---|
292 | //
|
---|
293 | for (;i<numw+numg; i++)
|
---|
294 | {
|
---|
295 | const Float_t gray = 1.0-(float)(i-numw)/(numg-1.0);
|
---|
296 |
|
---|
297 | gROOT->GetColor(52+i)->SetRGB(gray, gray, gray);
|
---|
298 | palette[i] = 52+i;
|
---|
299 | }
|
---|
300 |
|
---|
301 | //
|
---|
302 | // Set the palette and the number of contour levels
|
---|
303 | //
|
---|
304 | gStyle->SetPalette(numg+numw, palette);
|
---|
305 | fStarMap->SetContour(numg+numw-2);
|
---|
306 | }
|
---|
307 |
|
---|
308 |
|
---|
309 | // --------------------------------------------------------------------------
|
---|
310 | //
|
---|
311 | // Draw clones of the histograms, so that the object can be deleted
|
---|
312 | // and the histogram is still visible in the canvas.
|
---|
313 | // The cloned object is deleted together with the canvas if the canvas is
|
---|
314 | // destroyed. If you want to handle destroying the canvas you can get a
|
---|
315 | // pointer to it from this function
|
---|
316 | //
|
---|
317 | TObject *MHStarMap::DrawClone(Option_t *opt) const
|
---|
318 | {
|
---|
319 | TCanvas *c=MakeDefCanvas(fStarMap, 500, 500);
|
---|
320 |
|
---|
321 | //
|
---|
322 | // This is necessary to get the expected bahviour of DrawClone
|
---|
323 | //
|
---|
324 | gROOT->SetSelectedPad(NULL);
|
---|
325 |
|
---|
326 | PrepareDrawing();
|
---|
327 |
|
---|
328 | fStarMap->DrawCopy("colz");
|
---|
329 |
|
---|
330 | c->Modified();
|
---|
331 | c->Update();
|
---|
332 |
|
---|
333 | return c;
|
---|
334 | }
|
---|
335 |
|
---|
336 | // --------------------------------------------------------------------------
|
---|
337 | //
|
---|
338 | // Creates a new canvas and draw the histogram into it.
|
---|
339 | // Be careful: The histogram belongs to this object and won't get deleted
|
---|
340 | // together with the canvas.
|
---|
341 | //
|
---|
342 | void MHStarMap::Draw(Option_t *)
|
---|
343 | {
|
---|
344 | if (!gPad)
|
---|
345 | MakeDefCanvas(fStarMap, 500, 500);
|
---|
346 |
|
---|
347 | PrepareDrawing();
|
---|
348 |
|
---|
349 | fStarMap->Draw("colz");
|
---|
350 |
|
---|
351 | gPad->Modified();
|
---|
352 | gPad->Update();
|
---|
353 | }
|
---|