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

Last change on this file since 9235 was 9234, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 9.9 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// Check if the position given in the focal plane (so z can be ignored)
136// is a position which might hit the detector. It is meant to be a rough
137// and fast estimate not a precise calculation. All positions dicarded
138// must not hit the detector. All positions accepted might still miss
139// the detector.
140//
141// The units are cm.
142//
143Bool_t MGeomCamDwarf::HitDetector(const MQuaternion &v) const
144{
145 // Add 10% to the max radius and convert from mm to cm
146 return v.R()<GetMaxRadius()*0.11;//60.2;
147}
148
149// --------------------------------------------------------------------------
150//
151// Calculate in the direction 0-5 (kind of sector) in the ring-th ring
152// the x and y coordinate of the i-th pixel. The unitx are unity,
153// distance to (0,0) is retruned.
154//
155Double_t MGeomCamDwarf::CalcXY(Int_t dir, Int_t ring, Int_t i, Double_t &x, Double_t &y)
156{
157 const Double_t kSqrt32 = MGeomPix::gsTan60/2;
158
159 switch (dir)
160 {
161 case kDirCenter: // Center
162 x = 0;
163 y = 0;
164 break;
165
166 case kDirNE: // Direction North East
167 x = ring-i*0.5;
168 y = i*kSqrt32;
169 break;
170
171 case kDirN: // Direction North
172 x = ring*0.5-i;
173 y = ring*kSqrt32;
174 break;
175
176 case kDirNW: // Direction North West
177 x = -(ring+i)*0.5;
178 y = (ring-i)*kSqrt32;
179 break;
180
181 case kDirSW: // Direction South West
182 x = 0.5*i-ring;
183 y = -i*kSqrt32;
184 break;
185
186 case kDirS: // Direction South
187 x = i-ring*0.5;
188 y = -ring*kSqrt32;
189 break;
190
191 case kDirSE: // Direction South East
192 x = (ring+i)*0.5;
193 y = (-ring+i)*kSqrt32;
194 break;
195 }
196 return TMath::Hypot(x, y);
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 units are unity,
203// distance to (0,0) is retruned.
204//
205Int_t MGeomCamDwarf::CalcNumPix(Int_t rings)
206{
207 //
208 // add the first pixel to the list
209 //
210 Int_t cnt = 1;
211
212 for (Int_t ring=0; ring<rings; ring++)
213 cnt += 6*(ring+1);
214
215 return cnt;
216}
217
218// --------------------------------------------------------------------------
219//
220// Calculate in the direction 0-5 (kind of sector) in the ring-th ring
221// the x and y coordinate of the i-th pixel. The unitx are unity,
222// distance to (0,0) is retruned.
223//
224// Due to possible rounding errors we need to use exactly the same
225// algorithm as for creating the pixels!
226//
227Int_t MGeomCamDwarf::CalcNumPix(Double_t rad)
228{
229 //
230 // add the first pixel to the list
231 //
232 Int_t cnt = 1;
233 Int_t ring = 1;
234 while (1)
235 {
236 Int_t n = 0;
237
238 //
239 // calc. coords for this ring counting from the
240 // starting number to the ending number
241 //
242 for (Int_t dir=kDirNE; dir<=kDirSE; dir++)
243 {
244 for (int i=0; i<ring; i++)
245 {
246 Double_t x, y;
247 if (CalcXY(dir, ring, i, x, y)<rad)
248 n++;
249 }
250 }
251
252 if (n==0)
253 return cnt;
254
255 ring++;
256 cnt += n;
257 }
258
259 return cnt;
260}
261
262
263// --------------------------------------------------------------------------
264//
265// This fills the geometry information for a hexagonal camera
266//
267void MGeomCamDwarf::CreateCam(Double_t diameter, Int_t rings)
268{
269 // units for diameter are mm
270
271 //
272 // add the first pixel to the list
273 //
274 (*this)[0].Set(0, 0, diameter);
275
276 Int_t cnt = 1;
277
278 for (int ring=1; ring<=rings; ring++)
279 {
280 for (Int_t dir=kDirNE; dir<=kDirSE; dir++)
281 {
282 for (int i=0; i<ring; i++)
283 {
284 Double_t x, y;
285 CalcXY(dir, ring, i, x, y);
286 (*this)[cnt++].Set(x*diameter, y*diameter, diameter);
287 }
288 }
289 }
290}
291
292// --------------------------------------------------------------------------
293//
294// This fills the geometry information for a roundish camera
295//
296void MGeomCamDwarf::CreateCam(Double_t diameter, Double_t rad)
297{
298 // units for diameter are mm
299
300 //
301 // add the first pixel to the list
302 //
303 (*this)[0].Set(0, 0, diameter);
304
305 Int_t cnt = 1;
306 Int_t ring = 1;
307
308 while (1)
309 {
310 Int_t n = 0;
311
312 for (Int_t dir=kDirNE; dir<=kDirSE; dir++)
313 {
314 for (int i=0; i<ring; i++)
315 {
316 Double_t x, y;
317 if (CalcXY(dir, ring, i, x, y)<rad)
318 (*this)[cnt+n++].Set(x*diameter, y*diameter, diameter);
319 }
320 }
321
322 if (n==0)
323 return;
324
325 ring++;
326 cnt += n;
327 }
328}
329
330// --------------------------------------------------------------------------
331//
332// This fills the next neighbor information from a table into the pixel
333// objects.
334//
335void MGeomCamDwarf::CreateNN()
336{
337 TArrayI nn(6);
338
339 for (UInt_t i=0; i<GetNumPixels(); i++)
340 {
341 MGeomPix &pix = (*this)[i];
342
343 Int_t k = 0;
344 nn.Reset(-1);
345
346 for (UInt_t j=0; j<GetNumPixels(); j++)
347 {
348 if (i==j)
349 continue;
350
351 if (pix.GetDist((*this)[j])<pix.GetD()*1.5)
352 nn[k++] = j;
353 }
354
355 pix.SetNeighbors(nn[0], nn[1], nn[2], nn[3], nn[4], nn[5]);
356 }
357}
Note: See TracBrowser for help on using the repository browser.