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

Last change on this file since 3507 was 3392, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 7.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! Author(s): Harald Kornmayer 1/2001
20!
21! Copyright: MAGIC Software Development, 2000-2002
22!
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)
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)), fPixels(npix), fPixRatio(npix), fPixRatioSqrt(npix)
83{
84 fName = name ? name : "MGeomCam";
85 fTitle = title ? title : "Storage container for a camera geometry";
86
87 //
88 // make sure that the destructor delete all contained objects
89 //
90 fPixels.SetOwner();
91
92 for (UInt_t i=0; i<npix; i++)
93 fPixels[i] = new MGeomPix;
94
95 SetReadyToSave();
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 UInt_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 UInt_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 = 0;
197
198 for (UInt_t i=0; i<fNumPixels; i++)
199 {
200 const MGeomPix &pix = (*this)[i];
201
202 const Float_t x = pix.GetX();
203 const Float_t y = pix.GetY();
204 const Float_t d = pix.GetD();
205
206 const Float_t maxr = sqrt(x*x+y*y) + d;
207
208 if (maxr>fMaxRadius)
209 fMaxRadius = maxr;
210 }
211}
212
213// --------------------------------------------------------------------------
214//
215// returns the ratio of the area of the pixel with index 0 to the pixel
216// with the specified index i. 0 Is returned if the index argument is
217// out of range.
218//
219Float_t MGeomCam::GetPixRatio(UInt_t i) const
220{
221 // Former: (*this)[0].GetA()/(*this)[i].GetA();
222 // The const_cast is necessary to support older root version
223 return i<fNumPixels ? const_cast<TArrayF&>(fPixRatio)[i] : 0;
224}
225
226// --------------------------------------------------------------------------
227//
228// returns the square root of the ratio of the area of the pixel with
229// index 0 to the pixel with the specified index i. 0 Is returned if
230// the index argument is out of range.
231//
232Float_t MGeomCam::GetPixRatioSqrt(UInt_t i) const
233{
234 // The const_cast is necessary to support older root version
235 return i<fNumPixels ? const_cast<TArrayF&>(fPixRatioSqrt)[i] : 0;
236}
237
238// --------------------------------------------------------------------------
239//
240// Prints the Geometry information of all pixels in the camera
241//
242void MGeomCam::Print(Option_t *) const
243{
244 //
245 // Print Information about the Geometry of the camera
246 //
247 *fLog << all << " Number of Pixels (" << GetTitle() << "): " << fNumPixels << endl;
248
249 fPixels.Print();
250}
251
252// --------------------------------------------------------------------------
253//
254// Create a clone of this container. This is very easy, because we
255// simply have to create a new object of the same type.
256//
257TObject *MGeomCam::Clone(const char *newname) const
258{
259 return (TObject*)IsA()->New();
260}
261/*
262void MGeomCam::Streamer(TBuffer &R__b)
263{
264 // Stream an object of class MGeomCam.
265
266 if (R__b.IsReading())
267 {
268 MGeomCam::Class()->ReadBuffer(R__b, this);
269
270 UInt_t R__s, R__c;
271 Version_t R__v = b.ReadVersion(&R__s, &R__c);
272 if (R__v > 2) {
273 MGeomCam::Class()->ReadBuffer(b, this, R__v, R__s, R__c);
274
275 Version_t v = MGeomCam::Class()->GetClassVersion();
276 }
277 else
278 {
279 MGeomCam::Class()->WriteBuffer(R__b, this);
280 }
281}
282*/
Note: See TracBrowser for help on using the repository browser.