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

Last change on this file since 749 was 749, checked in by tbretz, 24 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 6.6 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// //
34/////////////////////////////////////////////////////////////////////////////
35#include "MHillas.h"
36
37#include <math.h>
38
39#include <TEllipse.h>
40
41#include "MCerPhotEvt.h"
42#include "MCerPhotPix.h"
43#include "MGeomCam.h"
44
45#include "MLog.h"
46
47ClassImp(MHillas)
48
49MHillas::MHillas(const char *name, const char *title) :
50 fAlpha(0), fTheta(0), fWidth(0), fLength(0), fSize(0), fDist(0), fEllipse(NULL)
51{
52 *fName = name ? name : "MHillas";
53 *fTitle = title ? title : "Storage container for Hillas parameter of one event";
54
55 // FIXME: Initialization of values missing
56}
57
58MHillas::~MHillas()
59{
60 Clear();
61}
62
63void MHillas::Print(Option_t *)
64{
65 *fLog << "Hillas Parameter:" << endl;
66 *fLog << " - Alpha = " << fabs(fAlpha) << endl;
67 *fLog << " - Width = " << fWidth << endl;
68 *fLog << " - Length = " << fLength << endl;
69 *fLog << " - Size = " << fSize << endl;
70 *fLog << " - Dist = " << fDist << endl;
71}
72
73void MHillas::Paint(Option_t *)
74{
75 if (!fEllipse)
76 return;
77
78 fEllipse->Paint();
79}
80
81void MHillas::Draw(Option_t *)
82{
83 //
84 // Instead of adding MHillas itself to the Pad
85 // (s. AppendPad in TObject) we create an ellipse,
86 // which is added to the Pad by it's Draw function
87 // You can remove it by deleting the Ellipse Object
88 // (s. Clear() )
89 //
90
91 Clear();
92
93 fEllipse = new TEllipse(cos(fTheta)*fDist, sin(fTheta)*fDist,
94 fLength, fWidth,
95 0, 360, fTheta*kRad2Deg+fAlpha-180);
96
97 fEllipse->SetLineWidth(2);
98 fEllipse->Draw();
99
100 /*
101 This is from TH1
102 TString opt = option;
103 opt.ToLower();
104 if (gPad && !opt.Contains("same")) {
105 //the following statement is necessary in case one attempts to draw
106 //a temporary histogram already in the current pad
107 if (TestBit(kCanDelete)) gPad->GetListOfPrimitives()->Remove(this);
108 gPad->Clear();
109 }
110 AppendPad(opt.Data());
111 */
112}
113
114void MHillas::Clear(Option_t *)
115{
116 if (!fEllipse)
117 return;
118
119 delete fEllipse;
120
121 fEllipse = NULL;
122}
123
124Bool_t MHillas::Calc(MGeomCam &geom, MCerPhotEvt &evt)
125{
126 //
127 // Calculate the Hillas parameters from a cerenkov photon event
128 // (The calcualtion is some kind of two dimentional statistics)
129 //
130
131 const UInt_t nevt = evt.GetNumPixels();
132
133 //
134 // sanity check
135 //
136 if (nevt <= 2)
137 return kFALSE;
138
139 //
140 // calculate mean valu of pixels
141 //
142 float xmean =0;
143 float ymean =0;
144
145 fSize = 0;
146
147 //
148 // FIXME! npix should be retrieved from MCerPhotEvt
149 //
150 UShort_t npix=0;
151 for (UInt_t i=0; i<nevt; i++)
152 {
153 const MCerPhotPix &pix = evt[i];
154
155 if (!pix.IsPixelUsed())
156 continue;
157
158 const MGeomPix &gpix = geom[pix.GetPixId()];
159
160 const float nphot = pix.GetNumPhotons();
161
162 fSize += nphot;
163 xmean += nphot * gpix.GetX(); // [mm]
164 ymean += nphot * gpix.GetY(); // [mm]
165
166 npix++;
167 }
168
169 //
170 // sanity check
171 //
172 if (fSize==0 || npix<=2)
173 return kFALSE;
174
175 xmean /= fSize; // [mm]
176 ymean /= fSize; // [mm]
177
178 //
179 // calculate sdev
180 //
181 float sigmaxx=0;
182 float sigmaxy=0;
183 float sigmayy=0;
184
185 for (UInt_t i=0; i<nevt; i++)
186 {
187 const MCerPhotPix &pix = evt[i];
188
189 if (!pix.IsPixelUsed())
190 continue;
191
192 const MGeomPix &gpix = geom[pix.GetPixId()];
193
194 const float dx = gpix.GetX() - xmean;
195 const float dy = gpix.GetY() - ymean;
196
197 const float nphot = pix.GetNumPhotons();
198
199 sigmaxx += nphot * dx*dx; // [mm^2]
200 sigmaxy += nphot * dx*dy; // [mm^2]
201 sigmayy += nphot * dy*dy; // [mm^2]
202 }
203
204 //
205 // check for orientation
206 //
207 const float theta = atan(sigmaxy/(sigmaxx-sigmayy)*2)/2;
208
209 float c = cos(theta); // [1]
210 float s = sin(theta); // [1]
211
212 //
213 // calculate the length of the two axis
214 //
215 float axis1 = 2.0*c*s*sigmaxy + c*c*sigmaxx + s*s*sigmayy; // [mm^2]
216 float axis2 = -2.0*c*s*sigmaxy + s*s*sigmaxx + c*c*sigmayy; // [mm^2]
217
218 axis1 /= fSize; // [mm^2]
219 axis2 /= fSize; // [mm^2]
220
221 //
222 // check for numerical negatives
223 // (very small number can get negative by chance)
224 //
225 if (axis1 < 0) axis1=0;
226 if (axis2 < 0) axis2=0;
227
228 //
229 // calculate the main Hillas parameters
230 //
231 // fLength, fWidth describes the two axis of the ellipse
232 // fAlpha is the angle between the length-axis and the center
233 // of the camera
234 // fDist is the distance between the center of the camera and the
235 // denter of the ellipse
236 //
237 const int rotation = axis1<axis2;
238
239 fLength = rotation ? sqrt(axis2) : sqrt(axis1); // [mm]
240 fWidth = rotation ? sqrt(axis1) : sqrt(axis2); // [mm]
241
242 const float a = c*xmean + s*ymean;
243 const float b = c*ymean - s*xmean;
244
245 fAlpha = rotation ? atan(a/b) : atan(-b/a); // [rad]
246 fAlpha *= kRad2Deg; // [deg]
247
248 fDist = sqrt(xmean*xmean + ymean*ymean); // [mm]
249
250 fTheta = atan(ymean/xmean); // [rad]
251 if (xmean<0) fTheta += kPI; // [rad]
252
253 return kTRUE;
254}
Note: See TracBrowser for help on using the repository browser.