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 <TArrayF.h>
|
---|
63 | #include <TEllipse.h>
|
---|
64 | #include <TVector2.h>
|
---|
65 |
|
---|
66 | #include "MGeomPix.h"
|
---|
67 | #include "MGeomCam.h"
|
---|
68 |
|
---|
69 | #include "MCerPhotPix.h"
|
---|
70 | #include "MCerPhotEvt.h"
|
---|
71 |
|
---|
72 | #include "MLog.h"
|
---|
73 | #include "MLogManip.h"
|
---|
74 |
|
---|
75 | ClassImp(MHillas);
|
---|
76 |
|
---|
77 | using namespace std;
|
---|
78 |
|
---|
79 | // --------------------------------------------------------------------------
|
---|
80 | //
|
---|
81 | // Default constructor.
|
---|
82 | //
|
---|
83 | MHillas::MHillas(const char *name, const char *title)
|
---|
84 | {
|
---|
85 | fName = name ? name : "MHillas";
|
---|
86 | fTitle = title ? title : "Storage container for image parameters of one event";
|
---|
87 |
|
---|
88 | Reset();
|
---|
89 | }
|
---|
90 |
|
---|
91 | // --------------------------------------------------------------------------
|
---|
92 | //
|
---|
93 | // Initializes the values with defaults. For the default values see the
|
---|
94 | // source code.
|
---|
95 | //
|
---|
96 | void MHillas::Reset()
|
---|
97 | {
|
---|
98 | fLength = -1;
|
---|
99 | fWidth = -1;
|
---|
100 | fDelta = 0;
|
---|
101 |
|
---|
102 | fSize = -1;
|
---|
103 | fMeanX = 0;
|
---|
104 | fMeanY = 0;
|
---|
105 | }
|
---|
106 |
|
---|
107 | // --------------------------------------------------------------------------
|
---|
108 | //
|
---|
109 | // return the mean position as TVector2(meanx, meany)
|
---|
110 | //
|
---|
111 | TVector2 MHillas::GetMean() const
|
---|
112 | {
|
---|
113 | return TVector2(fMeanX, fMeanY);
|
---|
114 | }
|
---|
115 |
|
---|
116 | // --------------------------------------------------------------------------
|
---|
117 | //
|
---|
118 | // Print the hillas Parameters to *fLog
|
---|
119 | //
|
---|
120 | void MHillas::Print(Option_t *) const
|
---|
121 | {
|
---|
122 | Double_t atg = atan2(fMeanY, fMeanX)*kRad2Deg;
|
---|
123 |
|
---|
124 | if (atg<0)
|
---|
125 | atg += 180;
|
---|
126 |
|
---|
127 | *fLog << all;
|
---|
128 | *fLog << "Basic Image Parameters (" << GetName() << ")" << endl;
|
---|
129 | *fLog << " - Length [mm] = " << fLength << endl;
|
---|
130 | *fLog << " - Width [mm] = " << fWidth << endl;
|
---|
131 | *fLog << " - Delta [deg] = " << fDelta*kRad2Deg << endl;
|
---|
132 | *fLog << " - Size [1] = " << fSize << " #CherPhot" << endl;
|
---|
133 | *fLog << " - Meanx [mm] = " << fMeanX << endl;
|
---|
134 | *fLog << " - Meany [mm] = " << fMeanY << endl;
|
---|
135 | *fLog << " - atg(y/x) [deg] = " << atg << endl;
|
---|
136 | }
|
---|
137 |
|
---|
138 | // --------------------------------------------------------------------------
|
---|
139 | //
|
---|
140 | // Print the hillas Parameters to *fLog, depending on the geometry in
|
---|
141 | // units of deg
|
---|
142 | //
|
---|
143 | void MHillas::Print(const MGeomCam &geom) const
|
---|
144 | {
|
---|
145 | Double_t atg = atan2(fMeanY, fMeanX)*kRad2Deg;
|
---|
146 |
|
---|
147 | if (atg<0)
|
---|
148 | atg += 180;
|
---|
149 |
|
---|
150 | *fLog << all;
|
---|
151 | *fLog << "Basic Image Parameters (" << GetName() << ")" << endl;
|
---|
152 | *fLog << " - Length [deg] = " << fLength*geom.GetConvMm2Deg() << endl;
|
---|
153 | *fLog << " - Width [deg] = " << fWidth *geom.GetConvMm2Deg() << endl;
|
---|
154 | *fLog << " - Delta [deg] = " << fDelta*kRad2Deg << endl;
|
---|
155 | *fLog << " - Size [1] = " << fSize << " #CherPhot" << endl;
|
---|
156 | *fLog << " - Meanx [deg] = " << fMeanX *geom.GetConvMm2Deg() << endl;
|
---|
157 | *fLog << " - Meany [deg] = " << fMeanY *geom.GetConvMm2Deg() << endl;
|
---|
158 | *fLog << " - atg(y/x) [deg] = " << atg << endl;
|
---|
159 | }
|
---|
160 |
|
---|
161 | // --------------------------------------------------------------------------
|
---|
162 | //
|
---|
163 | // Paint the ellipse corresponding to the parameters
|
---|
164 | //
|
---|
165 | void MHillas::Paint(Option_t *opt)
|
---|
166 | {
|
---|
167 | if (fLength<0 || fWidth<0)
|
---|
168 | return;
|
---|
169 |
|
---|
170 | TEllipse e(fMeanX, fMeanY, fLength, fWidth, 0, 360, fDelta*kRad2Deg+180);
|
---|
171 | e.SetLineWidth(2);
|
---|
172 | e.Paint();
|
---|
173 | }
|
---|
174 |
|
---|
175 | // --------------------------------------------------------------------------
|
---|
176 | //
|
---|
177 | // Calculate the image parameters from a Cherenkov photon event
|
---|
178 | // assuming Cher.photons/pixel and pixel coordinates are given
|
---|
179 | // In case you don't call Calc from within an eventloop make sure, that
|
---|
180 | // you call the Reset member function before.
|
---|
181 | // Returns:
|
---|
182 | // 0 no error
|
---|
183 | // 1 number of pixels < 3
|
---|
184 | // 2 size==0
|
---|
185 | // 3 number of used pixel < 3
|
---|
186 | // 4 CorrXY == 0
|
---|
187 | //
|
---|
188 | Int_t MHillas::Calc(const MGeomCam &geom, const MCerPhotEvt &evt, Int_t island)
|
---|
189 | {
|
---|
190 | //
|
---|
191 | // sanity check 1
|
---|
192 | //
|
---|
193 | if (evt.GetNumPixels()<3)
|
---|
194 | return 1;
|
---|
195 |
|
---|
196 | //
|
---|
197 | // calculate mean value of pixel coordinates and fSize
|
---|
198 | // -----------------------------------------------------
|
---|
199 | //
|
---|
200 | // Because this are only simple sums of roughly 600 values
|
---|
201 | // with an accuracy less than three digits there should not
|
---|
202 | // be any need to use double precision (Double_t) for the
|
---|
203 | // calculation of fMeanX, fMeanY and fSize.
|
---|
204 | //
|
---|
205 | fMeanX = 0;
|
---|
206 | fMeanY = 0;
|
---|
207 | fSize = 0;
|
---|
208 |
|
---|
209 | MCerPhotPix *pix = 0;
|
---|
210 |
|
---|
211 | TIter Next(evt);
|
---|
212 | UInt_t numused = 0;
|
---|
213 | while ((pix=(MCerPhotPix*)Next()))
|
---|
214 | {
|
---|
215 | if (island>=0 && pix->GetIdxIsland()!=island)
|
---|
216 | continue;
|
---|
217 |
|
---|
218 | const MGeomPix &gpix = geom[pix->GetPixId()];
|
---|
219 |
|
---|
220 | const Float_t nphot = pix->GetNumPhotons();
|
---|
221 |
|
---|
222 | fSize += nphot; // [counter]
|
---|
223 | fMeanX += nphot * gpix.GetX(); // [mm]
|
---|
224 | fMeanY += nphot * gpix.GetY(); // [mm]
|
---|
225 |
|
---|
226 | numused++;
|
---|
227 | }
|
---|
228 |
|
---|
229 | //
|
---|
230 | // sanity check 2
|
---|
231 | //
|
---|
232 | if (fSize==0)
|
---|
233 | return 2;
|
---|
234 |
|
---|
235 | fMeanX /= fSize; // [mm]
|
---|
236 | fMeanY /= fSize; // [mm]
|
---|
237 |
|
---|
238 | //
|
---|
239 | // sanity check 3
|
---|
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 | Next.Reset();
|
---|
258 | while ((pix=(MCerPhotPix*)Next()))
|
---|
259 | {
|
---|
260 | if (island>=0 && pix->GetIdxIsland()!=island)
|
---|
261 | continue;
|
---|
262 |
|
---|
263 | const MGeomPix &gpix = geom[pix->GetPixId()];
|
---|
264 |
|
---|
265 | const Float_t dx = gpix.GetX() - fMeanX; // [mm]
|
---|
266 | const Float_t dy = gpix.GetY() - fMeanY; // [mm]
|
---|
267 |
|
---|
268 | const Float_t nphot = pix->GetNumPhotons(); // [#phot]
|
---|
269 |
|
---|
270 | corrxx += nphot * dx*dx; // [mm^2]
|
---|
271 | corrxy += nphot * dx*dy; // [mm^2]
|
---|
272 | corryy += nphot * dy*dy; // [mm^2]
|
---|
273 | }
|
---|
274 |
|
---|
275 | //
|
---|
276 | // If corrxy=0 (which should happen not very often, because fSize>0)
|
---|
277 | // we cannot calculate Length and Width.
|
---|
278 | // In reallity it is almost impossible to have a distribution of
|
---|
279 | // cerenkov photons in the used pixels which is exactly symmetric
|
---|
280 | // along one of the axis.
|
---|
281 | // It seems to be less than 0.1% of all events.
|
---|
282 | //
|
---|
283 | if (corrxy==0)
|
---|
284 | return 4;
|
---|
285 |
|
---|
286 | //
|
---|
287 | // calculate the basic Hillas parameters: orientation and size of axes
|
---|
288 | // -------------------------------------------------------------------
|
---|
289 | //
|
---|
290 | // fDelta is the angle between the major axis of the ellipse and
|
---|
291 | // the x axis. It is independent of the position of the ellipse
|
---|
292 | // in the camera it has values between -pi/2 and pi/2 degrees
|
---|
293 | //
|
---|
294 | // Rem: I tested replacing sqrt() by hypot() but they exactly
|
---|
295 | // consume the same amount of time
|
---|
296 | //
|
---|
297 | const Double_t d0 = corryy - corrxx;
|
---|
298 | const Double_t d1 = corrxy*2;
|
---|
299 | const Double_t d2 = d0 + TMath::Sqrt(d0*d0 + d1*d1);
|
---|
300 | const Double_t tand = d2 / d1;
|
---|
301 | const Double_t tand2 = tand*tand;
|
---|
302 |
|
---|
303 | fDelta = TMath::ATan(tand);
|
---|
304 |
|
---|
305 | const Double_t s2 = tand2+1;
|
---|
306 | const Double_t s = TMath::Sqrt(s2);
|
---|
307 |
|
---|
308 | fCosDelta = 1.0/s; // need these in derived classes
|
---|
309 | fSinDelta = tand/s; // like MHillasExt
|
---|
310 |
|
---|
311 | const Double_t axis1 = (tand2*corryy + d2 + corrxx)/s2/fSize;
|
---|
312 | const Double_t axis2 = (tand2*corrxx - d2 + corryy)/s2/fSize;
|
---|
313 |
|
---|
314 | //
|
---|
315 | // fLength^2 is the second moment along the major axis of the ellipse
|
---|
316 | // fWidth^2 is the second moment along the minor axis of the ellipse
|
---|
317 | //
|
---|
318 | // From the algorithm we get: fWidth <= fLength is always true
|
---|
319 | //
|
---|
320 | // very small numbers can get negative by rounding
|
---|
321 | //
|
---|
322 | fLength = axis1<0 ? 0 : TMath::Sqrt(axis1); // [mm]
|
---|
323 | fWidth = axis2<0 ? 0 : TMath::Sqrt(axis2); // [mm]
|
---|
324 |
|
---|
325 | SetReadyToSave();
|
---|
326 |
|
---|
327 | return 0;
|
---|
328 | }
|
---|
329 |
|
---|
330 | // --------------------------------------------------------------------------
|
---|
331 | //
|
---|
332 | // This function is ment for special usage, please never try to set
|
---|
333 | // values via this function
|
---|
334 | //
|
---|
335 | void MHillas::Set(const TArrayF &arr)
|
---|
336 | {
|
---|
337 | if (arr.GetSize() != 6)
|
---|
338 | return;
|
---|
339 |
|
---|
340 | fLength = arr.At(0); // [mm] major axis of ellipse
|
---|
341 | fWidth = arr.At(1); // [mm] minor axis of ellipse
|
---|
342 | fDelta = arr.At(2); // [rad] angle of major axis with x-axis
|
---|
343 | fSize = arr.At(3); // [#CerPhot] sum of content of all pixels (number of Cherenkov photons)
|
---|
344 | fMeanX = arr.At(4); // [mm] x-coordinate of center of ellipse
|
---|
345 | fMeanY = arr.At(5); // [mm] y-coordinate of center of ellipse
|
---|
346 | }
|
---|