source: trunk/Mars/mgeom/MGeom.cc@ 10113

Last change on this file since 10113 was 9571, checked in by tbretz, 15 years ago
*** empty log message ***
File size: 5.8 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of CheObs, the Modular 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 appears 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!
20! Copyright: MAGIC Software Development, 2000-2009
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MGeom
28//
29// This container stores the geometry (position) information of
30// a single pixel together with the information about next neighbors.
31//
32//
33// Version 1:
34// ----------
35// - first implementation (previously part of MGeomPix)
36//
37////////////////////////////////////////////////////////////////////////////
38#include "MGeom.h"
39
40#include <TMath.h>
41#include <TVector2.h>
42#include <TVirtualPad.h>
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "MGeomCam.h"
48
49using namespace std;
50
51// --------------------------------------------------------------------------
52//
53// Initializes one pixel
54//
55MGeom::MGeom(Float_t x, Float_t y, UInt_t s, UInt_t a)
56 : fX(x), fY(y), fA(0), fSector(s), fAidx(a), fUserBits(0)
57{
58 // default constructor
59 SetNeighbors();
60}
61
62// --------------------------------------------------------------------------
63//
64// Return position as TVector2(fX, fY)
65//
66TVector2 MGeom::GetP() const
67{
68 return TVector2(fX, fY);
69}
70
71void MGeom::SetP(const TVector2 &v)
72{
73 fX = v.X();
74 fY = v.Y();
75}
76
77// --------------------------------------------------------------------------
78//
79// Initializes Next Neighbors.
80//
81// WARNING: This function is public, but it is not meant for user access.
82// It should only be used from geometry classes (like MGeomCam)
83//
84void MGeom::SetNeighbors(Short_t i0, Short_t i1, Short_t i2,
85 Short_t i3, Short_t i4, Short_t i5)
86{
87 fNeighbors[0] = i0;
88 fNeighbors[1] = i1;
89 fNeighbors[2] = i2;
90 fNeighbors[3] = i3;
91 fNeighbors[4] = i4;
92 fNeighbors[5] = i5;
93
94 int i;
95 for (i=0; i<6; i++)
96 if (fNeighbors[i]<0)
97 break;
98
99 fNumNeighbors = i;
100
101 // FIXME
102 fNumNeighbors<5 ? SETBIT(fUserBits, kIsInOutermostRing) : CLRBIT(fUserBits, kIsInOutermostRing);
103}
104
105// --------------------------------------------------------------------------
106//
107// Set the kIsOuterRing flag if this pixel has a outermost pixel
108// as Next Neighbor and don't have the kIsOutermostRing flag itself.
109//
110void MGeom::CheckOuterRing(const MGeomCam &cam)
111{
112 if (IsInOutermostRing())
113 return;
114
115 CLRBIT(fUserBits, kIsInOuterRing);
116
117 for (int i=0; i<fNumNeighbors; i++)
118 if (cam[fNeighbors[i]].IsInOutermostRing())
119 {
120 SETBIT(fUserBits, kIsInOuterRing);
121 return;
122 }
123}
124
125// --------------------------------------------------------------------------
126//
127// Print the geometry information of one pixel.
128//
129void MGeom::Print(Option_t *opt) const
130{
131 // information about a pixel
132 gLog << all << MParContainer::GetDescriptor(*this) << ": x/y=" << fX << "/" << fY << "mm ";
133 gLog << "A= " << fA << "mm" << UTF8::kSquare << " (";
134 for (int i=0; i<fNumNeighbors; i++)
135 gLog << fNeighbors[i] << (i<fNumNeighbors-1?",":"");
136 gLog << ")";
137}
138
139
140// ------------------------------------------------------------------------
141//
142// Return distance of center to coordinate origin: hypot(fX,fY)
143//
144Float_t MGeom::GetDist() const
145{
146 return TMath::Hypot(fX, fY);
147}
148
149// ------------------------------------------------------------------------
150//
151// Return distance of center to center of pix: hypot(fX-pix.fX,fY-pix.fY)
152//
153Float_t MGeom::GetDist(const MGeom &pix) const
154{
155 return TMath::Hypot(fX-pix.fX, fY-pix.fY);
156}
157
158// ------------------------------------------------------------------------
159//
160// Return distance squared of center to center of pix:
161// (fX-pix.fX)^2+(fY-pix.fY)^2
162//
163Float_t MGeom::GetDist2(const MGeom &pix) const
164{
165 const Double_t dx = fX-pix.fX;
166 const Double_t dy = fY-pix.fY;
167 return dx*dx + dy*dy;
168}
169
170// ------------------------------------------------------------------------
171//
172// Return angle defined by the center and the center of pix:
173// atan2(fX-pix.fX,fY-pix.fY)
174//
175Float_t MGeom::GetAngle(const MGeom &pix) const
176{
177 return TMath::ATan2(fX - pix.GetX(), fY - pix.GetY());
178}
179
180// ------------------------------------------------------------------------
181//
182// Return the direction of the pixel pix w.r.t. this pixel.
183// Remark: This function assumes a simple geometry.
184//
185Int_t MGeom::GetDirection(const MGeom &pix) const
186{
187 const Double_t phi = GetAngle(pix)*TMath::RadToDeg();
188
189 if (phi<-165) return kTop;
190 if (phi<-105) return kRightTop;
191 if (phi< -75) return kRight;
192 if (phi< -15) return kRightBottom;
193 if (phi< 15) return kBottom;
194 if (phi< 75) return kLeftBottom;
195 if (phi< 105) return kLeft;
196 if (phi< 165) return kLeftTop;
197
198 return kTop;
199}
200
201// ------------------------------------------------------------------------
202//
203// This implementation is based on the use of DistanceToPrimitive
204// (capital T) which should be implemented in user coordinates.
205//
206Int_t MGeom::DistancetoPrimitive(Int_t px, Int_t py)
207{
208 const Double_t x = gPad->AbsPixeltoX(px);
209 const Double_t y = gPad->AbsPixeltoY(py);
210
211 return IsInside(x, y) ? -1 : 999999;
212}
213
Note: See TracBrowser for help on using the repository browser.