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

Last change on this file since 6500 was 6338, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 11.5 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// Set the kIsOuterRing flag for all pixels which have a outermost pixel
144// as Next Neighbor and don't have the kIsOutermostRing flag itself.
145//
146void MGeomCam::InitOuterRing()
147{
148 fPixels.ForEach(MGeomPix, CheckOuterRing)(*this);
149}
150
151// --------------------------------------------------------------------------
152//
153// Calculate the highest sector index+1 of all pixels, please make sure
154// the the sector numbers are continous.
155//
156void MGeomCam::CalcNumSectors()
157{
158 fNumSectors = 0;
159
160 for (UInt_t i=0; i<fNumPixels; i++)
161 {
162 const Int_t s = (*this)[i].GetSector();
163
164 if (s>fNumSectors)
165 fNumSectors = s;
166 }
167
168 fNumSectors++;
169}
170
171// --------------------------------------------------------------------------
172//
173// Calculate the highest area index+1 of all pixels, please make sure
174// the the area indices are continous.
175//
176void MGeomCam::CalcNumAreas()
177{
178 fNumAreas = 0;
179
180 for (UInt_t i=0; i<fNumPixels; i++)
181 {
182 const Int_t s = (*this)[i].GetAidx();
183
184 if (s>fNumAreas)
185 fNumAreas = s;
186 }
187
188 fNumAreas++;
189}
190
191// --------------------------------------------------------------------------
192//
193// Calculate the maximum radius of the camera. This is ment for GUI layout.
194//
195void MGeomCam::CalcMaxRadius()
196{
197 fMaxRadius.Set(fNumAreas+1);
198 fMinRadius.Set(fNumAreas+1);
199
200 for (Int_t i=0; i<fNumAreas+1; i++)
201 {
202 fMaxRadius[i] = 0.;
203 fMinRadius[i] = FLT_MAX;
204 }
205
206 for (UInt_t i=0; i<fNumPixels; i++)
207 {
208 const MGeomPix &pix = (*this)[i];
209
210 const UInt_t s = pix.GetAidx();
211 const Float_t x = pix.GetX();
212 const Float_t y = pix.GetY();
213 const Float_t d = pix.GetD();
214
215 const Float_t r = TMath::Hypot(x, y);
216
217 const Float_t maxr = r + d;
218 const Float_t minr = r>d ? r-d : 0;
219
220 if (maxr>fMaxRadius[s+1])
221 fMaxRadius[s+1] = maxr;
222
223 if (minr<fMinRadius[s+1])
224 fMinRadius[s+1] = minr;
225
226 if (minr<fMinRadius[0])
227 fMinRadius[0] = minr;
228
229 if (maxr>fMaxRadius[0])
230 fMaxRadius[0] = maxr;
231 }
232}
233
234// --------------------------------------------------------------------------
235//
236// Have to call the radii of the subcameras starting to count from 1
237//
238Float_t MGeomCam::GetMaxRadius(const Int_t i) const
239{
240 return i<-1 || i>fNumAreas ? -1 : fMaxRadius[i+1];
241}
242
243// --------------------------------------------------------------------------
244//
245// Have to call the radii of the subcameras starting to count from 1
246//
247Float_t MGeomCam::GetMinRadius(const Int_t i) const
248{
249 return i<-1 || i>fNumAreas ? -1 : fMinRadius[i+1];
250}
251
252
253// --------------------------------------------------------------------------
254//
255// returns the ratio of the area of the pixel with index 0 to the pixel
256// with the specified index i. 0 Is returned if the index argument is
257// out of range.
258//
259Float_t MGeomCam::GetPixRatio(UInt_t i) const
260{
261 // Former: (*this)[0].GetA()/(*this)[i].GetA();
262 // The const_cast is necessary to support older root version
263 return i<fNumPixels ? const_cast<TArrayF&>(fPixRatio)[i] : 0;
264}
265
266// --------------------------------------------------------------------------
267//
268// returns the square root of the ratio of the area of the pixel with
269// index 0 to the pixel with the specified index i. 0 Is returned if
270// the index argument is out of range.
271//
272Float_t MGeomCam::GetPixRatioSqrt(UInt_t i) const
273{
274 // The const_cast is necessary to support older root version
275 return i<fNumPixels ? const_cast<TArrayF&>(fPixRatioSqrt)[i] : 0;
276}
277
278// --------------------------------------------------------------------------
279//
280// Prints the Geometry information of all pixels in the camera
281//
282void MGeomCam::Print(Option_t *) const
283{
284 //
285 // Print Information about the Geometry of the camera
286 //
287 *fLog << all << " Number of Pixels (" << GetTitle() << "): " << fNumPixels << endl;
288 *fLog << " Number of Sectors: " << GetNumSectors() << " Area-Indices: " << GetNumAreas() << endl;
289 *fLog << " Min.Radius: " << GetMinRadius() << " Max.Radius: " << GetMaxRadius() << endl;
290
291 fPixels.Print();
292}
293
294// --------------------------------------------------------------------------
295//
296// Create a clone of this container. This is very easy, because we
297// simply have to create a new object of the same type.
298//
299TObject *MGeomCam::Clone(const char *newname) const
300{
301 if (IsA()==MGeomCam::Class())
302 {
303 MGeomCam *cam = new MGeomCam(fNumPixels, fCamDist);
304 for (UInt_t i=0; i<fNumPixels; i++)
305 {
306 //if (fPixels.UncheckedAt(i))
307 (*this)[i].Copy((*cam)[i]);
308 }
309 cam->InitGeometry();
310 return cam;
311 }
312
313 return (TObject*)IsA()->New();
314}
315
316// --------------------------------------------------------------------------
317//
318// Return the pixel index corresponding to the coordinates given in x, y.
319// The coordinates are given in pixel units (millimeters)
320// If no pixel exists return -1;
321//
322Int_t MGeomCam::GetPixelIdxXY(Float_t x, Float_t y) const
323{
324 for (unsigned int i=0; i<fNumPixels; i++)
325 if ((*this)[i].IsInside(x, y))
326 return i;
327
328 return -1;
329}
330
331Int_t MGeomCam::GetPixelIdx(const TVector2 &v) const
332{
333 return GetPixelIdxXY(v.X(), v.Y());
334}
335
336Int_t MGeomCam::GetPixelIdxDeg(const TVector2 &v) const
337{
338 return GetPixelIdxXYdeg(v.X(), v.Y());
339}
340
341// --------------------------------------------------------------------------
342//
343// Add all indices to arr of all neighbors around pix in a radius r.
344// The center pixel is also returned.
345//
346void MGeomCam::GetNeighbors(TArrayI &arr, const MGeomPix &pix, Float_t r) const
347{
348 arr.Set(GetNumPixels());
349
350 Int_t n = 0;
351
352 for (unsigned int i=0; i<GetNumPixels(); i++)
353 {
354 if (r>TMath::Hypot(pix.GetX()-(*this)[i].GetX(), pix.GetY()-(*this)[i].GetY()))
355 arr[n++] = i;
356 }
357
358 arr.Set(n);
359}
360
361// --------------------------------------------------------------------------
362//
363// Add all indices to arr of all neighbors around idx in a radius r.
364// The center pixel is also returned.
365//
366void MGeomCam::GetNeighbors(TArrayI &arr, UInt_t idx, Float_t r) const
367{
368 if (idx>=GetNumPixels())
369 {
370 arr.Set(0);
371 return;
372 }
373
374
375 const MGeomPix &pix = (*this)[idx];
376 GetNeighbors(arr, pix, r);
377}
378
379// --------------------------------------------------------------------------
380//
381// Add all pixels to list of all neighbors around pix in a radius r.
382// The center pixel is also returned.
383//
384void MGeomCam::GetNeighbors(TList &arr, const MGeomPix &pix, Float_t r) const
385{
386 for (unsigned int i=0; i<GetNumPixels(); i++)
387 {
388 if (r>TMath::Hypot(pix.GetX()-(*this)[i].GetX(), pix.GetY()-(*this)[i].GetY()))
389 arr.Add(fPixels.UncheckedAt(i));
390 }
391}
392
393// --------------------------------------------------------------------------
394//
395// Add all pixels to list of all neighbors around idx in a radius r.
396// The center pixel is also returned.
397//
398void MGeomCam::GetNeighbors(TList &arr, UInt_t idx, Float_t r) const
399{
400 if (idx>=GetNumPixels())
401 return;
402
403 const MGeomPix &pix = (*this)[idx];
404 GetNeighbors(arr, pix, r);
405}
Note: See TracBrowser for help on using the repository browser.