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

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