source: trunk/MagicSoft/Mars/manalysis/MHillas.cc@ 1014

Last change on this file since 1014 was 1003, checked in by tbretz, 23 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 8.5 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): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
19! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
20!
21! Copyright: MAGIC Software Development, 2000-2001
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27// //
28// MHillas //
29// //
30// Storage Container for the Hillas parameter //
31// //
32// FIXME: - Here everybody should find an explanation of the parameters //
33// - using boooleans for fIsPixelUsed, fIsPixelCore, ... is rather //
34// slow because you have to loop over all pixels in any loop. //
35// There could be a huge speed improvement using Hash Tables //
36// (linked lists, see THashTable and THashList, too) //
37// //
38/////////////////////////////////////////////////////////////////////////////
39#include "MHillas.h"
40
41#include <math.h>
42#include <fstream.h>
43
44#include <TEllipse.h>
45
46#include "MGeomPix.h"
47#include "MGeomCam.h"
48
49#include "MCerPhotPix.h"
50#include "MCerPhotEvt.h"
51
52#include "MLog.h"
53
54ClassImp(MHillas);
55
56// --------------------------------------------------------------------------
57//
58// Default constructor.
59//
60MHillas::MHillas(const char *name, const char *title) : fEllipse(NULL)
61{
62 fName = name ? name : "MHillas";
63 fTitle = title ? title : "Storage container for Hillas parameter of one event";
64
65 Reset();
66 // FIXME: (intelligent) initialization of values missing
67}
68
69// --------------------------------------------------------------------------
70//
71// Destructor. Deletes the TEllipse if one exists.
72//
73MHillas::~MHillas()
74{
75 Clear();
76}
77
78void MHillas::Reset()
79{
80 fAlpha = 0;
81 fTheta = 0;
82 fWidth = 0;
83 fLength = 0;
84 fSize = 0;
85 fDist = 0;
86
87 Clear();
88}
89
90// --------------------------------------------------------------------------
91//
92// Print the hillas Parameters to *fLog
93//
94void MHillas::Print(Option_t *) const
95{
96 *fLog << "Hillas Parameter:" << endl;
97 *fLog << " - Alpha = " << fabs(fAlpha) << endl;
98 *fLog << " - Width = " << fWidth << endl;
99 *fLog << " - Length = " << fLength << endl;
100 *fLog << " - Size = " << fSize << endl;
101 *fLog << " - Dist = " << fDist << endl;
102}
103
104// --------------------------------------------------------------------------
105//
106// call the Paint function of the Ellipse if a TEllipse exists
107//
108void MHillas::Paint(Option_t *)
109{
110 if (!fEllipse)
111 return;
112
113 fEllipse->Paint();
114}
115
116// --------------------------------------------------------------------------
117//
118// Instead of adding MHillas itself to the Pad
119// (s. AppendPad in TObject) we create an ellipse,
120// which is added to the Pad by it's Draw function
121// You can remove it by deleting the Ellipse Object
122// (s. Clear() )
123//
124void MHillas::Draw(Option_t *)
125{
126 Clear();
127
128 fEllipse = new TEllipse(cos(fTheta)*fDist, sin(fTheta)*fDist,
129 fLength, fWidth,
130 0, 360, fTheta*kRad2Deg+fAlpha-180);
131
132 fEllipse->SetLineWidth(2);
133 fEllipse->Draw();
134
135 /*
136 This is from TH1
137 TString opt = option;
138 opt.ToLower();
139 if (gPad && !opt.Contains("same")) {
140 //the following statement is necessary in case one attempts to draw
141 //a temporary histogram already in the current pad
142 if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
143 gPad->Clear();
144 }
145 AppendPad(opt.Data());
146 */
147}
148
149// --------------------------------------------------------------------------
150//
151// If a TEllipse object exists it is deleted
152//
153void MHillas::Clear(Option_t *)
154{
155 if (!fEllipse)
156 return;
157
158 delete fEllipse;
159
160 fEllipse = NULL;
161}
162
163// --------------------------------------------------------------------------
164//
165// Calculate the Hillas parameters from a cerenkov photon event
166// (The calcualtion is some kind of two dimentional statistics)
167//
168// FIXME: MHillas::Calc is rather slow at the moment because it loops
169// unnecessarily over all pixels in all its loops (s.MImgCleanStd)
170// The speed could be improved very much by using Hash-Tables
171// (linked lists, see THashTable and THashList, too)
172//
173Bool_t MHillas::Calc(const MGeomCam &geom, const MCerPhotEvt &evt)
174{
175 const UInt_t nevt = evt.GetNumPixels();
176
177 //
178 // sanity check
179 //
180 if (nevt <= 2)
181 return kFALSE;
182
183 //
184 // calculate mean valu of pixels
185 //
186 float xmean =0;
187 float ymean =0;
188
189 fSize = 0;
190
191 //
192 // FIXME! npix should be retrieved from MCerPhotEvt
193 //
194 UShort_t npix=0;
195 for (UInt_t i=0; i<nevt; i++)
196 {
197 const MCerPhotPix &pix = evt[i];
198
199 if (!pix.IsPixelUsed())
200 continue;
201
202 const MGeomPix &gpix = geom[pix.GetPixId()];
203
204 const float nphot = pix.GetNumPhotons();
205
206 fSize += nphot;
207 xmean += nphot * gpix.GetX(); // [mm]
208 ymean += nphot * gpix.GetY(); // [mm]
209
210 npix++;
211 }
212
213 //
214 // sanity check
215 //
216 if (fSize==0 || npix<=2)
217 return kFALSE;
218
219 xmean /= fSize; // [mm]
220 ymean /= fSize; // [mm]
221
222 //
223 // calculate sdev
224 //
225 float sigmaxx=0;
226 float sigmaxy=0;
227 float sigmayy=0;
228
229 for (UInt_t i=0; i<nevt; i++)
230 {
231 const MCerPhotPix &pix = evt[i];
232
233 if (!pix.IsPixelUsed())
234 continue;
235
236 const MGeomPix &gpix = geom[pix.GetPixId()];
237
238 const float dx = gpix.GetX() - xmean;
239 const float dy = gpix.GetY() - ymean;
240
241 const float nphot = pix.GetNumPhotons();
242
243 sigmaxx += nphot * dx*dx; // [mm^2]
244 sigmaxy += nphot * dx*dy; // [mm^2]
245 sigmayy += nphot * dy*dy; // [mm^2]
246 }
247
248 //
249 // check for orientation
250 //
251 const float theta = atan(sigmaxy/(sigmaxx-sigmayy)*2)/2;
252
253 float c = cos(theta); // [1]
254 float s = sin(theta); // [1]
255
256 //
257 // calculate the length of the two axis
258 //
259 float axis1 = 2.0*c*s*sigmaxy + c*c*sigmaxx + s*s*sigmayy; // [mm^2]
260 float axis2 = -2.0*c*s*sigmaxy + s*s*sigmaxx + c*c*sigmayy; // [mm^2]
261
262 axis1 /= fSize; // [mm^2]
263 axis2 /= fSize; // [mm^2]
264
265 //
266 // check for numerical negatives
267 // (very small number can get negative by chance)
268 //
269 if (axis1 < 0) axis1=0;
270 if (axis2 < 0) axis2=0;
271
272 //
273 // calculate the main Hillas parameters
274 //
275 // fLength, fWidth describes the two axis of the ellipse
276 // fAlpha is the angle between the length-axis and the center
277 // of the camera
278 // fDist is the distance between the center of the camera and the
279 // denter of the ellipse
280 //
281 const int rotation = axis1<axis2;
282
283 fLength = rotation ? sqrt(axis2) : sqrt(axis1); // [mm]
284 fWidth = rotation ? sqrt(axis1) : sqrt(axis2); // [mm]
285
286 const float a = c*xmean + s*ymean;
287 const float b = c*ymean - s*xmean;
288
289 fAlpha = rotation ? atan(a/b) : atan(-b/a); // [rad]
290 fAlpha *= kRad2Deg; // [deg]
291
292 fDist = sqrt(xmean*xmean + ymean*ymean); // [mm]
293
294 fTheta = atan(ymean/xmean); // [rad]
295 if (xmean<0) fTheta += kPI; // [rad]
296
297 SetReadyToSave();
298
299 return kTRUE;
300}
301
302void MHillas::AsciiRead(ifstream &fin)
303{
304 fin >> fAlpha;
305 fin >> fTheta;
306 fin >> fWidth;
307 fin >> fLength;
308 fin >> fSize;
309 fin >> fDist;
310}
311
312void MHillas::AsciiWrite(ofstream &fout) const
313{
314 fout << fAlpha << " ";
315 fout << fTheta << " ";
316 fout << fWidth << " ";
317 fout << fLength << " ";
318 fout << fSize << " ";
319 fout << fDist << endl;
320}
Note: See TracBrowser for help on using the repository browser.