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

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