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

Last change on this file since 3204 was 2470, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.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/////////////////////////////////////////////////////////////////////////////
48#include "MGeomCam.h"
49
50#include <TClass.h> // IsA()->New()
51
52#include "MLog.h"
53#include "MLogManip.h"
54
55#include "MGeomPix.h"
56
57ClassImp(MGeomCam);
58
59using namespace std;
60
61// --------------------------------------------------------------------------
62//
63// Default Constructor
64//
65MGeomCam::MGeomCam()
66 : fNumPixels(0), fCamDist(0), fConvMm2Deg(0)
67{
68}
69
70// --------------------------------------------------------------------------
71//
72// Initializes a Camera Geometry with npix pixels. All pixels
73// are deleted when the corresponding array is deleted.
74//
75MGeomCam::MGeomCam(UInt_t npix, Float_t dist, const char *name, const char *title)
76 : fNumPixels(npix), fCamDist(dist), fConvMm2Deg(kRad2Deg/(dist*1000)), fPixels(npix), fPixRatio(npix), fPixRatioSqrt(npix)
77{
78 fName = name ? name : "MGeomCam";
79 fTitle = title ? title : "Storage container for a camera geometry";
80
81 //
82 // make sure that the destructor delete all contained objects
83 //
84 fPixels.SetOwner();
85
86 for (UInt_t i=0; i<npix; i++)
87 fPixels[i] = new MGeomPix;
88
89 SetReadyToSave();
90}
91
92// --------------------------------------------------------------------------
93//
94// Returns a reference of the i-th entry (the pixel with the software idx i)
95// The access is unchecked (for speed reasons!) accesing non existing
96// entries may crash the program!
97//
98MGeomPix &MGeomCam::operator[](Int_t i)
99{
100 return *static_cast<MGeomPix*>(fPixels.UncheckedAt(i));
101}
102
103// --------------------------------------------------------------------------
104//
105// Returns a reference of the i-th entry (the pixel with the software idx i)
106// The access is unchecked (for speed reasons!) accesing non existing
107// entries may crash the program!
108//
109MGeomPix &MGeomCam::operator[](Int_t i) const
110{
111 return *static_cast<MGeomPix*>(fPixels.UncheckedAt(i));
112}
113
114// --------------------------------------------------------------------------
115//
116// Calculate and fill the arrays storing the ratio of the area of a pixel
117// i to the pixel 0 and its square root.
118// The precalculation is done for speed reasons. Having an event the
119// ratio would be calculated at least once for each pixel which is
120// an enormous amount of numerical calculations, which are time
121// consuming and which can be avoided doing the precalculation.
122//
123void MGeomCam::CalcPixRatio()
124{
125 const Double_t a0 = (*this)[0].GetA();
126
127 for (UInt_t i=0; i<fNumPixels; i++)
128 {
129 fPixRatio[i] = a0/(*this)[i].GetA();
130 fPixRatioSqrt[i] = TMath::Sqrt(fPixRatio[i]);
131 }
132}
133
134// --------------------------------------------------------------------------
135//
136// Set the kIsOuterRing flag for all pixels which have a outermost pixel
137// as Next Neighbor and don't have the kIsOutermostRing flag itself.
138//
139void MGeomCam::InitOuterRing()
140{
141 fPixels.ForEach(MGeomPix, CheckOuterRing)(*this);
142}
143
144// --------------------------------------------------------------------------
145//
146// Calculate the highest sector index+1 of all pixels, please make sure
147// the the sector numbers are continous.
148//
149void MGeomCam::CalcNumSectors()
150{
151 fNumSectors = 0;
152
153 for (UInt_t i=0; i<fNumPixels; i++)
154 {
155 const UInt_t s = (*this)[i].GetSector();
156
157 if (s>fNumSectors)
158 fNumSectors = s;
159 }
160
161 fNumSectors++;
162}
163
164// --------------------------------------------------------------------------
165//
166// Calculate the maximum radius of the camera. This is ment for GUI layout.
167//
168void MGeomCam::CalcMaxRadius()
169{
170 fMaxRadius = 0;
171
172 for (UInt_t i=0; i<fNumPixels; i++)
173 {
174 const MGeomPix &pix = (*this)[i];
175
176 const Float_t x = pix.GetX();
177 const Float_t y = pix.GetY();
178 const Float_t d = pix.GetD();
179
180 const Float_t maxr = sqrt(x*x+y*y) + d;
181
182 if (maxr>fMaxRadius)
183 fMaxRadius = maxr;
184 }
185}
186
187// --------------------------------------------------------------------------
188//
189// returns the ratio of the area of the pixel with index 0 to the pixel
190// with the specified index i. 0 Is returned if the index argument is
191// out of range.
192//
193Float_t MGeomCam::GetPixRatio(UInt_t i) const
194{
195 // Former: (*this)[0].GetA()/(*this)[i].GetA();
196 // The const_cast is necessary to support older root version
197 return i<fNumPixels ? const_cast<TArrayF&>(fPixRatio)[i] : 0;
198}
199
200// --------------------------------------------------------------------------
201//
202// returns the square root of the ratio of the area of the pixel with
203// index 0 to the pixel with the specified index i. 0 Is returned if
204// the index argument is out of range.
205//
206Float_t MGeomCam::GetPixRatioSqrt(UInt_t i) const
207{
208 // The const_cast is necessary to support older root version
209 return i<fNumPixels ? const_cast<TArrayF&>(fPixRatioSqrt)[i] : 0;
210}
211
212// --------------------------------------------------------------------------
213//
214// Prints the Geometry information of all pixels in the camera
215//
216void MGeomCam::Print(Option_t *) const
217{
218 //
219 // Print Information about the Geometry of the camera
220 //
221 *fLog << all << " Number of Pixels (" << GetTitle() << "): " << fNumPixels << endl;
222
223 fPixels.Print();
224}
225
226// --------------------------------------------------------------------------
227//
228// Create a clone of this container. This is very easy, because we
229// simply have to create a new object of the same type.
230//
231TObject *MGeomCam::Clone(const char *newname) const
232{
233 return (TObject*)IsA()->New();
234}
Note: See TracBrowser for help on using the repository browser.