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 |
|
---|
49 | using namespace std;
|
---|
50 |
|
---|
51 | // --------------------------------------------------------------------------
|
---|
52 | //
|
---|
53 | // Initializes one pixel
|
---|
54 | //
|
---|
55 | MGeom::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 | //
|
---|
66 | TVector2 MGeom::GetP() const
|
---|
67 | {
|
---|
68 | return TVector2(fX, fY);
|
---|
69 | }
|
---|
70 |
|
---|
71 | // --------------------------------------------------------------------------
|
---|
72 | //
|
---|
73 | // Initializes Next Neighbors.
|
---|
74 | //
|
---|
75 | // WARNING: This function is public, but it is not meant for user access.
|
---|
76 | // It should only be used from geometry classes (like MGeomCam)
|
---|
77 | //
|
---|
78 | void MGeom::SetNeighbors(Short_t i0, Short_t i1, Short_t i2,
|
---|
79 | Short_t i3, Short_t i4, Short_t i5)
|
---|
80 | {
|
---|
81 | fNeighbors[0] = i0;
|
---|
82 | fNeighbors[1] = i1;
|
---|
83 | fNeighbors[2] = i2;
|
---|
84 | fNeighbors[3] = i3;
|
---|
85 | fNeighbors[4] = i4;
|
---|
86 | fNeighbors[5] = i5;
|
---|
87 |
|
---|
88 | int i;
|
---|
89 | for (i=0; i<6; i++)
|
---|
90 | if (fNeighbors[i]<0)
|
---|
91 | break;
|
---|
92 |
|
---|
93 | fNumNeighbors = i;
|
---|
94 |
|
---|
95 | // FIXME
|
---|
96 | fNumNeighbors<5 ? SETBIT(fUserBits, kIsInOutermostRing) : CLRBIT(fUserBits, kIsInOutermostRing);
|
---|
97 | }
|
---|
98 |
|
---|
99 | // --------------------------------------------------------------------------
|
---|
100 | //
|
---|
101 | // Set the kIsOuterRing flag if this pixel has a outermost pixel
|
---|
102 | // as Next Neighbor and don't have the kIsOutermostRing flag itself.
|
---|
103 | //
|
---|
104 | void MGeom::CheckOuterRing(const MGeomCam &cam)
|
---|
105 | {
|
---|
106 | if (IsInOutermostRing())
|
---|
107 | return;
|
---|
108 |
|
---|
109 | CLRBIT(fUserBits, kIsInOuterRing);
|
---|
110 |
|
---|
111 | for (int i=0; i<fNumNeighbors; i++)
|
---|
112 | if (cam[fNeighbors[i]].IsInOutermostRing())
|
---|
113 | {
|
---|
114 | SETBIT(fUserBits, kIsInOuterRing);
|
---|
115 | return;
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | // --------------------------------------------------------------------------
|
---|
120 | //
|
---|
121 | // Print the geometry information of one pixel.
|
---|
122 | //
|
---|
123 | void MGeom::Print(Option_t *opt) const
|
---|
124 | {
|
---|
125 | // information about a pixel
|
---|
126 | gLog << all << MParContainer::GetDescriptor(*this) << ": x/y=" << fX << "/" << fY << "mm ";
|
---|
127 | gLog << "A= " << fA << "mm² (";
|
---|
128 | for (int i=0; i<fNumNeighbors; i++)
|
---|
129 | gLog << fNeighbors[i] << (i<fNumNeighbors-1?",":"");
|
---|
130 | gLog << ")";
|
---|
131 | }
|
---|
132 |
|
---|
133 |
|
---|
134 | // ------------------------------------------------------------------------
|
---|
135 | //
|
---|
136 | // Return distance of center to coordinate origin: hypot(fX,fY)
|
---|
137 | //
|
---|
138 | Float_t MGeom::GetDist() const
|
---|
139 | {
|
---|
140 | return TMath::Hypot(fX, fY);
|
---|
141 | }
|
---|
142 |
|
---|
143 | // ------------------------------------------------------------------------
|
---|
144 | //
|
---|
145 | // Return distance of center to center of pix: hypot(fX-pix.fX,fY-pix.fY)
|
---|
146 | //
|
---|
147 | Float_t MGeom::GetDist(const MGeom &pix) const
|
---|
148 | {
|
---|
149 | return TMath::Hypot(fX-pix.fX, fY-pix.fY);
|
---|
150 | }
|
---|
151 |
|
---|
152 | // ------------------------------------------------------------------------
|
---|
153 | //
|
---|
154 | // Return angle defined by the center and the center of pix:
|
---|
155 | // atan2(fX-pix.fX,fY-pix.fY)
|
---|
156 | //
|
---|
157 | Float_t MGeom::GetAngle(const MGeom &pix) const
|
---|
158 | {
|
---|
159 | return TMath::ATan2(fX - pix.GetX(), fY - pix.GetY());
|
---|
160 | }
|
---|
161 |
|
---|
162 | // ------------------------------------------------------------------------
|
---|
163 | //
|
---|
164 | // Return the direction of the pixel pix w.r.t. this pixel.
|
---|
165 | // Remark: This function assumes a simple geometry.
|
---|
166 | //
|
---|
167 | Int_t MGeom::GetDirection(const MGeom &pix) const
|
---|
168 | {
|
---|
169 | const Double_t phi = GetAngle(pix)*TMath::RadToDeg();
|
---|
170 |
|
---|
171 | if (phi<-165) return kTop;
|
---|
172 | if (phi<-105) return kRightTop;
|
---|
173 | if (phi< -75) return kRight;
|
---|
174 | if (phi< -15) return kRightBottom;
|
---|
175 | if (phi< 15) return kBottom;
|
---|
176 | if (phi< 75) return kLeftBottom;
|
---|
177 | if (phi< 105) return kLeft;
|
---|
178 | if (phi< 165) return kLeftTop;
|
---|
179 |
|
---|
180 | return kTop;
|
---|
181 | }
|
---|
182 |
|
---|
183 | // ------------------------------------------------------------------------
|
---|
184 | //
|
---|
185 | // This implementation is based on the use of DistanceToPrimitive
|
---|
186 | // (capital T) which should be implemented in user coordinates.
|
---|
187 | //
|
---|
188 | Int_t MGeom::DistancetoPrimitive(Int_t px, Int_t py)
|
---|
189 | {
|
---|
190 | const Double_t x = gPad->AbsPixeltoX(px);
|
---|
191 | const Double_t y = gPad->AbsPixeltoY(py);
|
---|
192 |
|
---|
193 | return TMath::Nint(DistanceToPrimitive(x, y));
|
---|
194 | }
|
---|