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

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