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

Last change on this file since 9384 was 9369, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 9.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-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(*this);
105 cam->InitGeometry();
106 return cam;
107}
108
109// --------------------------------------------------------------------------
110//
111// Check if the photon which is flying along the trajectory u has passed
112// (or will pass) the frame of the camera (and consequently get
113// absorbed). The position p and direction u must be in the
114// telescope coordinate frame, which is z parallel to the focal plane,
115// x to the right and y upwards, looking from the mirror towards the camera.
116//
117// The units are cm.
118//
119Bool_t MGeomCamDwarf::HitFrame(MQuaternion p, const MQuaternion &u) const
120{
121 // z is defined from the mirror (0) to the camera (z>0).
122 // Thus we just propagate to the focal plane (z=fDist)
123 //p -= 1700./u.Z()*u;
124 p.PropagateZ(u, GetCameraDist()*100); // m->cm
125
126 // Add 10% to the max radius and convert from mm to cm
127 return p.R()<GetMaxRadius()*0.11;//TMath::Abs(p.X())<65 && TMath::Abs(p.Y())<65;
128}
129
130// --------------------------------------------------------------------------
131//
132// Calculate in the direction 0-5 (kind of sector) in the ring-th ring
133// the x and y coordinate of the i-th pixel. The unitx are unity,
134// distance to (0,0) is retruned.
135//
136Double_t MGeomCamDwarf::CalcXY(Int_t dir, Int_t ring, Int_t i, Double_t &x, Double_t &y)
137{
138 const Double_t kSqrt32 = MGeomPix::gsTan60/2;
139
140 switch (dir)
141 {
142 case kDirCenter: // Center
143 x = 0;
144 y = 0;
145 break;
146
147 case kDirNE: // Direction North East
148 x = ring-i*0.5;
149 y = i*kSqrt32;
150 break;
151
152 case kDirN: // Direction North
153 x = ring*0.5-i;
154 y = ring*kSqrt32;
155 break;
156
157 case kDirNW: // Direction North West
158 x = -(ring+i)*0.5;
159 y = (ring-i)*kSqrt32;
160 break;
161
162 case kDirSW: // Direction South West
163 x = 0.5*i-ring;
164 y = -i*kSqrt32;
165 break;
166
167 case kDirS: // Direction South
168 x = i-ring*0.5;
169 y = -ring*kSqrt32;
170 break;
171
172 case kDirSE: // Direction South East
173 x = (ring+i)*0.5;
174 y = (-ring+i)*kSqrt32;
175 break;
176 }
177 return TMath::Hypot(x, y);
178}
179
180// --------------------------------------------------------------------------
181//
182// Calculate in the direction 0-5 (kind of sector) in the ring-th ring
183// the x and y coordinate of the i-th pixel. The units are unity,
184// distance to (0,0) is retruned.
185//
186Int_t MGeomCamDwarf::CalcNumPix(Int_t rings)
187{
188 //
189 // add the first pixel to the list
190 //
191 Int_t cnt = 1;
192
193 for (Int_t ring=0; ring<rings; ring++)
194 cnt += 6*(ring+1);
195
196 return cnt;
197}
198
199// --------------------------------------------------------------------------
200//
201// Calculate in the direction 0-5 (kind of sector) in the ring-th ring
202// the x and y coordinate of the i-th pixel. The unitx are unity,
203// distance to (0,0) is retruned.
204//
205// Due to possible rounding errors we need to use exactly the same
206// algorithm as for creating the pixels!
207//
208Int_t MGeomCamDwarf::CalcNumPix(Double_t rad)
209{
210 //
211 // add the first pixel to the list
212 //
213 Int_t cnt = 1;
214 Int_t ring = 1;
215 while (1)
216 {
217 Int_t n = 0;
218
219 //
220 // calc. coords for this ring counting from the
221 // starting number to the ending number
222 //
223 for (Int_t dir=kDirNE; dir<=kDirSE; dir++)
224 {
225 for (int i=0; i<ring; i++)
226 {
227 Double_t x, y;
228 if (CalcXY(dir, ring, i, x, y)<rad)
229 n++;
230 }
231 }
232
233 if (n==0)
234 return cnt;
235
236 ring++;
237 cnt += n;
238 }
239
240 return cnt;
241}
242
243
244// --------------------------------------------------------------------------
245//
246// This fills the geometry information for a hexagonal camera
247//
248void MGeomCamDwarf::CreateCam(Double_t diameter, Int_t rings)
249{
250 // units for diameter are mm
251
252 //
253 // add the first pixel to the list
254 //
255 SetAt(0, MGeomPix(0, 0, diameter));
256
257 Int_t cnt = 1;
258
259 for (int ring=1; ring<=rings; ring++)
260 {
261 for (Int_t dir=kDirNE; dir<=kDirSE; dir++)
262 {
263 for (int i=0; i<ring; i++)
264 {
265 Double_t x, y;
266 CalcXY(dir, ring, i, x, y);
267 SetAt(cnt++, MGeomPix(x*diameter, y*diameter, diameter));
268 }
269 }
270 }
271}
272
273// --------------------------------------------------------------------------
274//
275// This fills the geometry information for a roundish camera
276//
277void MGeomCamDwarf::CreateCam(Double_t diameter, Double_t rad)
278{
279 // units for diameter are mm
280
281 //
282 // add the first pixel to the list
283 //
284 SetAt(0, MGeomPix(0, 0, diameter));
285
286 Int_t cnt = 1;
287 Int_t ring = 1;
288
289 while (1)
290 {
291 Int_t n = 0;
292
293 for (Int_t dir=kDirNE; dir<=kDirSE; dir++)
294 {
295 for (int i=0; i<ring; i++)
296 {
297 Double_t x, y;
298 if (CalcXY(dir, ring, i, x, y)<rad)
299 SetAt(cnt+n++, MGeomPix(x*diameter, y*diameter, diameter));
300 }
301 }
302
303 if (n==0)
304 return;
305
306 ring++;
307 cnt += n;
308 }
309}
310
311// --------------------------------------------------------------------------
312//
313// This fills the next neighbor information from a table into the pixel
314// objects.
315//
316void MGeomCamDwarf::CreateNN()
317{
318 TArrayI nn(6);
319
320 for (UInt_t i=0; i<GetNumPixels(); i++)
321 {
322 MGeomPix &pix = static_cast<MGeomPix&>((*this)[i]);
323
324 Int_t k = 0;
325 nn.Reset(-1);
326
327 for (UInt_t j=0; j<GetNumPixels(); j++)
328 {
329 if (i==j)
330 continue;
331
332 if (pix.GetDist((*this)[j])<pix.GetD()*1.5)
333 nn[k++] = j;
334 }
335
336 pix.SetNeighbors(nn[0], nn[1], nn[2], nn[3], nn[4], nn[5]);
337 }
338}
Note: See TracBrowser for help on using the repository browser.