source: trunk/MagicSoft/Mars/mimage/MHillas.cc@ 2132

Last change on this file since 2132 was 2026, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 9.8 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! Author(s): Rudolf Bock 10/2001 <mailto:Rudolf.Bock@cern.ch>
21! Author(s): Wolfgang Wittek 6/2002 <mailto:wittek@mppmu.mpg.de>
22!
23! Copyright: MAGIC Software Development, 2000-2003
24!
25!
26\* ======================================================================== */
27
28/////////////////////////////////////////////////////////////////////////////
29//
30// MHillas
31//
32// Storage Container for image parameters
33//
34// basic image parameters
35//
36// Version 1:
37// ----------
38// fLength [mm] major axis of ellipse
39// fWidth [mm] minor axis
40// fDelta [rad] angle of major axis with x-axis
41// by definition the major axis is pointing into
42// the hemisphere x>0, thus -pi/2 < delta < pi/2
43// fSize [#CerPhot] total sum of pixels
44// fMeanX [mm] x of center of ellipse
45// fMeanY [mm] y of center of ellipse
46//
47// Version 2:
48// ----------
49// fNumCorePixels number of pixels called core
50// fNumUsedPixels number of pixels which survived the cleaning
51//
52// Version 3:
53// ----------
54// fNumCorePixels moved to MNewImagePar
55// fNumUsedPixels moved to MNewImagePar
56// fCosDelta added
57// fSinDelte added
58//
59/////////////////////////////////////////////////////////////////////////////
60#include "MHillas.h"
61
62#include <fstream.h>
63
64#include <TArrayF.h>
65#include <TEllipse.h>
66
67#include "MGeomPix.h"
68#include "MGeomCam.h"
69
70#include "MCerPhotPix.h"
71#include "MCerPhotEvt.h"
72
73#include "MLog.h"
74#include "MLogManip.h"
75
76ClassImp(MHillas);
77
78// --------------------------------------------------------------------------
79//
80// Default constructor.
81//
82MHillas::MHillas(const char *name, const char *title) : fEllipse(NULL)
83{
84 fName = name ? name : "MHillas";
85 fTitle = title ? title : "Storage container for image parameters of one event";
86
87 Reset();
88
89 fEllipse = new TEllipse;
90}
91
92// --------------------------------------------------------------------------
93//
94// Destructor. Deletes the TEllipse if one exists.
95//
96MHillas::~MHillas()
97{
98 Clear();
99}
100
101// --------------------------------------------------------------------------
102//
103// Initializes the values with defaults. For the default values see the
104// source code.
105//
106void MHillas::Reset()
107{
108 fLength = -1;
109 fWidth = -1;
110 fDelta = 0;
111
112 fSize = -1;
113 fMeanX = -1;
114 fMeanY = -1;
115
116 Clear();
117}
118
119// --------------------------------------------------------------------------
120//
121// Print the hillas Parameters to *fLog
122//
123void MHillas::Print(Option_t *) const
124{
125 Double_t atg = atan2(fMeanY, fMeanX)*kRad2Deg;
126
127 if (atg<0)
128 atg += 180;
129
130 *fLog << all;
131 *fLog << "Basic Image Parameters (" << GetName() << ")" << endl;
132 *fLog << " - Length [mm] = " << fLength << endl;
133 *fLog << " - Width [mm] = " << fWidth << endl;
134 *fLog << " - Delta [deg] = " << fDelta*kRad2Deg << endl;
135 *fLog << " - Size [1] = " << fSize << " #CherPhot" << endl;
136 *fLog << " - Meanx [mm] = " << fMeanX << endl;
137 *fLog << " - Meany [mm] = " << fMeanY << endl;
138 *fLog << " - atg(y/x) [deg] = " << atg << endl;
139}
140
141// --------------------------------------------------------------------------
142//
143// Instead of adding MHillas itself to the Pad (s. AppendPad in TObject)
144// we create an ellipse, which is added to the Pad by its Draw function
145// You can remove it by deleting the Ellipse Object (s. Clear())
146//
147void MHillas::Draw(Option_t *opt)
148{
149 Clear();
150
151 if (fLength<0 || fWidth<0)
152 return;
153
154 fEllipse = new TEllipse(fMeanX, fMeanY, fLength, fWidth,
155 0, 360, fDelta*kRad2Deg+180);
156
157 fEllipse->SetLineWidth(2);
158 fEllipse->Draw();
159}
160
161// --------------------------------------------------------------------------
162//
163// If a TEllipse object exists it is deleted
164//
165void MHillas::Clear(Option_t *)
166{
167 if (!fEllipse)
168 return;
169
170 delete fEllipse;
171
172 fEllipse = NULL;
173}
174
175
176// --------------------------------------------------------------------------
177//
178// Calculate the image parameters from a Cherenkov photon event
179// assuming Cher.photons/pixel and pixel coordinates are given
180// In case you don't call Calc from within an eventloop make sure, that
181// you call the Reset member function before.
182// Returns:
183// 0 no error
184// 1 number of pixels < 3
185// 2 size==0
186// 3 number of used pixel < 3
187// 4 CorrXY == 0
188//
189Int_t MHillas::Calc(const MGeomCam &geom, const MCerPhotEvt &evt)
190{
191 const UInt_t npixevt = evt.GetNumPixels();
192
193 //
194 // sanity check
195 //
196 if (npixevt < 3)
197 return 1;
198
199 //
200 // calculate mean value of pixel coordinates and fSize
201 // -----------------------------------------------------
202 //
203 // Because this are only simple sums of roughly 600 values
204 // with an accuracy less than three digits there should not
205 // be any need to use double precision (Double_t) for the
206 // calculation of fMeanX, fMeanY and fSize.
207 //
208 fMeanX = 0;
209 fMeanY = 0;
210 fSize = 0;
211
212 Int_t numused = 0;
213
214 for (UInt_t i=0; i<npixevt; i++)
215 {
216 const MCerPhotPix &pix = evt[i];
217
218 if (!pix.IsPixelUsed())
219 continue;
220
221 const MGeomPix &gpix = geom[pix.GetPixId()];
222
223 const Float_t nphot = pix.GetNumPhotons();
224
225 fSize += nphot; // [counter]
226 fMeanX += nphot * gpix.GetX(); // [mm]
227 fMeanY += nphot * gpix.GetY(); // [mm]
228
229 numused++;
230 }
231
232 //
233 // sanity checks
234 //
235 if (fSize==0)
236 return 2;
237
238 fMeanX /= fSize; // [mm]
239 fMeanY /= fSize; // [mm]
240
241 if (numused<3)
242 return 3;
243
244 //
245 // calculate 2nd moments
246 // ---------------------
247 //
248 // To make sure that the more complicated sum is evaluated as
249 // accurate as possible (because it is needed for more
250 // complicated calculations (see below) we calculate it using
251 // double prcision.
252 //
253 Double_t corrxx=0; // [m^2]
254 Double_t corrxy=0; // [m^2]
255 Double_t corryy=0; // [m^2]
256
257 for (UInt_t i=0; i<npixevt; i++)
258 {
259 const MCerPhotPix &pix = evt[i];
260
261 if (!pix.IsPixelUsed())
262 continue;
263
264 const MGeomPix &gpix = geom[pix.GetPixId()];
265
266 const Float_t dx = gpix.GetX() - fMeanX; // [mm]
267 const Float_t dy = gpix.GetY() - fMeanY; // [mm]
268
269 const Float_t nphot = pix.GetNumPhotons(); // [#phot]
270
271 corrxx += nphot * dx*dx; // [mm^2]
272 corrxy += nphot * dx*dy; // [mm^2]
273 corryy += nphot * dy*dy; // [mm^2]
274 }
275
276 //
277 // If corrxy=0 (which should never happen, because fSize>0) we
278 // cannot calculate Length and Width. The calculation failed
279 // and returns kFALSE
280 // In reallity it is almost impossible to have a distribution
281 // of cerenkov photons in the used pixels which is exactly symmetric
282 // along one of the axis.
283 //
284 if (corrxy==0)
285 return 4;
286
287 //
288 // calculate the basic Hillas parameters: orientation and size of axes
289 // -------------------------------------------------------------------
290 //
291 // fDelta is the angle between the major axis of the ellipse and
292 // the x axis. It is independent of the position of the ellipse
293 // in the camera it has values between -pi/2 and pi/2 degrees
294 //
295 const Double_t d0 = corryy - corrxx;
296 const Double_t d1 = corrxy*2;
297 const Double_t d2 = d0 + sqrt(d0*d0 + d1*d1);
298 const Double_t tand = d2 / d1;
299 const Double_t tand2 = tand*tand;
300
301 fDelta = atan(tand);
302
303 const Double_t s2 = tand2+1;
304 const Double_t s = sqrt(s2);
305
306 fCosDelta = 1.0/s; // need these in derived classes
307 fSinDelta = tand/s; // like MHillasExt
308
309 Double_t axis1 = (tand2*corryy + d2 + corrxx)/s2/fSize;
310 Double_t axis2 = (tand2*corrxx - d2 + corryy)/s2/fSize;
311
312 //
313 // fLength^2 is the second moment along the major axis of the ellipse
314 // fWidth^2 is the second moment along the minor axis of the ellipse
315 //
316 // From the algorithm we get: fWidth <= fLength is always true
317 //
318 // very small numbers can get negative by rounding
319 //
320 fLength = axis1<0 ? 0 : sqrt(axis1); // [mm]
321 fWidth = axis2<0 ? 0 : sqrt(axis2); // [mm]
322
323 SetReadyToSave();
324
325 return 0;
326}
327
328// --------------------------------------------------------------------------
329//
330// This function is ment for special usage, please never try to set
331// values via this function
332//
333void MHillas::Set(const TArrayF &arr)
334{
335 if (arr.GetSize() != 6)
336 return;
337
338 fLength = arr.At(0); // [mm] major axis of ellipse
339 fWidth = arr.At(1); // [mm] minor axis of ellipse
340 fDelta = arr.At(2); // [rad] angle of major axis with x-axis
341 fSize = arr.At(3); // [#CerPhot] sum of content of all pixels (number of Cherenkov photons)
342 fMeanX = arr.At(4); // [mm] x-coordinate of center of ellipse
343 fMeanY = arr.At(5); // [mm] y-coordinate of center of ellipse
344}
Note: See TracBrowser for help on using the repository browser.