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@uni-sw.gwdg.de>
|
---|
19 | ! Harald Kornmayer 01/2001
|
---|
20 | ! Markus Gaug 03/2004 <mailto:markus@ifae.es>
|
---|
21 | !
|
---|
22 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MGeomCam
|
---|
29 | //
|
---|
30 | // This is the base class of different camera geometries. It creates
|
---|
31 | // a pixel object for a given number of pixels and defines the
|
---|
32 | // interface of how to acccess the geometry information.
|
---|
33 | //
|
---|
34 | // We use a TObjArray for possible future usage (it is much more flexible
|
---|
35 | // than a TClonesArray so that it can store more types of pixels (eg
|
---|
36 | // fake pixels which are not really existing)
|
---|
37 | //
|
---|
38 | // Version 1:
|
---|
39 | // ----------
|
---|
40 | // - first implementation
|
---|
41 | //
|
---|
42 | // Version 2:
|
---|
43 | // ----------
|
---|
44 | // - added fPixRatio
|
---|
45 | // - added fPixRatioSqrt
|
---|
46 | //
|
---|
47 | // Version 3:
|
---|
48 | // ----------
|
---|
49 | // - added fNumAreas
|
---|
50 | //
|
---|
51 | /////////////////////////////////////////////////////////////////////////////
|
---|
52 | #include "MGeomCam.h"
|
---|
53 |
|
---|
54 | #include <TClass.h> // IsA()->New()
|
---|
55 | #include <TArrayI.h> // TArrayI
|
---|
56 | #include <TVector2.h> // TVector2
|
---|
57 |
|
---|
58 | #include "MLog.h"
|
---|
59 | #include "MLogManip.h"
|
---|
60 |
|
---|
61 | #include "MGeomPix.h"
|
---|
62 |
|
---|
63 | ClassImp(MGeomCam);
|
---|
64 |
|
---|
65 | using namespace std;
|
---|
66 |
|
---|
67 | // --------------------------------------------------------------------------
|
---|
68 | //
|
---|
69 | // Default Constructor. Initializes a Camera Geometry with npix pixels. All
|
---|
70 | // pixels are deleted when the corresponding array is deleted.
|
---|
71 | //
|
---|
72 | MGeomCam::MGeomCam(UInt_t npix, Float_t dist, const char *name, const char *title)
|
---|
73 | : fNumPixels(npix), fCamDist(dist), fConvMm2Deg(kRad2Deg/(dist*1000)),
|
---|
74 | fPixels(npix), fMaxRadius(1), fMinRadius(1), fPixRatio(npix), fPixRatioSqrt(npix)
|
---|
75 | {
|
---|
76 | fName = name ? name : "MGeomCam";
|
---|
77 | fTitle = title ? title : "Storage container for a camera geometry";
|
---|
78 |
|
---|
79 | //
|
---|
80 | // make sure that the destructor delete all contained objects
|
---|
81 | //
|
---|
82 | fPixels.SetOwner();
|
---|
83 |
|
---|
84 | for (UInt_t i=0; i<npix; i++)
|
---|
85 | fPixels[i] = new MGeomPix;
|
---|
86 | }
|
---|
87 |
|
---|
88 | // --------------------------------------------------------------------------
|
---|
89 | //
|
---|
90 | // Returns a reference of the i-th entry (the pixel with the software idx i)
|
---|
91 | // The access is unchecked (for speed reasons!) accesing non existing
|
---|
92 | // entries may crash the program!
|
---|
93 | //
|
---|
94 | MGeomPix &MGeomCam::operator[](Int_t i)
|
---|
95 | {
|
---|
96 | return *static_cast<MGeomPix*>(fPixels.UncheckedAt(i));
|
---|
97 | }
|
---|
98 |
|
---|
99 | // --------------------------------------------------------------------------
|
---|
100 | //
|
---|
101 | // Returns a reference of the i-th entry (the pixel with the software idx i)
|
---|
102 | // The access is unchecked (for speed reasons!) accesing non existing
|
---|
103 | // entries may crash the program!
|
---|
104 | //
|
---|
105 | MGeomPix &MGeomCam::operator[](Int_t i) const
|
---|
106 | {
|
---|
107 | return *static_cast<MGeomPix*>(fPixels.UncheckedAt(i));
|
---|
108 | }
|
---|
109 |
|
---|
110 | // --------------------------------------------------------------------------
|
---|
111 | //
|
---|
112 | // Calculate and fill the arrays storing the ratio of the area of a pixel
|
---|
113 | // i to the pixel 0 and its square root.
|
---|
114 | // The precalculation is done for speed reasons. Having an event the
|
---|
115 | // ratio would be calculated at least once for each pixel which is
|
---|
116 | // an enormous amount of numerical calculations, which are time
|
---|
117 | // consuming and which can be avoided doing the precalculation.
|
---|
118 | //
|
---|
119 | void MGeomCam::CalcPixRatio()
|
---|
120 | {
|
---|
121 | const Double_t a0 = (*this)[0].GetA();
|
---|
122 |
|
---|
123 | for (UInt_t i=0; i<fNumPixels; i++)
|
---|
124 | {
|
---|
125 | fPixRatio[i] = a0/(*this)[i].GetA();
|
---|
126 | fPixRatioSqrt[i] = TMath::Sqrt(fPixRatio[i]);
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | // --------------------------------------------------------------------------
|
---|
131 | //
|
---|
132 | // Set the kIsOuterRing flag for all pixels which have a outermost pixel
|
---|
133 | // as Next Neighbor and don't have the kIsOutermostRing flag itself.
|
---|
134 | //
|
---|
135 | void MGeomCam::InitOuterRing()
|
---|
136 | {
|
---|
137 | fPixels.ForEach(MGeomPix, CheckOuterRing)(*this);
|
---|
138 | }
|
---|
139 |
|
---|
140 | // --------------------------------------------------------------------------
|
---|
141 | //
|
---|
142 | // Calculate the highest sector index+1 of all pixels, please make sure
|
---|
143 | // the the sector numbers are continous.
|
---|
144 | //
|
---|
145 | void MGeomCam::CalcNumSectors()
|
---|
146 | {
|
---|
147 | fNumSectors = 0;
|
---|
148 |
|
---|
149 | for (UInt_t i=0; i<fNumPixels; i++)
|
---|
150 | {
|
---|
151 | const Int_t s = (*this)[i].GetSector();
|
---|
152 |
|
---|
153 | if (s>fNumSectors)
|
---|
154 | fNumSectors = s;
|
---|
155 | }
|
---|
156 |
|
---|
157 | fNumSectors++;
|
---|
158 | }
|
---|
159 |
|
---|
160 | // --------------------------------------------------------------------------
|
---|
161 | //
|
---|
162 | // Calculate the highest area index+1 of all pixels, please make sure
|
---|
163 | // the the area indices are continous.
|
---|
164 | //
|
---|
165 | void MGeomCam::CalcNumAreas()
|
---|
166 | {
|
---|
167 | fNumAreas = 0;
|
---|
168 |
|
---|
169 | for (UInt_t i=0; i<fNumPixels; i++)
|
---|
170 | {
|
---|
171 | const Int_t s = (*this)[i].GetAidx();
|
---|
172 |
|
---|
173 | if (s>fNumAreas)
|
---|
174 | fNumAreas = s;
|
---|
175 | }
|
---|
176 |
|
---|
177 | fNumAreas++;
|
---|
178 | }
|
---|
179 |
|
---|
180 | // --------------------------------------------------------------------------
|
---|
181 | //
|
---|
182 | // Calculate the maximum radius of the camera. This is ment for GUI layout.
|
---|
183 | //
|
---|
184 | void MGeomCam::CalcMaxRadius()
|
---|
185 | {
|
---|
186 | fMaxRadius.Set(fNumAreas+1);
|
---|
187 | fMinRadius.Set(fNumAreas+1);
|
---|
188 |
|
---|
189 | for (Int_t i=0; i<fNumAreas+1; i++)
|
---|
190 | {
|
---|
191 | fMaxRadius[i] = 0.;
|
---|
192 | fMinRadius[i] = FLT_MAX;
|
---|
193 | }
|
---|
194 |
|
---|
195 | for (UInt_t i=0; i<fNumPixels; i++)
|
---|
196 | {
|
---|
197 | const MGeomPix &pix = (*this)[i];
|
---|
198 |
|
---|
199 | const UInt_t s = pix.GetAidx();
|
---|
200 | const Float_t x = pix.GetX();
|
---|
201 | const Float_t y = pix.GetY();
|
---|
202 | const Float_t d = pix.GetD();
|
---|
203 |
|
---|
204 | const Float_t r = TMath::Hypot(x, y);
|
---|
205 |
|
---|
206 | const Float_t maxr = r + d;
|
---|
207 | const Float_t minr = r>d ? r-d : 0;
|
---|
208 |
|
---|
209 | if (maxr>fMaxRadius[s+1])
|
---|
210 | fMaxRadius[s+1] = maxr;
|
---|
211 |
|
---|
212 | if (minr<fMinRadius[s+1])
|
---|
213 | fMinRadius[s+1] = minr;
|
---|
214 |
|
---|
215 | if (minr<fMinRadius[0])
|
---|
216 | fMinRadius[0] = minr;
|
---|
217 |
|
---|
218 | if (maxr>fMaxRadius[0])
|
---|
219 | fMaxRadius[0] = maxr;
|
---|
220 | }
|
---|
221 | }
|
---|
222 |
|
---|
223 | // --------------------------------------------------------------------------
|
---|
224 | //
|
---|
225 | // Returns the distance between the pixels i and j. -1 if an index
|
---|
226 | // doesn't exist. The default for j is 0. Assuming that 0 is the index
|
---|
227 | // for a central pixel you can get the distance to the camera center.
|
---|
228 | //
|
---|
229 | Float_t MGeomCam::GetDist(UShort_t i, UShort_t j) const
|
---|
230 | {
|
---|
231 | if (i>=fNumPixels || j>=fNumPixels)
|
---|
232 | return -1;
|
---|
233 |
|
---|
234 | return (*this)[i].GetDist((*this)[j]);
|
---|
235 | }
|
---|
236 |
|
---|
237 | // --------------------------------------------------------------------------
|
---|
238 | //
|
---|
239 | // Returns the angle between of pixels i wrt pixel j (default=0). The angle
|
---|
240 | // is returned in the range between -pi and pi (atan2) and 2*pi if i or j
|
---|
241 | // is out of range.
|
---|
242 | //
|
---|
243 | Float_t MGeomCam::GetAngle(UShort_t i, UShort_t j) const
|
---|
244 | {
|
---|
245 | if (i>=fNumPixels || j>=fNumPixels)
|
---|
246 | return TMath::TwoPi();
|
---|
247 |
|
---|
248 | return (*this)[i].GetAngle((*this)[j]);
|
---|
249 | }
|
---|
250 |
|
---|
251 | // --------------------------------------------------------------------------
|
---|
252 | //
|
---|
253 | // Have to call the radii of the subcameras starting to count from 1
|
---|
254 | //
|
---|
255 | Float_t MGeomCam::GetMaxRadius(const Int_t i) const
|
---|
256 | {
|
---|
257 | return i<-1 || i>fNumAreas ? -1 : fMaxRadius[i+1];
|
---|
258 | }
|
---|
259 |
|
---|
260 | // --------------------------------------------------------------------------
|
---|
261 | //
|
---|
262 | // Have to call the radii of the subcameras starting to count from 1
|
---|
263 | //
|
---|
264 | Float_t MGeomCam::GetMinRadius(const Int_t i) const
|
---|
265 | {
|
---|
266 | return i<-1 || i>fNumAreas ? -1 : fMinRadius[i+1];
|
---|
267 | }
|
---|
268 |
|
---|
269 |
|
---|
270 | // --------------------------------------------------------------------------
|
---|
271 | //
|
---|
272 | // returns the ratio of the area of the pixel with index 0 to the pixel
|
---|
273 | // with the specified index i. 0 Is returned if the index argument is
|
---|
274 | // out of range.
|
---|
275 | //
|
---|
276 | Float_t MGeomCam::GetPixRatio(UInt_t i) const
|
---|
277 | {
|
---|
278 | // Former: (*this)[0].GetA()/(*this)[i].GetA();
|
---|
279 | // The const_cast is necessary to support older root version
|
---|
280 | return i<fNumPixels ? const_cast<TArrayF&>(fPixRatio)[i] : 0;
|
---|
281 | }
|
---|
282 |
|
---|
283 | // --------------------------------------------------------------------------
|
---|
284 | //
|
---|
285 | // returns the square root of the ratio of the area of the pixel with
|
---|
286 | // index 0 to the pixel with the specified index i. 0 Is returned if
|
---|
287 | // the index argument is out of range.
|
---|
288 | //
|
---|
289 | Float_t MGeomCam::GetPixRatioSqrt(UInt_t i) const
|
---|
290 | {
|
---|
291 | // The const_cast is necessary to support older root version
|
---|
292 | return i<fNumPixels ? const_cast<TArrayF&>(fPixRatioSqrt)[i] : 0;
|
---|
293 | }
|
---|
294 |
|
---|
295 | // --------------------------------------------------------------------------
|
---|
296 | //
|
---|
297 | // Prints the Geometry information of all pixels in the camera
|
---|
298 | //
|
---|
299 | void MGeomCam::Print(Option_t *) const
|
---|
300 | {
|
---|
301 | //
|
---|
302 | // Print Information about the Geometry of the camera
|
---|
303 | //
|
---|
304 | *fLog << all << " Number of Pixels (" << GetTitle() << "): " << fNumPixels << endl;
|
---|
305 | *fLog << " Number of Sectors: " << GetNumSectors() << " Area-Indices: " << GetNumAreas() << endl;
|
---|
306 | *fLog << " Min.Radius: " << GetMinRadius() << " Max.Radius: " << GetMaxRadius() << endl;
|
---|
307 |
|
---|
308 | fPixels.Print();
|
---|
309 | }
|
---|
310 |
|
---|
311 | // --------------------------------------------------------------------------
|
---|
312 | //
|
---|
313 | // Create a clone of this container. This is very easy, because we
|
---|
314 | // simply have to create a new object of the same type.
|
---|
315 | //
|
---|
316 | TObject *MGeomCam::Clone(const char *newname) const
|
---|
317 | {
|
---|
318 | if (IsA()==MGeomCam::Class())
|
---|
319 | {
|
---|
320 | MGeomCam *cam = new MGeomCam(fNumPixels, fCamDist);
|
---|
321 | for (UInt_t i=0; i<fNumPixels; i++)
|
---|
322 | {
|
---|
323 | //if (fPixels.UncheckedAt(i))
|
---|
324 | (*this)[i].Copy((*cam)[i]);
|
---|
325 | }
|
---|
326 | cam->InitGeometry();
|
---|
327 | return cam;
|
---|
328 | }
|
---|
329 |
|
---|
330 | return (TObject*)IsA()->New();
|
---|
331 | }
|
---|
332 |
|
---|
333 | // --------------------------------------------------------------------------
|
---|
334 | //
|
---|
335 | // Return the pixel index corresponding to the coordinates given in x, y.
|
---|
336 | // The coordinates are given in pixel units (millimeters)
|
---|
337 | // If no pixel exists return -1;
|
---|
338 | //
|
---|
339 | Int_t MGeomCam::GetPixelIdxXY(Float_t x, Float_t y) const
|
---|
340 | {
|
---|
341 | for (unsigned int i=0; i<fNumPixels; i++)
|
---|
342 | if ((*this)[i].IsInside(x, y))
|
---|
343 | return i;
|
---|
344 |
|
---|
345 | return -1;
|
---|
346 | }
|
---|
347 |
|
---|
348 | Int_t MGeomCam::GetPixelIdx(const TVector2 &v) const
|
---|
349 | {
|
---|
350 | return GetPixelIdxXY(v.X(), v.Y());
|
---|
351 | }
|
---|
352 |
|
---|
353 | Int_t MGeomCam::GetPixelIdxDeg(const TVector2 &v) const
|
---|
354 | {
|
---|
355 | return GetPixelIdxXYdeg(v.X(), v.Y());
|
---|
356 | }
|
---|
357 |
|
---|
358 | // --------------------------------------------------------------------------
|
---|
359 | //
|
---|
360 | // Add all indices to arr of all neighbors around pix in a radius r.
|
---|
361 | // The center pixel is also returned.
|
---|
362 | //
|
---|
363 | void MGeomCam::GetNeighbors(TArrayI &arr, const MGeomPix &pix, Float_t r) const
|
---|
364 | {
|
---|
365 | arr.Set(GetNumPixels());
|
---|
366 |
|
---|
367 | Int_t n = 0;
|
---|
368 |
|
---|
369 | for (unsigned int i=0; i<GetNumPixels(); i++)
|
---|
370 | {
|
---|
371 | if (r>TMath::Hypot(pix.GetX()-(*this)[i].GetX(), pix.GetY()-(*this)[i].GetY()))
|
---|
372 | arr[n++] = i;
|
---|
373 | }
|
---|
374 |
|
---|
375 | arr.Set(n);
|
---|
376 | }
|
---|
377 |
|
---|
378 | // --------------------------------------------------------------------------
|
---|
379 | //
|
---|
380 | // Add all indices to arr of all neighbors around idx in a radius r.
|
---|
381 | // The center pixel is also returned.
|
---|
382 | //
|
---|
383 | void MGeomCam::GetNeighbors(TArrayI &arr, UInt_t idx, Float_t r) const
|
---|
384 | {
|
---|
385 | if (idx>=GetNumPixels())
|
---|
386 | {
|
---|
387 | arr.Set(0);
|
---|
388 | return;
|
---|
389 | }
|
---|
390 |
|
---|
391 |
|
---|
392 | const MGeomPix &pix = (*this)[idx];
|
---|
393 | GetNeighbors(arr, pix, r);
|
---|
394 | }
|
---|
395 |
|
---|
396 | // --------------------------------------------------------------------------
|
---|
397 | //
|
---|
398 | // Add all pixels to list of all neighbors around pix in a radius r.
|
---|
399 | // The center pixel is also returned.
|
---|
400 | //
|
---|
401 | void MGeomCam::GetNeighbors(TList &arr, const MGeomPix &pix, Float_t r) const
|
---|
402 | {
|
---|
403 | for (unsigned int i=0; i<GetNumPixels(); i++)
|
---|
404 | {
|
---|
405 | if (r>TMath::Hypot(pix.GetX()-(*this)[i].GetX(), pix.GetY()-(*this)[i].GetY()))
|
---|
406 | arr.Add(fPixels.UncheckedAt(i));
|
---|
407 | }
|
---|
408 | }
|
---|
409 |
|
---|
410 | // --------------------------------------------------------------------------
|
---|
411 | //
|
---|
412 | // Add all pixels to list of all neighbors around idx in a radius r.
|
---|
413 | // The center pixel is also returned.
|
---|
414 | //
|
---|
415 | void MGeomCam::GetNeighbors(TList &arr, UInt_t idx, Float_t r) const
|
---|
416 | {
|
---|
417 | if (idx>=GetNumPixels())
|
---|
418 | return;
|
---|
419 |
|
---|
420 | const MGeomPix &pix = (*this)[idx];
|
---|
421 | GetNeighbors(arr, pix, r);
|
---|
422 | }
|
---|