source: trunk/MagicSoft/Mars/mgeom/MGeomPix.cc@ 9150

Last change on this file since 9150 was 8923, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 6.2 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, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Harald Kornmayer 1/2001
20!
21! Copyright: MAGIC Software Development, 2000-2008
22!
23!
24\* ======================================================================== */
25
26//////////////////////////////////////////////////////////////////////////////
27//
28// MGeomPix
29//
30// This container stores the geometry (position) information of
31// a single pixel together with the information about next neighbors.
32//
33//
34// Version 1:
35// ----------
36// - first implementation
37//
38// Version 2:
39// ----------
40// - added fA
41//
42// Version 3:
43// ----------
44// - added fAidx
45//
46// Version 4:
47// ----------
48// - added fUserBits
49//
50//
51// FIXME: According to an agreement we have to change the name 'Id' to 'idx'
52//
53////////////////////////////////////////////////////////////////////////////
54#include "MGeomPix.h"
55
56#include <TMath.h>
57
58#include "MLog.h"
59#include "MLogManip.h"
60
61#include "MGeomCam.h"
62
63ClassImp(MGeomPix);
64
65using namespace std;
66
67const Float_t MGeomPix::gsTan30 = tan(30/kRad2Deg);
68const Float_t MGeomPix::gsTan60 = tan(60/kRad2Deg);
69
70// --------------------------------------------------------------------------
71//
72// Initializes one pixel
73//
74MGeomPix::MGeomPix(Float_t x, Float_t y, Float_t r, UInt_t s, UInt_t a)
75{
76 // default constructor
77 Set(x, y, r, s, a);
78 SetNeighbors();
79}
80
81// --------------------------------------------------------------------------
82//
83// Initializes Next Neighbors.
84//
85// WARNING: This function is public, but it is not meant for user access.
86// It should only be used from geometry classes (like MGeomCam)
87//
88void MGeomPix::SetNeighbors(Short_t i0, Short_t i1, Short_t i2,
89 Short_t i3, Short_t i4, Short_t i5)
90{
91 fNeighbors[0] = i0;
92 fNeighbors[1] = i1;
93 fNeighbors[2] = i2;
94 fNeighbors[3] = i3;
95 fNeighbors[4] = i4;
96 fNeighbors[5] = i5;
97
98 int i;
99 for (i=0; i<6; i++)
100 if (fNeighbors[i]<0)
101 break;
102
103 fNumNeighbors = i;
104
105 fNumNeighbors<5 ? SETBIT(fUserBits, kIsInOutermostRing) : CLRBIT(fUserBits, kIsInOutermostRing);
106}
107
108// --------------------------------------------------------------------------
109//
110// Set the kIsOuterRing flag if this pixel has a outermost pixel
111// as Next Neighbor and don't have the kIsOutermostRing flag itself.
112//
113void MGeomPix::CheckOuterRing(const MGeomCam &cam)
114{
115 if (IsInOutermostRing())
116 return;
117
118 CLRBIT(fUserBits, kIsInOuterRing);
119
120 for (int i=0; i<fNumNeighbors; i++)
121 if (cam[fNeighbors[i]].IsInOutermostRing())
122 {
123 SETBIT(fUserBits, kIsInOuterRing);
124 return;
125 }
126}
127
128// --------------------------------------------------------------------------
129//
130// Print the geometry information of one pixel.
131//
132void MGeomPix::Print(Option_t *opt) const
133{
134 // information about a pixel
135 *fLog << all << "MPixGeom: x/y=" << fX << "/" << fY << "mm ";
136 *fLog << "d= " << fD << "mm A= " << fA << "mm² (";
137 for (int i=0; i<fNumNeighbors; i++)
138 *fLog << fNeighbors[i] << (i<fNumNeighbors-1?",":"");
139 *fLog << ")" << endl;
140}
141
142// ------------------------------------------------------------------------
143//
144// Return distance of center to coordinate origin: hypot(fX,fY)
145//
146Float_t MGeomPix::GetDist() const
147{
148 return TMath::Hypot(fX, fY);
149}
150
151// ------------------------------------------------------------------------
152//
153// Return distance of center to center of pix: hypot(fX-pix.fX,fY-pix.fY)
154//
155Float_t MGeomPix::GetDist(const MGeomPix &pix) const
156{
157 return TMath::Hypot(fX-pix.fX, fY-pix.fY);
158}
159
160// ------------------------------------------------------------------------
161//
162// Return angle defined by the center and the center of pix:
163// atan2(fX-pix.fX,fY-pix.fY)
164//
165Float_t MGeomPix::GetAngle(const MGeomPix &pix) const
166{
167 return TMath::ATan2(fX - pix.GetX(), fY - pix.GetY());
168}
169
170// ------------------------------------------------------------------------
171//
172// compute the distance of a point (px,py) to the Hexagon center in
173// MGeomPix coordinates. Return kTRUE if inside.
174//
175Bool_t MGeomPix::IsInside(Float_t px, Float_t py) const
176{
177 //
178 // compute the distance of the Point to the center of the Hexagon
179 //
180 const Double_t dx = px-fX;
181
182 //
183 // Now check if point is outside of hexagon; just check x coordinate
184 // in three coordinate systems: the default one, in which two sides of
185 // the hexagon are paralel to the y axis (see camera displays) and two
186 // more, rotated with respect to that one by +- 60 degrees.
187 //
188 if (TMath::Abs(dx)*2>fD)
189 return kFALSE;
190
191 const Double_t dy = py-fY;
192
193 const static Double_t cos60 = TMath::Cos(60/kRad2Deg);
194 const static Double_t sin60 = TMath::Sin(60/kRad2Deg);
195
196 const Double_t dx2 = dx*cos60 + dy*sin60;
197 if (TMath::Abs(dx2)*2>fD)
198 return kFALSE;
199
200 const Double_t dx3 = dx*cos60 - dy*sin60;
201 if (TMath::Abs(dx3)*2>fD)
202 return kFALSE;
203
204 return kTRUE;
205}
206
207// ------------------------------------------------------------------------
208//
209// Return the direction of the pixel pix w.r.t. this pixel.
210// Remark: This function assumes a simple geometry.
211//
212Int_t MGeomPix::GetDirection(const MGeomPix &pix) const
213{
214 const Double_t x1 = GetX();
215 const Double_t y1 = GetY();
216
217 const Double_t x2 = pix.GetX();
218 const Double_t y2 = pix.GetY();
219
220 if (x1>=x2 && y1>y2) return kRightTop;
221 if (x1>=x2 && y1<y2) return kRightBottom;
222 if (x1<=x2 && y1>y2) return kLeftTop;
223 if (x1<=x2 && y1<y2) return kLeftBottom;
224 if (x1>x2) return kRight;
225 if (x1<x2) return kLeft;
226
227 return -1;
228}
Note: See TracBrowser for help on using the repository browser.