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-2002
|
---|
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 | /////////////////////////////////////////////////////////////////////////////
|
---|
53 | #include "MHillas.h"
|
---|
54 |
|
---|
55 | #include <fstream.h>
|
---|
56 |
|
---|
57 | #include <TArrayF.h>
|
---|
58 | #include <TEllipse.h>
|
---|
59 |
|
---|
60 | #include "MGeomPix.h"
|
---|
61 | #include "MGeomCam.h"
|
---|
62 |
|
---|
63 | #include "MCerPhotPix.h"
|
---|
64 | #include "MCerPhotEvt.h"
|
---|
65 |
|
---|
66 | #include "MLog.h"
|
---|
67 | #include "MLogManip.h"
|
---|
68 |
|
---|
69 | ClassImp(MHillas);
|
---|
70 |
|
---|
71 | // --------------------------------------------------------------------------
|
---|
72 | //
|
---|
73 | // Default constructor.
|
---|
74 | //
|
---|
75 | MHillas::MHillas(const char *name, const char *title) : fEllipse(NULL)
|
---|
76 | {
|
---|
77 | fName = name ? name : "MHillas";
|
---|
78 | fTitle = title ? title : "Storage container for image parameters of one event";
|
---|
79 |
|
---|
80 | Reset();
|
---|
81 |
|
---|
82 | fEllipse = new TEllipse;
|
---|
83 | }
|
---|
84 |
|
---|
85 | // --------------------------------------------------------------------------
|
---|
86 | //
|
---|
87 | // Destructor. Deletes the TEllipse if one exists.
|
---|
88 | //
|
---|
89 | MHillas::~MHillas()
|
---|
90 | {
|
---|
91 | Clear();
|
---|
92 | }
|
---|
93 |
|
---|
94 | // --------------------------------------------------------------------------
|
---|
95 | //
|
---|
96 | // Initializes the values with defaults. For the default values see the
|
---|
97 | // source code.
|
---|
98 | //
|
---|
99 | void MHillas::Reset()
|
---|
100 | {
|
---|
101 | fLength = -1;
|
---|
102 | fWidth = -1;
|
---|
103 | fDelta = 0;
|
---|
104 |
|
---|
105 | fSize = -1;
|
---|
106 | fMeanX = -1;
|
---|
107 | fMeanY = -1;
|
---|
108 |
|
---|
109 | fNumUsedPixels = -1;
|
---|
110 | fNumCorePixels = -1;
|
---|
111 |
|
---|
112 | Clear();
|
---|
113 | }
|
---|
114 |
|
---|
115 | // --------------------------------------------------------------------------
|
---|
116 | //
|
---|
117 | // Print the hillas Parameters to *fLog
|
---|
118 | //
|
---|
119 | void MHillas::Print(Option_t *) const
|
---|
120 | {
|
---|
121 | Double_t atg = atan2(fMeanY, fMeanX)*kRad2Deg;
|
---|
122 |
|
---|
123 | if (atg<0)
|
---|
124 | atg += 180;
|
---|
125 |
|
---|
126 | *fLog << all;
|
---|
127 | *fLog << "Basic Image Parameters (" << GetName() << ")" << endl;
|
---|
128 | *fLog << " - Length [mm] = " << fLength << endl;
|
---|
129 | *fLog << " - Width [mm] = " << fWidth << endl;
|
---|
130 | *fLog << " - Delta [deg] = " << fDelta*kRad2Deg << endl;
|
---|
131 | *fLog << " - Size [1] = " << fSize << " #CherPhot" << endl;
|
---|
132 | *fLog << " - Meanx [mm] = " << fMeanX << endl;
|
---|
133 | *fLog << " - Meany [mm] = " << fMeanY << endl;
|
---|
134 | *fLog << " - atg(y/x) [deg] = " << atg << endl;
|
---|
135 | *fLog << " - Used Pixels [#] = " << fNumUsedPixels << " Pixels" << endl;
|
---|
136 | *fLog << " - Core Pixels [#] = " << fNumCorePixels << " Pixels" << endl;
|
---|
137 | }
|
---|
138 |
|
---|
139 | /*
|
---|
140 | // -----------------------------------------------------------
|
---|
141 | //
|
---|
142 | // call the Paint function of the Ellipse if a TEllipse exists
|
---|
143 | //
|
---|
144 | void MHillas::Paint(Option_t *)
|
---|
145 | {
|
---|
146 | fEllipse->SetLineWidth(2);
|
---|
147 | fEllipse->PaintEllipse(fMeanX, fMeanY, fLength, fWidth,
|
---|
148 | 0, 360, fDelta*kRad2Deg+180);
|
---|
149 | }
|
---|
150 | */
|
---|
151 |
|
---|
152 | // --------------------------------------------------------------------------
|
---|
153 | //
|
---|
154 | // Instead of adding MHillas itself to the Pad
|
---|
155 | // (s. AppendPad in TObject) we create an ellipse,
|
---|
156 | // which is added to the Pad by its Draw function
|
---|
157 | // You can remove it by deleting the Ellipse Object
|
---|
158 | // (s. Clear() )
|
---|
159 | //
|
---|
160 | void MHillas::Draw(Option_t *opt)
|
---|
161 | {
|
---|
162 |
|
---|
163 | Clear();
|
---|
164 |
|
---|
165 | if (fLength<0 || fWidth<0)
|
---|
166 | return;
|
---|
167 |
|
---|
168 | fEllipse = new TEllipse(fMeanX, fMeanY, fLength, fWidth,
|
---|
169 | 0, 360, fDelta*kRad2Deg+180);
|
---|
170 |
|
---|
171 | fEllipse->SetLineWidth(2);
|
---|
172 | fEllipse->Draw();
|
---|
173 |
|
---|
174 | /*
|
---|
175 | fEllipse->SetPhimin();
|
---|
176 | fEllipse->SetPhimax();
|
---|
177 | fEllipse->SetR1(fLength);
|
---|
178 | fEllipse->SetR2(fWidth);
|
---|
179 | fEllipse->SetTheta(fDelta*kRad2Deg+180);
|
---|
180 | fEllipse->SetX1(fMeanX);
|
---|
181 | fEllipse->SetY1(fMeanY);
|
---|
182 |
|
---|
183 | fEllipse->SetLineWidth(2);
|
---|
184 | fEllipse->PaintEllipse(fMeanX, fMeanY, fLength, fWidth,
|
---|
185 | 0, 360, fDelta*kRad2Deg+180);
|
---|
186 |
|
---|
187 | AppendPad(opt);
|
---|
188 |
|
---|
189 | // This is from TH1
|
---|
190 | TString opt = option;
|
---|
191 | opt.ToLower();
|
---|
192 | if (gPad && !opt.Contains("same")) {
|
---|
193 | //the following statement is necessary in case one attempts to draw
|
---|
194 | //a temporary histogram already in the current pad
|
---|
195 | if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
|
---|
196 | gPad->Clear();
|
---|
197 | }
|
---|
198 | */
|
---|
199 | }
|
---|
200 |
|
---|
201 | // --------------------------------------------------------------------------
|
---|
202 | //
|
---|
203 | // If a TEllipse object exists it is deleted
|
---|
204 | //
|
---|
205 | void MHillas::Clear(Option_t *)
|
---|
206 | {
|
---|
207 | if (!fEllipse)
|
---|
208 | return;
|
---|
209 |
|
---|
210 | delete fEllipse;
|
---|
211 |
|
---|
212 | fEllipse = NULL;
|
---|
213 | }
|
---|
214 |
|
---|
215 |
|
---|
216 | // --------------------------------------------------------------------------
|
---|
217 | //
|
---|
218 | // Calculate the image parameters from a Cherenkov photon event
|
---|
219 | // assuming Cher.photons/pixel and pixel coordinates are given
|
---|
220 | // In case you don't call Calc from within an eventloop make sure, that
|
---|
221 | // you call the Reset member function before.
|
---|
222 | // Returns:
|
---|
223 | // 0 no error
|
---|
224 | // 1 number of pixels < 3
|
---|
225 | // 2 size==0
|
---|
226 | // 3 number of used pixel < 3
|
---|
227 | // 4 CorrXY == 0
|
---|
228 | //
|
---|
229 | Int_t MHillas::Calc(const MGeomCam &geom, const MCerPhotEvt &evt)
|
---|
230 | {
|
---|
231 | const UInt_t npixevt = evt.GetNumPixels();
|
---|
232 |
|
---|
233 | //
|
---|
234 | // sanity check
|
---|
235 | //
|
---|
236 | if (npixevt < 3)
|
---|
237 | {
|
---|
238 | //*fLog << warn << "MHillas::Calc: Event has less than three pixels... skipped." << endl;
|
---|
239 | return 1;
|
---|
240 | }
|
---|
241 |
|
---|
242 | //
|
---|
243 | // calculate mean value of pixel coordinates and fSize
|
---|
244 | // -----------------------------------------------------
|
---|
245 | //
|
---|
246 | // Because this are only simple sums of roughly 600 values
|
---|
247 | // with an accuracy less than three digits there should not
|
---|
248 | // be any need to use double precision (Double_t) for the
|
---|
249 | // calculation of fMeanX, fMeanY and fSize.
|
---|
250 | //
|
---|
251 | fMeanX = 0;
|
---|
252 | fMeanY = 0;
|
---|
253 | fSize = 0;
|
---|
254 |
|
---|
255 | fNumUsedPixels = 0;
|
---|
256 | fNumCorePixels = 0;
|
---|
257 |
|
---|
258 | for (UInt_t i=0; i<npixevt; i++)
|
---|
259 | {
|
---|
260 | const MCerPhotPix &pix = evt[i];
|
---|
261 |
|
---|
262 | if (!pix.IsPixelUsed())
|
---|
263 | continue;
|
---|
264 |
|
---|
265 | const MGeomPix &gpix = geom[pix.GetPixId()];
|
---|
266 |
|
---|
267 | const Float_t nphot = pix.GetNumPhotons();
|
---|
268 |
|
---|
269 | //if (nphot==0)
|
---|
270 | // *fLog << warn << GetDescriptor() << ": Pixel #" << pix.GetPixId() << " has no photons." << endl;
|
---|
271 |
|
---|
272 | fSize += nphot; // [counter]
|
---|
273 | fMeanX += nphot * gpix.GetX(); // [mm]
|
---|
274 | fMeanY += nphot * gpix.GetY(); // [mm]
|
---|
275 |
|
---|
276 | if (pix.IsPixelCore())
|
---|
277 | fNumCorePixels++;
|
---|
278 |
|
---|
279 | fNumUsedPixels++;
|
---|
280 | }
|
---|
281 |
|
---|
282 | //
|
---|
283 | // sanity checks
|
---|
284 | //
|
---|
285 | if (fSize==0)
|
---|
286 | {
|
---|
287 | //*fLog << inf << GetDescriptor() << ": Event has zero cerenkov photons... skipped." << endl;
|
---|
288 | return 2;
|
---|
289 | }
|
---|
290 |
|
---|
291 | fMeanX /= fSize; // [mm]
|
---|
292 | fMeanY /= fSize; // [mm]
|
---|
293 |
|
---|
294 | if (fNumUsedPixels<3)
|
---|
295 | {
|
---|
296 | //*fLog << inf << GetDescriptor() << ": Event has less than 3 used pixels... skipped." << endl;
|
---|
297 | return 3;
|
---|
298 | }
|
---|
299 |
|
---|
300 | //
|
---|
301 | // calculate 2nd moments
|
---|
302 | // ---------------------
|
---|
303 | //
|
---|
304 | // To make sure that the more complicated sum is evaluated as
|
---|
305 | // accurate as possible (because it is needed for more
|
---|
306 | // complicated calculations (see below) we calculate it using
|
---|
307 | // double prcision.
|
---|
308 | //
|
---|
309 | Double_t corrxx=0; // [m^2]
|
---|
310 | Double_t corrxy=0; // [m^2]
|
---|
311 | Double_t corryy=0; // [m^2]
|
---|
312 |
|
---|
313 | for (UInt_t i=0; i<npixevt; i++)
|
---|
314 | {
|
---|
315 | const MCerPhotPix &pix = evt[i];
|
---|
316 |
|
---|
317 | if (!pix.IsPixelUsed())
|
---|
318 | continue;
|
---|
319 |
|
---|
320 | const MGeomPix &gpix = geom[pix.GetPixId()];
|
---|
321 |
|
---|
322 | const Float_t dx = gpix.GetX() - fMeanX; // [mm]
|
---|
323 | const Float_t dy = gpix.GetY() - fMeanY; // [mm]
|
---|
324 |
|
---|
325 | const Float_t nphot = pix.GetNumPhotons(); // [#phot]
|
---|
326 |
|
---|
327 | corrxx += nphot * dx*dx; // [mm^2]
|
---|
328 | corrxy += nphot * dx*dy; // [mm^2]
|
---|
329 | corryy += nphot * dy*dy; // [mm^2]
|
---|
330 | }
|
---|
331 |
|
---|
332 | //
|
---|
333 | // If corrxy=0 (which should never happen, because fSize>0) we
|
---|
334 | // cannot calculate Length and Width. The calculation failed
|
---|
335 | // and returns kFALSE
|
---|
336 | // In reallity it is almost impossible to have a distribution
|
---|
337 | // of cerenkov photons in the used pixels which is exactly symmetric
|
---|
338 | // along one of the axis.
|
---|
339 | //
|
---|
340 | if (corrxy==0)
|
---|
341 | {
|
---|
342 | //*fLog << inf << GetDescriptor() << ": Event has CorrXY==0... skipped." << endl;
|
---|
343 | return 4;
|
---|
344 | }
|
---|
345 |
|
---|
346 | //
|
---|
347 | // calculate the basic Hillas parameters: orientation and size of axes
|
---|
348 | // -------------------------------------------------------------------
|
---|
349 | //
|
---|
350 | // fDelta is the angle between the major axis of the ellipse and
|
---|
351 | // the x axis. It is independent of the position of the ellipse
|
---|
352 | // in the camera it has values between -pi/2 and pi/2 degrees
|
---|
353 | //
|
---|
354 | const Double_t d0 = corryy - corrxx;
|
---|
355 | const Double_t d1 = corrxy*2;
|
---|
356 | const Double_t d2 = d0 + sqrt(d0*d0 + d1*d1);
|
---|
357 | const Double_t tand = d2 / d1;
|
---|
358 |
|
---|
359 | fDelta = atan(tand);
|
---|
360 |
|
---|
361 | const Double_t s2 = tand*tand+1;
|
---|
362 | const Double_t s = sqrt(s2);
|
---|
363 |
|
---|
364 | fCosDelta = 1.0/s; // need these in derived classes
|
---|
365 | fSinDelta = tand/s; // like MHillasExt
|
---|
366 |
|
---|
367 | Double_t axis1 = (tand*tand*corryy + d2 + corrxx)/s2/fSize;
|
---|
368 | Double_t axis2 = (tand*tand*corrxx - d2 + corryy)/s2/fSize;
|
---|
369 |
|
---|
370 | //
|
---|
371 | // fLength^2 is the second moment along the major axis of the ellipse
|
---|
372 | // fWidth^2 is the second moment along the minor axis of the ellipse
|
---|
373 | //
|
---|
374 | // From the algorithm we get: fWidth <= fLength is always true
|
---|
375 | //
|
---|
376 | // very small numbers can get negative by rounding
|
---|
377 | //
|
---|
378 | fLength = axis1<0 ? 0 : sqrt(axis1); // [mm]
|
---|
379 | fWidth = axis2<0 ? 0 : sqrt(axis2); // [mm]
|
---|
380 |
|
---|
381 | SetReadyToSave();
|
---|
382 |
|
---|
383 | return 0;
|
---|
384 | }
|
---|
385 |
|
---|
386 | // --------------------------------------------------------------------------
|
---|
387 | //
|
---|
388 | // This function is ment for special usage, please never try to set
|
---|
389 | // values via this function
|
---|
390 | //
|
---|
391 | void MHillas::Set(const TArrayF &arr)
|
---|
392 | {
|
---|
393 | if (arr.GetSize() != 8)
|
---|
394 | return;
|
---|
395 |
|
---|
396 | fLength = arr.At(0); // [mm] major axis of ellipse
|
---|
397 | fWidth = arr.At(1); // [mm] minor axis of ellipse
|
---|
398 | fDelta = arr.At(2); // [rad] angle of major axis with x-axis
|
---|
399 | fSize = arr.At(3); // [#CerPhot] sum of content of all pixels (number of Cherenkov photons)
|
---|
400 | fMeanX = arr.At(4); // [mm] x-coordinate of center of ellipse
|
---|
401 | fMeanY = arr.At(5); // [mm] y-coordinate of center of ellipse
|
---|
402 |
|
---|
403 | fNumUsedPixels = (Short_t)arr.At(6); // Number of pixels which survived the image cleaning
|
---|
404 | fNumCorePixels = (Short_t)arr.At(7); // number of core pixels
|
---|
405 | }
|
---|
406 |
|
---|
407 |
|
---|
408 | // --------------------------------------------------------------------------
|
---|
409 | //
|
---|
410 | /*
|
---|
411 | void MHillas::AsciiRead(ifstream &fin)
|
---|
412 | {
|
---|
413 | fin >> fLength;
|
---|
414 | fin >> fWidth;
|
---|
415 | fin >> fDelta;
|
---|
416 | fin >> fSize;
|
---|
417 | fin >> fMeanX;
|
---|
418 | fin >> fMeanY;
|
---|
419 | }
|
---|
420 | */
|
---|
421 | // --------------------------------------------------------------------------
|
---|
422 | /*
|
---|
423 | void MHillas::AsciiWrite(ofstream &fout) const
|
---|
424 | {
|
---|
425 | fout << fLength << " ";
|
---|
426 | fout << fWidth << " ";
|
---|
427 | fout << fDelta << " ";
|
---|
428 | fout << fSize << " ";
|
---|
429 | fout << fMeanX << " ";
|
---|
430 | fout << fMeanY;
|
---|
431 | }
|
---|
432 | */ |
---|