source: trunk/MagicSoft/Mars/mgeom/MGeomCam.cc@ 7304

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