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

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