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

Last change on this file since 1203 was 1203, checked in by rkb, 23 years ago
*** empty log message ***
File size: 5.8 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 delta = h.GetDelta();
98
99 const float m = tan(delta);
100 const float t = m*h.GetMeanX()-h.GetMeanY();
101
102 if (m>-1 && m<1)
103 for (int x=-298; x<298; x+=4)
104 {
105 const float y = m*x+t;
106
107 fStarMap->Fill(x, y);
108 }
109 else
110 for (int y=-298; y<298; y+=4)
111 {
112 const float x = (y-t)/m;
113
114 fStarMap->Fill(x, y);
115 }
116}
117
118// --------------------------------------------------------------------------
119//
120// Set the palette you wanna use:
121// - you could set the root "Pretty Palette Violet->Red" by
122// gStyle->SetPalette(1, 0), but in some cases this may look
123// confusing
124// - The maximum colors root allowes us to set by ourself
125// is 50 (idx: 51-100). This colors are set to a grayscaled
126// palette
127// - the number of contours must be two less than the number
128// of palette entries
129//
130void MHStarMap::PrepareDrawing() const
131{
132 const Int_t numg = 32; // number of gray scaled colors
133 const Int_t numw = 32; // number of white
134
135 Int_t palette[numg+numw];
136
137 //
138 // The first half of the colors are white.
139 // This is some kind of optical background supression
140 //
141 gROOT->GetColor(51)->SetRGB(1, 1, 1);
142
143 Int_t i;
144 for (i=0; i<numw; i++)
145 palette[i] = 51;
146
147 //
148 // now the (gray) scaled part is coming
149 //
150 for (;i<numw+numg; i++)
151 {
152 const Float_t gray = 1.0-(float)(i-numw)/(numg-1.0);
153
154 gROOT->GetColor(52+i)->SetRGB(gray, gray, gray);
155 palette[i] = 52+i;
156 }
157
158 //
159 // Set the palette and the number of contour levels
160 //
161 gStyle->SetPalette(numg+numw, palette);
162 fStarMap->SetContour(numg+numw-2);
163}
164
165
166// --------------------------------------------------------------------------
167//
168// Draw clones of the histograms, so that the object can be deleted
169// and the histogram is still visible in the canvas.
170// The cloned object is deleted together with the canvas if the canvas is
171// destroyed. If you want to handle destroying the canvas you can get a
172// pointer to it from this function
173//
174TObject *MHStarMap::DrawClone(Option_t *opt) const
175{
176 TCanvas *c=MakeDefCanvas(fStarMap, 500, 500);
177
178 //
179 // This is necessary to get the expected bahviour of DrawClone
180 //
181 gROOT->SetSelectedPad(NULL);
182
183 PrepareDrawing();
184
185 fStarMap->DrawCopy("colz");
186
187 c->Modified();
188 c->Update();
189
190 return c;
191}
192
193// --------------------------------------------------------------------------
194//
195// Creates a new canvas and draw the histogram into it.
196// Be careful: The histogram belongs to this object and won't get deleted
197// together with the canvas.
198//
199void MHStarMap::Draw(Option_t *)
200{
201 if (!gPad)
202 MakeDefCanvas(fStarMap, 500, 500);
203
204 PrepareDrawing();
205
206 fStarMap->Draw("colz");
207
208 gPad->Modified();
209 gPad->Update();
210}
Note: See TracBrowser for help on using the repository browser.