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

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