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

Last change on this file since 4308 was 3666, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 9.7 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 SetReadyToSave();
98}
99
100// --------------------------------------------------------------------------
101//
102// Returns a reference of the i-th entry (the pixel with the software idx i)
103// The access is unchecked (for speed reasons!) accesing non existing
104// entries may crash the program!
105//
106MGeomPix &MGeomCam::operator[](Int_t i)
107{
108 return *static_cast<MGeomPix*>(fPixels.UncheckedAt(i));
109}
110
111// --------------------------------------------------------------------------
112//
113// Returns a reference of the i-th entry (the pixel with the software idx i)
114// The access is unchecked (for speed reasons!) accesing non existing
115// entries may crash the program!
116//
117MGeomPix &MGeomCam::operator[](Int_t i) const
118{
119 return *static_cast<MGeomPix*>(fPixels.UncheckedAt(i));
120}
121
122// --------------------------------------------------------------------------
123//
124// Calculate and fill the arrays storing the ratio of the area of a pixel
125// i to the pixel 0 and its square root.
126// The precalculation is done for speed reasons. Having an event the
127// ratio would be calculated at least once for each pixel which is
128// an enormous amount of numerical calculations, which are time
129// consuming and which can be avoided doing the precalculation.
130//
131void MGeomCam::CalcPixRatio()
132{
133 const Double_t a0 = (*this)[0].GetA();
134
135 for (UInt_t i=0; i<fNumPixels; i++)
136 {
137 fPixRatio[i] = a0/(*this)[i].GetA();
138 fPixRatioSqrt[i] = TMath::Sqrt(fPixRatio[i]);
139 }
140}
141
142// --------------------------------------------------------------------------
143//
144// Set the kIsOuterRing flag for all pixels which have a outermost pixel
145// as Next Neighbor and don't have the kIsOutermostRing flag itself.
146//
147void MGeomCam::InitOuterRing()
148{
149 fPixels.ForEach(MGeomPix, CheckOuterRing)(*this);
150}
151
152// --------------------------------------------------------------------------
153//
154// Calculate the highest sector index+1 of all pixels, please make sure
155// the the sector numbers are continous.
156//
157void MGeomCam::CalcNumSectors()
158{
159 fNumSectors = 0;
160
161 for (UInt_t i=0; i<fNumPixels; i++)
162 {
163 const Int_t s = (*this)[i].GetSector();
164
165 if (s>fNumSectors)
166 fNumSectors = s;
167 }
168
169 fNumSectors++;
170}
171
172// --------------------------------------------------------------------------
173//
174// Calculate the highest area index+1 of all pixels, please make sure
175// the the area indices are continous.
176//
177void MGeomCam::CalcNumAreas()
178{
179 fNumAreas = 0;
180
181 for (UInt_t i=0; i<fNumPixels; i++)
182 {
183 const Int_t s = (*this)[i].GetAidx();
184
185 if (s>fNumAreas)
186 fNumAreas = s;
187 }
188
189 fNumAreas++;
190}
191
192// --------------------------------------------------------------------------
193//
194// Calculate the maximum radius of the camera. This is ment for GUI layout.
195//
196void MGeomCam::CalcMaxRadius()
197{
198 fMaxRadius.Set(fNumAreas+1);
199 fMinRadius.Set(fNumAreas+1);
200
201 for (Int_t i=0; i<fNumAreas+1; i++)
202 {
203 fMaxRadius[i] = 0.;
204 fMinRadius[i] = FLT_MAX;
205 }
206
207 for (UInt_t i=0; i<fNumPixels; i++)
208 {
209 const MGeomPix &pix = (*this)[i];
210
211 const UInt_t s = pix.GetAidx();
212 const Float_t x = pix.GetX();
213 const Float_t y = pix.GetY();
214 const Float_t d = pix.GetD();
215
216 const Float_t r = TMath::Hypot(x, y);
217
218 const Float_t maxr = r + d;
219 const Float_t minr = r>d ? r-d : 0;
220
221 if (maxr>fMaxRadius[s+1])
222 fMaxRadius[s+1] = maxr;
223
224 if (minr<fMinRadius[s+1])
225 fMinRadius[s+1] = minr;
226
227 if (minr<fMinRadius[0])
228 fMinRadius[0] = minr;
229
230 if (maxr>fMaxRadius[0])
231 fMaxRadius[0] = maxr;
232 }
233}
234
235// --------------------------------------------------------------------------
236//
237// Have to call the radii of the subcameras starting to count from 1
238//
239Float_t MGeomCam::GetMaxRadius(const Int_t i) const
240{
241 return i<-1 || i>fNumAreas ? -1 : fMaxRadius[i+1];
242}
243
244// --------------------------------------------------------------------------
245//
246// Have to call the radii of the subcameras starting to count from 1
247//
248Float_t MGeomCam::GetMinRadius(const Int_t i) const
249{
250 return i<-1 || i>fNumAreas ? -1 : fMinRadius[i+1];
251}
252
253
254// --------------------------------------------------------------------------
255//
256// returns the ratio of the area of the pixel with index 0 to the pixel
257// with the specified index i. 0 Is returned if the index argument is
258// out of range.
259//
260Float_t MGeomCam::GetPixRatio(UInt_t i) const
261{
262 // Former: (*this)[0].GetA()/(*this)[i].GetA();
263 // The const_cast is necessary to support older root version
264 return i<fNumPixels ? const_cast<TArrayF&>(fPixRatio)[i] : 0;
265}
266
267// --------------------------------------------------------------------------
268//
269// returns the square root of the ratio of the area of the pixel with
270// index 0 to the pixel with the specified index i. 0 Is returned if
271// the index argument is out of range.
272//
273Float_t MGeomCam::GetPixRatioSqrt(UInt_t i) const
274{
275 // The const_cast is necessary to support older root version
276 return i<fNumPixels ? const_cast<TArrayF&>(fPixRatioSqrt)[i] : 0;
277}
278
279// --------------------------------------------------------------------------
280//
281// Prints the Geometry information of all pixels in the camera
282//
283void MGeomCam::Print(Option_t *) const
284{
285 //
286 // Print Information about the Geometry of the camera
287 //
288 *fLog << all << " Number of Pixels (" << GetTitle() << "): " << fNumPixels << 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 return (TObject*)IsA()->New();
301}
302
303// --------------------------------------------------------------------------
304//
305// Return the pixel index corresponding to the coordinates given in x, y.
306// The coordinates are given in pixel units (millimeters)
307// If no pixel exists return -1;
308//
309Int_t MGeomCam::GetPixelIdxXY(Float_t x, Float_t y) const
310{
311 for (unsigned int i=0; i<fNumPixels; i++)
312 if ((*this)[i].IsInside(x, y))
313 return i;
314
315 return -1;
316}
317
318Int_t MGeomCam::GetPixelIdx(const TVector2 &v) const
319{
320 return GetPixelIdxXY(v.X(), v.Y());
321}
322
323Int_t MGeomCam::GetPixelIdxDeg(const TVector2 &v) const
324{
325 return GetPixelIdxXYdeg(v.X(), v.Y());
326}
327
328/*
329void MGeomCam::Streamer(TBuffer &R__b)
330{
331 // Stream an object of class MGeomCam.
332
333 if (R__b.IsReading())
334 {
335 MGeomCam::Class()->ReadBuffer(R__b, this);
336
337 UInt_t R__s, R__c;
338 Version_t R__v = b.ReadVersion(&R__s, &R__c);
339 if (R__v > 2) {
340 MGeomCam::Class()->ReadBuffer(b, this, R__v, R__s, R__c);
341
342 Version_t v = MGeomCam::Class()->GetClassVersion();
343 }
344 else
345 {
346 MGeomCam::Class()->WriteBuffer(R__b, this);
347 }
348}
349*/
Note: See TracBrowser for help on using the repository browser.