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

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