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

Last change on this file since 3615 was 3547, checked in by gaug, 21 years ago
*** empty log message ***
File size: 8.9 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
56#include "MLog.h"
57#include "MLogManip.h"
58
59#include "MGeomPix.h"
60
61ClassImp(MGeomCam);
62
63using namespace std;
64
65// --------------------------------------------------------------------------
66//
67// Default Constructor
68//
69MGeomCam::MGeomCam()
70 : fNumPixels(0), fCamDist(0), fConvMm2Deg(0), fMaxRadius(1), fMinRadius(1)
71{
72 fName = "MGeomCam";
73 fTitle = "Storage container for a camera geometry";
74}
75
76// --------------------------------------------------------------------------
77//
78// Initializes a Camera Geometry with npix pixels. All pixels
79// are deleted when the corresponding array is deleted.
80//
81MGeomCam::MGeomCam(UInt_t npix, Float_t dist, const char *name, const char *title)
82 : fNumPixels(npix), fCamDist(dist), fConvMm2Deg(kRad2Deg/(dist*1000)),
83 fPixels(npix), fMaxRadius(1), fMinRadius(1), fPixRatio(npix), fPixRatioSqrt(npix)
84{
85 fName = name ? name : "MGeomCam";
86 fTitle = title ? title : "Storage container for a camera geometry";
87
88 //
89 // make sure that the destructor delete all contained objects
90 //
91 fPixels.SetOwner();
92
93 for (UInt_t i=0; i<npix; i++)
94 fPixels[i] = new MGeomPix;
95
96 SetReadyToSave();
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
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
210 const MGeomPix &pix = (*this)[i];
211
212 const UInt_t s = pix.GetAidx();
213 const Float_t x = pix.GetX();
214 const Float_t y = pix.GetY();
215 const Float_t d = pix.GetD();
216
217 const Float_t r = TMath::Hypot(x, y);
218
219 const Float_t maxr = r + d;
220 const Float_t minr = r>d ? r-d : 0;
221
222 if (maxr>fMaxRadius[s+1])
223 fMaxRadius[s+1] = maxr;
224
225 if (minr<fMinRadius[s+1])
226 fMinRadius[s+1] = minr;
227
228 if (minr<fMinRadius[0])
229 fMinRadius[0] = minr;
230
231 if (maxr>fMaxRadius[0])
232 fMaxRadius[0] = maxr;
233
234 }
235}
236
237//
238// Have to call the radii of the subcameras starting to count from 1
239//
240Float_t MGeomCam::GetMaxRadius(const Int_t i) const
241{
242 if (i==-1) return fMaxRadius[0];
243 return i>fNumAreas ? -1 : fMaxRadius[i+1];
244}
245
246//
247// Have to call the radii of the subcameras starting to count from 1
248//
249Float_t MGeomCam::GetMinRadius(const Int_t i) const
250{
251 if (i==-1) return fMinRadius[0];
252 return i>fNumAreas ? -1 : fMinRadius[i+1];
253}
254
255
256// --------------------------------------------------------------------------
257//
258// returns the ratio of the area of the pixel with index 0 to the pixel
259// with the specified index i. 0 Is returned if the index argument is
260// out of range.
261//
262Float_t MGeomCam::GetPixRatio(UInt_t i) const
263{
264 // Former: (*this)[0].GetA()/(*this)[i].GetA();
265 // The const_cast is necessary to support older root version
266 return i<fNumPixels ? const_cast<TArrayF&>(fPixRatio)[i] : 0;
267}
268
269// --------------------------------------------------------------------------
270//
271// returns the square root of the ratio of the area of the pixel with
272// index 0 to the pixel with the specified index i. 0 Is returned if
273// the index argument is out of range.
274//
275Float_t MGeomCam::GetPixRatioSqrt(UInt_t i) const
276{
277 // The const_cast is necessary to support older root version
278 return i<fNumPixels ? const_cast<TArrayF&>(fPixRatioSqrt)[i] : 0;
279}
280
281// --------------------------------------------------------------------------
282//
283// Prints the Geometry information of all pixels in the camera
284//
285void MGeomCam::Print(Option_t *) const
286{
287 //
288 // Print Information about the Geometry of the camera
289 //
290 *fLog << all << " Number of Pixels (" << GetTitle() << "): " << fNumPixels << endl;
291
292 fPixels.Print();
293}
294
295// --------------------------------------------------------------------------
296//
297// Create a clone of this container. This is very easy, because we
298// simply have to create a new object of the same type.
299//
300TObject *MGeomCam::Clone(const char *newname) const
301{
302 return (TObject*)IsA()->New();
303}
304/*
305void MGeomCam::Streamer(TBuffer &R__b)
306{
307 // Stream an object of class MGeomCam.
308
309 if (R__b.IsReading())
310 {
311 MGeomCam::Class()->ReadBuffer(R__b, this);
312
313 UInt_t R__s, R__c;
314 Version_t R__v = b.ReadVersion(&R__s, &R__c);
315 if (R__v > 2) {
316 MGeomCam::Class()->ReadBuffer(b, this, R__v, R__s, R__c);
317
318 Version_t v = MGeomCam::Class()->GetClassVersion();
319 }
320 else
321 {
322 MGeomCam::Class()->WriteBuffer(R__b, this);
323 }
324}
325*/
Note: See TracBrowser for help on using the repository browser.