source: trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.cc@ 8405

Last change on this file since 8405 was 8388, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 8.3 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 03/2007 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Michael Backes 03/2007 <mailto:michael.backes@udo.edu>
20!
21! Copyright: MAGIC Software Development, 2000-2007
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MGeomCamDwarf
29//
30// This class stores the geometry information of the Dwarf camera.
31// MGeomCamDwarf cam; // Creates the 313 pixel dwarf camera
32//
33// It can also be used to create a hexagonal camera with identical sized
34// pixels and n rings (while the central pixel is counted as ring 0).
35// MGeomCamDwarf cam(9, 21); // Creates the CT3 camera
36//
37// Or it can be used to create a roundish camera, similar to a
38// hexagonal camera, but the edges filled with additional pixels
39// inside a circle.
40// MGeomCamDwarf cam(
41//
42////////////////////////////////////////////////////////////////////////////
43#include "MGeomCamDwarf.h"
44
45#include <iostream>
46#include <TArrayI.h>
47
48#include "MGeomPix.h"
49
50ClassImp(MGeomCamDwarf);
51
52using namespace std;
53
54// --------------------------------------------------------------------------
55//
56// Dwarf camera has 313 pixels. For geometry and Next Neighbor info see
57// CreateCam and CreateNN
58//
59MGeomCamDwarf::MGeomCamDwarf(const char *name)
60 : MGeomCam(CalcNumPix(9.5), 4.57, name, "Geometry information of Dwarf Camera")
61{
62 CreateCam(21, 9.5);
63 CreateNN();
64 InitGeometry();
65}
66
67// --------------------------------------------------------------------------
68//
69// Use this to create a camera with a roundish shape and a radius rad in
70// millimeter containing the pixel centers. The pixel will have a diameter
71// diameter in millimeters, and a distance dist in meters.
72//
73MGeomCamDwarf::MGeomCamDwarf(Double_t rad, Double_t diameter, Double_t dist, const char *name)
74 : MGeomCam(CalcNumPix(diameter<=0 ? rad : rad/diameter), dist, name, "Geometry information for a roundish camera")
75{
76 CreateCam(diameter, diameter<=0 ? rad : rad/diameter);
77 CreateNN();
78 InitGeometry();
79}
80
81// --------------------------------------------------------------------------
82//
83// Use this to create a camera with a hexagonal shape and rings rings.
84// The first ring around the central pixel is 1. The pixel will have a
85// diameter diameter in millimeters, and a distance dist in meters.
86//
87MGeomCamDwarf::MGeomCamDwarf(Int_t rings, Double_t diameter, Double_t dist, const char *name)
88 : MGeomCam(CalcNumPix(rings), dist, name, "Geometry information for a hexagonal camera")
89{
90 CreateCam(diameter, rings);
91 CreateNN();
92 InitGeometry();
93}
94
95// --------------------------------------------------------------------------
96//
97// Create a clone of this container. This is very easy, because we
98// simply have to create a new object of the same type.
99//
100TObject *MGeomCamDwarf::Clone(const char *newname) const
101{
102 MGeomCam *cam = new MGeomCam(GetNumPixels(), GetCameraDist());
103 for (UInt_t i=0; i<GetNumPixels(); i++)
104 (*this)[i].Copy((*cam)[i]);
105
106 cam->InitGeometry();
107 return cam;
108}
109
110// --------------------------------------------------------------------------
111//
112// Calculate in the direction 0-5 (kind of sector) in the ring-th ring
113// the x and y coordinate of the i-th pixel. The unitx are unity,
114// distance to (0,0) is retruned.
115//
116Double_t MGeomCamDwarf::CalcXY(Int_t dir, Int_t ring, Int_t i, Double_t &x, Double_t &y)
117{
118 const Double_t kSqrt32 = MGeomPix::gsTan60/2;
119
120 switch (dir)
121 {
122 case kDirCenter: // Center
123 x = 0;
124 y = 0;
125 break;
126
127 case kDirNE: // Direction North East
128 x = ring-i*0.5;
129 y = i*kSqrt32;
130 break;
131
132 case kDirN: // Direction North
133 x = ring*0.5-i;
134 y = ring*kSqrt32;
135 break;
136
137 case kDirNW: // Direction North West
138 x = -(ring+i)*0.5;
139 y = (ring-i)*kSqrt32;
140 break;
141
142 case kDirSW: // Direction South West
143 x = 0.5*i-ring;
144 y = -i*kSqrt32;
145 break;
146
147 case kDirS: // Direction South
148 x = i-ring*0.5;
149 y = -ring*kSqrt32;
150 break;
151
152 case kDirSE: // Direction South East
153 x = (ring+i)*0.5;
154 y = (-ring+i)*kSqrt32;
155 break;
156 }
157 return TMath::Hypot(x, y);
158}
159
160// --------------------------------------------------------------------------
161//
162// Calculate in the direction 0-5 (kind of sector) in the ring-th ring
163// the x and y coordinate of the i-th pixel. The units are unity,
164// distance to (0,0) is retruned.
165//
166Int_t MGeomCamDwarf::CalcNumPix(Int_t rings)
167{
168 //
169 // add the first pixel to the list
170 //
171 Int_t cnt = 1;
172
173 for (Int_t ring=0; ring<rings; ring++)
174 cnt += 6*(ring+1);
175
176 return cnt;
177}
178
179// --------------------------------------------------------------------------
180//
181// Calculate in the direction 0-5 (kind of sector) in the ring-th ring
182// the x and y coordinate of the i-th pixel. The unitx are unity,
183// distance to (0,0) is retruned.
184//
185Int_t MGeomCamDwarf::CalcNumPix(Double_t rad)
186{
187 //
188 // add the first pixel to the list
189 //
190 Int_t cnt = 1;
191 Int_t ring = 1;
192 while (1)
193 {
194 Int_t n = 0;
195
196 //
197 // calc. coords for this ring counting from the
198 // starting number to the ending number
199 //
200 for (int i=0; i<ring; i++)
201 {
202 Double_t x, y;
203 if (CalcXY(kDirN, ring, i, x, y)<rad)
204 n++;
205 }
206
207 if (n==0)
208 return cnt;
209
210 ring++;
211 cnt += 6*n; // Because of symmetry only one direction is enough
212 }
213
214 return cnt;
215}
216
217
218// --------------------------------------------------------------------------
219//
220// This fills the geometry information for a hexagonal camera
221//
222void MGeomCamDwarf::CreateCam(Double_t diameter, Int_t rings)
223{
224 // units for diameter are mm
225
226 //
227 // add the first pixel to the list
228 //
229 (*this)[0].Set(0, 0, diameter);
230
231 Int_t cnt = 1;
232
233 for (int ring=1; ring<=rings; ring++)
234 {
235 for (Int_t dir=kDirNE; dir<=kDirSE; dir++)
236 {
237 for (int i=0; i<ring; i++)
238 {
239 Double_t x, y;
240 CalcXY(dir, ring, i, x, y);
241 (*this)[cnt++].Set(x*diameter, y*diameter, diameter);
242 }
243 }
244 }
245}
246
247// --------------------------------------------------------------------------
248//
249// This fills the geometry information for a roundish camera
250//
251void MGeomCamDwarf::CreateCam(Double_t diameter, Double_t rad)
252{
253 // units for diameter are mm
254
255 //
256 // add the first pixel to the list
257 //
258 (*this)[0].Set(0, 0, diameter);
259
260 Int_t cnt = 1;
261 Int_t ring = 1;
262
263 while (1)
264 {
265 Int_t n = 0;
266
267 for (Int_t dir=kDirNE; dir<=kDirSE; dir++)
268 {
269 for (int i=0; i<ring; i++)
270 {
271 Double_t x, y;
272 if (CalcXY(dir, ring, i, x, y)<rad)
273 (*this)[cnt+n++].Set(x*diameter, y*diameter, diameter);
274 }
275 }
276
277 if (n==0)
278 return;
279
280 ring++;
281 cnt += n;
282 }
283}
284
285// --------------------------------------------------------------------------
286//
287// This fills the next neighbor information from a table into the pixel
288// objects.
289//
290void MGeomCamDwarf::CreateNN()
291{
292 TArrayI nn(6);
293
294 for (UInt_t i=0; i<GetNumPixels(); i++)
295 {
296 MGeomPix &pix = (*this)[i];
297
298 Int_t k = 0;
299 nn.Reset(-1);
300
301 for (UInt_t j=0; j<GetNumPixels(); j++)
302 {
303 if (i==j)
304 continue;
305
306 if (pix.GetDist((*this)[j])<pix.GetD()*1.5)
307 nn[k++] = j;
308 }
309
310 pix.SetNeighbors(nn[0], nn[1], nn[2], nn[3], nn[4], nn[5]);
311 }
312}
Note: See TracBrowser for help on using the repository browser.