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 <TEllipse.h>
|
---|
58 |
|
---|
59 | #include "MGeomPix.h"
|
---|
60 | #include "MGeomCam.h"
|
---|
61 |
|
---|
62 | #include "MCerPhotPix.h"
|
---|
63 | #include "MCerPhotEvt.h"
|
---|
64 |
|
---|
65 | #include "MLog.h"
|
---|
66 | #include "MLogManip.h"
|
---|
67 |
|
---|
68 | ClassImp(MHillas);
|
---|
69 |
|
---|
70 | // --------------------------------------------------------------------------
|
---|
71 | //
|
---|
72 | // Default constructor.
|
---|
73 | //
|
---|
74 | MHillas::MHillas(const char *name, const char *title) : fEllipse(NULL)
|
---|
75 | {
|
---|
76 | fName = name ? name : "MHillas";
|
---|
77 | fTitle = title ? title : "Storage container for image parameters of one event";
|
---|
78 |
|
---|
79 | Reset();
|
---|
80 | // FIXME: (intelligent) initialization of values missing
|
---|
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 | }
|
---|
136 |
|
---|
137 | /*
|
---|
138 | // -----------------------------------------------------------
|
---|
139 | //
|
---|
140 | // call the Paint function of the Ellipse if a TEllipse exists
|
---|
141 | //
|
---|
142 | void MHillas::Paint(Option_t *)
|
---|
143 | {
|
---|
144 | fEllipse->SetLineWidth(2);
|
---|
145 | fEllipse->PaintEllipse(fMeanX, fMeanY, fLength, fWidth,
|
---|
146 | 0, 360, fDelta*kRad2Deg+180);
|
---|
147 | }
|
---|
148 | */
|
---|
149 |
|
---|
150 | // --------------------------------------------------------------------------
|
---|
151 | //
|
---|
152 | // Instead of adding MHillas itself to the Pad
|
---|
153 | // (s. AppendPad in TObject) we create an ellipse,
|
---|
154 | // which is added to the Pad by its Draw function
|
---|
155 | // You can remove it by deleting the Ellipse Object
|
---|
156 | // (s. Clear() )
|
---|
157 | //
|
---|
158 | void MHillas::Draw(Option_t *opt)
|
---|
159 | {
|
---|
160 |
|
---|
161 | Clear();
|
---|
162 |
|
---|
163 | fEllipse = new TEllipse(fMeanX, fMeanY, fLength, fWidth,
|
---|
164 | 0, 360, fDelta*kRad2Deg+180);
|
---|
165 |
|
---|
166 | fEllipse->SetLineWidth(2);
|
---|
167 | fEllipse->Draw();
|
---|
168 |
|
---|
169 | /*
|
---|
170 | fEllipse->SetPhimin();
|
---|
171 | fEllipse->SetPhimax();
|
---|
172 | fEllipse->SetR1(fLength);
|
---|
173 | fEllipse->SetR2(fWidth);
|
---|
174 | fEllipse->SetTheta(fDelta*kRad2Deg+180);
|
---|
175 | fEllipse->SetX1(fMeanX);
|
---|
176 | fEllipse->SetY1(fMeanY);
|
---|
177 |
|
---|
178 | fEllipse->SetLineWidth(2);
|
---|
179 | fEllipse->PaintEllipse(fMeanX, fMeanY, fLength, fWidth,
|
---|
180 | 0, 360, fDelta*kRad2Deg+180);
|
---|
181 |
|
---|
182 | AppendPad(opt);
|
---|
183 |
|
---|
184 | // This is from TH1
|
---|
185 | TString opt = option;
|
---|
186 | opt.ToLower();
|
---|
187 | if (gPad && !opt.Contains("same")) {
|
---|
188 | //the following statement is necessary in case one attempts to draw
|
---|
189 | //a temporary histogram already in the current pad
|
---|
190 | if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
|
---|
191 | gPad->Clear();
|
---|
192 | }
|
---|
193 | */
|
---|
194 | }
|
---|
195 |
|
---|
196 | // --------------------------------------------------------------------------
|
---|
197 | //
|
---|
198 | // If a TEllipse object exists it is deleted
|
---|
199 | //
|
---|
200 | void MHillas::Clear(Option_t *)
|
---|
201 | {
|
---|
202 | if (!fEllipse)
|
---|
203 | return;
|
---|
204 |
|
---|
205 | delete fEllipse;
|
---|
206 |
|
---|
207 | fEllipse = NULL;
|
---|
208 | }
|
---|
209 |
|
---|
210 |
|
---|
211 | // --------------------------------------------------------------------------
|
---|
212 | //
|
---|
213 | // Calculate the image parameters from a Cherenkov photon event
|
---|
214 | // assuming Cher.photons/pixel and pixel coordinates are given
|
---|
215 | // In case you don't call Calc from within an eventloop make sure, that
|
---|
216 | // you call the Reset member function before.
|
---|
217 | //
|
---|
218 | Bool_t MHillas::Calc(const MGeomCam &geom, const MCerPhotEvt &evt)
|
---|
219 | {
|
---|
220 | const UInt_t npixevt = evt.GetNumPixels();
|
---|
221 |
|
---|
222 | //
|
---|
223 | // sanity check
|
---|
224 | //
|
---|
225 | if (npixevt <= 2)
|
---|
226 | {
|
---|
227 | *fLog << warn << "MHillas::Calc: Event has less than two pixels... skipped." << endl;
|
---|
228 | return kFALSE;
|
---|
229 | }
|
---|
230 |
|
---|
231 | //
|
---|
232 | // calculate mean value of pixel coordinates and fSize
|
---|
233 | // -----------------------------------------------------
|
---|
234 | //
|
---|
235 | // Because this are only simple sums of roughly 600 values
|
---|
236 | // with an accuracy less than three digits there should not
|
---|
237 | // be any need to use double precision (Double_t) for the
|
---|
238 | // calculation of fMeanX, fMeanY and fSize.
|
---|
239 | //
|
---|
240 | fMeanX = 0;
|
---|
241 | fMeanY = 0;
|
---|
242 | fSize = 0;
|
---|
243 |
|
---|
244 | fNumUsedPixels = 0;
|
---|
245 | fNumCorePixels = 0;
|
---|
246 |
|
---|
247 | for (UInt_t i=0; i<npixevt; i++)
|
---|
248 | {
|
---|
249 | const MCerPhotPix &pix = evt[i];
|
---|
250 |
|
---|
251 | if (!pix.IsPixelUsed())
|
---|
252 | continue;
|
---|
253 |
|
---|
254 | const MGeomPix &gpix = geom[pix.GetPixId()];
|
---|
255 |
|
---|
256 | const Float_t nphot = pix.GetNumPhotons();
|
---|
257 |
|
---|
258 | if (nphot==0)
|
---|
259 | *fLog << warn << GetDescriptor() << ": Pixel #" << pix.GetPixId() << " has no photons." << endl;
|
---|
260 |
|
---|
261 | fSize += nphot; // [counter]
|
---|
262 | fMeanX += nphot * gpix.GetX(); // [mm]
|
---|
263 | fMeanY += nphot * gpix.GetY(); // [mm]
|
---|
264 |
|
---|
265 | if (pix.IsPixelCore())
|
---|
266 | fNumCorePixels++;
|
---|
267 |
|
---|
268 | fNumUsedPixels++;
|
---|
269 | }
|
---|
270 |
|
---|
271 | //
|
---|
272 | // sanity checks
|
---|
273 | //
|
---|
274 | if (fSize==0)
|
---|
275 | {
|
---|
276 | *fLog << warn << GetDescriptor() << ": Event has zero cerenkov photons... skipped." << endl;
|
---|
277 | return kFALSE;
|
---|
278 | }
|
---|
279 |
|
---|
280 | if (fNumUsedPixels<3)
|
---|
281 | {
|
---|
282 | *fLog << warn << GetDescriptor() << ": Event has less than 3 used pixels... skipped." << endl;
|
---|
283 | return kFALSE;
|
---|
284 | }
|
---|
285 |
|
---|
286 | fMeanX /= fSize; // [mm]
|
---|
287 | fMeanY /= fSize; // [mm]
|
---|
288 |
|
---|
289 | //
|
---|
290 | // calculate 2nd moments
|
---|
291 | // ---------------------
|
---|
292 | //
|
---|
293 | // To make sure that the more complicated sum is evaluated as
|
---|
294 | // accurate as possible (because it is needed for more
|
---|
295 | // complicated calculations (see below) we calculate it using
|
---|
296 | // double prcision.
|
---|
297 | //
|
---|
298 | Double_t corrxx=0; // [m^2]
|
---|
299 | Double_t corrxy=0; // [m^2]
|
---|
300 | Double_t corryy=0; // [m^2]
|
---|
301 |
|
---|
302 | for (UInt_t i=0; i<npixevt; i++)
|
---|
303 | {
|
---|
304 | const MCerPhotPix &pix = evt[i];
|
---|
305 |
|
---|
306 | if (!pix.IsPixelUsed())
|
---|
307 | continue;
|
---|
308 |
|
---|
309 | const MGeomPix &gpix = geom[pix.GetPixId()];
|
---|
310 |
|
---|
311 | const Float_t dx = gpix.GetX() - fMeanX; // [mm]
|
---|
312 | const Float_t dy = gpix.GetY() - fMeanY; // [mm]
|
---|
313 |
|
---|
314 | const Float_t nphot = pix.GetNumPhotons(); // [#phot]
|
---|
315 |
|
---|
316 | corrxx += nphot * dx*dx; // [mm^2]
|
---|
317 | corrxy += nphot * dx*dy; // [mm^2]
|
---|
318 | corryy += nphot * dy*dy; // [mm^2]
|
---|
319 | }
|
---|
320 |
|
---|
321 | //
|
---|
322 | // If corrxy=0 (which should never happen, because fSize>0) we
|
---|
323 | // cannot calculate Length and Width. The calculation failed
|
---|
324 | // and returnes kFALSE
|
---|
325 | //
|
---|
326 | if (corrxy==0)
|
---|
327 | {
|
---|
328 | *fLog << warn << GetDescriptor() << ": Event has CorrXY==0... skipped." << endl;
|
---|
329 | return kFALSE;
|
---|
330 | }
|
---|
331 |
|
---|
332 | //
|
---|
333 | // calculate the basic Hillas parameters: orientation and size of axes
|
---|
334 | // -------------------------------------------------------------------
|
---|
335 | //
|
---|
336 | // fDelta is the angle between the major axis of the ellipse and
|
---|
337 | // the x axis. It is independent of the position of the ellipse
|
---|
338 | // in the camera it has values between -pi/2 and pi/2 degrees
|
---|
339 | //
|
---|
340 | const Double_t d0 = corryy - corrxx;
|
---|
341 | const Double_t d1 = corrxy*2;
|
---|
342 | const Double_t d2 = d0 + sqrt(d0*d0 + d1*d1);
|
---|
343 | const Double_t tand = d2 / d1;
|
---|
344 |
|
---|
345 | fDelta = atan(tand);
|
---|
346 |
|
---|
347 | const Double_t s2 = tand*tand+1;
|
---|
348 | const Double_t s = sqrt(s2);
|
---|
349 |
|
---|
350 | fCosDelta = 1.0/s; // need these in derived classes
|
---|
351 | fSinDelta = tand/s; // like MHillasExt
|
---|
352 |
|
---|
353 | Double_t axis1 = (tand*tand*corryy + d2 + corrxx)/s2/fSize;
|
---|
354 | Double_t axis2 = (tand*tand*corrxx - d2 + corryy)/s2/fSize;
|
---|
355 |
|
---|
356 | //
|
---|
357 | // fLength^2 is the second moment along the major axis of the ellipse
|
---|
358 | // fWidth^2 is the second moment along the minor axis of the ellipse
|
---|
359 | //
|
---|
360 | // From the algorithm we get: fWidth <= fLength is always true
|
---|
361 | //
|
---|
362 | // very small numbers can get negative by rounding
|
---|
363 | //
|
---|
364 | fLength = axis1<0 ? 0 : sqrt(axis1); // [mm]
|
---|
365 | fWidth = axis2<0 ? 0 : sqrt(axis2); // [mm]
|
---|
366 |
|
---|
367 | SetReadyToSave();
|
---|
368 |
|
---|
369 | return kTRUE;
|
---|
370 | }
|
---|
371 |
|
---|
372 | // --------------------------------------------------------------------------
|
---|
373 | //
|
---|
374 | /*
|
---|
375 | void MHillas::AsciiRead(ifstream &fin)
|
---|
376 | {
|
---|
377 | fin >> fLength;
|
---|
378 | fin >> fWidth;
|
---|
379 | fin >> fDelta;
|
---|
380 | fin >> fSize;
|
---|
381 | fin >> fMeanX;
|
---|
382 | fin >> fMeanY;
|
---|
383 | }
|
---|
384 | */
|
---|
385 | // --------------------------------------------------------------------------
|
---|
386 | /*
|
---|
387 | void MHillas::AsciiWrite(ofstream &fout) const
|
---|
388 | {
|
---|
389 | fout << fLength << " ";
|
---|
390 | fout << fWidth << " ";
|
---|
391 | fout << fDelta << " ";
|
---|
392 | fout << fSize << " ";
|
---|
393 | fout << fMeanX << " ";
|
---|
394 | fout << fMeanY;
|
---|
395 | }
|
---|
396 | */ |
---|