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 (tbretz@uni-sw.gwdg.de)
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
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 <TH2.h> // TH2F
|
---|
38 | #include <TStyle.h> // gStyle
|
---|
39 | #include <TColor.h> // SetRGB
|
---|
40 | #include <TCanvas.h> // TCanvas
|
---|
41 |
|
---|
42 | #include "MHillas.h"
|
---|
43 |
|
---|
44 | ClassImp(MHStarMap);
|
---|
45 |
|
---|
46 | // --------------------------------------------------------------------------
|
---|
47 | //
|
---|
48 | // Create the star map histogram
|
---|
49 | //
|
---|
50 | MHStarMap::MHStarMap (const char *name, const char *title)
|
---|
51 | {
|
---|
52 | //
|
---|
53 | // default constructor
|
---|
54 | // creates an a list of histograms for all pixels and both gain channels
|
---|
55 | //
|
---|
56 |
|
---|
57 | //
|
---|
58 | // set the name and title of this object
|
---|
59 | //
|
---|
60 |
|
---|
61 | *fName = name ? name : "MHStarMap" ;
|
---|
62 | *fTitle = title ? title : "Container for a Star Map" ;
|
---|
63 |
|
---|
64 | //
|
---|
65 | // loop over all Pixels and create two histograms
|
---|
66 | // one for the Low and one for the High gain
|
---|
67 | // connect all the histogram with the container fHist
|
---|
68 | //
|
---|
69 | fStarMap = new TH2F("StarMap", "Counts",
|
---|
70 | 150, -300, 300,
|
---|
71 | 150, -300, 300);
|
---|
72 | }
|
---|
73 |
|
---|
74 | // --------------------------------------------------------------------------
|
---|
75 | //
|
---|
76 | // delete the histogram instance
|
---|
77 | //
|
---|
78 | MHStarMap::~MHStarMap()
|
---|
79 | {
|
---|
80 | delete fStarMap;
|
---|
81 | }
|
---|
82 |
|
---|
83 | // --------------------------------------------------------------------------
|
---|
84 | //
|
---|
85 | // Fill the four histograms with data from a MHillas-Container.
|
---|
86 | // Be careful: Only call this with an object of type MHillas
|
---|
87 | //
|
---|
88 | void MHStarMap::Fill(const MParContainer *par)
|
---|
89 | {
|
---|
90 | const MHillas &h = *(MHillas*)par;
|
---|
91 |
|
---|
92 | const float dist = h.GetDist();
|
---|
93 | const float theta = h.GetTheta();
|
---|
94 | const float alpha = h.GetAlpha()/kRad2Deg;
|
---|
95 |
|
---|
96 | const float m = tan(theta+alpha-kPI);
|
---|
97 | const float t = dist*(sin(theta)-cos(theta)*m);
|
---|
98 |
|
---|
99 | if (m>-1 && m<1)
|
---|
100 | for (int x=-298; x<298; x+=4)
|
---|
101 | {
|
---|
102 | const float y = m*x+t;
|
---|
103 |
|
---|
104 | fStarMap->Fill(x, y);
|
---|
105 | }
|
---|
106 | else
|
---|
107 | for (int y=-298; y<298; y+=4)
|
---|
108 | {
|
---|
109 | const float x = (y-t)/m;
|
---|
110 |
|
---|
111 | fStarMap->Fill(x, y);
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | // --------------------------------------------------------------------------
|
---|
116 | //
|
---|
117 | // Set the palette you wanna use:
|
---|
118 | // - you could set the root "Pretty Palette Violet->Red" by
|
---|
119 | // gStyle->SetPalette(1, 0), but in some cases this may look
|
---|
120 | // confusing
|
---|
121 | // - The maximum colors root allowes us to set by ourself
|
---|
122 | // is 50 (idx: 51-100). This colors are set to a grayscaled
|
---|
123 | // palette
|
---|
124 | // - the number of contours must be two less than the number
|
---|
125 | // of palette entries
|
---|
126 | //
|
---|
127 | void MHStarMap::PrepareDrawing() const
|
---|
128 | {
|
---|
129 | const Int_t numg = 32; // number of gray scaled colors
|
---|
130 | const Int_t numw = 32; // number of white
|
---|
131 |
|
---|
132 | Int_t palette[numg+numw];
|
---|
133 |
|
---|
134 | //
|
---|
135 | // The first half of the colors are white.
|
---|
136 | // This is some kind of optical background supression
|
---|
137 | //
|
---|
138 | gROOT->GetColor(51)->SetRGB(1, 1, 1);
|
---|
139 |
|
---|
140 | Int_t i;
|
---|
141 | for (i=0; i<numw; i++)
|
---|
142 | palette[i] = 51;
|
---|
143 |
|
---|
144 | //
|
---|
145 | // now the (gray) scaled part is coming
|
---|
146 | //
|
---|
147 | for (;i<numw+numg; i++)
|
---|
148 | {
|
---|
149 | const Float_t gray = 1.0-(float)(i-numw)/(numg-1.0);
|
---|
150 |
|
---|
151 | gROOT->GetColor(52+i)->SetRGB(gray, gray, gray);
|
---|
152 | palette[i] = 52+i;
|
---|
153 | }
|
---|
154 |
|
---|
155 | //
|
---|
156 | // Set the palette and the number of contour levels
|
---|
157 | //
|
---|
158 | gStyle->SetPalette(numg+numw, palette);
|
---|
159 | fStarMap->SetContour(numg+numw-2);
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 | // --------------------------------------------------------------------------
|
---|
164 | //
|
---|
165 | // Draw clones of the histograms, so that the object can be deleted
|
---|
166 | // and the histogram is still visible in the canvas.
|
---|
167 | // The cloned object is deleted together with the canvas if the canvas is
|
---|
168 | // destroyed. If you want to handle destroying the canvas you can get a
|
---|
169 | // pointer to it from this function
|
---|
170 | //
|
---|
171 | TObject *MHStarMap::DrawClone(Option_t *opt) const
|
---|
172 | {
|
---|
173 | TCanvas *c = new TCanvas("Star Map", "Star Map created from Hillas Parameters", 500, 500);
|
---|
174 |
|
---|
175 | //
|
---|
176 | // This is necessary to get the expected bahviour of DrawClone
|
---|
177 | //
|
---|
178 | gROOT->SetSelectedPad(NULL);
|
---|
179 |
|
---|
180 | PrepareDrawing();
|
---|
181 |
|
---|
182 | fStarMap->DrawClone("colz")->SetBit(kCanDelete);
|
---|
183 |
|
---|
184 | c->Modified();
|
---|
185 | c->Update();
|
---|
186 |
|
---|
187 | return c;
|
---|
188 | }
|
---|
189 |
|
---|
190 | // --------------------------------------------------------------------------
|
---|
191 | //
|
---|
192 | // Creates a new canvas and draw the histogram into it.
|
---|
193 | // Be careful: The histogram belongs to this object and won't get deleted
|
---|
194 | // together with the canvas.
|
---|
195 | //
|
---|
196 | void MHStarMap::Draw(Option_t *)
|
---|
197 | {
|
---|
198 | if (!gPad)
|
---|
199 | {
|
---|
200 | if (!gROOT->GetMakeDefCanvas())
|
---|
201 | return;
|
---|
202 | (gROOT->GetMakeDefCanvas())();
|
---|
203 | }
|
---|
204 |
|
---|
205 | // TCanvas *c = new TCanvas("Star Map", "Star Map created from Hillas Parameters", 500, 500);
|
---|
206 |
|
---|
207 | PrepareDrawing();
|
---|
208 |
|
---|
209 | fStarMap->Draw("colz");
|
---|
210 |
|
---|
211 | gPad->Modified();
|
---|
212 | gPad->Update();
|
---|
213 | }
|
---|
214 |
|
---|