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

Last change on this file since 8802 was 8757, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 8.5 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//
185// Due to possible rounding errors we need to use exactly the same
186// algorithm as for creating the pixels!
187//
188Int_t MGeomCamDwarf::CalcNumPix(Double_t rad)
189{
190 //
191 // add the first pixel to the list
192 //
193 Int_t cnt = 1;
194 Int_t ring = 1;
195 while (1)
196 {
197 Int_t n = 0;
198
199 //
200 // calc. coords for this ring counting from the
201 // starting number to the ending number
202 //
203 for (Int_t dir=kDirNE; dir<=kDirSE; dir++)
204 {
205 for (int i=0; i<ring; i++)
206 {
207 Double_t x, y;
208 if (CalcXY(dir, ring, i, x, y)<rad)
209 n++;
210 }
211 }
212
213 if (n==0)
214 return cnt;
215
216 ring++;
217 cnt += n;
218 }
219
220 return cnt;
221}
222
223
224// --------------------------------------------------------------------------
225//
226// This fills the geometry information for a hexagonal camera
227//
228void MGeomCamDwarf::CreateCam(Double_t diameter, Int_t rings)
229{
230 // units for diameter are mm
231
232 //
233 // add the first pixel to the list
234 //
235 (*this)[0].Set(0, 0, diameter);
236
237 Int_t cnt = 1;
238
239 for (int ring=1; ring<=rings; ring++)
240 {
241 for (Int_t dir=kDirNE; dir<=kDirSE; dir++)
242 {
243 for (int i=0; i<ring; i++)
244 {
245 Double_t x, y;
246 CalcXY(dir, ring, i, x, y);
247 (*this)[cnt++].Set(x*diameter, y*diameter, diameter);
248 }
249 }
250 }
251}
252
253// --------------------------------------------------------------------------
254//
255// This fills the geometry information for a roundish camera
256//
257void MGeomCamDwarf::CreateCam(Double_t diameter, Double_t rad)
258{
259 // units for diameter are mm
260
261 //
262 // add the first pixel to the list
263 //
264 (*this)[0].Set(0, 0, diameter);
265
266 Int_t cnt = 1;
267 Int_t ring = 1;
268
269 while (1)
270 {
271 Int_t n = 0;
272
273 for (Int_t dir=kDirNE; dir<=kDirSE; dir++)
274 {
275 for (int i=0; i<ring; i++)
276 {
277 Double_t x, y;
278 if (CalcXY(dir, ring, i, x, y)<rad)
279 (*this)[cnt+n++].Set(x*diameter, y*diameter, diameter);
280 }
281 }
282
283 if (n==0)
284 return;
285
286 ring++;
287 cnt += n;
288 }
289}
290
291// --------------------------------------------------------------------------
292//
293// This fills the next neighbor information from a table into the pixel
294// objects.
295//
296void MGeomCamDwarf::CreateNN()
297{
298 TArrayI nn(6);
299
300 for (UInt_t i=0; i<GetNumPixels(); i++)
301 {
302 MGeomPix &pix = (*this)[i];
303
304 Int_t k = 0;
305 nn.Reset(-1);
306
307 for (UInt_t j=0; j<GetNumPixels(); j++)
308 {
309 if (i==j)
310 continue;
311
312 if (pix.GetDist((*this)[j])<pix.GetD()*1.5)
313 nn[k++] = j;
314 }
315
316 pix.SetNeighbors(nn[0], nn[1], nn[2], nn[3], nn[4], nn[5]);
317 }
318}
Note: See TracBrowser for help on using the repository browser.